How to detect walking with Android accelerometer

前端 未结 5 1382
悲&欢浪女
悲&欢浪女 2020-12-13 04:53

I\'m writing an application and my aim is to detect when a user is walking. I\'m using a Kalman filter like this:

float kFilteringFactor=0.6f;

        gravi         


        
相关标签:
5条回答
  • 2020-12-13 05:27

    Google provides an API for this called DetectedActivity that can be obtained using the ActivityRecognitionApi. Those docs can be accessed here and here.

    DetectedActivity has the method public int getType() to get the current activity of the user and also public int getConfidence() which returns a value from 0 to 100. The higher the value returned by getConfidence(), the more certain the API is that the user is performing the returned activity.

    Here is a constant summary of what is returned by getType():

    • int IN_VEHICLE The device is in a vehicle, such as a car.
    • int ON_BICYCLE The device is on a bicycle.
    • int ON_FOOT The device is on a user who is walking or running.
    • int RUNNING The device is on a user who is running.
    • int STILL The device is still (not moving).
    • int TILTING The device angle relative to gravity changed significantly.
    • int UNKNOWN Unable to detect the current activity.
    • int WALKING The device is on a user who is walking.
    0 讨论(0)
  • 2020-12-13 05:29

    My first intuition would be to run an FFT analysis on the sensor history, and see what frequencies have high magnitudes when walking.

    It's essentially seeing what walking "sounds like", treating the accelerometer sensor inputs like a microphone and seeing the frequencies that are loud when walking (in other words, at what frequency is the biggest acceleration happening).

    I'd guess you'd be looking for a high magnitude at some low frequency (like footstep rate) or maybe something else. It would be interesting to see the data.

    My guess is you run the FFT and look for the magnitude at some frequency to be greater than some threshold, or the difference between magnitudes of two of the frequencies is more than some amount. Again, the actual data would determine how you attempt to detect it.

    0 讨论(0)
  • 2020-12-13 05:42

    For walking 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. But I guess that it's not best practise, furthermore it only works when the phone is placed in a pants pocket.

    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-13 05:45

    Try detecting the up and down oscillations, the fore and aft oscillations and the frequency of each and make sure they stay aligned within bounds on average, because you would detect walking and specifically that person's gait style which should remain relatively constant for several steps at once to qualify as moving. As long as the last 3 oscillations line up within reason then conclude walking is occurring as long as this also is true:-

    You measure horizontal acceleration and update a velocity value with it. Velocity will drift with time, but you need to keep a moving average of velocity smoothed over the time of a step, and as long as it doesn't drift more than say half of walking speed per 3 oscillations then it's walking but only if it initially rose to walking speed within a short time ie half a second or 2 oscillations perhaps.
    All of that should just about cover it. Of course, a little ai would help make things simpler or just as complex but amazingly accurate if you considered all of these as inputs to a NN. Ie preprocessing.

    0 讨论(0)
  • 2020-12-13 05:50

    EDIT: I don't think it's accurate enough since when walking normally the average acceleration would be near 0. The most you could do measuring acceleration is detect when someone starts walking or stops (But as you said, it's difficult to filter it from the device moved by someone standing at one place)

    So... what I wrote earlier, probably wouldn't work anyway:

    You can "predict" whether the user is moving by discarding when the user is not moving (obvious), And first two options coming to my mind are:
    Check whether the phone is "hidden", using proximity and light sensor (optional). This method is less accurate but easier.
    Controlling the continuity of the movement, if the phone is moving for more than... 10 seconds and the movement is not despicable, then you consider he is walking. I know is not perfet either, but it's difficult wihout using any kind of positioning, by the way... why don't you just use LocationManager?

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