I have a magnetometer, accelerometer and gyro which all go swimming (attached to a person.) Data is logged and I now have a sample of that data.

I want to calculate the magnetic heading the user was travelling in. However, all the documents I can find on tilt compensated compasses (they're mostly applicable to phones) do not mention anything about accelerating at the same time, which happens in my application. It seems to me like this would make tilt compensation very difficult; it would only be possible when stationary.

Does anyone know if it's possible?

  • \$\begingroup\$ You should be able to calculate immediate vectors then average those vectors over 10 to 20 seconds or so for reasonable results... ? Low pass filtering should be even better. I'm not making an answer because this is somewhat speculative. \$\endgroup\$
    – darron
    Nov 25, 2013 at 21:56
  • \$\begingroup\$ Even if it's stationary, you are accelerating at the same time. Your accelerometer will be measuring the acceleration due to gravity. What are you actually asking? \$\endgroup\$
    – Samuel
    Nov 26, 2013 at 1:45
  • \$\begingroup\$ @Samuel Yes, I know I will have the 1g acceleration in the Z-axis. I thought this is what the tilt compensation looks for. So I don't know how well it works if there is additional acceleration on top of gravity. \$\endgroup\$
    – Thomas O
    Nov 26, 2013 at 9:05
  • \$\begingroup\$ @ThomasO 1g acceleration in the Z-axis is the trivial case, the device is not tilted, you're done. Any tilt compensation worth anything will be dealing with every other case. It seems what you actually want to do is separate the gravity vector from the other accelerations, or, to make the device an AHRS. Correct? Can you use the kinematics of the human attachment point to aid your calculations? \$\endgroup\$
    – Samuel
    Nov 26, 2013 at 18:24
  • \$\begingroup\$ @Samuel - ah yes, I see what you mean. In my case, I cannot rely on the accelerometer to figure out the orientation, so can I still tilt compensate? \$\endgroup\$
    – Thomas O
    Nov 26, 2013 at 20:04

1 Answer 1


Somehow, I didn't notice this question at the time it was asked, or I would have answered sooner.

Yes, what you want to do is definitely possible, and there is software out there to help you do it, but unfortunately, some of it is quite expensive.

Basically, you need to use something like a Kalman filter to combine all of your data (raw acceleration, angular rate and magnetic field readings) into a complete model of the sensor that includes both its relative position and its absolute attitude (orientation). (If you also add something like a GPS receiver, you can also get absolute position.)

The filter operates in such a way that it uses the magnetometer to correct for the long-term errors (e.g., offset and scale changes) in the accelerometers and gyros, and then you can use this estimate of the attitude of the sensor to tilt-compensate the magnetic field readings in order to get a magnetic heading. As a bonus, you also get the true "course over ground" of the sensor from the sequence of position estimates, which could differ from the heading if the swimmer is swimming in a cross-current of some sort.

As far as the software for doing this kind of post-processing, one example I'm aware of is called Inertial Explorer, but it's very expensive and is probably way overkill for your application. If you search around, you should be able to find open-source projects that meet your needs.


Your Answer

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

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