Code Monkey home page Code Monkey logo

heartbeats.jl's Introduction

License

HeartBeats.jl

HeartBeats.jl provides a heartbeat detector based on the approach described by Pan & Tompkins (1985). It is based on the implementation available in the Python package SleepECG.

Installation

Use the package manager to add HeartBeats.jl by typing ] add HeartBeats in the Julia REPL.

Example

HeartBeats.jl contains a short example ECG dataset taken from scipy.misc.electrocardiogram(). The function example_ecg() returns this data, which was sampled with a sampling frequency of 360 Hz, as a Vector{Float64}. We can use this dataset to showcase the detect_heartbeats() function:

using HeartBeats

ecg = example_ecg()
fs = 360  # sampling frequency

beats = detect_heartbeats(ecg, fs)

The beats array will contain all detected R peak locations.

Benchmark

The detector is based on the Python implementation available in SleepECG. It is about 18× faster than the Python implementation and only 2× slower than the C implementation. Follow these steps to reproduce the benchmark:

  1. Export all data records used in the 'runtime' benchmark by including export_records = True in config.yml (refer to the SleepECG documentation for details on how to set up and run the benchmarks). This will generate 15 text files.
  2. Move those text files to a folder that you can access from Julia (i.e. set the Julia working directory accordingly).
  3. Run the following code snippet to benchmark the runtime for 60 minute data segments (note that you need to add the CSV package):
using CSV, HeartBeats

function run_benchmark()
    total = 0
    fs = 128
    files = filter(x -> endswith(x, ".txt"), readdir(".", join=true))
    for file in files
        println(file)
        data = CSV.File(file, comment="#")
        ecg = view(data[:ecg], 1:60*60*fs)  # 60 minutes
        stats = @timed detect_heartbeats(ecg, fs)
        total += stats.time
    end
    println("Total: $total, Average: $(total / length(files))")
    total
end

run_benchmark()

heartbeats.jl's People

Contributors

cbrnr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ecgkit

heartbeats.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.