103 lines
2.2 KiB
C
Raw Normal View History

2020-11-27 11:16:22 +01:00
#pragma once
//
// FILE: Histogram.h
// AUTHOR: Rob Tillaart
2023-11-05 10:18:54 +01:00
// VERSION: 0.3.5
// PURPOSE: Histogram library for Arduino
// DATE: 2012-11-10
2021-11-04 12:32:04 +01:00
#include "Arduino.h"
2023-11-05 10:18:54 +01:00
#define HISTOGRAM_LIB_VERSION (F("0.3.5"))
2023-07-24 12:51:25 +02:00
// return STATUS add(), sub(), clear(), setBucket();
#define HISTO_OK 0x00 // idem
#define HISTO_FULL 0x01 // just got full
#define HISTO_ERR_FULL 0xFF // over- underflow
#define HISTO_ERR_LENGTH 0xFE // constructor issue.
2021-11-04 12:32:04 +01:00
class Histogram
{
public:
2023-07-24 12:51:25 +02:00
Histogram(const uint16_t length, float * bounds);
~Histogram();
2023-07-24 12:51:25 +02:00
uint8_t clear(int32_t value = 0);
uint8_t add(const float value);
uint8_t sub(const float value);
virtual uint8_t setBucket(const uint16_t index, int32_t value = 0);
// returns last known status
uint8_t status();
2022-11-09 10:42:12 +01:00
// number of buckets
uint16_t size();
2022-11-09 10:42:12 +01:00
// number of values added to all buckets
uint32_t count();
2021-11-04 12:32:04 +01:00
2022-11-09 10:42:12 +01:00
// number of values added to single bucket
2021-11-04 12:32:04 +01:00
int32_t bucket(const uint16_t index);
float frequency(const uint16_t index);
float PMF(const float value);
float CDF(const float value);
2023-02-22 10:34:45 +01:00
float VAL(const float probability);
2023-07-24 12:51:25 +02:00
int32_t sum();
2021-11-04 12:32:04 +01:00
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);
2023-07-24 12:51:25 +02:00
// use with care
int32_t getMaxBucket();
void setMaxBucket(int32_t value);
protected:
float * _bounds;
int32_t * _data;
2021-11-04 12:32:04 +01:00
uint16_t _length;
uint32_t _count;
2023-07-24 12:51:25 +02:00
int32_t _maxBucket;
uint8_t _status;
2021-11-04 12:32:04 +01:00
};
//////////////////////////////////////////////////////////////
//
// DERIVED CLASS
//
class Histogram16 : public Histogram
{
public:
2023-07-24 12:51:25 +02:00
Histogram16(const uint16_t length, float * bounds);
2021-11-04 12:32:04 +01:00
~Histogram16();
2023-07-24 12:51:25 +02:00
uint8_t setBucket(const uint16_t index, int16_t value = 0);
2021-11-04 12:32:04 +01:00
protected:
int16_t * _data;
};
2021-11-04 12:32:04 +01:00
class Histogram8 : public Histogram
{
public:
2023-07-24 12:51:25 +02:00
Histogram8(const uint16_t length, float * bounds);
2021-11-04 12:32:04 +01:00
~Histogram8();
2023-07-24 12:51:25 +02:00
uint8_t setBucket(const uint16_t index, int8_t value = 0);
2021-11-04 12:32:04 +01:00
protected:
int8_t * _data;
};
2023-02-22 10:34:45 +01:00
// -- END OF FILE --
2021-11-04 12:32:04 +01:00