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

Re: Avoiding a for cicle




"J.D. Smith" <jdsmith@astro.cornell.edu> writes:
> > This one does exactly what was requested, which I'm not sure of about
> > your solution, J.D.  On the other hand, your solution may be more
> > physically meaningful since it involves smoothing.
> > 
> 
> Nice entry Craig.  But unfortunatly it doesn't *alway* do exactly
> what was requested.  It works fine for n=5, but for n>5 (7,9,...),
> the index is off.  Part of the reason is in the way convol works.
> For n=5, nh=2, and convol subscripts are left of center (t+i-1 for
> i=0,1).  For n=7, nh=3, and convol subscripts are (t+i-1 for
> i=0,1,2), which is centered.  For n=9, nh=4, and you again have
> (t+i-2 for i=0,1,2,3), left of center again... and so on.  The
> additional complication is that you are finding the center of the
> *wrapped* up-going and down-going entries... the center of the peak
> is offset from this by (nh+1)/2 (which happens to equal 1 when n=5
> or n=3).  Adding this rather than 1 to the returned indices would
> make it correct.  Here's an example for n=9 (^=up-goin,
> v=down-going):
> ...

Arghh.  I stand corrected.  This turns out to be the kind of "feature"
in CONVOL which we can turn off, by setting the keyword CENTER=0.  I
actually read the documentation for the function, intended to put
CENTER=0 in, but forgot.  I think now it works as advertised.

dd = d(1:*)-d
nh = (n-1)/2
wh = where(convol((dd GT 0) AND (dd(nh:*) LT 0), bytarr(nh)+1, nh, center=0) $
           EQ 1, count) + 1

> Now I'll explain my solution, which does indeed produce indentical
> results ...

I must admit your entry was the cruftier.  Nice explanation.

Here is the algorithm I used to make my random spiky_data.sav.  You
will find a 13-peak about every 4000 data points with this.

m = 1024L
d = randomn(seed,m)
for i = 1L, m-1 do d(i) = d(i-1)+d(i)

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------