Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Accelerometer filtering?

I saw many examples about filtering Accelermeter's values, to cancel out the gravity (High-pass filter).

But most of them were 1st order one, which is said to be simple, but laggy and not the best one (though I know nothing about the filters or DSP).

Somebody in here said that there exists the better solution used in DSP to sense the motion. Regretfully I can't even imagine what it would be, as I am completely outsider to the field.

I hope somebody could tell at least the type of filters that can be used when dealing with the sensor. Of course, even brief introduction to the specific algorithm will be very pleased :)

Thanks in advance.

like image 740
Kyoung-Rok Jang Avatar asked Jan 20 '11 01:01

Kyoung-Rok Jang


3 Answers

You can try a higher order FIR or IIR filter which could give you a sharper frequency domain transition. But a more advanced method is to use an adaptive Kalman filter. Here's one article on accelerometers and Kalman filters.

like image 150
hotpaw2 Avatar answered Oct 16 '22 11:10

hotpaw2


the DSP Guide is what you're looking for. It gives the basic 'theory' as well as mathematics behind Digital Signal Processing and the works.

http://www.dspguide.com/ch14.htm That is a good starting point

Check it out.

And from personal experience, a 1st order filter will be 'good' enough for most simple applications. Though this completely depends on the specific application

like image 41
g19fanatic Avatar answered Oct 16 '22 09:10

g19fanatic


You want to utilize Android's SensorListener() Class. For example, "The Schwartz Unsheathed" is open source Android project hosted on Google Code that looks like it should be quite useful (written by Clark Scheff).

You can check out its source via SVN http://code.google.com/p/the-schwartz-unsheathed/source/checkout or just browse it on the web. The source is broken up into an Activity (TheSchwartz.java) and a View (GraphView.java). GraphView.java contains SensorListener() ad onSensorChanged() classes which is where the accelerometer processing occurs. Lines 284 and 285:

magnitude = (float)Math.sqrt(values[0]*values[0]+values[1]*values[1]+values[2]*values[2]);
magnitude = Math.abs(magnitude - SensorManager.GRAVITY_EARTH);

The value of magnitude is evaluated for no movement, a "hit" or a "swing" of the Android phone. I realize this does not filter the data in a signal processing sense, but it does show a way to classify sensor data. Hope it helps.

like image 1
gary Avatar answered Oct 16 '22 09:10

gary