From cb9d4a784b92b92969a0f3147d14c16d14cb8a1f Mon Sep 17 00:00:00 2001 From: Manuel Meier Date: Fri, 5 Nov 2021 16:55:28 +0100 Subject: [PATCH 1/3] Made ma_perc_list symmetric into the negative --- heartpy/peakdetection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heartpy/peakdetection.py b/heartpy/peakdetection.py index 518b21d..1b65e3b 100644 --- a/heartpy/peakdetection.py +++ b/heartpy/peakdetection.py @@ -281,7 +281,7 @@ def fit_peaks(hrdata, rol_mean, sample_rate, bpmmin=40, bpmmax=180, working_data ''' # moving average values to test - ma_perc_list = [5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 150, 200, 300] + ma_perc_list = [-100, -90, -80, -70, -60, -50, -40, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 150, 200, 300] rrsd = [] valid_ma = [] From 9c8b61cf58548405b10a33cf5a501a7a883df4b2 Mon Sep 17 00:00:00 2001 From: Manuel Meier Date: Fri, 5 Nov 2021 18:01:07 +0100 Subject: [PATCH 2/3] Removed the offsetting of functions that reach into the negative, switched to rolling_mean offsets based on the standard deviation and added negative offsets as well. --- heartpy/heartpy.py | 5 ----- heartpy/peakdetection.py | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/heartpy/heartpy.py b/heartpy/heartpy.py index 7979f3c..053a719 100644 --- a/heartpy/heartpy.py +++ b/heartpy/heartpy.py @@ -276,11 +276,6 @@ def process(hrdata, sample_rate, windowsize=0.75, report_time=False, hrdata = enhance_peaks(hrdata) hrdata = hampel_correcter(hrdata, sample_rate) - # check that the data has positive baseline for the moving average algorithm to work - bl_val = np.percentile(hrdata, 0.1) - if bl_val < 0: - hrdata = hrdata + abs(bl_val) - working_data['hr'] = hrdata working_data['sample_rate'] = sample_rate diff --git a/heartpy/peakdetection.py b/heartpy/peakdetection.py index 1b65e3b..cf32057 100644 --- a/heartpy/peakdetection.py +++ b/heartpy/peakdetection.py @@ -179,7 +179,7 @@ def detect_peaks(hrdata, rol_mean, ma_perc, sample_rate, update_dict=True, worki rmean = np.array(rol_mean) #rol_mean = rmean + ((rmean / 100) * ma_perc) - mn = np.mean(rmean / 100) * ma_perc + mn = np.std(hrdata)*4*ma_perc/100 rol_mean = rmean + mn peaksx = np.where((hrdata > rol_mean))[0] @@ -281,7 +281,7 @@ def fit_peaks(hrdata, rol_mean, sample_rate, bpmmin=40, bpmmax=180, working_data ''' # moving average values to test - ma_perc_list = [-100, -90, -80, -70, -60, -50, -40, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 150, 200, 300] + ma_perc_list = [-50, -40, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 150, 200, 300] rrsd = [] valid_ma = [] From f498204155fb07de21df5b7b90631f2bf44781e1 Mon Sep 17 00:00:00 2001 From: Manuel Meier Date: Fri, 5 Nov 2021 18:03:03 +0100 Subject: [PATCH 3/3] Updated documentation, testing --- heartpy/peakdetection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/heartpy/peakdetection.py b/heartpy/peakdetection.py index cf32057..7e4f05d 100644 --- a/heartpy/peakdetection.py +++ b/heartpy/peakdetection.py @@ -263,10 +263,10 @@ def fit_peaks(hrdata, rol_mean, sample_rate, bpmmin=40, bpmmax=180, working_data Now the wd dict contains the best fit paramater(s): >>> wd['best'] - 20 + 25 This indicates the best fit can be obtained by raising the moving average - with 20%. + with 25% of the standard deviation of the signal. The results of the peak detection using these parameters are included too. To illustrate, these are the first five detected peaks: