There's an accelerometer in the IMU. The output can then be integrated to estimate the position, at least in theory.

But in practice, there's a huge acceleration from gravity, which varies rather randomly across locations. Vibrations etc can be filtered out with low-pass filters, but how do you filter out gravity? Is it simply the case that the vertical vector is ignored when doing any calculations?

My application is, I want to build a quadcopter that could hover in one place even in the presence of (reasonable) winds: the quadcopter ideally would tilt towards random gusts to maintain a certain position. Every single tutorial I could find on the Internet only uses the accelerometer to estimate where down is when stationary, and simply assumes that using the gyroscope to hold the quadcopter level is enough.

I also want to use the IMU to estimate altitude if possible, of course as an input to something like a Kalman filter in conjunction with a sonar system.

Obviously, for my application GPS is far too slow.

  • $\begingroup$ Not try to be rude, but what exactly is your question? Are you asking how to filter the noise out of accelerometer readings? $\endgroup$
    – Chuck
    Jun 9, 2015 at 1:25
  • $\begingroup$ I will rephrase my question. My biggest question is how to filter out gravity actually. $\endgroup$
    – ithisa
    Jun 9, 2015 at 1:30
  • $\begingroup$ Why you want to filter out the gravity? The gravity vector can be used for attitude estimation by vector projection. With the gravity vector alone you can easily estimate the pitch and roll. If you even take the magnetic field vector you can apply the so-called "bi-vector" method. In general a vector projection to estimate the attitude of the quadrocopter. $\endgroup$
    – TobiasK
    Jun 9, 2015 at 5:53
  • $\begingroup$ didn't read all your questions. But for filter out the gravity: use a high-pass filter on accelerometer. As what Android does: developer.android.com/reference/android/hardware/… $\endgroup$
    – lanyusea
    Jun 9, 2015 at 12:24
  • $\begingroup$ another maybe better idea is the step detection algorithem, but can only detect there happened a movement/vertical instead of finding its direction. To do it, calculate the total magnitude of acceleration on three axis, then minus 9.8, and set a threshold to detect whether there is a movement or not. $\endgroup$
    – lanyusea
    Jun 9, 2015 at 12:28

3 Answers 3


To "filter" out gravity is not necessarily the correct terminology. The accelerometer measures all forces acting on it, so when it is stationary the only force is gravity. However, because the accelerometer may not be level, the gravity force might not be directly on the Z-axis (assuming Z axis is representing the vertical). Usually a gyroscope is used along with the accelerometer to level the acceleromter, this way the gravity force can be directly subtracted from the accelerometer readings.


Most flight controllers that I am aware of do not use the IMU for absolute positioning they are only used for attitude estimation and in some cases to try to dampen the effects of external forces (i.e. wind) but it can only be effective at damping these external forces if they are above a certain reasonably detectable level so over the long run you will drift quite a bit but in the short run you can somewhat compensate for the effects of wind.

If you need more robust position holding you might be better off using another system in conjunction with the imu like an optical flow sensor and a target dot or good old gps.

What is your target application?


See also this question for some info on how accelerometers handle gravity versus an external force.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.