A sensor’s readings jump around. Keep a smoothed value that updates with every new reading. Write smooth(previous, reading, keep): the new smoothed value, where previous is the smoothed value so far and keep (0 to 1) is how much of it to hold on to.
A thermometer reads 21, then 25, 19, 23, 20, 24. The smoothed value starts at 21, and after each new reading smooth(previous, reading, keep) gives the next one, here with keep 0.8. What should they be?
click a smoothed value to see the call that made it
smooth(previous, reading, keep)| previous | the smoothed value so far | e.g. 5 |
| reading | the newest reading from the sensor | e.g. 5 |
| keep | 0 to 1, how much of previous to hold on to | e.g. 0.9 |
| returns | the new smoothed value | |