arduino-audio-tools
Loading...
Searching...
No Matches
MovingAverage.h
Go to the documentation of this file.
1
2#include "Collections/List.h"
3
4namespace audio_tools {
5
13template <class N>
15 public:
18 }
19
20 void addMeasurement(N value) {
21 if (this->values.size() == this->size) {
22 this->values.pop_front();
23 }
24 this->values.push_back(value);
25 }
26
27 float calculate() {
28 if (this->values.empty()) return 0;
29 float sum = 0;
30 for (auto it = this->values.begin(); it != this->values.end(); ++it) {
31 sum += *it;
32 }
33 return sum / this->values.size();
34 }
35
37 void setSize(size_t size) {
38 this->size = size;
39 }
40
41 protected:
43 size_t size = 0;;
44};
45
46} // namespace audio_tools
Double linked list.
Definition List.h:19
size_t size()
Definition List.h:294
Iterator begin()
Definition List.h:274
bool empty()
Definition List.h:298
bool pop_front()
Definition List.h:202
Iterator end()
Definition List.h:279
bool push_back(T data)
Definition List.h:148
Caclulates the moving average of a number of values.
Definition MovingAverage.h:14
float calculate()
Definition MovingAverage.h:27
void addMeasurement(N value)
Definition MovingAverage.h:20
MovingAverage(size_t size)
Definition MovingAverage.h:16
List< N > values
Definition MovingAverage.h:42
size_t size
Definition MovingAverage.h:43
void setSize(size_t size)
Defines the number of values.
Definition MovingAverage.h:37
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6