# Using iPhone accelerometer data

• swied
In summary, the person was trying to use the raw accelerometer data from their iPhone to track displacement, but found that the data was too noisy to be useful. They suggest smoothing out the noise using a weighted moving average, depending on the type of noise, and then trying to track displacement using the data.
swied
I wanted to use the raw data from my iPhone accelerometer to track displacement. I downloaded an app called Accelerometer Data Pro. It is pretty fun. You slide a bar to start sampling, walk around the room, and then slide the same bar to stop sampling. The time series results can then be downloaded to your computer in csv format.

I tried using the simple equations of motion in an Excel spreadsheet to convert accelerations into displacements, but there is so much noise. I did a test where it picked up the phone, walked around, and placed it back in the same spot. I set the origin to be the original resting place of the unit. If everything worked correctly, I hypothesized, then I should be able to plot a path that curves around in space, and then returns back to the origin. ...That didn't happen.

I was wondering if anyone else had every played around with similar accelerometer data. What tricks did you use to filter out the noise in the data? Also, how did you subtract out the acceleration of gravity. Unless I hold the phone perfectly level, it is hard to differentiate the accelerations from motion, from gravity. The iPhone doesn't have gyros, so it is difficult to determin the orientation of the device at each data reading.

Could you post the data?

Problems with noise can be smoothed out using a weighted moving average, depending on what kind of noise it is...

DavidSnider said:
Could you post the data?

Problems with noise can be smoothed out using a weighted moving average, depending on what kind of noise it is...

The data is on my computer at home. I'll post it later tonight.

Last edited:
I think you'll run into problems trying this. The problem is that the accelerometers are not oriented in the same position at all times. You might "think" that you're measuring vertical accleration, but it could be a mix of 2 or 3 components.

I originally thought the Nike+ system was based on acclerometers, but then thought they would run into the same problem and therefore need gryos or some other method to keep track of angle. It turns out it simple measures the time your foot is in contact with the ground and uses impirical data to guess your speed.

If you're trying to keep track of displacement maybe the best method with what you have is to identify the acclerometer that measures up (lets say while your phone is in your pocket) and then "watch" for the impacts and go the Nike way.

It won't work very well unless the iphone's axes always point in the same direction. As soon as you rotate the device at all, you've changed what the iphone thinks is the +x direction.

DavidSnider said:
Could you post the data?

Problems with noise can be smoothed out using a weighted moving average, depending on what kind of noise it is...

Here is a sample file of raw accelerometer data measured at 60 Hz. To keep it simple, I put the phone flat on a table, I hit the start sampling button, took my hand away for a couple seconds, grabbed the phone and slid it across the table, let go of the unit for a second, grabbed it again, and slid it back to its original position. The sliding motion was along the y-axis. The z-axis acceleration is close to 1 which is gravity. The x-axis acceleration is from the caffeine induced shake from my hand.

Hmm. I guess you can't upload .csv files. I changed the extension to .txt, and tried again. Hopefully it will work this time.

#### Attachments

• capture4.txt
57.8 KB · Views: 923
I see the column of z axis data is almost always -1. This would lead me to believe that we're in units of g. z is the vertical axis of however the device was being held. Not sure on x and y.

I don't really see any decent data as I'm looking at it now. I used a simple trapezodial rule to get velocities and again to get displacements.

Even with a 1/2 second moving average, the accelerations seem too noisy to be useful. Looking at the displacements, I would expect a line which parabolically increases to a value then stops. From there, it should parabolically decrease back to a value close to the starting point. Mostly, all I see is a noisy line.

I wonder if decreasing the sampling rate would help?

hello there,
i am using a tilt pad gravis destroyer tilt
i have acquired the raw data from it by DirectInput,
it has 2-axis i was wondering if i could use it for detecting
displacement too

i see you guys are trying to do the same thing,
could you guys tell me how do you calculate from these raw
data velocity, acceleration, orientation
i have some ideas but I am really confused right now

Here is another data set that is a little more interesting than what I posted previously. I attached a string to the belt clip on the case of my iPhone, and let it swing back and forth from a fixed point on my desk. The string was about 18 inches long. I tried several sampling rates, and looked at the resulting data. A sample rate of 60 Hz was the best for capturing enough data points to cover the entire period of the swing. I also selected the hi-pass filter option. The Accelerometer Data Pro software states that this filter can be used to remove the acceleration of gravity from the data. Check it out and have fun with it.

#### Attachments

• capture pendulum 60 hz hi pass.txt
49.8 KB · Views: 756
Last edited:
Attached is a time series graph of the x,y,z accelerations. It looks like a classical damped pendulum. The noise at the beginning and end are from my hand starting and stopping the swinging iPhone.

Edit: I forgot to mention that the acceleration values are measured with respect to gravity. For example, the iPhone sitting at rest on a desk would register a value of 1 along the z-axis.

#### Attachments

• pendulum data.png
13.2 KB · Views: 1,291
NOW you have something useable! Any plans for using these capabilities?

1. Accurately determine the period
2. Perform the same experiment in the two other dimentions.
3. Calculate the center of mass of the Iphone!

Regarding data reduction, acceleration, velocity, and position are all vector quantities. Also, since, in reality, the phone is a rigid body (and not a particle), rotations must be accounted for in the equations of motion. While the accelerometers are incapable (on their own) of logging rotation about the vertical axis (invariant with the phone's orientation), this seemingly is overcome by placing the iPhone away from the center of rotation of the vehicle you wish to investigate (i.e. car, bike, aircraft).

Intuitively, the data obtained will be point-of-view of the body (i.e. Lagrangian), and not point-of-view of the observer (Eulerian). In other words, acceleration along anybody principle axis may have components along all three global axes. This naturally varies with the orientation of the body coordinate system (CYSb) with respect to the global field CYSg as data are logged.

Thus, a transformation from CYSb to CYSg is necessary when the path traversed is not composed solely of 1:1:1 ordered triplets (ui,vi,wi), if one wishes to obtain a three dimensional path in time.

I'd have to give this some further consideration, but I'd rather get my hands on some data I have logged using the Accelerometer Data Pro app which I have purchased. Unfortunately, I am so far unable to extract data, despite having in best faith replicated the instructions (i.e. WiFi internal server's URL accessed by an independent computer).

Any advice or insights on that front would be of utility.

swied said:
I tried using the simple equations of motion in an Excel spreadsheet to convert accelerations into displacements, but there is so much noise. I did a test where it picked up the phone, walked around, and placed it back in the same spot. I set the origin to be the original resting place of the unit. If everything worked correctly, I hypothesized, then I should be able to plot a path that curves around in space, and then returns back to the origin. ...That didn't happen.

I don't think you can determine your position like this. If you move very slowly the accelerometer doesn't detect anything. But still you change your position.

For example you move north then stop. Then you turn 90° to the right (very slowly) and move forward. The rotation is not detected.

swied said:
I was wondering if anyone else had every played around with similar accelerometer data. What tricks did you use to filter out the noise in the data? Also, how did you subtract out the acceleration of gravity. Unless I hold the phone perfectly level, it is hard to differentiate the accelerations from motion, from gravity. The iPhone doesn't have gyros, so it is difficult to determin the orientation of the device at each data reading.

Hi! I'm developing an app on the iphone for research, using accelerometer raw data. It is very simple to differentiate motion accelerations against gravity acceleration. You can obtain the three components of the motion acceleration using an high-pass filter on the accelerometer raw data. Gravity is a constant acceleration, so using an high-pass filter (which pass high-frequencies and cut low ones) will remove this component. If you use this trick, when the iphone is quiet you wil see (0,0,0) but when the iphone is in motion you will see the motion components, without gravity. In this way the relative orientation of your device during the motion will not affect your data.

Feel free to ask me if you want ;)

Kevinzz, I didnt understand the logic behind what you said so maybe you could explain it.

If I remove the first few frequencies of my accelerometer data (i.e. highpass the data) then I am simply removing slow changing data. That doesn't mean I am rectifiying for orientation unless I know that the orientation of the phone changes less quickly and more smoothly than the motion data.

If I throw my phone up in the air and spin it at the same time then the orientation is changing VERY fast and hence it would be impossible to determine the direction of gravity unless I modeled the throw itself. This is just an example of motion which cannot be rectified. Most uncontrolled motion would be the same.

You say you have used the data for research but how did you use it and under what conditions?

Im trying to get the position accurately under general conditions but its a hard problem. If you have made any progress Id love to hear about it.

You can use the accelerometer and the 3-axis gyro in the iPhone 4 to do more accurate relative rotational detection (especially when traveling in a car).

A better explanation of the differences between the 3-axis gyro and the 3-axis accelerometer, AND the 3-axis digital compass is available in the link below:

iPhone 4 secrets page: http://www.edepot.com/iphone.html

hey
Am kind of doing some similar research so if anyone could help me out with this problem it would be great.
Am using a 3axis accelerometer and a 2 axis gyro sensors which i attach to my leg. Now while walking I want to measure the displacement and also I want to plot the trace of my path. I have use Kalman filter to try to remove the noise while integrating the acceleration but it has not worked as I have expected it too.

Like the original poster, have been using the Accelerometer Data Pro app and Motion Data for some time, like a year. Have been wanting to get the gyro data from my iPhone 4 and have been pestering the ADP author and they finally released the new app that now gets you everything, and uses the gyro to separate out user acceleration vs attitude (as well as gets you GPS data and other stuff). Looks awesome so far.
http://itunes.apple.com/us/app/sensor-data/id397619802?mt=8

There's a MATLAB demo doing exactly this-

http://www.mathworks.co.uk/products/matlab/demos.html?file=/products/demos/shipping/matlab/quake.html

Accelerometer data was used to plot the displacement of the ground during an earthquake. Perhaps the equations will be helpful to you?

Earth quick is an extreme example when the time doesn't play any role,

By taking two times integral from acceleration, you are adding noise, continuesly, So this method for calculating the displacement for longer time from acceleration is not the best one.

Does anyone have some statistical idea to estimate the error or some other clever solution ?
I am specifily looking for a method for 2D trajectory movement within less than 15 sec with almost 200g acceleration.

naarkhoo- Late reply, but 200g is beyond the accelerometer's output capability, even though it should be in-range for the sensor itself. The problem is the data type, which I suppose was done for processing efficiency's sake. Can't post links yet, but I found a thread on another forum that said that the values are stored as doubles, and therefore there's a tradeoff between accuracy and range. Apple has limited the accelerometers to about +/-4g, but apparently it would be possible for them to go to +/-8g by halving the accuracy. This would be enough for me, although I don't see why they can't just open it up to allow us to choose our own range and accuracy within some wide limits. If anyone has any insight into changes Apple has made since this post, and what the current range is, please share.

If anyone has made any progress on their projects, I'd love to hear it. This thread has gone cold, but I'm looking into making my own logging app at the moment. My background is in vestibular neurophysiology, which I haven't done for a while, but I still get the general gist of this problem and would like to play around with the iPhone's sensors to measure displacement and plot things. I'm new to iOS programming though, so it's a tough slog. Any info you guys could provide would be much appreciated!

Neurodoxy - I am interested in this issue as well. I have good iOS programming skills, but would need help in devising the algorithm to compute displacement. I can help with getting the data to you and maybe we can work together on the algorithm?

Have you tried to implement a code to collect accelerometer reading before?
If so, do you have any idea if the accelerometer sensor embedded in the smartphone is sensitive enough to collect the reading every X ms (e.g. 100 ms) or not?

## 1. How does the iPhone accelerometer work?

The iPhone accelerometer is a small sensor embedded in the device that measures changes in acceleration and movement. It works by using tiny micro-electromechanical systems (MEMS) to detect changes in the device's position and movement, and then translates that data into usable information.

## 2. What types of data can be collected from the iPhone accelerometer?

The iPhone accelerometer can collect data on the device's orientation, acceleration, and movement in three-dimensional space. This includes data on the device's tilt, rotation, and overall movement, as well as specific measurements such as velocity and impact force.

## 3. How accurate is the data collected from the iPhone accelerometer?

The accuracy of the data collected from the iPhone accelerometer depends on various factors such as the quality of the hardware, the sensitivity settings, and the calibration of the device. Generally, the data is accurate enough for most applications, but may not be precise enough for highly specialized or scientific purposes.

## 4. What are some common applications that use iPhone accelerometer data?

The iPhone accelerometer data is used in a wide range of applications, including fitness and health tracking, gaming, navigation, and augmented reality. It can also be used for scientific research and data analysis in fields such as sports science and biomechanics.

## 5. How can I access and use the iPhone accelerometer data?

The iPhone accelerometer data can be accessed through the device's built-in accelerometer API, which is available for developers to use in their apps. This API provides access to raw data as well as pre-processed data, making it easier to integrate into various applications. There are also third-party libraries and tools available for easier access and analysis of the data.

• General Engineering
Replies
9
Views
8K
• General Engineering
Replies
6
Views
3K
• General Engineering
Replies
4
Views
5K
• Mechanics
Replies
1
Views
1K
• General Math
Replies
14
Views
1K
• Mechanics
Replies
4
Views
8K
• Mechanics
Replies
3
Views
1K
• Programming and Computer Science
Replies
7
Views
2K
• Introductory Physics Homework Help
Replies
15
Views
6K
• Mechanics
Replies
6
Views
6K