Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I improve the accuracy of this pedometer algorithm?

I've tried several ways of measuring the steps a user makes with an iPhone by reading the accelerometer, but none have been very accurate. The most accurate implementation I've used is the following:

 float xx  = acceleration.x;
 float yy  = acceleration.y;
 float zz = acceleration.z;

 float dot = (mOldAccX * xx) + (mOldAccY * yy) + (mOldAccZ * zz);
 float a = ABS(sqrt(mOldAccX * mOldAccX + mOldAccY * mOldAccY + mOldAccZ * mOldAccZ));

 float b = ABS(sqrt(xx * xx + yy * yy + zz * zz));

 dot /= (a * b);

 if (dot  <= 0.994 && dot > 0.90) // bounce
 {

  if (!isChange)
  {

   isChange = YES;
   mNumberOfSteps += 1;

  } else {
   isChange = NO;
  }
 }

 mOldAccX = xx;
 mOldAccY = yy; 
 mOldAccZ = zz;
}

However, this only catches 80% of the user's steps. How can I improve the accuracy of my pedometer?

like image 400
user470872 Avatar asked Oct 09 '10 06:10

user470872


3 Answers

Here is some more precise answer to detect each step. But yes in my case I am getting + or - 1 step with every 25 steps. So I hope this might be helpful to you. :)

if (dot <= 0.90) {
    if (!isSleeping) {
        isSleeping = YES;
        [self performSelector:@selector(wakeUp) withObject:nil afterDelay:0.3];
        numSteps += 1;
        self.stepsCount.text = [NSString stringWithFormat:@"%d", numSteps];
    }
}



- (void)wakeUp {

       isSleeping = NO;
     }
like image 119
procrastinator Avatar answered Nov 08 '22 16:11

procrastinator


Keep in mind that not everyone makes the same big steps. So the dot calculation should be adjusted according to someone's length, step size.

You should adjust the bounce threshold accordingly. Try to make the program learn about it's passenger.

like image 24
dominus Avatar answered Nov 08 '22 16:11

dominus


ok, I'm assuming this code is within the addAcceleration function...

-(void)addAcceleration:(UIAcceleration*)accel

So, you could increase your sampling rate to get a finer granularity of detection. So for example, if you are currently taking 30 samples per second, you could increase it to 40, 50, or 60 etc... Then decide if you need to count a number of samples that fall within your bounce and consider that a single step. It sounds like you are not counting some steps due to missing some of the bounces.

Also, what is the purpose of toggling isChange? Shouldn't you use a counter with a reset after x number of counts? If you are within your bounce...

if (dot  <= 0.994 && dot > 0.90) // bounce

you would have to hit this sweet spot 2 times, but the way you have set this up, it may not be two consecutive samples in a row, it may be a first sample and a 5th sample, or a 2nd sample and an 11th sample. That is where you are loosing step counts.

like image 35
jcpennypincher Avatar answered Nov 08 '22 18:11

jcpennypincher