ENع
←The FFT
Lesson 31 · From the DTFT to the FFT

The FFT: why it is fast

15 min10 steps5 questionsIntermediate
About this lesson

The DFT turns N samples into N frequency values, but done directly it costs N² multiplications. The fast Fourier transform (FFT) gets exactly the same answer with about (N/2)·log2 N. Follow one 8-sample pulse through the radix-2 FFT: split the samples into even and odd, keep splitting into bit-reversed order, then rebuild the spectrum with three stages of butterflies. Count the work (12 multiplications instead of 64) and see why the saving grows to about 205 times at N = 1024. It builds on the lessons on the DFT and on circular convolution, and uses complex numbers from the Maths course.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 31 · Interactive
01 / 10

The DFT, done directly

Our signal is a pulse of N = 8 samples. Each output X[k] multiplies all 8 samples by a twiddle factor W^(nk) and adds them up. Eight outputs × eight products = 64 multiplications.

X[k] = Σ x[n]·W^(nk),  n = 0 .. 7
W = e^(−j2π/8)  (a turn of 1/8 circle)

x = [1, 1, 1, 1, 0, 0, 0, 0]

one X[k]:   8 multiplications
8 outputs:  8 × 8 = 64

N samples cost N² multiplications.
N = 1024 -> 1,048,576
Loading figure…
or ← →
Read the lesson step by step
  1. The DFT, done directly

    Our signal is a pulse of N = 8 samples. Each output X[k] multiplies all 8 samples by a twiddle factor W^(nk) and adds them up. Eight outputs × eight products = 64 multiplications.

    X[k] = Σ x[n]·W^(nk),  n = 0 .. 7
    W = e^(−j2π/8)  (a turn of 1/8 circle)
    
    x = [1, 1, 1, 1, 0, 0, 0, 0]
    
    one X[k]:   8 multiplications
    8 outputs:  8 × 8 = 64
    
    N samples cost N² multiplications.
    N = 1024 -> 1,048,576
  2. Split into even and odd samples

    Sort the samples: the even ones x[0], x[2], x[4], x[6] go left, the odd ones go right. Each half has its own 4-point DFT, E[k] and O[k]. Then X[k] = E[k] + W^k·O[k].

    X[k]     = E[k] + W^k·O[k]
    X[k + 4] = E[k] − W^k·O[k]   (k = 0 .. 3)
    
    E = DFT of [x0, x2, x4, x6]
    O = DFT of [x1, x3, x5, x7]
    
    cost: 2 × 4² + 8 = 40
          (was 8² = 64)
    
    one split cuts the work from 64 to 40;
    for large N one split nearly halves it
  3. Split again: bit-reversed order

    Split each half the same way, and again, until each group holds one sample. A 1-point DFT is just the sample. The order 0, 4, 2, 6, 1, 5, 3, 7 is bit-reversed: 1 = 001 becomes 100 = 4.

    8 -> 4 + 4 -> 2+2+2+2 -> 1×8
    
    position  binary  reversed  sample
       0       000     000       x[0]
       1       001     100       x[4]
       2       010     010       x[2]
       3       011     110       x[6]
       4       100     001       x[1]
       5       101     101       x[5]
       6       110     011       x[3]
       7       111     111       x[7]
    
    log2 8 = 3 splits
  4. One butterfly

    The building block is the butterfly. It takes two numbers a and b, multiplies b by one twiddle factor W, and outputs a + W·b and a − W·b: one multiplication, two additions. Here a = 1, b = 0, W = 1.

    a ──┬──────► a + W·b
         ╲    ╱
          ╲  ╱    (the crossing lines
          ╱  ╲     look like wings)
         ╱    ╲
    b ─×W┴──────► a − W·b
    
    a = x[0] = 1,  b = x[4] = 0,  W = 1
    -> 1 + 0 = 1,  1 − 0 = 1
    
    1 multiplication, 2 additions
  5. Stage 1: four 2-point DFTs

    Stage 1 runs four butterflies on neighbouring pairs, all with W = 1. Each pair of samples becomes its own 2-point DFT. Every cell of the next row now holds 1.

    pairs (x0,x4) (x2,x6) (x1,x5) (x3,x7)
    W = W⁰ = 1 for all four
    
    1 ± 1·0 -> 1, 1
    1 ± 1·0 -> 1, 1
    1 ± 1·0 -> 1, 1
    1 ± 1·0 -> 1, 1
    
    row 1 = [1, 1, 1, 1, 1, 1, 1, 1]
    4 butterflies, 4 multiplications
  6. Stage 2: twiddle factors 1 and −j

    Stage 2 pairs cells two apart and joins the 2-point DFTs into 4-point DFTs. Now W changes: 1 for the first pair, W² = −j (a quarter turn) for the second. Complex numbers appear: 1 − j.

    pairs two apart: (0,2) (1,3) (4,6) (5,7)
    W⁰ = 1,  W² = e^(−jπ/2) = −j
    
    1 ± (1)·1 -> 2, 0
    1 ± (−j)·1 -> 1−j, 1+j
    1 ± (1)·1 -> 2, 0
    1 ± (−j)·1 -> 1−j, 1+j
    
    row 2 = [2, 1−j, 0, 1+j, 2, 1−j, 0, 1+j]
    each half is now a 4-point DFT
  7. Stage 3: the full 8-point DFT

    Stage 3 pairs cells four apart, with W⁰, W¹, W², W³. This is X[k] = E[k] ± W^k·O[k] from the split. W¹ = 0.71−0.71j, so X[1] = 1−2.41j.

    pairs four apart: (0,4) (1,5) (2,6) (3,7)
    W¹ = e^(−jπ/4) = 0.71−0.71j
    W³ = e^(−j3π/4) = −0.71−0.71j
    
    k=0: 2 ± W⁰·(2)
    k=1: 1−j ± W¹·(1−j)
    k=2: 0 ± W²·(0)
    k=3: 1+j ± W³·(1+j)
    
    X = [4, 1−2.41j, 0, 1−0.41j, 0, 1+0.41j, 0, 1+2.41j]
  8. The same answer as the direct DFT

    The bottom row holds X[k] in natural order, k = 0 to 7, exactly what the 64-multiplication sum gives. Its sizes |X[k]| are samples of the pulse's smooth DTFT, taken at ω = 2πk/8.

    k   X[k]        |X[k]|
    0   4           4
    1   1−2.41j     2.61
    2   0           0
    3   1−0.41j     1.08
    4   0           0
    5   1+0.41j     1.08
    6   0           0
    7   1+2.41j     2.61
    
    |X[1]| = √(1² + 2.41²) = 2.61
    same as the direct DFT (checked)
  9. Why it is fast: N/2 × log2 N

    3 stages × 4 butterflies = 12 multiplications instead of 64. In general (N/2)·log2 N instead of N². For N = 1024 that is 5,120 instead of 1,048,576: about 205 times fewer.

    stages      log2 N
    butterflies N/2 per stage
    mults       (N/2)·log2 N
    adds        N·log2 N
    
    N       direct N²     FFT (N/2)log2N
    8       64            12
    1024    1,048,576     5,120
    4096    16,777,216    24,576
    
    the gap grows with N
  10. In Python: numpy.fft.fft

    In Python, np.fft.fft(x) runs a fast algorithm like this one and returns the same eight X[k]. Its documentation says it is most efficient when N is a power of 2.

    typed at the Python prompt (>>>):
    
    >>> import numpy as np
    >>> x = [1,1,1,1,0,0,0,0]
    >>> X = np.fft.fft(x)
    >>> abs(X).round(2)
    array([4.  , 2.61, 0.  , 1.08, 0.  , 1.08, 0.  , 2.61])
    
    not on the card, to see X itself:
    >>> X.round(2)
    array([4.+0.j  , 1.-2.41j, 0.+0.j  , 1.-0.41j, 0.+0.j  , 1.+0.41j,
           0.+0.j  , 1.+2.41j])
    
    (Python 3 with numpy 2.4)

Quiz Unlocks after the last step.