BandPass

class torch_ecg._preprocessors.BandPass(lowcut: Real | None = 0.5, highcut: Real | None = 45, filter_type: str = 'butter', filter_order: int | None = None, **kwargs: Any)[source]

Bases: PreProcessor

Bandpass filtering preprocessor.

Parameters:
  • lowcut (numbers.Real, optional) – Low cutoff frequency

  • highcut (numbers.Real, optional) – High cutoff frequency.

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

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

  • **kwargs (dict, optional) – Other arguments for PreProcessor.

Examples

from torch_ecg.cfg import DEFAULTS
sig = DEFAULTS.RNG.randn(1000)
pp = BandPass(lowcut=0.5, highcut=45, filter_type="butter", filter_order=4)
sig, _ = pp(sig, 500)
apply(sig: ndarray, fs: int) Tuple[ndarray, int][source]

Apply the preprocessor to sig.

Parameters:
  • sig (numpy.ndarray) –

    The ECG signal, can be
    • 1d array, which is a single-lead ECG;

    • 2d array, which is a multi-lead ECG of “lead_first” format;

    • 3d array, which is a tensor of several ECGs, of shape (batch, lead, siglen).

  • fs (int) – Sampling frequency of the ECG signal.

Returns:

  • filtered_sig (numpy.ndarray) – Bandpass filtered ECG signal.

  • fs (int) – Sampling frequency of the filtered ECG signal.

extra_repr_keys() List[str][source]

Extra keys for __repr__() and __str__().