I am currently trying to plot all the peaks of my data. Unfortunatley the last peak fails to be plotted using this function. It also happens to be the penultimate value in my data set so I'm not sure if this is where the problem is. It would be apprciated if someone could take a look and see if they can figure out where I am going wrong.
Thanks very much.
ECG = load('ECG.csv')
Frequency = 350; %Frequency of ECG [Hz]
Time = (0:length(ECG)-1)/Frequency; %Number of samples divided by frquency
Amp = ECG(:,1); %ECG Amplitude
figure
plot(Time,Amp)
findpeaks(Amp,Time,'MinPeakProminence',100);
[pks,locs] = findpeaks(Amp,Time,'MinPeakProminence',100);
meanCycle = mean(diff(locs));
BPM = 60/meanCycle;
fprintf('%.2f', BPM)

 Akzeptierte Antwort

Star Strider
Star Strider am 6 Jan. 2020

0 Stimmen

Thje last R-wave is not actually a peak as findpeaks defines it.
It is necessary to get creative in order to isolate and define it:
ECG = load('ECG.csv')
Frequency = 350; %Frequency of ECG [Hz]
Time = (0:length(ECG)-1)/Frequency; %Number of samples divided by frquency
Amp = ECG(:,1); %ECG Amplitude
figure
% plot(Time,Amp)
findpeaks(Amp,Time,'MinPeakProminence',100);
[pks,locs] = findpeaks(Amp,'MinPeakProminence',100); % Return Indices Instead of Times
ofst = locs(end)+1; % Last Peak ‘loc’ + 1
[Rwaves,idx] = max(Amp(ofst:end)); % Maximum Of Remaining Segment Of ‘Amp’
meanCycle = mean(diff(Time(locs)));
BPM = 60/meanCycle;
fprintf('%.2f\n', BPM)
figure
plot(Time,Amp)
hold on
plot(Time(locs), Amp(locs), '^r', 'MarkerFaceColor','r') % Plot Peaks That ‘findpeaks’ Returns
plot(Time(idx+ofst), Rwaves, 'pr', 'MarkerFaceColor','r') % Plot Last Incomplete Peak
hold off
Producing:
1Findpeaks function won't plot all peaks - 2020 01 06.png
With the last ‘peak’ plotted with a pentagram.

4 Kommentare

ImperialStar
ImperialStar am 6 Jan. 2020
Brilliant thank you. Do you mind telling my why findpeaks doesn't define it as a peak? I thought a peak was defined as a sample larger than both its neigbours?
Thanks for your help.
Star Strider
Star Strider am 6 Jan. 2020
As always, my pleasure! I very much appreciate your compliment!
I thought a peak was defined as a sample larger than both its neigbours?
That is correct. However the problem is that the end value has no neighbour to the right of it to compare it to (for lack of a better description), so findpeaks does not see it as a peak. It is just an isolated value.
ImperialStar
ImperialStar am 7 Jan. 2020
My hero. Thanks for all of your help.
Star Strider
Star Strider am 7 Jan. 2020
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by