thearn / webcam-pulse-detector

A python application that detects and highlights the heart-rate of an individual (using only their own webcam) in real-time.
Other
3.14k stars 592 forks source link

How to smooth data #59

Open connormeaton opened 3 years ago

connormeaton commented 3 years ago

When plotting the output from your program, it produces a waveform like this:

Screen Shot 2020-08-20 at 10 51 39 AM

I understand this output is more sensitive than an on-finger bpm reader, but with a little imagination the waveform looks similar to what is produced by my on device, like this:

Screen Shot 2020-08-20 at 10 54 13 AM

The waveform on the pulse reader is ultimately transformed to give 1 value as the bpm. Any idea how this transformation is completed? In other words, how do I transform the output from your model to give a reliable, stable bpm? I've tried aggregating at varying levels (1 sec, 2 sec, etc.) with different statistics (mean, min, max, mode), but these values rarely match my on-finger device.

The closest your model gets to my on-finger device is at the local minima on the waveforms. Is this the value I should select for?

Thanks!

keyan commented 3 years ago

@cmeaton I would suggest reading up on digital signal processing. This task seems well suited to an application of the Kalman filter.

e.g. https://scipy-cookbook.readthedocs.io/items/KalmanFiltering.html

connormeaton commented 3 years ago

@keyan IIUC, the Kalman filter estimates smoothed data by considering observed data and an a prior model. What I don't understand is how to determine the a priori model in this case. Is it a manually-defined expected range of values, or something determined statistically?