ECG Analysis Functions for PhysioExperiment Objects
PhysioECG provides electrocardiography (ECG) analysis functions for the PhysioExperiment ecosystem. With 18 exported functions, it delivers a complete ECG analysis pipeline -- from R-peak detection using an adaptive Pan-Tompkins algorithm, through RR interval computation and ectopic beat correction, to comprehensive heart rate variability (HRV) analysis across time-domain, frequency-domain, and nonlinear methods. It also includes ECG morphology analysis (PQRST waveform delineation, clinical interval measurement) and signal quality assessment.
You can install PhysioECG from r-universe:
# the containers build on Bioconductor, so its repositories are needed too
install.packages("BiocManager", repos = "https://cloud.r-project.org")
install.packages("PhysioECG",
repos = c("https://x-biosignal.r-universe.dev", BiocManager::repositories()))
Or install the development version from GitHub:
# install.packages("remotes", repos = "https://cloud.r-project.org")
remotes::install_github("x-biosignal/PhysioECG")
library(PhysioECG)
# Generate a simulated ECG signal (10 seconds at 500 Hz, 72 bpm)
pe <- make_ecg(n_time = 5000, sr = 500, heart_rate = 72)
# Detect R-peaks using the adaptive Pan-Tompkins algorithm
peaks <- ecgDetectRpeaks(pe)
head(peaks)
#> channel sample time_sec amplitude
#> 1 1 347 0.692 1.50
#> 2 1 764 1.526 1.50
#> ...
# Compute RR intervals
rr <- ecgRRintervals(pe, peaks)
# Time-domain HRV metrics
hrv_time <- ecgHRVtime(rr)
hrv_time
#> channel mean_rr sdnn rmssd pnn50 mean_hr
#> 1 1 833.33 1.23 0.87 0 72.00
# Frequency-domain HRV analysis (Welch PSD)
hrv_freq <- ecgHRVfreq(rr, method = "welch")
# Nonlinear HRV (Poincare, Sample Entropy, DFA)
hrv_nl <- ecgHRVnonlinear(rr)
# ECG morphology: delineate P, QRS, T waves
delin <- ecgDelineate(pe, peaks)
intervals <- ecgIntervals(delin, sr = 500)
head(intervals)
#> channel beat pr_ms qt_ms qtc_ms qrs_ms rr_ms
#> 1 1 1 126.0 360.0 394.1 80.0 833.3
Adaptive dual-threshold Pan-Tompkins detector with automatic inverted-signal handling:
ecgDetectRpeaks() -- detect R-peaks using bandpass filtering (5--15 Hz), differentiation, squaring, moving-window integration, and adaptive thresholdingRR interval computation and ectopic beat correction:
ecgRRintervals() -- compute RR intervals from detected R-peaksecgQualityCheck() -- detect ectopic beats using local median comparisonecgRRcorrect() -- correct ectopic beats by interpolation or removalStandard time-domain HRV metrics per ESC/NASPE Task Force guidelines:
ecgHRVtime() -- SDNN, RMSSD, pNN50, mean RR, mean heart ratePower spectral density estimation with standard frequency band integration:
ecgHRVfreq() -- VLF (0.003--0.04 Hz), LF (0.04--0.15 Hz), HF (0.15--0.4 Hz) power, LF/HF ratio, total powerNonlinear dynamics and complexity measures:
ecgHRVnonlinear() -- convenience wrapper combining all nonlinear metricsecgHRVpoincare() -- Poincare plot descriptors (SD1, SD2, SD1/SD2 ratio)ecgSampleEntropy() -- sample entropy for signal complexity/regularityecgDFA() -- detrended fluctuation analysis (alpha1 short-range, alpha2 long-range)Waveform delineation and clinical interval measurement:
ecgDelineate() -- identify QRS complex boundaries, P-wave and T-wave peaks, and T-wave end for each beatecgIntervals() -- compute PR interval, QRS duration, QT interval, and QTc (Bazett correction)Signal quality evaluation and baseline correction:
ecgSignalQuality() -- per-channel SNR, baseline wander, saturation ratio, and composite quality scoreecgBaselineCorrect() -- remove baseline wander using highpass moving-average or running-median subtractionSynthetic ECG generators for testing and demonstration:
make_ecg() -- regular ECG with Gaussian-shaped R-peaks at fixed heart ratemake_ecg_pqrst() -- realistic PQRST morphology with known fiducial points for validationmake_ecg_irregular() -- ECG with simulated ectopic (premature) beats and compensatory pausesmake_ecg_noisy() -- ECG contaminated with baseline wander, powerline interference, and broadband noisePhysioECG is the ECG analysis module of the PhysioExperiment ecosystem, a suite of R packages for multi-modal physiological signal analysis:
| Package | Description |
|---|---|
| PhysioCore | Core data structures and accessors |
| PhysioIO | File I/O (EDF, HDF5, BIDS, CSV, MAT) |
| PhysioPreprocess | Preprocessing (filters, ICA, resampling) |
| PhysioAnalysis | Analysis and visualization |
| PhysioECG | ECG analysis and HRV |
| PhysioEDA | Electrodermal activity analysis |
Visit the r-universe page to browse all available packages.
MIT License. See LICENSE for details.
Yusuke Matsui
Part of the Physio ecosystem. Community and policy documents live in the umbrella repository: