TExcelTAD
Home › Fourier Analysis & Signals › Power Spectra and Noise

Power Spectra and Noise

For random signals (noise, vibration, speech), each FFT gives a different, very noisy spectrum. What is stable is the power spectral density (PSD): the average power per unit frequency. This lesson shows why a single periodogram is a poor estimate, how Welch's method averages it into a good one, and what white and coloured noise look like.

The periodogram and its problem

The periodogram of NN samples is P[k]=1Nfs∣X[k]∣2P[k] = \frac{1}{N f_s}\lvert X[k] \rvert^2 (power per Hz). For white noise with variance σ2\sigma^2 the true PSD is flat at σ2/fs\sigma^2/f_s (two-sided), but each periodogram value fluctuates by about 100 % of its mean, however long the recording: more data gives more bins, not less noise per bin.

python · try it yourself
import numpy as np

rng = np.random.default_rng(0)
fs = 1000.0
for N in (256, 4096, 65536):
    x = rng.normal(size=N)                       # white noise, variance 1
    P = np.abs(np.fft.rfft(x)) ** 2 / (N * fs)
    P = P[1:-1]                                  # drop DC and Nyquist bins
    print(f"N={N:6d}: mean PSD {P.mean():.2e}  (true {1 / fs:.0e})   std/mean {P.std() / P.mean():.2f}")
N=   256: mean PSD 1.02e-03  (true 1e-03)   std/mean 1.06
N=  4096: mean PSD 9.97e-04  (true 1e-03)   std/mean 0.98
N= 65536: mean PSD 9.99e-04  (true 1e-03)   std/mean 0.99

The mean is right, but the relative spread stays near 1: the periodogram is an inconsistent estimator.

Welch's method

Split the signal into overlapping segments, window each, compute periodograms, and average. Averaging KK independent estimates reduces the spread by K\sqrt{K}, at the cost of resolution (shorter segments):

python · try it yourself
import numpy as np

rng = np.random.default_rng(1)
fs, N = 1000.0, 65536
x = rng.normal(size=N)

def welch(x, fs, nper):
    w = 0.5 - 0.5 * np.cos(2 * np.pi * np.arange(nper) / nper)   # Hann
    step = nper // 2                                               # 50 % overlap
    segs = [x[i:i + nper] * w for i in range(0, len(x) - nper + 1, step)]
    P = np.mean([np.abs(np.fft.rfft(s)) ** 2 for s in segs], axis=0) / (fs * np.sum(w ** 2))
    return P[1:-1], len(segs)

for nper in (4096, 1024, 256):
    P, K = welch(x, fs, nper)
    print(f"segments of {nper:4d}: {K:3d} averages, resolution {fs / nper:5.2f} Hz, std/mean {P.std() / P.mean():.3f}")
segments of 4096:  31 averages, resolution  0.24 Hz, std/mean 0.186
segments of 1024: 127 averages, resolution  0.98 Hz, std/mean 0.095
segments of  256: 511 averages, resolution  3.91 Hz, std/mean 0.052

Coloured noise

Noise is named by the slope of its PSD: white (flat), pink (1/f1/f, equal power per octave, common in nature and electronics), brown (1/f21/f^2, a random walk). Their PSD slopes in decibels per decade are 0, −10-10 and −20-20:

python · try it yourself
import numpy as np

rng = np.random.default_rng(2)
N, fs = 2 ** 16, 1000.0
white = rng.normal(size=N)
brown = np.cumsum(white); brown -= brown.mean()
W = np.fft.rfft(rng.normal(size=N))
f = np.fft.rfftfreq(N, 1 / fs)
W[1:] /= np.sqrt(f[1:]); W[0] = 0
pink = np.fft.irfft(W, N)                         # shape white noise by 1/sqrt(f) in amplitude

def slope_db_per_decade(x):
    P = np.abs(np.fft.rfft(x)) ** 2
    band = (f > 5) & (f < 200)
    return np.polyfit(np.log10(f[band]), 10 * np.log10(P[band]), 1)[0]

for name, x in (("white", white), ("pink", pink), ("brown", brown)):
    print(f"{name:6s} PSD slope {slope_db_per_decade(x):6.1f} dB/decade")
white  PSD slope   -0.1 dB/decade
pink   PSD slope  -10.0 dB/decade
brown  PSD slope  -19.6 dB/decade

In software

  • scipy.signal.welch(x, fs, nperseg=...) is the standard PSD estimator; periodogram gives the raw version. Units: V2/HzV^2/\text{Hz} for scaling="density", V2V^2 for "spectrum".
  • Noise specifications of sensors and amplifiers are given as PSDs (for example nV per root hertz); vibration testing uses PSD profiles.

Exercises

Exercise 1: White noise level

White noise with variance 4 is sampled at 2000 Hz. What is its one-sided PSD level?

Answer

0.004 per Hz.

Solution

The total power 4 is spread evenly over 00 to fs/2=1000f_s/2 = 1000 Hz (one-sided), giving 4/1000=0.0044/1000 = 0.004 per Hz. The two-sided density is half that over −1000-1000 to 10001000 Hz.

Exercise 2: Trade-off

Welch with segments of 1024 samples at fs=8192f_s = 8192 Hz: what is the frequency resolution? How many averages from 10 s of data with 50 % overlap?

Answer

8 Hz; 159 segments.

Solution

Resolution 8192/1024=88192/1024 = 8 Hz. 10 s is 81920 samples; with step 512 the segment count is ⌊(81920−1024)/512⌋+1=159\lfloor (81920 - 1024)/512 \rfloor + 1 = 159.

Exercise 3: Total power from the PSD (code)

Integrate the Welch PSD of seeded white noise with variance 1 over 00 to fs/2f_s/2 (one-sided, so doubled) and check it recovers the variance.

Answer

About 1.0.

Solution
python · try it yourself
import numpy as np
rng = np.random.default_rng(3)
fs, nper = 1000.0, 1024
x = rng.normal(size=100000)
w = 0.5 - 0.5 * np.cos(2 * np.pi * np.arange(nper) / nper)
segs = [x[i:i + nper] * w for i in range(0, len(x) - nper + 1, nper // 2)]
P = np.mean([np.abs(np.fft.rfft(s)) ** 2 for s in segs], axis=0) / (fs * np.sum(w ** 2))
P[1:-1] *= 2                                     # one-sided
print(round(float(np.sum(P) * fs / nper), 3))
0.998

By Parseval, the area under the PSD is the signal's power.

Test yourself

Why is a single periodogram a poor PSD estimate?

  1. it is biased low
  2. its values fluctuate by about 100 % no matter how long the recording
  3. it needs a window
  4. it only works for sines

Welch's method reduces the variance by…

  1. zero padding
  2. averaging periodograms of overlapping windowed segments
  3. using a larger FFT
  4. filtering the signal

Pink noise has a PSD proportional to…

  1. 1
  2. 1/f1/f
  3. 1/f21/f^2
  4. ff