Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 38 ยท Spectral Analysis

The Periodogram and Welch's Method

Estimate the power spectral density of noisy signals with the periodogram and Welch's averaged method, and learn how segment length trades variance for resolution.

The FFT of a recorded signal gives a spectrum, but for noisy signals that spectrum is itself noisy. A single random recording produces a jagged estimate that does not get smoother as you record longer. The fix is to average, and the standard way to do it is Welch's method. This lesson defines the power spectral density (PSD), shows why the plain periodogram is a poor estimator, and demonstrates how Welch's method improves it.

Power spectral density

For a random signal, the interesting question is how its power is distributed across frequency. The PSD S(f) is measured in units of power per hertz (for example Vยฒ/Hz). Integrating it over a band gives the power in that band, and over all frequencies gives the total power (the variance, for zero-mean signals).

The simplest estimator is the periodogram: S(f) = |X(f)|ยฒ / (fs N) for a window-free block. With a window w, normalize by fs * sum(w**2) instead.

The periodogram is noisy

For white noise with variance sigmaยฒ, the true PSD is flat at sigmaยฒ / (fs/2) per one-sided Hz, but any single periodogram fluctuates strongly around it: the standard deviation of each bin is about as large as its mean, and this does not shrink with N. Longer records give more bins, not better bins.

Python Periodogram of white noise

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 mean is right, but the relative spread stays near 1 for every N. The periodogram is unbiased but not consistent.

Welch's idea

Split the record into overlapping segments, window each one, compute its periodogram and average them. Averaging K independent estimates reduces the variance by roughly K. With a Hann window the overlap that works best is 50%, which recovers most of the data weight lost by the taper.

Python Welch smooths the estimate

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.

Shorter segments mean more averages and a smoother estimate (relative spread near 1/sqrt(K)), but fewer frequency bins. This is the central trade-off.

Resolution versus variance

  • Frequency resolution is about fs / nperseg hertz (times the window's main-lobe factor).
  • Variance drops roughly as 1 / segments.

If your signal has two sinusoids 5 Hz apart, you need nperseg of at least a few times fs/5. If you are measuring a smooth noise spectrum, you can use short segments and enjoy a smooth curve.

Finding a tone in noise

A 100 Hz sine with amplitude 0.5 in white noise of variance 1. The tone's power is 0.5ยฒ/2 = 0.125.

Python Tone power from a Welch PSD

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.

Notice the two scalings. scaling="density" gives Vยฒ/Hz, right for noise. scaling="spectrum" gives Vยฒ, right for reading the power of a sinusoid directly from the peak height.

Practical settings

  • Window: Hann by default. See windowing and spectral leakage.
  • Overlap: 50% for Hann or Hamming, 66% to 75% for Blackman-type windows.
  • Detrend: remove the mean (detrend="constant", the default) or a linear trend; any DC otherwise leaks into the lowest bins.
  • nfft: pad each segment to a power of two for speed, or to a larger size for a smoother-looking (not more-resolved) curve; see zero padding and peak interpolation.
  • Units: report which scaling you used. Plot in dB with 10*log10(P).

For very long recordings, use scipy.signal.welch on blocks you read from disk, or accumulate periodograms yourself. The method needs only one segment in memory at a time.

Other estimators

Welch is the workhorse, but others exist. Bartlett's method is Welch without overlap and window. Blackman-Tukey smooths the autocorrelation. Multitaper estimators (scipy.signal.windows.dpss) use several orthogonal windows to get lower variance and little leakage. Parametric estimators such as AR models can give sharp peaks from short records, but need a model order.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does recording a longer signal not smooth a single periodogram?

    The periodogram is not a consistent estimator: each bin keeps a spread comparable to its mean, no matter the length.
  2. 2. What does Welch's method do?

    Averaging windowed segment periodograms reduces variance at the price of frequency resolution.
  3. 3. If you halve nperseg, what happens approximately?

    Shorter segments give coarser frequency bins but more of them to average, so the estimate is smoother.
  4. 4. Which scaling reads the power of a sinusoid directly from a peak?

    scaling='spectrum' returns power per bin (V^2), so a sinusoid's peak height approximates its power; 'density' gives power per hertz.

Summary

  • The PSD describes how power spreads across frequency; the periodogram estimates it but is noisy.
  • Welch's method averages windowed, overlapping periodograms, trading frequency resolution for lower variance.
  • Pick nperseg from the resolution you need, use 50% overlap with Hann, and mind density versus spectrum scaling.
  • Multitaper and parametric methods offer alternatives.

Next: The STFT and Spectrograms