Code Monkey home page Code Monkey logo

swiftheartrate's Introduction

SwiftHeartRate

Use video in cell phone camera to determine a user's heart rate (pulse)

Coded in Swift using Accelerate Library

swiftheartrate's People

Contributors

timestocome avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swiftheartrate's Issues

How are these values calculated?

Hi there,

First of all thanks for your code. I appreciate if you can have the time to explain the part when you calculate the heartbeat.

You have this function:

        // find peak power and bin
        var power = 0.0 as Float
        var bin = 0 as vDSP_Length
        
        // calculate heart rate, ie pulse
        // course bandwidth filter --- skip hr under/over unreasonable amounts
        let minHeartRate = 20                                       // skip anything lower ~35 bpm
        let maxHeartRate = Double(windowSizeOverTwo) / 4            // skip anything over ~225 bpm
        vDSP_maxvi(&powerVector+minHeartRate, 1, &power, &bin, vDSP_Length(maxHeartRate))
        bin += vDSP_Length(minHeartRate)        
        
        // push heart rate data to the user
        let timeElapsed = NSDate().timeIntervalSinceDate(timeElapsedStart)
        timeLabel.text = NSString(format: "Seconds: %d", Int(timeElapsed)) as String
        
        let binSize = fps * 60.0 / Float(windowSize)
        let errorSize = fps * 60.0 / Float(windowSize)
        
        let bpm = Float(bin) / Float(windowSize) * (fps * 60.0)
        pulseLabel.text = ("\(Int(bpm))")
  1. First of all, I think the values you get there for minHeartRate and maxHeartRate depends on the FPS you are using that is 30 FPS, right? How do you get these values? In my case I am using 60 FPS and still using 512 samples when the app gets there.

  2. power will contain the maximum value coming from the fourier transform and bin its index. You calculate these values but you just use bin.

  3. you do not use either binSize and errorSize. What these variables represent?

  4. what shows on the pulseLabel is the result of bpm that is the division of bin by some number.

I do not understand this.

bin is the Fourier Transform bin that has the highest intensity. A bin in the Fourier Transform is a frequency. I do not understand the relation between a bin and the heartbeat..

thanks.

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.