{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Heart rate analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial shows how to extract heart rate estimates using photoplethysmography (PPG) data and accelerometer data. The pipeline consists of a stepwise approach to determine signal quality, assessing both PPG morphology and accounting for periodic artifacts using the accelerometer. Based on the signal quality, we extract high-quality segments and estimate the heart rate for every 2 s using the smoothed pseudo Wigner-Ville Distribution." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This pipeline requires accelerometer and PPG data to run. In this example we loaded data from a participant of the Personalized Parkinson Project. We load the corresponding dataframes using the [load_tsdf_dataframe](https://github.com/biomarkersParkinson/paradigma/blob/main/src/paradigma/util.py#:~:text=load_tsdf_dataframe) function. The channel `green` represents the values obtained with PPG using green light.\n", "\n", "In this example we use the interally developed `TSDF` ([documentation](https://biomarkersparkinson.github.io/tsdf/)) to load and store data [[1](https://arxiv.org/abs/2211.11294)]. \n", "\n", "However, we are aware that there are other common data formats. For example, the following functions can be used depending on the file extension of the data:\n", "- _.csv_: `pandas.read_csv()` ([documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html))\n", "- _.json_: `json.load()` ([documentation](https://docs.python.org/3/library/json.html#json.load))\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | time | \n", "green | \n", "
---|---|---|
0 | \n", "0.00000 | \n", "649511 | \n", "
1 | \n", "0.00996 | \n", "648214 | \n", "
2 | \n", "0.01992 | \n", "646786 | \n", "
3 | \n", "0.02988 | \n", "645334 | \n", "
4 | \n", "0.03984 | \n", "644317 | \n", "
... | \n", "... | \n", "... | \n", "
64770 | \n", "644.54720 | \n", "553884 | \n", "
64771 | \n", "644.55716 | \n", "554088 | \n", "
64772 | \n", "644.56712 | \n", "554240 | \n", "
64773 | \n", "644.57708 | \n", "555134 | \n", "
64774 | \n", "644.58704 | \n", "557205 | \n", "
64775 rows × 2 columns
\n", "\n", " | time | \n", "accelerometer_x | \n", "accelerometer_y | \n", "accelerometer_z | \n", "
---|---|---|---|---|
0 | \n", "0.00000 | \n", "0.550718 | \n", "0.574163 | \n", "-0.273684 | \n", "
1 | \n", "0.01004 | \n", "0.535885 | \n", "0.623445 | \n", "-0.254545 | \n", "
2 | \n", "0.02008 | \n", "0.504306 | \n", "0.651675 | \n", "-0.251675 | \n", "
3 | \n", "0.03012 | \n", "0.488517 | \n", "0.686603 | \n", "-0.265550 | \n", "
4 | \n", "0.04016 | \n", "0.494258 | \n", "0.725359 | \n", "-0.278469 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
72942 | \n", "730.74468 | \n", "0.234928 | \n", "-0.516268 | \n", "-0.802871 | \n", "
72943 | \n", "730.75472 | \n", "0.245455 | \n", "-0.514354 | \n", "-0.806699 | \n", "
72944 | \n", "730.76476 | \n", "0.243541 | \n", "-0.511005 | \n", "-0.807177 | \n", "
72945 | \n", "730.77480 | \n", "0.240191 | \n", "-0.514354 | \n", "-0.808134 | \n", "
72946 | \n", "730.78484 | \n", "0.243541 | \n", "-0.511005 | \n", "-0.808134 | \n", "
72947 rows × 4 columns
\n", "\n", " | time | \n", "green | \n", "
---|---|---|
0 | \n", "0.000000 | \n", "-1434.856838 | \n", "
1 | \n", "0.033333 | \n", "-3461.717789 | \n", "
2 | \n", "0.066667 | \n", "-5172.913796 | \n", "
3 | \n", "0.100000 | \n", "-6343.203160 | \n", "
4 | \n", "0.133333 | \n", "-6875.904054 | \n", "
... | \n", "... | \n", "... | \n", "
19333 | \n", "644.433333 | \n", "-2403.547097 | \n", "
19334 | \n", "644.466667 | \n", "-7434.311944 | \n", "
19335 | \n", "644.500000 | \n", "-8214.847078 | \n", "
19336 | \n", "644.533333 | \n", "-5194.393329 | \n", "
19337 | \n", "644.566667 | \n", "70.147000 | \n", "
19338 rows × 2 columns
\n", "\n", " | time | \n", "accelerometer_x | \n", "accelerometer_y | \n", "accelerometer_z | \n", "
---|---|---|---|---|
0 | \n", "0.00 | \n", "0.053078 | \n", "0.010040 | \n", "-0.273154 | \n", "
1 | \n", "0.01 | \n", "0.038337 | \n", "0.058802 | \n", "-0.256899 | \n", "
2 | \n", "0.02 | \n", "0.006824 | \n", "0.086559 | \n", "-0.256739 | \n", "
3 | \n", "0.03 | \n", "-0.009156 | \n", "0.120855 | \n", "-0.273280 | \n", "
4 | \n", "0.04 | \n", "-0.003770 | \n", "0.159316 | \n", "-0.289007 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
64454 | \n", "644.54 | \n", "0.104185 | \n", "0.101627 | \n", "-0.029342 | \n", "
64455 | \n", "644.55 | \n", "0.120403 | \n", "0.090413 | \n", "0.051113 | \n", "
64456 | \n", "644.56 | \n", "0.101289 | \n", "0.128684 | \n", "0.037951 | \n", "
64457 | \n", "644.57 | \n", "0.073139 | \n", "0.137399 | \n", "0.030834 | \n", "
64458 | \n", "644.58 | \n", "0.004578 | \n", "0.102862 | \n", "0.025627 | \n", "
64459 rows × 4 columns
\n", "\n", " | time | \n", "var | \n", "mean | \n", "median | \n", "kurtosis | \n", "skewness | \n", "signal_to_noise | \n", "auto_corr | \n", "f_dom | \n", "rel_power | \n", "spectral_entropy | \n", "acc_power_ratio | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0.0 | \n", "1.697510e+07 | \n", "3418.696392 | \n", "2892.815105 | \n", "2.540447 | \n", "0.277237 | \n", "3.241634 | \n", "0.282452 | \n", "1.171875 | \n", "0.179922 | \n", "0.561186 | \n", "0.014196 | \n", "
1 | \n", "1.0 | \n", "1.635033e+07 | \n", "3350.769158 | \n", "2892.815105 | \n", "2.647951 | \n", "0.420163 | \n", "3.202313 | \n", "0.276526 | \n", "1.171875 | \n", "0.201972 | \n", "0.547812 | \n", "0.015343 | \n", "
2 | \n", "2.0 | \n", "1.921248e+07 | \n", "3698.963099 | \n", "3310.773556 | \n", "2.333687 | \n", "0.481974 | \n", "3.521882 | \n", "0.210984 | \n", "0.820312 | \n", "0.264922 | \n", "0.509015 | \n", "0.042583 | \n", "
3 | \n", "3.0 | \n", "1.646562e+07 | \n", "3389.325775 | \n", "2946.588526 | \n", "2.608187 | \n", "0.733913 | \n", "3.346236 | \n", "0.225823 | \n", "0.703125 | \n", "0.270707 | \n", "0.496051 | \n", "0.034215 | \n", "
4 | \n", "4.0 | \n", "1.603135e+07 | \n", "3364.366313 | \n", "2912.280798 | \n", "2.268768 | \n", "0.440357 | \n", "3.314565 | \n", "0.305998 | \n", "0.820312 | \n", "0.264097 | \n", "0.496697 | \n", "0.056204 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
634 | \n", "634.0 | \n", "2.281660e+06 | \n", "1106.006037 | \n", "838.307729 | \n", "4.058037 | \n", "0.674184 | \n", "2.072660 | \n", "0.172052 | \n", "0.703125 | \n", "0.204028 | \n", "0.577570 | \n", "0.060486 | \n", "
635 | \n", "635.0 | \n", "2.224441e+06 | \n", "1113.194933 | \n", "838.307729 | \n", "3.684159 | \n", "0.067979 | \n", "2.118019 | \n", "0.236408 | \n", "0.703125 | \n", "0.221044 | \n", "0.560362 | \n", "0.053120 | \n", "
636 | \n", "636.0 | \n", "5.103141e+06 | \n", "1627.618918 | \n", "1030.113303 | \n", "3.913068 | \n", "0.852331 | \n", "2.040094 | \n", "0.235822 | \n", "0.585938 | \n", "0.157667 | \n", "0.514717 | \n", "0.058853 | \n", "
637 | \n", "637.0 | \n", "7.428728e+06 | \n", "2093.736007 | \n", "1520.640067 | \n", "3.188753 | \n", "0.305780 | \n", "2.457446 | \n", "0.322034 | \n", "0.468750 | \n", "0.150582 | \n", "0.458477 | \n", "0.061269 | \n", "
638 | \n", "638.0 | \n", "1.549534e+07 | \n", "2974.462555 | \n", "2482.703944 | \n", "4.042171 | \n", "-0.628008 | \n", "2.228730 | \n", "0.095918 | \n", "0.468750 | \n", "0.102976 | \n", "0.493830 | \n", "0.105554 | \n", "
639 rows × 12 columns
\n", "\n", " | time | \n", "pred_sqa_proba | \n", "pred_sqa_acc_label | \n", "
---|---|---|---|
0 | \n", "0.0 | \n", "0.006031 | \n", "1 | \n", "
1 | \n", "1.0 | \n", "0.011725 | \n", "1 | \n", "
2 | \n", "2.0 | \n", "0.068063 | \n", "1 | \n", "
3 | \n", "3.0 | \n", "0.080808 | \n", "1 | \n", "
4 | \n", "4.0 | \n", "0.074591 | \n", "1 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
634 | \n", "634.0 | \n", "0.001387 | \n", "1 | \n", "
635 | \n", "635.0 | \n", "0.001570 | \n", "1 | \n", "
636 | \n", "636.0 | \n", "0.000380 | \n", "1 | \n", "
637 | \n", "637.0 | \n", "0.000406 | \n", "1 | \n", "
638 | \n", "638.0 | \n", "0.000004 | \n", "1 | \n", "
639 rows × 3 columns
\n", "\n", " | time | \n", "heart_rate | \n", "
---|---|---|
0 | \n", "56.0 | \n", "86.404715 | \n", "
1 | \n", "58.0 | \n", "86.640472 | \n", "
2 | \n", "60.0 | \n", "86.345776 | \n", "
3 | \n", "62.0 | \n", "84.872299 | \n", "
4 | \n", "64.0 | \n", "84.872299 | \n", "
5 | \n", "66.0 | \n", "84.194499 | \n", "