Subscribe
AI
6 min read

What Is the Fourier Transform? The 1822 Math Behind Voice Models and Long Context

An 1822 book about heat flow produced the math that still runs every speech model's front end, every transformer's position encoding, and the convolutions state-space models race to replace.

What Is the Fourier Transform? The 1822 Math Behind Voice Models and Long Context

The most-used piece of mathematics in modern AI was invented to solve a problem nobody phones in about: how heat spreads through a metal rod. In 1807 a French prefect named Jean-Baptiste Joseph Fourier submitted a memoir to the Académie des Sciences claiming that an arbitrary function, even a jagged or broken one, could be written as a sum of smooth sine waves. He published the argument in book form in 1822 as the Théorie analytique de la chaleur, the Analytical Theory of Heat (MacTutor, Wikipedia).

Two centuries later, that idea is running inside your AI stack in three places you can point at: every speech model's front end, every transformer's position encoding, and every convolution that state-space models compute the fast way. This is an explainer of what the Fourier transform does and where it sits in the machinery of large language models.

What the transform actually does

The claim is simple. Take any signal that varies over time, a recording of a voice, a stock chart, the temperature along a rod. That signal can be rewritten as a sum of sine and cosine waves, each with its own frequency, amplitude, and phase. The Fourier transform is the procedure that finds those ingredients. Feed it a signal, get back a spectrum: a list that says how much of each frequency the signal contains.

The decomposition is lossless. Knowing the amplitudes and phases of all the component waves lets you rebuild the original exactly, which is the inverse transform. A waveform and its spectrum are the same object described in two coordinate systems, one indexed by time, one indexed by frequency.

A jagged waveform separating into three smooth sine waves of different frequencies

Why bother switching coordinate systems? Because operations that look hard in one look easy in the other. Convolving a signal with a filter, the operation at the heart of audio engineering and deep learning, is a long, expensive weighted sum in the time domain and a single multiplication at each frequency in the frequency domain.

The 1965 patch that made it usable

Fourier's original formulas describe a continuous signal. Computers see a finite list of samples, which needs the discrete Fourier transform (DFT). The DFT as written costs work proportional to the square of the number of samples: process twice as many, do roughly four times the arithmetic. For small N that is fine. For real-time audio and imaging it was close to hopeless.

In 1965 James Cooley and John Tukey published an algorithm that computes the same DFT with work proportional to N log N (Mathematics of Computation 19(90):297-301; original paper PDF). The trick is recursive: split the transform of N points into two transforms of N/2 points, combine them with a handful of multiplications, and repeat. The gain compounds with size. A million-sample signal that is impractical by direct DFT becomes ordinary. The fast Fourier transform (FFT) is what turned Fourier analysis from an analytical tool into something you can run continuously on a chip, and it underpins essentially all of digital signal processing since.

One historical footnote keeps the editors honest: the speedup is what made the transform practical, but the mathematics itself survived a priority fight. Fourier's contemporaries were skeptical. Biot objected to parts of his heat-transfer derivation, and Laplace and later Poisson shared the objections, according to the MacTutor biography. Fourier became permanent secretary of the Académie in 1822, the year it published his book.

Where it lives in your speech model

Text-only models can avoid the Fourier transform, but anything that hears runs it. The standard pipeline for speech recognition, established by Whisper, converts raw audio into an 80-channel log-mel spectrogram: audio resampled to 16,000 Hz, chopped into overlapping 25-millisecond windows with a 10-millisecond stride, and each window Fourier-analyzed into frequency magnitudes, reweighted onto the mel scale, which approximates how humans perceive pitch. The model never sees the waveform. It sees a frequency table, essentially an image made of sound, and the Fourier transform is the pixel maker.

A microphone radiating sound waves toward an abstract spectrogram grid of colored cells

The interesting development is that the newest generation of audio models claims to skip this step, and even they do not get away. Meta's EnCodec, a high-fidelity neural audio codec, encodes raw waveforms with a learned encoder-decoder rather than a hand-written spectrogram front end. But its abstract is explicit that training relies on a multiscale spectrogram discriminator, a critic that judges reconstructed audio by comparing frequency-domain representations at several window sizes. The Fourier transform demoted from preprocessor to referee. It still runs.

Where it lives in the transformer

This is the placement most LLM readers will find surprising. In the original attention paper, Vaswani and colleagues did not learn position embeddings at first. They used fixed sinusoids: each position in the sequence is encoded by a vector whose coordinates are sine and cosine functions of that position, and the wavelengths of the different coordinate pairs form a geometric progression running from 2pi up to 10,000 2*pi. A bank of sines at exponentially spaced frequencies is, in every meaningful sense, a Fourier basis. The transformer knows where a token sits by reading out which phase of each frequency it matches, the same logic the transform uses to read which frequencies sit inside a sound.

RoPE, rotary position embedding, the scheme almost every current open model uses, sharpens the Fourier connection. RoPE treats each pair of query and key components as a point on the plane and rotates it by an angle proportional to the token position, each pair rotating at its own frequency. The attention score between two tokens then depends on their relative position, because the product of two rotations at different frequencies differs exactly by the frequency response at the distance between them. When YaRN extends a pretrained model's context window, it does so by rescaling precisely these frequencies, interpolating some wavelength bands and extrapolating others. Long-context tricks are Fourier tuning under another name.

Where it lives in the convolution

State-space models sell themselves on an efficiency claim that is borrowed wholesale from the frequency domain. A convolution, the operation at the core of every CNN and of the S4 family of sequence models, is a slow weighted sliding sum in the time domain and a fast elementwise product in the Fourier domain: transform the input, transform the kernel, multiply, invert. The S4 paper computes whole sequence convolutions this way, via FFTs, and Mamba describes the same recipe, FFT forward, multiply in the frequency domain, FFT back, as the primitive its selective version has to beat. Mamba's whole design point is that once the kernel changes per input step, the frequency-domain shortcut stops applying, and the winning architecture is the one that replaces it with a hardware-efficient scan. The Fourier transform sets the baseline these models are measured against.

What to take from it

Three lessons, none of them hype. First, the boundary between "language model" and "signal processor" is a matter of front ends: a model that hears is a Fourier transform wearing a transformer. Second, position in a transformer was always a frequency problem; the arguments inside RoPE and its many context-extension successors are sine tables that Fourier wrote down first. Third, the 1822 decomposition and the 1965 algorithm that made it cheap are a reminder that some infrastructure never ages. The heat equation is not going to be deprecated in a model release.

Sources

AILLMeducational