paulvangentcom / heartrate_analysis_python

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

The rolling_mean function adds zero in half the cases #85

Closed meierman1 closed 2 years ago

meierman1 commented 2 years ago

According to the source code, it is a known issue that the rolling mean calculation ends up with a trace too short. There is a patch that adds a zero in that case. The reason for the bug is an integer division in int(abs(len(data_arr) - len(rol_mean))/2) which means that it only works precisely if len(data_arr) - len(rol_mean) is a multiple of 2.

Instead of a fix, I propose to dump the whole function and use scipy.ndimage.filters.uniform_filter1d which does exactly what we need but faster and better (handles edges well). (See pull request)