Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

01.03.00 Initial update #8

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# Data Stream Statistical Library
# Statistical
> version 1.3.0

Descriptive statistics for Arduino float arrays

We developed this library to help quickly accomplish median and mode filtering when collecting sensor data. Functions in this library operate on an array of float variables, of dimension "m", and return the corresponding statistic. This library was originally created for a data smoothing strategy for float variables. Using a median or mode filtering strategy (opposed to mean filtering) is better at removing spikes from aberrant readings.

A bubble sort algorithm is also contained in this library which was necessary to calculate median and mode.

### Array Statistics

Array_Sum
Array_Max
Array_Min
Array_Sq_Sum
Array_Aritmetic_Average
Array_Geometric_Average
Array_RMS_Average
Array_Ext_RMS_Average
Array_Bubble_Sort
Array_Median
Array_Standart_Deviation
Array_Standart_Deviation_Error
Array_Coefficient_Factor
Array_Average

### Stream Statistics

Stream_Statistic
Data_Clear
LinearRegression

Stream_Average
Stream_Minimum
Stream_Maximum

Linear_Regression_MeanX
Linear_Regression_MeanX2
Linear_Regression_VarianceX
Linear_Regression_MeanY
Linear_Regression_MeanY2
Linear_Regression_MeanXY
Linear_Regression_VarianceY
Linear_Regression_CovarianceXY
Linear_Regression_a
Linear_Regression_b

Binary file added examples/.DS_Store
Binary file not shown.
16 changes: 3 additions & 13 deletions examples/Array/Array.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ void loop() {
// Set Data
Serial.println("Learning Data...");
float Data_Array[] = {220.14, 221.36, 218.21, 217.6, 215.7, 225.8, 220.14 };
int Data_Size = 7;
uint8_t Data_Size = 7;

// Print Array
Serial.print("Data Array : ");
for (uint8_t i = 0; i < sizeof(Data_Array); i++) {
Serial.print("[");
Serial.print(Data_Array[i]);
Serial.print("] ");
}
Serial.println("");
for (uint8_t i = 0; i < Data_Size; i++) {Serial.print("["); Serial.print(Data_Array[i]); Serial.print("] ");} Serial.println("");

// Print Stats
Serial.print("Array Sum : "); Serial.println(Stats.Array_Sum(Data_Array, Data_Size));
Expand All @@ -39,12 +34,7 @@ void loop() {
Serial.print("Array Coefficient Factor : "); Serial.println(Stats.Array_Coefficient_Factor(Data_Array, Data_Size));

Serial.print("Sorted Data Array : ");
for (uint8_t i = 0; i < sizeof(Data_Array); i++) {
Serial.print("[");
Serial.print(Data_Array[i]);
Serial.print("] ");
}
Serial.println("");
for (uint8_t i = 0; i < Data_Size; i++) {Serial.print("["); Serial.print(Data_Array[i]); Serial.print("] ");} Serial.println("");

Serial.println("--------------------------------------------------");

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Statistical",
"version": "1.2.0",
"version": "1.3.0",
"keywords": "Statistical, Max, Min, Average, Regression, Data, Sensor, Slope, Offset",
"description": "Function calculates statistical parameters of data stream and array",
"authors":
Expand Down
9 changes: 4 additions & 5 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name=Statistical
version=1.2.0
version=1.3.0
author=Gunce Akkoyun <akkoyun@me.com>
maintainer=Gunce Akkoyun <akkoyun@me.com>
sentence=Statistic, Max, Min, Average, Stream, Regression, Slope, Data, Analyse
sentence=Statistic, Sum, Max, Min, Sq_Sum, Aritmetic Average, Geometric Average, RMS Average, Ext RMS Average, Bubble Sort, Median, Standart Deviation, Standart Deviation Error, Coefficient Factor, Average, Stream, Regression, Slope, Data, Analyse
paragraph=Function calculates statistical parameters of data stream and array.
category=Other
category=Data Processing
url=https://github.com/akkoyun/Statistical
architectures=*

architectures=*
31 changes: 15 additions & 16 deletions src/Statistical.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* *******************************************************************************
* Copyright (C) 2014-2021 Mehmet Gunce Akkoyun Can not be copied and/or
* Copyright (C) 2014-2022 Mehmet Gunce Akkoyun Can not be copied and/or
* distributed without the express permission of Mehmet Gunce Akkoyun.
*
* Library : Data Stream Statistical Library
* Library : Data Statistical Library
* Code Developer : Mehmet Gunce Akkoyun (akkoyun@me.com)
* Revision : 01.01.02
*
*********************************************************************************/

#include "Statistical.h"
Expand Down Expand Up @@ -103,7 +101,7 @@ float Statistical::Array_Sum(float _Data[], uint16_t _Data_Count) {
}

// End Function
return(_Sum)
return(_Sum);

}
float Statistical::Array_Max(float _Data[], uint16_t _Data_Count) {
Expand All @@ -119,7 +117,7 @@ float Statistical::Array_Max(float _Data[], uint16_t _Data_Count) {
}

// End Function
return(_Max)
return(_Max);

}
float Statistical::Array_Min(float _Data[], uint16_t _Data_Count) {
Expand All @@ -135,7 +133,7 @@ float Statistical::Array_Min(float _Data[], uint16_t _Data_Count) {
}

// End Function
return(_Min)
return(_Min);

}
float Statistical::Array_Sq_Sum(float _Data[], uint16_t _Data_Count) {
Expand All @@ -151,7 +149,7 @@ float Statistical::Array_Sq_Sum(float _Data[], uint16_t _Data_Count) {
}

// End Function
return(_Sq_Sum)
return(_Sq_Sum);

}
float Statistical::Array_Aritmetic_Average(float _Data[], uint16_t _Data_Count) {
Expand All @@ -166,7 +164,7 @@ float Statistical::Array_Aritmetic_Average(float _Data[], uint16_t _Data_Count)
float _Average = _Sum / _Data_Count;

// End Function
return(_Average)
return(_Average);

}
float Statistical::Array_Geometric_Average(float _Data[], uint16_t _Data_Count) {
Expand All @@ -185,7 +183,7 @@ float Statistical::Array_Geometric_Average(float _Data[], uint16_t _Data_Count)
float _GAvg = exp(_GAvg_Sum);

// End Function
return(_GAvg)
return(_GAvg);

}
float Statistical::Array_RMS_Average(float _Data[], uint16_t _Data_Count) {
Expand All @@ -194,10 +192,10 @@ float Statistical::Array_RMS_Average(float _Data[], uint16_t _Data_Count) {
float _Sum = Array_Sq_Sum(_Data, _Data_Count);

// Calculate RSM Average
float _RMS_Avg = (sqrt(Array_Sq_Sum / _Data_Count));
float _RMS_Avg = (sqrt(_Sum / _Data_Count));

// End Function
return(_RMS_Avg)
return(_RMS_Avg);

}
float Statistical::Array_Ext_RMS_Average(float _Data[], uint16_t _Data_Count) {
Expand All @@ -219,13 +217,14 @@ float Statistical::Array_Ext_RMS_Average(float _Data[], uint16_t _Data_Count) {
float _Ext_RMS_Avg = (sqrt(_Sum / _Data_Count));

// End Function
return(_Ext_RMS_Avg)
return(_Ext_RMS_Avg);

}
void Statistical::Array_Bubble_Sort(float _Data[], uint16_t _Data_Count) {

// Declare Buffer Variables
uint16_t _New_n;
uint16_t _n = _Data_Count;
float _Temp = 0;

// Sort Array
Expand All @@ -249,10 +248,10 @@ void Statistical::Array_Bubble_Sort(float _Data[], uint16_t _Data_Count) {

}

} while (_Data_Count > 1);
} while (_New_n > 1);

}
void Statistical::Array_Median(float _Data[], uint16_t _Data_Count) {
float Statistical::Array_Median(float _Data[], uint16_t _Data_Count) {

// Sort Array
Array_Bubble_Sort(_Data, _Data_Count);
Expand All @@ -272,7 +271,7 @@ void Statistical::Array_Median(float _Data[], uint16_t _Data_Count) {
}

// End Function
return(_Median)
return(_Median);

}
float Statistical::Array_Standart_Deviation(float _Data[], uint16_t _Data_Count) {
Expand Down
6 changes: 3 additions & 3 deletions src/Statistical.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* *******************************************************************************
* Copyright (C) 2014-2020 Mehmet Gunce Akkoyun Can not be copied and/or
* Copyright (C) 2014-2022 Mehmet Gunce Akkoyun Can not be copied and/or
* distributed without the express permission of Mehmet Gunce Akkoyun.
*
* Library : Linear Regression Library
* Library : Data Statistical Library
* Code Developer : Mehmet Gunce Akkoyun (akkoyun@me.com)
*********************************************************************************/

Expand Down Expand Up @@ -46,8 +46,8 @@ class Statistical {
// Public Functions
// ************************************************************
void Stream_Statistic(float _Data);
void Data_Clear(void);
void LinearRegression(float _X, float _Y);
void Data_Clear(void);

/**
* @brief Calculate the array sum.
Expand Down