0.3.7 Histogram

This commit is contained in:
Rob Tillaart 2024-05-26 11:07:34 +02:00
parent bf6dfb798c
commit 66d02b94cf
8 changed files with 144 additions and 5 deletions

View File

@ -6,12 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.7] - 2024-05-25
- add examples **hist_pointer.ino** and **hist_array.ino**
- issue #10 spin off library https://github.com/RobTillaart/Kurtosis
- minor edits
## [0.3.6] - 2024-01-03
- add **float saturation()**
- fix examples
- minor edits
## [0.3.5] - 2023-11-04
- update readme.md
- minor fix in changelog.md

View File

@ -0,0 +1,75 @@
//
// FILE: hist_array.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo histogram array
// URL: https://github.com/RobTillaart/Histogram
#include "histogram.h"
// float b[] = { 0, 100, 200, 300, 325, 350, 375, 400, 500, 600, 700, 800, 900, 1000 };
// boundaries does not need to be equally distributed.
float a[] = {
0, 50, 125, 200, 250, 350, 500
};
float b[] = {
0, 100, 200, 300, 325, 350, 375, 450
};
Histogram hist[2] = { Histogram(7, a), Histogram(8, b)};
uint32_t lastTime = 0;
const uint32_t threshold = 25; // in milliseconds, for updating display
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HISTOGRAM_LIB_VERSION: ");
Serial.println(HISTOGRAM_LIB_VERSION);
Serial.println();
}
void loop()
{
// choose a "generator" for histogram data
// int x = analogRead(A0);
int x = random(600) - 50; // below lower limit
hist[0].add(x);
hist[1].add(x);
// update output
uint32_t now = millis();
if (now - lastTime > threshold)
{
lastTime = now;
Serial.print(hist[0].count());
for (uint16_t i = 0; i < hist[0].size(); i++)
{
Serial.print("\t");
Serial.print(hist[0].frequency(i), 2);
}
Serial.println();
Serial.print(hist[1].count());
for (uint16_t i = 0; i < hist[1].size(); i++)
{
Serial.print("\t");
Serial.print(hist[1].frequency(i), 2);
}
Serial.println();
if (hist[0].count() > 10000UL) hist[0].clear();
if (hist[1].count() > 10000UL) hist[1].clear();
}
}
// -- END OF FILE --

View File

@ -0,0 +1,59 @@
//
// FILE: hist_pointer.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo histogram pointer
// URL: https://github.com/RobTillaart/Histogram
#include "histogram.h"
// boundaries does not need to be equally distributed.
float a[] = {
0, 50, 125, 200, 250, 350, 500
};
float b[] = {
0, 100, 200, 300, 325, 350, 375, 400
};
Histogram histA(7, a);
Histogram histB(8, b);
Histogram *phist;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HISTOGRAM_LIB_VERSION: ");
Serial.println(HISTOGRAM_LIB_VERSION);
Serial.println();
phist = &histA;
}
void loop()
{
phist->clear();
for (int i = 0; i < 10000; i++)
{
int x = random(600) - 50;
phist->add(x);
}
Serial.print(phist->count());
for (uint16_t i = 0; i < phist->size(); i++)
{
Serial.print("\t");
Serial.print(phist->frequency(i), 2);
}
Serial.println();
// swap
if (phist == &histA) phist = &histB;
else phist = &histA;
}
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
// FILE: Histogram.cpp
// AUTHOR: Rob Tillaart
// DATE: 2012-11-10
// VERSION: 0.3.6
// VERSION: 0.3.7
// PURPOSE: Histogram library for Arduino
// URL: https://github.com/RobTillaart/Histogram

View File

@ -3,7 +3,7 @@
// FILE: Histogram.h
// AUTHOR: Rob Tillaart
// DATE: 2012-11-10
// VERSION: 0.3.6
// VERSION: 0.3.7
// PURPOSE: Histogram library for Arduino
// URL: https://github.com/RobTillaart/Histogram

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Histogram.git"
},
"version": "0.3.6",
"version": "0.3.7",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=Histogram
version=0.3.6
version=0.3.7
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for creating histograms math.

View File

@ -31,6 +31,7 @@ If you need more quantitative analysis, you might need the statistics library,
- https://github.com/RobTillaart/Correlation
- https://github.com/RobTillaart/GST - Golden standard test metrics
- https://github.com/RobTillaart/Histogram
- https://github.com/RobTillaart/Kurtosis
- https://github.com/RobTillaart/RunningAngle
- https://github.com/RobTillaart/RunningAverage
- https://github.com/RobTillaart/RunningMedian