Looping for find peak of signal
Show older comments
Hai...i have a problem to save looping data. For one row signal, my matlab is OK, but if my input more than one row signals it's a trouble. I want to find peak of signal but the peaks of every signal is diffent...please help me
clear erp
%Data
Ypeak = D3_Kiri_Bior35
%Ypeak = Ypeak(2:2,:)
[M1 M2] = size (Ypeak)
for M3 = 1:M1
Xpeak = Ypeak (M3:M3, 1 : M2)
%Xpeak = Ypeak
V = std(Xpeak)
M = mean(Xpeak)
S = 2*(M+V)
[maxmin] = find(Xpeak > S);
[minmax] = find(Xpeak <-S);
%Find ERP
Apeak = maxmin(1,:);
Bpeak = minmax(1,:);
Bpeak = Bpeak'
[ap1,bp1] = size(Xpeak)
[ap2,bp2] = size(Bpeak)
kurang = Bpeak(:,1:1)-30;
tambah = Bpeak(:,1:1)+30;
%Loop [Edit SCd: code formatting]
for ipeak = 1:ap2
if kurang(ipeak) <= 0
kurang(ipeak) = Bpeak(ipeak,1:1)-(Bpeak(ipeak,1:1)-1)
else kurang(ipeak) > 0
kurang(ipeak) = Bpeak(ipeak,1:1)-30
end
end
for kpeak = 1:ap2
if tambah(kpeak) >= M2
tambah(kpeak) = Bpeak(kpeak,1:1)+ (bp1- Bpeak(kpeak,1:1))
else tambah(kpeak) < M2
tambah(kpeak) = Bpeak(kpeak,1:1)+30
end
end
for iipeak = 1:ap2
erp=Ypeak(1:1,kurang(iipeak:iipeak,1:1):tambah(iipeak:iipeak,1:1))
end
end
Answers (2)
Sean de Wolski
on 6 Oct 2011
why can't you just use max or findpeaks?
More per comments
%data 1 valley, two peaks
x = rand(1,100)*10;
x(20) = -3;
x([52 72]) = 7*pi;
the_mean = mean(x);
stddev = std(x);
low_lim = the_mean - 2*stddev; %lower limit
up_lim = the_mean + 2*stddev;
idx_up = find(x>up_lim); %locations
idx_low = find(x<low_lim);
xup_parts = x(min(max(bsxfun(@plus,idx_up(:),-30:30),1),length(x))); %indices of parts
xlow_parts = x(min(max(bsxfun(@plus,idx_low(:),-30:30),1),length(x)));
12 Comments
Endro Yulianto
on 6 Oct 2011
Endro Yulianto
on 6 Oct 2011
Sean de Wolski
on 6 Oct 2011
Yeah, just loop over every row:
for ii = 1:size(x,1)
do_stuff_with(x(ii,:))
end
Endro Yulianto
on 6 Oct 2011
Endro Yulianto
on 6 Oct 2011
Endro Yulianto
on 6 Oct 2011
Sean de Wolski
on 6 Oct 2011
because you overwrite it on each iteration. You need to save to the current location. The easiest way would just to be
xup_parts = [xup_parts;new_x_up_parts];
Add the old one to the end.
Endro Yulianto
on 6 Oct 2011
Sean de Wolski
on 6 Oct 2011
that's my way of trying to hint that the new computation on each iteration of the for-loop. It wasn't working code.
Endro Yulianto
on 6 Oct 2011
Endro Yulianto
on 6 Oct 2011
Endro Yulianto
on 7 Oct 2011
Endro Yulianto
on 6 Oct 2011
0 votes
4 Comments
Sean de Wolski
on 6 Oct 2011
Calculate the std multiply by two and add/subtract from mean. Then use logical indexing to find what's outside that? I'm sorry, I'm having trouble understanding you.
Endro Yulianto
on 6 Oct 2011
Image Analyst
on 7 Oct 2011
Can you give us some MATLAB code to generate some sample data, that we can then use to create a demo for you?
Endro Yulianto
on 7 Oct 2011
Categories
Find more on Vibration 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!