mathematics//signal processing//digital filter
A digital filter is an algorithm that computes each output sample as a combination of the current and past input samples, and sometimes of past outputs, so that some frequencies of a sampled signal pass and others are attenuated; it is the most used piece of signal processing in any loop, cleaning gyro readings in an autopilot, pressure readings in a PLC and currents in a motor drive. A filter running on live data is a **causal filter**: it can only use samples that have already arrived, which is the only kind possible in flight or on a running plant.
A digital filter is an algorithm that computes each output sample as a combination of the current and past input samples, and sometimes of past outputs, so that some frequencies of a sampled signal pass and others are attenuated; it is the most used piece of signal processing in any loop, cleaning gyro readings in an autopilot, pressure readings in a PLC and currents in a motor drive. A filter running on live data is a causal filter: it can only use samples that have already arrived, which is the only kind possible in flight or on a running plant.
Causality has a price. To average away noise, a filter has to lean on older samples, so its output describes the signal as it was a little while ago. That lag is measured as group delay, τg(ω)=−dϕ/dω\tau_g(\omega)=-d\phi/d\omegaτg(ω)=−dϕ/dω, the time by which the filter shifts the content at each frequency: a moving average of NNN samples delays by (N−1)/2(N-1)/2(N−1)/2 samples, a first-order low-pass filter cut at 20 Hz by about 8 ms, and a second-order Butterworth low-pass at 30 Hz, run at 1 kHz on a gyro, by about 7.7 ms in band.
Every causal filter trades noise for delay, and delay is poison for control.
An attitude loop that crosses over at 30 rad/s with 45° of phase margin tolerates about 26 ms of extra delay (delay margin); the 7.7 ms Butterworth spends almost a third of it, some 13° of phase at crossover. Filtering harder makes the trace look cleaner and the drone oscillate: the error has moved from noise to delay (error relocation).
The delay of a real chain is a sum of physical sources, and a filter is only one. On a drone the gyro is first smoothed by a digital low-pass inside the MEMS chip (configured by a register, often left at a default nobody chose), then waits its turn on the serial bus, passes the software low-pass and notches, is held for up to a sample by the controller, and its correction reaches the air through the ESC and the lag of motor and propeller. Loop delay tallies them.
The members differ in what they cost. The moving average and the first-order low-pass filter are the cheap defaults for broadband noise; the median filter removes isolated spikes, which linear filters only smear; the notch filter removes one narrow vibration line with far less delay at low frequencies than a low-pass aggressive enough to reach it; FIR and IIR designs give precise bands, the first with many coefficients and equal delay at every frequency, the second with few coefficients and phase distortion.
A drone's gyro is typically filtered by a second-order IIR low-pass plus notches at the motor frequency, and the notch often follows the rpm reported by the ESCs.
Filtering recorded data has no such price. Running a filter forwards and then backwards cancels its delay, but only by using the future (zero-phase filtering); a detector designed that way arrives late once it runs live.
Removing the vibration at its source beats any filter. Balanced propellers and an isolated IMU leave less to filter, and each hertz of cut-off given back is phase the loop keeps (flyswatter rule).