Hi there,
I´m using the runningAverage library and got some problems when clearing the averaging variabel every 300 counts.
Now, I did a Measurement series showing my raw sensor data and the avaregd data (see attached Differenzdruck_gemittelt_100.pdf). Looking at these curves, it is clearly visible that my avareged sensor data is going bogus when the averaging variabel is cleared after 300 samples. Now, looking at the library I found the option to use the a "fillvalue" instead. As the code is not that good commented, I just thought to ask what it actually does. However, Im loosing the peaks in my sensor data but seems to oscillate now. Well, to make a long story short, could someone explain the fillvalue feature of the running average library in more detail.
Code using the running average (plain and simple)
/*
*************************************
* Thread: THREAD_DifferentialPressure
* Get`s the differential pressure.
*************************************
*/
/* Global variables for this function */
float diff_Pressure = 0;
float offset_diff_pressure; // offset which can be set by the user -> FUNC_OffsetDiffPressure (X_E_LCDML_MenuFunctions)
RunningAverage diff_p_RA(100); // use default size for running average for differential pressure
int diff_p_samples = 0; // create a samples counter
/* --------- 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.addValue(getDifferentialPressure()); // read out the sensor value and add to averaging variable
diff_p_samples++; // increase samples counter
// set averaged differential pressure - pressure offset set by the user
diff_Pressure = diff_p_RA.getAverage() - offset_diff_pressure;
Serial.println(diff_Pressure);
if (diff_p_samples == 300) // handle large samplenumbers...
{
diff_p_samples = 0; // ...delete samples counter, and...
diff_p_RA.clear(); // ...clear the averaging variable.
}
else 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;
}
Same code using the running average wih the fill value option:
/*
*************************************
* Thread: THREAD_DifferentialPressure
* Get`s the differential pressure.
*************************************
*/
/* Global variables for this function */
float diff_Pressure = 0;
float offset_diff_pressure; // offset which can be set by the user -> FUNC_OffsetDiffPressure (X_E_LCDML_MenuFunctions)
RunningAverage diff_p_RA(100); // use default size for running average for differential pressure
int diff_p_samples = 0; // create a samples counter
/* --------- 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.fillValue(0,50); // 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.addValue(getDifferentialPressure()); // read out the sensor value and add to averaging variable
diff_p_samples++; // increase samples counter
// set averaged differential pressure - pressure offset set by the user
diff_Pressure = diff_p_RA.getAverage() - offset_diff_pressure;
if (diff_p_samples == 300) // handle large samplenumbers...
{
diff_p_samples = 0; // ...delete samples counter, and...
diff_p_RA.fillValue(diff_Pressure, 25); // ...clear the averaging variable.
}
else 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;
}
Thank you for any help.
Best regards,
Jan
Differenzdruck_gemittelt_100.pdf (182 KB)