mathematics//signal processing//digital filter//first-order low-pass filter
A first-order low-pass filter is the simplest recursive digital filter: each output moves a fixed fraction of the way from the previous output towards the new sample, which lets slow changes through and attenuates fast ones, and it is the default first tool for cleaning a noisy sensor in firmware, a PLC block or a data pipeline. It is the digital twin of an RC circuit, and it is the same computation that statistics calls an exponentially weighted moving average (EWMA).
A first-order low-pass filter is the simplest recursive digital filter: each output moves a fixed fraction of the way from the previous output towards the new sample, which lets slow changes through and attenuates fast ones, and it is the default first tool for cleaning a noisy sensor in firmware, a PLC block or a data pipeline. It is the digital twin of an RC circuit, and it is the same computation that statistics calls an exponentially weighted moving average (EWMA).
yk=yk−1+α (xk−yk−1),α=Δtτ+Δty_k=y_{k-1}+\alpha\,(x_k-y_{k-1}),\qquad \alpha=\frac{\Delta t}{\tau+\Delta t}yk=yk−1+α(xk−yk−1),α=τ+ΔtΔt
xkx_kxk is the raw sample, yky_kyk the filtered one, Δt\Delta tΔt the sample period and τ\tauτ the time constant that sets the behaviour. With α=0.1\alpha=0.1α=0.1 every new reading moves the output by a tenth of its disagreement with it. The filter cuts at fc=1/(2πτ)f_c=1/(2\pi\tau)fc=1/(2πτ), and below that frequency it delays the signal by about τ\tauτ seconds: a cut at 20 Hz means τ≈8\tau\approx 8τ≈8 ms of lag, a cut at 2 Hz about 80 ms. Above the cut it attenuates by half for each doubling of frequency (20 dB per decade).
One knob sets both the noise removed and the delay added.
Lowering the cut-off by a factor of ten removes more noise and multiplies the lag by ten, and that lag is a first-order system inserted in every loop that reads the filtered value. Setting the corner several times above the loop's bandwidth keeps the phase cost at crossover to a few degrees.
It responds from the first sample, which separates it from a pure delay. A step in the input starts moving the output at once and reaches 63 % of the way after τ\tauτ, the classic lag of delay and lag; a transport delay would show nothing at all until its dead time had passed.
It costs one multiply, one add and one stored number, so it runs anywhere, and its single parameter can be explained to an operator in a sentence. With a median of three samples in front to take out spikes, it covers a large part of real sensor cleaning (median filter, flyswatter rule).
Its roll-off is gentle. When noise sits close to the band of interest, or a strong vibration line must be removed, a second-order IIR filter or a notch filter does it with less delay than pushing this filter's corner down.
The same equation appears in the complementary filter, which splits the job between a gyro and an accelerometer with one time constant, and in the derivative term of a PID, which needs its own low-pass to stop amplifying noise (derivative action).