# Pulse Oximetry equations

Summary:
Pulse Oximetry equations
I wrote a program that uses your computer camera to monitor your Pulse Oximetry and get your heart rate.
I got the program to work. I can see the heart beat in my graph.
Anyhow, I set my timer interval to 0.0226757 ms which is 44100 hz.

so I have a few questions,
I was seeing a lot of noise at 1st, so I started taking the average of every five samples and plotting that.

Not filter:

Filter graph:

Now you can see the heart beat.

Why was there so much noise? Where is this noise even coming from ? Is there a better number for average measurement, I should be using ? if so How do I determine the best number for average measurement ?

What kind of filter is average number measurement? How does it work ?

From this graph how do you determine the heart rate?

#### Attachments

• Not Filter.PNG
18.5 KB · Views: 11

Ibix
2020 Award
Something's screwy here. No way can a commercial camera provide 44k frames per second. And if that's supposed to be 44k pixels per second then that's a really low rate, given that a three colour 640×480 pixel camera has nearly a million pixels.

There is no way that second graph is a five sample average of the first. An average smooths a line and blurs its features. It doesn't pull that second graph out of the first. And the pulse rate is about one per ten dots in the second graph, which would imply one per fifty original samples or about one per millisecond. With that kind of pulse rate I'd suggest consulting a doctor sometime in the next few seconds.

Something's going on here that you either don't understand or are reporting inaccurately. If the second graph were a five thousand sample average of the first I'd believe the relationship between the graphs. But I still don't understand what you are sampling. At 44k it looks like either one pixel waaaay too fast or the entire image way too slowly. Or maybe you're taking the bit stream from the camera (~20M bytes per second for a 640×480 24 bit camera) every 0.02ms, in which case you are just sampling different single pixels each time. Any of those would cause noise for different reasons.

Something's screwy here. No way can a commercial camera provide 44k frames per second. And if that's supposed to be 44k pixels per second then that's a really low rate, given that a three colour 640×480 pixel camera has nearly a million pixels.

There is no way that second graph is a five sample average of the first. An average smooths a line and blurs its features. It doesn't pull that second graph out of the first. And the pulse rate is about one per ten dots in the second graph, which would imply one per fifty original samples or about one per millisecond. With that kind of pulse rate I'd suggest consulting a doctor sometime in the next few seconds.

Something's going on here that you either don't understand or are reporting inaccurately. If the second graph were a five thousand sample average of the first I'd believe the relationship between the graphs. But I still don't understand what you are sampling. At 44k it looks like either one pixel waaaay too fast or the entire image way too slowly. Or maybe you're taking the bit stream from the camera (~20M bytes per second for a 640×480 24 bit camera) every 0.02ms, in which case you are just sampling different single pixels each time. Any of those would cause noise for different reasons.
So I do have an irregular heartbeat and I have had open heart surgery.
So that could be why...

But that aside, I draw a box around the red area from my thump and take the average value of pixels in that area. I do this ever 0.0226757 milliseconds. That is how the non Filter graph works.

For the Filter graph, I do the same thing but I add up 5 samples and take the average.

So for the filter graph the sample time is really 0.0226757 * 5 = 0.1133785 ms. Because I do not display the new point until after I got 5 sample and took the average.

So yeah I code that today and that is how it is working.

So I do have an irregular heartbeat and I have had open heart surgery.
So that could be why...

But that aside, I draw a box around the red area from my thump and take the average value of pixels in that area. I do this ever 0.0226757 milliseconds. That is how the non Filter graph works.

For the Filter graph, I do the same thing but I add up 5 samples and take the average.

So for the filter graph the sample time is really 0.0226757 * 5 = 0.1133785 ms. Because I do not display the new point until after I got 5 sample and took the average.

So yeah I code that today and that is how it is working.
So I am new to this. And I could be doing something wrong. I am trying to learn. but the filter graph looks how normal heart monitor graph look.
right ?

#### Attachments

• heart beat 3.PNG
34.2 KB · Views: 17
Something's screwy here. No way can a commercial camera provide 44k frames per second. And if that's supposed to be 44k pixels per second then that's a really low rate, given that a three colour 640×480 pixel camera has nearly a million pixels.

There is no way that second graph is a five sample average of the first. An average smooths a line and blurs its features. It doesn't pull that second graph out of the first. And the pulse rate is about one per ten dots in the second graph, which would imply one per fifty original samples or about one per millisecond. With that kind of pulse rate I'd suggest consulting a doctor sometime in the next few seconds.

Something's going on here that you either don't understand or are reporting inaccurately. If the second graph were a five thousand sample average of the first I'd believe the relationship between the graphs. But I still don't understand what you are sampling. At 44k it looks like either one pixel waaaay too fast or the entire image way too slowly. Or maybe you're taking the bit stream from the camera (~20M bytes per second for a 640×480 24 bit camera) every 0.02ms, in which case you are just sampling different single pixels each time. Any of those would cause noise for different reasons.
I use the light on my cell phone to illuminate my thumb. It looks like it is working right ?
oh my web cam is an 1280 X 720
Video Quality
is
720p 16:9 30fps

#### Attachments

• New grapth.PNG
31.4 KB · Views: 15
Something's screwy here. No way can a commercial camera provide 44k frames per second. And if that's supposed to be 44k pixels per second then that's a really low rate, given that a three colour 640×480 pixel camera has nearly a million pixels.

There is no way that second graph is a five sample average of the first. An average smooths a line and blurs its features. It doesn't pull that second graph out of the first. And the pulse rate is about one per ten dots in the second graph, which would imply one per fifty original samples or about one per millisecond. With that kind of pulse rate I'd suggest consulting a doctor sometime in the next few seconds.

Something's going on here that you either don't understand or are reporting inaccurately. If the second graph were a five thousand sample average of the first I'd believe the relationship between the graphs. But I still don't understand what you are sampling. At 44k it looks like either one pixel waaaay too fast or the entire image way too slowly. Or maybe you're taking the bit stream from the camera (~20M bytes per second for a 640×480 24 bit camera) every 0.02ms, in which case you are just sampling different single pixels each time. Any of those would cause noise for different reasons.
Oh sorry my timer is set to go off every 1/44100 ms . So I am sampling the video at that speed. Oh! so that is why I have to do an average measurement of 5. I am sampling too fast and the picture is not updating. So I should change my timer to 33.33 ms?

Oh sorry my timer is set to go off every 1/44100 ms . So I am sampling the video at that speed. Oh! so that is why I have to do an average measurement of 5. I am sampling too fast and the picture is not updating. So I should change my timer to 33.33 ms?
So that did not work. I changed the timer interval to 33.33 milsec and removed the average number of measurement of 5.

but I got this:

#### Attachments

• New not Filter gapth.PNG
23.4 KB · Views: 16
What are you trying to measure? Pulse rate, O2, or perfusion ?
How have you mounted the light source and detector?
https://en.wikipedia.org/wiki/Pulse_oximetry#Mode_of_operation
The detector is my computer Dell integrated camera. The light source is my Iphone and I had it in behind my thumb. I cover the camera with my thumb. I am measuring the oxidation level in the blood cause be a heart beat.

do anyone know why I have to do an average measurement of 5 for my graph to look right ?

kuruman
Homework Helper
Gold Member
So that did not work. I changed the timer interval to 33.33 milsec and removed the average number of measurement of 5.

but I got this:

### View attachment 284688​

If I get this correctly, you have programmed your phone to send a flash of light through your thumb once every 33.33 ms; the computer camera picks up the transmitted signal. Have you investigated your system's overall response by seeing what it does when there is a thumb-equivalent without a pulse? I recommend that you go to the store and buy a nice steak. Slice a 1/4-inch thick piece with no fat. Use it as a thumb surrogate, pulse your phone and see what kind of graph you get. Take it from there but be sure to save the rest of the steak for tomorrow to grill for Father's day.

jim mcnamara
If I get this correctly, you have programmed your phone to send a flash of light through your thumb once every 33.33 ms; the computer camera picks up the transmitted signal. Have you investigated your system's overall response by seeing what it does when there is a thumb-equivalent without a pulse? I recommend that you go to the store and buy a nice steak. Slice a 1/4-inch thick piece with no fat. Use it as a thumb surrogate, pulse your phone and see what kind of graph you get. Take it from there but be sure to save the rest of the steak for tomorrow to grill for Father's day.
wait what? I do not understand.

Also the Iphone is not programmed. I just turn the flashlight on and point it at my thumb. The software is on my computer.

kuruman
Homework Helper
Gold Member
wait what? I do not understand.

Also the Iphone is not programmed. I just turn the flashlight on and point it at my thumb. The software is on my computer.
Sorry, I thought you also pulsed your phone. OK, you still need to ascertain how intrinsically noisy your system is. That is why I suggested the piece of steak. If all work according to plan, your software should return a flat line. Does it?

Sorry, I thought you also pulsed your phone. OK, you still need to ascertain how intrinsically noisy your system is. That is why I suggested the piece of steak. If all work according to plan, your software should return a flat line. Does it?
lol I would have to buy one and see... but why steak?

kuruman
Homework Helper
Gold Member
I think raw red meat, not necessarily steak, would simulate the blood in your thumb better than pork or chicken.

Baluncore
Summary:: Pulse Oximetry equations

I wrote a program that uses your computer camera to monitor your Pulse Oximetry and get your heart rate.
I cannot read the titles of, or the values on the axes on the graphs so it is difficult to guess.
Please post a copy of the program you wrote.
Do you have a link to someone else who has used a similar setup?

After conducting a lot of troubleshooting, I learned there was an error in my code. I corrected it, but I am still unable to get a good graph. after testing, I am sure the code is working as it should. SO I believe the problem is the DELL PRECISION 7740 camera. So, I know this works on the iPhone. I found out that the iPhone uses a ten bit camera with a high of 60 fps.

I could not find that much information on the DELL PRECISION 7740 camera, but I think it is an 8-bit camera.

I know the human eye cannot pick up the change in skin color from oxidation and that 8 bits (255) it the limit of what humans can see, so I think an 8-bit camera is not going to work. Is that correct?

I cannot read the titles of, or the values on the axes on the graphs so it is difficult to guess.
Please post a copy of the program you wrote.
Do you have a link to someone else who has used a similar setup?
I do not know anyone else that has done this before., beside Apple with the Iphone.

Baluncore
How are you generating and detecting the two wavelengths needed.
The finger clip is needed for pulse oximetry to prevent movement artifacts.

How are you generating and detecting the two wavelengths needed.
The finger clip is needed for pulse oximetry to prevent movement artifacts.

Apple does it with just a camera:

https://apps.apple.com/us/app/instant-heart-rate-hr-monitor/id409625068

What do you mean by " have I generating and detecting the two wavelengths needed?"

Do you mean have I synthesize the waveform in a simulator and run that through my code to see if I can detect the Heart rate ?

no, but that is a really good idea.

thanks

kuruman
Homework Helper
Gold Member
How are you generating and detecting the two wavelengths needed.
The finger clip is needed for pulse oximetry to prevent movement artifacts.
I think you are thinking of the two wavelengths at which oxyhemoglobin and deoxyhemoglobin have absorption peaks. These are needed for the "oximeter" function of the instrument to determine the ratio of oxygenated blood cells to blood cells without oxygen. OP is interested in the "pulse" function of the instrument.

@btb4198: How does your program decide that it is looking at a frame of your thumb when the pulse is on as opposed to off?

Baluncore
OP is interested in the "pulse" function of the instrument.
Then this is not "Pulse Oximetry" as it said in the title.
Simply blocking the entire camera with your thumb, out of focus, will be sufficient to read the light transmission. But remember that there is no pulse in the finger tip surface so the light must pass through the nail bed.

kuruman
Homework Helper
Gold Member
Then this is not "Pulse Oximetry" as it said in the title.
Simply blocking the entire camera with your thumb, out of focus, will be sufficient to read the light transmission. But remember that there is no pulse in the finger tip surface so the light must pass through the nail bed.
I bought a commercial pulse oximeter when it became de riguer to own one 14 months ago. It gives readings of both my pulse and my O2 level. I assumed that when I clamp the instrument to my finger, the oxygen saturation level is measured by looking at the ratio of absorbance of two wavelengths while the pulse measurement is performed by some type of transducer, probably piezoelectric. OP proposes is using light to measure pulse which is an admixture of the pulse oximeter's functions. That is why I suggested a blank measurement and then at a later posting asked OP to explain what detectable change occurs in the photograph that is interpreted by the analyzing program as a pulse.

The OP apparently does PPG Photoplethysmography, its essentially the same type of sensor as used in oximetriy, in that it measures variations in optical variations due to pulsations of blood. The diffence is that a full blown oximeter usually has a couple of wavelenghts and is calibrated to get te SpO2 from the PPG signal but cheaper devices, just gets you a simple uncalibrated "PPG signal", from which you can infer pulserate. An even simlper method is to use a regular camera and white light (like a mobile phone and the pulse-app).

In labs, typicaly PPG signal is LP filtered at 3-10Hz, and HP filtered at 0.05-0.5Hz is used to get rid of any baselinedrift. Its usually done in the amplifier. But motion artifacts are usually not easy to filter out.

Motion artifacts is likely even more of a problem if using a regular camera with white light.

But the general method for deciding best artifact or filtering method, means first oversample the full signal and inspect it. If you have spiky noise, a moving median filter can be nice, to prevent energy from spikes affecting the smoothed signal. You can even apply median filtering to the HR signal, to filter out ectopic beats. Then the median windows would be at least 3 heartbeats, assuming you do not several ectopics in a row. Motion artifacts are not always easy to get rid of, the solution is to control the measurement better.

/Fredrik

Tom.G and berkeman