# How to calculate horizontal angle from from (Iphone) Accelerometer data.

1. Feb 6, 2009

### RaviTiwari

Hi All,

Thanks in Advance.Need help on maths related to angular motion.We have a device that returns the acceleration in ax,ay,az for motion along a curve.we are trying to calculate the
angle using these acceleration values and the radius (which is fix in our case).

Below is what we are trying to do with these values.However whatever angles
we are getting from calculation does not match the actual angle.what could
wrong we be doing there. kindly enlighten me.

Is there any other method to calculate the angle given these set of data is
available with us.Calculating angle of rotation from acceleration data[ax,ay,az].

1)Calculate resultant acceleration from ax,ay,az.
Resultant Acceleration = SQRT (ax^2 + ay^2 +az^2) * G; //G = 9806.7 mm/s2;

2) Calculate angular Acceleration
Resultant Acceleration = Radius * Angular acceleration;
Angular acceleration (Alpha) = Radius / Resultant Acceleration ;

3) Angular velocity (omega) = omega zero ( previous) + alpha* time;

4) Angular displacement = Angular velocity *time;

5) Convert angular displacement from radian to degree.
Angle = angular displacement *57.3;

6) Sample Data

ax ay az dt(time difference)
0.018169 -0.036337 -1.144622 0.009766
0.054506 -0.036337 -1.071948 0.009766
:
:
:
:
-0.109012 -0.054506 -1.199128 0.018311
-0.163517 0.018169 -1.453488 0.009521
-0.163517 -0.036337 -1.398983 0.009033

2. Feb 7, 2009

### reasonableman

Hmm, I not entirely clear what your doing. As you say the radius is fixed I assume this is some sort of circular motion. In that case I think you're best off double integrating the acceleration data to get displacement then relate the displacement to the angle.

3. Feb 11, 2009

### RaviTiwari

Hi Reasonableman,

Thanks for reply and sorry for late reply.We are using Iphone Accelerometer to measure the Range of Motion. We said radius is fixed as the arm/hand of the user will be fixed in our case.

Now regarding the use of double integrating, let me explain what i have understood by this plz correct me if i am wrong here

Theta_n = Theta_(n-1) + Omega_(n-1) * t_(n-1) + 0.5 alpha_n*Power(tn, 2);

where
Theta is angular displacement.

We are doing this still results are not correct. Also shared here is an excel that has values generated for various angles along with the calculation.

#### Attached Files:

• ###### Sample Data.zip
File size:
92.2 KB
Views:
106
4. Apr 15, 2009

### eng2009

Hi
RaviTiwari, you said Angular acceleration (Alpha) = Radius / Resultant Acceleration , is this right??
if Resultant Acceleration = Radius * Angular acceleration ==> Angular acceleration (Alpha) =Resultant Acceleration/Radius,
despite, the unities are not compatible, so I suggest to calculate the speed by integring the acceleration then use this formula:

5. Apr 15, 2009

### minger

Here would be my process. Using your time step and cartesian acceleration measurements, calculate cartesian velocities and change in positions. We now have $$dx,dy,dz,\dot{x},\dot{y},\dot{z},\ddot{x},\ddot{y},\ddot{z}$$

From here, you can calculate the spherical trasnlations:
$$r = \sqrt{x^2 + y^2 + z^2}$$
$$\theta = \tan\left(\frac{y}{x}\right)$$
$$\psi = \sin\left(\frac{z}{r}\right)$$
If at any point now you wish to know velocities/accelerations in that coordinate system, you can take derivatives to find velocity
$$\dot{r} = \frac{x\dot{x}+y\dot{y}+z\dot{z}}{r}$$
$$\dot{\theta} = \frac{x\dot{y}+y\dot{x}}{x^2 + y^2}$$
$$\dot{\psi} = \frac{r\dot{z}-z\dot{r}}{r^2\sqrt{1-\left(\frac{z}{r}\right)2}}$$

Similarily, you can derivate that to get accelerations in spherical coordinate systems.

6. Oct 20, 2009

### nununo

Hi RaviTiwari,

I'm an artist trying to build a video installation with an iphone and I need to accomplish a very similar thing: I'll have an iphone moving in a constant pendular motion and I need to determine it's angle/position.

My problem is that the last time I did some real math was back in College in 1996. Did you manage to implement the code to determine the angle based on the iphone accelerometer? If so, would it be possible for you to share the code with me?

Otherwise, does anyone know where I can find a thorough mathematical explanation of what is needed so that I can give a try at understanding it and implementing it?