.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Recording/plot_InstantaneousHeartRate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_Recording_plot_InstantaneousHeartRate.py: Instantaneous Heart Rate ======================== This example show how to record PPG signals using the `Nonin 3012LP Xpod USB pulse oximeter `_ and the `Nonin 8000SM 'soft-clip' fingertip sensors `_. Peaks are automatically labelled online and the instantaneous heart rate is plotted. .. GENERATED FROM PYTHON SOURCE LINES 11-23 .. code-block:: default # Author: Nicolas Legrand # Licence: GPL v3 import matplotlib.pyplot as plt import numpy as np import pandas as pd from systole import serialSim from systole.detection import ppg_peaks from systole.plots import plot_raw, plot_rr from systole.recording import Oximeter .. GENERATED FROM PYTHON SOURCE LINES 24-28 Recording --------- For the demonstration purpose, here we simulate data acquisition through the pulse oximeter using pre-recorded signal. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: default ser = serialSim() .. GENERATED FROM PYTHON SOURCE LINES 32-35 If you want to enable online data acquisition, you should uncomment the following lines and provide the reference of the COM port where the pulse oximeter is plugged in. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: python import serial ser = serial.Serial('COM4') # Change this value according to your setup .. GENERATED FROM PYTHON SOURCE LINES 41-46 .. code-block:: default # Create an Oxymeter instance, initialize recording and record for 30 seconds oxi = Oximeter(serial=ser, sfreq=75).setup() oxi.read(30) .. rst-class:: sphx-glr-script-out .. code-block:: none Reset input buffer .. GENERATED FROM PYTHON SOURCE LINES 47-49 Plotting -------- .. GENERATED FROM PYTHON SOURCE LINES 49-62 .. code-block:: default signal, peaks = ppg_peaks(signal=oxi.recording, sfreq=75) fig, ax = plt.subplots(3, 1, figsize=(13, 8), sharex=True) plot_raw(signal=signal, show_heart_rate=False, ax=ax[0]) times = pd.to_datetime(np.arange(0, len(peaks)), unit="ms", origin="unix") ax[1].plot(times, peaks, "#55a868") ax[1].set_title("Peaks vector") ax[1].set_ylabel("Peak\n detection") plot_rr(peaks, input_type="peaks", ax=ax[2]) plt.tight_layout() .. image-sg:: /auto_examples/Recording/images/sphx_glr_plot_InstantaneousHeartRate_001.png :alt: PPG recording, Peaks vector, Instantaneous heart rate :srcset: /auto_examples/Recording/images/sphx_glr_plot_InstantaneousHeartRate_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 32.218 seconds) .. _sphx_glr_download_auto_examples_Recording_plot_InstantaneousHeartRate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_InstantaneousHeartRate.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_InstantaneousHeartRate.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_