how to count step using accelerometer in android

前端 未结 3 1444
野性不改
野性不改 2020-12-07 15:46

i need to count no of steps while walking. so that i am using accelerometer. in the above coding i get accelerometer sensor\'s x,y,z values. this is i have done so far. my p

相关标签:
3条回答
  • 2020-12-07 16:27

    You will not find here a simple code to just count steps (it is just too complex). But there's info out there if you're interested:

    • There are good diagrams and step analyses here (in pdf).

    • You can find a more formal publication here: http://portal.acm.org/citation.cfm?id=1554235

    • And if you want to create a sensitive pedometer (proposed for the elderly), I suggest you to start from this paper: http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4575030

    0 讨论(0)
  • 2020-12-07 16:43

    For step detection I use the derivative applied to the smoothed signal from accelerometer. When the derivative is greater than threshold value I can suggest that it was a step. May be it's not best practise but it's works for me :)

    The following code was used in this app https://play.google.com/store/apps/details?id=com.tartakynov.robotnoise

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER){
                return;
            }
            final float z = smooth(event.values[2]); // scalar kalman filter                               
            if (Math.abs(z - mLastZ) > LEG_THRSHOLD_AMPLITUDE)
            {
                mInactivityCount = 0;
                int currentActivity = (z > mLastZ) ? LEG_MOVEMENT_FORWARD : LEG_MOVEMENT_BACKWARD;                  
                if (currentActivity != mLastActivity){
                    mLastActivity = currentActivity;
                    notifyListeners(currentActivity);
                }                   
            } else {
                if (mInactivityCount > LEG_THRSHOLD_INACTIVITY) {
                    if (mLastActivity != LEG_MOVEMENT_NONE){
                        mLastActivity = LEG_MOVEMENT_NONE;
                        notifyListeners(LEG_MOVEMENT_NONE);                                 
                    }
                } else {
                    mInactivityCount++;
                }
            }
            mLastZ = z;
        }
    
    0 讨论(0)
  • 2020-12-07 16:46

    You can estimate the gravity force on the phone using the x,y,z values...

    float g = (x * x + y * y + z * z) / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
    

    ...here a value of 1 = normal (1g is normal)

    The a crude pedometer can be built fairly easily by just counting how many peaks above a specified g value over a given sample period (eg 6 seconds and multiple by 10 for paces per minute)

    Say for example record the time in ms that a g of >2 is recorded... then the peak will continue going up.... and come back down below 2.. probably to 0.5 or something.. then it'll go up again >2... at this point stop the clock.

    ...then you have a complete cycle timed!

    To stabilise the result it's better to count a few cycles.

    0 讨论(0)
提交回复
热议问题