S7 · Lesson 27 · FFT algorithms
Decimation in time and in frequency, butterflies and bit reversal, operation counts, radix-4 and mixed-radix FFTs, the Goertzel algorithm and the chirp z-transform
Computing an N-point DFT straight from its definition takes N² complex multiplications: a million for N = 1024. Cooley and Tukey's 1965 algorithm, which Gauss had found and set aside in 1805, does it in about five thousand by splitting the transform in half again and again. C9 used the FFT; this lesson takes it apart: where the savings come from, why the data comes out in bit-reversed order, how other radices and lengths are handled, and when computing just a few bins directly with the Goertzel algorithm beats the FFT altogether.
- Real multiplications against transform length N (both axes logarithmic): a direct DFT of a real signal (about 2N²), a radix-2 FFT (2N log₂N, counting four real multiplications per complex one) and the Goertzel algorithm for K bins (about K(N + 2)).
- The FFT's advantage grows without limit: 205 times at N = 1024.
- When only a few bins are needed, Goertzel's line sits below the FFT's: for K bins it wins while K is less than about 2 log₂N.
Predict
A touch-tone decoder needs the strength of exactly 8 frequencies in each 205-sample block. Which is cheaper, a 256-point FFT or 8 Goertzel filters?
Eight Goertzel recursions over 205 samples cost about 8 × 207 = 1,656 real multiplications, and need no buffering or bit reversal. A 256-point FFT costs about 2 × 256 × 8 = 4,096 and computes 248 bins nobody wants. With K bins the Goertzel approach wins while K < 2 log₂N, here about 16.
Name it
Decimation in time
Split x[n] into even and odd samples:
where G and H are N/2-point DFTs. Each pair of outputs is a butterfly: one complex multiplication by the twiddle factor , one addition and one subtraction. Repeating the split gives stages of N/2 butterflies:
against N² for the direct DFT, a speedup of . In place, the input must be read in bit-reversed order (index 3 = 011 sits at 110 = 6 for N = 8). Decimation in frequency splits the outputs instead and takes natural-order input, bit-reversed output.
Other lengths
- Radix-4 butterflies combine two radix-2 stages and save about 25% of the multiplications; split-radix saves a bit more.
- Mixed-radix FFTs handle N = N₁N₂…; the prime-factor algorithm avoids twiddle factors when the factors are coprime.
- The chirp z-transform (Bluestein) computes any N, or samples of the z-transform along a spiral, by turning the DFT into a convolution done with power-of-two FFTs.
The Goertzel algorithm
One bin k of an N-point DFT, as a second-order recursion run over the block:
One real multiplication per input sample per bin, plus a few at the end. The bin for a tone f is k = round(fN/f_s).
Worked example
Count complex multiplications for a 1024-point DFT done directly and by radix-2 FFT.
Show the solution
- Direct DFT.
- Radix-2 FFT. There are 10 stages of 512 butterflies:
- Ratio. times fewer.
- Trivial twiddles. Some twiddles are ±1 or ±j and cost nothing, so real FFTs do a little better still.
Answer 1,048,576 complex multiplications directly and 5,120 by radix-2 FFT, 204.8 times fewer.
Worked example
A DTMF decoder uses N = 205 at 8 kHz. Which bin and coefficient does the 697 Hz row tone use?
Show the solution
- Bin.
- Coefficient.
- The 1209 Hz column tone. The same steps give k = 31 and 1.1631.
- Why 205. N = 205 is chosen so that all eight DTMF frequencies fall close to integer bins.
Answer bin 18, with coefficient 1.7033.
Worked example
Trace a 16-point radix-2 decimation-in-time FFT: where does input sample 3 sit in the bit-reversed order, how many stages and butterflies are there, and how many twiddle multiplications?
Show the solution
- Bit reversal. 3 is 0011 in four bits; reversed, it's 1100 = 12, so x[3] goes in position 12.
- Stages and butterflies. There are stages of 8 butterflies, 32 butterflies in all.
- Twiddle multiplications. Each butterfly has one twiddle multiplication: 32 in all, against 256 for the direct DFT.
- Nontrivial ones. Only 10 of the 32 are nontrivial, since and only swap or negate parts, which is why small FFTs are hand-optimized to skip the rest.
Answer x[3] sits in position 12; there are 4 stages of 8 butterflies (32 in all) and 32 twiddle multiplications, only 10 of them nontrivial.
Check
How many complex multiplications does a radix-2 FFT of length 512 need (counting every twiddle)?
Check
By what factor does the radix-2 FFT reduce the multiplications of a 512-point DFT?
Check
A Goertzel detector with N = 205 at 8 kHz looks for 852 Hz. Which bin k does it use?
Check
What coefficient does the Goertzel recursion use for bin 31 of a 205-point DFT?
Check
By the real-multiplication model, below how many bins K does Goertzel beat a radix-2 FFT of length 1024?
Check
How many butterfly stages does a radix-2 FFT of length 2048 have?
Check
A Goertzel detector looks for 1633 Hz with N = 256 at 8 kHz.
(a)
Which bin does it use?
(b)
What coefficient does its recursion use?
Check
A radix-2 FFT of length N is compared with K Goertzel detectors on the same block.
Step 1
How many real multiplications does the FFT need (four per complex one)?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
How many does Goertzel need for K bins?
Step 3
Below how many bins is Goertzel cheaper?
Explain why
Where does the FFT's saving come from?
A direct DFT computes each of the N outputs as a separate sum of N products, never reusing work. But the DFT's twiddle factors are powers of one root of unity, so the sums share structure: splitting the input into even and odd samples turns one N-point transform into two N/2-point transforms, whose results combine into all N outputs with only N/2 extra multiplications, since each half-size result is used twice, once with a plus sign and once with a minus. Repeating the split until the pieces are single samples gives log₂N stages of N/2 multiplications each, so the work grows like N log N instead of N². The saving is the reuse of each intermediate result in two outputs at every stage.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.