-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpSmoothingFilter.h
39 lines (34 loc) · 1004 Bytes
/
ExpSmoothingFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef EXP_SMOOTHING_FILTER_H
#define EXP_SMOOTHING_FILTER_H
#include "Filter.h"
/**
* Class for a exponential smoothing filter implementing the Filter interface.
* @tparam T type of the variable to be filtered.
*/
template<typename T>
class ExpSmoothingFilter: public Filter<T> {
public:
/**
* Constructor for the exponential smoothing filter.
* The weight for the filter is given by the parameters a and b, representing the fraction a/b.
* @param a weight fraction numerator.
* @param b weight fraction denominator.
*/
ExpSmoothingFilter(int a, int b) {
this->a = a;
this->b = b;
previous = 0;
}
/**
* Computes the filtered output using an exponential filter, giving the passed value a weight of a/b.
* @param value to be filtered.
* @return T filtered output.
*/
T filter(T value) {
return previous = (value*a + previous*(b-a))/b;
}
private:
T previous;
int a, b;
};
#endif