      SpO2 Sensor - Unit Conversion
Difficulty Level:
 Tags pre-process☁conversion☁spo2

The OpenSignals outputted file formats contain raw data, so each sample has a digital unit.

In scientific terms it is recommended the use of specific units, like electric tension (V) or electric current (A). Each sensor that PLUX commercialise has a datasheet where a transfer function is mentioned for unit conversion be done.

The next lines are intended to explain how this conversion can be programmatically applied.

In spite of the unit conversion procedure has some common steps applicable to all sensors, the current Jupyter Notebook is dedicated to the unit conversion procedure of signals acquired with SpO2 sensor.

1 - Importation of the needed packages

In :
# biosignalsnotebooks Python package with useful functions that support and complement the available Notebooks
import biosignalsnotebooks as bsnb

# Function used for creating a numpy array, where a mathematical operation can be applied to each entry in an easy and automatic way. On the other side, linspace, here will be used for generation of a time-axis.
from numpy import array, linspace


2 - Download of the sensor datasheet (from https://biosignalsplux.com/index.php/learn/documentation ). In this case we are working with SpO2, being our file located at https://www.biosignalsplux.com/datasheets/SpO2_Sensor_Datasheet.pdf

In :
# Embedding of .pdf file
from IPython.display import IFrame
IFrame('../../images/pre-process/unit_conversion_SpO2/SpO2_Sensor_Datasheet.pdf', width="100%", height="350")

Out:

3 - Extraction of the transfer function from the beginning of the second page

\begin{equation} I(A) = \frac{1.2 V \times ADC}{2^n \times G} \end{equation}
 $I_{A}$ - Photodiode current in Amperes $ADC$ - Value sampled from the acquisition channel $n$ - Number of bits of the channel (dependent on the chosen resolution specified on OpenSignals previously to the acquisition stage [8 or 16 bits]) $G$ - Transimpedance Gain (1MOhm)

In :
# Data loading


In the following cell, some relevant information is stored inside variables. This relevant information includes the mac-address of the device, channel number and signal acquisition parameters such as resolution and sampling rate.

For a detailed explanation of how to access this info, the "Signal Loading - Working with File Header" Notebook should be consulted.

In :
mac = "00:07:80:79:6F:DB" # Mac-address
ch_red = "CH9" # Channel (Red Light)
ch_infrared = "CH10" # Channel (Infrared Light)
sr = 1000 # Sampling rate
resolution = 16 # Resolution (number of available bits)


In :
signal_red = data[ch_red]
signal_infrared = data[ch_infrared]


5 - Final unit conversion (to A ) by applying the transfer function sample by sample

Definition of $G_{SpO2}$ constants

In :
gain = 1 #MOhm


Application of transfer function

In :
signal_red_i_pd = (1.2 * array(signal_red)) / 2**resolution
signal_infrared_i_pd = (1.2 * array(signal_infrared)) / 2**resolution


6 - Time axis generation

In :
time = bsnb.generate_time(signal_red_i_pd, sr)


Comparison between RAW signal and electric current (A) values.

In :
bsnb.plot([time[500:], time[500:],time[500:],time[500:]], [signal_red[500:], signal_red_i_pd[500:],signal_infrared[500:],signal_infrared_i_pd[500:]], y_axis_label=["Raw Data", "Electric Current (i_pd)", "Raw Data", "Electric Current (uA)"], title=["Red Channel (Raw)", "Red Channel (i_pd)", "Infrared Channel (Raw)", "Infrared Channel (i_pd)"], x_range=(0, 95), grid_lines=2, grid_columns=2, grid_plot=True)