PIA-Group / BioSPPy

Biosignal Processing in Python
Other
569 stars 273 forks source link

fix(ecg): correct Pth parameter and pass it as argument in ASI_segmentor #99

Closed afonsocraposo closed 2 years ago

afonsocraposo commented 2 years ago

I was trying to use the ASI_segmentor, implemented by @TiagoTostas, and noticed that it wasn't working as expected. I tested using the example ECG signal available in the repo and it gave me this: original algorithm As it can be seen, the threshold decays too quickly, resulting in the detection of false peaks. After reading the paper regarding this algorithm Rodrigues et al. (2021), I noticed that something was off with the Pth parameter on the Python implementation. The authors state that Pth is a free parameter and chose the value 5 as the best one. On the Python implementation, I found that: https://github.com/PIA-Group/BioSPPy/blob/ff940abbac86e4a405979a4ea7a1c7abcd06d7bf/biosppy/signals/ecg.py#L1328 Which, using a sampling frequency of 1000, results in a Pth of 10.2 - making the threshold way too sensitive. I don't think the Pth value should be dependent on the sampling frequency since, as the authors state in the paper and can be seen in the code, the exponential decay is already dependent on the sampling frequency: https://github.com/PIA-Group/BioSPPy/blob/ff940abbac86e4a405979a4ea7a1c7abcd06d7bf/biosppy/signals/ecg.py#L1371

After changing the Pth to a const value, e.g. 4, the results greatly improved: improved

Therefore, I propose that the Pth becomes an argument of the ASI_segmentor with the default value 5.0 (proposed in the paper).