Fourier series
Any periodic wave can be built by adding sine and cosine waves at whole-number multiples of one frequency. Add harmonics and watch the sum close in on the target, everywhere except right next to a jump.
Spectrum: amplitude of each harmonic
Readouts
What's happening
A wave with period 2π can be written as a constant plus harmonics: f(t) ≈ a₀/2 + Σ (aₙ cos nt + bₙ sin nt). Each coefficient measures how much of that harmonic the wave contains, and it is found by multiplying by cos nt or sin nt and averaging over a period, because different harmonics average to zero against each other. Symmetry does a lot of the work: an odd wave needs only sines, an even wave only cosines, and a wave with f(t + π) = −f(t) only odd harmonics. Smooth waves have coefficients that fall fast (1/n² for the triangle) and the sum fits quickly; waves with a jump fall like 1/n and the sum wobbles. Right beside a jump the partial sum always overshoots by about 8.95% of the jump, however many terms you take: that is the Gibbs phenomenon. The overshoot gets thinner, so the RMS error still shrinks to 0, and Parseval's theorem gives that error straight from the coefficients. Press Start to see each harmonic as a rotating arrow: the arrows add tip to tail and the height of the last tip traces out the sum.
First-year university maths, physics and engineering: Fourier series, even and odd functions, convergence, the Gibbs phenomenon and Parseval's theorem. Links to A-Level Further Maths work on series.
Work through the numbers with Graphing Calculator.
Challenge
Predict first: as N grows, does the square wave's overshoot next to the jump shrink towards 0? Guess its size at N = 99 as a percentage of the jump, type it in, then turn on the zoom in Advanced and step N up.
No. The overshoot narrows and moves closer to the jump, but its height settles at about 8.95% of the jump (0.179 above the top value 1, since the jump is 2). At N = 99 it is 8.95% to two decimal places. The RMS error still tends to 0, because the overshoot gets thinner.
FAQ
- How do I calculate Fourier coefficients?
- For period 2π, aₙ = (1/π)∫ f(t) cos nt dt and bₙ = (1/π)∫ f(t) sin nt dt over one period, and a₀/2 is the average value of f. For the square wave (−1 then 1) this gives bₙ = 4/(nπ) for odd n and every other coefficient 0.
- Why does an odd function have only sine terms?
- If f(−t) = −f(t), then f(t) cos nt is odd too, and an odd function integrates to 0 over a symmetric period, so every aₙ is 0. In the same way an even function has every bₙ = 0.
- What is the Gibbs phenomenon?
- Near a jump, a Fourier partial sum overshoots the wave by about 8.95% of the jump, and adding more terms does not remove it: the overshoot only gets narrower and closer to the jump. The exact limit of the peak is (2/π)Si(π) ≈ 1.179 for a step from −1 to 1.
- What does Parseval's theorem say?
- The mean of f² equals (a₀/2)² + ½Σ(aₙ² + bₙ²). So the energy left out of a partial sum, and with it the RMS error, comes straight from the coefficients you have not included.
- How many harmonics do I need for a given RMS error?
- Use Parseval: the mean square error after N harmonics is the mean of f² minus (a₀/2)² minus half the sum of aₙ² + bₙ² that you kept. For the square wave the mean of f² is 1 and each odd harmonic takes off 8/(π²n²). The RMS error is 0.1006 at N = 39 and first drops below 0.1 at N = 41 (0.0982). N for an RMS error under Solve for does the sum.