---
title: "Fourier series of square wave and DFT"
subject: "Instrumentation and Measurement"
chapter: 2
key: "semester_4/instrumentation_and_measurement:fourier-series-square-wave-dft"
source: https://www.bctengineer.com/q/semester_4/instrumentation_and_measurement/fourier-series-square-wave-dft
site: BCT Engineering
---

# Fourier series of square wave and DFT

Instrumentation and Measurement · Chapter 2: Time Dependent Properties of Signal

- Asked in: year not given, 5+3 marks
- Video: [How to Compute a FOURIER SERIES // Formulas & Full Example](https://www.youtube.com/watch?v=ijQaTAT3kOg) — Dr. Trefor Bazett
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/instrumentation_and_measurement/fourier-series-square-wave-dft
- Whole chapter: https://www.bctengineer.com/md/semester_4/instrumentation_and_measurement/chapter-2

## Question

(a) Derive the Fourier series of a square wave of amplitude $\pm A$ and period $T$, defined as $+A$ for $0 < t < T/2$ and $-A$ for $T/2 < t < T$.

(b) Four equally spaced samples of a signal are $x = \{1, 3, 2, 0\}$. Compute the 4-point DFT and state why the FFT is preferred for large $N$.

## Short answer

Fourier series of ±A square wave: only odd harmonics, f(t) = (4A/π)(sin ω₀t + 1/3 sin 3ω₀t + …). 4-point DFT of {1,3,2,0}: X = {6, -1-j3, 0, -1+j3}. FFT reduces operations from N² to (N/2)log₂N, enabling fast real-time spectral analysis.

## Answer

#### (a) Fourier series of the square wave
A periodic signal of period $T$ and $\omega_0 = 2\pi/T$ is written as

$$
f(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty}\left(a_n\cos n\omega_0 t + b_n\sin n\omega_0 t\right)
$$

with $a_0 = \frac{2}{T}\int_0^T f\,dt$, $a_n = \frac{2}{T}\int_0^T f\cos n\omega_0 t\,dt$, $b_n = \frac{2}{T}\int_0^T f\sin n\omega_0 t\,dt$.

```text
  +A   +---------+         +---------+
       |         |         |         |
   0 --+---------+---------+---------+---> t
       |         |         |         |
  -A   |         +---------+         +----
       0        T/2        T       3T/2
```

The wave has zero mean over a period, so $a_0 = 0$. With the origin at the rising edge it is an odd function (about $t=0$, over $-T/2 < t < T/2$), so all $a_n = 0$.

$$
b_n = \frac{2}{T}\left[\int_0^{T/2} A\sin n\omega_0 t\,dt - \int_{T/2}^{T} A\sin n\omega_0 t\,dt\right]
$$

$$
\int_0^{T/2}\sin n\omega_0 t\,dt = \frac{1-\cos n\pi}{n\omega_0}, \qquad \int_{T/2}^{T}\sin n\omega_0 t\,dt = \frac{\cos n\pi - 1}{n\omega_0}
$$

$$
b_n = \frac{2A}{T}\cdot\frac{2(1-\cos n\pi)}{n\omega_0} = \frac{2A(1-\cos n\pi)}{n\pi}
$$

So $b_n = 4A/(n\pi)$ for odd $n$ and $b_n = 0$ for even $n$. Therefore

$$
f(t) = \frac{4A}{\pi}\left[\sin\omega_0 t + \frac{1}{3}\sin 3\omega_0 t + \frac{1}{5}\sin 5\omega_0 t + \cdots\right]
$$

Only odd harmonics exist, and their amplitudes fall as $1/n$.

#### (b) 4-point DFT
$$
X_k = \sum_{n=0}^{3} x_n e^{-j2\pi kn/4}, \qquad x = \{1, 3, 2, 0\}
$$

Using $e^{-j\pi k n/2} = 1, -j, -1, j$ for $kn = 0, 1, 2, 3 \pmod 4$:

- $X_0 = 1+3+2+0 = 6$
- $X_1 = 1 + 3(-j) + 2(-1) + 0 = -1 - j3$
- $X_2 = 1 + 3(-1) + 2(1) + 0 = 0$
- $X_3 = 1 + 3(j) + 2(-1) + 0 = -1 + j3$

| k | $X_k$ | Magnitude | Phase |
|---|---|---|---|
| 0 | 6 | 6 | 0 |
| 1 | $-1 - j3$ | 3.16 | $-108.4^\circ$ |
| 2 | 0 | 0 | - |
| 3 | $-1 + j3$ | 3.16 | $+108.4^\circ$ |

**Answer: $X = \{6,\ -1-j3,\ 0,\ -1+j3\}$.**

#### Why FFT
A direct DFT needs about $N^2$ complex multiplications. The FFT (Cooley-Tukey) repeatedly splits the sum into even and odd samples and needs only about $(N/2)\log_2 N$. For $N = 1024$ this is about 5120 instead of about 1,000,000, so spectra can be obtained quickly, even in real time.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why are a0 and all an zero for the square wave (with origin at the rising edge)?
   A. The wave has zero mean and is an odd function
   B. The wave is even and has zero mean
   C. The wave has a nonzero mean but is odd
   D. The amplitude is too small
   Answer: A. Zero mean gives a0 = 0 and odd symmetry removes all cosine terms, leaving only sine terms. (Key point: Zero a0 and an)

2. Which harmonics does the square wave contain and how do amplitudes vary?
   A. All harmonics, falling as 1/n^2
   B. Even harmonics only, falling as 1/n
   C. Odd harmonics only, falling as 1/n
   D. Odd harmonics only, constant amplitude
   Answer: C. bn = 4A/(nπ) for odd n and 0 for even n. (Key point: Harmonic content)

3. For x = {1, 3, 2, 0}, what are X0 and X2?
   A. X0 = 6, X2 = 0
   B. X0 = 6, X2 = 2
   C. X0 = 0, X2 = 6
   D. X0 = 3, X2 = 0
   Answer: A. X0 = 1+3+2+0 = 6; X2 = 1 - 3 + 2 + 0 = 0. (Key point: DFT values)

4. Why is the FFT preferred for large N?
   A. It gives more accurate spectra than the DFT
   B. It needs about (N/2)log2 N multiplications instead of about N^2
   C. It needs fewer samples
   D. It avoids complex numbers
   Answer: B. The FFT splits the sum into even and odd samples; for N=1024 it needs about 5120 instead of about a million multiplications. (Key point: Why FFT)

## Related in Instrumentation and Measurement

- [Harmonic signal parameters and RMS value](https://www.bctengineer.com/question.md?key=semester_4%2Finstrumentation_and_measurement%3Aharmonic-signal-parameters-rms) — Instrumentation and Measurement, chapter 2

## Related in other subjects

- [Fourier series coefficients of a square wave](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Afs-coefficients-square-wave) — Data Communication, chapter 3
- [8-point DFT by FFT of {1,−1,2,2,1,1,2,2}](https://www.bctengineer.com/question.md?key=semester_7%2Fdigital_signal_analysis_and_processing%3Afft-8pt-73s) — Digital Signal Analysis and Processing, chapter 7, asked 4×
- [8-point DIF-FFT of {1/2,1/2,1/2,1/2,0,0,0,0}](https://www.bctengineer.com/question.md?key=semester_7%2Fdigital_signal_analysis_and_processing%3Adif-fft-half-ones) — Digital Signal Analysis and Processing, chapter 7
- [Derive the discrete-time Fourier series](https://www.bctengineer.com/question.md?key=semester_4%2Fsignals_and_systems%3Adtfs-derivation) — Signals and Systems, chapter 2, asked 15×
