title: Remove gravity from raw accelerometer data of IMU--> please approve math and algo
body: <p>I am using this device (<a href="http://www.sparkfun.com/products/10724" rel="nofollow">http://www.sparkfun.com/products/10724</a>) and have successfully implemented an quite well working orientation estimation based on a fusion of magnetometer, accelerometer and gyroscope data based on this <a href="http://www.x-io.co.uk/node/8#open_source_imu_and_ahrs_algorithms" rel="nofollow">http://www.x-io.co.uk/node/8#open_source_imu_and_ahrs_algorithms</a> implementation. Now I want to calculate the dynamic acceleration (measures acceleration without static gravity acceleration). For doing this I came to the following idea.</p>
  
  <p>Calculate a running average of the raw accelerometer data. If the raw acceleration is stable for some time (small difference between running average and current measured raw data) we assume the device does not move and we are measuring the raw gravity. Now save the gravity vector and also current orientation as quaternion. This approach assumes that our device could not be accelerated constantly without gravity.</p>
  
  <p>For calculating the acceleration without gravity I am now doing following quaternion calculation:</p>
  
  <hr>
  
  <pre class="lang-js prettyprint-override"><code>RA = Quaternion with current x,y,z raw acceleration values
  GA = Quaternion with x,y,z raw acceleration values of estimated gravity
  CO = Quaternion of current orientation
  GO = saved gravity orientation
  
  DQ = GO^-1 * CO // difference of orientation between last gravity estimation and current orientation
  
  DQ = DQ^-1 // get the inverse of the difference
  
  SQ = DQ * GA * DQ^1  // rotate gravity vector
  
  DA = RA - SQ // get the dynamic acceleration by subtracting the rotated gravity from the raw acceleration
  </code></pre>
  
  <hr>
  
  <p>Could someone check if this is correct? I am not sure because on testing it I get some high acceleration on rotating my sensor board, but I am able to get some acceleration data (but is is much smaller than the accelration during rotation) if the device is moved without rotating it.</p>
  
  <p>Moreover I have the question if the accelerometer is also measuring acceleration if it is rotated on place or not!</p>