title: Android Compass orientation on unreliable (Low pass filter)
body: <p>Im creating an application where i need to position a ImageView depending on the Orientation of the device. 
  I use the values from a MagneticField and Accelerometer Sensors to calculate the device orientation with </p>
  
  <pre><code>SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerValues, magneticFieldValues)
  SensorManager.getOrientation(rotationMatrix, values);
  double degrees = Math.toDegrees(values[0]);
  </code></pre>
  
  <p>My problem is that the positioning of the ImageView is very sensitive to changes in the orientation. Making the imageview constantly jumping around the screen. (because the degrees change)</p>
  
  <p>I read that this can be because my device is close to things that can affect the magneticfield readings. But this is not the only reason it seems.</p>
  
  <p>I tried downloading some applications and found that the "<a href="http://www.androlib.com/android.application.com-a0soft-gphone-acompass-zzzw.aspx" rel="noreferrer">3D compass</a>" and "<a href="http://www.androlib.com/android.application.com-apksoftware-compass-qAC.aspx" rel="noreferrer">Compass</a>" remains extremely steady in its readings (when setting the noise filter up), i would like the same behavior in my application.</p>
  
  <p>I read that i can tweak the "noise" of my readings by adding a "<strong>Low pass filter</strong>", but i have no idea how to implement this (because of my lack of Math). </p>
  
  <p>Im hoping someone can help me creating a more steady reading on my device, Where a little movement to the device wont affect the current orientation.
  Right now i do a small </p>
  
  <pre><code>if (Math.abs(lastReadingDegrees - newReadingDegrees) &gt; 1) { updatePosition() }
  </code></pre>
  
  <p>To filter abit of the noise. But its not working very well :)</p>