2011-10-09 16:06:19 -04:00
|
|
|
#ifndef Statistic_h
|
|
|
|
#define Statistic_h
|
2013-08-17 09:44:20 -04:00
|
|
|
//
|
2011-10-09 16:06:19 -04:00
|
|
|
// FILE: Statistic.h
|
2013-08-17 09:44:20 -04: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
|
|
|
|
// 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>
|
|
|
|
|
2013-08-17 09:44:20 -04:00
|
|
|
#define STATISTIC_LIB_VERSION "0.3.2"
|
2013-08-17 09:08:50 -04:00
|
|
|
|
2013-08-17 09:44:20 -04:00
|
|
|
class Statistic
|
2011-10-09 16:06:19 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Statistic();
|
|
|
|
void clear();
|
|
|
|
void add(float);
|
2013-08-17 09:44:20 -04:00
|
|
|
unsigned long count();
|
2011-10-09 16:06:19 -04:00
|
|
|
float sum();
|
|
|
|
float average();
|
|
|
|
float minimum();
|
|
|
|
float maximum();
|
|
|
|
|
|
|
|
#ifdef STAT_USE_STDEV
|
2013-08-17 09:44:20 -04:00
|
|
|
float variance();
|
2011-10-09 16:06:19 -04:00
|
|
|
float pop_stdev(); // population stdev
|
|
|
|
float unbiased_stdev();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
2013-08-17 09:44:20 -04:00
|
|
|
unsigned long _cnt;
|
2011-10-09 16:06:19 -04:00
|
|
|
float _store; // store to minimise computation
|
|
|
|
float _sum;
|
|
|
|
float _min;
|
|
|
|
float _max;
|
|
|
|
#ifdef STAT_USE_STDEV
|
|
|
|
float _ssqdif; // sum of squares difference
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2013-08-17 09:08:50 -04:00
|
|
|
// END OF FILE
|