C9 · Lesson 24 · The discrete Fourier transform
A spectrum a computer can calculate
The DTFT is a function of a continuous frequency, so no computer can store it. The DFT takes N samples and returns N numbers: the DTFT at N equally spaced frequencies. It's what an FFT computes, what a spectrum analyzer shows, and the engine of fast convolution. Because it only ever sees N samples, it quietly treats the signal as repeating every N, and that assumption explains its surprises: tones that smear across several bins, convolutions that wrap around, and zero padding that makes a spectrum smoother without making it sharper.
- The dots are the N-point DFT magnitudes of a complex tone at "bin" , that is at frequency . The dashed curve is the tone's DTFT, which the DFT samples.
- With a whole number, the tone completes whole cycles in the window: one bin gets everything (height N) and the rest are exactly zero.
- Move between bins. The energy leaks into every bin, and the tallest drops to about 0.64 N halfway between: the scalloping loss.
Predict
A real cosine completes exactly 3 cycles in a 16-point window. How many of its 16 DFT values are nonzero?
Two: bins 3 and 13. A cosine is two complex exponentials, at and , and in the DFT the negative frequency shows up at bin 16 − 3 = 13. Each holds A·N/2.
Name it
The DFT
for k = 0 to N − 1. X[k] is the DTFT of the N samples at , which at sample rate is hertz: the bins are apart. X[0] is the sum of the samples, and for even N, X[N/2] is the alternating sum. Bins above N/2 are negative frequencies: for real x, .
A cosine of amplitude A exactly on bin gives (and the same at ). Off a bin, its energy leaks into all bins, and halfway between two bins the peak falls to of its on-bin height.
It assumes the signal repeats
The inverse DFT produces a sequence that repeats every N. So shifts are circular (what falls off the end comes back at the start), and multiplying DFTs gives circular convolution:
which equals linear convolution with its tail wrapped onto its start. To get the linear convolution of L and M samples, zero-pad both to at least L + M − 1 points.
Zero padding
Appending zeros before the DFT gives more bins, closer together: samples of the same DTFT, more finely spaced. It smooths the picture but doesn't separate two tones closer than about , where N is the number of real samples.
Worked example
A 1024-point DFT at 48 kHz. How far apart are its bins, and where does a 1 kHz tone fall?
Show the solution
- Bin spacing.
- Where 1 kHz falls. That's between bins 21 and 22, so it leaks, and its peak is somewhat below the on-bin height.
Answer the bins are 46.875 Hz apart, and 1 kHz falls at 21.33, between bins 21 and 22.
Worked example
Circularly convolve [1, 2, 3, 4] with [1, 1, 0, 0], and compare with the linear convolution.
Show the solution
- Linear convolution. It has five samples: [1, 3, 5, 7, 4].
- Wrap it for N = 4. The fifth sample, 4, wraps onto n = 0:
- Making them agree. Padding both to 5 points or more makes the two agree.
Answer the circular convolution is [5, 3, 5, 7], against the linear [1, 3, 5, 7, 4]: the last sample wraps onto the first.
Worked example
A 256-sample record at 8 kHz is zero-padded to 1024 points. What changes, and what doesn't?
Show the solution
- Bin spacing. The bins get closer: instead of 31.25 Hz, so peaks are drawn more smoothly and located more precisely.
- Resolution. The resolution doesn't change: two tones closer than about still merge, because the record is still 32 ms long.
- The rule. Padding interpolates the spectrum; only a longer record separates close tones.
Answer the bin spacing shrinks from 31.25 Hz to 7.8125 Hz, but the resolution stays about 31 Hz.
Check
A 256-point DFT is taken at 48000 Hz.
(a)
How far apart are the bins?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
At what (possibly fractional) bin number does 3000 Hz fall?
Check
A real cosine of amplitude 2 sits exactly on a bin of a 64-point DFT. How big is that bin?
Check
A real signal has a strong component in bin 3 of a 64-point DFT. Which other bin has the same magnitude?
Check
A 1000-sample signal is to be linearly convolved with a 64-tap filter using DFTs.
(a)
What is the smallest DFT length that avoids wrap-around?
(b)
What is the smallest power of two that works?
Check
x = [1, 3, 4, 1] is circularly convolved (N = 4) with h = [1, 1, 0, 0].
(a)
What is ?
(b)
What is ?
Check
A complex tone sits exactly halfway between two bins of a 64-point DFT. How tall is the nearest bin, as a fraction of the on-bin height N?
Check
A 256-sample recording is zero-padded to 4096 points before its DFT. What does that do?
Check
A 1024-point DFT runs at 8000 Hz.
(a)
How far apart are its bins?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
At what (fractional) bin does a 2500 Hz tone fall?
Check
Sequences of 100 and 20 samples are convolved by DFT.
(a)
How long is their linear convolution?
(b)
What is the smallest power-of-two DFT that avoids wraparound?
Explain why
Why does multiplying two DFTs give a circular convolution instead of the ordinary one?
The DFT only knows N samples and represents them with N harmonics of the window length, which are all periodic with period N. So everything it computes treats the signal as one period of an endlessly repeating sequence. Multiplying DFTs convolves those periodic versions, and the part of the true output that runs past sample N − 1 lands in the next period, which overlaps the start of this one: it wraps around. Padding with enough zeros makes the period longer than the true output, so nothing overlaps and circular and linear convolution agree.
Practice
Keep practicing
11 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.