Not sure what kind of actual impact this might have on the rest of the library, but I believe there is something wrong in the LowPassFilter class:
LowPassFilter::LowPassFilter(float time_constant)
: ...
, y_prev(0.0f)
{
...
}
float LowPassFilter::operator() (float x)
{
...
float y = alpha*y_prev + (1.0f - alpha)*x;
y_prev = y;
...
return y;
}
Because y_prev is initialized to zero, the first calls to operator() returns the wrong result. At the first call, y_prev should probably be initialized with x instead of zero. In other words, the first call to LowPassFilter(5) should return 5 and not a weighted average of 5 with zero.
Notice that, in LowPassFilter::operator(), you can also see:
if(dt > 0.3f) {
y_prev = x;
timestamp_prev = timestamp;
return x;
}
So if you are lucky enough to have spent 0.3 seconds between the class construction and the first call to operator(), then y_prev is correctly initialized.
Not sure what kind of actual impact this might have on the rest of the library, but I believe there is something wrong in the LowPassFilter class:
Because
y_previs initialized to zero, the first calls tooperator()returns the wrong result. At the first call,y_prevshould probably be initialized withxinstead of zero. In other words, the first call toLowPassFilter(5)should return 5 and not a weighted average of 5 with zero.Notice that, in
LowPassFilter::operator(), you can also see:So if you are lucky enough to have spent 0.3 seconds between the class construction and the first call to
operator(), theny_previs correctly initialized.