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.