pyPPG example code

In this tutorial you will learn how to use pyPPG to engineer morphological PPG biomarkers and export their values.

Introduction

This tutorial provides step-by-step instructions for installing pyPPG and running the example code.

Step 1: Install Python 3.10

Download and install Python 3.10 on your computer or server by visiting the official Python website: Python 3.10.

Step 2: Download the Sample PPG Data

You can use the sample PPG data by downloading it from the following link: Sample PPG data.

Step 3: Create and Activate a Virtual Environment

Create a virtual environment named “ppgenv” specifically for Python 3.10 using the py launcher:

py -3.10 -m venv ppgenv

Activate the virtual environment:

ppgenv\Scripts\activate

Step 4: Install pyPPG

While the virtual environment is active, install pyPPG using pip:

ppgenv\Scripts\python.exe -m pip install pyPPG

WARNING: Running pip as the ‘root’ user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead, or please review carefully the list of package requirements.

Step 5: Run the Example Code

Open the Python interpreter:

python

Run the example code, load the example files (.mat, .txt, .csv, or .edf formats) and check the results:

from pyPPG.example import ppg_example
ppg_example()

The resulting figures and outcomes are stored within the temp_dir folder, which is automatically generated within the project directory.

Step 6: Exit the Python Interpreter and Deactivate the Virtual Environment

To exit the Python interpreter, type:

exit()

Deactivate the virtual environment:

deactivate

You have successfully installed pyPPG, executed the example code, and explored the results. Feel free to customize and use pyPPG for your projects.

Example pyPPG code

The provided example code consists of seven modules that effectively showcase the capabilities of the pyPPG toolbox.

  1. Raw PPG Signal Loading: This module facilitates the loading of raw PPG signals from various file formats, including .mat, .csv, .txt, or .edf.

  2. Fiducial Point Extraction: This module focuses on extracting fiducial points from PPG signals, encompassing PPG, PPG’, PPG’’, and PPG’’’.

  3. Fiducial Points Plotting: Here, the extracted fiducial points are visually represented through plotting.

  4. Biomarker Extraction: This module offers the extraction of 74 distinct PPG biomarkers, categorized into:

    1. PPG signal characteristics

    2. Signal ratios

    3. PPG derivatives

    4. Derivative ratios

  5. Biomarker Statistics: A concise summary of the 74 PPG biomarkers is provided within this module.

  6. SQI calculation: This module calculates the PPG Signal Quality Index based on beat template correlation.

  7. Save data: This module allows for the saving of extracted Fiducial points, Biomarkers, and Statistics into a .csv file.

../_images/PPG_MAT_sample.png