A visual and mathematical journey through one of the most beautiful ideas in all of mathematics — decomposing any signal into its frequency components.
The Fourier transform is everywhere — in your phone's WiFi, in JPEG compression, in quantum mechanics. At its core it answers a deceptively simple question: what frequencies make up this signal?
The Core Idea
Any periodic signal can be written as a sum of sines and cosines:
The coefficients and tell us how much of each frequency is present. Computing them is the Fourier transform.
The complex exponential form is more elegant:
Each term in that sum is one pure tone. Before adding them up, here's a single one — drag the sliders and notice that no choice of frequency or amplitude ever turns it into anything but a sine. The transform asks the opposite question: given a shape, which tones?
Single frequency component
Interactive: Fourier Series Approximation
The pink wave below is a square wave — famously impossible to represent with a finite number of sines. Watch what happens as we add more harmonics:
Square wave via Fourier series
The ripples near the discontinuities that never quite go away are called Gibbs phenomenon. Even with infinite harmonics they persist — peaking at about 9% overshoot.
The Continuous Fourier Transform
Moving from discrete harmonics to a continuous spectrum, the Fourier transform of is:
And the inverse recovers from its spectrum:
This is profound: you can freely move between the time domain and frequency domain.
The Winding Machine: Why the Integral Works
That integral looks like it was handed down from on high. It isn't. You can see what it does in about ten seconds, and it's the most useful mental model of the Fourier transform there is.
Read the complex exponential as a clock hand: is a unit vector at angle , so it spins times per second. Then there are only three steps:
- Pick a frequency and spin a hand. One hand, rotating at turns per second.
- Multiply the signal by it. Each sample is a point on the real axis; multiplying by the hand rotates it by the hand's angle and stretches it to length . Do it for every in the window and the results trace a curve in the complex plane — the winding of at frequency .
- Average all the points. The average is the centre of mass of that curve, and it equals the integral up to a factor — the playground below uses this normalised version, which is why it reads for a unit sine instead of .
And here is the whole trick, in one line:
A full turn of the clock hand averages to nothing. So if has no component at , its winding is spread evenly around the origin — for every point at angle there's a matching one at — and everything cancels. If does contain , the hand turns at exactly the rate that keeps that component standing still, all of its contributions pile up on one side of the plane, and the centre of mass lands far from the origin. The distance from the origin is how much of is in the signal; the angle is the phase it starts at.
Formally, feed a Fourier series into the transform and it does the cancelling for you:
The kernel is exactly at , and exactly at every other frequency the window can resolve (, ). So on that grid the whole sum collapses to a single coefficient: . Between grid points you don't get zero, you get a sinc ripple — that's leakage, and it's the only reason a real spectrum ever looks smeared.
Every term except the one that matches averages away. The transform is not computing anything clever — it is a filter made of cancellation.
Play with it
Type any function of — the window is seconds, so is in cycles per second. Drag (or click the spectrum strip underneath) and watch. The left plot is the signal; the right is its winding. Grey is the whole window, bright is what has been wound so far, and the dashed wave is the reference clock hand, .
The winding machine
X(ξ) = (1/T) ∫₀ᵀ f(t) e−2πiξt dt
f(t) · dim = whole window · bright = wound so far · dashed = cos(2πξt)
f(t)e−2πiξt in the complex plane · dot = running average · ring = final average
|X(ξ)| for every ξ — click or drag to retarget the winding
ξ (Hz)
1.00
Re X(ξ)
0.000
Im X(ξ)
-0.499
|X(ξ)|
0.499
The winding is a closed loop whose centre sits away from the origin, and the pink dot settles exactly in it: the points all pull in the same direction, so they add up instead of cancelling. The length of that vector is how much of ξ lives in f(t); its angle is the phase the component starts at.
A few things worth trying:
- Type
sin(2*pi*t)and slide to . The winding is a circle with the average sitting dead centre in it, and the dot stops moving. Now slide to : the curve smears evenly around the origin and the dot collapses onto it. That's the difference between "present" and "absent", animated. - Switch to
sweep ξ. The winding frequency drives itself across the range, so the centre of mass erupts at the resonances and dies everywhere else. The trail it leaves is the spectrum drawn underneath. - Try
sign(sin(2*pi*t)). A square wave has energy at Hz and exactly nothing at the even ones — no matter how square it looks in the time domain. - Untick
snap to 1/Tand hunt between the peaks. The dot shrinks but never quite reaches the origin. That's leakage, and it's why windowing matters. (Trytorexp(-0.7*t)*sin(2*pi*2*t)for signals that never repeat at all — no frequency makes them stand still.)
A subtlety worth noticing: type sin(2*pi*t) and sit at . The centre of mass has length , not , because a real sine splits into two counter-rotating half-amplitude pieces at and — one of them is exactly the wave that gets stopped by the hand. So for a real signal, the amplitude of a component at is . You can check it in the readout: the playground shows both numbers.
Computing it in Python
The standard algorithm is the Fast Fourier Transform (FFT) — instead of the naive .
import numpy as np
import matplotlib.pyplot as plt
# Generate a noisy signal
t = np.linspace(0, 1, 1000, endpoint=False)
signal = np.sin(2 * np.pi * 50 * t) + 0.5 * np.sin(2 * np.pi * 120 * t)
signal += 0.2 * np.random.randn(len(t)) # add noise
# Compute the FFT
freqs = np.fft.fftfreq(len(t), d=t[1] - t[0])
spectrum = np.abs(np.fft.fft(signal))
# Plot only positive frequencies
pos = freqs > 0
plt.plot(freqs[pos], spectrum[pos])
plt.xlabel("Frequency (Hz)")
plt.ylabel("|X(f)|")
plt.title("Frequency Spectrum")
plt.show()The two peaks at 50 Hz and 120 Hz pop out clearly, even though the signal looked like noise in the time domain.
The Convolution Theorem
One of the Fourier transform's killer applications is convolution. In the time domain:
This is expensive — . But in the frequency domain it becomes pointwise multiplication:
This is why image blurring, audio filtering, and polynomial multiplication can all be done in .
def fast_convolve(f, g):
"""Convolve two signals using FFT — O(n log n)."""
n = len(f) + len(g) - 1
F = np.fft.rfft(f, n=n)
G = np.fft.rfft(g, n=n)
return np.fft.irfft(F * G, n=n)Beyond Signals: The Same Trick Everywhere
Everything above is one idea wearing different costumes: the transform is a change of basis that makes hard operations easy. Find the basis in which your problem is diagonal, and the hard part evaporates. Here are the three disguises it wears most often, and the places it turns up.
Polynomial multiplication is convolution
Take and and multiply them out:
Now look at the coefficient lists, and . The coefficient of in the product is
which is exactly the convolution of the two lists. So the school algorithm — multiply everything by everything and collect like terms — is a convolution, and it costs . For two polynomials with a million coefficients each that's multiplications; the FFT does the same job in about operations, five orders of magnitude cheaper.
The route is the familiar one, just read as algebra:
A polynomial of degree less than is completely determined by its values at distinct points, and evaluating at the special points , with , is precisely the DFT. Multiplication at those points is pointwise — no convolution at all — and the inverse DFT interpolates back to coefficients. In other words: the DFT is the change of basis in which convolution becomes an ordinary product. That is the convolution theorem seen from the polynomial side.
import numpy as np
def poly_mul(a, b):
"""Multiply polynomials given as coefficient lists, in O(n log n)."""
n = len(a) + len(b) - 1
size = 1 << (n - 1).bit_length() # next power of two >= n
A = np.fft.rfft(a, size)
B = np.fft.rfft(b, size)
return np.rint(np.fft.irfft(A * B, size)[:n]).astype(int)
poly_mul([1, 2, 3], [4, 5]) # -> array([ 4, 13, 22, 15])Floating-point FFTs round, so coefficients above about come back wrong. Real implementations either use an NTT — the same transform over a prime field, where roots of unity exist and nothing rounds — or pack the coefficients into one giant integer and multiply that.
That last option has a lovely one-line form, Kronecker substitution: write each coefficient list as a number in a base larger than any coefficient of the product.
# [1, 2, 3] and [4, 5] written in base 100
a, b = 30201, 504
q = a * b # 15221304
[q // 100**k % 100 for k in range(4)] # [4, 13, 22, 15]No digit ever carries into its neighbour, so one ordinary multiplication produces the whole convolution. This is not a curiosity: it is why the fastest libraries for huge numbers (GMP and friends) are, at bottom, doing polynomial multiplication with an FFT — and why Karatsuba, Schönhage–Strassen and the algorithms of Harvey and van der Hoeven are really statements about polynomials in disguise. It is also how a lot of cryptographic code spends its time.
The same evaluation picture powers Reed–Solomon codes: the message is a polynomial, the codeword is that polynomial evaluated at many points, and decoding is interpolation from the points that survive — the ones that disagree are the errors. Choosing those points as roots of unity makes encoding a DFT over a finite field, which is why QR codes, CDs, DSL lines and hard drives all contain a small piece of Fourier analysis.
Addition becomes multiplication
Why does any of this work? One identity:
Adding to the argument of the clock hand multiplies its value. That is the whole mechanism: a convolution sums a signal against shifted copies of something, and each shift contributes nothing but a phase factor, so in the frequency domain
Compare with logarithms, the other great operation-shuffler: logs turn multiplication into addition, the Fourier transform turns convolution into multiplication. Both work by moving to a representation where the expensive operation is free.
Shifts-into-phases is not a footnote — it is how you steer things:
- Delays and beamforming. Give each antenna in a phased array the right phase offset and their signals add up in only one direction: the beam points where the phases line up. Radar, 5G and ultrasound all work this way.
- Alignment and ranging. Cross-correlating a recording with itself at many lags finds the offset with the biggest response — audio/video sync, GPS timing, radar distance.
- Matched filtering. To find a known chirp buried in noise, multiply the received spectrum by the conjugate of the reference spectrum (a correlation, computed as one product) and look for the peak. That is how LIGO finds gravitational waves.
Differentiation becomes multiplication
The second identity is why the transform owns differential equations:
Differentiation is the most delicate operation in numerical analysis — finite differences lose accuracy and stiff systems force tiny time steps. But the exponentials are eigenfunctions of , so in the Fourier basis a derivative is a scalar multiply: no stencils, no truncation error, just a coefficient times . Two consequences:
- Solving PDEs. Turn the equation into algebra on the spectrum, divide, transform back. This is the spectral method behind weather and turbulence codes and fast Poisson solvers, and it converges exponentially fast for smooth solutions.
- Everything called "frequency response". Circuit impedance, control-system transfer functions, filter design, the Bode plot on an oscilloscope: all of it is "" applied to a linear system.
The same idea, in a table
| you want to… | in the natural domain | after transforming |
|---|---|---|
| filter a signal, blur an image | convolution, | multiply pointwise, |
| multiply polynomials or huge integers | convolve coefficients | multiply values |
| differentiate, solve a linear PDE | finite differences, stability limits | multiply by |
| delay by , steer a beam | shift the waveform | multiply by a phase |
| compare two signals | cross-correlation, | product with the conjugate |
| find hidden periods | try every candidate period | look for peaks in |
Hiding in plain sight
- Compression. JPEG cuts the image into blocks and discards the DCT coefficients — a real, cosine-only cousin of the Fourier transform — that quantize to zero; MP3 and Opus do the same with the MDCT. It works because energy piles up in a few frequencies, exactly the sparsity you saw in the square wave.
- Imaging. An MRI scanner measures Fourier coefficients of the body's spin density (k-space) and reconstructs with an inverse transform; a lens physically performs a 2D Fourier transform on the light passing through it; X-ray crystallography reads molecular structure off a diffraction pattern, which is a power spectrum.
- Physics. Position and momentum are Fourier transforms of each other, and the uncertainty principle is the time–bandwidth inequality of the transform you have been winding on screen. More generally, any linear system that behaves the same everywhere (translation invariant) is diagonal in the Fourier basis — which is why this particular transform, rather than some other, is the one nature keeps handing back.
- Probability. The characteristic function is a Fourier transform of the distribution. Sums of independent variables convolve densities, hence multiply characteristic functions — a one-line proof of the central limit theorem.
- Time series. Autocorrelation and the power spectrum are a Fourier pair (Wiener–Khinchin): the basis of pitch detection, vibration monitoring and pulsar timing. If you have read the piano tuning article, that is the same tool deciding whether two notes are in tune.
The pattern is always the same one: change basis, do the easy thing, change back. Sines are the basis in which shifts become phases, derivatives become multiplication and convolution becomes a product — which is a decent definition of why the Fourier transform is the most successful change of basis in applied mathematics.
Further Reading
- Stein & Shakarchi, Fourier Analysis: An Introduction
- 3Blue1Brown's visual explanation of the winding picture
- Cooley & Tukey, An algorithm for the machine calculation of complex Fourier series (1965)
- CLRS, Introduction to Algorithms, chapter 30 — the FFT and polynomial multiplication
- Harvey & van der Hoeven, Integer multiplication in time (2021)
Related Articles
Why Tuning a Piano is Mathematically Impossible
Perfect harmony is a mathematical impossibility. Here's the beautiful, maddening reason why — and how piano tuners have learned to live with it.
The Abelian Sandpile: A Group Hiding in a Pile of Sand
The Bak–Tang–Wiesenfeld sandpile model (ASM) is a deceptively simple cellular automaton that conceals a rich algebraic structure — an abelian group whose identity element is a non-trivial fractal-like configuration.
Automatic Differentiation
A deep-dive into automatic differentiation: symbolic vs. numerical vs. AD, AST transformation, dual numbers, tapes, hybrid methods, and a generic C++ implementation that computes gradients and solves optimisation problems.