2020-11-27 05:16:22 -05:00
|
|
|
#pragma once
|
2013-09-29 15:55:02 -04:00
|
|
|
//
|
2013-09-29 13:28:34 -04:00
|
|
|
// FILE: Histogram.h
|
2013-09-29 15:55:02 -04:00
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-09 04:42:12 -05:00
|
|
|
// VERSION: 0.3.2
|
2013-09-29 13:28:34 -04:00
|
|
|
// PURPOSE: Histogram library for Arduino
|
2013-09-29 15:55:02 -04:00
|
|
|
// DATE: 2012-11-10
|
2013-09-29 13:28:34 -04:00
|
|
|
//
|
|
|
|
|
2021-11-04 07:32:04 -04:00
|
|
|
|
2013-09-29 15:55:02 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2022-11-09 04:42:12 -05:00
|
|
|
#define HISTOGRAM_LIB_VERSION (F("0.3.2"))
|
2021-11-04 07:32:04 -04:00
|
|
|
|
2013-09-29 13:28:34 -04:00
|
|
|
|
2013-09-29 15:55:02 -04:00
|
|
|
class Histogram
|
2013-09-29 13:28:34 -04:00
|
|
|
{
|
2013-09-29 15:55:02 -04:00
|
|
|
public:
|
2021-11-04 07:32:04 -04:00
|
|
|
Histogram(const uint16_t length, float *bounds);
|
2017-07-27 07:13:41 -04:00
|
|
|
~Histogram();
|
|
|
|
|
2021-11-04 07:32:04 -04:00
|
|
|
void clear(int32_t value = 0);
|
2022-11-09 04:42:12 -05:00
|
|
|
void setBucket(const uint16_t index, int32_t value = 0);
|
2021-11-04 07:32:04 -04:00
|
|
|
void add(const float value);
|
|
|
|
void sub(const float value);
|
2017-07-27 07:13:41 -04:00
|
|
|
|
2022-11-09 04:42:12 -05:00
|
|
|
// number of buckets
|
|
|
|
uint16_t size();
|
2017-07-27 07:13:41 -04:00
|
|
|
|
2022-11-09 04:42:12 -05:00
|
|
|
// number of values added to all buckets
|
|
|
|
uint32_t count();
|
2021-11-04 07:32:04 -04:00
|
|
|
|
2022-11-09 04:42:12 -05:00
|
|
|
// number of values added to single bucket
|
2021-11-04 07:32:04 -04:00
|
|
|
int32_t bucket(const uint16_t index);
|
|
|
|
|
|
|
|
float frequency(const uint16_t index);
|
|
|
|
float PMF(const float value);
|
|
|
|
float CDF(const float value);
|
|
|
|
float VAL(const float prob);
|
|
|
|
|
|
|
|
uint16_t find(const float value);
|
|
|
|
uint16_t findMin();
|
|
|
|
uint16_t findMax();
|
|
|
|
uint16_t countLevel(const int32_t level);
|
|
|
|
uint16_t countAbove(const int32_t level);
|
|
|
|
uint16_t countBelow(const int32_t level);
|
2017-07-27 07:13:41 -04:00
|
|
|
|
2013-09-29 13:28:34 -04:00
|
|
|
|
|
|
|
protected:
|
2017-07-27 07:13:41 -04:00
|
|
|
float * _bounds;
|
|
|
|
int32_t * _data;
|
2021-11-04 07:32:04 -04:00
|
|
|
uint16_t _length;
|
|
|
|
uint32_t _count;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DERIVED CLASS
|
|
|
|
//
|
|
|
|
|
|
|
|
class Histogram16 : public Histogram
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Histogram16(const uint16_t length, float *bounds);
|
|
|
|
~Histogram16();
|
|
|
|
protected:
|
|
|
|
int16_t * _data;
|
2013-09-29 13:28:34 -04:00
|
|
|
};
|
|
|
|
|
2021-11-04 07:32:04 -04:00
|
|
|
|
|
|
|
class Histogram8 : public Histogram
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Histogram8(const uint16_t length, float *bounds);
|
|
|
|
~Histogram8();
|
|
|
|
protected:
|
|
|
|
int8_t * _data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
// -- END OF FILE --
|
2021-11-04 07:32:04 -04:00
|
|
|
|