DSP: spectral estimation, windows, resampling and multirate processing
The previous chapter shaped signals with filters. This one measures them and changes their sampling rate. Spectral estimation asks how a signal’s power is distributed over frequency: the periodogram and Welch’s average, the spectrogram for signals that change, the Lomb-Scargle periodogram for irregular samples, models that resolve finer than the DFT allows, and wavelets that analyse many scales at once. Windows control the leakage that every finite record suffers. Multirate processing changes the sampling rate efficiently and splits signals into channels.
The central questions
- Resolution or dynamic range? A window’s main lobe sets how close two components can be; its side lobes set how weak one can be next to a strong one. Parametric methods buy resolution with assumptions.
- Bias or variance? Longer segments give finer frequency resolution; more segments give steadier estimates. The record length fixes the product.
- Time or frequency? A spectrogram trades one for the other uniformly; wavelets trade them differently at each scale; the analytic signal gives an instantaneous frequency for narrow-band signals.
- How to change the rate cheaply? Compute only the samples that are kept, from only the samples that are not zero: polyphase filters, half-band stages and multiplier-free CIC filters.
Testing against SciPy
Every window function, in symmetric and periodic forms, is compared with scipy.signal.windows in the window entry. The other computations:
Table 15.1. Spectral routines against SciPy.
| SciPy function and case | largest difference ÷ largest value |
|---|---|
| periodogram hann density | 2.0e-16 |
| welch hann 64/32 linear spectrum | 5.2e-17 |
| hilbert 64 | 2.4e-16 |
| czt 20 points | 2.6e-15 |
| lombscargle unnormalized | 3.8e-15 |
| upfirdn up 3 | 0.0e0 |
| upfirdn up 3 down 2 | 0.0e0 |
| levinson order 8 | 4.1e-15 |
| stft hann 64/16 | 2.1e-16 |
| spectrogram hann 64/16 density | 4.3e-16 |
| square period 8 | 0.0e0 |
| find_peaks all | 0.0e0 |
| find_peaks height 0.8 | 0.0e0 |
| find_peaks threshold 0.4 | 0.0e0 |
| find_peaks distance 12 | 0.0e0 |
| find_peaks prominence 1 | 0.0e0 |
| find_peaks prominence 1 wlen 15 | 0.0e0 |
| find_peaks width 2-6 | 0.0e0 |
| find_peaks width 3 rel_height 1 | 0.0e0 |
| find_peaks plateau_size 2 (rounded signal) | 0.0e0 |
In the library
All of these are in lib_jsl_dsp (API reference): windows in discrete::windows, spectral methods in discrete::spectral,
resamplers in discrete::resampling, and Fourier integrals in continuous::spectral.
| You need | Use | Entry |
|---|---|---|
| A taper for spectral analysis or filter design | generate_window, WindowType, hann, kaiser, chebwin, dpss, … | Window functions |
| A power spectrum, a spectrogram, or a spectrum of irregular samples | periodogram, welch, stft, istft, spectrogram, lomb_scargle | Power spectra |
| A few DFT bins, a zoomed band, or a Fourier integral | goertzel, chirpz, fourier_integral | Spectra at chosen frequencies |
| An envelope or instantaneous frequency | analytic_signal, hilbert_transform, instantaneous_attributes | Hilbert transform |
| Resolution beyond the DFT; a linear-prediction model | levinson_durbin, linear_predictive_coding, burg, music | Parametric spectra |
| The peaks of a signal or spectrum, with their prominences and widths | find_peaks, peak_prominences, peak_widths | Peak finding |
| Group delay, minimum phase, least-squares FIR design, decimation, FFT resampling, median filtering, cross spectra and coherence | group_delay, minimum_phase, firls, decimate, resample, medfilt, csd, coherence | Signal-processing utilities |
| Partial fractions of a transfer function; deconvolution; zero-pole-gain conversions | residue, residuez, deconvolve, tf2zpk, ss2zpk | Partial fractions, zoom FFT and waveforms |
| A finely spaced spectrum on a narrow band | zoom_fft | Partial fractions, zoom FFT and waveforms |
| Chirps, Gaussian pulses, sawtooth and square test signals | chirp, sweep_poly, gausspulse, sawtooth, square_wave | Partial fractions, zoom FFT and waveforms |
| Multiscale analysis, compression or denoising | dwt, wavedec, waverec, continuous_wavelet_transform | Wavelet transforms |
| A different sampling rate | PolyphaseIntegerResampler, PolyphaseArbitraryResampler, HalfBandDecimator, CicDecimator | Resampling |
| Many frequency channels, and recombining them | *PolyphaseAnalysisFilterBank, *PolyphaseSynthesisFilterBank | Polyphase filter banks |