help-octave
[Top][All Lists]
Advanced

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

Re: findpeak


From: Luke M
Subject: Re: findpeak
Date: Wed, 28 Mar 2012 10:37:59 -0700 (PDT)

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.

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Re-Reading-mat-file-tp4487833p4513068.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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