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
|
2015-03-07 14:32:51 -05:00
|
|
|
// VERSION: 0.3.3
|
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)
|
|
|
|
// it can be in/excluded by un/commenting next line
|
|
|
|
#define STAT_USE_STDEV
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2015-03-07 14:32:51 -05:00
|
|
|
#define STATISTIC_LIB_VERSION "0.3.3"
|
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:
|
|
|
|
Statistic();
|
|
|
|
void clear();
|
|
|
|
void add(double);
|
|
|
|
|
|
|
|
// returns the number of values added
|
|
|
|
unsigned long count() { return _cnt; }; // zero if empty
|
|
|
|
double sum() { return _sum; }; // zero if empty
|
|
|
|
double minimum() { return _min; }; // zero if empty
|
|
|
|
double maximum() { return _max; }; // zero if empty
|
|
|
|
double average();
|
2011-10-09 16:06:19 -04:00
|
|
|
|
|
|
|
#ifdef STAT_USE_STDEV
|
2015-03-07 14:32:51 -05:00
|
|
|
double variance();
|
|
|
|
double pop_stdev(); // population stdev
|
|
|
|
double unbiased_stdev();
|
2011-10-09 16:06:19 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
2015-03-07 14:32:51 -05:00
|
|
|
unsigned long _cnt;
|
|
|
|
double _store; // store to minimise computation
|
|
|
|
double _sum;
|
|
|
|
double _min;
|
|
|
|
double _max;
|
2011-10-09 16:06:19 -04:00
|
|
|
#ifdef STAT_USE_STDEV
|
2015-03-07 14:32:51 -05:00
|
|
|
double _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
|