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;
gravity[0] = (accelerometer_values[0] * kFilteringFactor) + (gravity[0] * (1.0f - kFilteringFactor));
gravity[1] = (accelerometer_values[1] * kFilteringFactor) + (gravity[1] * (1.0f - kFilteringFactor));
gravity[2] = (accelerometer_values[2] * kFilteringFactor) + (gravity[2] * (1.0f - kFilteringFactor));
linear_acceleration[0] = (accelerometer_values[0] - gravity[0]);
linear_acceleration[1] = (accelerometer_values[1] - gravity[1]);
linear_acceleration[2] = (accelerometer_values[2] - gravity[2]);
float magnitude = 0.0f;
magnitude = (float)Math.sqrt(linear_acceleration[0]*linear_acceleration[0]+linear_acceleration[1]*linear_acceleration[1]+linear_acceleration[2]*linear_acceleration[2]);
magnitude = Math.abs(magnitude);
if(magnitude>0.2)
//walking
The array gravity[] is initialized with 0s.
I can detect when a user is walking or not (looking at the value of the magnitude of the acceleration vector), but my problem is that when a user is not walking and he moves the phones, it seems that he is walking.
Am I using the right filter?
Is it right to watch only the magnitude of the vector or have I to look at the single values ??
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.
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.
The accelerometers read around -0.8 ms^-2 on both X and Y axes when stationary, so I used this as my offset.
An accelerometer is an electronic sensor that measures the acceleration forces acting on an object, in order to determine the object's position in space and monitor the object's movement.
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()
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With