A small collection of sensor smoothing functions designed for embedded devices and other resource-constrained environments.
Pull requests and contributions are welcome!
float
(single precision) as it is the most common size for sensor data in embedded platforms.
double
precision can modify the source code accordingly, and contributions to support this are welcome.The simple moving average function maintains a circular buffer of recent input values and returns their average. The user must allocate and manage this buffer.
sensor_smoother_simple_moving_average_t sma_state = {0}; sma_state.buffer = buffer; // pre-allocated float array sma_state.buffer_size = sizeof(buffer) / sizeof(buffer[0]); float smoothed_value = sensor_smoother_simple_moving_average(&sma_state, input);
The function performs runtime validation by default:
DISABLE_SENSOR_SMOOTHER_SIMPLE_MOVING_AVERAGE_CHECKS
to disable null buffer and zero-size checks in the simple moving average function for performance reasons.The exponential moving average uses a smoothing factor alpha
between 0 (exclusive) and 1 (exclusive) to weight new input values. Smaller alpha values smooth more aggressively.
sensor_smoother_exponential_moving_average_t ema_state = {0}; ema_state.alpha = 0.1f; // Smoothing factor: 0 < alpha < 1 float smoothed_value = sensor_smoother_exponential_moving_average(&ema_state, input);
The function performs runtime validation by default:
DISABLE_SENSOR_SMOOTHER_EXPONENTIAL_MOVING_AVERAGE_CHECKS
to disable alpha range checks in the exponential moving average function for performance reasons.You can install this library using clib:
clib install mofosyne/sensor_smoother.c
This will download sensor_smoother.c
and sensor_smoother.h
into your project’s deps/
directory that you can then include into your codebase.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4