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

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" k0, that is at frequency 2πk0/N. The dashed curve is the tone's DTFT, which the DFT samples.
  • With k0 a whole number, the tone completes whole cycles in the window: one bin gets everything (height N) and the rest are exactly zero.
  • Move k0 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?

Name it

The DFT

X[k]=∑n=0N−1x[n]e−j2πkn/N,x[n]=1N∑k=0N−1X[k]ej2πkn/N

for k = 0 to N − 1. X[k] is the DTFT of the N samples at ωk=2πk/N, which at sample rate fs is kfs/N hertz: the bins are fs/N 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, X[N−k]=X[k]*.

A cosine of amplitude A exactly on bin k0 gives |X[k0]|=AN/2 (and the same at N−k0). Off a bin, its energy leaks into all bins, and halfway between two bins the peak falls to 2/π≈0.64 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:

yc[n]=∑k=0N−1x[k]h[(n−k)modN]

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 fs/N, 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
  1. Bin spacing. 48000/1024=46.875Hz
  2. Where 1 kHz falls. 1000×1024/48000=21.33 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
  1. Linear convolution. It has five samples: [1, 3, 5, 7, 4].
  2. Wrap it for N = 4. The fifth sample, 4, wraps onto n = 0: [1+4,3,5,7]=[5,3,5,7]
  3. 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
  1. Bin spacing. The bins get closer: 8000/1024=7.8125Hz instead of 31.25 Hz, so peaks are drawn more smoothly and located more precisely.
  2. Resolution. The resolution doesn't change: two tones closer than about 8000/256=31Hz still merge, because the record is still 32 ms long.
  3. 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 yc[0]?

(b)

What is yc[3]?

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?

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.