#include <Filters/SMA.hpp>
template<uint8_t N, class input_t = uint16_t, class sum_t = uint32_t>
class SMA< N, input_t, sum_t >
Simple Moving Average filter.
Returns the average of the N most recent input values.
\[
y[n] = \frac{1}{N} \sum_{i=0}^{N-1}x[n-i]
\]
- See also
- https://tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Digital-filters/Simple%20Moving%20Average/Simple-Moving-Average.html
- Template Parameters
-
N | The number of samples to average. |
input_t | The type of the input (and output) of the filter. |
sum_t | The type to use for the accumulator, must be large enough to fit N times the maximum input value. |
- Examples
- SimpleMovingAverage.ino.
Definition at line 32 of file SMA.hpp.
|
| SMA ()=default |
| Default constructor (initial state is initialized to all zeros). More...
|
|
| SMA (input_t initialValue) |
| Constructor (initial state is initialized to given value). More...
|
|
input_t | operator() (input_t input) |
| Update the internal state with the new input \( x[n] \) and return the new output \( y[n] \). More...
|
|
◆ SMA() [1/2]
Default constructor (initial state is initialized to all zeros).
◆ SMA() [2/2]
SMA |
( |
input_t |
initialValue | ) |
|
|
inline |
Constructor (initial state is initialized to given value).
- Parameters
-
initialValue | Determines the initial state of the filter:
\( x[-N] =\ \ldots\ = x[-2] = x[-1] = \text{initialValue} \) |
Definition at line 46 of file SMA.hpp.
◆ operator()()
input_t operator() |
( |
input_t |
input | ) |
|
|
inline |
Update the internal state with the new input \( x[n] \) and return the new output \( y[n] \).
- Parameters
-
input | The new input \( x[n] \). |
- Returns
- The new output \( y[n] \).
Definition at line 59 of file SMA.hpp.
◆ index
◆ previousInputs
input_t previousInputs[N] = {} |
|
private |
◆ sum
The documentation for this class was generated from the following file: