Normalization

Pure numpy, no scipy required.

All functions accept a Lead, a list[Lead], an ECGRecord (leads and median beats), a list[ECGRecord], or a numpy array of shape (n_samples,), (n_leads, n_samples) or (n_ecgs, n_leads, n_samples). Each lead (each row along the last axis) is normalized independently, and numpy results are float64.

  • normalize_minmax and normalize_zscore return dimensionless leads: units="", resolution=1.0, resolution_unit="", offset=0.0, is_raw=False.

  • normalize_amplitude is a pure gain and keeps units and scaling metadata. For a lead in a known voltage unit the peak becomes target_mv millivolts in that unit (1000 for a "uV" lead). Raw leads are scaled through their resolution. Without a known unit, and for numpy input, the peak becomes target_mv in the signal’s own units.

  • NaN samples are ignored when computing the statistics and stay NaN. A constant signal normalizes to zeros. A peak-to-peak range of at most 1e-12 times the largest magnitude counts as constant, so rounding noise (e.g. [0.1 + 0.2, 0.3]) is not scaled up to ±1. A flat line around zero, such as a high-passed constant, has no reference scale and is normalized like any other signal.

normalize_minmax()

Scale signal to the [−1, 1] range

normalize_zscore()

Normalize to zero mean and unit variance (z-score)

normalize_amplitude()

Scale peak amplitude to a target value

ecgdatakit.processing.normalize_minmax(data)[source]

Scale signal to the [-1, 1] range.

Overloads:
  • data (Lead) → Lead

  • data (list[Lead]) → list[Lead]

  • data (ECGRecord) → ECGRecord

  • data (list[ECGRecord]) → list[ECGRecord]

  • data (NDArray[np.float64]) → NDArray[np.float64]

Parameters:

data (Lead | list[Lead] | ECGRecord | list[ECGRecord] | NDArray[float64])

Return type:

Lead | list[Lead] | ECGRecord | list[ECGRecord] | NDArray[float64]

Normalization is applied per lead, per ECG.

Accepted inputs:

  • Lead — single lead.

  • list[Lead] — multiple leads (e.g. a 12-lead ECG).

  • ECGRecord — all leads and median beats in the record.

  • list[ECGRecord] — multiple records.

  • numpy array: 1-D (n_samples,), 2-D (n_leads, n_samples) or 3-D (n_ecgs, n_leads, n_samples); each row along the last axis is normalized independently and the result is float64.

Returns the same type as the input.

ecgdatakit.processing.normalize_zscore(data)[source]

Normalize signal to zero mean and unit variance (z-score).

Overloads:
  • data (Lead) → Lead

  • data (list[Lead]) → list[Lead]

  • data (ECGRecord) → ECGRecord

  • data (list[ECGRecord]) → list[ECGRecord]

  • data (NDArray[np.float64]) → NDArray[np.float64]

Parameters:

data (Lead | list[Lead] | ECGRecord | list[ECGRecord] | NDArray[float64])

Return type:

Lead | list[Lead] | ECGRecord | list[ECGRecord] | NDArray[float64]

Normalization is applied per lead, per ECG.

Accepted inputs:

  • Lead — single lead.

  • list[Lead] — multiple leads (e.g. a 12-lead ECG).

  • ECGRecord — all leads and median beats in the record.

  • list[ECGRecord] — multiple records.

  • numpy array: 1-D (n_samples,), 2-D (n_leads, n_samples) or 3-D (n_ecgs, n_leads, n_samples); each row along the last axis is normalized independently and the result is float64.

Returns the same type as the input.

ecgdatakit.processing.normalize_amplitude(data, target_mv=1.0)[source]

Scale signal so that its maximum absolute amplitude equals target_mv.

Overloads:
  • data (Lead), target_mv (float) → Lead

  • data (list[Lead]), target_mv (float) → list[Lead]

  • data (ECGRecord), target_mv (float) → ECGRecord

  • data (list[ECGRecord]), target_mv (float) → list[ECGRecord]

  • data (NDArray[np.float64]), target_mv (float) → NDArray[np.float64]

Parameters:
Return type:

Lead | list[Lead] | ECGRecord | list[ECGRecord] | NDArray[float64]

Normalization is applied per lead, per ECG.

Accepted inputs:

  • Lead — single lead.

  • list[Lead] — multiple leads (e.g. a 12-lead ECG).

  • ECGRecord — all leads and median beats in the record.

  • list[ECGRecord] — multiple records.

  • numpy array: 1-D (n_samples,), 2-D (n_leads, n_samples) or 3-D (n_ecgs, n_leads, n_samples); each row along the last axis is normalized independently and the result is float64.

Returns the same type as the input.

The scaling is a pure gain on the physical signal, so the lead keeps its units and scaling metadata. For a lead in a known voltage unit (units for physical leads, resolution_unit for raw leads) the peak of the physical signal becomes target_mv millivolts, expressed in that unit (e.g. 1000 for a "uV" lead). Without a known unit, and for numpy input, the peak becomes target_mv in the signal’s own units.

Parameters:
Return type:

Lead | list[Lead] | ECGRecord | list[ECGRecord] | NDArray[float64]