-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunningMedian.h
68 lines (57 loc) · 1.33 KB
/
RunningMedian.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef RunningMedian_h
#define RunningMedian_h
//
// FILE: RunningMedian.h
// AUTHOR: Rob dot Tillaart at gmail dot com
// PURPOSE: RunningMedian library for Arduino
// VERSION: 0.1.04.waspmote
// URL: http://arduino.cc/playground/Main/RunningMedian
// HISTORY: See RunningMedian.cpp
//
// Released to the public domain
//
// Start of fixes for Waspmote
// #if defined(ARDUINO) && ARDUINO >= 100
// #include "Arduino.h"
// #else
// #include "WProgram.h"
// #endif
#include <math.h>
#include "wiring.h"
typedef uint8_t boolean;
// End of fixes for Waspmote
#include <inttypes.h>
#define RUNNING_MEDIAN_VERSION "0.1.04"
// should at least be 5 to be practical
#define MEDIAN_MIN_SIZE 1
#define MEDIAN_MAX_SIZE 19
#define MEDIAN_DEF_SIZE 5
// conditional compile to minimize lib
#define RUNNING_MEDIAN_ALL
class RunningMedian
{
public:
RunningMedian(uint8_t);
RunningMedian();
void clear();
void add(float);
float getMedian();
#ifdef RUNNING_MEDIAN_ALL
float getAverage();
float getAverage(uint8_t);
float getHighest();
float getLowest();
uint8_t getSize();
uint8_t getCount();
#endif
protected:
boolean _sorted;
uint8_t _size;
uint8_t _cnt;
uint8_t _idx;
float _ar[MEDIAN_MAX_SIZE];
float _as[MEDIAN_MAX_SIZE];
void sort();
};
#endif
// END OF FILE