opyeb WaveLab

Guides · FFT

Inside the radix-2 FFT

Basis 28 Nov 2026 · digital signal processing · 7 min read

The discrete Fourier transform of N samples is a sum of N terms for each of N outputs: N² complex multiply-adds. For 4 096 samples that is 16.8 million, and a browser would stall doing it thirty times a second. The fast Fourier transform reorganises the same sum so that most of the work is shared.

X[k] = Σₙ₌₀^{N−1} x[n]·e^(−j2πkn/N)

Splitting the sum in two

Separate the even-indexed samples from the odd ones. Each half is a DFT of length N/2, and because e^(−j2πk(n+N/2)/N) = −e^(−j2πkn/N), the two halves combine with a single sign change: X[k] = E[k] + W_N^k·O[k] and X[k+N/2] = E[k] − W_N^k·O[k], where W_N = e^(−j2π/N). Apply the same split to each half and the recursion runs log₂N levels deep.

X[k] = E[k] + W^k O[k], X[k + N/2] = E[k] − W^k O[k]

One butterfly

The pair of equations above is a butterfly: two inputs, one twiddle factor, two outputs. Each level of the transform performs N/2 butterflies, and there are log₂N levels, so the total is (N/2)·log₂N butterflies — 24 576 for N = 4 096 instead of 16.8 million. Every textbook FFT is a schedule for doing those butterflies in place.

NDirect DFT (N²)Radix-2 butterfliesSpeed-up
512262 1442 304114×
1 0241 048 5765 120205×
2 0484 194 30411 264372×
4 09616 777 21624 576683×

Why the input is bit-reversed

Working in place saves the memory for a second array, but the recursion visits the samples in a scrambled order. If you write the index in binary, reverse its bits and read the samples in that order, the butterflies at each level consume neighbours, and the whole transform becomes a loop over levels with no recursion at all. The bit-reversal permutation is what makes the in-place version look confusing in source code.

For N = 8 the permuted order is 0, 4, 2, 6, 1, 5, 3, 7. Consecutive pairs then differ in the highest bit, which is exactly what the first level needs. Each level doubles the span and halves the twiddle step.

Numerical behaviour

Each butterfly does one complex multiply and two adds, so the accumulated rounding is modest: for N = 4 096 in double precision the relative error of a transform is around 1e-15, far below anything audible. In single precision it is around 1e-6, which is still invisible in a spectrum display but can matter for narrow-band peak interpolation.

WaveLab runs the transform in double precision (Float64Array) on the main thread. At N = 4 096 that is about 25 000 butterflies per frame, a fraction of a millisecond, so the display keeps its refresh rate.

What the FFT does not do

It computes the DFT exactly — no approximation of the spectrum beyond the one every DFT makes: the signal is assumed periodic with period N. That assumption is the source of leakage, and it is why the window choice matters more than the transform itself.

Questions

Why must N be a power of two?

The radix-2 decomposition splits the input in half at every level, so it needs N to divide by two repeatedly. Other lengths are handled by mixed-radix or Bluestein algorithms, or by zero-padding to the next power of two.

Is the inverse FFT a different algorithm?

No. Reverse the input order, conjugate the twiddle factors, run the same transform, and scale by 1/N. Most libraries share one routine for both.

Change N in the analyser from 512 to 4096 and watch the bin width fall by eight while the spectrum gets finer — the same butterflies, more of them.

Open the studio

Written from standard Fourier analysis, digital signal processing and acoustics; the worked numbers can be reproduced in the studio linked above.

Back to the guides