biopsykit.signals.ecg.segmentation package

Module for ECG segmentation.

class biopsykit.signals.ecg.segmentation.BaseHeartbeatSegmentation[source]

Bases: Algorithm

Base class for all heartbeat segmentation algorithms.

This class defines the interface for all heartbeat segmentation algorithms. Heartbeat segmentation algorithms are used to segment ECG signals into individual heartbeats.

heartbeat_list_

DataFrame containing the segmented heartbeats. Each row represents one heartbeat.

Type

DataFrame

heartbeat_list_: DataFrame
extract(*, ecg, sampling_rate_hz)[source]

Segment ECG signal into heartbeats.

Parameters
  • ecg (EcgRawDataFrame) – ECG data.

  • sampling_rate_hz (float) – Sampling rate of the ECG data in Hz.

class biopsykit.signals.ecg.segmentation.HeartbeatSegmentationNeurokit(*, variable_length=True, start_factor=0.35, r_peak_detection_method='neurokit', handle_missing_events='warn')[source]

Bases: BaseHeartbeatSegmentation, CanHandleMissingEventsMixin

Initialize new HeartbeatSegmentationNeurokit algorithm instance.

Parameters
  • variable_length (bool, optional) – True if extracted heartbeats should have variable length (depending on the current RR-interval) or False if extracted heartbeats should have fixed length (same length for all heartbeats, depending on the mean heartrate of the complete signal, 35% of mean heartrate in seconds before R-peak and 50% after r_peak, see neurokit2.ecg_segment() for details). For variable length heartbeats, the start of the next heartbeat follows directly after end of last (ends exclusive); For fixed length heartbeats, there might be spaces between heartbeat borders, or they might overlap. Default: True

  • start_factor (float, optional) – only needed if variable_length=True. This parameter defines where the start border between heartbeats is set depending on the RR-interval to previous heartbeat. For example, start_factor=0.35 means that the beat start is set at 35% of current RR-distance before the R-peak of the beat

  • r_peak_detection_method (str, optional) – Method to detect R-peaks that is passed to neurokit2.ecg_peaks(). Default: “neurokit”

  • handle_missing_events (one of {"warn", "raise", "ignore"}, optional) – How to handle missing data in the input dataframes. Default: “warn”

heartbeat_list_: biopsykit.utils.dtypes._HeartbeatSegmentationDataFrame | pandas.core.frame.DataFrame
variable_length: bool
start_factor: float
r_peak_detection_method: str
extract(*, ecg, sampling_rate_hz)[source]

Segment ECG signal into heartbeats.

The function uses R-peak detection to segment the ECG signal into heartbeats. The start of each heartbeat is determined based on the R-peak and the current RR-interval.

The results (start and end sample, R-peak sample, current RR-interval in samples and milliseconds) are saved in the heartbeat_list_ attribute.

Parameters
  • ecg (Series or DataFrame) – ECG signal

  • sampling_rate_hz (int) – Sampling rate of ECG signal in hz

Return type

self

Raises

EventExtractionError – If the event extraction fails and handle_missing is set to “raise”