The wandering was never noise. Flicking your wrist 20° in 150 ms puts 19.5 m/s² through the accelerometer — five hundred times the noise floor — and that reading is correct: the phone really does travel 70 mm along an arc. Physics was right, intent was not.
So the gyroscope now predicts exactly how much acceleration your rotation explains, and only the remainder is treated as real movement. Add a hard stop whenever the phone is genuinely still and the drift has nowhere left to accumulate.
Calibration runs first: rock the phone side to side, then tilt it forward and back.
Linear acceleration source: detecting…
The gyroscope predicts the acceleration your rotation must have caused: a = α×s + ω×(ω×s). Only what is left over counts as real movement. Auto fit regresses your measured acceleration against that prediction to find the pivot distance itself — turn the phone about your wrist a few times and watch it converge. Pure roll contributes nothing, because the pivot lies on that axis.
When the residual acceleration and the gyroscope are both quiet for a moment, velocity is forced to exactly zero rather than left to decay. Drift then only accrues during the few hundred milliseconds you are actually moving, never in between.
Integrator memory. Longer is more faithful and creeps more — but with the stationary lock active you can afford considerably more of it than before.
Soft gate: subtracts the floor instead of clipping, so real motion keeps its magnitude.
Hand motion lives below about 10 Hz. Everything above it is noise you would otherwise integrate.
Accelerometer anchors the angle, gyroscope smooths it. This is the one you ship.
Detecting…
Gravity sign: normal.