Kolton Ndoj

The Fast Fourier Transform: hearing the notes inside a sound

Inside music streaming, phone calls, Wi-Fi, music visualisers and every audio app that shows a spectrum

What problem does it solve?

How do you split a sound into its frequencies fast enough to do it thousands of times a second?

The big idea

The Fourier transform says any signal is a sum of spinning circles (sine waves) of different speeds. Measuring the amount of each of N frequencies the obvious way costs N × N multiplications. The FFT's aha is that the spinning circles are made of the same 'roots of unity', points equally spaced around Euler's circle. So you can split the samples into even and odd positions, transform each half, and combine them with a twist, then split those halves again, and again. The work drops from N² to N log₂ N.

How it works, step by step

  1. 1. Take N samples of the sound, with N a power of 2 (e.g. 1024).
  2. 2. Split them into even-numbered and odd-numbered samples.
  3. 3. Compute the FFT of each half (by splitting again, all the way down to single samples).
  4. 4. Combine: X_k = E_k + e^{−2πik/N}·O_k and X_{k+N/2} = E_k − e^{−2πik/N}·O_k, two answers per multiplication.
  5. 5. The sizes |X_k| tell you how loud each frequency is.

The key formula

Xk=∑n=0N−1xn e−2πi kn/NX_k=\sum_{n=0}^{N-1}x_n\,e^{-2\pi i\,kn/N}
xnx_n
the n-th sample of the sound
e−2πi kn/Ne^{-2\pi i\,kn/N}
a point spinning around Euler's circle at speed k
XkX_k
how much of frequency k is in the sound (a complex number: size and phase)

How fast is it?

For a million samples, N² ≈ 10¹² operations versus N log₂ N ≈ 2 × 10⁷, about 50,000 times faster. Honest note on music streaming: audio codecs like MP3, AAC and Vorbis (which Spotify has long used) store sound with the MDCT, a cosine-only Fourier cousin computed with FFT-style speedups, and use a 'psychoacoustic model' to throw away sounds your ear can't hear because louder nearby frequencies mask them.

Graph for The Fast Fourier Transform: hearing the notes inside a sound 241004000
How many times faster the FFT is than the obvious method for t samples: N² ÷ (N log₂ N). At 4096 samples it's already about 340 times faster, and the gap keeps growing. (drawn with the default slider values — move the sliders live)

Try it yourself

Fun fact

James Cooley and John Tukey published the FFT in 1965, partly motivated by detecting Soviet nuclear tests from seismic signals. Later, historians found that Carl Friedrich Gauss had used the same trick around 1805 to calculate asteroid orbits, but it was only published after his death.

Related

Open it in the Math Lab →

Media · Stretch