Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 38 ยท Spectral Analysis

Zero Padding, Resolution and Peak Interpolation

Understand what zero padding really does, how many samples you need to resolve two tones, and how parabolic interpolation locates a spectral peak between FFT bins.

Three questions come up whenever you read an FFT plot. Does padding with zeros improve the resolution? How long must the record be to separate two nearby tones? And how can I measure a frequency more precisely than the bin spacing? This lesson answers all three with experiments.

Zero padding does not add information

Appending zeros to a block before the FFT gives more output bins, spaced fs / N_fft apart. But the information in the signal has not changed. The padded transform is the same continuous spectrum, sampled on a finer grid (it is the DTFT of the windowed block evaluated at more points). The shape, including the main-lobe width, is fixed by the original block length.

The benefit is a smoother-looking curve and a more accurate reading of the peak location; the limit to separating two tones remains the main lobe width.

Python Padding refines the grid, not the lobe

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With nfft = 100 the peak reads 10 Hz (error 0.37 Hz). With more padding the reading approaches 10.37 Hz, but the measured -6 dB lobe width stays near 1 Hz once the grid is fine enough to show it (the 100-point grid is too coarse and reports 2 Hz).

How long a record do you need?

Two sinusoids at f1 and f2 are separable when their main lobes do not merge. For a rectangular window this needs roughly |f2 - f1| > fs / N, i.e. a record longer than 1 / |f2 - f1| seconds. Tapered windows widen the lobe (Hann needs about twice as long). More samples is the only way to add real resolution; zero padding cannot.

Python Resolving two close tones

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The rectangular window separates the tones at N = 200, as predicted. Hann also shows two peaks there, but they are pulled to wrong positions (97.5 and 107.5 Hz); it needs about twice as many samples (N = 400) for trustworthy positions. Note how a shorter record merges both into a single peak, and padding does not change that.

Reading a frequency between the bins

Even without resolving two tones, you can locate one tone very precisely. Because the main lobe of a windowed sinusoid is smooth, the peak bin and its two neighbors determine where the true maximum sits. Parabolic interpolation fits a parabola through the log-magnitudes at bins k-1, k, k+1:

delta = 0.5 (a - c) / (a - 2b + c), with a, b, c the dB values at k-1, k, k+1

and the frequency estimate is (k + delta) * fs / N. For a Hann window this typically gets within a few hundredths of a bin.

Python Parabolic peak interpolation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The raw bin reading can be off by up to half a bin (about 0.5 Hz here); interpolation reduces the error to a few hundredths of a hertz.

Other precision tricks

  • Phase-vocoder estimate: compare the phase of two overlapping frames; accurate to a tiny fraction of a bin.
  • Zoom FFT / chirp-Z transform (scipy.signal.czt): evaluate the spectrum on a fine grid over a narrow band only.
  • Quadratic interpolation on log-magnitude versus linear: log (dB) works better for Gaussian-like lobes; for the rectangular window use the sinc shape or a different estimator.
  • Averaging: for noisy signals, combine with Welch averaging.

Do not report a frequency to more digits than the signal supports. The Cramer-Rao bound shows that precision depends on the signal-to-noise ratio and the record length, not on the padding you chose.

A summary of the rules of thumb

  • Resolution = fs / N times the window's main-lobe factor (1 for rect, about 2 for Hann).
  • Grid spacing = fs / N_fft; padding sets this and nothing more.
  • Accuracy of a single peak can be far better than resolution, with interpolation.
  • Pick the window from windowing and leakage and the length from the closest pair of tones you must separate.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does zero padding change?

    Padding samples the underlying DTFT more densely. The main lobe width, and thus the resolution, is set by the original record length.
  2. 2. To separate tones 4 Hz apart with a rectangular window, you need a record longer than about

    Resolution is about 1/T, so tones 4 Hz apart need T of at least 1/4 = 0.25 s.
  3. 3. How does parabolic interpolation estimate a peak frequency?

    The three magnitudes (usually in dB) define a parabola whose vertex gives a fractional-bin offset.
  4. 4. Why does a Hann window need a longer record than a rectangular one to resolve two tones?

    Tapering widens the main lobe by about a factor of two, so the tones must be farther apart or the record longer.

Summary

  • Zero padding interpolates the spectrum; it does not improve resolution.
  • Resolution is set by record length and window: about fs / N for a rectangular window and roughly double for Hann.
  • Parabolic interpolation of the peak bins gives a precise frequency estimate for one tone.
  • Precision is limited by noise and record length, not by padding.

Next: Decimation and Aliasing