heart_rate_monitor.py
is a module housing the HeartRateMonitor
class. This class accepts a path to a local CSV file that contains time, voltage
pairs.
Test data is housed in test_data/test_data1.csv
More test data can be found here.
HeartRateMonitor
class analyzes the ECG input signal and creates the following attributes:
mean_hr_bpm
: average heart rate over a user specified number of minutes (defaults to average rate over entire CSV). Users can update this value by calling theHeartRateMonitor.calc_mean_hr_bpm(start_ts, end_ts)
method.voltage_extremes
: tuple of min and max lead voltages. Format(min_voltage, max_voltage)
duration
: duration of the ECG datanum_beats
: number of detected beats in ECG databeats
: numpy array of times when beats occurred
Upon successful creation of a HeartRateMonitor
class instance, a JSON file with the above attributes is saved in the output_json_files
directory. The JSON file will have the same name as the source CSV file test_data.csv -> test_data.json
First, ensure that you're in a virtual environment and have installed all of the packages listed in requirements.txt
. More information on virtual environement here.
Import the class:
from heart_rate_monitor import HeartRateMonitor
Next, create an instance of the class (and pass in a local CSV):
a = HeartRateMonitor('test_data/test_data1.csv')
Notice that a JSON file with the attributes described above has been created in the output_json_files
directory.
Additionally, users can access any of the attributes within their python code like so:
ecg_duration = a.duration
For a complete list of available attributes, see the documentation.
Users can generate plots of the raw ECG data and the detected heart beats using:
HeartRateMonitor.plot_ecg_and_beats()
Example plot:
The matplotlib
doesn't work well with all virtual environments. If you're seeing errors, please make sure that you're using venv
instead of virtualenv
to create your virtual environment. More here.
Signal processing is NOT my strong suit. To detect peaks in ECG data, I'm using the peakutils
python module. Documentation can be found here.
Detailed logs can be found in the logs
directory.
Documentation can be found here.