The FFT: why it is fast
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
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.
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
اقرأ الدرس خطوة بخطوة
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,576Split 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 itSplit 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 splitsOne 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 additionsStage 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 multiplicationsStage 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 DFTStage 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]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)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 NIn 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)
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01How many complex multiplications does a direct DFT of N = 16 samples need?
Each of the 16 outputs needs 16 products, so 16 × 16 = 256. The radix-2 FFT needs (16/2)·log2 16 = 8 × 4 = 32.
02In an 8-point radix-2 FFT, which sample is loaded into position 3 of the bit-reversed input?
3 is 011 in binary; reversed it is 110 = 6. So position 3 holds x[6].
03A butterfly gets a = 2 and b = 1 − j with twiddle factor W = −j. What are its two outputs?
W·b = −j(1 − j) = −j + j² = −1 − j. Then a + W·b = 2 − 1 − j = 1 − j, and a − W·b = 2 + 1 + j = 3 + j.
04For N = 4096, about how many complex multiplications does the radix-2 FFT need?
(N/2)·log2 N = 2048 × 12 = 24,576, against N² = 16,777,216 for the direct DFT: about 683 times fewer.
05What does the FFT change compared with the DFT?
The FFT is not a different transform. It is a faster way to compute the very same DFT values, equal up to rounding error.
المسرد
- DFT
- The discrete Fourier transform: X[k] = Σ x[n]·W^(nk) turns N samples into N frequency values.
- FFT
- Fast Fourier transform: any algorithm that computes the DFT in about N·log N operations instead of N².
- Twiddle factor W^r
- A complex number on the unit circle, W^r = e^(−j2πr/N): a turn of r/N of a full circle.
- Butterfly
- The FFT's building block: from a and b it makes a + W·b and a − W·b with one multiplication and two additions.
- Decimation in time
- Splitting the input samples into even-indexed and odd-indexed halves, again and again.
- Bit-reversed order
- The input order of a radix-2 decimation-in-time FFT: position i holds the sample whose index is i with its binary digits reversed.
- Radix-2
- An FFT that splits by two at every stage, so N must be a power of 2; it has log2 N stages of N/2 butterflies.
الملاحظات والمصادر
- Counts are complex multiplications, the usual measure (Oppenheim and Schafer, ch. 9). They include the trivial ones by 1 and −j; real programs skip those, so they do even less work. The direct DFT also needs N(N−1) additions; the FFT needs N·log2 N.
- This is the radix-2 decimation-in-time FFT published by Cooley and Tukey in 1965. Gauss had found the same idea around 1805, unpublished in his lifetime. numpy.fft uses its own optimized FFT code, but the cost has the same N·log N shape.
- Every value in the figure is computed from the model: the pulse x = [1, 1, 1, 1, 0, 0, 0, 0], the butterflies, and the direct sum, which agree to rounding.
- MIT OpenCourseWare 6.341 Discrete-Time Signal Processing (A. V. Oppenheim): the DFT and the FFT algorithm
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed., ch. 9 (course text listed on MIT OCW 6.341 readings)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011)
- Cooley–Tukey FFT algorithm (Wikipedia): the 1965 paper, Gauss around 1805, X_k = E_k ± e^(−2πik/N)·O_k, bit reversal
- Fast Fourier transform (Wikipedia): O(n²) direct, O(n log n) FFT, (n/2)·log2 n multiplications for radix-2
- Butterfly diagram (Wikipedia): the size-2 DFT building block
- NumPy documentation: numpy.fft (definition A_k = Σ a_m·exp(−2πi·mk/n))
- NumPy documentation: numpy.fft.fft (most efficient when n is a power of 2)
اختبار يتاح بعد الخطوة الأخيرة.