apopt.comCBE 493R Data-Driven Athletics

Course / Tutorials / Week 4 / Q-10

Quick tutorial Q-10 · Week 4 · about 15 min · Foundation

Open a phone sensor log and plot it

Open a phone accelerometer log, compute its real sample rate from the time stamps, turn three axes into one magnitude, and plot the whole session and a zoom to see the steps and the faults.

  1. 1Gather (used)
  2. 2Statistics (used)
  3. 3Visualize (used)
  4. 4Cleanse
  5. 5Features
  6. 6Balance
  7. 7Scale
  8. 8Split
  9. 9Deploy
  1. Ask
  2. Collect (this week)
  3. Check (this week)
  4. Interpret
  5. Coach
  6. Reassess

Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser.

The decision

A walker wants a step count from a phone in a pocket. Before counting anything, find out what the phone actually recorded: how often, along which axes, and with what faults.

The raw data

Try it

What a phone writes

A free sensor-logging app on a phone writes the accelerometer as a table: a time stamp and three accelerations, x, y and z, along the phone's own axes, in m/s². The file here is the book's synthetic 60-second walk (Chapter 4), made by a script so that its faults are known: the phone was in a pocket, the walker stood still for about 5 seconds, walked, and stood again. Open it and look before you compute anything.

PythonOpen the log

Type a prediction to enable Run.

Show the expected result without running
(2980, 5)
               time  seconds_elapsed      z       y       x
1799704800000000000           0.0000 0.7775 10.3907 -0.4525
1799704800020080128           0.0201 0.0022 10.0185 -0.1915
1799704800041169664           0.0412 0.7386  9.3640 -0.0227
time               0
seconds_elapsed    0
z                  0
y                  0
x                  6

The time column is in nanoseconds since 1 January 1970, the form many logging apps use; seconds_elapsed counts from the start of the log. Six cells of x are empty. Now the clock. Never take the sample rate from the app's settings screen; compute it from the time stamps (Section 4.2.4).

PythonThe real sample rate

Show the expected result without running
median spacing 20.0 ms -> 49.9 Hz
largest gap 820 ms; steps that do not move forward: 20
total acceleration: median 10.11 m/s², largest 78.4

About 50 samples a second, with one gap of 820 ms and 20 rows that do not move forward in time: a block the phone wrote twice. The magnitude of the three axes, √(x² + y² + z²), does not care how the phone sits in the pocket. Standing still it reads gravity, 9.81 m/s²; walking makes it swing around that. The largest value, 78 m/s², is eight times gravity: a spike to check.

One chart

PythonThe walk at two zoom levels

Show the expected result without running
samples between 10 and 14 s: 220 (expected about 200)
Two panels of total acceleration in m/s squared against time in seconds. Top, the whole 60 s: flat near 9.8 for the first and last 5 s, swinging between about 5 and 15 while walking, with one spike to 78 near 21 s and a short flat stretch near 33 s. Bottom, 10 to 14 s: a regular wave with about two peaks a second.

The top panel shows the shape of the session: still, walking, still, and two faults, the spike near 21 s (drawn off the scale here) and a stretch near 33 s where the line goes flat because the sensor froze. The zoom shows the steps themselves, about two a second. The zoom window also holds about 20 more samples than 4 seconds should: that is the block written twice, near 12 s. Nothing has been cleaned yet; Q-12 marks what is wrong without deleting it.

For the athlete: "Your phone logged about 50 readings a second and caught your walking rhythm clearly; before we count steps we'll fix one spike, one frozen second and one repeated block in the file."

With your own data

Record a minute of standing, walking and standing with a free sensor-logging app, phone in a pocket, export the accelerometer as CSV, and run the same cells. Check the rate it delivered against the rate you set.

Check yourself

  1. Time stamps 1799704800020080128 and 1799704800041169664 are in nanoseconds. How many milliseconds apart are they?

    ms

  2. Why plot the magnitude √(x² + y² + z²) rather than one axis?

  3. Why compute the sample rate from the median spacing rather than the mean?

0 of 3 answered · 0 right the first time

References

Built 2026-11-30 with Python packages numpy 2.5.5, pandas 3.1.1, matplotlib 3.11.2. In the browser the same code runs on Pyodide, so the last digit can differ.