Looping for find peak of signal

2 views (last 30 days)
Endro Yulianto
Endro Yulianto on 6 Oct 2011
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
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
Endro Yulianto on 7 Oct 2011
I do it for 2 week but i don't know how to save looping in current location

Sign in to comment.


Endro Yulianto
Endro Yulianto on 6 Oct 2011
I try to find peak of signal that amplitudo of the peak is above and under mean (+/-) 2*standart deviation and from that peak i segmenteg that signal (+/-) 30 data with peak is the center. The problem is when i try to find more than 2 row signal from looping, only last data is saved. Please help me
  4 Comments
Image Analyst
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
Endro Yulianto on 7 Oct 2011
x = rand(2,100)*10;
x(:,20) = -3;
x(:,[52 72]) = 7*pi;

Sign in to comment.

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!