HeartbeatSegmentationNeurokit#
- class pepbench.algorithms.heartbeat_segmentation.HeartbeatSegmentationNeurokit(*, variable_length: bool = True, start_factor: float = 0.35, r_peak_detection_method: str = 'neurokit', handle_missing_events: Literal['raise', 'warn', 'ignore'] = 'warn')[source]#
Segment ECG signal into individual heartbeats based on NeuroKit2.
This algorithm segments the ECG signal into individual heartbeats based on the R-peaks detected by Neurokit’s
ecg_peaksfunction. The start of each heartbeat is determined based on the R-peak and the current RR-interval.For more information on NeuroKit2, see [Mak21].
- Parameters:
- variable_lengthbool, optional
Trueif extracted heartbeats should have variable length (depending on the current RR-interval) orFalseif 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, seeneurokit2.ecg_segmentfor 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_factorfloat, 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.35means that the beat start is set at 35% of current RR-distance before the R-peak of the beat- r_peak_detection_methodstr, optional
Method to detect R-peaks that is passed to
neurokit2.ecg_peaks. Default: “neurokit”- handle_missing_eventsone of {“warn”, “raise”, “ignore”}, optional
How to handle missing data in the input dataframes. Default: “warn”
- Attributes:
- heartbeat_list_
HeartbeatSegmentationDataFrame - DataFrame containing the segmented heartbeats with the following columns:
start_time: Start time of the heartbeatstart_sample: Start sample of the heartbeatend_sample: End sample of the heartbeatr_peak_sample: Sample of the R-peak of the heartbeatrr_interval_sample: RR-interval to the next heartbeat in samplesrr_interval_ms: RR-interval to the next heartbeat in milliseconds
- heartbeat_list_
References
[Mak21]Makowski, D., Pham, T., Lau, Z. J., Brammer, J. C., Lesspinasse, F., Pham, H., Schölzel, C., & S.H. Chen (2021). NeuroKit2: A Python Toolbox for Neurophysiological Signal Processing. Behavior Research Methods. https://doi.org/10.3758/s13428-020-01516-y
Methods
clone()Create a new instance of the class with all parameters copied over.
extract(*, ecg, sampling_rate_hz)Segment ECG signal into heartbeats.
get_params([deep])Get parameters for this algorithm.
set_params(**params)Set the parameters of this Algorithm.
- __init__(*, variable_length: bool = True, start_factor: float = 0.35, r_peak_detection_method: str = 'neurokit', handle_missing_events: Literal['raise', 'warn', 'ignore'] = 'warn')[source]#
Initialize new
HeartbeatSegmentationNeurokitalgorithm instance.- Parameters:
- variable_lengthbool, optional
Trueif extracted heartbeats should have variable length (depending on the current RR-interval) orFalseif 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, seeneurokit2.ecg_segmentfor 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_factorfloat, 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.35means that the beat start is set at 35% of current RR-distance before the R-peak of the beat- r_peak_detection_methodstr, optional
Method to detect R-peaks that is passed to
neurokit2.ecg_peaks. Default: “neurokit”- handle_missing_eventsone of {“warn”, “raise”, “ignore”}, optional
How to handle missing data in the input dataframes. Default: “warn”
- clone() Self[source]#
Create a new instance of the class with all parameters copied over.
This will create a new instance of the class itself and all nested objects
- get_params(deep: bool = True) dict[str, Any][source]#
Get parameters for this algorithm.
- Parameters:
- deep
Only relevant if object contains nested algorithm objects. If this is the case and deep is True, the params of these nested objects are included in the output using a prefix like
nested_object_name__(Note the two “_” at the end)
- Returns:
- params
Parameter names mapped to their values.
- set_params(**params: Any) Self[source]#
Set the parameters of this Algorithm.
To set parameters of nested objects use
nested_object_name__para_name=.
- extract(*, ecg: _EcgRawDataFrame | DataFrame, sampling_rate_hz: float)[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:
- Returns:
- self
- Raises:
EventExtractionErrorIf the event extraction fails and
handle_missingis set to “raise”