|
@ -12,9 +12,13 @@ class MedianFilter : public BaseFilter { |
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
virtual void reset() { |
|
|
virtual void reset() { |
|
|
|
|
|
|
|
|
|
|
|
// When resetting we get the last value |
|
|
|
|
|
// and make it the first of the new series |
|
|
double last = _data.empty() ? 0 : _data.back(); |
|
|
double last = _data.empty() ? 0 : _data.back(); |
|
|
_data.clear(); |
|
|
_data.clear(); |
|
|
add(last); |
|
|
add(last); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
virtual double result() { |
|
|
virtual double result() { |
|
@ -25,9 +29,13 @@ class MedianFilter : public BaseFilter { |
|
|
|
|
|
|
|
|
for (unsigned char i = 1; i <= _data.size() - 2; i++) { |
|
|
for (unsigned char i = 1; i <= _data.size() - 2; i++) { |
|
|
|
|
|
|
|
|
double previous = _data.at(i-1); |
|
|
|
|
|
double current = _data.at(i); |
|
|
|
|
|
double next = _data.at(i+1); |
|
|
|
|
|
|
|
|
// For each position, |
|
|
|
|
|
// we find the median with the previous and next value |
|
|
|
|
|
// and use that for the sum |
|
|
|
|
|
|
|
|
|
|
|
double previous = _data[i-1]; |
|
|
|
|
|
double current = _data[i]; |
|
|
|
|
|
double next = _data[i+1]; |
|
|
|
|
|
|
|
|
if (previous > current) std::swap(previous, current); |
|
|
if (previous > current) std::swap(previous, current); |
|
|
if (current > next) std::swap(current, next); |
|
|
if (current > next) std::swap(current, next); |
|
|