Skip to content

Latest commit

 

History

History
67 lines (42 loc) · 1.6 KB

README.md

File metadata and controls

67 lines (42 loc) · 1.6 KB

Statistics Library (version: 1.0)

© 2012-2013 Scott Daniels <provideyourown.com> under GNU General Public License

The Statistics Library permits you to easily perform statistical analysis on data collected. This information can be useful for determining data quality as well as smoothing jittery readings such as those from touch sensors.

In order to conserve precious SRAM when necessary, two versions of the library are available:

IntStatistics.h - uses only integer math Statistics.h - uses floating point math

The inclusion of floating point math in an Arduino sketch will consume over 200 bytes of SRAM in overhead.

Methods

Construction & Configuration

Statistics(numSamples) - specify the number of samples to be collected

void setNewSampleSize(numSamples) - change the sample size (will reset any data collected)

void reset() - reset the collected data

Adding data

void addData(val) - add a data point to the collection

Data Analysis

[type] mean() - the arthemetic mean of the data collected

[type] variance() - the variance of the data

[type] stdDeviation() - the standard deviation (NOT available in the integer version)

[type] maxVal() - the maximum data point

[type] minVal() - the minimum data point

Usage example

#include <Statistics.h>

Statistics stats(10);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int data = analogRead(A0);
  stats.addData(data);
  
  Serial.print("Mean: ");
  Serial.print(stats.mean());
  Serial.print(" Std Dev: ");
  Serial.println(stats.stdDeviation());
}