{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Instantaneous Heart Rate\n\nThis example show how to record PPG signals using the [Nonin 3012LP\nXpod USB pulse oximeter](https://www.nonin.com/products/xpod/) and the [Nonin\n8000SM 'soft-clip' fingertip sensors](https://www.nonin.com/products/8000s/).\nPeaks are automatically labelled online and the instantaneous heart rate is\nplotted.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Author: Nicolas Legrand \n# Licence: Apache-2.0\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nfrom systole import serialSim\nfrom systole.detection import ppg_peaks\nfrom systole.plots import plot_raw, plot_rr\nfrom systole.recording import Oximeter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Recording\nFor the demonstration purpose, here we simulate data acquisition through\nthe pulse oximeter using pre-recorded signal.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ser = serialSim()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to enable online data acquisition, you should uncomment the\nfollowing lines and provide the reference of the COM port where the pulse\noximeter is plugged in.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```python\nimport serial\nser = serial.Serial('COM4') # Change this value according to your setup\n```\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Create an Oxymeter instance, initialize recording and record for 30 seconds\noxi = Oximeter(serial=ser, sfreq=75).setup()\noxi.read(30)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "signal, peaks = ppg_peaks(signal=oxi.recording, sfreq=75)\n\nfig, ax = plt.subplots(3, 1, figsize=(13, 8), sharex=True)\n\nplot_raw(signal=signal, show_heart_rate=False, ax=ax[0])\n\ntimes = pd.to_datetime(np.arange(0, len(peaks)), unit=\"ms\", origin=\"unix\")\nax[1].plot(times, peaks, \"#55a868\")\nax[1].set_title(\"Peaks vector\")\nax[1].set_ylabel(\"Peak\\n detection\")\n\nplot_rr(peaks, input_type=\"peaks\", ax=ax[2])\nplt.tight_layout()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.16" } }, "nbformat": 4, "nbformat_minor": 0 }