Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rolling mean offsetter #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions heartpy/heartpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions heartpy/peakdetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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 = [-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 = []
Expand Down