Signal Quality

signal_quality_index()

Compute a composite signal quality index (SQI) in [0, 1]

classify_quality()

Classify signal quality as a human-readable category

snr_estimate()

Estimate signal-to-noise ratio in dB

The SQI is a heuristic screening score, not a validated clinical measure. It is the mean of four sub-scores, each in [0, 1]. Band components are obtained with zero-phase Butterworth filters, so the scores do not depend on the sample rate. The signal must be 1-D, finite and at least 1 s long.

Sub-score

Definition

Scoring

Kurtosis

Excess kurtosis of the signal (after Li, Clark and Clifford 2008)

1 from 3 to 20, k / 3 below 3, 0 when negative, linear decrease to 0 at 50 above 20

Power ratio

Variance of the 1–40 Hz band / variance of the mean-removed signal

ratio / 0.7, clipped to [0, 1]

Peak regularity

Coefficient of variation (CV) of RR intervals from detect_r_peaks()

1 − 2 × CV, clipped, or 0.3 when fewer than 3 peaks

Baseline stability

Variance below 1 Hz / variance of the 1–40 Hz band

1 − ratio, clipped

classify_quality() maps the SQI to "excellent" (> 0.8), "acceptable" (0.5–0.8) or "unacceptable" (< 0.5).

Note

Irregular rhythms (atrial fibrillation, frequent ectopy) lower the peak-regularity score even when the recording is clean.

SNR estimate. snr_estimate() takes the noise floor as the mean power spectral density above 100 Hz (Welch, 1 s segments), assumes it is white, and extrapolates it over the 1–40 Hz ECG band. The result is the 1–40 Hz power divided by that noise power, in dB. Limits:

  • It returns nan at 200 Hz or below, where there is no band above 100 Hz (the half-weight Nyquist bin is excluded from the noise band).

  • It returns inf when no noise is measured.

  • It measures only broadband noise reaching above 100 Hz (EMG, electronic noise). Baseline wander, powerline interference and in-band motion artefacts are not counted.

  • Recordings low-pass filtered below 100 Hz by the device read as noise-free.

ecgdatakit.processing.signal_quality_index(lead, *, fs=None)[source]

Compute a composite signal quality index (SQI) in the range [0, 1].

Mean of four sub-scores: kurtosis, power ratio, R-peak regularity and baseline stability (see the module documentation for definitions and thresholds).

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or raw signal array (at least 1 s).

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

Returns:

Score between 0.0 (unusable) and 1.0 (excellent).

Return type:

float

Raises:

ValueError – Signal shorter than 1 s, not 1-D, or containing NaN or infinite values.

ecgdatakit.processing.classify_quality(lead, *, fs=None)[source]

Classify signal quality as a human-readable category.

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

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

Returns:

"excellent" (SQI > 0.8), "acceptable" (0.5–0.8), or "unacceptable" (< 0.5).

Return type:

str

ecgdatakit.processing.snr_estimate(lead, *, fs=None)[source]

Estimate signal-to-noise ratio in dB.

The noise floor is the mean power spectral density (Welch, 1 s segments) above 100 Hz, assumed white and extrapolated over the 1–40 Hz ECG band. The SNR is the 1–40 Hz power divided by that extrapolated noise power.

Limits: only broadband noise that reaches above 100 Hz (EMG, electronic noise) is measured. Baseline wander, powerline interference and in-band motion artefacts are not counted, and recordings low-pass filtered below 100 Hz by the device read as noise-free.

Parameters:
  • lead (Lead | NDArray[double]) – Input ECG lead or raw signal array (at least 1 s).

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

Returns:

Estimated SNR in dB. nan when the sample rate is 200 Hz or lower (no band above 100 Hz); inf when no noise is measured.

Return type:

float