mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added support to change thresholds independently
This commit is contained in:
parent
27e8a40e1b
commit
707f6539de
1 changed files with 7 additions and 4 deletions
11
trigger.hh
11
trigger.hh
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue