Hi Rob,
I did some more measurements and used RunningMedian instead of RunningAverage. The Code I used can be found here:
/*
*************************************
* Thread: THREAD_DifferentialPressure
* Get`s the differential pressure.
*************************************
*/
/* Global variables for this function */
float diff_Pressure_median = 0;
float diff_Pressure = 0;
float offset_diff_pressure; // offset which can be set by the user -> FUNC_OffsetDiffPressure (X_E_LCDML_MenuFunctions)
int n_averaging; // variable can be set by the user to define ow many measurements shall be averaged
RunningMedian diff_p_RA(200); // use a uer defined size for the running averaging of the differential pressure
/* --------- INIT ---------
* Initialization of this function
* is only being done once at the start of the function
*/
void simpleThread_setup(THREAD_DifferentialPressure)
{
/* Init Function */
//diff_p_RA.clear; // Running Average for diff. pressure; explicitly start clean
}
/* --------- LOOP ----------
* This is the place for code which is going to be repeated constantly
* e.g. a time-diplay or the like.
*/
boolean simpleThread_loop(THREAD_DifferentialPressure)
{
/* Loop Function */
diff_p_RA.add(getDifferentialPressure()); // read out the sensor value and add to averaging variable
// set averaged differential pressure - pressure offset set by the user
diff_Pressure = diff_p_RA.getAverage() - offset_diff_pressure;
diff_Pressure_median = diff_p_RA.getMedian() - offset_diff_pressure;
Serial.print(diff_Pressure);
Serial.print(";");
Serial.println(diff_Pressure_median);
if (isnan(diff_Pressure) || diff_Pressure < 0.00)
{
diff_Pressure = 0.00; // set diff_Pressure to zero if the reading is NaN - Not a Number, or lower than zero
}
return true;
}
The results of these measurements can be found in the attached pdf file "Diff_Pressure_averaged_median.pdf". Now there is something strange about the averaging value. The buffer size seems not to change. even the 200 value buffer size ("RunningMedian diff_p_RA(200); ") looks more like the 25 or even 10. The RunningMedian Code I used is from your (Rob Tillaart) github repository. Furthermore, I expected something else from the RunningMedian. Let me know what you think.
Best regards,
Jan
P.S.: I now added the raw data of these measurements.
Diff_Pressure_averaged_median.pdf (893 KB)
Diff_Pressure_averaged_median.zip (2.46 MB)