3. The Fast Fourier Transform

The algorithm that changed the world

Audio at CD quality runs at 44,100 samples per second. If you want to analyze the frequency content of a single second of audio using the Discrete Fourier Transform, that's a 44,100-point DFT — which requires about 2 billion multiply-add operations. Do this in real time and you need a computer capable of 2 billion floating-point operations every second, just for frequency analysis. In 1965, that was not something you had on your desk.

The Fast Fourier Transform (FFT) computes the exact same result as the DFT but requires only O(N log N) operations instead of O(N²). For N = 44,100, that's roughly 720,000 operations — a speedup of about 2,700×. For N = 1,048,576 (2²⁰ samples), the speedup exceeds 52,000×. The FFT didn't improve the DFT; it changed what was computationally possible. It is, without much debate, one of the most important algorithms ever discovered.

Why the DFT Is Slow

The DFT of N points is defined as:

The DFT Formula

X[k] = Σ x[n] · e^(-i·2π·k·n/N)    for k = 0, 1, ..., N-1
       n=0..N-1

For each output frequency bin k, you sum N complex products. There are N output bins. Total work: N × N = N² complex multiply-adds.

For N = 1024, that's 1,048,576 operations. For N = 65,536, that's over 4 billion. Each doubling of N quadruples the work. This scaling is what makes the naïve DFT impractical for real-world signal sizes.

The crucial observation is that the DFT formula involves a lot of redundant computation. The complex exponential e^(-i·2π·k·n/N) is periodic — many of the twiddle factor values repeat. The FFT exploits this structure systematically.

The Cooley-Tukey Insight

James Cooley and John Tukey published the FFT algorithm in 1965 (though it was independently discovered earlier by Gauss and rediscovered several times). The core idea is beautifully simple: split the DFT in half.

Given an N-point DFT (where N is even), split the input sequence into:

  • Even-indexed samples: x[0], x[2], x[4], ..., x[N-2]
  • Odd-indexed samples: x[1], x[3], x[5], ..., x[N-1]

The Cooley-Tukey Decomposition

X[k] = Σ x[2n] · e^(-i·2π·k·n/(N/2))
       n=0..N/2-1
     + e^(-i·2π·k/N) · Σ x[2n+1] · e^(-i·2π·k·n/(N/2))
                        n=0..N/2-1

X[k] = E[k] + W_N^k · O[k]

Where E[k] is the (N/2)-point DFT of the even samples, O[k] is the (N/2)-point DFT of the odd samples, and W_N^k = e^(-i·2π·k/N) is called the twiddle factor.

Both E[k] and O[k] are periodic with period N/2, so for k ≥ N/2:

X[k]       = E[k mod N/2] + W_N^k · O[k mod N/2]
X[k + N/2] = E[k mod N/2] - W_N^k · O[k mod N/2]

One N-point DFT becomes two (N/2)-point DFTs plus N/2 complex multiplications to combine them. Since each half-size DFT costs (N/2)² operations, the total is 2·(N/2)² + N/2 = N²/2 + N/2. Already nearly half the work.

The Recursive Payoff

The real power comes from applying this split recursively. Each (N/2)-point DFT splits into two (N/4)-point DFTs. Each of those splits again. If N is a power of 2, you keep splitting until you reach N = 1, where the DFT of a single point is just that point itself. The total number of levels is log₂N, and each level requires N/2 butterfly operations — giving the famous O(N log₂N) total.

The Butterfly Operation

The butterfly is the fundamental building block of the FFT. At each stage, pairs of values are combined using a twiddle factor. Given two complex values a and b, and twiddle factor W:

The Butterfly

Inputs:   a, b
Twiddle:  W = e^(-i·2π·k/N)

Outputs:
  a' = a + W·b
  b' = a - W·b

Two inputs produce two outputs. The two output values share the computation of W·b (computed once, reused twice with + and −). One butterfly costs 1 complex multiplication and 2 complex additions.

Diagram

Butterfly operation

a b a+Wb a−Wb W + −
A single butterfly operation. The crossing lines give the operation its name. W is the twiddle factor e^(−i·2πk/N). Both outputs reuse the single computation W·b.

Recursive FFT

The Cooley-Tukey algorithm has a clean recursive structure:

Recursive FFT Pseudocode

function FFT(x):
    N = length(x)
    if N == 1:
        return x

    // Split into even and odd
    even = FFT(x[0, 2, 4, ..., N-2])
    odd  = FFT(x[1, 3, 5, ..., N-1])

    // Combine with twiddle factors
    output = new array of length N
    for k = 0 to N/2 - 1:
        W = e^(-i·2π·k/N)
        output[k]       = even[k] + W · odd[k]
        output[k + N/2] = even[k] - W · odd[k]

    return output

The recursion bottoms out at N = 1. On the way back up, each level combines two half-size transforms using N/2 butterfly operations. There are log₂N levels, giving O(N log N) total.

The Full Butterfly Diagram

For N = 8, the FFT has log₂8 = 3 stages. Here is the complete data-flow diagram with all butterfly connections, showing how 8 inputs (in bit-reversed order on the left) produce 8 frequency-domain outputs on the right:

Diagram

N=8 FFT butterfly diagram

Stage 1 Stage 2 Stage 3 x[0] x[4] x[2] x[6] x[1] x[5] x[3] x[7] X[0] X[1] X[2] X[3] X[4] X[5] X[6] X[7] W⁰ W⁰ W⁰ W⁰ W⁰ W¹ W⁰ W¹ W⁰ W¹ W² W³
The complete N=8 FFT butterfly diagram. Teal: Stage 1 (stride 1). Orange: Stage 2 (stride 2). Red: Stage 3 (stride 4). Each stage performs N/2 = 4 butterflies. W^k = e^(−i·2πk/N) with N=8.

Every signal path flows strictly left to right. The three stages each double the "reach" of connections — Stage 1 connects adjacent pairs, Stage 2 skips one row, Stage 3 skips three rows. After all three stages, every output is a linear combination of all eight inputs.

Bit-Reversal Permutation

Notice that the inputs on the left side of the diagram are not in natural order (0, 1, 2, 3, 4, 5, 6, 7). They are in bit-reversed order. This is a necessary consequence of the even/odd splitting. Each level of the recursion separates even and odd indices — by the time the recursion bottoms out, the inputs have been permuted according to their index's bit-reversed value.

Bit-Reversal for N = 8 (3-bit indices)

Natural index Binary Bit-reversed Permuted index
0 000 000 0
1 001 100 4
2 010 010 2
3 011 110 6
4 100 001 1
5 101 101 5
6 110 011 3
7 111 111 7

Index 1 (binary 001) has bit-reversed binary 100 = 4. So input x[1] moves to position 4. Index 3 (binary 011) reverses to 110 = 6. Note that 0, 2, 5, and 7 map to themselves — they are palindromes in binary and need no swap.

To perform the permutation in-place: for each pair (i, j) where j = bitreverse(i) and j > i, swap x[i] and x[j].

Iterative FFT

The recursive formulation is elegant but carries function-call overhead and awkward memory layout. In practice, FFT implementations are iterative — they perform the stages in order on a bit-reversed input array:

Iterative Cooley-Tukey FFT

function FFT_iterative(x):
    N = length(x)

    // Step 1: Bit-reverse permutation
    bit_reverse_copy(x)

    // Step 2: Process log2(N) stages
    for s = 1 to log2(N):
        m = 2^s                  // butterfly span at this stage
        W_m = e^(-i·2π/m)       // base twiddle factor for stage

        for k = 0 to N-1 step m:
            W = 1                // accumulate W_m^j as j increases
            for j = 0 to m/2 - 1:
                t = W · x[k + j + m/2]
                u = x[k + j]
                x[k + j]       = u + t   // butterfly upper output
                x[k + j + m/2] = u - t   // butterfly lower output
                W = W · W_m              // next twiddle factor

The outer loop iterates over stages (s = 1 is the first stage, span = 2; s = log₂N is the last stage, span = N). The middle loop selects groups of butterflies at this stage. The inner loop performs m/2 butterflies within each group, accumulating the twiddle factor by multiplication (rather than recomputing the exponential each time).

In-Place Computation

Notice that in the iterative version, each butterfly writes its outputs back to the same two array locations it read from. The result overwrites the input. This means the FFT requires no extra memory beyond the input array itself (plus a handful of scalar temporaries). For large N, this is a significant practical advantage.

Operation Count

How much work does the FFT actually save? For a radix-2 FFT on N = 2^m points:

  • Stages: log₂N
  • Butterflies per stage: N/2
  • Total butterflies: (N/2) · log₂N
  • Each butterfly: 1 complex multiply + 2 complex additions

DFT vs FFT: Operation Comparison

N DFT: N² FFT: (N/2)·log₂N Speedup
8 64 12 5×
64 4,096 192 21×
1,024 1,048,576 5,120 205×
65,536 4,294,967,296 524,288 8,192×
Diagram

DFT vs FFT operation count

N=8 N=64 N=1024 N=65536 Operations (log scale) DFT (N²) FFT (N/2·log₂N)
Operation counts for DFT vs FFT on a log scale. The gap grows dramatically with N — at N=65,536 the FFT requires 8,192 times fewer operations.

Where the FFT Is Used

The FFT's O(N log N) complexity unlocked an enormous range of applications that were previously impractical:

  • Audio processing — real-time EQ, pitch detection, spectrum analysis, noise suppression
  • Image compression — JPEG uses the DCT, which can be computed via an FFT-like algorithm
  • Wireless communications — OFDM (used in 4G/5G, Wi-Fi, DVB) modulates hundreds of subcarriers simultaneously; the FFT demodulates them in one operation
  • Scientific computing — solving PDEs, convolution in O(N log N) instead of O(N²), radar signal processing
  • Polynomial multiplication — the FFT can multiply two N-degree polynomials in O(N log N), which underlies fast large-integer arithmetic (used in cryptography)

The connection to convolution is especially powerful: multiplying two spectra in the frequency domain corresponds to convolving their time-domain signals. Convolution naïvely costs O(N²), but via FFT it drops to O(N log N). This is how audio reverb, image blurring, and matched filters work in real time.

Key Takeaways

  • The DFT costs O(N²) — for N = 44,100 that's ~2 billion operations per transform, far too slow for real-time use
  • The Cooley-Tukey FFT splits the N-point DFT into two (N/2)-point DFTs and combines them with N/2 butterfly operations; applied recursively, total cost becomes O(N log N)
  • The butterfly operation is the fundamental unit: two inputs a, b with twiddle factor W produce a+Wb and a−Wb using one multiply and two additions
  • Inputs must be permuted into bit-reversed order before the iterative algorithm begins; this is a consequence of the even/odd splitting at each recursive level
  • The iterative version runs in-place — the N output values overwrite the N input values with no extra memory allocation
  • At N = 65,536 the FFT is over 8,000 times faster than the DFT; this speedup enabled real-time audio, modern wireless communications, and practical signal processing at scale

Try It Yourself — FFT Butterfly Visualizer

Watch the Cooley-Tukey algorithm work through each butterfly operation. Select an input size, choose a preset, then step through the stages one butterfly at a time or let it auto-play.


The FFT is a rare kind of discovery: an algorithm that doesn't just solve a problem faster but transforms what is possible. It turned frequency analysis from a batch computation into a real-time operation, made wireless communications at scale conceivable, and reduced convolution from an O(N²) bottleneck into a routine subroutine. Cooley and Tukey published it in ten pages in 1965. The algorithm they described — and the butterfly diagram that makes it visual — is still what runs inside every audio device, every radio, and every spectrum analyzer operating today.