The idea: the DFT sees one period of a repeating signal
The discrete Fourier transform (DFT) of N samples gives N numbers X[k], one per bin: X[k] = Σ x[n]·e−j2πkn/N. Bin k stands for the frequency k·fs/N, where fs is the sampling rate. The page uses fs = 32 Hz and N = 32, so the record lasts 1 s and the bins are 1 Hz apart. How the FFT computes these sums fast is on Fourier series and the FFT; this page is about what the numbers mean on real, finite records.
The key fact: the DFT only fits waves that make a whole number of cycles in the record. It treats the record as one period of a signal that repeats forever. If the tone ends where it started, the repeat is seamless. If not, the repeat has a jump at the seam, and a jump needs many frequencies to build (see how a square wave is built from sines on Fourier series, harmonic by harmonic).
Spectral leakage
The record x[n] = cos(2π·4·n/32) holds exactly 4 cycles. Its 32-point DFT is 16 at bin 4 (and its mirror, bin 28) and exactly 0 everywhere else (Demo 1). 16 = N/2: a cosine of amplitude 1 splits its energy between the bin and its mirror.
At 4.5 Hz the record holds 4.5 cycles. The tone would go on at −1, but the repeat starts again at +1. Now |X[4]| = 9.78 and |X[5]| = 10.60, and no bin is 0: even 0 Hz and 16 Hz get 1.00. 9.66 % of the energy sits more than 2 bins from the tone (Demo 2). This is spectral leakage. The energy is not lost: Parseval's rule Σ|x[n]|² = Σ|X[k]|²/N still holds; it is spread out.
The grey curve on row C explains it. The record's smooth spectrum (its DTFT, the same sum for every real frequency, not only whole bins) is a narrow peak with ripples on both sides. The DFT bins are samples of that curve. For 4 Hz the bins happen to sit on its zeros, all but one. For 4.5 Hz they sit on the ripples.
| record, rectangular window | |X[4]| | |X[5]| | |X[12]| | energy > 2 bins away |
|---|---|---|---|---|
| 4 Hz, 4 cycles | 16.00 | 0 | 0 | 0 % |
| 4.5 Hz, 4.5 cycles | 9.78 | 10.60 | 1.13 | 9.66 % |
Real signals almost never fit the record, so leakage is the normal case. A strong tone's skirt can hide a weak tone a few bins away.
Windows: taper the ends
A window w[n] multiplies the record before the DFT. It is near 1 in the middle and goes to (near) 0 at both ends, so the two sides of the seam meet near 0 and the jump is gone. The page uses the periodic forms, the usual choice for spectrum analysis:
- Rectangular (no window): w[n] = 1.
- Hann: w[n] = 0.5 − 0.5·cos(2πn/N), which starts at 0.
- Hamming: w[n] = 0.54 − 0.46·cos(2πn/N), which starts at 0.08.
With Hann on the 4.5 Hz record, the far bin |X[12]| drops from 1.13 to 0.0059, and the energy more than 2 bins away from 9.66 % to 0.084 % (Demo 3). There is a price. The peak drops to 6.79 (the window removed half the signal), and bins 3 and 6 grow to 1.35 and 1.36: the main lobe is wider.
A windowed tone's spectrum is the window's own spectrum, moved to the tone's frequency. So the whole trade-off is in the window's spectrum (Demo 4):
| window (N = 32) | main lobe, null to null | highest side lobe | far side lobes |
|---|---|---|---|
| rectangular | 2 bins (±1) | −13.2 dB | fall slowly |
| Hann | 4 bins (±2) | −31.5 dB | fall fast |
| Hamming | 4 bins (±2) | −41.8 dB | stay between −42 and −44 dB |
Use the rectangular window (no window) when tones are close and of similar strength, Hann for general analysis, Hamming when the nearest side lobe matters most. Windows also shape filters: cutting an ideal impulse response with a window is the window method of FIR design, on FIR and IIR filters.
Zero padding: a finer picture, not more detail
Zero padding appends zeros to the record before the DFT: 32 samples + 96 zeros give a 128-point DFT with bins 0.25 Hz apart (Demo 5). The new bins are more samples of the same grey curve. Every 4th padded bin equals an old bin (|X[16]| = 9.78 = old |X[4]|), and the in-between bins find the true peak, 16.00 at 4.5 Hz. The skirt does not change: padding does not remove leakage.
Frequency resolution is fs/N
The width of the main lobe is set by the length of the record, T = N/fs, not by the number of DFT points. The frequency resolution is about fs/N = 1/T: 1 Hz for a 1 s record. Take two tones 0.5 Hz apart, 4 Hz + 4.5 Hz (Demo 6). In a 1 s record their main lobes overlap. Padded to 128 points the spectrum is drawn finely, and it is one bump, peak 21.39 at 4.25 Hz, between the tones. Record 2 s instead (N = 64, bins 0.5 Hz apart): both tones make a whole number of cycles (8 and 9), and |X[8]| = |X[9]| = 32 with every other bin 0. More samples of the signal separate the tones; more zeros do not.
Resolution is a different limit from aliasing. Aliasing depends on fs, how often you sample (see sampling and aliasing); resolution depends on T, how long you listen.
Multiplying DFTs gives circular convolution
Convolution in time is multiplication of spectra, so a filter can run as DFT → multiply → inverse DFT. But the DFT believes every signal repeats, so the product gives circular convolution: the output also repeats every N samples, and whatever falls past the end wraps onto the start.
Take x = [1, 2, 3, 4, 5, 6, 7, 8] and h = [1, 1, 1, 0, 0, 0, 0, 0], both 8-point arrays (Demo 7). The linear convolution is [1, 3, 6, 9, 12, 15, 18, 21, 15, 8], 10 non-zero samples. With 8-point DFTs, the samples 15 and 8 at n = 8, 9 wrap to n = 0, 1: IDFT(X·H) = [16, 11, 6, 9, 12, 15, 18, 21]. Pad both arrays with zeros to at least 8 + 8 − 1 = 15 points and nothing wraps: the 15-point result is [1, 3, 6, 9, 12, 15, 18, 21, 15, 8, 0, 0, 0, 0, 0], the linear convolution. Linear convolution itself is on discrete-time LTI systems.
Overlap-add: long signals in blocks
A stream has no end, so it cannot go into one DFT. Overlap-add cuts it into blocks of B samples, convolves each block with h (M taps) through DFTs of at least B + M − 1 points, and adds the outputs where they overlap (Demo 8). With 24 samples, B = 8 and h = [1, 1, 1], each block gives 10 samples through a 16-point DFT. Block 1 covers n = 0…9, block 2 covers 8…17, so at n = 8 and 9 block 1's tail is added to block 2's head: y[8] = 8 + 5 = 13, y[9] = 6 + 8 = 14. The 26 summed samples equal the direct convolution of the whole signal.
For a long h this is much faster than the direct sum: with the FFT a block costs about N·log₂N operations instead of B·M. The poles and zeros behind a filter's frequency response are on the z-transform.
What the page leaves out
The page shows only magnitudes, never phase, and only one-sided spectra (0 to fs/2) of real signals. Other windows (Blackman, Kaiser, flat-top, Blackman-Harris), the symmetric window forms, scalloping-loss and noise-bandwidth figures, amplitude correction factors, and averaging many windowed blocks (Welch's method) are left out. So are overlap-save, the short-time Fourier transform and spectrograms, the FFT algorithm itself, and noise.