2011-10-09 16:06:19 -04:00
|
|
|
#ifndef Statistic_h
|
|
|
|
#define Statistic_h
|
2015-03-07 14:32:51 -05:00
|
|
|
//
|
2011-10-09 16:06:19 -04:00
|
|
|
// FILE: Statistic.h
|
2015-03-07 14:32:51 -05:00
|
|
|
// AUTHOR: Rob dot Tillaart at gmail dot com
|
2011-10-09 16:06:19 -04:00
|
|
|
// modified at 0.3 by Gil Ross at physics dot org
|
2017-07-31 15:40:26 -04:00
|
|
|
// VERSION: 0.3.4
|
2011-10-09 16:06:19 -04:00
|
|
|
// PURPOSE: Recursive Statistical library for Arduino
|
|
|
|
// HISTORY: See Statistic.cpp
|
|
|
|
//
|
|
|
|
// Released to the public domain
|
|
|
|
//
|
|
|
|
|
|
|
|
// the standard deviation increases the lib (<100 bytes)
|
2017-07-31 15:40:26 -04:00
|
|
|
// it can be in/excluded by un/commenting next line (compile time)
|
|
|
|
#define STAT_USE_STDEV 1
|
2011-10-09 16:06:19 -04:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2017-07-31 15:40:26 -04:00
|
|
|
#define STATISTIC_LIB_VERSION "0.3.4"
|
2013-08-17 09:08:50 -04:00
|
|
|
|
2015-03-07 14:32:51 -05:00
|
|
|
class Statistic
|
2011-10-09 16:06:19 -04:00
|
|
|
{
|
2015-03-07 14:32:51 -05:00
|
|
|
public:
|
2017-07-31 15:40:26 -04:00
|
|
|
Statistic(); // "switches on/off" stdev run time
|
|
|
|
void clear(); // "switches on/off" stdev run time
|
|
|
|
void add(const float);
|
2015-03-07 14:32:51 -05:00
|
|
|
|
|
|
|
// returns the number of values added
|
2017-07-31 15:40:26 -04:00
|
|
|
uint32_t count() const { return _cnt; }; // zero if empty
|
|
|
|
float sum() const { return _sum; }; // zero if empty
|
|
|
|
float minimum() const { return _min; }; // zero if empty
|
|
|
|
float maximum() const { return _max; }; // zero if empty
|
|
|
|
float average() const; // NAN if empty
|
2011-10-09 16:06:19 -04:00
|
|
|
|
|
|
|
#ifdef STAT_USE_STDEV
|
2017-07-31 15:40:26 -04:00
|
|
|
float variance() const; // NAN if empty
|
|
|
|
float pop_stdev() const; // population stdev // NAN if empty
|
|
|
|
float unbiased_stdev() const; // NAN if empty
|
2011-10-09 16:06:19 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
2017-07-31 15:40:26 -04:00
|
|
|
uint32_t _cnt;
|
|
|
|
float _sum;
|
|
|
|
float _min;
|
|
|
|
float _max;
|
2011-10-09 16:06:19 -04:00
|
|
|
#ifdef STAT_USE_STDEV
|
2017-07-31 15:40:26 -04:00
|
|
|
float _ssqdif; // sum of squares difference
|
2011-10-09 16:06:19 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2013-08-17 09:08:50 -04:00
|
|
|
// END OF FILE
|