I need help with a problem regarding exponential smoothing in C++
The smoothing follows this equation :
newValue = inputSignal*smoothFactor + (1-smoothFactor)*oldValue
My function is supposed to only have one input parameter, that is the inputSignal
parameter (the smoothFactor
can be declared within the function and is not subject of the problem) and one output parameter, that is the newValue
.
Now the issue I am having is that the FIRST calculation is missing an oldValue
, since the oldValue
is the preceding newValue
in the first function call.
So the oldValue
has to equal the first inputSignal
in the first function call.
That means my function needs to behave different in its first call than every following call. I can solve this if I declare a global i=0
parameter and count up i++
after the first call. This however is NOT a function independent of outside circumstances, which it should be.
I was able to solve the problem with the i=0
and i++
global variables, but fail to find a solution without this.