The function `a()` takes three arguments: `delta`, `prev`, and `sample`....
The function a()
takes three arguments: delta
, prev
, and sample
.
delta
is a duration value representing the time difference between the current sample and the previous one.
prev
is the value of the previous sample, and sample
is the current sample value.
The function returns a float64 value that represents the exponentially weighted moving average of the previous and current sample values. The formula for calculating this value is:
newSample = sample + exp(-delta/200)*(prev-sample)
Here, exp
refers to the exponential function from the math
package in Go language. The duration value delta
is converted to milliseconds and then divided by 200 before being passed to the exponential function. The resulting value is multiplied by the difference between the previous and current samples, which is then added to the current sample value.
In summary, this function calculates an exponentially weighted moving average of the previous and current sample values using a decay factor of 200 milliseconds.