title: How to detect walking with Android accelerometer
body: <p>I'm writing an application and my aim is to detect when a user is walking.
  I'm using a Kalman filter like this:</p>
  
  <pre><code>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&gt;0.2)
    //walking
  </code></pre>
  
  <p>The array gravity[] is initialized with 0s.</p>
  
  <p>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.</p>
  
  <p>Am I using the right filter?</p>
  
  <p>Is it right to watch only the magnitude of the vector or have I to look at the single values ??</p>