Chapter 7The DFT & FFT
Everything so far has been building intuition. This is the actual algorithm: given nothing but a list of sampled numbers, compute exactly which frequencies are in the signal — no peeking at how it was built.
The formula
The Discrete Fourier Transform takes $N$ samples $x_0, x_1, \dots, x_{N-1}$ and produces $N$ complex numbers describing the signal's frequency content:
Each $X_k$ answers one question: "how much of frequency $k$ (in cycles per sample-window) is present?" $|X_k|$ — the magnitude of that complex number — is exactly the bar height you see plotted above. This is the same $e^{-i\theta}$ rotation from Chapter 4's circles, just run once per frequency you want to test for, instead of drawn out over time.
Why the FFT exists
Computed directly, the formula above costs $O(N^2)$ multiplications — for every one of the $N$ output frequencies, you sum over all $N$ input samples. The Fast Fourier Transform (FFT) is not a different formula; it's the same DFT computed cleverly, by recursively splitting the sum into even- and odd-indexed samples and reusing work between them. That drops the cost to $O(N \log N)$:
| N (samples) | DFT: N² ops | FFT: N·log₂N ops | Speedup |
|---|
At small $N$ the difference barely matters. At the sizes real audio, image, and radio-signal processing use — millions of samples — the FFT is the only reason any of this runs in real time at all.