← Back

Motion Detection

DeviceMotion API — raw acceleration, magnitude envelope, step detection from vertical-axis peaks, and movement state classification.

Raw acceleration

X, Y, Z axes and vector magnitude. Walk around to see the rhythmic oscillation of a stride. Sitting still should produce a near-flat line at ≈9.8 m/s² (gravity — if including gravity) or ≈0 (if gravity-subtracted).

Not started
X
0.00
Y
0.00
Z
0.00
Magnitude
0.00
State
Still
Steps
0

Step detection

Steps are detected by finding peaks in the vertical-axis acceleration that exceed a threshold and are separated by at least 300 ms (minimum plausible stride interval). Each detected peak is marked with a tick.

Peak detection algorithm. Smooth the signal with a rolling average to remove high-frequency noise, then detect when the smoothed value rises above mean + threshold and subsequently falls back below it. A refractory period prevents double-counting the same step.