Signals as sums of sinusoids
A signal with period can be written as a sum of sinusoids whose frequencies are multiples of the fundamental frequency , the harmonics:
The waves here are odd, , so all vanish and only sines remain. Here . The sines of different frequencies are orthogonal: the integral of over a period is 0 for . Each coefficient is therefore just the projection of the signal onto its sine,
and adding a term never changes the coefficients found so far. For the square wave, which jumps between and , this gives
with only odd harmonics, because the second half of each period is the negative of the first, . The partial sum of the first terms is the best approximation of with these frequencies in the least-squares sense.
Smoothness and decay
How fast the coefficients decay depends on how smooth the signal is. A signal with jumps, like the square and sawtooth waves, has coefficients that fall off like : many high frequencies are needed to build the steep edges. The triangle wave is continuous and only its slope jumps; its coefficients fall off like , and a few terms already look almost exact. Sharp edges in an image need high frequencies in the same way, which is why blurring (removing high frequencies) softens edges, and why edges alias so easily when an image is subsampled.
Energy
The energy of the signal is split among its terms. By Parseval's theorem, the mean of over a period is . For the square wave the mean of is 1, and the first term alone already carries of it.
The Gibbs phenomenon
At a jump, the partial sums overshoot. With more terms the ripples get narrower and move closer to the jump, but the first peak does not get lower: it stays at about 9 % of the jump height, for the square wave. The series still converges at every point, and the error energy goes to 0, but not uniformly. The same ringing appears next to edges in images when high frequencies are cut off abruptly, for example by an ideal low-pass filter in the 2D Fourier transform.
Try this
- Click “Add term” a few times and follow the newest term: each one is faster than the last and pushes the sum closer to the flat parts and the jumps.
- Look at the coefficient plot of the square wave: every even harmonic is missing, and the bars fall off like .
- Increase to 60 terms: the ripples crowd towards the jumps, but the overshoot in the values panel stays near 9 %.
- Switch to the triangle wave: with 3 terms the sum is hard to tell apart from the target. Compare its RMS error with the square wave's.
- Switch to the sawtooth: it needs all harmonics, even and odd, with alternating signs.
- With the square wave, compare the energy captured by 1, 2 and 10 terms: most of it is in the first term, but the corners are in the rest.