Chapter 3Fourier Series
Here's the claim that makes all of this useful: any repeating shape — even one with a sharp corner, like a square wave — can be built purely out of smooth sine waves. Watch it happen.
Target shape
Fourier approximation
What's actually being summed right now:
The formulas
Each target shape has its own recipe of harmonics — a fundamental frequency $f$ plus a specific series of multiples of it, each with a prescribed amplitude:
Square wave (odd harmonics only)
$$ s(t) = \frac{4}{\pi}\sum_{k=1,3,5,\dots} \frac{1}{k}\sin(2\pi k f t) $$
Sawtooth wave (every harmonic)
$$ s(t) = \frac{2}{\pi}\sum_{k=1}^{\infty} \frac{(-1)^{k+1}}{k}\sin(2\pi k f t) $$
Triangle wave (odd harmonics, squared decay)
$$ s(t) = \frac{8}{\pi^2}\sum_{k=1,3,5,\dots} \frac{(-1)^{(k-1)/2}}{k^2}\sin(2\pi k f t) $$
What to notice
- N = 1 is just a plain sine wave — a rough guess at the shape.
- Each added harmonic sharpens a corner or flattens a curve a little more. Notice the triangle wave's amplitudes shrink as $1/k^2$ — its harmonics fade fast, so it converges to a clean shape quickly. The square wave's amplitudes only shrink as $1/k$ — much slower — so it needs far more harmonics to look sharp.
- Ripples near the corners never fully disappear, even at N = 30 for the square wave. That persistent ~9% overshoot is called the Gibbs phenomenon — a real mathematical limit, not a bug in this demo.
Every one of these harmonics, individually, is exactly the sine wave from Chapter 1 — just a different frequency, amplitude, and (via the sign) phase. A Fourier series is nothing more than Chapter 2's addition trick, done with a very specific guest list of waves.