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).

Top: 4 cycles of a cosine in the record, repeated; the copy joins smoothly and the spectrum has one spike at 4 Hz of height 16. Bottom: 4.5 cycles; the tone would go on at −1 but the copy starts at +1, a jump at the seam, and the spectrum is spread over every bin with 9.78 and 10.60 at 4 and 5 Hz.
A whole number of cycles repeats smoothly: one bin. 4.5 cycles jump at the seam: every bin.

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 cycles16.00000 %
4.5 Hz, 4.5 cycles9.7810.601.139.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 nullhighest side lobefar side lobes
rectangular2 bins (±1)−13.2 dBfall slowly
Hann4 bins (±2)−31.5 dBfall fast
Hamming4 bins (±2)−41.8 dBstay between −42 and −44 dB
Three window spectra in dB from −8 to +8 bins. Rectangular: nulls at ±1 bin, first side lobe −13.2 dB. Hann: nulls at ±2 bins, side lobe −31.5 dB, falling fast. Hamming: nulls at ±2 bins, side lobe −41.8 dB, staying between −42 and −44 dB.
A narrower main lobe always comes with higher side lobes: pick the window for the job.

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.

Three input blocks of 8 samples each give output blocks of 10 samples at n = 0 to 9, 8 to 17 and 16 to 25. Each block's last 2 samples overlap the next block's first 2 and are added, for example y[8] = 8 + 5 = 13.
Each block's output is 2 samples longer than the block; the overlapping tails are added.

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.

On the mind map

Open the Geometric Algorithms mind mapGeometricAlgorithmsTransform matrices: multiply each vertex by a matrixTransform matricesCoordinate frames: same point, different framesCoordinate framesHulls and curves: cross products and lerpsHulls and curvesRendering: which pixel shows whatRenderingFourier and DCT: a signal as a sum of wavesFourier and DCTTriangulations: mesh a point setTriangulationsSegments and polygons: lines, crossings, regionsSegments and polygonsFourier series and FFTFourier series and FFTcircles add up; FFT is O(n log n)Z-Transform Poles and ZerosZ-Transform Poles and ZerosStable: every pole inside the unit circleFIR and IIR filtersFIR and IIR filtersFIR: taps, linear phase; IIR: feedback, poleDiscrete LTI systemsDiscrete LTI systemsy = x * h: flip, slide, multiply, addDFT Leakage and WindowsWhole cycles: one bin; else leakageJPEG DCTJPEG DCTcosine coefficients, round most to zeroSampling and aliasingSampling and aliasingabove fs/2 a wave folds into a slower aliasOpen the Geometric Algorithms mind mapGeometric Algorithmsa signal as a sum of wavesFourier and DCTFourier series and FFTFourier series and FFTcircles add up; FFT is O(n log n)Z-Transform Poles and ZerosZ-Transform Poles and ZerosStable: every pole inside the unit circleFIR and IIR filtersFIR and IIR filtersFIR: taps, linear phase; IIR: feedback, poleDiscrete LTI systemsDiscrete LTI systemsy = x * h: flip, slide, multiply, addDFT Leakage and WindowsWhole cycles: one bin; else leakageJPEG DCTJPEG DCTcosine coefficients, round most to zeroSampling and aliasingSampling and aliasingabove fs/2 a wave folds into a slower alias
This page on the Geometric Algorithms mind map · 32 pages in 7 branches · open it to see the whole map and test yourself in recall mode.