|
Envorimental Monitoring
|
Sliding-window median filter implementation. More...
#include "filter.h"Functions | |
| float | filter_sensor_value (Filter_Handle_t *p_filt, float raw_sensor_value, uint8_t window_size) |
| Applies a sliding-window median filter to a single raw sample. | |
| void | bubble_sort (float *array, uint8_t array_size) |
| Sorts a float array in ascending order using bubble sort. | |
| float | calculate_median (float *array, uint8_t array_size) |
| Computes the median of a pre-sorted float array. | |
Sliding-window median filter implementation.
| void bubble_sort | ( | float * | array, |
| uint8_t | array_size ) |
Sorts a float array in ascending order using bubble sort.
Runs in O(n²) time; suitable for the small window sizes used here (≤ MAX_WINDOW_SIZE = 20 elements).
| [in,out] | array | Pointer to the array to sort in place. |
| [in] | array_size | Number of elements in array. |
| float calculate_median | ( | float * | array, |
| uint8_t | array_size ) |
Computes the median of a pre-sorted float array.
For even-length arrays the median is the average of the two central elements. For odd-length arrays it is the single central element.
| [in] | array | Pointer to a sorted array of floats. |
| [in] | array_size | Number of elements in array. |
| float filter_sensor_value | ( | Filter_Handle_t * | p_filt, |
| float | raw_sensor_value, | ||
| uint8_t | window_size ) |
Applies a sliding-window median filter to a single raw sample.
On each call the new sample is inserted into the window. If the window has not yet reached window_size the sample is appended; otherwise the oldest sample is discarded (left-shift) and the new one placed at the end. A copy of the window is then sorted and the median returned.
| [in,out] | p_filt | Pointer to the filter state structure. |
| [in] | raw_sensor_value | The latest raw measurement from the sensor. |
| [in] | window_size | Effective window length (must be ≤ MAX_WINDOW_SIZE). |