Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vankesteren/rpeaks
Fast detection of R peaks in ecg data
https://github.com/vankesteren/rpeaks
ecg heart-rate-analysis qrs qrs-detection signal-processing
Last synced: 27 days ago
JSON representation
Fast detection of R peaks in ecg data
- Host: GitHub
- URL: https://github.com/vankesteren/rpeaks
- Owner: vankesteren
- License: gpl-3.0
- Created: 2020-04-29T18:21:45.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-28T08:47:41.000Z (10 months ago)
- Last Synced: 2024-04-14T06:38:17.188Z (8 months ago)
- Topics: ecg, heart-rate-analysis, qrs, qrs-detection, signal-processing
- Language: R
- Homepage:
- Size: 365 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![R-CMD-check](https://github.com/vankesteren/rpeaks/actions/workflows/rcmdcheck.yml/badge.svg)](https://github.com/vankesteren/rpeaks/actions/workflows/rcmdcheck.yml)
[![rpeaks status badge](https://vankesteren.r-universe.dev/badges/rpeaks)](https://vankesteren.r-universe.dev/rpeaks)Fast implementation of Pan & Tompkins (1985). It is programmed relatively efficiently, using `Rcpp` and `RcppArmadillo` to process long ecg data much faster than alternatives. Default processing parameters are taken directly from the original paper.
This package gratefully borrows parts of the processing code from `rsleep::detect_rpeaks()`.
_NB: use at your own risk. This method has not been officially validated!_
## Installation
Install `rpeaks` from `r-universe` like so:
```r
install.packages("rpeaks", repos = c("https://vankesteren.r-universe.dev", "https://cloud.r-project.org"))
```## Usage
```r
library(rpeaks)
ecg_url <- "https://physionet.org/files/ecgiddb/1.0.0/Person_01/rec_2.dat?download"
ecg_dat <- readBin(ecg_url, integer(), 500*30)
ecg_sec <- (0:(length(ecg_dat) - 1)) / 500 # rel. time in seconds
r_peaks <- rpeaks_pan_tompkins(ecg = ecg_dat, sample_rate = 500)
plot(x = ecg_sec, y = ecg_dat, type = "l", xlab = "time (seconds)", ylab = "ecg")
abline(v = r_peaks, col = "blue", lty = 3)
```
## Speed comparison
The package achieves a nice speedup relative to the `rsleep` implementation:
## Details
This algorithm uses a butterworth filter of order 1 for the band-pass step, and a 3rd-order length-5 Savitzky-Golay smoothing filter to compute the derivative of the band-passed signal. Peak detection on the preprocessed signal works in a simplified way: we take the first value above the lower bound (3 * the mean signal value) which is higher than its neighbours, and not within the refractory period after the previous R peak.### Reference
Pan, J., & Tompkins, W. J. (1985). A real-time QRS detection algorithm. _IEEE transactions on biomedical engineering, (3)_, 230-236.