I received snippets of data of an IMU with 9 DoF in motion. For these I wanted to get their rotation by angles relative to the earth frame. My goal is to receive the absolute vertical acceleration, therefore I'd like to know about the sensors rotation.

Thus I was reading about pitch, roll and yaw and also about AHRS Filters like Madgwick- and Complementary-Filter. Now I have a question about the feasibility and understanding:

Since I only have snippets, I don’t know the initial sensor rotation. Is my understanding correct that the filters are only calculating the rotation relative to the last known rotation, so I‘d always have an offset of the initial orientation regarding to the earth frame? Is it even possible to calculate the rotation having only a random snapshot and if so, what would be the best approach?

Thank you very much.


1 Answer 1


The best approach is to use the Madgwick filter. The trick is that gravity always points down, and gravity is the only sustainable acceleration. Magnetic North points North (assuming you're not near ferrous/magnetic stuff) and so you can determine the orientation through magnetometer and accelerometer readings in the very long term. Short-term the gyroscopes will give you good motion estimates, but they have biases and so you get angular drift in the long term.

You could write your own complementary filter to join the two, or use a Kalman filter, but the Madgwick filter is even better for IMU sensor fusion and it has implementations that are freely available.

You'll have some time at the start of the data set where the filter is converging, but there's nothing you can do about that. After convergence you should have a remarkably robust orientation estimate.

  • $\begingroup$ Thanks for your answer. You said gravity is the only sustainable acceleration, but what if during my snippets of data the sensor is in motion? The accelerometer has two sources of acceleration then and couldn't retrieve the orientation by itself. Would the gyroscope compensate for that? Also just to clarify it for myself: if short-term orientation can best be obtained from the gyroscope, would that also work in an excerpt of the data? Or is it only giving me the orientation in regard to the unknown orientation-offset I have at the beginning of my data snapshot? $\endgroup$ Jul 26, 2022 at 17:44
  • $\begingroup$ @user9155899 if your object is doing aerobatics or something and that's the only part of the run you captured then yeah, you're going to get invalid results, but there's nothing any filter is going to be able to do about that. To your question directly, Is my understanding correct that the filters are only calculating the rotation relative to the last known rotation, no, you can recover rotation from accelerometers (by looking for down) and magnetometers (by looking for North). I'd highly recommend giving the Madgwick filter a shot, visualize the results, and then see how it looks to you. $\endgroup$
    – Chuck
    Jul 27, 2022 at 0:03
  • $\begingroup$ but isn't looking for down in accelerometer data falsified when the object was moving? As far as I know you can only get the correct rotation angle by using only the accelerometer when the sensor is standing still. $\endgroup$ Aug 13, 2022 at 18:20
  • $\begingroup$ @user9155899 - Only when the sensor is at constant speed. But again, the only sustainable long-term acceleration is gravity, and as I mention above if you didn't capture sufficient time for the filter to converge before starting your aerobatics then there's not really anything you're going to be able to do to pad the data out to create that data. $\endgroup$
    – Chuck
    Aug 13, 2022 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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