A common way to low pass filter:
Another way to write the same code:
Time constant is,
where dt is the execution interval and α is 0.04 in the above example.
Check with α = 0.04 and dt = 0.001 (τ = 0.024):Above confirms that
yreaches 63.2% of
raw's changes in τ seconds.
First code can be rewritten so that constants have physical meanings:
Now, if the loop needs to run at a different interval,
LOOP_FREQUENCY needs to be changed.
Filter properties will stay unaffected.