All filter and transform functions accept a Lead and return a newLead (immutable pattern via dataclasses.replace). The original lead is never modified.
Filters
All filters use SOS (second-order sections) + zero-phase sosfiltfilt to preserve ECG morphology.
Function
Returns
Description
lowpass(lead, cutoff, order=4)
Lead
Butterworth low-pass filter
highpass(lead, cutoff, order=4)
Lead
Butterworth high-pass filter
bandpass(lead, low, high, order=4)
Lead
Butterworth band-pass filter
notch(lead, freq=50.0, quality=30.0)
Lead
IIR notch (band-stop) filter
remove_baseline(lead, cutoff=0.5, order=2)
Lead
Remove baseline wander (highpass at 0.5 Hz)
diagnostic_filter(lead, notch_freq=50.0)
Lead
AHA diagnostic: 0.05–150 Hz bandpass + notch
monitoring_filter(lead, notch_freq=50.0)
Lead
Monitoring: 0.67–40 Hz bandpass + notch
fromecgdatakit.processingimportdiagnostic_filter,notch# Diagnostic-grade filteringfiltered=diagnostic_filter(lead)# Or build a custom pipelinefiltered=notch(lead,freq=60.0)# 60 Hz for US mains
R-peak sample indices. Methods: "pan_tompkins" (bandpass + derivative + adaptive threshold) or "shannon_energy" (Shannon energy envelope detector).
heart_rate(lead, peaks=None)
float
Average heart rate in bpm
rr_intervals(lead, peaks=None)
NDArray[np.float64]
RR intervals in milliseconds
instantaneous_heart_rate(lead, peaks=None)
NDArray[np.float64]
Beat-by-beat heart rate in bpm
All functions auto-detect peaks if peaks=None.
fromecgdatakit.processingimportdetect_r_peaks,heart_rate,rr_intervals# Pan-Tompkins (default)peaks=detect_r_peaks(filtered)# Shannon energy envelope — good for noisy signalspeaks_se=detect_r_peaks(filtered,method="shannon_energy")hr=heart_rate(filtered,peaks)# e.g. 72.5rr=rr_intervals(filtered,peaks)# array of RR in ms