S727 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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?

Name it

Decimation in time

Split x[n] into even and odd samples:

X[k]=G[k]+WNkH[k],X[k+N/2]=G[k]−WNkH[k]

where G and H are N/2-point DFTs. Each pair of outputs is a butterfly: one complex multiplication by the twiddle factor WNk, one addition and one subtraction. Repeating the split gives log2⁡N stages of N/2 butterflies:

N2log2⁡N complex multiplications,Nlog2⁡N complex additions

against N² for the direct DFT, a speedup of 2N/log2⁡N. 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:

s[n]=x[n]+2cos⁡(2πkN)s[n−1]−s[n−2],|X[k]|2=s2[N−1]+s2[N−2]−2cos⁡(2πkN)s[N−1]s[N−2]

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
  1. Direct DFT. 10242=1048576
  2. Radix-2 FFT. There are 10 stages of 512 butterflies: 512×10=5120
  3. Ratio. 2Nlog2⁡N=204.8 times fewer.
  4. 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
  1. Bin. k=round(697×205/8000)=round(17.86)=18
  2. Coefficient. c=2cos⁡(2π×18/205)=1.7033
  3. The 1209 Hz column tone. The same steps give k = 31 and 1.1631.
  4. 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
  1. Bit reversal. 3 is 0011 in four bits; reversed, it's 1100 = 12, so x[3] goes in position 12.
  2. Stages and butterflies. There are log2⁡16=4 stages of 8 butterflies, 32 butterflies in all.
  3. Twiddle multiplications. Each butterfly has one twiddle multiplication: 32 in all, against 256 for the direct DFT.
  4. Nontrivial ones. Only 10 of the 32 are nontrivial, since W0=1 and W4=−j 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°.

Explain why

Where does the FFT's saving come from?

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.