Files
firmware/Filters/median3.hpp

19 lines
529 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// быстрый медианный фильтр 3-го порядка
#ifndef _GMedian3_h
#define _GMedian3_h
template < typename TYPE >
class GMedian3 {
public:
TYPE filtered(TYPE value) { // возвращает фильтрованное значение
buf[_counter] = value;
if (++_counter > 2) _counter = 0;
return (max(buf[0], buf[1]) == max(buf[1], buf[2])) ? max(buf[0], buf[2]) : max(buf[1], min(buf[0], buf[2]));
}
private:
TYPE buf[3];
uint8_t _counter = 0;
};
#endif