Fast Fourier Transform


Fast Fourier Transform

Anna
Welcome. Today we’re unpacking the fast Fourier transform, or FFT: a divide-and-conquer algorithm that makes polynomial multiplication dramatically faster. It also turns out to be central to digital signal processing, including audio and image applications.

Michael
The lecture’s starting point is a polynomial written with n coefficients: a zero plus a one x, plus a two x squared, and so on through a n minus one times x to the n minus one. So its degree is n minus one. We’ll also treat those coefficients as a vector, which is useful because sampled audio, for example, is itself a sequence of real numbers.

Anna
And the variable x isn’t always the main thing we care about. A vector of coefficients can represent a one-dimensional data sequence, such as microphone measurements over time. Thinking of that sequence as a polynomial gives us an algebraic tool for working with it.

Michael
There are three operations to keep in view: evaluate a polynomial at a point, add two polynomials, and multiply two polynomials. Evaluation means we’re given a particular value, x zero, and want to find a of x zero. What’s the straightforward way to do that?

Anna
Compute the powers of x zero one after another. Once you know x zero to the k, one multiplication gives you x zero to the k plus one. Then multiply each power by its corresponding coefficient and add them up. That takes a number of arithmetic operations proportional to n.

Michael
Horner’s rule writes the same calculation in a nested form: a zero plus x times the quantity a one plus x times the quantity a two, and so on. It’s another way to get linear-time evaluation. For this lecture’s model, addition and multiplication of two numbers each count as one operation.

Anna
Adding polynomials is also linear time. If c of x equals a of x plus b of x, then each coefficient c k is just a k plus b k. We add corresponding entries in the two coefficient vectors.

Michael
Multiplication is the challenge. The coefficient of x to the k in the product is the sum, from j equals zero through k, of a j times b sub k minus j. In other words, all pairs of terms whose powers add to k contribute to that coefficient.

Anna
So computing one coefficient can take on the order of k operations. Doing that for every coefficient gives a quadratic-time method. The goal is to do better: about n log n operations rather than n squared.

Michael
Polynomial multiplication is closely related to convolution, an operation on vectors. Imagine sliding one vector across another and taking a dot product at each shift. Those dot products combine entries in the same pattern as the polynomial multiplication formula, with a reversal of one vector and some boundary details.

Anna
That connection is useful because convolution appears in audio processing and image editing. For instance, applying a Gaussian blur to an image is a kind of convolution. A direct method can look like it does quadratic work, but the FFT lets us compute the needed results in n log n time.

Michael
The key idea is to switch how we represent a polynomial. One representation is its coefficient vector. Another is a list of its roots, with multiplicities and a constant multiplier. And a third is a set of sample points: distinct x values together with the polynomial’s value at each one.

Anna
For a degree n minus one polynomial, n samples at distinct points uniquely determine the polynomial. The coefficient representation is convenient for addition, and roots make multiplication simple: multiply two polynomials by combining their root lists, while accounting for their constant factors.

Michael
But roots are a poor general-purpose representation. Even converting coefficients to roots can’t be done using just the usual arithmetic operations and radicals for every polynomial: the lecture notes that there’s no general quintic formula. Addition is also awkward in root form, because the roots of a sum don’t follow simply from the roots of the inputs.

Anna
Samples have the opposite strengths. If we already know a and b at the same points, then the samples of their sum or product are easy: add or multiply the corresponding values. The trouble is converting between coefficients and samples efficiently.

Michael
With arbitrary sample points, evaluating a polynomial at n points takes n linear-time evaluations, or n squared time overall. In matrix form, that’s a Vandermonde matrix times the coefficient vector. Going backward means solving the corresponding linear system, which is also not the fast route we need.

Anna
So the strategy is to choose special sample points. If we can convert from coefficients to samples quickly, multiply the sample values point by point, and then convert back just as quickly, we’ll have a fast polynomial multiplication algorithm.

Michael
Before choosing the points, let’s build the divide-and-conquer idea. Split the coefficients into the even-indexed ones and the odd-indexed ones. Call the resulting polynomials a even and a odd. Each has about half as many coefficients as the original.

Anna
The algebra explains why that split helps. The even terms of a of x are a even of x squared, because an even-indexed term has the form a sub 2k times x to the 2k. The odd terms are x times a odd of x squared. So a of x equals a even of x squared plus x times a odd of x squared.

Michael
That identity gives us the combine step. To evaluate a at a collection of x values, recursively evaluate a even and a odd at the squares of those values. For each original x, combine the two results with one multiplication and one addition.

Anna
The recurrence has two variables: n, the number of coefficients, and the size of the set of points we need to evaluate at. Each recursive call halves the number of coefficients, but initially the squared-point set might not get any smaller.

Michael
If the point set stays the same size, then every level still has work proportional to that original size. There are about log n levels, but the number of recursive calls doubles each level, leading to quadratic total work. We need the squaring operation to shrink the set of points by half.

Anna
Here’s the surprising part: use complex numbers. The points we want are roots of unity, which lie evenly spaced around the unit circle in the complex plane. The n-th roots of unity are the numbers e to the i times k tau over n, for k from zero to n minus one, where tau is a full circle, or two pi.

Michael
Euler’s formula says e to the i theta equals cosine theta plus i sine theta. So those exponential expressions describe points on the unit circle at evenly spaced angles. Squaring one doubles its angle, because e to the i theta squared is e to the i two theta.

Anna
That angle-doubling behavior is exactly what the recursion needs. When n is a power of two, squaring the n-th roots of unity maps them onto the n over two-th roots of unity: pairs of points collapse to the same squared point. Repeating that, the set size halves at every recursive level.

Michael
So with these points, both the coefficient count and the point-set size shrink by half in the recursive calls. The recurrence becomes T of n equals two times T of n over two plus a linear amount of work. That’s the familiar divide-and-conquer recurrence, and it solves to n log n.

Anna
If n isn’t already a power of two, the lecture suggests rounding up to the next power of two, which increases the size by at most a factor of two. The important choice is that the sample points are the n-th roots of unity, not arbitrary points such as the integers.

Michael
The mathematical transformation from coefficients to samples at those roots of unity is called the discrete Fourier transform, or DFT. The fast Fourier transform is the divide-and-conquer algorithm that computes that transformation in n log n time.

Anna
In matrix language, the DFT is a Vandermonde matrix times the coefficient vector. Its entries have the form e to the i times j k tau over n. The FFT computes that matrix-vector product quickly by using the even-odd recursion we just described.

Michael
Now we can multiply polynomials. Transform both coefficient vectors into sample vectors using the FFT. At every root of unity, multiply the sample of a by the sample of b. Those pointwise products are the samples of the product polynomial.

Anna
Then we need to transform those product samples back into coefficients. That’s the inverse DFT. The nice result is that it uses almost exactly the same algorithm: change the sign in the exponent and divide the final values by n.

Michael
Why does that work? If V is the DFT matrix, its inverse is its complex conjugate divided by n. Complex conjugation changes a plus i b into a minus i b; geometrically, it reflects a point across the real axis, which changes the angle’s sign.

Anna
The lecture verifies the matrix identity by multiplying V by its complex conjugate. The entry in row j and column k is a sum over m of exponential terms, which simplifies to a geometric series involving j minus k.

Michael
On the diagonal, j equals k, so every term in that sum is one. There are n terms, giving n. Off the diagonal, the terms form a geometric series whose numerator is zero, because the relevant exponential raised to the n-th power is one. So the product is n on the diagonal and zero elsewhere: n times the identity matrix.

Anna
That proves the inverse formula. The inverse FFT applies the transform with negative exponents and then divides by n. Put the whole multiplication together and we use two forward FFTs, pointwise multiplication, and one inverse FFT.

Michael
The transforms take n log n time, and the pointwise multiplication takes linear time, so polynomial multiplication runs in n log n time. Since convolution has the same coefficient-combination structure, this also gives a fast way to compute convolution.

Anna
And that’s not just a polynomial trick. In digital audio, the original samples describe a waveform over time. A Fourier transform represents the signal in terms of frequencies instead: each position corresponds to a frequency, and its complex value indicates how much of that frequency is present and how it is shifted in time.

Michael
For a pure tone, the frequency representation has a contribution at its frequency and zeros at the others, with the phase reflected in the complex value. More generally, converting to frequency space makes certain audio operations easier.

Anna
For example, a high-pass filter removes high frequencies, while a low-pass filter removes low frequencies. In frequency space, you can zero out the parts you want to remove and then transform back. The lecture mentions audio editors, MP3 processing, and noise-cancelling headsets as examples of FFT applications.

Michael
The same broad idea appears in image processing, including Gaussian blur, and in many other settings involving signals. The naming convention can vary: the lecture describes the time-to-frequency operation using its chosen transform convention and notes that it is usually called the Fourier transform.

Anna
So the central lesson is a change of representation. Coefficients make addition easy; samples make multiplication easy; and carefully chosen roots of unity let us move between those representations quickly. The FFT is the divide-and-conquer engine that makes that change efficient.

Michael
And once you recognize the even-odd split, the angle-doubling behavior of complex roots of unity, and the inverse transform, the apparent magic has a clear structure: each level does linear work, there are logarithmically many levels, and that’s how n log n replaces n squared.

Ask anything
We've read this whole study set, so questions about it get the best answers.