logoalt Hacker News

plasticeagle11/20/20242 repliesview on HN

This is cool, but a moving average filter is pretty bad at removing noise - it tends to be longer than it needs to be because its passband is so bad. Try using a IIR filter instead. You don't need to deal with calculating the coefficients correctly because they'll just be empirically determined.

out = last_out * x + input * (1-x)

Where x is between zero and one. Closer to one, the more filtering you'll do. You can cascade these too, to make a higher order filter, which will work even better.


Replies

thefroh11/20/2024

i've heard good things about using the 1 euro filter for user input related tasks, where you're trying to effectively remove noise, but also keep latency down.

see https://gery.casiez.net/1euro/ with plenty of existing implementations to pick from

show 1 reply
reynaldi11/20/2024

Interesting, never heard of the IIR filter before, will keep in mind as one of the options if I ever worked with removing noise again, thanks for sharing!

show 1 reply