Skip to content

Methods for extracting and analysing Heart Rate Variability from a smart phone's camera

Notifications You must be signed in to change notification settings

Lenskiy/Heart-Dynamics-Research-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Eye library: methods for extracting and analyzing Heart Rate Variability from a smart phone's camera

A set of function for extracting PPG from videos recorded by a smartphone’s camera. The tip of the finger should be resting on the camera, gently pressing the camera.

readVideo()

reads a video from a file and returns a cell array of 3 elements i.e. for red, green and blue channels, every element of the cell array is a three dimensional array i.e. I(x,y,t).

Example: [subject{1}, framerate] = readVideo([video_path 'subject1.avi']);

playVideo()

visualize the cell array containing the video.

Example: playVideo(subject{1}, framerate);

videoToPPG()

converts video to PPG signal. The function sums up all pixels in each frame, producing one sample of a PPG signal then removes extremely large values setting them to zero and applies band-pass filter.

Example:

for k = 1:size(subject,2)
ppgs{k}{1} = videoToPPG(subject{k}{1}, framerate);
ppgs{k}{2} = videoToPPG(subject{k}{2}, framerate);
ppgs{k}{3} = videoToPPG(subject{k}{3}, framerate);
end

localizeMaxima()

find peaks in a given PPG. The function first smooths the signal using Savitzky-Golay method and then apply findpeaks_ext() to find the maxima.

Example: [maxLocs, avgInterval] = localizeMaxima(ppg, framerate);

localizeMinima()

finds minima in between the peaks detected by localizeMaxima ().

Example: minLocs = localizeMinima(ppg, maxLocs);

peakEnvelopeGivenPeaks()

makes use of maxima and minima to find the envelope of the signal.

Example: env = peakEnvelopeGivenPeaks(ppg, minLocs, maxLocs);

equalizeSignal()

uses located minima and maxima to equalize the signal.

Example: eqPpg = equalizeSignal(ppg, env);

segmentBeats()

splits an input signal into an array of beats. The beats are resampled to have the same number of samples.

Example: beats = segmentBeats(ppg, minLocs, 30);

findBestBeatShape()

finds the best shape of a heart beat shape. The function clusters all beats into a given number of clusters and return the closest beats to the centeroids as well as the centeroids itself. Besides the function returns indexes of those shapes that are close to the centroids and thus eliminates those beats which shapes are far from the beat shapes represented by the centroids.

Example: [bestShape, beatCentroids_, goodBeatsIndx, hist] = findBestBeatShape(beats, 3);

adjustBeats()

interpolates samples around the peaks and finds a new maximum. Although a better model of a heart beat should be created.

Examples: beatsLocs = adjustBeats(ppg, maxLocs(goodBeatsIndx), framerate);

Heart rate variabitly is simply calculated as follows

hrv = diff(beatsLocs)/framerate;

postprocessHRV()

To fix intervals obtained from incorrectly detected beats, function postprocessHRV () is used.

Example: hrv_filtered = postprocessHRV(hrv);

About

Methods for extracting and analysing Heart Rate Variability from a smart phone's camera

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages