Spectral Estimation, Windowing & Leakage
A spectrum computed from a finite noisy record is an estimate, not a direct view of an infinite signal. This entry derives leakage from time-domain truncation, compares window tradeoffs, distinguishes bin spacing from resolution, and gives reproducible periodogram and Welch workflows with correct units.
A finite record never reveals an infinite-duration spectrum directly. It reveals the spectrum of the signal after observation, sampling, detrending, windowing, and noise have altered it. Spectral estimation is the discipline of keeping those operations explicit so a peak, floor, or bandwidth has defensible units and resolution.
The central trade cannot be tuned away: concentrating a window in time spreads it in frequency. Narrow main lobes separate nearby tones; low sidelobes keep a strong tone from hiding a weak one. Averaging lowers estimator variance by spending time or frequency resolution.
Truncation creates leakage #
Recording samples is multiplication by a finite window . Multiplication in time becomes convolution in frequency:
A rectangular window is not neutral. Its transform is a Dirichlet kernel with a narrow main lobe and slowly decaying sidelobes. A sinusoid exactly at a DFT bin completes an integer number of cycles in the record and lands at orthogonal bins. Move it between bins and its energy spreads through the sampled window spectrum. That spread is spectral leakage, not new physical frequencies.
flowchart TB
subgraph PRE["Record conditioning"]
direction LR
R["Finite record"] --> D["Justified detrend"] --> W["Window"]
end
subgraph EST["Estimation and validation"]
direction LR
F["DFT / FFT"] --> S["Amplitude / power / PSD"] --> A["Average"] --> V["Validate units + resolution"]
end
W --> F
Bin spacing is not resolving power #
For sampling rate and segment length , DFT bins are spaced by
Actual ability to distinguish two components depends on the window's main-lobe width, component amplitudes and phases, noise, and decision rule. A common window can have a main lobe several bins wide. Two labelled bins therefore need not represent two resolvable tones.
Zero-padding changes the grid at which the same windowed transform is sampled. It improves interpolation of peak position and plots, but the main lobe retains the width set by observed duration and window. To gain physical resolution, observe longer or adopt a justified parametric model; do not count padded bins as evidence.
Window metrics express different costs #
No single number ranks windows. Four metrics answer different questions:
- main-lobe width: how close equal-strength components can be before they merge;
- peak sidelobe level: how far a strong component leaks into nearby bins;
- scalloping loss: worst amplitude loss when a tone lies between bins;
- equivalent noise bandwidth (ENBW): how much white-noise power one windowed bin integrates relative to an ideal rectangular bin.
For a sampled window,
is coherent gain, used to recover a bin-centred sinusoid's amplitude, while
is ENBW in hertz. Correcting amplitude with does not correct a PSD; correcting noise bandwidth does not restore an off-bin peak. They are distinct normalizations.
| Window | Main use | Cost to remember |
|---|---|---|
| Rectangular | coherent/bin-centred tones; maximum nominal resolution | high sidelobes, severe leakage |
| Hann | general-purpose PSD and unknown tone position | wider main lobe than rectangular |
| Blackman–Harris | reveal weak tones near strong tones | wider main lobe and larger ENBW |
| Flat-top | accurate amplitude for isolated tones | very wide main lobe and high noise bandwidth |
| Kaiser | tune sidelobe suppression versus width | parameter must be reported |
Window names are insufficient because periodic and symmetric definitions differ at the endpoint. Record the exact library, function, and parameters when results must reproduce.
Periodogram scaling #
Let have physical unit U and let be the unscaled DFT of . A two-sided density estimate is
with units U$^2$/Hz. For real input, a one-sided PSD doubles interior positive-frequency bins so integrated positive-frequency power still equals total mean square; DC and Nyquist are not doubled.
The consistency check is
after accounting for detrending and estimator conventions. If changing changes the integrated power of the same physical record solely because of scaling, the output is not a correctly normalized density.
scipy.signal.periodogram(..., scaling="density") implements PSD units; scaling="spectrum" gives squared-magnitude spectrum units. A plot labelled only “FFT amplitude” is not enough to compare different record lengths or sampling rates.
Welch trades resolution for repeatability #
The raw periodogram is asymptotically unbiased under useful conditions but remains a high-variance estimator: more samples create more frequency detail without making each unsmoothed bin settle tightly around the true PSD. Welch's method reduces variance by:
- splitting the record into overlapping segments;
- detrending and windowing each segment;
- computing one periodogram per segment;
- averaging the periodograms.
Shorter segments create more averages but broader main lobes and coarser grid spacing. Overlap reuses samples to avoid wasting the low-weight ends of tapered windows; it does not create independent data. The effective number of averages is smaller than the segment count because overlapping periodograms are correlated.
Welch is appropriate for a stationary noise-like process whose average power distribution matters. It can be misleading for a transient or changing tone: segment averaging smears time variation into one spectrum. A spectrogram keeps segment time, while multitaper or parametric methods may be better when their assumptions fit.
Worked choice: two close tones and a noise floor #
Suppose kHz, record length is 48,000 samples, and tones lie at 1,000 and 1,006 Hz. The full-record grid is 1 Hz. With a Hann window, the main lobe spans several bins; six-hertz separation is plausible to resolve at similar amplitudes, but a much weaker second tone can still sit under the first tone's skirt.
Now use Welch segments of 4,096 samples. Grid spacing becomes Hz before padding. The two tones cannot be resolved by that segmentation even if the plotted FFT is padded to 65,536 points. Welch may estimate the surrounding noise floor much more smoothly, but it has spent the duration needed to separate the tones.
A defensible analysis therefore produces two products if both questions matter:
- a long-record, low-sidelobe spectrum for tone separation and amplitude;
- a separately configured Welch PSD for stable broadband noise density.
One setting cannot optimize both.
Detrending and nonstationarity #
Removing the sample mean suppresses DC leakage caused by a constant offset. Removing a fitted linear trend can reduce low-frequency leakage, but it also removes real low-frequency content. Detrending is a model decision: “the baseline is nuisance” must be true for the measurement.
Before averaging, inspect the time record and a spectrogram. Clipping creates harmonics; gaps and timestamp jitter create modulation; changing operating states create multiple spectra; impulsive events raise a broadband floor. A stationary PSD is a poor summary when the data-generating state changes inside the record.
For a short-time Fourier transform,
where is hop size. Short windows localize changes in time but broaden frequency features; long windows do the opposite. This is the same uncertainty trade, exposed along two axes.
Measurement workflow #
- Protect acquisition. Verify anti-alias filtering, sampling-rate accuracy, timestamps, clipping margin, and analogue front-end bandwidth.
- Inspect time data. Locate states, transients, dropouts, saturation, and obvious periodicity.
- Name the quantity. Choose complex spectrum, sinusoid amplitude, power spectrum, or PSD before scaling.
- Choose duration from the required resolution. Make the segment long enough for the narrowest feature, including window main-lobe width.
- Choose a window from dynamic range. Strong-near-weak favors low sidelobes; isolated amplitude measurement favors flat-top; coherent sampling can justify rectangular.
- Choose averaging from variance. Report segment length, overlap, window, detrend, averaging rule, and confidence interval if decisions depend on the floor.
- Calibrate. Include sensor response, gain, units, and any antenna/microphone or cable correction.
- Cross-check invariants. Integrated PSD should match time-domain mean square; known injected tones should recover amplitude and frequency within the documented estimator bias.
Failure signatures #
| Symptom | Likely mechanism | Next check |
|---|---|---|
| broad symmetric skirt around one stable tone | finite-record leakage or phase noise | change window and duration independently |
| harmonics at integer multiples | clipping or another nonlinearity | time waveform and input attenuation |
| peaks mirrored or folded | aliasing or wrong frequency axis | analogue bandwidth and metadata |
| comb of equally spaced lines | periodic modulation, switching, or record discontinuity | spacing versus known clocks and segment boundaries |
| floor changes with segment length | per-bin power compared instead of PSD | units and ENBW normalization |
| peak moves when window changes | unresolved components or estimator bias | longer record and synthetic two-tone validation |
Spectral estimation is successful when another person can reconstruct not only the plot, but also what quantity each ordinate means and which alternatives the measurement could not distinguish.
Sources
- docsSciPy User Guide: Spectral Analysis
- docsSciPy: periodogram
- paperThe Use of Fast Fourier Transform for the Estimation of Power Spectra
- bookFundamentals of Information Processes 1: Collection, Transmission and Processing of Informationpdfnotes