a floating median filter to filter floating point data such as analog inputs
Fork of filter by
Diff: filter.cpp
- Revision:
- 1:9ce370b360ba
- Parent:
- 0:46a72e790df8
diff -r 46a72e790df8 -r 9ce370b360ba filter.cpp --- a/filter.cpp Wed Feb 16 20:05:42 2011 +0000 +++ b/filter.cpp Wed Apr 01 11:18:55 2015 +0000 @@ -1,9 +1,9 @@ #include <float.h> #include "filter.h" -medianFilter::medianFilter(int window): N(window) { +filter::filter(int window): N(window) { big = new bool[N]; - val = new float[N]; + val = new double[N]; big = new bool[N]; i = 0; for (int j = 0; j < N; j++) { @@ -14,8 +14,8 @@ median=0; } -int medianFilter::findmax() { - float m = -FLT_MAX; +int filter::findmax() { + double m = -FLT_MAX; int n = -1; for (int j = 0; j < N; j++) { if (j == med) continue; @@ -29,8 +29,8 @@ return n; } -int medianFilter::findmin() { - float m = FLT_MAX; +int filter::findmin() { + double m = FLT_MAX; int n = -1; for (int j = 0; j < N; j++) { if (big[j]) { //find min @@ -43,7 +43,7 @@ return n; } -float medianFilter::process(float in) { +double filter::process(double in) { //the value at position 'i' is to be replaced by 'in' and the new median is computed //var 'median' refers to the old median // val[j] <= median <= val[k] @@ -79,3 +79,8 @@ median = val[med]; return median; } + +double filter::getMedian() +{ + return median; +}