TYPE_ACCELEROMETER Remove gravity, value t / (t + dT)

Android Developer Example:

public void onSensorChanged(SensorEvent event)
{
      // alpha is calculated as t / (t + dT)
      // with t, the low-pass filter 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];
}

alpha = 0.8, which of the numerical calculations? I want to set specific t and dT values.

+4
source share
1 answer

To answer your question, I will have to slip a little into the low-pass filter, since alpha is almost the last value that we get.

A low-pass filter is usually created in the following order:

  • The cutoff frequency fc in Hertz you want to cut off (here gravity continues, so the value should be around 1 Hz)
  • Time constant τ (tau)τ = 1/(2 * π * fc)
  • Delta time Δt in the second. ∆t = t2 - t1
  • The smoothing factor α, in this case α = τ / (τ + ∆t)
  • .

alpha . - 0 1. () 80% , (event.values) 20% = > new gravity = 80% old gravity + 20% acceleration.

∆t . SENSOR_DELAY_NORMAL 0.2s.

τ α = 0,8 Δt = 0,2

τ α :

τ = (∆t * α) / (1 - α)

τ  = 0.2 * 0.8 / (1 - 0.8) = 0.8

τ fc:

fc = 1 / (2 * π * τ) = 1/( 2 * 3.14 * 0.8) = 0.2Hz.
+1

Source: https://habr.com/ru/post/1627233/


All Articles