This function I've created is just one line of code that can emulate a type of averaging
of anything from 1 sample to infinite samples (using a transfer function with response constant).
No arrays required, fast performance, proportionally filters small and large changes
in readings. Spreadsheet attached to test different response and reading values.
Pseudo code...
float response = 0.3; // 0-1 range, 0 = no response, 1 = no filtering
float nresponse = 1 - response;
float tavg; //transfer function average
float ptavg; //previous transfer function average
void getTemperature(int temp) {
tavg = (ptavg * nresponse) + (analogRead(THERMISTORPIN) * response);
ptavg = tavg;
delayMicroseconds(200);
}
Note: If response is set to 0.5, then
each 1.0 deg change in temp reading will change tavg by 0.5 deg
each 0.3 deg change in temp reading will change tavg by 0.15 deg
Note: If response is set to 0.3, then
each 1.0 deg change in temp reading from tavg will change tavg by 0.3 deg
each 0.3 deg change in temp reading from tavg will change tavg by 0.1 deg
Note: If response is set to 0.1, then
each 1.0 deg change in temp reading from tavg will change tavg by 0.1 deg
each 0.3 deg change in temp reading from tavg will change tavg by 0.03 deg
Note: If response is set to 0.05, then
each 1.0 deg change in temp reading from tavg will change tavg by 0.05 deg
each 0.3 deg change in temp reading from tavg will change tavg by 0.015 deg
Response.xls (19 KB)