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?
Inverting the theory with coefficients 3227/320 at 660 nm and 693/1214 at 940 nm gives S = 73.9% at R = 1, while the calibration gives 85%. Over the range the reference data cover, the theory reads about 10 percentage points low on average, because scattering makes red and infrared light travel different effective path lengths through tissue.
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, , with a realistic pulse shape p(t), and check R against .
Step 2: theory both ways
r_theory(S) gives lesson 33's R; spo2_theory(R) inverts it:
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
r_theory(0.98).spo2_theory(0.5). It returns 0.909.- 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
- The fitted line. The fit gives a = 109.75 and b = −24.54, close to the 110 and −25 that generated the data.
- 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.
- 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?
Beer–Lambert assumes light travels in a straight line through a uniform absorber, so the path length cancels between the two wavelengths. Tissue scatters light strongly, and photons wander along paths whose average length depends on how strongly each wavelength is absorbed and scattered: red light, absorbed more by deoxygenated blood, samples shorter effective paths than infrared, and the difference changes with saturation. The ratio of ratios therefore isn't simply the ratio of extinction coefficients, and the error is tens of percent. Manufacturers measure R on volunteers breathing reduced oxygen while drawing arterial blood samples for reference saturation, and fit the calibration curve to those data, which absorbs the scattering effects the simple theory leaves out.
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.