Digital signal processing · Multirate systems · EEG

Preserve the signal.
Remove the wasted computation.

A 500 Hz → 32 Hz EEG resampling pipeline designed from explicit anti-alias constraints, then validated for numerical equivalence, spectral preservation, and computational efficiency.

Sampling rate500 → 32 Hzexact rational conversion
FIR workload~1000× lesstheoretical core-operation comparison
Runtime~119× fastermedian benchmark on validation machine
PSD shape0.999999996median correlation in 0.5–12.5 Hz

01 · Engineering question

Downsampling is only safe when the new Nyquist limit is treated as a design constraint.

Reducing EEG from 500 Hz to 32 Hz can cut storage and downstream computation substantially. But a naïve decimator can fold energy above 16 Hz back into the retained spectrum.

This project therefore treats resampling as a complete system: derive the anti-alias filter from the protected analysis band, implement an efficient polyphase form, and verify what information is preserved after conversion.

Protect

0.5–12.5 Hz

The full target analysis band is kept essentially flat.

Reject

≥ 16 Hz

The stopband starts at the output Nyquist limit.

Verify

Signal + spectrum

Numerical equivalence and multiple spectral descriptors are checked separately.

02 · Multirate architecture

An exact 8/125 rational conversion.

Input500 Hz

EEG recording

→
InterpolationL = 8

4 kHz intermediate rate

→
Anti-alias FIR4,145 taps

Kaiser window

→
DecimationM = 125

retain required phases

→
Output32 Hz

1,920 samples / 60 s

Aligned spectral grid: 8 s epochs give 500 / 4000 = 32 / 256 = 0.125 Hz bin spacing on both branches; Hann-window spectral resolution is broader.

03 · Specification-driven filtering

The FIR length comes from the specification—not an arbitrary tap count.

Passband edge12.5 Hzprotected analysis limit
Stopband edge16 Hznew Nyquist limit
Target attenuation60 dBKaiser design objective
Resulting filter4,145 tapsβ = 5.653
Anti-alias Kaiser FIR frequency response with the 12.5 Hz passband edge, 16 Hz stopband edge, and minus 60 dB target
The visual check makes the design intent immediate: the protected band stays essentially flat, then the response falls through the 12.5–16 Hz transition before decimation.
Response checkMeasured
Gain at 12.5 Hz−0.0095 dB
Worst passband deviation0.0090 dB
Gain at 16 Hz−60.32 dB
Minimum stopband attenuation59.89 dB

04 · Polyphase optimisation

Same FIR response. Far less unnecessary work.

Direct form994.8M

approximate FIR MACs for the 30,000-sample validation recording

Polyphase core0.995M

approximate FIR MACs after phase decomposition

Theoretical reduction~1000×

operation-count comparison

Measured speed-up~119×

median wall-clock benchmark; machine-dependent

Direct-form and polyphase resampling outputs overlaid across the common valid region
Direct-form and polyphase outputs remain numerically equivalent: correlation 1.000000, MSE 7.77×10⁻²⁷.

05 · Spectral preservation

Validation asks more than one frequency-domain question.

PSD shape0.999999996

Median normalized-PSD correlation across 8 s epochs.

Normalized PSD error0.0091%

Median relative RMSE.

Band-power error0.026–0.032%

Median error across 0.5–4, 4–8, and 8–12.5 Hz.

IWMF0.0412 Hz

RMSE, with correlation 0.9911.

Mean normalized PSD before and after resampling, with the protected 0.5 to 12.5 Hz analysis band and the transition to 16 Hz marked
The 500 Hz reference and 32 Hz output overlap across the protected analysis band. Separation becomes visible only in the transition toward the 16 Hz output Nyquist limit, where attenuation is expected.
IWMF feature values before and after resampling across epochs
IWMF tracks the reference across epochs while exposing the small residual error quantitatively.

06 · Engineering ownership

What I designed and verified.

01

Multirate design

Defined the exact 8/125 conversion and the protected spectral band.

02

Filter derivation

Derived the Kaiser FIR from passband, stopband, and attenuation requirements.

03

Implementation check

Implemented a direct reference and integrated SciPy’s polyphase resampler with the same FIR coefficients; verified numerical equivalence.

04

Spectral validation

Compared PSD shape, sub-band power, entropy, SEF95, and IWMF.

05

Efficiency analysis

Separated theoretical operation-count reduction from measured runtime speed-up.

06

Reproducibility

Added synthetic demo data, regression tests, CI, and a public executable pipeline.

Scope: results cover one 60 s recording and 14 overlapping epochs. The original recording is not redistributed. Direct/polyphase equivalence uses the common 1,904-sample prefix, including the start transient. This is a signal-processing and implementation study. It does not claim clinical performance, diagnostic validity, or preservation of frequencies above the 32 Hz output Nyquist limit.