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

A10 · Lesson 16 · The FFT in practice

What an FFT analyzer actually shows you

Press the FFT button on an oscilloscope and a spectrum appears: but it's not the Fourier transform from the last few lessons. It's computed from a finite record of samples, so it can only show frequencies on a grid, it smears a tone that falls between grid points, and its heights depend on how you scale it. Reading such a spectrum correctly, and computing one yourself with NumPy, means knowing three things: bin spacing, amplitude scaling, and leakage with the windows that tame it.

  • A 1 V tone near 1 kHz is analyzed from a 4 ms record with a rectangular window. The spectrum is in decibels.
  • Set the tone to exactly 1 kHz, then nudge it. As soon as it falls between the analyzer's grid points, energy spreads into a wide skirt.
  • That spreading is leakage. How far down is the skirt several bins away?

Predict

You sample at 8 kHz and take a 1024-point FFT. How far apart are the frequencies it can show?

Name it

Bins

An N-point FFT of samples taken at fs gives values at frequencies

fk=kfsN,k=0,1,…,N2

The spacing Δf=fsN=1T is set by the record length T. The highest frequency is fs/2, the Nyquist frequency. In NumPy, np.fft.rfft(x) returns the N2+1 values and np.fft.rfftfreq(N, 1/fs) their frequencies.

Scaling

A sine of amplitude A that lands exactly on a bin gives |Xk|=AN2, so the amplitude spectrum is 2|Xk|N. (The DC bin and the Nyquist bin aren't doubled.)

Leakage

A finite record is the infinite signal multiplied by a rectangular window, so the spectrum is convolved with a sinc. A tone exactly on a bin falls on the sinc's peak and lands on the other bins' zeros. A tone between bins spreads into all of them: its peak drops (by up to 3.9 dB, the "picket fence" loss) and its skirt falls only slowly, about −32 dB twenty bins away.

Windows

Multiplying the record by a smooth taper, such as the Hann window wn=12(1−cos⁡2πnN), kills the abrupt edges. The skirt drops to about −86 dB twenty bins away, and the worst peak loss to 1.4 dB, at the price of a main lobe twice as wide. Normalize by ∑wn instead of N to keep amplitudes right.

Worked example

A 3 V, 1 kHz tone is sampled at 8 kHz for 1024 points. Where is it in the FFT, and how big?

Show the solution
  1. Find the bin. k=1000×10248000=128 exactly.
  2. Its magnitude. 3×10242=1536
  3. Recover the amplitude. 2×15361024=3V

Answer it lands exactly in bin 128 with magnitude 1536, which scales back to 3 V.

Worked example

The tone moves to 1003.9 Hz, half a bin off. What do the rectangular and Hann spectra show?

Show the solution
  1. The rectangular window. The peak reads 1.92 V (down 3.9 dB), and the skirt 20 bins away is only 32 dB down.
  2. The Hann window. Normalized by ∑w, the peak reads 2.55 V (down 1.4 dB), and the skirt 20 bins away is 86 dB down.
  3. Compare. For measuring a weak tone near a strong one, the window makes the difference.

Answer the rectangular window reads 1.92 V with its skirt only 32 dB down 20 bins away; Hann reads 2.55 V with the skirt 86 dB down.

Check

What is the bin spacing of a 1024-point FFT at a sample rate of 8000 Hz?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

At which bin index does a tone at 2500 Hz fall, for a 1024-point FFT at 8000 Hz?

Check

A tone sits exactly on a bin of a 1024-point FFT, with |Xk| = 1536. What is its amplitude?

Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.

Check

How long a record do you need for a bin spacing of 0.5 Hz?

Write units the way you normally would: 1.5 s and 1500 ms are the same answer.

Check

What is the highest frequency an FFT of data sampled at 44100 Hz can show?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

Write spectrum(x, fs) returning (freqs, amps): the frequencies from np.fft.rfftfreq and the amplitudes 2|Xk|N from np.fft.rfft. Then a tone's amplitude and frequency can be read off the peak.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write hann_spectrum(x, fs): multiply by np.hanning(len(x)) before the FFT and normalize by 2/np.sum(w) instead of 2/N. The test compares leakage far from a tone that falls between bins.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a tone that falls between FFT bins spread into all the other bins?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.