S7 · Lesson 35 · Spectral analysis lab
Window figures of merit, scalloping by direct evaluation, and Levinson–Durbin on a known AR process, in Python
Lessons 29 to 34 quoted tables: a Hann window's coherent gain of 0.5 and noise bandwidth of 1.5 bins, scalloping losses of 3.92 and 1.42 dB, and the claim that Levinson–Durbin recovers an AR model's coefficients from its autocorrelation. This lab computes each from its definition: the window figures from the samples themselves, the scalloping loss by evaluating the window's transform half a bin off, and an AR(2) model recovered exactly from the autocorrelation the Yule–Walker equations predict.
- The curve is the peak response of an N-point DFT to a tone d bins away from the nearest bin, for a rectangular window: in dB, with N = 64.
- It is 0 dB on a bin and drops to −3.92 dB halfway between bins (the right edge): the scalloping loss. Past halfway the tone is nearer the next bin, so the picture repeats.
- A Hann window's wider main lobe flattens this to −1.42 dB, at the cost of 1.76 dB more noise bandwidth.
Predict
An AR(2) process has a₁ = 0.75, a₂ = −0.5 and unit driving noise. Its autocorrelation is computed exactly and fed to Levinson–Durbin with order 2. What comes out?
With exact autocorrelation (φ[0] = 1.778, φ[1] = 0.889, φ[2] = −0.222), the Yule–Walker equations are exactly the ones the process satisfies, so Levinson–Durbin returns a = [0.75, −0.5] and . Estimated autocorrelations from finite data give estimates scattered around these.
Name it
What the lab computes
- Windows (periodic forms): rectangular; Hann ; Hamming .
- Coherent gain and ENBW bins.
- Scalloping loss: , the window's transform half a bin from its peak, by direct summation.
- Levinson–Durbin: from φ[0..p], the reflection coefficients and predictor coefficients order by order, with (lesson 34).
Check
Write window(name, N) for 'rect', 'hann' and 'hamming' (periodic forms), and cg(w) and enbw(w).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write scalloping_db(w): the window's response half a bin off, relative to its peak, in dB, by direct evaluation of its DTFT.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write levinson(phi, p): return (a, E) with a = [a₁, …, a_p] the predictor coefficients and E the final prediction error.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a window with lower scalloping loss usually have a larger noise bandwidth?
A window that keeps a tone's reading nearly constant when it falls between bins must have a broad, flat main lobe, so that half a bin away its response has hardly fallen. A broad main lobe in frequency means the window collects energy from a wider band around each bin, which for white noise means more noise power per bin: a larger equivalent noise bandwidth. Tapering the window also reduces its sum relative to its energy, which is exactly what the noise-bandwidth formula measures. So measuring tone amplitudes accurately and detecting weak tones in noise pull toward different windows.