Filters

All filters use SOS (second-order sections) + zero-phase sosfiltfilt to preserve ECG morphology.

  • Input must be a single finite lead (1-D). NaN or Inf samples raise ValueError, since one NaN would spread over the whole filtered output. Signals shorter than the filter’s edge padding (27 samples for a 4th-order band-pass) also raise ValueError.

  • Raw leads are filtered in ADC counts. Their offset is folded into the samples, so to_physical() after filtering gives the same result as filtering the physical signal.

  • diagnostic_filter and monitoring_filter lower their upper cutoff to 0.45 * fs when the sampling rate is too low (e.g. 81 Hz instead of 150 Hz at 180 Hz), and skip a notch that is not below Nyquist. Both cases emit a warning that points at your code. clean_ecg(method="default") applies the same rule to its 40 Hz cutoff (27 Hz at 60 Hz). Pass notch_freq=None to disable the notch, or notch_freq=60 for 60 Hz mains.

lowpass()

Apply a Butterworth low-pass filter

highpass()

Apply a Butterworth high-pass filter

bandpass()

Apply a Butterworth band-pass filter

notch()

Apply an IIR notch (band-stop) filter

remove_baseline()

Remove baseline wander using a high-pass filter

diagnostic_filter()

Apply AHA diagnostic-grade filtering: 0.05–150 Hz bandpass + notch

monitoring_filter()

Apply monitoring-grade filtering: 0.67–40 Hz bandpass + notch

ecgdatakit.processing.lowpass(lead, cutoff, order=4, *, fs=None)[source]

Apply a Butterworth low-pass filter.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array.

  • cutoff (float) – Cutoff frequency in Hz.

  • order (int) – Filter order (default 4).

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead

ecgdatakit.processing.highpass(lead, cutoff, order=4, *, fs=None)[source]

Apply a Butterworth high-pass filter.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array.

  • cutoff (float) – Cutoff frequency in Hz.

  • order (int) – Filter order (default 4).

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead

ecgdatakit.processing.bandpass(lead, low, high, order=4, *, fs=None)[source]

Apply a Butterworth band-pass filter.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array.

  • low (float) – Lower cutoff frequency in Hz.

  • high (float) – Upper cutoff frequency in Hz.

  • order (int) – Filter order (default 4).

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead

ecgdatakit.processing.notch(lead, freq=50.0, quality=30.0, *, fs=None)[source]

Apply an IIR notch (band-stop) filter.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array.

  • freq (float) – Center frequency to remove (default 50 Hz for mains hum).

  • quality (float) – Quality factor, higher means narrower notch (default 30).

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead

ecgdatakit.processing.remove_baseline(lead, cutoff=0.5, order=2, *, fs=None)[source]

Remove baseline wander using a high-pass filter.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array.

  • cutoff (float) – Cutoff frequency in Hz (default 0.5 Hz).

  • order (int) – Filter order (default 2).

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead

ecgdatakit.processing.diagnostic_filter(lead, notch_freq=50.0, *, fs=None)[source]

Apply AHA diagnostic-grade filtering: 0.05–150 Hz bandpass + notch.

Suitable for diagnostic ECG interpretation where full morphology (including ST segment) must be preserved.

The 150 Hz upper cutoff needs a sampling rate above 333 Hz. At lower rates (e.g. 180 or 250 Hz Holter recordings) it is lowered to 0.45 * fs and a warning is emitted. The notch is skipped with a warning when notch_freq is not below the Nyquist frequency.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array.

  • notch_freq (float | None) – Power-line frequency to notch out (50 or 60 Hz), None for no notch.

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead

ecgdatakit.processing.monitoring_filter(lead, notch_freq=50.0, *, fs=None)[source]

Apply monitoring-grade filtering: 0.67–40 Hz bandpass + notch.

Suitable for arrhythmia monitoring where baseline stability is more important than preserving fine morphology. As in diagnostic_filter(), the upper cutoff is lowered to 0.45 * fs at low sampling rates and an impossible notch is skipped, both with a warning.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or 1-D signal array.

  • notch_freq (float | None) – Power-line frequency to notch out (50 or 60 Hz), None for no notch.

  • fs (int | None) – Sample rate in Hz. Required when lead is a numpy array.

Return type:

Lead