|
@ -1,5 +1,5 @@ |
|
|
// ----------------------------------------------------------------------------- |
|
|
// ----------------------------------------------------------------------------- |
|
|
// Stream Injector |
|
|
|
|
|
|
|
|
// Median Filter |
|
|
// ----------------------------------------------------------------------------- |
|
|
// ----------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
#pragma once |
|
|
#pragma once |
|
@ -16,27 +16,25 @@ class MedianFilter { |
|
|
if (_data) delete _data; |
|
|
if (_data) delete _data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual void add(double value) { |
|
|
|
|
|
_data->push_back(value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual unsigned char count() { |
|
|
|
|
|
return _data->size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
virtual void reset() { |
|
|
virtual void reset() { |
|
|
double last = _data->empty() ? 0 : _data->back(); |
|
|
double last = _data->empty() ? 0 : _data->back(); |
|
|
_data->clear(); |
|
|
_data->clear(); |
|
|
add(last); |
|
|
add(last); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
virtual void add(double value) { |
|
|
|
|
|
_data->push_back(value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual double median(bool do_reset = false) { |
|
|
|
|
|
|
|
|
virtual double result(bool do_reset = false) { |
|
|
|
|
|
|
|
|
double sum = 0; |
|
|
double sum = 0; |
|
|
|
|
|
|
|
|
if (_data->size() == 1) { |
|
|
|
|
|
sum = _data->back(); |
|
|
|
|
|
|
|
|
|
|
|
} else if (_data->size() == 2) { |
|
|
|
|
|
sum = _data->front(); |
|
|
|
|
|
|
|
|
|
|
|
} else if (_data->size() > 2) { |
|
|
|
|
|
|
|
|
if (_data->size() > 2) { |
|
|
|
|
|
|
|
|
for (unsigned char i = 1; i <= _data->size() - 2; i++) { |
|
|
for (unsigned char i = 1; i <= _data->size() - 2; i++) { |
|
|
|
|
|
|
|
@ -54,6 +52,10 @@ class MedianFilter { |
|
|
|
|
|
|
|
|
sum /= (_data->size() - 2); |
|
|
sum /= (_data->size() - 2); |
|
|
|
|
|
|
|
|
|
|
|
} else if (_data->size() > 0) { |
|
|
|
|
|
|
|
|
|
|
|
sum = _data->front(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (do_reset) reset(); |
|
|
if (do_reset) reset(); |
|
@ -62,10 +64,6 @@ class MedianFilter { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
virtual unsigned char count() { |
|
|
|
|
|
return _data->size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
|
|
|
|
|
|
std::vector<double> *_data; |
|
|
std::vector<double> *_data; |
|
|