Android Acceleration Sensor: Mean Filter

All sensors have noise that is sometimes desirable to filter out at a cost to other characteristics of the signal. To read more about sensor noise, see  Android Acceleration Sensor: Sensor Noise.

Mean Filter:

The mean filter (or moving average filter) is the most common of filters used in digital signal processing. The mean filter is easy to understand and implement and has the desirable characteristics of reducing random noise while maintaining a sharp step response (it still responds quickly relative to the noise reduction).

The disadvantage to a Mean Filter is that its memory and time complexity are an order of magnitude higher than that of a low-pass filter.

FSenor:

If your Android project requires a mean filter, FSenor has already done the hard work for. FSensor provides an implementation that is easily configured and accounts for varying sensor frequencies amongst different devices for you. This means you get more consistent results among different devices than you would with a vanilla Mean Filter.

Mean Filter Implementation:

The mean filter simply averages the values within a fixed window. The mean filter will sum all values in the fixed window and device the result of the summation by the number of values in the summation.


private float[] getMean(float[] data) {

float mean;

for (int i = 0; i < data.length; i++) {
mean += axis[i];
}

mean /= data.length;

return mean;
}

Testing Nexus 5:

Here you can see the results of applying the FSenor Mean Filter with a time constant of 0.5 seconds. This means the averaging window is half a second long. With an update frequency of ~200Hz the filter window is ~100 (0.5*200 = 100). You can see a dramatic reduction in noise with the filter applied.

No Filter:

Mean Filter with Time Constant = 0.5 seconds:

Leave a Reply

Your email address will not be published. Required fields are marked *