Course / Tutorials / Week 2 / Q-6
Quick tutorial Q-6 · Week 2 · about 15 min · Core
A first-order response: heart rate after a step
Cut the first stage out of a chest strap's step-test record, fit a first-order response with curve_fit, and read the time constant three ways.
- 1Gather (used)
- 2Statistics
- 3Visualize (used)
- 4Cleanse
- 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 2 (sections 2.4)
Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser. Helpful first: Q-5 Fit a straight line and read the slope's units.
The decision
A coach wants to know how long after the start of an interval the athlete's heart rate is worth reading. The answer is a time constant, and a fit gives it with an uncertainty.
The raw data
raw/steptest_hr.csv: second-by-second heart rate through a three-stage step test and five minutes of recovery, with the phase of each second (synthetic). Data-Driven Athletics, Chapter 2, Sections 2.4 and 2.11: Sam's step test, synthetic data built with a 35 s time constant for the climb and 50 s for recovery.
Try it
A step in work, a curve in heart rate
When Sam steps onto the bench, the work jumps to its new level at once. Heart rate does not: it climbs toward a new level over tens of seconds. Section 2.4 models that climb as a first-order response, the curve of a tank filling through a valve:
y(t) = y∞ + (y₀ − y∞) e^(−t/τ)
where y₀ is the heart rate before the step, y∞ the level it settles toward, and τ (tau) the time constant: the time to cover 63% of the change. The file is a chest strap's heart rate, one value a second, through Sam's step test. Sam is made up; the data are the book's synthetic test, built with a time constant of 35 s for the climb, so you can check the fit.
Type a prediction to enable Run.
Show the expected result without running
phase step 540 recovery 330 rest 120 pause 40 stage 1: 180 s, heart rate 64 -> 104 bpm (mean of the last 10 s)
Fit the curve
curve_fit from SciPy adjusts y₀, y∞ and τ together until the squared misses, in beats a minute, are as small as possible. It needs a rough starting guess: the first value, the last values, and 30 s.
Show the expected result without running
y0 64.9 bpm, y_inf 103.9 bpm, tau 37.2 +/- 1.4 s 63% of the rise is 89 bpm; the data first reach it at t = 35 s
The fit gives a time constant of 37 ± 1.4 s, against the 35 s the data were built with. The 63% rule read straight off the data gives 35 s. The fit is a little long because the synthetic heart rate also drifts up slowly through the stage (Section 2.4, "Drift"), which a single exponential cannot follow, so it stretches τ to absorb it.
One chart
Show the expected result without running
after 3 tau (112 s) the fit is within 5% of its new level

After three time constants, just under two minutes, heart rate is within 5% of its new level. That is why the step test's stages last three minutes: a count taken earlier would catch heart rate still climbing.
For the athlete: "Your heart rate takes 35 to 40 seconds to cover most of its rise when you start a new effort, so judge an interval's intensity by your heart rate only after the first two minutes."
With your own data
Record a chest strap through a rest and a steady effort (Chapter 5 shows how), cut out the first three minutes of the effort, and fit the same curve. Real heart rate is noisier than this file; report τ with its ± from the fit.
Check yourself
What fraction of the change has a first-order response covered after one time constant?
The fit gives 37 s where the data were built with 35 s. What is the most likely reason?
Why does the step test use three-minute stages?
References
- Data-Driven Athletics, Chapter 2, The Response to a Step (Section 2.4) and Measuring Yourself: A Step Test (Section 2.11).
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.