This filter library is sensitive to the timing of you calling
FilterOnePole::input(). It assumes that the delays between consecutive
calls are the same as the delays between the samples being measured.
C.f. the first statement in the method, which is a call to
micros(). The pauses between your 20-sample buffers are then
interpreted like long times during which the input only changed very
little.
If you are sampling at a constant data rate, I recommend you reimplement the filter yourself: it is simple enough and it will be way more efficient than the one you found on Playground.
Edit: Here is a simple implementation of a first-order high-pass filter like the one in the library, but using a constant sampling rate:
class HigPassFilter
{
public:
HigPassFilter(float reduced_frequency)
: alpha(1-exp(-2*M_PI*reduced_frequency)), y(0) {}
float operator()(float x) {
y += alpha*(x-y);
return x-y;
}
private:
float alpha, y;
};
You would use it like this:
// Create the filters.
HigPassFilter highpassFilter_x(cutoffFrequency/samplingFerquency);
HigPassFilter highpassFilter_y(cutoffFrequency/samplingFerquency);
HigPassFilter highpassFilter_z(cutoffFrequency/samplingFerquency);
// Apply them.
filtered_x_val[i] = highpassFilter_x(x_arr[i]);
filtered_y_val[i] = highpassFilter_y(y_arr[i]);
filtered_z_val[i] = highpassFilter_z(z_arr[i]);