mathematics//signal processing//digital filter//zero-phase filtering
Zero-phase filtering is the technique of running a digital filter over a recorded signal once forwards and once backwards, so that the delay of the first pass is undone by the second and the output lines up exactly with the input in time; it is the standard way to clean recorded data for analysis, plotting and offline labelling, and the function `filtfilt` in SciPy and MATLAB does it in one call. Peaks stay where they happened and steps are not shifted, which is what an engineer wants when measuring the timing of an event in a log.
Zero-phase filtering is the technique of running a digital filter over a recorded signal once forwards and once backwards, so that the delay of the first pass is undone by the second and the output lines up exactly with the input in time; it is the standard way to clean recorded data for analysis, plotting and offline labelling, and the function filtfilt in SciPy and MATLAB does it in one call. Peaks stay where they happened and steps are not shifted, which is what an engineer wants when measuring the timing of an event in a log.
The trick needs the future. The backward pass reads, for each sample, the samples that came after it, so the filter is non-causal: on a log of yesterday's flight every sample is available, and in flight none of the following ones exist yet. The magnitude response is applied twice (the attenuation in decibels doubles), and the phase of the two passes cancels at every frequency.
Design with the filter you will deploy.
A detector tuned on a laptop with filtfilt and deployed with the same filter run causally (lfilter) suddenly fires about 8 ms late, because the delay that forward-backward filtering hid has come back; thresholds tuned on the aligned traces then misfire too. Offline development of anything that will run live must use the causal filter from the start.
The same idea exists in estimation. A Kalman smoother runs a filter forwards and then a correction backwards over a recorded batch, so each estimate uses the readings after it as well as before (RTS smoother); it is the right tool for post-flight analysis and the wrong one inside a loop.
Zero phase is free only offline. A live system can approach it by predicting, with a model, where the signal is now from where the delayed filter says it was, which is what a Smith predictor or an estimator propagating forward does; the delay is then compensated, at the price of trusting the model.
The ends of the record need care. Both passes start from somewhere, and the first and last stretches carry the filter's start-up transient unless the signal is padded; trimming a few time constants from each end of an analysis window avoids reading artefacts as events.
A centred moving average used to smooth a series for display is the same thing in its simplest form, and it shares the same restriction (moving average).