Median Filter for PPG Artifact Removal

Median filtering is a non-linear smoothing operation that replaces each PPG sample with the median of surrounding samples within a sliding window, effectively removing spike artifacts and impulse noise while preserving sharp transitions like the systolic upstroke that linear filters would blur.

The median filter output y(n) = median{x(n-k), ..., x(n), ..., x(n+k)} for window size 2k+1 is maximally robust to outliers: up to k corrupted samples within the window do not affect the output. For PPG, window sizes of 3–7 samples (at 25–100 Hz) remove single-sample spikes from electrical glitches, sensor contact disruptions, and quantization artifacts without distorting the underlying pulse waveform.

Unlike linear filters (FIR, IIR), median filtering preserves monotonic edges — the sharp systolic upstroke and diastolic downstroke are maintained without the ringing or smoothing that occurs with low-pass linear filtering. This property makes median filtering ideal as a preprocessing step before morphological analysis that depends on precise feature timing and amplitude.

Weighted median filters assign position-dependent weights to samples within the window, allowing center-weighted variants that provide even better edge preservation. Running median computation can be implemented efficiently using a sorted linked list or min-max heap data structure, achieving O(log k) per sample update instead of O(k log k) for naive sort-based implementation.

Frequently Asked Questions

What window size should be used for PPG median filtering?

3–5 samples for spike removal at 25–100 Hz. Larger windows (7–15) can smooth low-amplitude oscillations but may distort the dicrotic notch. Window size should be smaller than the shortest expected pulse feature duration.

When should median filtering be preferred over linear filtering?

Median filtering is preferred when impulse noise (spikes, dropouts) is present and waveform edge preservation is important. Linear filtering is preferred for removing continuous narrowband or broadband noise where edge preservation is less critical.

Can median filtering introduce artifacts?

Median filtering can create staircase artifacts in slowly varying signals and may eliminate legitimate brief signal features shorter than the window length. For PPG, these effects are minimal with window sizes of 3–5 samples.

Related Algorithms