peterhcharlton / ppg-beats

PPG-beats is a Matlab library of algorithms to detect heartbeats in photoplethysmogram (PPG) signals.
https://peterhcharlton.github.io/project/ppg-beats/
Other
54 stars 10 forks source link

Missed peaks #6

Open wesambachir opened 2 years ago

wesambachir commented 2 years ago

I have missed peaks (using the provided sample data) for all the beat detectors in the toolbox. Although you pointed out this in your video clip, however I could not find out how to resolve this issue. Could you please explain that.

peterhcharlton commented 2 years ago

Thanks for your query. Might you be able to provide the process to replicate this issue (e.g. specify which sample data you used, and the code you used)?

Please note that in the 'PPG beat detection tutorial', it appears that all the peaks were correctly detected by the 'IMS' beat detection algorithm when using this sample data. Perhaps you have been using one of the other sample data files which do result in missed beats?

Many thanks

wesambachir commented 2 years ago

Thank you, In fact I used the sample data file "MIMIC_PERform_1_min_normal.mat" (https://zenodo.org/record/6967256/files/MIMIC_PERform_1_min_normal.mat?download=1) I used the following MATLAB code located on the webpage https://ppg-beats.readthedocs.io/en/latest/tutorials/ppg_beat_detection/ S = data.ppg; % extract PPG data beat_detector = 'IMS'; % Select Incremental-Merge Segmentation beat detector [peaks, onsets, mid_amps] = detect_ppg_beats(S, beat_detector); % detect beats in PPG

figure('Position', [20,20,1000,350]) % Setup figure subplot('Position', [0.05,0.17,0.92,0.82]) t = [0:length(S.v)-1]/S.fs; % Make time vector plot(t, S.v, 'b'), hold on, % Plot PPG signal plot(t(peaks), S.v(peaks), 'or'), % Plot detected beats ftsize = 20; % Tidy up plot set(gca, 'FontSize', ftsize, 'YTick', [], 'Box', 'off'); ylabel('PPG', 'FontSize', ftsize), xlabel('Time (s)', 'FontSize', ftsize)

Missed peaks.pdf

peterhcharlton commented 2 years ago

Thanks very much indeed for highlighting this. I was mistaken when I said "it appears that all the peaks were correctly detected" - as you highlighted in your PDF, they weren't.

I've had a brief look and it appears that the problem is in the definition of a 'local maximum' (and 'local minimum') in the _tidy_peaks_andonsets function within _detect_ppgbeats.m. The current definitions assume that these consist of a single sample at either a maximum (or minimum). In the sample data there are instances of local minima consisting of multiple consecutive samples at the same amplitude, which means they are not identified as local minima.

I'll work on adjusting this.

wesambachir commented 2 years ago

Thank you Dr. Peter for your reply. I'll be looking forward for the corrected code.

MitsurugiMeiya commented 1 year ago

I've had a brief look and it appears that the problem is in the definition of a 'local maximum' (and 'local minimum') in the _tidy_peaks_andonsets function within _detect_ppgbeats.m. The current definitions assume that these consist of a single sample at either a maximum (or minimum). In the sample data there are instances of local minima consisting of multiple consecutive samples at the same amplitude, which means they are not identified as local minima.

Hi Dr.Peter, I have the same issue, but when I try to use the sample data file "MIMIC_PERform_1_min_normal.mat" on the performance assessment tutorial (https://ppg-beats.readthedocs.io/en/latest/tutorials/performance_assessment/)

Could you explain if there is a problem in a function within _detect_ppgbeats.m , why access_beat_detectors.m ,which have also use the functions in __detect_ppgbeats.m , will return 100 F1 score in some beat detectors?

res noQual txt

By the way, I have another question, is it possible to get the heart rate data plot beside a PPG signal(ex. 70beats/min)?

I'm not quite understand how these procedures work, I had a brief look on your paper which had mentioned time alignment, it seems that I cannot simply treat every peak in a PPG signal as a correct beat, but there is no tutorial explain how to do time alignment with PPG and ECG on your webpage(https://ppg-beats.readthedocs.io/en/latest/tutorials/time_alignment/), I have tried to read the functions in _access_beatdetectors.m but it is way too hard for me to understand. So I wonder if there is a simple way to plot the beats data along beside the PPG signal without modify _access_beatdetectors.m?

peterhcharlton commented 1 year ago

Thanks once again @wesambachir . I think I've now resolved this problem with commit https://github.com/peterhcharlton/ppg-beats/commit/df24b4da0253bd1b2749ad1a5355337419abee6d .

peterhcharlton commented 1 year ago

@MitsurugiMeiya my apologies, I haven't fully understood your question. However:

Does that help?