help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: findpeak


From: asha g
Subject: Re: findpeak
Date: Thu, 29 Mar 2012 14:34:03 +0800 (SGT)


asha g wrote
>
> Sorry, I can't get this to work but is there something in octave similar
> to Matlab's
> pks = findpeaks(data)
> [pks,locs]
> = findpeaks(data) returns the
> indices of the local peaks.
>
> If I can get this, then my problem is solved.
> Thanks
> Asha
>

One simple solution (O(n), in algorithm design terms):
- place the first element in a "candidate vector"
- loop through each element 2 through end, comparing it to the previous one
---if it's higher, set the candidate vector to the current element
---if it's equal, append the current element to the candidate vector
---if it's lower,
-----if the candidate vector is not empty, save the local maxima and idx
from the candidate vector and empty the candidate vector

Problems you would have to solve:
- Which index do you want to save in the case of a flat peak (length of
candidate vector > 1)?
- How do you want to handle possible local maxima at the beginning and end
(e.g. [2 1 2 3 2 1 2]?  The algorithm above will find a local maximum in the
first element, but not in the last element.  Whether you want to ignore both
or save both is an easy fix.

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
   
        
    disp (maxima)
    disp(minima)
                disp (tx )
        disp(txmin)








reply via email to

[Prev in Thread] Current Thread [Next in Thread]