Spo2 and heart rate calculation

Hello,

I am trying to implement pulse oximetry and heart rate calculation algorithm on Arduino UNO. I have already implement analog circuit but i am confused to generate Arduino code. I can calculate heart rate with finding peak values with using only one led. When I used two led(ir and red) how can I calculate maximum and minimum voltages as an AC and DC voltage?

I attached my led blinking code. Could you please inform me about how much time I should read analog voltage to have maximum value for red led, and similarly for ir led? While I am reading these voltages how can i calculate heart rate with obtaining peak values? I am new on Arduino and coding so I could not understand exactly the example codes. If someone can explain me, I will be very grateful.

thanks in advance.
Duygu

digitalwrite_spo2.ino (551 Bytes)

Need more information about the analogCircuit. Please post

Think you need to measure the signal with analogRead() e.g. 20 times per second, that should be enough to detect every meaningful heart rate.

compare every value with minimum and adjust minimum if needed
Same with maximum,

If you are just past the max ( numbers are decreasing constantly) you should reset the minimum.
If you are just past the min ( numbers are increasing constantly) you should reset the maximum
.

Thanks for your reply. I attached the output of my analog circuit, maybe it is more useful. Could you please explain the method you suggest with code or algorithm chart?

Thanks,
Duygu

I attached the output of my analog circuit, maybe it is more useful.

No it is not more useful than the circuit. Post a schematic diagram (not Fritzing).

this is my analog circuit.

analog_circuit.pdf (120 KB)

Do not cross post.

here I am just trying to understand Spo2 calculation algorithm and the circuit output is the above image I uploaded without any input bias. Why is it crossing, I didn't understand?

The circuit in reply #4 has the two LEDs powered in parallel. How can you only turn on one LED at a time?

Is one of the LEDs supposed to be reversed?

I gave SPO2 measuring a try once and I had a heck of a time getting signals with enough resolution to calculate SPO2.

Calculating heart rate is very easy compared with calculating SPO2 (as it appears you're learning).

I know you need to be able to measure the light levels from the red and IR LEDs independently. I don't see how you can do that with your current circuit.

yes u are right, one of the led is reversed.I draw the schematic wrongly but in real circuit it is true. according to my blinking code I attached before, I am open red led 250 us,red and ir off 250 us, only ir led on 250 us and again ir and red led off 250us, it repeats like this. After that amplification and filtering is implemented. therefore I can get PPG signal as I attached before.

But How can I calculate Sp02? It is not clear for me yet.

Please give me more detail information about Spo2 calculation algorithm.

Duygu

duyguuu:
But How can I calculate Sp02? It is not clear for me yet.

Well, obviously it is related to the ratio of IR and red absorption, which means that you have to be able to translate the DAC values into some sort of absorption curve, then calculate the ratio of those corrected values and then map that to PO2%.

As DuaneDegn points out, that will require a lot of work, and few people here would have gone through the process.

Easier just to buy one on eBay as I have (actually, one for each room and one I carry on my belt). :grinning:

duyguuu:
here I am just trying to understand Spo2 calculation algorithm

It is explained here:

The key to SpO2 calculation is the modulation ratio between red and infrared LED signals.

Formulas are in the linked document. The modulation ratio is calculated by:
R = (ACrms of Red / DC of Red) / (ACrms of IR / DC of IR)

Where "DC of Red" and "DC of IR" mean: "Average value over time".
And "ACrms" means: alternating amount within the signal values over time

These have to be calculated from your measurements.

Next you need a calibrated table for your specific sensor which tells you about which modulation ratio belongs to how many % SpO2. For the Texas Instruments TI AFE4403 sensor the table is contained in the document above, and also a formula:
% SpO2 = 110 – 25 × R
So for this sensor you need no table lookup, but you can use the formula.
For different sensors you need different formulas or a lookup table.

If you built the sensor yourself, you'd have to create a calibration table for your sensor. Either by doing calibration with a calibrated medical sensor, or by doing actually measuring O2 concentration in the blood and comparing with your sensor.

So what do you have in your code until now:

  • DC of Red (average over time)?
  • DC if IR (average over time)?
  • ACrms of Red?
  • ACrms of IR?
  • modulation ratio R?
  • are you using a sensor with well known calibration data like TI AFE4403?
  • or are the calibration data of your sensor completely unknown?

jurs:
If you built the sensor yourself, you'd have to create a calibration table for your sensor. Either by doing calibration with a calibrated medical sensor, or by doing actually measuring O2 concentration in the blood and comparing with your sensor.

As I was pointing out.

I doubt you would want to do the latter. :astonished:

Jurs, thank u very much for your interest. Actually I have nothing completely now. I try to calculate AC voltages as taking maximum point of the signal and DC voltages as taking minimum of the signal. I can be acceptable? Or should I take max-min for AC and average for DC?

I attached the code, there is a mistake because ir_max and led_max value is calculated always the same. But I couldn't find the mistake.

In addition how much time should I open the red led and calculate AC and DC voltages?

Thanks,
Duygu

digitalwrite_spo2_only_calculate.ino (2.35 KB)

1 Like

duyguuu:
I try to calculate AC voltages as taking maximum point of the signal and DC voltages as taking minimum of the signal. I can be acceptable?

That's not acceptable, because it's wrong.
You'll have to do a VRMS calculation to strip out AC voltage amount from the raw signal values.

What's your professional qualification for creating that type of hardware and programming?

Did you ever hear anything about something like "elements of electrical engineering"?

1 Like

Sorry for the late reply and silly question before. Now I understand the Spo2 calculation exactly. But I have a problem about led timing. What should be the sampling periode of opening red and ir leds?

I try to open ir led for 3 seconds, gathering data at 10Hz, max-min points and average...
And than open red led for 3 seconds, gathering data at 10 Hz, max-min points and average...

but with this way the photodiode out was not stable. Could you please lead me about this timing periode?

Thanks.

1 Like

If you wish to gather data at 10 Hz, then you must necessarily sample from each LED illumination for 50 ms - fifty milliseconds.

1 Like

Paul__B:
If you wish to gather data at 10 Hz, then you must necessarily sample from each LED illumination for 50 ms - fifty milliseconds.

Agreed. The LEDs need to alternate between red and IR. You can't just sample one and then the other.

10Hz seems like a low sample rate. It's been awhile since I've worked on my (failed) attempt to read blood oxygen but I thought the sample frequency had to be higher than 10Hz.

1 Like

No, I think it is a pretty reasonable rate - this is to determine the pulse rate which is most unlikely to exceed 120 per minute or two pulses a second, (OK, technically they could have PAT at 180 or be a super athlete but that is a bit extreme) and you want a low-pass filter anyway so five to ten "bins" per pulse sounds quite reasonable.

We're not talking about an ECG!

1 Like

Paul__B:
No, I think it is a pretty reasonable rate

I'm not convinced.

The article linked in reply #10 above shows graphs with the x-axis labelled "Number of Samples". It looks like there are about 450 samples per pulse.

Page 21 of this Freescale app note mentions a sample being taken once every microsecond (1MHz sample rate).

Back when I experimented with trying to measure blood oxygen, I used a 20Hz sample rate and I was very concerned by this low resolution.

Maybe I was too worried about minimizing the time difference between reading from the red and IR measurements but I found my 20Hz rate was slower than the other examples of blood oxygen sensors I could find.

The graphs in the document linked in reply #10 have relatively stable DC offsets. I found I had to hold very still while using the sensor on myself if I hoped to keep the DC offset the same at the beginning and end of a pulse.

If you jump to 1:07 in the video I posted in the Parallax thread, you can see what my 20Hz output looked like.

Again, maybe I was/am overly concerned about the sample frequency but all the documentation I've found suggest higher sampling rates are the norm.

1 Like

will you provide the corrected code for pulse oximeter?

1 Like