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

Re: Avoiding a for cicle




davidf@dfanning.com (David Fanning) writes:
> Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:
> 
> > dd = d(1:*)-d
> > nh = (n-1)/2
> > wh = where(convol((dd GT 0) AND (dd(nh:*) LT 0), bytarr(nh)+1, nh) EQ 1, ct)+1
> > 
> > For the goobledy-gook impaired (aka DF :-),
> >   dd is the first difference of the data 
> >   nh is the half-width of the peak
> >   (dd GT 0) AND (dd(nh:*) LT 0) locates up-going followed by down-going points
> >   convol(...) locates runs of length nh
> > 
> > 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.
> 
> Alright, now that Craig has oriented me a little bit,
> I find that I, uh..., have a *need* for this sort of thing. :-)
> 
> I presume you gentlemen are testing these little theories of yours
> on a test data set. Could you supply such a data set for the
> rest of us to fool around with? And if you gave us just a little
> hint about how such a thing might be useful to *you*, that might
> help too. I might even take a stab at writing an article about
> it all, especially if I feel like it has been a day or two since
> I really embarrassed myself. 

Okay, try this:

ftp://cow.physics.wisc.edu/pub/craigm/spiky_data.sav

It's the cumulative sum of normally distributed random deviates, so it
has lots of peaks and valleys to practice on.

Personally, I was responding to the challenge that J.D. put forth.
I've never used this snippet "for real."  I just did it today.  I said
that smoothing might be more appropriate for real life situations
because real-life data often has noise.  My algorithm does not really
tolerate noise.

Peak finding has obvious uses.  Need I say more?  I personally don't
do too much of it.  I do have time series with peaks, but I know where
to expect the peaks so I can just fit an amplitude.

For a noisy signal with many potential (but unknown) peaks I would
probably perform a cross correlation between the signal and a
template, and then threshold.  This prevents a single noisy point from
ruining an otherwise nice peak.

For a noisy signal with a single peak, an algorithm such as IDL's
GAUSSFIT(), or my own MPFITPEAK() might be worthwhile.  Those two
algorithms are different; I assert mine is better :-)

Craig

MPFITPEAK is found at
http://cow.physics.wisc.edu/~craigm/idl/idl.html

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