How to get R-R peaks from ECG and PPG signals into InfluxDB for respiratory rate estimation

Last Updated on January 24, 2023 by pg@petergamma.org

Peter Charlton from University of Cambridge UK requires R-R peaks from heart rate sensor to calculate the respiratory rate for his respiratory rate estimation in Matlab. The Polar Sensor Logger app from Jukka Happonen, Senior Specialist Polar Electro Oy:

https://fi.linkedin.com/in/jukka-happonen-aa354a1

logs R-R peak and P-P peak data to his app for these calculations. Happonens app offers MQTT, as a first and only Android app which supports MQTT which we know. Home Assistant has an MQTT integration to connect to MQTT.

We should be able to get these parameters over the Polar SDK as well, if we don t want a path over and Android app. R-R peak data can also be obtained from ECG toolboxes as for instance the iWorx ECG toolbox and HeartPy. For us personally, the easiest open source solution to build an ECG device is OpenBCI. There is an example how to build a 3 lead ECG device, which is gold standard for HR measurement:

https://docs.openbci.com/GettingStarted/Biosensing-Setups/ECGSetup/

We can start with a single lead ECG which is connected to OpenBCI modules. ECG RAW data can be visualized in OpenBCI GUI and stored in .csv. We can analyse ECG raw data from there with HeartPy.

There are several options for a live-stream from OpenBCI if want our sensor data in InfluxDB:

There also Python examples from Harrison Kinsley who teaches Python on his YouTube channel sentdex:

which can be used to connect over Python to OpenBCI. From Python, we can use Rahul Banerjees Python examples to write and read data to InfluxDB:

https://thenewstack.io/getting-started-with-python-and-influxdb/

We know one paper which describes a live stream of EEG data from OpenBCI which is used for Home Automation:

We did not test these examples. But we can imagine that non-coders as we are can test those to see if we can get those to work.