←back to thread

220 points wonger_ | 5 comments | | HN request time: 0s | source
1. plasticeagle ◴[] No.42191292[source]
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(2): >>42191330 #>>42191815 #
2. thefroh ◴[] No.42191330[source]
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

replies(1): >>42197815 #
3. reynaldi ◴[] No.42191815[source]
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!
replies(1): >>42193074 #
4. jmiskovic ◴[] No.42193074[source]
You are already using the IIR filter as part of one-euro filter. The 1€ filter is an adaptive filter that uses first-order IIR, also called exponential filter as its bases. Depending on your filtering parameters you can turn off the adaptive part and you are left with just the IIR.
5. plasticeagle ◴[] No.42197815[source]
That sounds very interesting. I've been needing a filter to deal with noisy A/D conversions for pots in an audio project. Noise on a volume control turns into noise on the output, and sounds horrible, but excessive filtering causes unpleasant latency when using the dials.