Skip to content

Commit eedeaab

Browse files
author
mars
committed
exponential smoothing
1 parent 65834f3 commit eedeaab

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

LibSource/SmoothFloat.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
/**
3+
* Applies exponential smoothing to a float value.
4+
* y(n) = lambda*y(n-1) + (1.0-lambda)*y(n)
5+
*/
6+
class SmoothFloat {
7+
private:
8+
float value;
9+
public:
10+
float lambda;
11+
SmoothFloat(float l=0.9, float initialValue=0.0)
12+
: lambda(l), value(initialValue){}
13+
void setValue(float newValue){
14+
value = value*lambda + newValue*(1.0-lambda);
15+
}
16+
float getValue(){
17+
return value;
18+
}
19+
SmoothFloat& operator=(const float& other){
20+
setValue(other);
21+
return *this;
22+
}
23+
operator float(){
24+
return value;
25+
}
26+
};
27+

0 commit comments

Comments
 (0)