The Fourier transform
Any signal is a sum of sine waves of different frequencies. The Fourier transform converts between the time domain (the wave) and the frequency domain (which frequencies it contains) — and it's quietly inside audio ML, rotary positional embeddings, and fast convolution.
What you'll learn
- Complex numbers and Euler's formula — rotation as the language of oscillation
- The Fourier transform — decomposing a signal into frequencies (DFT/FFT)
- Reading magnitude and phase from the spectrum
- The ML hooks — spectrograms, RoPE, and the convolution theorem
Before you start
The last lesson ended on a small piece of magic: switch a computation into log-space — a different representation — and an impossible product becomes a stable sum. Transform, do the easy thing, transform back. This lesson is that same trick at full power, applied not to a single number but to an entire signal.
It rests on one of the most useful ideas in all of applied math: any signal can be written as a sum of sine waves of different frequencies. The Fourier transform is the machine that switches between the two ways of describing that signal — the time domain (the wiggly wave you actually see) and the frequency domain (the list of which frequencies it is built from, and how much of each). Move freely between them and a surprising amount of ML input processing, plus a few architectural tricks, stops being mysterious.
Complex numbers: rotation in disguise
The natural language for oscillation is complex numbers. A complex number a + bi
(with i² = −1) is a point in a 2-D plane, and Euler’s formula is the key fact:
e^(iθ) = cos θ + i sin θ
That is a point on the unit circle at angle θ — so multiplying by e^(iθ) is a
rotation by θ. A complex exponential e^(i·2π·f·t) is therefore a point spinning
around the circle at frequency f: a sine and cosine bundled into one rotating object.
(If that sounds familiar, it’s exactly the mechanism behind
rotary positional embeddings — RoPE rotates query
and key vectors, which is Fourier thinking applied to attention.)
The transform: from a wave to its frequencies
The Fourier transform writes a signal as a sum of these rotating exponentials, one per
frequency, each with an amplitude. The discrete version (the DFT), computed
efficiently by the FFT in O(N log N), takes N samples of a signal and returns,
for each frequency, a complex number whose magnitude says how much of that
frequency is present and whose phase says where it sits. Hand it a signal that is
secretly two sine waves and it hands back exactly those two frequencies:
import numpy as np
fs = 64 # samples over one second
t = np.arange(fs) / fs
sig = np.sin(2*np.pi*3*t) + 0.5*np.sin(2*np.pi*7*t) # a 3 Hz tone + a softer 7 Hz tone
mag = np.abs(np.fft.rfft(sig)) / (fs/2) # amplitude per frequency
freqs = np.fft.rfftfreq(fs, 1/fs)
for f, m in zip(freqs, mag):
if m > 0.1:
print(f"freq {f:.0f} Hz -> magnitude {m:.2f}")
freq 3 Hz -> magnitude 1.00
freq 7 Hz -> magnitude 0.50
The transform reads the two sine waves straight out of the combined signal — magnitude
1.0 at 3 Hz and 0.5 at 7 Hz, exactly the amplitudes we mixed in.
Why ML cares
- Audio and speech. The standard input to a speech model isn’t the raw waveform but a spectrogram — a short-time Fourier transform showing how the frequency content changes over time. Fourier is the front door to audio ML.
- RoPE. Rotary positional embeddings rotate Q/K vectors by an angle proportional to position — complex-exponential rotation, the same math as Fourier (positional encodings).
- The convolution theorem. Convolution in the time domain equals multiplication in
the frequency domain. So a huge convolution can be done as
FFT → multiply → inverse FFT, far faster than the direct sum — which is how long-convolution architectures (S4, Hyena) and classic signal processing scale. - Spectral methods. Some models mix tokens with a Fourier transform instead of attention (FNet), and the frequency view explains why diffusion and image models tend to fill in low frequencies (coarse structure) before high frequencies (detail).
In one breath
- Any signal is a sum of sine waves; the Fourier transform moves between the time domain (the wave) and the frequency domain (its frequency recipe).
- Complex numbers are the language: Euler’s formula
e^(iθ) = cos θ + i sin θmakese^(i·2π·f·t)a point rotating at frequencyf(the same rotation idea as RoPE). - The DFT (computed by the FFT,
O(N log N)) returns, per frequency, a complex number whose magnitude = how much of that frequency and phase = its offset; it recovers the two sines (1.0 at 3 Hz, 0.5 at 7 Hz) from their sum. - ML hooks: spectrograms for audio, RoPE as complex rotation, the convolution theorem (FFT makes big/long convolutions fast — S4/Hyena), and spectral mixing/ coarse-to-fine generation.
- It’s a change of basis: transform, do the easy thing in the other domain, transform back.
Practice
Quick check
A question to carry forward
The Fourier transform made one quiet assumption: the signal lived on a tidy, regular line — sample 0, sample 1, sample 2, evenly spaced in time. Enormous amounts of real data flatly refuse to live like that. A social network, a molecule, a road map, a knowledge base, the citations between papers — these are not lines of samples but webs of connection, where what matters is not when a thing happened but what is linked to what.
So the course closes on the mathematics of connection itself. What is a graph, and how do you turn a tangle of nodes and edges into objects linear algebra can actually chew on — the adjacency and Laplacian matrices? And here is the thread that ties the whole chapter shut: the eigenvectors of that graph Laplacian turn out to generalise the Fourier basis from regular grids to arbitrary networks — the “graph Fourier transform” beneath graph neural networks. One last change of basis, on the most irregular data there is.