Please, someone help me to understand this code.

1 view (last 30 days)
I'm a beginner in MATLAB and i have to understand this code as it's important for my project. I request you guys to please help me to understand this code.
ec=xlsread('sumit_ecg.xlsx','B3:B1000003');
figure;
plot(ec);
j=1;
for i=2:length(ec)-1;
if ec(i-1)< ec(i) && ec(i+1)<ec(i);
ecgy1(j)=ec(i);
ecgx1(j)=i;
j=j+1;
end
end
figure;plot(ec); hold on;
plot(ecgx1,ecgy1,'*');
j=j+1;
for i=1:length(ecgy1);
if ecgy1(i)>=2;
ecgy2(j)=ecgy1(i);
ecgx2(j)=ecgx1(i);
j=j+1;
end
end
figure;plot(ec); hold on;
plot(ecgx2,ecgy2,'*');

Accepted Answer

Image Analyst
Image Analyst on 9 May 2021
It would be easier if you'd attach your workbook, but it looks like it's doing some kind of peak detection where if an element is more than the prior one and subsequent one (so it's a local max), it logs/records the value of that local maximum.
Then it plots it and records where the peaks have a value of more than 2 and then plots those.
  4 Comments
Image Analyst
Image Analyst on 9 May 2021
if ec(i-1)< ec(i) && ec(i+1)<ec(i);
basically sees if the i'th element is more than the elements on either side of it.
j is a counter so that the ecgx1 and ecgy1 only have the peak values and none of the values in between.
ecgy1(j)=ec(i);
ecgx1(j)=i;
The first line records the y value of the j'th peak. The second line records the index that the j'th peak occurred at.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!