|
|
|
@ -35,9 +35,15 @@ public:
@@ -35,9 +35,15 @@ public:
|
|
|
|
|
// apply - Add a new raw value to the filter, retrieve the filtered result
|
|
|
|
|
virtual T apply(T sample); |
|
|
|
|
|
|
|
|
|
// get - get latest filtered value from filter (equal to the value returned by latest call to apply method)
|
|
|
|
|
virtual T get() const { |
|
|
|
|
return _output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
// private methods
|
|
|
|
|
uint8_t _return_element; |
|
|
|
|
T _output; |
|
|
|
|
void isort(T sample, bool drop_high_sample); |
|
|
|
|
bool drop_high_sample; // switch to determine whether to drop the highest or lowest sample when new value arrives
|
|
|
|
|
}; |
|
|
|
@ -63,6 +69,11 @@ typedef ModeFilter<uint16_t,4> ModeFilterUInt16_Size4;
@@ -63,6 +69,11 @@ typedef ModeFilter<uint16_t,4> ModeFilterUInt16_Size4;
|
|
|
|
|
typedef ModeFilter<uint16_t,5> ModeFilterUInt16_Size5; |
|
|
|
|
typedef ModeFilter<uint16_t,6> ModeFilterUInt16_Size6; |
|
|
|
|
typedef ModeFilter<uint16_t,7> ModeFilterUInt16_Size7; |
|
|
|
|
typedef ModeFilter<float,3> ModeFilterFloat_Size3; |
|
|
|
|
typedef ModeFilter<float,4> ModeFilterFloat_Size4; |
|
|
|
|
typedef ModeFilter<float,5> ModeFilterFloat_Size5; |
|
|
|
|
typedef ModeFilter<float,6> ModeFilterFloat_Size6; |
|
|
|
|
typedef ModeFilter<float,7> ModeFilterFloat_Size7; |
|
|
|
|
|
|
|
|
|
// Constructor //////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
@ -91,10 +102,10 @@ T ModeFilter<T,FILTER_SIZE>:: apply(T sample)
@@ -91,10 +102,10 @@ T ModeFilter<T,FILTER_SIZE>:: apply(T sample)
|
|
|
|
|
// return results
|
|
|
|
|
if( FilterWithBuffer<T,FILTER_SIZE>::sample_index < FILTER_SIZE ) { |
|
|
|
|
// middle sample if buffer is not yet full
|
|
|
|
|
return FilterWithBuffer<T,FILTER_SIZE>::samples[(FilterWithBuffer<T,FILTER_SIZE>::sample_index / 2)]; |
|
|
|
|
return _output = FilterWithBuffer<T,FILTER_SIZE>::samples[(FilterWithBuffer<T,FILTER_SIZE>::sample_index / 2)]; |
|
|
|
|
}else{ |
|
|
|
|
// return element specified by user in constructor
|
|
|
|
|
return FilterWithBuffer<T,FILTER_SIZE>::samples[_return_element]; |
|
|
|
|
return _output = FilterWithBuffer<T,FILTER_SIZE>::samples[_return_element]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|