ADCFFT1X16 = np.fft.rfft(x)2X64 = np.fft.rfft(x, n=64)3f = np.fft.rfftfreq(64, 1/fs)16 samples · 2 ms
016324863-2-1012n (sample number)x[n]THE RECORD x[n]N = 16 · 2 ms16 + 48 zerosN = 64 · 8 ms0500100015002000250000.250.50.75f (Hz)|X| / NSPECTRUM |X|/Nbins every 500 Hzbins every 125 Hzone hump · top 1139 Hzpeaks 1000 & 1250 Hzargmax: 1125 Hz
Coloured parts: what the current step is about; everything else rests in whiteBlocks: two tones, converter (ADC), the record tray (tall cells = samples, flat tiles = padded zeros), FFT chip, code cardPlots: the record x[n], and the spectrum |X(f)|/N: smooth DTFT curves with DFT bins as stemsZero tiles slide in, the write head records, the record flies into the FFT; the pill says what the tray holdsTwo tones 250 Hz apart, sampled at 8000 samples a second. Zero-padding 16 samples to 64 gives bins every 125 Hz on the same one-hump curve; 64 real samples split it into two peaks.

One short record

  1. Two tones, 1000 Hz and 1250 Hz, play together. A converter samples them 8000 times a second and keeps N = 16 samples: a record 2 ms long. Can its spectrum show two tones, only 250 Hz apart?

Zero-padding

Real resolution

In code

The working

# step 1/10 · record

x[n] = cos(2π·1000·n/fs) + cos(2π·1250·n/fs)
fs = 8000 samples per second
N  = 16 samples

record length = N / fs = 16 / 8000 s
              = 2 ms

the two tones are 1250 − 1000 = 250 Hz apart

Every number is computed from this model: two tones of amplitude 1 at 1000 Hz and 1250 Hz, sampled at 8000 samples a second. Heights are |X| divided by the number of real samples, so a tone that stands alone reads 0.5. The plot stops at 2500 Hz; above it, up to fs/2 = 4000 Hz, there is only small ripple. "About one main-lobe width, 2·fs/N" is the rectangular-window rule from J. O. Smith's Spectral Audio Signal Processing. It is a rule of thumb: tapered windows (the Windowing lesson) trade a wider lobe for lower side lobes.