BME 590 - Heart Rate Monitor Assignment
Developed By: Harvey Shi (@rvshi)
Course: Duke BME 590-05 Medical Software Design (Spring 2018)
This project defines a Python 3 class, HRMonitor
, for processing ECG data.
DataHandler
class is used, to allow further extensibility in the future.For more detailed information on the individual class methods, see the documentation site.
First, you want to set up a Python virtual environment and install the packages in requirements.txt
.
HRmonitor
class from hrmonitor.py
and start using this module in your code.
from hrmonitor import HRMonitor
hr = HRMonitor('./test_data/test_data5.csv')
hr.plot_data()
Which produces the following files:
./test_data/test_data5.json
:
{
"peak_interval": 0.808,
"mean_hr_bpm": [74.25743, 73.71007, 74.25743],
"voltage_extremes": [-1.155, 1.72],
"duration": 27.775,
"num_beats": 36,
"beats": [0.061, 0.886, 1.714, 2.511, 3.306, 4.081, 4.869, 5.736, 6.564, 7.372, 8.181, 8.986, 9.772, 10.556, 11.403, 12.25, 13.075, 13.886, 14.678, 15.489, 16.258, 17.072, 17.928, 18.742, 19.569, 20.378, 21.178, 21.958, 22.742, 23.111, 23.411, 23.875, 24.436, 25.253, 26.058, 26.867]
}
./test_data/test_data5.png
:
.csv
format..csv
, in this order: time, voltage
.test_data/
directory.time_units
and voltage_units
arguments in the HRMonitor constructor function.time_units
is a float representing the new unit of time in terms of seconds.voltage_units
is a float representing the new unit of time in terms of seconds.
HRMonitor('./file.csv', time_units = 0.001, voltage_units = 1000)
time
: numpy vector of the time datavoltage
: numpy vector of the voltage datapeak_interval
: interval between all peaks in the signal, as estimated via autocorrelation of the signal (in seconds)mean_hr_bpm
: numpy vector containing the average heart rate (in bpm) for contiguous bins with a size specified by the userpeak_interval
over chunks of the dataget_mean_hr(<window_size>)
function, where window_size
is the size of the chunks in secondsvoltage_extremes
: tuple of the (min, max) of the voltage dataduration
: total length of the signal in secondsbeats
: numpy array with the approximate time locations of heart beats via peak detection following a bandpass filternum_beats
: estimated number of beats in the data, taken as the length of beats
.csv
.time
and voltage
are not exported since they are already in archival format.plot_data()
method.The current module has only been tested with Python 3.6.4 on MacOS 10.13