added support to change thresholds independently

This commit is contained in:
Ahmet Inan 2020-04-19 15:19:49 +02:00
commit 707f6539de

View file

@ -11,19 +11,22 @@ namespace DSP {
template <typename TYPE> template <typename TYPE>
class SchmittTrigger class SchmittTrigger
{ {
TYPE threshold; TYPE low, high;
bool previous; bool previous;
public: public:
constexpr SchmittTrigger(TYPE threshold = TYPE(1)/TYPE(3), bool previous = false) : threshold(threshold), previous(previous) constexpr SchmittTrigger(TYPE threshold = TYPE(1)/TYPE(3), bool previous = false) : low(-threshold), high(threshold), previous(previous)
{
}
constexpr SchmittTrigger(TYPE low, TYPE high, bool previous = false) : low(low), high(high), previous(previous)
{ {
} }
bool operator() (TYPE input) bool operator() (TYPE input)
{ {
if (previous) { if (previous) {
if (input < -threshold) if (input < low)
previous = false; previous = false;
} else { } else {
if (input > threshold) if (input > high)
previous = true; previous = true;
} }
return previous; return previous;