Spectral Analysis
Spectral analysis estimates how signal power spreads over frequency from finite noisy samples, trading resolution against variance.
Why Does This Exist?
A measured trace mixes tones, broadband noise, and interference; decisions (bearing fault? grid oscillation? seizure onset?) need power per frequency with uncertainty attached. The raw periodogram (squared DFT magnitudes) is unbiased but inconsistent: its variance never shrinks with more data, so longer records merely add wobblier bins. Spectral analysis fixes estimation: windowed, averaged, and tapered variants that trade resolution for stability with stated degrees of freedom. Transforms are Fourier; time-localized alternatives are wavelets.
The one idea you need first
The power spectral density gives power per Hz: tone power concentrates in lines, white noise spreads flat at per bin. Estimates report power per bin with chi-square fluctuations around .
Think of It Like This
Weighing flour with a shaky scale
One scale reading flickers wildly: , , grams for the same scoop. Averaging ten scoops steadies the mean but blurs whether the flour came in one pour or two (resolution lost). A steadier scale (tapered, damped) reads calmer per scoop but responds slower to sudden changes.
Periodograms are the shaky scale: each bin reads times exponential noise (standard deviation equals the mean). Welch averaging trades frequency sharpness for calm; multitapers trade measurement count for leakage control. No estimator is both sharpest and calmest.
How It Actually Works
Periodogram: , variance per bin regardless of (2 degrees of freedom). Bartlett/Welch: split into segments (Welch: overlapping, windowed), average: variance , resolution coarser, degrees of freedom . Multitaper: orthogonal Slepian tapers on the full record: degrees of freedom at full resolution minus bandwidth widening. Rule: segments (or tapers) before quoting levels.
Worked example
Bearing vibration at Hz, samples ( s): fault tone Hz at power (, noise floor per bin (ratio : dB). Raw periodogram bins fluctuate with standard deviation equal to the mean: noise bins read to (some crossing of the tone); the tone bin reads to across realizations. Welch with half-overlapping Hann segments: noise standard deviation falls to ; tone resolves at with degrees of freedom; interval (chi-square): detection margin above the noise ceiling. Decision-grade where raw was not.
Code
import cmathimport math
def periodogram(xs: list[float], fs: float) -> list[float]: n = len(xs) # squared magnitudes scaled to power per bin out = [] for k in range(n // 2 + 1): s = sum(x * cmath.exp(-2j * cmath.pi * k * t / n) for t, x in enumerate(xs)) out.append(round(abs(s) ** 2 / (fs * n), 4)) return out
tone = [2 * math.cos(2 * math.pi * 2 * t / 16) for t in range(16)]spec = periodogram(tone, 16.0)print(spec.index(max(spec)), round(max(spec), 2)) # -> bin 2, power 4.0Tone power lands in bin exactly (frequency Hz at s): the estimator finds the line where planted.
Watch Out For
Quoting raw periodogram levels as measurements
Single-bin periodogram values carry relative standard deviation: a " dB rise" in one bin is one standard wobble, not an event. Average to stated degrees of freedom () before alerting, trending, or thresholding anything.
Windowing away closely spaced tones
Heavy windows (Blackman) widen main lobes times: tones Hz apart at -Hz resolution merge into one. Match taper to the question (detect presence: average hard; separate neighbors: window light, record long) instead of defaulting to Hann everywhere.
The Quick Version
- Power spectra report power per frequency with chi-square fluctuations per bin.
- Raw periodograms never steady with record length: variance equals the mean squared.
- Welch with segments cuts noise deviation to and gives degrees of freedom.
- The fault tone at stands times above the noise ceiling after averaging.
- Multitapers keep resolution while buying stability through orthogonal windows.
- Average before alerting; window lightly when tones sit close.