# Inertial Motion Sensing on Commodity Devices

**Packet:** movement-capture-and-networked-musical-expression · **Date:** 2026-08-16
**Verification:** live-web-verified · **Lane model class:** Claude Sonnet 5

## Why this field grounds the work

`@miadi/termux-motion` turns a phone's inertial measurement unit (IMU) into a music-control signal, and every one of its nine channels inherits the physics and error model of consumer MEMS sensing — not a clean abstraction. Channels 1–3 are only "gravity removed" because Android's software fusion subtracts an estimate of gravity from a raw accelerometer reading that physically includes it; channels 7–9 (attitude) are a filtered, drift-prone derivative of gyroscope and accelerometer data, not a direct measurement. The g-vs-m/s² conversion the dispatcher flagged as a risk is in fact already handled correctly in `packages/termux-motion/src/source.ts` (`STANDARD_GRAVITY = 9.80665`). And the belly placement and 5.01 Hz / 9.9 Hz rates measured in Episode 083 sit at the edge of, or below, what the sensing and human-activity-recognition (HAR) literature treats as usable — this is the field that explains exactly what that edge costs.

## Canonical concepts

- **Specific force, not coordinate acceleration.** A MEMS accelerometer measures the force per unit mass acting on its proof mass — "specific force" — which is indistinguishable from gravity when the device is stationary. A phone lying flat reads ~1 g on its vertical axis even though it is not accelerating in the inertial sense; this is why "gravity-removed" acceleration is always a computed quantity, never a raw one [madgwick-2010].
- **Gyroscope integration drift.** A MEMS gyroscope measures angular rate, not angle; integrating it over time to get orientation accumulates bias and noise as an unbounded random walk. Neither sensor alone gives a usable pose: the accelerometer alone cannot resolve orientation during motion (it cannot separate gravity from linear acceleration), and the gyroscope alone cannot hold a stable heading over any meaningful duration [mahony-2008].
- **Complementary/Mahony/Madgwick/EKF fusion.** Complementary filters blend high-pass-filtered gyroscope integration with low-pass-filtered accelerometer (and magnetometer) references; Mahony's formulation poses this as a nonlinear observer on SO(3) with proportional-integral gyro-bias correction, tuned for computational efficiency on embedded hardware [mahony-2008]. Madgwick's gradient-descent filter operates on quaternions directly and is reported as more accurate but more compute-hungry; Mahony is reported to hold up better under fast dynamic motion [madgwick-2010].
- **Quaternions vs. Euler angles, and gimbal lock.** Roll/pitch/azimuth (Euler angles) are intuitive but singular: when pitch approaches ±90°, roll and yaw axes align and one rotational degree of freedom is lost — gimbal lock. Fusion filters compute internally in quaternions (a 4-parameter, singularity-free representation) and convert to Euler angles only for output, which is exactly what Android's rotation-vector/orientation pipeline and this repo's attitude channel do [madgwick-2010].
- **Yaw/azimuth is the weak axis.** Roll and pitch are observable from gravity via the accelerometer; yaw (azimuth/heading) is not — gravity gives no heading reference. Without a magnetometer, yaw is gyro-integration-only and drifts unbounded; with a magnetometer it is bounded but corrupted by magnetic disturbance, which differs sharply between indoor environments (steel structures, electronics) and outdoor open-air movement practice like Episode 083's landbase walk.
- **Android's sensor stack is two tiers.** `TYPE_ACCELEROMETER` and `TYPE_GYROSCOPE` are hardware sensors reporting in SI units (m/s², rad/s); `TYPE_LINEAR_ACCELERATION` and `TYPE_ROTATION_VECTOR`/`TYPE_GAME_ROTATION_VECTOR` are documented "software-based" sensors, fused from the hardware ones on-device, and Android's own developer documentation names `TYPE_LINEAR_ACCELERATION` explicitly as acceleration "excluding the force of gravity" [android-sensors-overview].
- **`SENSOR_DELAY_*` is a hint, not a contract.** Android's documentation states plainly that "the delay that you specify is only a suggested delay [and] the system typically uses a smaller delay than the one you specify" — there is no public API to determine the actual delivered rate short of timestamping events yourself [android-sensors-overview].
- **Nyquist bounds what a sampled signal can represent.** A signal sampled at *f*ₛ Hz can only unambiguously represent content up to *f*ₛ/2 Hz; content above that aliases into the recoverable band as spurious low-frequency energy rather than simply disappearing.

## Key findings

1. **The g-conversion is a documented Android fact, and the repo already gets it right.** Android's accelerometer and linear-acceleration sensors report in m/s²; dividing by standard gravity (9.80665 m/s²) is the correct, conventional way to express that in g, and `packages/termux-motion/src/source.ts` already does exactly this (`STANDARD_GRAVITY = 9.80665`), with a comment explaining it aligns Android scores with an "iOS-era corpus." This is not a gap — it is the field's central unit fact, already handled [android-sensors-overview].
2. **9.80665 m/s² is standard gravity by international convention, not local measured gravity.** Actual surface gravity varies ~9.78–9.83 m/s² by latitude and altitude. The conversion is a defensible convention (matching what iOS and most consumer tooling use), not a claim about the gravity experienced at the Episode 083 capture site.
3. **Attitude (channels 7–9) is categorically different from acceleration/rotation (channels 1–6).** The first six channels are close to raw hardware output (acceleration has gravity subtracted, but is still a per-sample physical measurement); attitude is the output of a fusion filter with its own drift, latency, and (for yaw specifically) unboundedness absent a magnetometer reference. A builder should not treat all nine channels as equally trustworthy.
4. **`SENSOR_DELAY` being a hint explains, at least in part, why requested and observed rates diverge.** `packages/termux-motion/src/source.ts` requests a bridge delay (`delayMs`, default 100 ms → a nominal 10 Hz ask); Android's own documentation states the OS "typically uses a smaller delay than the one you specify" and offers no guarantee. That the Episode 083 capture measured 5.01 Hz against (presumably) a 10 Hz-class ask, and a later run measured 9.9 Hz, is consistent with this being throttled by the OS/bridge stack rather than a defect in the source code [android-sensors-overview].
5. **What 5 Hz can and cannot see.** At 5.01 Hz, Nyquist gives a ~2.5 Hz ceiling on recoverable content. Human walking cadence and its lowest gait harmonics sit close to or above that ceiling (walking signal energy is described in the literature as concentrated below roughly 6 Hz, with running content reaching ~15 Hz); the HAR literature's empirical floor for stable activity-classification accuracy is around 10 Hz (accuracy stable at 10 Hz, degrading sharply only below 1 Hz in one recent multi-site-sensor study), with the field's practical optimum commonly cited as 20–50 Hz and datasets such as UCI HAR built at 50 Hz. **Recoverable at 5 Hz:** gross presence/absence of motion, coarse tempo/envelope trends, step-count-scale events. **Lost at 5 Hz:** individual stride kinematics, gait-cycle harmonics and asymmetry, heel-strike-scale transients, and any fine gesture detail — the resolution needed for anything beyond "is the body moving, roughly how fast."
6. **Belly/waist placement is a defensible, not optimal, choice for whole-body capture.** It sits near the body's center of mass, giving accurate step counts and gross temporal gait measures with <5% error against ankle-worn reference in one study; it is documented to be specifically poor at stride-asymmetry and step-time-variability measures, partly attributed to sensing through clothing rather than skin contact [vavasour-2023].
7. **Consumer smartphone MEMS IMU noise floors are low relative to gross-movement needs, but not research-grade.** Reference-class MEMS parts used in phones report noise densities on the order of tens of µg/√Hz (accelerometer) and a few mdps/√Hz (gyroscope); direct phone-vs-phone lab measurements found real-world accelerometer standard deviations around 0.01 m/s² and gyroscope standard deviations around 0.003 rad/s across tested devices — adequate for coarse movement-practice signals, not for kinematic reconstruction.
8. **Long unattended outdoor captures on Android are vulnerable to Doze/battery-optimization throttling**, which can defer or suspend background work; robust long-duration capture typically needs a foreground-service-equivalent posture (Termux itself commonly needs `termux-wake-lock` and a battery-optimization exemption) — a second plausible confound alongside the `SENSOR_DELAY` hint for rate variability across runs.
9. **`termux-sensor` (Termux:API) is a community-documented CLI, not a benchmarked instrument.** It lists sensors (`-l`), selects them by role-name (`-s`), and takes a delay-in-milliseconds argument (`-d`) — exactly the interface `source.ts` drives — but its actual achieved rate is governed by the same underlying Android `SensorManager` hint behavior, with an added layer of process/JSON-serialization overhead from the bridge binary itself.

## Cautions & contested ground

- The 9.9 Hz figure from the 2026-08-15 run is lane-reported in this packet's brief, not independently verified by this lane — treat it as provisional until the raw capture is inspected.
- No peer-reviewed literature reviewed here validates a 5 Hz phone-IMU stream specifically for expressive/musical motion-to-sound mapping. The HAR and gait literature's "10 Hz is often adequate" findings are about *classification accuracy* on discrete activity labels, not continuous expressive control latency or nuance — the transfer is plausible, not established.
- "Sufficient sampling rate" numbers in the literature are strongly task-dependent: one orientation-estimation study puts sufficient IMU rates at 100 Hz (walking), 200 Hz (running), 400 Hz (fast cyclic movement) [fan-2025], while HAR classification studies find 20–50 Hz adequate and even 10 Hz survivable for coarse activities [yamane-2025]. These are not contradictory — they answer different questions (continuous kinematic reconstruction vs. discrete activity labeling) — but citing either number as a universal floor would be wrong.
- Android's exact `SENSOR_DELAY` throttling behavior is OS-version- and vendor-dependent and not something either this lane or the cited documentation can pin to a specific number for the Episode 083 device; it explains the *shape* of the observed gap (requested-vs-delivered), not a precise mechanism.
- Direct fetches of the Termux wiki and Termux:API GitHub wiki were blocked by an anti-bot gate (Anubis) and a GitHub wiki edit-form redirect respectively during this session; the `termux-sensor` flag details above come from live search-result snippets referencing that documentation, not a direct page read — treat the CLI-flag claims as web-search-verified, not primary-source-verified.
- Consumer MEMS noise-density figures cited here come from a reference-class datasheet part (ICM-42688-P) used as an illustrative example plus one lab comparison study measuring several actual phones; they are indicative of the class of hardware, not a spec sheet for the specific device used in Episode 083, which is unidentified in the material available to this lane.

## Engineering implications for this repo

- `packages/termux-motion/src/source.ts` already implements the correct g-conversion (`STANDARD_GRAVITY = 9.80665`) and the correct degrees→radians, `[azimuth, pitch, roll]`→`[roll, pitch, azimuth]` reordering for attitude — no change indicated by this field's findings. The `delayMs` option (default 100) should be documented explicitly as a *request*, per Android's own "hint, not guarantee" language, so its default's relationship to the observed 5.01 Hz / 9.9 Hz field results reads as expected behavior rather than a bug to chase.
- `packages/termux-motion/src/discover.ts`'s `castRoles` correctly prefers a "linear acceleration"-named sensor over a raw accelerometer, and a calibrated gyroscope over an uncalibrated one — both match this field's finding that gravity-removed and bias-corrected variants are what the frame contract expects. One forward-looking note: it casts attitude onto a legacy `"orientation"`-named virtual sensor; Android's own docs describe `TYPE_ORIENTATION` as superseded by `TYPE_ROTATION_VECTOR` plus `getOrientation()`/`getRotationMatrix()`. If a target device lacks a legacy orientation sensor, deriving attitude from `TYPE_ROTATION_VECTOR`'s quaternion locally (rather than trusting a device-side Euler fusion of unknown filter quality) would be the more defensible long-term path — worth a note in `discover.ts`, not an urgent fix.
- `packages/movement-conductor/src/frame.ts` documents the nine-channel contract correctly; consider adding an explicit doc note there that channels 1–6 are near-raw per-sample physical measurements while channels 7–9 are filtered/derived with materially different error and drift behavior — a fact a downstream mapping/ML lane needs to weight channels correctly, and one this field makes concrete rather than a stylistic preference.
- `packages/movement-conductor/src/summary.ts` is already doing exactly the right instrumentation — `rate_hz_over_window` and `rate_hz_between_first_last` are the honest way to surface the "requested vs. delivered" sampling-rate gap this field identifies as expected Android behavior, not a defect. Consider also recording the *requested* `delayMs` in `SummaryMeta`/`ScoreSummary` (it currently tracks `requestedDurationSeconds` but not requested rate) so a score can show "asked for 10 Hz, got 5.01 Hz" side by side — that comparison is the single most diagnostic number this field says to capture, and it is currently only reconstructable by cross-referencing CLI args against the summary output.
- Given the Nyquist-vs-5-Hz finding, any downstream consumer of these scores (mapping/ML lane, not this lane's concern to design) should not expect stride-level or fast-gesture detail from a ~5 Hz capture; `summary.ts`'s honest low-rate reporting (never inflating a partial signal) is the structurally correct posture given that ceiling, not something to silently interpolate away.

## Lines worth carrying into voice chronicle

- A phone held to the belly still feels gravity — the software has to guess it away before a number means motion.
- Ten samples a second were asked for; about five arrived — that gap is the phone's own timing hint being loose, not a broken sensor.
- At five samples a second you can hear that a body moved and roughly how fast, but not the fine rhythm of each step.
- Roll, pitch, and yaw are never read directly off the phone — they are the sensor's best guess, stitched together and always a little unsure of north.
- The belly is a fair place to feel a whole body move, and a poor place to feel the small print of one single stride.

## Sources

| id | title | author / venue | year | url or doi | verified |
|---|---|---|---|---|---|
| madgwick-2010 | An efficient orientation filter for inertial and inertial/magnetic sensor arrays | S.O.H. Madgwick, technical report, University of Bristol | 2010 | https://www.semanticscholar.org/paper/An-efficient-orientation-filter-for-inertial-and-Madgwick/bfb456caf5e71d426bd3e2fd529ee833a6c3b7e7 | true |
| mahony-2008 | Nonlinear Complementary Filters on the Special Orthogonal Group | R. Mahony, T. Hamel, J-M. Pflimlin, IEEE Transactions on Automatic Control 53(5) | 2008 | https://hal.science/hal-00488376 | true |
| android-sensors-overview | Sensors Overview (Sensor coordinate system, delay constants, software-based sensors) | Android Developers documentation | 2026 (accessed) | https://developer.android.com/develop/sensors-and-location/sensors/sensors_overview | true |
| twomey-khan-2016 | Optimising sampling rates for accelerometer-based human activity recognition | Khan, Hammerla, et al., Pattern Recognition Letters 73 | 2016 | https://doi.org/10.1016/j.patrec.2016.01.001 | true |
| yamane-2025 | Effects of Sampling Frequency on Human Activity Recognition with Machine Learning Aiming at Clinical Applications | Yamane, Kimura, Morita et al., Sensors 25(12):3780 | 2025 | https://pmc.ncbi.nlm.nih.gov/articles/PMC12196717/ | true |
| fan-2025 | Influence of Sampling Rate on Wearable IMU Orientation Estimation Accuracy for Human Movement Analysis | Fan, Zhang, Cai, Du, Liu, Li, Shull, Sensors 25(7):1976 | 2025 | https://pmc.ncbi.nlm.nih.gov/articles/PMC11991382/ | true |
| anguita-2013 | A Public Domain Dataset for Human Activity Recognition Using Smartphones | Anguita et al., ESANN 2013 (UCI HAR dataset, 50 Hz waist-mounted phone) | 2013 | https://www.esann.org/sites/default/files/proceedings/legacy/es2013-84.pdf | true |
| vavasour-2023 | Waist—What? Can a single sensor positioned at the waist detect parameters of gait at a speed and distance reflective of older adults' activity? | Vavasour, Giggins, Flood, Doyle, Doheny, Kelly, PLOS ONE 18(6):e0286707 | 2023 | https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0286707 | true |
| smartphone-imu-lab-2023 | Smartphone MEMS Accelerometer and Gyroscope Measurement Errors: Laboratory Testing and Analysis of the Effects on Positioning Performance | PMC10490716 | 2023 | https://pmc.ncbi.nlm.nih.gov/articles/PMC10490716/ | true |
| icm42688p-datasheet-ref | ICM-42688-P noise density specification (reference-class MEMS 6-axis part, illustrative of consumer-phone-grade IMU noise floor) | InvenSense/TDK datasheet (via web search excerpt) | n/a | https://www.scribd.com/document/745929015/ICM-42688-P | true |
| imu-optoelectronic-2025 | Validation of a Commercially Available IMU-Based System Against an Optoelectronic System for Full-Body Motor Tasks | Sensors 25(12):3736 | 2025 | https://pmc.ncbi.nlm.nih.gov/articles/PMC12196846/ | true |
| standard-gravity-def | Standard gravity definition (9.80665 m/s², international convention since 1901/re-affirmed) | conversion.org / ASA Standards (via web search) | n/a | https://asastandards.org/terms/standard-acceleration-due-to-earths-gravity/ | true |
| termux-play-store-2026 | Termux Google Play Store deprecation, F-Droid/GitHub as official sources, 2026 status | termux/termux-app GitHub Discussions | 2026 | https://github.com/termux/termux-app/discussions/4000 | true |
| termux-sensor-flags | termux-sensor CLI flags (-l, -s, -d, -n, -a, -c) | Termux Wiki / termux-api source (via web search excerpt; direct wiki fetch blocked by anti-bot gate this session) | n/a | https://wiki.termux.com/wiki/Termux-sensor | true |
| android-doze-standby | Optimize for Doze and App Standby | Android Developers documentation | 2026 (accessed) | https://developer.android.com/training/monitoring-device-state/doze-standby | true |
| gait-frequency-content | Frequency Domain Approach for Activity Classification using Accelerometer (walking signal frequency content) | arXiv:1107.4417 | n/a | https://arxiv.org/pdf/1107.4417 | true |
