Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MAX30100_SpO2Calculator.cpp
00001 /* 00002 Arduino-MAX30100 oximetry / heart rate integrated sensor library 00003 Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org> 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 You should have received a copy of the GNU General Public License 00013 along with this program. If not, see <http://www.gnu.org/licenses/>. 00014 */ 00015 00016 #include <math.h> 00017 00018 #include "MAX30100_SpO2Calculator.h" 00019 00020 // SaO2 Look-up Table 00021 // http://www.ti.com/lit/an/slaa274b/slaa274b.pdf 00022 const uint8_t SpO2Calculator::spO2LUT[43] = {100,100,100,100,99,99,99,99,99,99,98,98,98,98, 00023 98,97,97,97,97,97,97,96,96,96,96,96,96,95,95, 00024 95,95,95,95,94,94,94,94,94,93,93,93,93,93}; 00025 00026 SpO2Calculator::SpO2Calculator() : 00027 irACValueSqSum(0), 00028 redACValueSqSum(0), 00029 beatsDetectedNum(0), 00030 samplesRecorded(0), 00031 spO2(0) 00032 { 00033 } 00034 00035 void SpO2Calculator::update(float irACValue, float redACValue, bool beatDetected) 00036 { 00037 irACValueSqSum += irACValue * irACValue; 00038 redACValueSqSum += redACValue * redACValue; 00039 ++samplesRecorded; 00040 00041 if (beatDetected) { 00042 ++beatsDetectedNum; 00043 if (beatsDetectedNum == CALCULATE_EVERY_N_BEATS) { 00044 float acSqRatio = 100.0 * log(redACValueSqSum/samplesRecorded) / log(irACValueSqSum/samplesRecorded); 00045 uint8_t index = 0; 00046 00047 if (acSqRatio > 66) { 00048 index = (uint8_t)acSqRatio - 66; 00049 } else if (acSqRatio > 50) { 00050 index = (uint8_t)acSqRatio - 50; 00051 } 00052 reset(); 00053 00054 spO2 = spO2LUT[index]; 00055 } 00056 } 00057 } 00058 00059 void SpO2Calculator::reset() 00060 { 00061 samplesRecorded = 0; 00062 redACValueSqSum = 0; 00063 irACValueSqSum = 0; 00064 beatsDetectedNum = 0; 00065 spO2 = 0; 00066 } 00067 00068 uint8_t SpO2Calculator::getSpO2() 00069 { 00070 return spO2; 00071 }
Generated on Wed Jul 13 2022 10:11:08 by
1.7.2