2020-11-27 05:33:55 -05:00
|
|
|
#pragma once
|
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
|
2021-01-29 06:31:58 -05:00
|
|
|
// VERSION: 0.4.3
|
2011-10-09 16:06:19 -04:00
|
|
|
// PURPOSE: Recursive Statistical library for Arduino
|
|
|
|
// HISTORY: See Statistic.cpp
|
|
|
|
//
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2017-09-27 02:42:54 -04:00
|
|
|
#include <Arduino.h>
|
2011-10-09 16:06:19 -04:00
|
|
|
#include <math.h>
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
#define STATISTIC_LIB_VERSION (F("0.4.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:
|
2021-01-29 06:31:58 -05:00
|
|
|
Statistic(bool useStdDev = true); // "switches on/off" stdev run time
|
|
|
|
void clear(bool useStdDev = true); // "switches on/off" stdev run time
|
|
|
|
float add(const float); // returns value actually added
|
|
|
|
|
|
|
|
|
|
|
|
// returns the number of values added
|
|
|
|
uint32_t count() const { return _cnt; }; // zero if count == zero
|
|
|
|
float sum() const { return _sum; }; // zero if count == zero
|
|
|
|
float minimum() const { return _min; }; // zero if count == zero
|
|
|
|
float maximum() const { return _max; }; // zero if count == zero
|
|
|
|
float average() const; // NAN if count == zero
|
|
|
|
|
|
|
|
|
|
|
|
// useStdDev must be true to use next three
|
|
|
|
float variance() const; // NAN if count == zero
|
|
|
|
float pop_stdev() const; // population stdev // NAN if count == zero
|
|
|
|
float unbiased_stdev() const; // NAN if count == zero
|
|
|
|
|
2011-10-09 16:06:19 -04:00
|
|
|
|
|
|
|
protected:
|
2021-01-29 06:31:58 -05:00
|
|
|
uint32_t _cnt;
|
|
|
|
float _sum;
|
|
|
|
float _min;
|
|
|
|
float _max;
|
|
|
|
bool _useStdDev;
|
|
|
|
float _ssqdif; // sum of squares difference
|
2020-11-27 05:33:55 -05:00
|
|
|
|
2011-10-09 16:06:19 -04:00
|
|
|
};
|
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
// -- END OF FILE --
|