SamProell / yarppg

Yet another implementation of remote photoplethysmography (rPPG) in Python
MIT License
51 stars 14 forks source link

Any way to output raw PPG signal to calculate HRV metrics? #19

Open Niteesh-Kalangi opened 3 weeks ago

Niteesh-Kalangi commented 3 weeks ago

I am trying to calculate HRV metrics from videos, and I think I need the raw PPG signal to do that. Is there any way I can get the code to output raw PPG signals? I need metrics of {'HR', 'SDRR', 'RMSSD', 'SDSD', 'pNN50'}.

SamProell commented 3 weeks ago

You can run the programm with run-yarppg --savepath=./signals.csv which will write a history of the recorded processor values after the window is closed.

Concerning HRV, you may need to consider that due to the low sampling rate (typically 30 frames per second on a webcam), some parameters may not be very accurate.

Niteesh-Kalangi commented 3 weeks ago

I was going to ask, what kind of data does that data outputted represent? Because its not a raw PPG signal right? So what do the columns represent, and how can they be used to get HRV metrics?

SamProell commented 3 weeks ago

It depends on the algorithm/processor you choose. By default, you get a bandpass-filtered version of the average green channel in the region of interest.

For HRV, you would need to identify the heart beats in the output signal, then calculate the time differences between successive beats (in ECG this would be RR intervals - RRI). Then you could something like neurokit to calculate HRV https://neuropsychology.github.io/NeuroKit/examples/ecg_hrv/ecg_hrv.html

But as I said, many of the features may not make sense due to the low sampling rate.

Niteesh-Kalangi commented 2 weeks ago

Also, I see that in the code, you guys calculate heartbeats from peaks in hr.py with the from_peaks method. Could I just use that code and the pulse wave signal values to identify heartbeats and then use that for HRV? Or would you suggest using the outputted csv file for those calculations instead?

SamProell commented 2 weeks ago

I actually just this week updated the repo with a complete rework of the functionality. There is now also a documentation for most of the code. You can go through the instructions here: https://samproell.github.io/yarppg/video_processing/ to get signal values directly for a video file. You can then detect heartbeats from there to do the HRV.