# Calculating accelerometer vector when tilted

I'm trying to develop a 3D position estimation program using an xyz accelerometer. Ignoring the massive error introduced by double integration of the acceleration to get displacement, I have another problem with rotation.

When the phone is upright I have no problems. I can stand the phone straight up and move it side to side on the desk on the x-axis alone to get the desired values. The issue is if the phone is tilted slightly (say 45 degrees) and again moved side to side. Internally the phone thinks it's moving in a diagonal direction on both x and y axes.

Since the phone is actually just moving on the x-axis, is it possible to use the tilt angle to modify the x and y values so that x is the actual acceleration in the x-axis and y is 0?

To clarify, imagine the phone is set at a 45 degree angle and moved right at a speed of 1ms-2. The x and y accelerometer values will both read ~0.71. I can use the SOH CAH TOA rules to get an x value of 1, which is what I wanted. However I can't see how I can get the y value to 0.

• If the phone is free to rotate, than you need gyroscope too. For example you can't determine if the phone is rotating around vertical axis or not. So do you have at your disposal full 3 axis gyroscope? – tom Apr 24 '14 at 11:45
• I have a 3 axis gyroscope built in, and I do intend to fuse that with the accelerometer, but I'm not worrying about that for now. Right now I'm assuming that the phone is fixed at any given angle. – karoma Apr 24 '14 at 12:05

Phone is rotated by $45°$ and accelerating in x-direction at rate $1ms^{-2}$. The accelerometer is reading acceleration in coordinate frame fixed with phone so it reads acceleration $\left(\frac{\sqrt{2}}{2},\frac{\sqrt{2}}{2}\right)ms^{-2}$ to transform acceleration from phone's local frame to world frame you just do matrix multiplication $$\left( \begin{matrix} \cos{45} & \sin{45} \\ -\sin{45} & \cos{45} \end{matrix} \right) \left( \begin{matrix} \frac{\sqrt{2}}{2} \\ \frac{\sqrt{2}}{2} \end{matrix} \right) = \left( \begin{matrix} 1 \\ 0 \end{matrix} \right)$$
Of course you can change $45$ to any angle you wish.