HeartSounds is a package for automatically annotating heart sound locations based on ECG traces.
You can download HeartSounds from PyPI.
pip install heartsounds
from heartsounds.find_ecg_peaks import find_ecg_peaks
from heartsounds.annotations import get_heart_sound_timings_by_intervals, save_annotations_to_file
import wfdb
# Download example data
signal, fields = wfdb.rdsamp('ECGPCG0007', pn_dir='ephnogram/WFDB', channels=[0])
ecg = signal[:, 0]
ecg_sample_rate = fields['fs']
# Find ECG R and T peaks
ecg_peaks = find_ecg_peaks(ecg, ecg_sample_rate)
# Find heart sound timings
annotations = get_heart_sound_timings_by_intervals(ecg_peaks)
# Save annotations to file
save_annotations_to_file('./', 'annotations', annotations)