torch_ecg._preprocessors.preprocess_single_lead_signal#

torch_ecg._preprocessors.preprocess_single_lead_signal(raw_sig: ndarray[tuple[Any, ...], dtype[_ScalarT]], fs: int | float, bl_win: List[int | float] | None = None, band_fs: List[int | float] | None = None, filter_type: Literal['butter', 'fir'] = 'butter', filter_order: int | None = None) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Perform preprocessing for single lead ECG signal (with units in mV).

Preprocessing may include median filter, bandpass filter, and rpeaks detection, etc.

Parameters:
  • raw_sig (numpy.ndarray) – Raw ECG signal, with units in mV.

  • fs (int or float) – Sampling frequency of raw_sig.

  • bl_win (list (of 2 int or float), optional) – Window (units in second) of baseline removal using median_filter(), the first is the shorter one, the second the longer one, a typical pair is [0.2, 0.6]. If is None or empty, baseline removal will not be performed.

  • band_fs (list of int or float, optional) – Frequency band of the bandpass filter, a typical pair is [0.5, 45]. Be careful when detecting paced rhythm. If is None or empty, bandpass filtering will not be performed.

  • filter_type ({"butter", "fir"}, default "butter") – Type of the bandpass filter.

  • filter_order (int, optional) – Order of the bandpass filter.

Returns:

filtered_ecg – The array of the processed ECG signal.

Return type:

numpy.ndarray

Note

Bandpass filter uses FIR filters, an alternative can be Butterworth filter, e.g. butter_bandpass_filter().