Detects R-peaks in a raw ECG signal using the Pan-Tompkins algorithm. Implements bandpass filtering, derivative, squaring, moving-average integration, and adaptive dual-threshold peak detection with T-wave rejection and search-back for missed beats.
Arguments
- ecg
Numeric vector. Raw ECG signal.
- fs
Numeric. Sampling frequency in Hz. If
ecgcomes fromread_philips_physlog(), userec$HDR$sfreq.
Value
A list of class mrpheus_qrs with components:
qrs_iInteger vector of R-peak sample indices (1-based), referenced to the bandpass-filtered signal.
qrs_ampNumeric vector of R-wave amplitudes at each detected peak (normalised bandpass signal units).
delayNumeric. Sample delay introduced by the moving-average stage (half the 150 ms window length).
fsNumeric. Sampling frequency passed to the function.
Details
Processing pipeline (Pan & Tompkins, 1985):
Bandpass filter 5–15 Hz (Butterworth N=3). At fs = 200 Hz, implemented as separate 12 Hz low-pass then 5 Hz high-pass stages.
Derivative filter — 5-point kernel interpolated to match fs.
Squaring — non-linear emphasis of dominant peaks.
150 ms moving-average integration.
Adaptive thresholding — dual-threshold scheme with T-wave rejection and search-back for missed beats (initialised on 2-second training window).
R-peak indices are returned relative to the bandpass-filtered signal.
Account for delay if you need indices aligned to the raw ECG.
References
Pan J, Tompkins WJ. A real-time QRS detection algorithm. IEEE Trans Biomed Eng. 1985;32(3):230–236. doi:10.1109/TBME.1985.325532
Examples
if (FALSE) { # \dontrun{
rec <- read_philips_physlog("sub-01_physlog.log")
qrs <- detect_qrs(rec$C[, "v1raw"], fs = rec$HDR$sfreq)
qrs
# Downstream HR signal
hr <- compute_hr_signal(qrs)
} # }