Sensor Filter Code Tracing
Sensor Filter Code Tracing
Moving average startup
Trace the startup case before copying the pattern. With only two valid readings, divide by two, not by the configured maximum window size. Then trace one complete replacement and check that the sum contains exactly the current window. These checks explain the algorithm more usefully than watching a smooth plot. The class handles averaging; the surrounding pipeline still needs timestamps, invalid-sample policy, and calibration. A correct buffer implementation cannot decide whether the window is short enough to preserve a real event.
Median window
Trace a window with one extreme value and verify that the returned middle value stays near its neighbours. Next trace several consecutive elevated readings. Once they occupy enough of the window, the median follows them. That is expected behaviour, not a failure of sorting. It shows why the window must be checked against real event duration. Keep validity checks outside the helper, and decide what its output means before the window is fully populated.
Ema step
Trace the worked 20°C-to-24°C change with alpha set to 0.25: the next two estimates should be 21°C and 21.75°C. Then repeat at a different sampling interval and compare the response in seconds. The arithmetic per call is unchanged, but the physical response time changes. Keep this distinction in the prototype record. Low memory use makes the pattern convenient; it does not remove the need to justify alpha, handle invalid readings, and verify threshold timing.
Kalman update
Follow one update with a prediction below the measured value. The corrected estimate should move toward that measurement by the calculated gain. Then ask what repeated disagreement means: the physical state may have changed, the model may be inadequate, or the sensor may be faulty. The implementation cannot distinguish those explanations by itself. Use recorded steady and changing inputs to evaluate the model, and keep raw observations beside the estimate. Copying a compact Kalman class does not supply the missing system model.
Technical boundaries. The worked exponential average assumes a 20°C-to-24°C change and alpha of 0.25. The averaging helper leaves timestamps, invalid-sample policy, and calibration to the surrounding pipeline.