1. Home
  2. Explore
  3. Computer Science
  4. Fast Fourier Transform

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Fast Fourier Transform

Fast Fourier Transform and Polynomial Multiplication

Polynomial representations and basic operations

A polynomial with nnn coefficients can be written as

A(x)=a0+a1x+a2x2+⋯+an−1xn−1=∑k=0n−1akxk.A(x)=a_0+a_1x+a_2x^2+\cdots+a_{n-1}x^{n-1} =\sum_{k=0}^{n-1}a_kx^k.A(x)=a0​+a1​x+a2​x2+⋯+an−1​xn−1=∑k=0n−1​ak​xk.

Its degree is at most n−1n-1n−1. The coefficients can also be viewed as a vector, (a0,a1,…,an−1)(a_0,a_1,\ldots,a_{n-1})(a0​,a1​,…,an−1​). This viewpoint is useful because many kinds of one-dimensional data, such as sampled audio, are naturally represented as sequences of numbers.

For the algorithms in these notes, the arithmetic-operation model assumes that adding or multiplying two real or complex numbers takes constant time.

Evaluation

Given a polynomial AAA and a value x0x_0x0​, evaluation computes A(x0)A(x_0)A(x0​). Horner’s rule rewrites the polynomial as

A(x)=a0+x(a1+x(a2+⋯+xan−1)).A(x)=a_0+x\bigl(a_1+x(a_2+\cdots+x a_{n-1})\bigr).A(x)=a0​+x(a1​+x(a2​+⋯+xan−1​)).

Evaluating this nested expression takes O(n)O(n)O(n) additions and multiplications. Equivalently, the powers of x0x_0x0​ can be generated successively: once x0kx_0^kx0k​ is known, x0k+1x_0^{k+1}x0k+1​ requires just one more multiplication.

Addition

For two polynomials

A(x)=∑k=0n−1akxkandB(x)=∑k=0n−1bkxk,A(x)=\sum_{k=0}^{n-1}a_kx^k \qquad\text{and}\qquad B(x)=\sum_{k=0}^{n-1}b_kx^k,A(x)=∑k=0n−1​ak​xkandB(x)=∑k=0n−1​bk​xk,

their sum is obtained by adding corresponding coefficients:

C(x)=A(x)+B(x),ck=ak+bk.C(x)=A(x)+B(x), \qquad c_k=a_k+b_k.C(x)=A(x)+B(x),ck​=ak​+bk​.

This takes O(n)O(n)O(n) time.

Multiplication

For a product C(x)=A(x)B(x)C(x)=A(x)B(x)C(x)=A(x)B(x), each coefficient collects all products whose powers add to the same exponent:

ck=∑j=0kajbk−j.c_k=\sum_{j=0}^{k}a_jb_{k-j}.ck​=∑j=0k​aj​bk−j​.

For example, the coefficient of x2x^2x2 is a0b2+a1b1+a2b0a_0b_2+a_1b_1+a_2b_0a0​b2​+a1​b1​+a2​b0​. Computing each coefficient this way takes quadratic time overall: naive polynomial multiplication takes O(n2)O(n^2)O(n2) arithmetic operations for two inputs of length nnn.

The key goal of the fast Fourier transform is to reduce this cost to O(nlog⁡n)O(n\log n)O(nlogn).


Polynomial multiplication and convolution

A polynomial’s coefficient vector can be treated as a numerical signal. Multiplying two polynomials then produces the same coefficient-summing pattern as a convolution.

For two sequences aaa and bbb, their convolution has entries

ck=∑jajbk−j,c_k=\sum_j a_jb_{k-j},ck​=∑j​aj​bk−j​,

where entries outside the sequences’ ranges are treated as zero. This is exactly the coefficient formula for polynomial multiplication.

Convolution is useful in signal and image processing:

  • In audio, a waveform can be convolved with a filter to smooth it or alter its frequency content.

  • In image processing, a small kernel can be applied at many positions. A Gaussian blur, for example, smooths an image and can create the appearance of an out-of-focus lens.

  • Similar operations occur in many other forms of digital signal processing.

Convolution can also be described as taking dot products between one vector and shifted versions of another. Depending on the indexing convention, this may require reversing one vector; boundary handling must also be specified. The essential operation is the same as polynomial multiplication.


Three ways to represent a polynomial

A polynomial can be represented in several forms. Each makes some operations easy and others less convenient.

Coefficient representation

The polynomial is stored as (a0,a1,…,an−1)(a_0,a_1,\ldots,a_{n-1})(a0​,a1​,…,an−1​).

  • Evaluation: O(n)O(n)O(n) using Horner’s rule.

  • Addition: O(n)O(n)O(n) by adding corresponding coefficients.

  • Multiplication: O(n2)O(n^2)O(n2) using the direct coefficient formula.

Root representation

Over the complex numbers, a degree-ddd polynomial can be represented by its leading coefficient and its ddd roots, counted with multiplicity:

A(x)=λ∏r=1d(x−ρr).A(x)=\lambda\prod_{r=1}^{d}(x-\rho_r).A(x)=λ∏r=1d​(x−ρr​).

This representation makes multiplication easy: the roots of the product are the combined root lists, and the leading coefficients are multiplied. Evaluation is also straightforward: multiply the factors (x−ρr)(x-\rho_r)(x−ρr​) and the leading coefficient.

However, addition is difficult in this representation. The roots of a sum are generally not obtained by simply combining the roots of the original polynomials. Moreover, there is no general formula in radicals for solving arbitrary polynomials of degree five or higher, so converting general coefficient data into exact roots cannot be done by a universal formula using only arithmetic operations and radicals.

Sample representation

A polynomial of degree at most n−1n-1n−1 is uniquely determined by its values at nnn distinct points. In this representation, the data are pairs

(xj,yj),A(xj)=yj,0≤j<n.(x_j,y_j), \qquad A(x_j)=y_j, \qquad 0\leq j<n.(xj​,yj​),A(xj​)=yj​,0≤j<n.

Distinct input points are essential. Given nnn distinct points, there is exactly one polynomial of degree at most n−1n-1n−1 that passes through the corresponding samples.

Samples make addition and multiplication easy when two polynomials are represented at the same points. If A(xj)=yjA(x_j)=y_jA(xj​)=yj​ and B(xj)=zjB(x_j)=z_jB(xj​)=zj​, then

(A+B)(xj)=yj+zjand(AB)(xj)=yjzj.(A+B)(x_j)=y_j+z_j \qquad\text{and}\qquad (AB)(x_j)=y_jz_j.(A+B)(xj​)=yj​+zj​and(AB)(xj​)=yj​zj​.

The difficulty is changing representations. Evaluating a coefficient vector at nnn arbitrary points by separately evaluating the polynomial at each point costs O(n2)O(n^2)O(n2). Recovering coefficients from samples is an interpolation problem; ordinary linear-algebra methods are also costly. The FFT achieves fast conversion for a carefully chosen set of sample points.


Evaluation as a matrix–vector product

Suppose A(x)=∑k=0n−1akxkA(x)=\sum_{k=0}^{n-1}a_kx^kA(x)=∑k=0n−1​ak​xk is to be evaluated at points x0,…,xn−1x_0,\ldots,x_{n-1}x0​,…,xn−1​. The output values yj=A(xj)y_j=A(x_j)yj​=A(xj​) satisfy

yj=∑k=0n−1akxjk.y_j=\sum_{k=0}^{n-1}a_kx_j^k.yj​=∑k=0n−1​ak​xjk​.

In matrix form,

y=Va,\mathbf{y}=V\mathbf{a},y=Va,

where a\mathbf{a}a is the coefficient vector, y\mathbf{y}y is the sample vector, and VVV is the Vandermonde matrix:

Vjk=xjk.V_{jk}=x_j^k.Vjk​=xjk​.

With arbitrary points, this matrix has n2n^2n2 entries, and forming the evaluations directly takes O(n2)O(n^2)O(n2) time. The crucial freedom is that the points xjx_jxj​ can be chosen. A special choice makes the transformation and its inverse much faster.


Complex roots of unity

The useful sample points are evenly spaced around the unit circle in the complex plane.

A complex number has the form u+ivu+ivu+iv, where i2=−1i^2=-1i2=−1. It can be viewed as the point (u,v)(u,v)(u,v) in the complex plane. A point on the unit circle can be written as

cos⁡θ+isin⁡θ=eiθ,\cos\theta+i\sin\theta=e^{i\theta},cosθ+isinθ=eiθ,

using Euler’s formula. Its magnitude is 111, and its angle is θ\thetaθ.

Let τ=2π\tau=2\piτ=2π. The nnnth roots of unity are

1,eiτ/n,ei2τ/n,…,ei(n−1)τ/n.1,e^{i\tau/n},e^{i2\tau/n},\ldots,e^{i(n-1)\tau/n}.1,eiτ/n,ei2τ/n,…,ei(n−1)τ/n.

Equivalently, set

ω=eiτ/n,ωj=eijτ/nfor 0≤j<n.\omega=e^{i\tau/n}, \qquad \omega^j=e^{ij\tau/n} \quad\text{for }0\leq j<n.ω=eiτ/n,ωj=eijτ/nfor 0≤j<n.

These points are evenly spaced around the unit circle, and each satisfies (ωj)n=1(\omega^j)^n=1(ωj)n=1.

A central geometric property is that squaring doubles a point’s angle:

(eiθ)2=ei2θ.(e^{i\theta})^2=e^{i2\theta}.(eiθ)2=ei2θ.

Thus, squaring the nnnth roots of unity maps them onto the (n/2)(n/2)(n/2)th roots of unity when nnn is even. Each resulting point has two preimages among the original roots. Repeated squaring therefore reduces the number of distinct points by a factor of two at each stage.


Divide and conquer using even and odd coefficients

Splitting a polynomial’s coefficient vector into its even and odd positions gives the decomposition

A(x)=Aeven(x2)+xAodd(x2),A(x)=A_{\mathrm{even}}(x^2)+xA_{\mathrm{odd}}(x^2),A(x)=Aeven​(x2)+xAodd​(x2),

where

Aeven(z)=∑ka2kzk,Aodd(z)=∑ka2k+1zk.A_{\mathrm{even}}(z)=\sum_k a_{2k}z^k, \qquad A_{\mathrm{odd}}(z)=\sum_k a_{2k+1}z^k.Aeven​(z)=∑k​a2k​zk,Aodd​(z)=∑k​a2k+1​zk.

Each of the two smaller polynomials has about half as many coefficients as AAA.

For any evaluation point xxx,

A(x)=Aeven(x2)+xAodd(x2).A(x)=A_{\mathrm{even}}(x^2)+xA_{\mathrm{odd}}(x^2).A(x)=Aeven​(x2)+xAodd​(x2).

This identity gives the divide-and-conquer structure:

  1. Divide: Separate the coefficients into even-indexed and odd-indexed subsequences.

  2. Conquer: Recursively evaluate both smaller polynomials at the squared points x2x^2x2.

  3. Combine: For each original point xxx, compute Aeven(x2)+xAodd(x2)A_{\mathrm{even}}(x^2)+xA_{\mathrm{odd}}(x^2)Aeven​(x2)+xAodd​(x2).

When the original points are the nnnth roots of unity, their squares form the (n/2)(n/2)(n/2)th roots of unity. Both recursive subproblems therefore need only about half as many points as the original problem.

For nnn a power of two, the running time satisfies

T(n)=2T(n2)+O(n).T(n)=2T\left(\frac{n}{2}\right)+O(n).T(n)=2T(2n​)+O(n).

The two recursive calls each handle about n/2n/2n/2 coefficients and points. Dividing the coefficients and combining the results each take linear time. The recurrence gives

T(n)=O(nlog⁡n).T(n)=O(n\log n).T(n)=O(nlogn).

This divide-and-conquer evaluation algorithm is the fast Fourier transform (FFT).


The discrete Fourier transform

The mathematical transformation computed by the FFT is the discrete Fourier transform (DFT). Given coefficients a0,…,an−1a_0,\ldots,a_{n-1}a0​,…,an−1​, it computes the polynomial’s values at the nnnth roots of unity:

A(ωj)=∑k=0n−1akωjk,0≤j<n.A(\omega^j)=\sum_{k=0}^{n-1}a_k\omega^{jk}, \qquad 0\leq j<n.A(ωj)=∑k=0n−1​ak​ωjk,0≤j<n.

In matrix form,

y=Va,Vjk=ωjk.\mathbf{y}=V\mathbf{a}, \qquad V_{jk}=\omega^{jk}.y=Va,Vjk​=ωjk.

The DFT is the transformation; the FFT is a fast algorithm for computing it. A direct matrix–vector multiplication takes O(n2)O(n^2)O(n2) time, while the FFT uses the even–odd recursion to take O(nlog⁡n)O(n\log n)O(nlogn) time.

The distinction matters: the FFT does not make every arbitrary polynomial evaluation problem fast. It makes evaluation at this specially structured set of roots of unity fast.


Inverse DFT and inverse FFT

To multiply polynomials efficiently, the coefficients must eventually be recovered from the transformed samples. The inverse transformation follows from the orthogonality of the roots of unity.

The complex conjugate of u+ivu+ivu+iv is u−ivu-ivu−iv. For a unit-circle point,

eiθ‾=e−iθ.\overline{e^{i\theta}}=e^{-i\theta}.eiθ=e−iθ.

Let V‾\overline{V}V denote the matrix obtained by taking the complex conjugate of every entry of VVV. Since VVV is symmetric, its conjugate is also its conjugate transpose. The matrix product satisfies

VV‾=nI,V\overline{V}=nI,VV=nI,

where III is the identity matrix.

To see why, consider the entry in row jjj and column kkk:

(VV‾)jk=∑m=0n−1ωjmω−mk=∑m=0n−1(ωj−k)m.(V\overline{V})_{jk} =\sum_{m=0}^{n-1}\omega^{jm}\omega^{-mk} =\sum_{m=0}^{n-1}\left(\omega^{j-k}\right)^m.(VV)jk​=∑m=0n−1​ωjmω−mk=∑m=0n−1​(ωj−k)m.
  • If j=kj=kj=k, every term is 111, so the sum is nnn.

  • If j≠kj\neq kj=k, the terms form a geometric series whose ratio is a nontrivial nnnth root of unity. The series sums to 000.

Therefore,

V−1=1nV‾.V^{-1}=\frac{1}{n}\overline{V}.V−1=n1​V.

The inverse DFT recovers the coefficients from the transformed values:

ak=1n∑j=0n−1yjω−jk.a_k=\frac{1}{n}\sum_{j=0}^{n-1}y_j\omega^{-jk}.ak​=n1​∑j=0n−1​yj​ω−jk.

It can be computed with the same FFT structure: use roots with the negative exponent, then divide every output by nnn. Applying the negative-exponent transform without this division produces nnn times the original vector.


Fast polynomial multiplication

To multiply two polynomials efficiently, both must be evaluated at the same roots of unity. Their values can then be multiplied point by point, and the inverse transform recovers the product’s coefficients.

A robust procedure is:

  1. Pad the inputs with zeros. If each input has nnn coefficients, their product can have up to 2n−12n-12n−1 coefficients. Choose a transform length N≥2n−1N\geq 2n-1N≥2n−1, usually the next power of two, and append zeros as needed.

  2. Transform each input. Compute the FFTs of the padded coefficient vectors.

  3. Multiply the transformed values. For each index jjj, set

    Yj=AjBj.Y_j=A_jB_j.Yj​=Aj​Bj​.
  4. Transform back. Apply the inverse FFT to the values YjY_jYj​ to obtain the product coefficients.

The padding is necessary because only NNN samples cannot, in general, uniquely determine a product with more than NNN coefficients. It also prevents the coefficients from wrapping around and being combined incorrectly in a cyclic convolution.

Each transform takes O(Nlog⁡N)O(N\log N)O(NlogN) time, pointwise multiplication takes O(N)O(N)O(N) time, and the result is therefore computed in

O(Nlog⁡N)=O(nlog⁡n)O(N\log N)=O(n\log n)O(NlogN)=O(nlogn)

time when NNN is chosen proportional to nnn. This improves on the direct O(n2)O(n^2)O(n2) coefficient-by-coefficient method.


Applications of Fourier transforms

A Fourier transform expresses a signal in terms of its frequency components rather than its values over time. For audio, the original vector contains measurements of the signal amplitude at successive time samples. After transformation, the vector describes the signal in frequency space.

A transformed entry is generally a complex number. Its magnitude indicates how much of the corresponding frequency is present; its angle, or phase, describes that component’s shift relative to the signal’s timing. A signal consisting of a single ideal frequency has energy concentrated at that frequency’s transformed entry, rather than spread across all entries.

This representation makes several operations convenient:

  • A high-pass filter removes low-frequency components by suppressing the corresponding transformed entries.

  • A low-pass filter removes high-frequency components.

  • After modifying the frequency components, the inverse transform converts the signal back to the time domain.

Fourier methods are also useful in image processing and other signal-processing tasks. Convolution with a kernel, such as a Gaussian blur, can be carried out efficiently using Fourier transforms, particularly for large data sets. FFT-based techniques are used in audio compression and processing, noise-cancelling systems, and many other applications.

The FFT’s practical importance comes from combining a fast algorithm with a useful representation: it converts data between time or coefficient space and frequency or sample space in O(nlog⁡n)O(n\log n)O(nlogn) time.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent