alt.hn

7/28/2026 at 6:11:18 AM

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

https://www.staszewski.xyz/blog/recursive-filters/

by kamilstaszewski

7/30/2026 at 6:54:28 AM

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.

by jampekka

7/30/2026 at 8:33:42 AM

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.

by quietbritishjim

7/30/2026 at 1:07:56 AM

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.

by deepsun

7/30/2026 at 4:17:55 AM

Ten Little Algorithms, Part 2: The Single-Pole Low-Pass Filter (https://www.embeddedrelated.com/showarticle/779.php)

by jason_s

7/30/2026 at 5:01:52 AM

OT but I've always appreciated your posts, Jason -- you should think about expanding them into a book, or at least an e-book. It would end up on my shelf next to Lyons.

That being said, it'd be good to update this post to clarify the difference between angular frequency and plain old cycles-per-second frequency, as one of the commenters calls out.

by CamperBob2

7/30/2026 at 1:26:31 AM

Too basic for who? You?

by Vaslo

7/30/2026 at 3:21:30 AM

Wait till he learns about PID controllers

by glouwbug

7/30/2026 at 6:11:44 AM

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.

by buildingrobots

7/30/2026 at 7:44:26 PM

That gives you the time constant for the 63% step response, but that's not quite the same thing as the 3-dB cutoff, due to frequency warping. I do this to get an alpha value for cutoff_Hz at a given sampling interval dt_s:

    double omega_c = TWO_PI * cutoff_Hz * dt_s;     
    double b = 4.0 - (2.0 * cos(omega_c));
    
    return 1.0 - ((b - sqrt(b*b - 4.0)) * 0.5);
Probably won't matter most of the time, though, when you're just trying to make some noise go away.

by CamperBob2

7/30/2026 at 7:49:28 AM

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

by myky22

7/30/2026 at 4:45:03 AM

Good

by adenjoe

7/30/2026 at 6:10:56 AM

[dead]

by reindeer2

7/30/2026 at 4:43:50 AM

[dead]

by adenjoe