1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Using iPhone accelerometer data

  1. Aug 21, 2009 #1
    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.
  2. jcsd
  3. Aug 21, 2009 #2


    User Avatar
    Gold Member

    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...
  4. Aug 21, 2009 #3
    The data is on my computer at home. I'll post it later tonight.
    Last edited: Aug 21, 2009
  5. Aug 21, 2009 #4


    User Avatar
    Science Advisor

    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.
  6. Aug 21, 2009 #5
    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.
  7. Aug 21, 2009 #6
    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.
  8. Aug 21, 2009 #7
    Hmm. I guess you can't upload .csv files. I changed the extension to .txt, and tried again. Hopefully it will work this time.

    Attached Files:

  9. Aug 22, 2009 #8
    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.
  10. Aug 24, 2009 #9


    User Avatar
    Science Advisor

    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?
  11. Aug 25, 2009 #10
    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 im really confused right now
  12. Aug 27, 2009 #11
    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.

    Attached Files:

    Last edited: Aug 27, 2009
  13. Aug 27, 2009 #12
    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.

    Attached Files:

  14. Aug 28, 2009 #13


    User Avatar
    Science Advisor

    NOW you have something useable! Any plans for using these capabilities?
  15. Aug 28, 2009 #14
    1. Accurately determine the period
    2. Perform the same experiment in the two other dimentions.
    3. Calculate the center of mass of the Iphone!!
  16. Sep 2, 2009 #15
    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 any body 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.
  17. Sep 2, 2009 #16
    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.
  18. Sep 14, 2009 #17
    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 ;)
  19. Mar 21, 2010 #18
    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 im simply removing slow changing data. That doesnt mean im 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 modelled 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.
  20. Jul 6, 2010 #19
    You can use the accelerometer and the 3-axis gyro in the iPhone 4 to do more accurate relative rotational detection (especially when travelling 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
  21. Sep 13, 2010 #20
    Am kind of doing some similar research so if any one 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.
    Any comments on this?
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook