|
void | Filter_Init (filter_t *f_ptr, int16_t offset, float scale) |
| Initializes all struct variables and calculates the shift based on scale input for linear transfer function. new_value = raw_value * scale + offset. More...
|
|
void | Filter_Update (int16_t raw_value, filter_t *f_ptr) |
| computes the new value after going through the transfer function and inputs it into filter buffer array More...
|
|
int16_t | Filter_Get (filter_t *f_ptr) |
| Filter_Get will retrieve the current value from the filter instance. More...
|
|
void | Filter_SetMin (filter_t *f_ptr, int16_t threshold, void(*callback)(int16_t)) |
| Filter_SetMin will set the MIN value in the filter to the threshold specified. Calls the callback function with the current value when the value drops below the threshold. More...
|
|
void | Filter_SetMax (filter_t *f_ptr, int16_t threshold, void(*callback)(int16_t)) |
| Filter_SetMin will set the MAX value in the filter to the threshold specified. Calls the callback function with the current value when the value goes above the threshold. More...
|
|
int16_t | MovingAvgFilter (int16_t *values, uint16_t index, uint16_t size, int16_t Last_Value) |
| Moving Average filter - Default filter that adds the previous X values and divides by number of values to compute a rolling mean. More...
|
|
void | Filter_SetFilter (filter_t *f_ptr, int16_t(*new_filter)(int16_t *values, uint16_t index, uint16_t size, int16_t last_value)) |
| Method that allows user to pass a function to a pointer a different type of filter (i.e IIR, FIR) More...
|
|
This module implements a Filter using a linear transfer function that takes in scale/offset in order to calculate new values new_value = raw_value * scale + offset
This module defaults to a MovingAvg Filter function. The user is resposible for implementing a filter based on application. It can be changed using the Set_Filter function
Example, MSP9700 temperature sensor, output voltage directly proportional to measured temperature MCP9700 can accurately measure temperature from -40C to +150C. The output of the MCP9700 is calibrated to a slope of 10mV/°C and has a DC offset of 500mV. The offset allows reading negative temperatures without the need for a negative supply.
V = T_c * 10mV + 500 mV
T_c = 0.322*V - 50
scale = 0.322 offset = -50
Example for implementation with ADC module
int16_t MinThreshold = 100;
int16_t MaxThreshold = 150;
int16_t offset = -50;
float scale = 0.322;
- Author
- Neil Surti
-
Alexander Revolous
-
Michael Muhlbaier
#define FILTER_BUFFER_SIZE 10 |
Filter_Get will retrieve the current value from the filter instance.
- Returns
- int16_t value stored in filter_t->value
void Filter_Init |
( |
filter_t * |
f_ptr, |
|
|
int16_t |
offset, |
|
|
float |
scale |
|
) |
| |
Initializes all struct variables and calculates the shift based on scale input for linear transfer function. new_value = raw_value * scale + offset.
- Parameters
-
scale | - Value that multiples with the input |
offset | - A constant value added to the linear transfer function to compute the desired result if needed |
void Filter_SetFilter |
( |
filter_t * |
f_ptr, |
|
|
int16_t(*)(int16_t *values, uint16_t index, uint16_t size, int16_t last_value) |
new_filter |
|
) |
| |
Method that allows user to pass a function to a pointer a different type of filter (i.e IIR, FIR)
- Parameters
-
new_filter | * - function pointer to the new filter |
void Filter_SetMax |
( |
filter_t * |
f_ptr, |
|
|
int16_t |
threshold, |
|
|
void(*)(int16_t) |
callback |
|
) |
| |
Filter_SetMin will set the MAX value in the filter to the threshold specified. Calls the callback function with the current value when the value goes above the threshold.
- Parameters
-
void Filter_SetMin |
( |
filter_t * |
f_ptr, |
|
|
int16_t |
threshold, |
|
|
void(*)(int16_t) |
callback |
|
) |
| |
Filter_SetMin will set the MIN value in the filter to the threshold specified. Calls the callback function with the current value when the value drops below the threshold.
- Parameters
-
void Filter_Update |
( |
int16_t |
raw_value, |
|
|
filter_t * |
f_ptr |
|
) |
| |
computes the new value after going through the transfer function and inputs it into filter buffer array
- Parameters
-
raw_value | - Values from ADC module that will go through the linear transfer function |
int16_t MovingAvgFilter |
( |
int16_t * |
values, |
|
|
uint16_t |
index, |
|
|
uint16_t |
size, |
|
|
int16_t |
Last_Value |
|
) |
| |
Moving Average filter - Default filter that adds the previous X values and divides by number of values to compute a rolling mean.
- Parameters
-
*values | - pointer to the values |
index | - location in array |
size | - size of data |
Last_Value | - last value in the array |
- Returns
- - returns the average value as int16_t