Course / Tutorials / Week 9 / Q-25
Quick tutorial Q-25 · Week 9 · about 15 min · Foundation
Find foot contacts in an ankle trace
Find each foot contact in a treadmill runner's ankle trace, first the naive way, then with the running app's three guards.
- 1Gather
- 2Statistics
- 3Visualize (used)
- 4Cleanse (used)
- 5Features (used)
- 6Balance
- 7Scale
- 8Split
- 9Deploy
- Ask
- Collect
- Check (this week)
- Interpret (this week)
- Coach
- Reassess
Download notebook ·Python file ·Read as Markdown ·Data folder ·Chapter 9 (sections 9.1, 9.2)
Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser. Helpful first: Q-24 Seventeen keypoints for one frame, as a table.
The decision
Every timing measure of running, cadence, contact time and flight time, starts from a list of foot contacts. Is the list right: one contact per foot plant, none doubled, none missed?
The raw data
raw/form1_ankles.csv: both ankles' image position and confidence in every frame of a treadmill run filmed from behind at 30 frames per second (464 rows). Chapter 9's example table, also published with the book's data (book/ch09-gait).
Try it
Chapter 9's running example is a runner on a treadmill, filmed from behind at 30 frames per second for 15.5 s. A pose model found both ankles in every frame, and the table keeps their image position and confidence. A foot on the belt is at its lowest point in the picture, which in image coordinates is its largest y. So a contact is a peak of y.
Type a prediction to enable Run.
Show the expected result without running
(464, 8) 15.5 s; median ankle confidence 0.99 left ankle, every local peak: 107 'contacts'
A runner at 170 steps a minute makes 85 contacts a minute on each foot, about 22 in 15.5 s. Every local peak gives 107, five times too many: a noisy trace has small bumps, and each bump is a peak. The running app adds three guards (checked in its source, form/src/lib/metrics.ts): smooth the trace over about 0.08 s (3 frames at 30 per second); accept only peaks in the bottom 15% of the foot's range, above the 85th percentile of y; and keep peaks at least 0.2 s apart.
Show the expected result without running
l: 22 contacts; same-foot interval median 0.700 s, range 0.667 to 0.733 s r: 22 contacts; same-foot interval median 0.700 s, range 0.667 to 0.733 s
Show the expected result without running

With the guards, each foot gives 22 contacts, one per stride, and the same-foot interval stays between about 0.67 and 0.73 s, 20 to 22 frames. That narrow range is the check that no contact was doubled or missed: a doubled contact would show as an interval near half a stride, a missed one as an interval near a whole extra stride. Notice that the intervals can only be whole frames, 33 ms apart; Q-26 shows what that does to a cadence.
For the athlete: a phone can find every foot contact in a steady run, as long as the whole foot stays in the frame.
With your own data
Build the same two-ankle table from your own clip (Chapter 9's first listing, or CS-10's local cells) and run this page on it. Film 15 s or more of steady running with the feet always in the frame.
Check yourself
Why is a foot contact a peak of image y, not a dip?
The guards keep peaks at least 0.2 s apart. At 30 frames per second, how many frames is that?
The same method in another field
Finding events in a repeating signal with a level and a minimum spacing is how heartbeats are found in an ECG (Q-13) and how cycles are counted in a machine's vibration record.
Acknowledgements
Ankle table from Chapter 9 of Data-Driven Athletics, made with Ultralytics YOLO26 (AGPL-3.0).
References
- Chapter 9 of Data-Driven Athletics: Cycles and Events; Running: Contact and Flight.
Built 2026-11-30 with Python packages numpy 2.5.5, pandas 3.1.1, matplotlib 3.11.2, scipy 1.18.1. In the browser the same code runs on Pyodide, so the last digit can differ.