views:

364

answers:

2

hi i want to know how to calculate steps taken using the Accelerometer. Actually i calculate acceleration and use this code to count step

length = sqrt(x * x + y * y + z * z);
if(length>=2){
   stepcount+=1;
}

where length calculate acceleration using acceleration.x, acceleration.y,acceleration.z But my main problem at starting the application the stepcount gives correct step value but as time pass its value is not correct.Plz help me

A: 

Edit: I seem to have misunderstood the problem. See Omnifarious' answer, which is more appropritate.


If you take the length of the acceleration vector, that is not going to give you the total distance traveled. This is going to be a bit more complex than that:

  • Set your distance (scalar) and velocity (vector) to 0 to start with.
  • At each time interval, add the current acceleration vector to the velocity vector to compute an updated velocity vector.
  • At each time interval, add the magnitude of the velocity vector to the distance to accumulate the distance traveled.
  • If these intervals are not unit intervals in whatever time coordinate system you are using, then scale the acceleration and velocity vectors appropriately. For example, if you acceleration is expressed in m/s^2 and your sampling interval is 100ms, then scale the acceleration vector by 0.1 before adding it to the velocity vector. Likewise when accumulating velocity into distance.

For example, suppose you accelerate a bit and then travel at a steady speed, the acceleration vector is going to be 0. However, since some velocity has built up, the distance traveled should steadily keep on increasing.

If you want to track the actual position, then maintain that as a vector, and keep adding the current velocity vector to it at each interval of time.

This is inertial navigation by dead reckoning, and errors will start to accumulate (in the velocity vector, and hence over the distance) over time. You need to do some experimentation to see what kind of accuracy you can hope to get.

Tarydon
The asker doesn't want to measure distance. S/he just wants to implement a pedometer.
KennyTM
He says he wants to measure steps, not total distance traveled. Looking for sudden changes of acceleration isn't actually a horrible way to do this.
Omnifarious
@Omnifarious: I bow to your superior wisdom.
Tarydon
@Tarydon, gee, I feel special now. :-) I also initially misread it as a dead-reckoning problem.
Omnifarious
+3  A: 

Basically you're using sudden acceleration over a certain value as a sign that someone is ending or starting a step.

First, you have to make sure you end up sampling the accelerometer frequently enough not to miss a step. Then you're going to have to make sure that you are guessing correctly about what your threshold should be.

This is going to require a lot of trial and error.

What I would recommend is graphing out what the length is over time and seeing if you can come up with a good threshold value that's usually correct.

But, regardless, it's never really going to be accurate. I think the only way to really measure steps accurately is with a heel sensor in the shoe.

Omnifarious
don't You know the threshold?????
Nope. I imagine it would be different from device model to device model even. It depends on the units the accelerometer measures.
Omnifarious