comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » A better way to find a dip (local minimum with certain conditions)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: A better way to find a dip (local minimum with certain conditions) [message #69211 is a reply to message #69046] Thu, 17 December 2009 14:57 Go to previous message
James[2] is currently offline  James[2]
Messages: 44
Registered: November 2009
Member
what about:

FUNCTION finddip, array, min, range

; find the derivative
deriv = array - SHIFT(array, -1)

; reduce the derivative to negative and positive
pos = deriv gt 0
neg = deriv lt 0

; create convolution kernels for the elements before and after
beforekern = [replicate(1,range),intarr(range-1)]
afterkern = [intarr(range+1),replicate(1,range)]

; find places where the leading derivatives are non-positive
; and the trailing derivatives are non-negative
dip = logical_and(convol(pos, beforekern) eq 0, convol(neg, afterkern)
eq 0)

; find where the value exceeds the threshold
thresh = array gt min

; put it all together
localmin = logical_and(dip, thresh)

return, localmin

end


does what you want, it might be a little heavy on the memory but it
doesn't use any loops.
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Catalyst Object Widget Hierarchy
Next Topic: smooth function and rounding error

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 03:58:04 PDT 2025

Total time taken to generate the page: 0.96102 seconds