Skip to content

The Fourier series of a square wave

5 min read

Short answer

A square wave equal to +1+1 on (0,π)(0,\pi) and −1-1 on (−π,0)(-\pi,0) has the series 4π(sin⁡x+sin⁡3x3+sin⁡5x5+⋯ )\dfrac4\pi\left(\sin x+\dfrac{\sin3x}3+\dfrac{\sin5x}5+\cdots\right): only odd sine harmonics, with amplitudes falling like 1/n1/n. Near the jump, partial sums overshoot by about 9%, the Gibbs phenomenon.

Bar chart1357911Amplitude of each odd harmonic: 4/(nπ).
Sharp edges need many high harmonics, and their amplitudes decay slowly.

The calculation

The wave is odd, so an=0a_n=0. Then bn=2π∫0πsin⁡nx dx=2nπ(1−cos⁡nπ)b_n=\dfrac2\pi\int_0^\pi\sin nx\,dx=\dfrac{2}{n\pi}\big(1-\cos n\pi\big). For even nn this is 00; for odd nn it equals 4nπ\dfrac{4}{n\pi}.

Convergence and Gibbs

At each jump, the series converges to the midpoint of the two sides (00 here). Near the jump the partial sums overshoot by about 9%9\% of the jump size, and adding terms squeezes the overshoot toward the jump but never removes it.

Worked example

Use the series at x=π2x=\tfrac\pi2 to evaluate 1−13+15−17+⋯1-\tfrac13+\tfrac15-\tfrac17+\cdots.

At x=π2x=\tfrac\pi2 the wave equals 11 and sin⁡nπ2\sin\tfrac{n\pi}{2} alternates 1,−1,1,…1,-1,1,\ldots for n=1,3,5,…n=1,3,5,\ldots. So 1=4π(1−13+15−⋯ )1=\dfrac4\pi\left(1-\tfrac13+\tfrac15-\cdots\right), giving 1−13+15−⋯=π41-\tfrac13+\tfrac15-\cdots=\dfrac\pi4 (the Leibniz series).

Try it yourself

What value does the Fourier series take at x=0x=0, where the square wave jumps from −1-1 to 11?

Show the answer

Every term sin⁡nx\sin nx vanishes at 00, so the series gives 00, the average of the two one-sided values.

Keep going with practice

Vidi's signals lessons build square waves in audio from exactly these odd harmonics.