systole.recording.Oximeter#

class systole.recording.Oximeter(serial, sfreq: int = 75, add_channels: int | None = None, data_format: str = '2')[source]#

Recording PPG signal with Nonin pulse oximeter.

Examples

First, you will need to define a serial() instance, indexing the USB port where the Nonin Pulse Oximeter is plugged.

>>> import serial
>>> ser = serial.Serial('COM4')

This instance is then used to create an Oximeter() instance that will be used for the recording.

>>> from systole.recording import Oximeter
>>> oximeter = Oximeter(serial=ser, sfreq=75)

Use the setup() method to initialize the recording. This will find the start byte to ensure that all the forthcoming data is in Synch. You should not wait more than ~10s between the setup and the recording, otherwise the buffer will start to overwrite the data.

>>> oximeter.setup()

Two methods are availlable to record PPG signal:

  1. The read() function.

Will continuously record for certain amount of time (specified by the duration parameter, in seconds). This is the easiest and most robust method, but it is not possible to run instructions in the meantime.

>>> oximeter.read(duration=10)
  1. The readInWaiting() function.

Will read all the availlable bytes (up to 10 seconds of recording). When inserted into a while loop, it allows to record PPG signal together with other scripts.

>>> import time
>>> tstart = time.time()
>>> while time.time() - tstart < 10:
>>>     oximeter.readInWaiting()
>>>     # Insert code here

The recorded signal can latter be inspected using the plot() method.

>>> oximeter.plot()

Warning

Data read from the serial port are appended to list and processed for pulse detection and instantaneous heart rate estimation. The time required to append new data to the recording will increase as its size increase. You should beware that this processing time does not exceed the sampling frequency (i.e. 75Hz or 0.013 seconds per sample for Nonin pulse oximeters) to allow continuous recording and fast processing of in waiting samples. We recommend storing regularly 5 minutes recording as .npy file using the :py:func:save() function.

Attributes:
instant_rr

Time serie of instantaneous heartrate.

n_channelsint | None

Number of additional channels.

recording

Time serie of PPG signal.

sfreq

Sampling frequnecy. Default value is 75 Hz.

threshold

The threshold used to detect beat peaks. Will use the average + standars deviation.

times

Time vector (in seconds).

diff

Records the differential of the PPG signal. Used to detect heartbeat peaks.

peaks

List of 0 and 1. 1 index detected peaks.

channels

Additional channels to record. Will continuously record n_channels additional channels in parallel of recording with default 0 as defalut value.

serial

PySerial object indexing the USB port to read.

rr

RR intervals time course. The time course will be generated if self.find_peaks() is used.

__init__(serial, sfreq: int = 75, add_channels: int | None = None, data_format: str = '2')[source]#
Parameters:
serial

The serial instance interfacing with the USB port.

sfreq

The sampling frequency of the recording. Defautl is 75 Hz.

add_channels

If int, will create as many additionnal channels. If None, no additional channels created.

data_format

Data format returned by the USB dongle (“2” or “7”). See https://www.nonin.com/wp-content/uploads/6000-7000-CP-7602-000-11_ENG.pdf for details. The pulse waveform value is automatically normalized and range between 0 and 255 both for data format “2” and “7”.

Methods

__init__(serial[, sfreq, add_channels, ...])

Parameters:

add_paquet(value[, window])

Read a portion of data.

check(paquet)

Check if the provided paquet is correct

data_format2(paquet)

Extract pulse waveform value for data format 2.

data_format7(paquet)

Extract pulse waveform value for data format 7.

find_peaks(**kwargs)

Find peaks in recorded signal.

plot_events([n_channel])

Visualize the distribution of events stored in additional channels.

plot_raw(**kwargs)

Plot the raw PPG signal.

read(duration)

Read PPG signal for some amount of time.

readInWaiting([stop])

Read in wainting oxi data.

reset(serial[, sfreq, add_channels, data_format])

Initialize/restart the recording instance.

save(fname)

Save the recording instance.

setup([read_duration, clear_peaks, nAttempts])

Find start byte and read a portion of signal.

waitBeat()

Read Oximeter until a heartbeat is detected.