pub fn running_median(values: &[f64], half: usize) -> Vec<f64>Expand description
The running median of values: each sample replaced by the median of the samples within
half places of it, the window cut short at either end of the record. NaNs are skipped; a
window with no finite sample gives NaN. An even count takes the mean of the middle two.
This is the standard median filter, the Hampel filter at threshold t = 0 (R. K. Pearson et
al., The Class of Generalized Hampel Filters, EUSIPCO 2015, §2, eqs. 1 and 2, with K = half). It removes any excursion narrower than half + 1 samples, such as the pressure pulse an
ejection charge punches into a barometric altitude, and leaves a monotonic run exactly as it
was. At a noise-free peak it reads low, never high: by the fall over ⌈half/2⌉ samples from
the highest sample, as half + 1 of the window’s samples lie that close to it
(crate::readings::peak_bound_m gives the bound for a peak bent by gravity). With noise, the
highest of the medians can read above the peak.