Joe Lertola · Mathematical Handbook Big idea 10 of 12

Built from waves

From the handbook: Series, trigonometric and Fourier series, §411–418, pages 608–624

Any repeating shape, even one with sharp corners, is a sum of smooth sine waves of different sizes and speeds.

Vygodsky's Mathematical Handbook
The target shape (white) and the sum of waves so far (orange). Add waves.
The recipe: how much of each wave, from the slowest (1) to faster ones. This is the shape's spectrum.

The sum so far

At x = π/2 (the dotted line)

Sum of waves
True value
Highest point of the sum

Every repeating shape is a sum of waves

A sine wave is the smoothest possible repeating shape. In the 1800s Joseph Fourier claimed that every repeating shape, however jagged, can be built by stacking sine waves: one that repeats once per cycle, one that repeats twice, three times, and so on, each with its own size. Even a square wave, which jumps straight up and down, is a sum of perfectly smooth curves.

The slowest wave sets the overall swing. Faster waves add detail: they sharpen corners and flatten tops. The list of sizes, one per speed, is the shape's recipe, called its spectrum.

The formula

For a shape f(x) that repeats every 2π (one full turn of a circle), the book (§415) writes

f(x) = a₀/2 + a₁ cos x + b₁ sin x + a₂ cos 2x + b₂ sin 2x + …

Read it as “f of x equals a constant, plus some amount of the wave that repeats once, plus some amount of the wave that repeats twice, and so on”. sin kx and cos kx are waves that repeat k times per cycle; cosine is the same wave as sine, just shifted a quarter turn. The numbers ak and bk say how much of each to use.

How much of each? The Euler-Fourier formulas (§414) answer it: multiply the shape by the wave you're asking about and find the average (an integral, idea 6):

bk = (1/π) ∫ f(x) sin kx dx,  from −π to π

Read it as “b-sub-k is one over pi times the integral of the shape times the kth sine wave”. Where the shape and the wave rise and fall together, the product is mostly positive and the amount is large; where they have nothing in common, it averages out to zero. The ak come the same way using cosine.

Worked example: the square wave

A square wave that sits at +1 for half a cycle and −1 for the other half turns out to need only the odd-numbered sine waves, in sizes 4/π, 4/(3π), 4/(5π), …:

f(x) = (4/π) (sin x + sin 3x / 3 + sin 5x / 5 + …)

Check it at the middle of the flat top, x = π/2, where the true value is 1. The first wave gives 4/π ≈ 1.273, too high. Adding the second (sin 3x/3 is at its lowest there) takes away 0.424, giving 0.849. The third adds back 0.255: 1.103. The fourth takes 0.182: 0.921. The sum swings above and below 1, closer each time. The page opens with two waves added.

Near the jump the sum always overshoots by about 9% however many waves you add (the Gibbs effect), though the overshoot gets squeezed into a thinner and thinner spike. At the jump itself the sum lands halfway, at 0, just as the book's theorem for shapes with jumps says (§418).

Where it shows up

This is how sound is analysed and music compressed, how a JPEG image throws away detail you won't miss (it keeps the slow waves and drops the fast ones), and how MRI and CT scanners build an image: the scanner measures the spectrum and a computer adds the waves back up. Procedural terrain and clouds are made the other way round, by stacking noise at many speeds and sizes. Any looping animation cycle is a repeating shape and can be smoothed by dropping its fastest waves.

Try this

  1. Add square-wave terms one at a time and read the value at π/2: it zigzags in on 1, as in the worked example.
  2. Push the slider to 50 and look at the corners. The sum fits almost everywhere, but a thin spike still overshoots each jump by about 9%.
  3. Choose Book's y = x². It has corners but no jumps, and its recipe sizes shrink much faster (1/k² instead of 1/k), so a handful of waves already looks right.
  4. Turn off Show the separate waves and watch only the sum. Then turn it back on and see which wave makes each wiggle.

In the book

Vygodsky, Mathematical Handbook: Higher Mathematics, chapter “Series”.

  • §411–412 Trigonometric series, and their history. p. 608–609
  • §413–414 Why the waves don't interfere when you measure them, and the Euler-Fourier formulas. p. 609–613
  • §415–416 Fourier series, and when they reproduce a continuous shape. p. 613–618
  • §417 Even and odd shapes; the book's example x² = π²/3 − 4(cos x − cos 2x/4 + cos 3x/9 − …). p. 618–622
  • §418 Shapes with jumps: the series lands halfway across each jump. p. 622–624