signal processing and paek counts
4 views (last 30 days)
Show older comments
i am simply trying to wrote an algorithm to detects the peaks on a certain ecg signal without using built-in function (findpeaks)
my code works just fine for the full period of the signal which is 540000 sample
but i need the code to count the peaks for each 1 min (6000 sample) and save them into an array
i used the code below but it always shows me the same error:
{
index in position 2 exceeds array bounds. Index must not exceed 1.
Error in algorithm (line 124)
max_h = max(ecgsig(ii,kk));
}
for ii =(0:6000:540000)
max_h = max(ecgsig(ii,ii+6000));
thresh = mean (ecgsig(ii,ii+6000));
poss_reg =(ecgsig(ii,kk)>thresh*max_h)';
left = find(diff([0 poss_reg])==1);
right = find(diff([poss_reg 0])==-1);
for i=1:length(left)
[R_value(i) R_loc(i)] = max( ecgsig(left(i):right(i)) );
R_loc(i) = R_loc(i)-1+left(i);
end
R_loc=R_loc(find(R_loc~=0));
f = length(R_value);
t1=(length(ecg_sm(ii,ii+6000))/fs)/60
bpm=f/t1
end
so what is the problem and how can i solve it?
any help is much appreciated
Answers (1)
Image Analyst
on 2 Jan 2023
Why can't you use findpeaks()? Do you not have the toolbox, or is this homework where you are supposed to reinvent the findpeaks function? If it's your homework, then please tag it as homework. If you can't use that function, I imagine there are others you can't use either, like movmax.
Your error message says you used kk
max_h = max(ecgsig(ii,kk));
while the line in the larger snippet of code you posted says you're using ii
max_h = max(ecgsig(ii,ii+6000));
Which is it? Or is it both and you just posted a snippet from the wrong lines of your program?
So what is the value of kk? Evidently it's more than 1. Why do you even have a 2-D image for your ecg signal anyway? Shouldn't it be a 1-D signal, so you wouldn't even have a column index like kk or ii+6000?
Maybe you mean
max_h = max(ecgsig(ii : ii+6000));
to specify a range of elements rather than a single (row, column) location in an image.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
0 Comments
See Also
Categories
Find more on Time-Frequency Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!