apopt.comCBE 493R Data-Driven Athletics

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.

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

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

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.

PythonOpen the strap file and cut out the first stage

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.

PythonFit a first-order response

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

PythonData, fit and the time constant

Show the expected result without running
after 3 tau (112 s) the fit is within 5% of its new level
Heart rate in beats per minute against seconds since the step, 0 to 180 s. Gray dots from the strap rise from about 64 to about 104; a black fitted curve follows them; a dashed vertical line at tau, about 37 s, meets the curve at 63% of the rise.

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

  1. What fraction of the change has a first-order response covered after one time constant?

    %

  2. The fit gives 37 s where the data were built with 35 s. What is the most likely reason?

  3. Why does the step test use three-minute stages?

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, scipy 1.18.1. In the browser the same code runs on Pyodide, so the last digit can differ.