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_minmaxandnormalize_zscorereturn dimensionless leads:units="",resolution=1.0,resolution_unit="",offset=0.0,is_raw=False.normalize_amplitudeis a pure gain and keeps units and scaling metadata. For a lead in a known voltage unit the peak becomestarget_mvmillivolts in that unit (1000 for a"uV"lead). Raw leads are scaled through theirresolution. Without a known unit, and for numpy input, the peak becomestarget_mvin 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-12times 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.
Scale signal to the [−1, 1] range |
|
Normalize to zero mean and unit variance (z-score) |
|
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 (
unitsfor physical leads,resolution_unitfor 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.