paulvangentcom / heartrate_analysis_python

Python Heart Rate Analysis Package, for both PPG and ECG signals
MIT License
959 stars 322 forks source link

BadSignalWarning on data with 0.5s intervals #28

Closed oskar-j closed 5 years ago

oskar-j commented 5 years ago

Hello!

I'm trying to use your tool for the first time.

I took the data from here: http://ecg.mit.edu/time-series/ ("series 2") Direct link for downloading data: http://ecg.mit.edu/time-series/hr.7275

From the description:

Each series contains 1800 evenly-spaced measurements of instantaneous heart rate from a single subject. The two subjects were engaged in comparable activities for the duration of each series. The measurements (in units of beats per minute) occur at 0.5 second intervals, so that the length of each series is exactly 15 minutes

I'm trying to use this code to load the data:

data = pd.read_csv('hr.7257', header=None, index_col=None, sep='\n')
data.columns = ['data', ]
data = df.data

fs = hp.get_samplerate_mstimer([(x/2) * 1000 for x in data.index.tolist()])
print(fs)  # according to http://ecg.mit.edu/time-series/, is sampled at 0.5[s] intervals
working_data, measures = hp.process(data.values, fs)

The sample rate is 2.0 Hz, but I get the BadSignalWarning. What I am doing wrong? Thanks for help!

Best regards, Oskar

paulvangentcom commented 5 years ago

Hi Oskar,

Thanks for your message, apologies it took me until now to reply, I missed the notification.

It seems you're trying to feed instantaneous heart rate (BPM) data into HeartPy. HeartPy is meant to analyse raw heart rate data.

Beat-beat intervals are required to compute many of the measures HeartPy usually does. It is not straightforward to go from bpm measurements back to beat-beat intervals without knowing how the BPM was derived (most notably how many beats are used to compute it with 2 Hz).

Cheers Paul