Android Low pass filter and High pass filter

Jeet picture Jeet · Jun 9, 2014 · Viewed 25.6k times · Source

I have a very basic question. What is Low Pass filter and High Pass filter in case of Android Accelerometer?

When I see the output from the Accelerometer Sensor, I see If I don't use any filter, (Case : I kept my cell phone idle on table) I get z Axis +ve value. Now If I think using basic physics, it gives me exact value(9.8approx) for small g i.e Acceleration due to gravity.

To get the linear acceleration, If I add any force to phone it will change the Accelerometer value, but it will be g + a that I applied. So to get a why can't I just subtract directly from the value I am getting from Accelerometer?

What is the use?
A basic definition I understand for low pass: To allow low value, High Pass : To allow high value.

Answer

shuttle87 picture shuttle87 · Jun 9, 2014

If you look at the documentation you will see that SensorEvent returns an array which represents the vector of all the forces. http://developer.android.com/reference/android/hardware/SensorEvent.html#values This is how the components of the acceleration break down into each axis:

 values[0] //acceleration on x axis
 values[1] //acceleration on y axis
 values[2] //acceleration on z axis

You need to find which direction gravity is operating in then decompose that into its component parts. The magnitude of the gravity force will always be 9.8 but the direction, and hence how it breaks down into the component parts, will change. Assuming that we could get the value of gravity and store that vector in an array like gravity[3]:

 gravity[0] //gravity x axis
 gravity[1] //gravity y axis
 gravity[2] //gravity z axis

The total acceleration, T, on the phone is T = g + a. To get just a we would need a = T - g:

 linear_acceleration[0] = event.values[0] - gravity[0];
 linear_acceleration[1] = event.values[1] - gravity[1];
 linear_acceleration[2] = event.values[2] - gravity[2];

Notice how this calculates everything element by element because it's a vector operation.

The tricky part is finding gravity because there is only one accelerometer in the phone which measures both the gravity AND the other forces at the same time. We have 2 different forces that we want to find from the one sensor. If we could only look at the forces at an isolated point in time we wouldn't be able to extract the information. However we do get samples over a range of times and by looking at how the forces change over time we can extract the information.

This means we need to filter out the results from that one source based on how quickly those forces change. The magnitude of acceleration due to gravity does not change quickly because it doesn't change at all. Gravity is a constant force. However other forces will change over time. If we filter out the slow changing forces like gravity by using a high-pass filter then the remaining forces are the fast changing ones like the forces being applied to the phone. This is why the high-pass filter is used.