Settings

Theme

Recursive Filters: SMA, EMA, Low‑Pass, and a Tiny Kalman

staszewski.xyz

52 points by kamilstaszewski 2 days ago · 13 comments

Reader

jampekka 5 hours ago

A perhaps interesting (and sometimes even useful) property of the 1D Kalman filter is that it becomes an EMA when it's in the "steady state" (the gain to which it converges asymptotically, in practice often quite fast).

Specifically:

  alpha = (Q + 2*R - sqrt(Q^2 + 4*Q*R))/(2*R)
This also concretizes that the Kalman filter is not adaptive in the sense of adapting to the data. The filtering behavior is fully specified by the parameterization.

The sometimes useful part is that with this formulation you can get the alpha parameter for an EMA in terms of the sensor and process noises.

  • quietbritishjim 3 hours ago

    Agreed - a Kalman filter is often just a EMA in disguise.

    I remember using a Kalman filter many years ago and getting confused when a measurement was fairly far from the current estimate, and the uncertainty still went down. Surely the uncertainty should go up if a measurement shows that our previous estimate was unreliable? I spent a lot of time debugging my code before someone pointed out to me that the Kalman filter does not adjust its uncertainties (and therefore the effective value of alpha) at all based on the data.

    But a Kalman filter does not converge to EMA if either:

    * Measurements occur at irregular intervals

    * Measurements can have different errors (which you can meaningfully estimate)

    These are exactly the situations when it's worth using a Kalman filter instead.

buildingrobots 5 hours ago

You can choose their version of alpha by picking a cutoff frequency f and setting alpha = exp(-2*pi*f*dt) where dt is your sample rate. f will be the ≈-3dB point of your filter where frequencies above it are reduced by 0.707 or more.

deepsun 11 hours ago

Too basic, I'm not sure anyone needs that to solve the task as basic would need to read an article, it's obvious.

> Tune by eyeballing lag vs. noise.

In any serious installations (more than a homelab) you want some numeric metrics, not eyeballing. E.g. management or next engineer may reasonably ask "why alpha is 0.8? what's the rationale, why not 0.85", you want some formula to show it's what we want.

myky22 4 hours ago

For one second I thought the post was about analogic music filters (hardware synthesis) ToT

adenjoe 7 hours ago

Good

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection