Tool Libs
UMIT-TIROL Institute of Automation and Control Engineering library collection
 
Loading...
Searching...
No Matches
movingaverage.h
Go to the documentation of this file.
1
5#pragma once
6#include <utils/queue.h>
7
13template<typename T, int N>
15 Queue<T> samples{N};
16 T total{};
17public:
22 double operator()() {
23 return (double)total / samples.size();
24 }
25
30 void operator()(T tSample) {
31 total += tSample;
32 if (samples.full()) {
33 total -= samples.pop();
34 }
35 samples.push(tSample);
36 }
37};
Template class that implements a moving average filter as fifo.
Definition movingaverage.h:14
void operator()(T tSample)
Operator overload to add a new value to the filter.
Definition movingaverage.h:30
double operator()()
Operator overload to return the average value.
Definition movingaverage.h:22
simple Buffer backed queue implementation
Definition queue.h:12
Copyright (c) 2023 IACE.