followup of - http://forum.arduino.cc/index.php/topic,38092.0.html -
updated the statistics library to version 0.3.3.
changed floats to double to support ARM boards like DUE.
Comments and remarks are welcome,
Rob
I need some help. I am trying to use this to record average temperature. What is the purpose of dividing the value you are adding by 100? I have also seen this in the running average library as well. I could not get that one to work to save my life. The average was always equal to the current reading?
myStats.add(rn/100.0);
that is just a demo and by dividing it by 100.0 it is forced to be a float.
Oh ok. I got it working and it looks like it is actually giving me an average! Thanks
I modified the library.
Hopefully, this version is not too buggy, and is numerically stable.
WARNING: Untested code!!!
Statistic.cpp (1.99 KB)
Statistic.h (1.4 KB)
How was this one changed I have not had any issues with the previous?
The version of odometer uses Kahan summation - Kahan summation algorithm - Wikipedia
This kind of summation helps to keep accuracy if one need to add up a set of numbers with a dynamic range larger than the scope of the mantisse of the IEEE754 float .
In normal peoples language,
if you add a small number to a big number, the big number does not change.
if you add a zillion small numbers to a big number it still does not changes
If you do the addition according to the kahan sum, it eventually does change. (it adds up the addition errors)
@odometer
looks good, impact on footprint and performance is quite minimal.
needs substantial testing to see improvement in practice (will take time)
furthermore I need to think how to embed this in the lib (I'm thinking of a #define to switch it on/off)