mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added Schmitt trigger and edge triggers
This commit is contained in:
parent
d2b1bf32b4
commit
1fd1f9e2ec
2 changed files with 72 additions and 0 deletions
|
|
@ -56,6 +56,14 @@ The following [infinite impulse response](https://en.wikipedia.org/wiki/Infinite
|
|||
|
||||
[atan](https://en.wikipedia.org/wiki/Inverse_trigonometric_functions) and [atan2](https://en.wikipedia.org/wiki/Atan2).
|
||||
|
||||
### [trigger.hh](trigger.hh)
|
||||
|
||||
Implemented are the following [trigger functions](https://en.wikipedia.org/wiki/Flip-flop_(electronics)):
|
||||
|
||||
* [Schmitt trigger](https://en.wikipedia.org/wiki/Schmitt_trigger)
|
||||
* [Rising edge trigger](https://en.wikipedia.org/wiki/Signal_edge)
|
||||
* [Falling edge trigger](https://en.wikipedia.org/wiki/Signal_edge)
|
||||
|
||||
### [const.hh](const.hh)
|
||||
|
||||
Some constants we need
|
||||
|
|
|
|||
64
trigger.hh
Normal file
64
trigger.hh
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
Some trigger functions
|
||||
|
||||
Copyright 2019 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE>
|
||||
class SchmittTrigger
|
||||
{
|
||||
TYPE treshold;
|
||||
bool previous;
|
||||
public:
|
||||
constexpr SchmittTrigger(TYPE treshold, bool previous = false) : treshold(treshold), previous(previous)
|
||||
{
|
||||
}
|
||||
bool operator() (TYPE input)
|
||||
{
|
||||
if (previous) {
|
||||
if (input < -treshold)
|
||||
previous = false;
|
||||
} else {
|
||||
if (input > treshold)
|
||||
previous = true;
|
||||
}
|
||||
return previous;
|
||||
}
|
||||
};
|
||||
|
||||
class FallingEdgeTrigger
|
||||
{
|
||||
bool previous;
|
||||
public:
|
||||
constexpr FallingEdgeTrigger(bool previous = false) : previous(previous)
|
||||
{
|
||||
}
|
||||
bool operator() (bool input)
|
||||
{
|
||||
bool tmp = previous;
|
||||
previous = input;
|
||||
return tmp && !input;
|
||||
}
|
||||
};
|
||||
|
||||
class RisingEdgeTrigger
|
||||
{
|
||||
bool previous;
|
||||
public:
|
||||
constexpr RisingEdgeTrigger(bool previous = false) : previous(previous)
|
||||
{
|
||||
}
|
||||
bool operator() (bool input)
|
||||
{
|
||||
bool tmp = previous;
|
||||
previous = input;
|
||||
return !tmp && input;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue