[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: findpeak
From: |
Luke M |
Subject: |
Re: findpeak |
Date: |
Thu, 29 Mar 2012 11:23:10 -0700 (PDT) |
asha g wrote
>
> I wrote the following code. I know it needs to be tweaked a bit. Can you
> help me do that and get it to run ? Help appreciated. Asha G
>
> for iter = 1: (niter-2)
>
> if (vv1(iter)<vv1(iter+1)>vv1(iter+2))
> x = (iter +1)
> maxima(niter) = vv1(x)
> tx(iter,:) = (iter+1)
>
> elseif (vv1(iter)>vv1(iter+1)<vv1(iter+2))
> minima(iter,:) = vv1(iter+1);
> txmin = [(iter+1),1];
>
> endif
>
> endfor
>
The problem with your idea is that it doesn't find flat peaks. I guess
that's okay if you don't want it to do so, but if that's the case you might
as well use the diff approach mentioned before. Some quick untested code
for my algorithm:
candlist = vv1(1);
maxima = []; maximaIdx = [];
for k = 2:length(vv1)
if (vv1(k) > vv1(k-1))
candlist = vv1(k);
elseif (vv1(k) == vv1(k-1))
candlist = [candlist vv1(k)];
else % vv1(k) < vv1(k-1)
if ~isempty(candlist)
maxima = [maxima vv1(k-1)];
maximaIdx = [maximaIdx k-1];
candlist = [];
end
end
end
This (hopefully) saves the last index of flat peaks, as well as the sharp
peaks. To save the middle index of a flat peak, you'd do something like
maximaIdx = [maximaIdx ceil(k-1-length(candlist)/2)]. Note again this won't
save a peak that includes the last index. To do that, in the if and elseif
section you check if k == length(vv1), and do the maxima and maximaIdx lines
except on index k instead of k-1.
To extend this to find minima as well, I believe you'd have to keep track of
two separate candidate lists, but it's the same method, you just flip the
less than/greater than signs (you could even use the same loop).
--
View this message in context:
http://octave.1599824.n4.nabble.com/Re-Reading-mat-file-tp4487833p4516404.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Re: Reading mat file, (continued)
- Re: Reading mat file, Doug Stewart, 2012/03/21
- Re: Reading mat file, ahowe42, 2012/03/21
- Re: Reading mat file, Jordi Gutiérrez Hermoso, 2012/03/21
- findpeak, asha g, 2012/03/28
- findpeak, asha g, 2012/03/28
- Re: findpeak, Luke M, 2012/03/28
- Re: findpeak, asha g, 2012/03/29
- Re: findpeak,
Luke M <=
- Re: findpeak -> peakdet.m ?, Olivier Crouzet, 2012/03/29
- Message not available
- Re: findpeak -> peakdet.m ?, Olivier Crouzet, 2012/03/30
- Re: findpeak -> peakdet.m ?, asha g, 2012/03/31
- Message not available
- Re: findpeak -> peakdet.m ?, asha g, 2012/03/29
- Re: Reading mat file, asha g, 2012/03/21
- Re: Reading mat file, Mech.Mon, 2012/03/22
- Re: Reading mat file, Luke M, 2012/03/29
- Re: Reading mat file, asha g, 2012/03/30
- Re: Reading mat file, Luke M, 2012/03/31
- Re: Reading mat file, Doug Stewart, 2012/03/21