We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 65834f3 commit eedeaabCopy full SHA for eedeaab
1 file changed
LibSource/SmoothFloat.hpp
@@ -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
25
26
+};
27
0 commit comments