Skip to content

embodied-computation-group/systole

Repository files navigation

https://github.com/LegrandNico/systole/blob/master/Images/logo.png

Systole is an open-source Python package providing simple tools to record and analyze body signal for psychophysiology. This module is developed by the ECG group (https://the-ecg.org/).

Installation

Download the zip file, extract the folder and run from the terminal:

python setup.py install

Recording

Oximeter

Recording signal with the Nonin 3012LP Xpod USB pulse oximeter (https://www.nonin.com/products/xpod/) together with the Nonin 8000SM 'soft-clip' fingertip sensors (https://www.nonin.com/products/8000s/).

Quick start

Record and plot data with less than 6 lines of code.

import serial
from ecgrecording import Oximeter
ser = serial.Serial('COM4')  # Add your USB port here

# Open serial port, initialize and plot recording for Oximeter
oxi = Oximeter(serial=ser, sfreq=75).setup().read(duration=10)

# Plot data
oxi.plot()
https://github.com/LegrandNico/systole/blob/master/Images/recording.png

Recording

2 methods are available to record PPG signal:

  • The read() method 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 (serial mode).

# Code 1 {}
oximeter.read(duration=10)
# Code 2 {}
  • The readInWaiting() method will read all the availlable bytes (up

to 10 seconds of recording). When inserted into a while loop, it allows to record PPG signal in parallel with other commands.

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

Online detection

Set an online peak detection algorithm in less than 10 lines of code.

import serial
import time
from systole.recording import Oximeter

# Open serial port
ser = serial.Serial('COM4')  # Change this value according to your setup

# Create an Oxymeter instance and initialize recording
oxi = Oximeter(serial=ser, sfreq=75, add_channels=4).setup()

# Online peak detection for 10 seconds
tstart = time.time()
while time.time() - tstart < 10:
    while oxi.serial.inWaiting() >= 5:
        paquet = list(oxi.serial.read(5))
        oxi.add_paquet(paquet[2])  # Add new data point
        if oxi.peaks[-1] == 1:
          print('Heartbeat detected')

See also a complete tutorial here: <https://github.com/LegrandNico/systole/tree/master/notebooks/HeartBeatEvokedTone.rst>

Peaks detection

Work in progress

Artifact removal

Work in progress

Signal quality

Outliers in R-R time series

Heart rate variability

Import RR time-serie.

from systole import import_rr
rr = import_rr().rr.values

Time-domain

Extract summary of time-domain indexes.

from systole.hrv import time_domain

stats = time_domain(rr)
stats
Output
Value Metric
26.23 pnn50
883.00 MeanRR
68.58 MeanBPM
886.67 MedianRR
67.67 MedianBPM
676.00 MinRR
53.70 MinBPM
1117.33 MaxRR
88.76 MaxBPM
84.69 SDNN
45.55 RMSSD
64.00 nn50
26.23 pnn50

Frequency-domain

https://github.com/LegrandNico/systole/blob/master/Images/psd.png

Extract summary of frequency-domain indexes.

Non-linear

All the results have been tested against Kubios HVR 2.2 (<https://www.kubios.com>). Some variability can be observed with frequency-domain outputs.

Interactive visualization

Work in progress

Development

This program is provided with NO WARRANTY OF ANY KIND.

Acknowledgement

Systole was largely inspired by preexisting toolboxes for heart rate variability and signal analysis.

HeartPy: https://python-heart-rate-analysis-toolkit.readthedocs.io/en/latest/

hrv: https://github.com/rhenanbartels/hrv

ECG-detector: https://github.com/berndporr/py-ecg-detectors

References

Peak detection (PPG signal)

van Gent, P., Farah, H., van Nes, N., & van Arem, B. (2019). HeartPy: A novel heart rate algorithm for the analysis of noisy signals. Transportation Research Part F: Traffic Psychology and Behaviour, 66, 368–378. https://doi.org/10.1016/j.trf.2019.09.015

Artefact detection and correction:

Lipponen, J. A., & Tarvainen, M. P. (2019). A robust algorithm for heart rate variability time series artefact correction using novel beat classification. Journal of Medical Engineering & Technology, 43(3), 173–181. https://doi.org/10.1080/03091902.2019.1640306