SwiftHeartRate
Use video in cell phone camera to determine a user's heart rate (pulse)
Coded in Swift using Accelerate Library
Use video in cell phone camera to determine a user's heart rate (pulse)
License: MIT License
Use video in cell phone camera to determine a user's heart rate (pulse)
Coded in Swift using Accelerate Library
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))")
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.
power
will contain the maximum value coming from the fourier transform and bin
its index. You calculate these values but you just use bin
.
you do not use either binSize
and errorSize
. What these variables represent?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.