Question

I'd like to use the values that Android's SensorEvent provides to calculate the same values that are specified for DeviceMotionEvent.

My problem is the part in the Android documentation that refers to Gx, Gy, Gz:

 public void onSensorChanged(SensorEvent event)
 {
      // alpha is calculated as t / (t + dT)
      // with t, the low-pass filter's time-constant
      // and dT, the event delivery rate

      final float alpha = 0.8;

      gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
      gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
      gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

      linear_acceleration[0] = event.values[0] - gravity[0];
      linear_acceleration[1] = event.values[1] - gravity[1];
      linear_acceleration[2] = event.values[2] - gravity[2];
 }

What are supposed to be values of the gravity array referenced in that code? It also mentions alpha, but I still don't understand what it is/represents, how the equation works (What's a low-pass filter? How do you determine the "time-constant"? What's the "delivery-rate" even measuring?), or why it was even set (quite arbitrarily) to 0.8.

I'm obviously lacking in the physics department, but I understand the math. So if someone would be so kind to explain the physics reasoning behind, I would be much obliged. I know that there are explanations of the terms on the pages I linked, but they still hold no meaning in my mind except that the terms match pictures of which axes the device is acceleration along or rotating around.

Was it helpful?

Solution

This is a low-pass digital filter. It is employed for removing vibrations (high-freq signals) in a simple way.

Alpha is between 0 and 1. The higher alpha the more vibrations are removed (you trust more in the historical values of gravity), on the other hand the gravity value is highly delayed.

You have more information here: http://en.wikipedia.org/wiki/Low-pass_filter , look at Discrete-time realization section.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top