mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added integrator and differentiator
This commit is contained in:
parent
d4841b2998
commit
ca7a7ad56f
2 changed files with 49 additions and 0 deletions
|
|
@ -89,6 +89,13 @@ Implemented are the following [trigger functions](https://en.wikipedia.org/wiki/
|
|||
|
||||
The [simple moving average](https://en.wikipedia.org/wiki/Moving_average#Simple_moving_average) gives us the mean of the last N data points.
|
||||
|
||||
### [calculus.hh](calculus.hh)
|
||||
|
||||
Some [calculus](https://en.wikipedia.org/wiki/Calculus) functions:
|
||||
|
||||
* [Integrator](https://en.wikipedia.org/wiki/Integrator)
|
||||
* [Differentiator](https://en.wikipedia.org/wiki/Differentiator)
|
||||
|
||||
### [const.hh](const.hh)
|
||||
|
||||
Some constants we need
|
||||
|
|
|
|||
42
calculus.hh
Normal file
42
calculus.hh
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
Some calculus functions
|
||||
|
||||
Copyright 2019 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE>
|
||||
class Integrator
|
||||
{
|
||||
TYPE sum;
|
||||
public:
|
||||
constexpr Integrator(TYPE sum = TYPE(0)) : sum(sum)
|
||||
{
|
||||
}
|
||||
TYPE operator()(TYPE input)
|
||||
{
|
||||
return sum += input;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TYPE>
|
||||
class Differentiator
|
||||
{
|
||||
TYPE prev;
|
||||
public:
|
||||
constexpr Differentiator(TYPE prev = TYPE(0)) : prev(prev)
|
||||
{
|
||||
}
|
||||
TYPE operator()(TYPE input)
|
||||
{
|
||||
TYPE diff = input - prev;
|
||||
prev = input;
|
||||
return diff;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue