ECG Cleaning¶
Unified cleaning interface with multiple backends.
Clean an ECG lead signal |
- ecgdatakit.processing.clean_ecg(lead, method='default', *, fs=None, **kwargs)[source]¶
Clean an ECG lead signal.
- Parameters:
lead (
Lead|ndarray[tuple[Any,...],dtype[double]]) – Input ECG lead or raw signal array.method (
str) – Cleaning method:"default","biosppy","neurokit2","combined", or"deepfade".fs (
int|None) – Sample rate in Hz. Required when lead is a numpy array.**kwargs –
Extra arguments forwarded to the selected backend:
device(str): PyTorch device for"deepfade"(default"cpu").weights_path(str | Path): Override the bundled DeepFADE weights.batch_size(int): Inference batch size for"deepfade"(default 32).
- Returns:
Cleaned lead (new object, original unchanged).
- Return type:
Available methods¶
Method |
Extra dependency |
Description |
|---|---|---|
|
scipy |
Bandpass 0.5–40 Hz + 50 Hz notch |
|
|
BioSPPy ECG filter |
|
|
NeuroKit2 adaptive pipeline |
|
biosppy + neurokit2 |
BioSPPy → NeuroKit2 |
|
|
DeepFADE denoising autoencoder |
DeepFADE¶
DeepFADE is a denoising autoencoder developed as part of ECGDataKit, trained on a large private multi-source ECG database with extensive noise augmentations (baseline wander, electrode motion, muscle artifacts, powerline interference). The architecture follows a symmetric DenseNet encoder-decoder design: the encoder compresses a 10-second single-lead ECG segment (500 Hz, 5 000 samples) through four dense blocks with progressive downsampling into an 8-channel latent representation, while the decoder mirrors the path with transposed-convolution upsampling and produces two outputs — the denoised signal and the estimated baseline wander. Pre-trained weights are bundled with the package.
from ecgdatakit.processing import clean_ecg
# CPU inference (default)
denoised = clean_ecg(lead, method="deepfade")
# GPU acceleration
denoised = clean_ecg(lead, method="deepfade", device="cuda")
# Apple Silicon MPS
denoised = clean_ecg(lead, method="deepfade", device="mps")
# Custom weights and batch size
denoised = clean_ecg(lead, method="deepfade", weights_path="my_weights.pt", batch_size=64)
Tip
Signals are automatically resampled to 500 Hz, segmented into 5 000-sample chunks, denoised in batches, and reassembled to the original length and sample rate.