Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to calculate exact foot step count using accelerometer in android?

I am developing some application like Runtastic Pedometer using the algorithm but I am not getting any similarity between the results.

my code is as follows:

public void onSensorChanged(SensorEvent event)  {         Sensor sensor = event.sensor;          synchronized (this)  {             if (sensor.getType() == Sensor.TYPE_ORIENTATION) {}             else {             int j = (sensor.getType() == Sensor.TYPE_ACCELEROMETER) ? 1 : 0;                 if (j == 1) {                     float vSum = 0;                     for (int i=0 ; i<3 ; i++) {                         final float v = mYOffset + event.values[i] * mScale[j];                         vSum += v;                      }                     int k = 0;                     float v = vSum / 3;                     //Log.e("data", "data"+v);                      float direction = (v > mLastValues[k] ? 1 : (v < mLastValues[k] ? -1 : 0));                     if (direction == - mLastDirections[k]) {                         // Direction changed                         int extType = (direction > 0 ? 0 : 1); // minumum or maximum?                         mLastExtremes[extType][k] = mLastValues[k];                         float diff = Math.abs(mLastExtremes[extType][k] - mLastExtremes[1 - extType][k]);                          if (diff > mLimit) {                              boolean isAlmostAsLargeAsPrevious = diff > (mLastDiff[k]*2/3);                             boolean isPreviousLargeEnough = mLastDiff[k] > (diff/3);                             boolean isNotContra = (mLastMatch != 1 - extType);                              if (isAlmostAsLargeAsPrevious && isPreviousLargeEnough && isNotContra) {                                  for (StepListener stepListener : mStepListeners) {                                     stepListener.onStep();                                 }                                 mLastMatch = extType;                             }                             else {                                 Log.i(TAG, "no step");                                 mLastMatch = -1;                             }                         }                         mLastDiff[k] = diff;                     }                     mLastDirections[k] = direction;                     mLastValues[k] = v;                 }             }         }     } 

for registering sensors:

mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);         mSensor = mSensorManager.getDefaultSensor(                 Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(mStepDetector,mSensor,SensorManager.SENSOR_DELAY_NORMAL); 

in the algorithm i have different levels for sensitivity as public void

setSensitivity(float sensitivity) {         mLimit = sensitivity; // 1.97  2.96  4.44  6.66  10.00  15.00  22.50  33.75  50.62     } 

on various sensitivity level my result is:

sensitivity   rantastic pedometer  my app 10.00           3870                 5500 11.00           3000                 4000 11.15           3765                 4576 13.00           2000                 890 11.30           754                  986 

I am not getting any proper pattern to match with the requirement. As per my analysis this application is using Sensor.TYPE_MAGNETIC_FIELD for steps calculation please let me know some algorithm so that I can meet with the requirement.

like image 385
user3056585 Avatar asked Dec 02 '13 09:12

user3056585


People also ask

Can an accelerometer measure steps?

Steps can be counted using a pedometer, which often uses data from a hardware accelerometer as input.

Which sensor is used to count steps in Android?

Use the step counter sensor The step counter sensor provides the number of steps taken by the user since the last reboot while the sensor was activated.


1 Answers

The first thing you need to do is decide on an algorithm. As far as I know there are roughly speaking three ways to detect steps using accelerometers that are described in the literature:

  1. Use the Pythagorean theorem to calculate the magnitude of the acceleration vector of each sample from the accelerometer. Low-pass filter the magnitude signal to remove high frequency noise and then look for peaks and valleys in the filtered signal. You may need to add additional requirements to remove false positives. This is by far the simplest way to detect steps, it is also the way that most if not all ordinary pedometers of the sort that you can buy from a sports store work.

  2. Use Pythagoras' like in (1), then run the signal through an FFT and compare the output from the FFT to known outputs of walking. This requires you to have access to a fairly large amount of training data.

  3. Feed the accelerometer data into an algorithm that uses some suitable machine learning technique, for example a neural network or a digital wavelet transform. You can of course include other sensors in this approach. This also requires you to have access to a fairly large amount of training data.

Once you have decided on an algorithm you will probably want to use something like Matlab or SciPy to test your algorithm on your computer using recordings that you have made on Android phones. Dump accelerometer data to a cvs file on your phone, make a record of how many steps the file represents, copy the file to your computer and run your algorithm on the data to see if it gets the step count right. That way you can detect problems with the algorithm and correct them.

If this sounds difficult, then the best way to get access to good step detection is probably to wait until more phones come with the built-in step counter that KitKat enables.

like image 53
Rasmusob Avatar answered Sep 19 '22 22:09

Rasmusob