Skip to content

Commit

Permalink
Doc updates, bump version to 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
vankesteren committed Feb 21, 2024
1 parent 89aa5fb commit 2586e8d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
^LICENSE\.md$
^.gitignore$
^img/*$
^readme.md$
^readme.md$
^.github
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rpeaks
Type: Package
Title: Fast detection of R peaks in ecg data
Version: 1.4
Version: 1.5
Date: 2020-04-29
Author: Erik-Jan van Kesteren
Maintainer: Erik-Jan van Kesteren <e.vankesteren1@uu.nl>
Expand All @@ -13,4 +13,6 @@ Imports:
Rcpp,
signal
LinkingTo: Rcpp, RcppArmadillo
RoxygenNote: 7.1.0
Encoding: UTF-8
RoxygenNote: 7.3.0
Roxygen: list(markdown = TRUE)
9 changes: 9 additions & 0 deletions R/pantompkins.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ NULL
#' @references Pan, J., & Tompkins, W. J. (1985). A real-time QRS detection
#' algorithm. IEEE transactions on biomedical engineering, (3), 230-236.
#'
#' @examples
#' 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)
#'
#'
#' @export
rpeaks_pan_tompkins <- function(ecg, sample_rate, integration_window = 0.15,
refractory = 0.2, band_low = 5,
Expand Down
Binary file added img/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 15 additions & 5 deletions man/rpeaks_pan_tompkins.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@
<img src="./img/logo.png" width="200px"></img>
</p>

[![R-CMD-check](https://github.com/vankesteren/rpeaks/actions/workflows/rcmdcheck.yml/badge.svg)](https://github.com/vankesteren/rpeaks/actions/workflows/rcmdcheck.yml)

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")
abline(v = r_peaks, col = "blue", lty = 3)
```

## Speed comparison
<p align="center">
<img src="./img/speedcomparison.png" width="700px"></img>
Expand Down
5 changes: 5 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// fast_conv
arma::vec fast_conv(const arma::vec& x, const arma::vec& y);
RcppExport SEXP _rpeaks_fast_conv(SEXP xSEXP, SEXP ySEXP) {
Expand Down

0 comments on commit 2586e8d

Please sign in to comment.