peakswift

Swift library for the R-Peak detection in single-lead electrocardiogram signals

https://github.com/cardiokit/peakswift

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
    Links to: sciencedirect.com
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.2%) to scientific vocabulary

Keywords

ecg-signal r-peak swift
Last synced: 6 months ago · JSON representation ·

Repository

Swift library for the R-Peak detection in single-lead electrocardiogram signals

Basic Info
  • Host: GitHub
  • Owner: CardioKit
  • License: apache-2.0
  • Language: Swift
  • Default Branch: main
  • Homepage:
  • Size: 651 KB
Statistics
  • Stars: 14
  • Watchers: 1
  • Forks: 3
  • Open Issues: 1
  • Releases: 1
Topics
ecg-signal r-peak swift
Created almost 3 years ago · Last pushed about 1 year ago
Metadata Files
Readme License Citation

README.md

PeakSwift

Swift Platforms Swift Package Manager

PeakSwift is a Swift package designed for accurate and real-time R-peak detection in single-lead Electrocardiogram (ECG) data, tailored for the iOS environment. PeakSwift provides also functionality for context-aware R-Peak detection and ECG signal quality evaluation.

Features

  • [x] 9 R-Peak detectors (Christov, nabian2018, Hamilton, TwoAverage, NeuroKit, Pan & Tompkins, UNSW, Engzee, Kalidas)
  • [x] 2 Signal quality evaluators (Zhao2018 Simple, Zhao2018 Fuzzy)
  • [x] Context-aware R-Peak detection

Requirements

| Platform | Minimum Swift Version | Installation | Status | | --- | --- | --- | --- | | iOS 13.0+ / macOS 10.15+ | 5.3 | Swift Package Manager| Fully Tested |

Installation

Swift Package Manager

To install PeakSwift using Swift Package Manager you can follow the tutorial published by Apple using the URL for the PeakSwift repo on the main branch:

  1. In Xcode, select “File” → “Add Packages...”
  2. Enter https://github.com/CardioKit/PeakSwift

or you can add the following dependency to your Package.swift:

swift dependencies: [ .package(url: "https://github.com/CardioKit/PeakSwift.git", branch: "main") ]

You need to restrict the package version to: swift platforms: [ .macOS(.v10_15), .iOS(.v13) ]

And add PeakSwift to your target library.

swift targets: [ .target( name: "<YourLibrary>", dependencies: ["PeakSwift"]) ]

Usage

Setup Electrocardiogram

First of all, configure the ECG, you would like to analyze.

```swift let ecg: [Double] = /* put your ECG here/ let samplingRate: Double = / put your SamplinRate here*/

let electrocardiogram = Electrocardiogram(ecg: ecg, samplingRate: samplingRate) ```

R-Peak detection

PeakSwift provides a R-Peak detection feature as follows:

```swift let qrsDetector = QRSDetector()

// A default algorithm will be selected qrsDetector.detectPeaks(electrocardiogram: electrocardiogram)

// Alternative: An algorithm may be specified let qrsResult = qrsDetector.detectPeaks(electrocardiogram: electrocardiogram, algorithm: .neurokit)

// Extract results let rPeaks = qrsResult.rPeaks let cleanedSignal = qrsResult.cleanedElectrocardiogram ```

Context-aware R-Peak detection

You can pass the ECG signal context to PeakSwift and let PeakSwift decide on the most suitable algorithm.

```swift let qrsDetector = QRSDetector()

// The most suitable algorithm for signal with Atrial Firbrillation will be selcted qrsDetector.detectPeaks(electrocardiogram: electrocardiogram) { config in config.setClassification(.atrialFibrillation) } ```

You can also directly specify the context provided by HealthKit: ```swift import HealthKit

let qrsDetector = QRSDetector()

qrsDetector.detectPeaks(electrocardiogram: electrocardiogram) { config in config.setClassification(fromHealthKit: .sinusRhythm) } ```

ECG signal quality evaluation

PeakSwift support signal quality evaluations:

```swift let signalQualityEvaluator = ECGQualityEvaluator()

let signalQuality = signalQualityEvaluator.evaluateECGQuality( electrocardiogram: electrocardiogram, algorithm: .zhao2018(.fuzzy))

// signalQuality has to be unacceptable, barelyAcceptable or excellent ```

Test suite

The python-based library NeuroKit is used to generate the test data.

Firstly, install the necessary dependencies. We recommend to use the virtual environment manager (venv) for isolating the dependencies.

properties pip3 install -r requirements.txt

To generate the test data & run the test suite use following commands:

```properties

Generate test data

cd TestDataGenerator python3 main.py

Run swift based test suite

cd .. swift build swift test ```

Dependencies

PeakSwift relies on the following libraries:

Contributing

We welcome contributions to enhance PeakSwift:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Commit your changes: git commit -am 'feat(Scope): Add some feature'
  4. Push to the branch: git push origin feature/your-feature-name
  5. Create a pull request.

PeakWatch - Demo app

To illustrate and analyze the functionalities of PeakSwift, a dedicated demo app is developed. It integrates R-Peak detection and signal quality analysis of PeakSwift and can be evaluated with an external analysis tool.

You can explore PeakWatch here: PeakWatch.

Warning

This software is for research purposes only.

How to cite?

If you are using parts of this work or build your experiments up on this repository please cite the following article: @article{kapsecker2024peakswift, title = {PeakSwift: Mobile Detection of R-peaks in Single Lead Electrocardiograms}, journal = {SoftwareX}, volume = {25}, pages = {101608}, year = {2024}, issn = {2352-7110}, doi = {https://doi.org/10.1016/j.softx.2023.101608}, url = {https://www.sciencedirect.com/science/article/pii/S2352711023003047}, author = {Maximilian Kapsecker and Nikita Charushnikov and Leon Nissen and Stephan M. Jonas}, keywords = {Electrocardiogram, R-peak detection, Swift, Benchmark} }

License

PeakSwift is released under Apache License 2.0. See LICENSE for details.

Owner

  • Name: CardioKit
  • Login: CardioKit
  • Kind: organization
  • Email: max.kapsecker@tum.de
  • Location: Germany

A system composed of tools for the analysis of electrocardiogram signals.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Kapsecker"
  given-names: "Maximilian"
- family-names: "Charushnikov"
  given-names: "Nikita"
- family-names: "Nissen"
  given-names: "Leon"
- family-names: "Jonas"
  given-names: "Stephan M."
title: "PeakSwift: Mobile Detection of R-peaks in Single Lead Electrocardiograms"
version: 1.0.0
doi: https://doi.org/10.1016/j.softx.2023.101608
date-released: 2023-09-03
url: "https://github.com/CardioKit/PeakSwift"
preferred-citation:
  type: article
  authors:
    - family-names: "Kapsecker"
      given-names: "Maximilian"
    - family-names: "Charushnikov"
      given-names: "Nikita"
    - family-names: "Nissen"
      given-names: "Leon"
    - family-names: "Jonas"
      given-names: "Stephan M."
  doi: "https://doi.org/10.1016/j.softx.2023.101608"
  journal: "SoftwareX"
  pages: 101608
  title: "PeakSwift: Mobile Detection of R-peaks in Single Lead Electrocardiograms"
  volume: 25
  year: 2024

GitHub Events

Total
  • Issues event: 1
  • Watch event: 2
  • Push event: 1
Last Year
  • Issues event: 1
  • Watch event: 2
  • Push event: 1