EmotiBit / EmotiBit_FeatherWing

Firmware to run Emotibit with Adafruit feather M0 WiFi and Feather ESP32
MIT License
19 stars 9 forks source link

Add SpO2 derivative metric #191

Open nitin710 opened 2 years ago

nitin710 commented 2 years ago

Description

Add SpO2 metric utilizing MAXIM's SpO2 algorithm, but reduce it's resource(primarily memory) requirement.

Useful links

Current SpO2 algorithm

SpO2 Algo explained

Suggested tweaks to the algorithm

Step Current Approach Purpose Requirements Notes on current approach Suggested approach
Store 100 samples in a buffer 2 100 uint32 buffers are used to store 4 secs worth of data(freq=25Hz) 2 x array[100] These buffer sizes grow linearly with frequency
Calculate DC mean of 100 samples (only on 1 channel) take avg of 100 points Remove DC component 1 byte The Assumption being that both channels of sensors are syunced in time
Subtract DC mean from actual data (only on 1 channel) Use 1 new array of 100 data points to store DC removed signal To process only AC component 1x array[100]
invert the signal multiple by -1 To use existing peak detector(to find valleys. Peak = valleys in inverted signal) NA
Smooth the signal 4 point moving avg to prevent erroneous peak detection NA
Calculate Threshold Specify bounds for peak detection algo ? 1 byte
Detect valleys(using peak detector) use defined peak detector algo find valleys (valleys in the OG signal) NA
calc HR using dist. b/w valleys average all inter valley sapcing and use Fs to calc HR in bpm get HR Not m/m intensive double check the algo
Perform bounds check on valley locs simple array bounds check All valleys must have a valid index, [0,BUFFER_LEN). If a valley lies, outside these bounds, there has been an error, and algo returns with invalid NA
Perform AC/DC signal content analysis for SpO2 defined algo Find N and D, when LUT_index = N/D, and LUT[i] = SpO2 2 adjacent valleys, and the peak in the middle of the valleys
Post-process SpO2 post processing find median of SpO2 values
return result - Use the Look-up-table to get SpO2 value
nitin710 commented 2 years ago

Requirements to port the algorithm

synopsis

Implementation

nitin710 commented 2 years ago

❓ Where would the SpO2 live in the oscilloscope?