The library statistically smooths a data serie by running statistics, namely average, median, minimum, or maximum. It calculates a new smoothed value from a couple of previously provided values.
- The library stores
5recently provided values, e.g., samples from a sensor reading, and calculates particular statistical value right after it from those values. - The library instance object acts as a sample cache for recent samples.
- gbj_apphelpers: Library for generic logics and calculations loaded from file
gbj_apphelpers.h.
- Arduino.h: Main include file for the Arduino SDK version greater or equal to 100.
- inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.
- Arduino.h: Main include file for the Arduino platform.
Particular constructor for desired statistic to be calculated. Each constructor initiates the internal data buffer acting as the cache within a class instance object, which keeps a serie of provided values, e.g., samples from a sensor's reading, for calculating a running statistic.
- Running values of samples from sensor reading reduce excesses and extremes in the physical value measurement.
gbj_running::average()
gbj_running::median()
gbj_running::minimum()
gbj_running::maximum()
None
Object preforming a particular running statistic calculation.
gbj_running runAvg = gbj_running::average();The method initiates all internal resources of a class instance object to default values as they are right after creating a library instance object.
void init()
None
None
The method is overloaded and returns a result of the recent smoothing calculation.
- If an input argument is provided, it calculates and returns a new running statistic from the input value and previously stored ones in the cache. This value is stored in the internal cache for the future calculation. At the same time the last value in the cache is removed.
- If no input argument is provided, the method returns the recently calculated running statistic without need of new recalculation.
- If the method without input value is used before the first using the method with input value since initiation either by creating the instance object or calling the method init(), the
0is retuned as a default statistic value. - The method is useful if there is no variable used for the running statistic in an application and the recent statistic is needed.
float getValue(float value)
float getValue()
- value: Value (sample) to be used for calculating a new running statistic.
- Valid values: float
- Default value: none
Running statistic of default statistic type or recently calculated running statistic.
The method returns current number of samples in the internal cache, which are going to be used for calculating running statistics.
- The calculation of a running value can be provided before the cache is full. It happens at start of the smoothing process after initialization by either creating the instance object or calling the method init(). In that case the method returns the number less than the length of the buffer.
byte getSamples()
None
Actual number of samples in the cache.