The Fourier Series

Put the building blocks and their coefficients together and you have the Fourier series of a periodic function f of period 2L:

f(x) = \frac{a_0}{2} + \sum_{n=1}^{\infty}\Big(a_n\cos\frac{n\pi x}{L} + b_n\sin\frac{n\pi x}{L}\Big).

The constant a_0/2 sets the average level; each n adds a ripple of frequency n\pi/L in just the amount the coefficient prescribes. Truncating after N terms gives a partial sum S_N(x) — a finite, smooth approximation that improves as N grows.

A square wave from smooth ripples

The cleanest demonstration is the square wave: f(x) = +1 where \sin x > 0 and -1 where it is negative. It is odd, so only sines survive, and only the odd harmonics at that:

f(x) = \frac{4}{\pi}\Big(\sin x + \frac{\sin 3x}{3} + \frac{\sin 5x}{5} + \cdots\Big) = \frac{4}{\pi}\sum_{k\ \text{odd}}\frac{\sin kx}{k}.

Each new harmonic squares off the corners a little more. The astonishing claim — sharp, flat-topped steps emerging from nothing but smooth sine waves — is right there to watch.

Add the harmonics

The faint dashed line is the target square wave; the bold curve is the partial sum S_N using the first N odd harmonics. Raise N and the approximation hugs the steps ever more tightly — flat where the wave is flat, snapping over at each jump.

Symmetry saves work. If f is even (f(-x) = f(x)), every b_n = 0 and only cosines appear. If f is odd (f(-x) = -f(x)), every a_n = 0 and only sines appear — which is why the odd square wave is a pure sine series. Spotting symmetry first can halve the integrals you actually have to do.