S1553 of 56
0 XP
  1. Hook
  2. Predict
  3. Name it
  4. Check
  5. Explain

S15 · Lesson 53 · Pulse oximeter project

Computing the ratio of ratios from two-wavelength photoplethysmograms, checking it against Beer–Lambert theory, inverting the theory, and fitting an empirical calibration to reference data, then seeing why the calibration is needed

Lesson 33 explained what a pulse oximeter measures; this project builds the calculation. You'll take the red and infrared signals a photodiode would record, extract the ratio of ratios, convert it to saturation with Beer–Lambert theory, and then do what every manufacturer does: fit a calibration line to reference measurements and show that it beats the theory by a wide margin. It's a small version of a real device-development step, where physics gives the form of the answer and data from people gives the numbers.

Predict

Reference data follow SpO₂ = 110 − 25R. At R = 1, what does the Beer–Lambert theory of lesson 33 report?

Name it

Step 1: the ratio of ratios

For each wavelength, the DC level is the record's mean and the AC level its standard deviation; R is their ratios' ratio. Any consistent measure of the pulse works, because the same measure appears at both wavelengths. The tests build signals from Beer–Lambert, I=I0e−kε(λ,S)p(t), with a realistic pulse shape p(t), and check R against ε(660,S)/ε(940,S).

Step 2: theory both ways

r_theory(S) gives lesson 33's R; spo2_theory(R) inverts it:

S=εHb660−RεHb940εHb660−εHbO2660+R(εHbO2940−εHb940)

Step 3: calibration

fit_calibration fits a straight line S = a + bR by least squares to 60 calibration points (with measurement scatter of 1.5 percentage points), and spo2_calibrated applies it. The tests check the fit on 40 new points and compare the theory's error on the same data.

Worked example

What should step 2 give at 98% saturation, and for R = 0.5?

Show the solution
  1. r_theory(0.98). R=3227×0.02+320×0.98693×0.02+1214×0.98=378.11203.6=0.314
  2. spo2_theory(0.5). It returns 0.909.
  3. Against the empirical line. The line gives 97.5% at R = 0.5, so the theory and the calibration disagree by about 7 points even near normal saturations.

Answer r_theory(0.98) gives 0.314, and spo2_theory(0.5) gives 0.909, about 7 points below the empirical line's 97.5%.

Worked example

What does step 3 report on the test data?

Show the solution
  1. The fitted line. The fit gives a = 109.75 and b = −24.54, close to the 110 and −25 that generated the data.
  2. Its error on new points. On the 40 new points its RMS error is 1.60 percentage points, about the scatter in the reference data.
  3. The theory's error. On the same points the Beer–Lambert theory reads 10.4 points low on average.

Answer the fit gives a = 109.75 and b = −24.54, with an RMS error of 1.60 points on the test data, while the uncalibrated theory reads 10.4 points low on average.

Check

Step 1. Write ratio_of_ratios: the oximeter's measurement from two photodetector records.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 2. Write r_theory and spo2_theory: Beer–Lambert in both directions.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 3. Write fit_calibration: an empirical calibration line from reference data.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a pulse oximeter need an empirical calibration when Beer–Lambert theory predicts the ratio from first principles?

Practice

Keep practicing

3 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.