tags:

views:

349

answers:

4

I am trying to filter out the noise from the orientation/compass sensor in my magic phone.

Some of the readings seem to be 90-180 degrees off and there is a lot of jiggle. I have tried different things with limited success, so I was wondering if anyone could recommend an algorithm to filter this sort of noise to get a stable output.

BR, Mads

+1  A: 

What have you tried? How many readings do you get per second?

I would suggest something along the lines of an average of the last X number of readings to get rid of the "jiggles" and throw away any readings that are wildly different from the current direction to stop any crazy "jumping" of values. Depending on how many readings you are getting, and how much averaging you are doing, your app may lose responsiveness.

The following link might be useful. http://www.chem.uoa.gr/applets/appletsmooth/appl%5Fsmooth2.html

Loopo
+2  A: 

You need Low Pass Filter. There are explanation and simple algorithm on wikipedia

db_
+1  A: 

If you do get a significant number of completely-wrong values, you probably don't want to just average them. You could try applying a median filter first - take N samples, calculate the median, and throw out anything more than +- some threshold value. You can apply a smoothing filter after that.

Mark Bessey
+1  A: 

I got rid of most of the noise by just using a slower update time. I'm not sure if Android has a built-in filter for these, but it seems to stabalize a lot. Something like:

mSensorManager.registerListener( 
    mSensorListener, 
    mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), 
    // SENSOR_DELAY_UI, instead of SENDOR_DELAY_FASTEST (or similar)
    //    seems to iron out a lot of the jitter
    SensorManager.SENSOR_DELAY_UI
);

SensorManager offers:

  • SENSOR_DELAY_FASTEST : get sensor data as fast as possible
  • SENSOR_DELAY_GAME : rate suitable for games
  • SENSOR_DELAY_NORMAL : rate (default) suitable for screen orientation changes
  • SENSOR_DELAY_UI : rate suitable for the user interface
fiXedd