Fourier series

Any closed shape is a sum of circles spinning at different speeds.

Draw a shape below. Its outline becomes two equations, x(t) and y(t), each a sum of sines and cosines, and a chain of spinning circles draws it back. Slide the number of terms to watch the shape sharpen.

Try: heart · star · square · bird

Try this

  1. Set the terms to 1. Every shape becomes an ellipse. One circle can only ever draw an ellipse.
  2. Pick the star, then the heart, at 10 terms. The heart is almost perfect; the star's points are still round. Corners need many more circles than curves.
  3. Draw a circle by hand. Nearly all of it is in the first term. Look at the equations: after k = 1 the numbers are tiny.
  4. Slide the terms slowly from 1 to 100 on the square. The error drops fast at first, then slowly. The last bit of a corner is the hardest.

From a drawing to an equation, step by step

The pictures below are made from your shape. Draw something new above and they all change.

1Walk round the outline at an even pace

Your hand drew some parts slowly and others fast, so the points it left are bunched up in places. First the outline is re-measured: points are placed at equal distances along it, a few hundred of them, all the way round and back to the start.

Now a single number, t, says where the pen is: t = 0 at the start, t = 2π after one lap. Equal steps in t are equal steps along the outline.

Every 8th point is shown. Green is the start; the arrow shows the direction of travel.

2Split it into two wiggles

As the pen walks round, its left-right position goes up and down, and so does its up-down position. Plot each against t and you get two separate wiggly lines: x(t) and y(t).

Both repeat exactly every lap, because the outline is closed. Anything that repeats can be built from waves that also repeat every lap: one wave per lap, two per lap, three per lap, and so on.

Blue: x(t). Red: y(t). One lap, t from 0 to 2π.

3Measure how much of each wave is in there

To find how much of the "k waves per lap" cosine is in x(t), multiply the two together at every point and take the average. Where they rise and fall together the products are positive; where they don't, they cancel out. Doubled, that average is the coefficient aₖ.

aₖ = 2 · average of x(t)·cos(kt)
bₖ = 2 · average of x(t)·sin(kt)
cₖ, dₖ: the same for y(t)

Nobody guesses these numbers. They are measured from the drawing, which is the whole trick. Most of the size sits in the slow waves; the fast ones only add detail.

The size of each frequency in your shape (the radius of its circles), k = 1 to 40.

4Add the waves back up, one at a time

With only k = 1, every shape becomes an ellipse: the crudest possible version. Each extra frequency adds a smaller, faster wiggle on top, and the shape sharpens.

Smooth curves need only a few terms. Sharp corners, like a star's points or a bird's beak, need many: smooth waves can only ever approximate a corner.

Your shape with 1, 2, 3, 5, 10 and 40 terms. Grey is what you drew.

5Turn each wave into a spinning circle

A cosine and a sine of the same speed together are just a point going round a circle. So each frequency is a circle turning k times per lap, some clockwise and some anticlockwise.

Put each circle's centre on the rim of the one before, biggest first, and the tip of the last one traces your shape. That chain is exactly the animation at the top of the page, and the two equations are the same thing written down.

The first 8 circles at one moment. The red dot is the pen.

In symbols

x(t) = a₀ + Σ aₖ cos(kt) + bₖ sin(kt)

In words: the left-right position is its average, plus a little of each wave that repeats k times per lap.

y(t) = c₀ + Σ cₖ cos(kt) + dₖ sin(kt)

In words: the same for the up-down position, with its own amounts.

aₖ = (1/π) ∫ x(t) cos(kt) dt (t from 0 to 2π)

In words: how much of wave k is in x is twice the average of x times that wave. The page uses the same sum over its few hundred points.

z(t) = Σ Cₖ e^{ikt}, k = −N … N

In words: written with complex numbers, each term is one arm of length |Cₖ| turning k times per lap. That's the chain of circles.

Where you meet it

Fun facts

It started with heat

Joseph Fourier came up with these series around 1807 while working out how heat spreads through a metal bar. Leading mathematicians of the day, Lagrange among them, doubted that any function could be built from waves.

The ancient Greeks were close

Ptolemy's astronomy, around 150 AD, explained the planets' looping paths with circles riding on circles: epicycles. That is the same idea as the animation above, about 1,650 years before Fourier.

The 9% overshoot

Near a sharp jump, the sum of waves always overshoots by about 9% of the jump, however many terms you add. It's called the Gibbs phenomenon. Henry Wilbraham spotted it in 1848, fifty years before Gibbs.

Your photos use a cousin

JPEG images store small blocks of pixels as a sum of cosine waves and throw away the fast, faint ones you'd hardly see. MP3 and AAC audio do the same with sound.

Gauss got there first

The Fast Fourier Transform, published by Cooley and Tukey in 1965, is one of the most used algorithms ever. Gauss had worked out the same trick around 1805, in notes that went unpublished for decades.

Your ears do this too

Inside your ear, the cochlea responds to different pitches at different places along its length. In effect it splits sound into its frequencies before your brain ever hears it.

Common mix-ups