I'm receiving angle updates from a sensor in radians and I want to pass them through a low pass filtering function to smooth them slightly because of noise.
My low pass filter function looks like this
protected void lowPass(float alpha, double[] input, double[] output) {
for (int i = 0; i < input.length; i++) {
output[i] = alpha * output[i] + (1 - alpha) * input[i];
}
}
and it works great for the most parts.
The problem is that sometimes the angles "go full circle", e.g. from 2π to 0, 0 to -2π, etc. Of course this results in "incorrect" output, since the filter function treats 2π and 0 as simply 6.28 and 0.0.
How would I implement a filter function that can handle these kinds of angles correctly?