forked from DrGFreeman/SharpDistSensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MedianFilter.h
executable file
·67 lines (52 loc) · 2.49 KB
/
MedianFilter.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
/*
MedianFilter.h - Median Filter for the Arduino platform.
Copyright (c) 2013 Phillip Schmidt. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
A median filter object is created by by passing the desired filter window size on object creation.
The window size should be an odd number between 3 and 255.
New data is added to the median filter by passing the data through the in() function. The new medial value is returned.
The new data will over-write the oldest data point, then be shifted in the array to place it in the correct location.
The current median value is returned by the out() function for situations where the result is desired without passing in new data.
!!! All data must be type INT. !!!
*/
#ifndef MedianFilter_h
#define MedianFilter_h
#include "Arduino.h"
class MedianFilter
{
public:
MedianFilter(int size, int seed);
int in(const int & value);
int out();
int getMin();
int getMax();
int getMean();
int getStDev();
/*
void printData(); // used for debugging
void printSizeMap();
void printLocationMap();
void printSortedData();
*/
private:
uint8_t medFilterWin; // number of samples in sliding median filter window - usually odd #
uint8_t medDataPointer; // mid point of window
int * data; // array pointer for data sorted by age in ring buffer
uint8_t * sizeMap; // array pointer for locations data in sorted by size
uint8_t * locationMap; // array pointer for data locations in history map
uint8_t oldestDataPoint; // oldest data point location in ring buffer
int32_t totalSum;
};
#endif