scientisst / BioSPPy

Biosignal Processing in Python
https://biosppy.readthedocs.io/
Other
66 stars 21 forks source link

Add PCG segmentation based on simultaneous ECG + bug correction #1

Closed sofia3ms closed 2 years ago

sofia3ms commented 2 years ago

Added a new function in the pcg module that segments the PCG into the heart sound states based on the R-peak and end T-wave positions of a simultaneous ECG signal (adapted to Python from code developed by David Springer ). An example file with the two simultaneous signals is included.

I used the getTPositions function from the ecg module and found an issue. The identification of the R-peak and the T-wave on the ECG templates was done using the array indexes:

https://github.com/scientisst/BioSPPy/blob/7a34e1f1c01fc6c27e0620c2cb9e0b60c34ebc13/biosppy/signals/ecg.py#L1599-L1602

but these values seem to change depending on the sampling frequency of the signal. I changed it to be based on the templates time axis reference templates_ts in seconds:

# R peak on the template is always on time instant 0 seconds
template_r_position = np.argmin(np.abs(templates_ts - 0))  
# the T wave start is approximately 0.14 seconds after R-peak
template_T_position_min = np.argmin(np.abs(templates_ts - 0.14))

I corrected the same issue in getQPositions, getSPositions and getPPositions, and also added some exception handling so the functions return an output even when they can't find the specific wave in all of the templates.