I have a signal in which I want to identify peaks, in R or Python (using numpy or scipy), preferentially using array expressions instead of loops.
I have a pair of thresholds that define the levels a peak has to exceed in order to be a peak, so I can easily obtain all samples that are part of a peak with an expression like
However, I'd like to identify to first and last samples of each peak ... and I don't really see how to achieve that easily when there is more than 1 peak in my signal.
Something like
should do the trick, but I haven't yet found primitives to do the shifting.
Is there an efficient call or set of calls that allows to do this without resorting to looping over my signal? Is there a signal length/size above (or under...) which it is more efficient to write a bit of C-code containing the necessary loops?
And while I'm at it, how about more elaborate peak identification, where one tries to find the 'real' start and end of a peak found by the threshold crossing, for instance the preceding or subsequent zero-crossing?
Thanks in advance,
René
I have a pair of thresholds that define the levels a peak has to exceed in order to be a peak, so I can easily obtain all samples that are part of a peak with an expression like
Code:
peaksamples = sig[ (sig > Hthres) | (sig < Lthres) ]
However, I'd like to identify to first and last samples of each peak ... and I don't really see how to achieve that easily when there is more than 1 peak in my signal.
Something like
Code:
peakStarts = sig[ ((sig > Hthres) & (Shift1Left(sig) <= Hthres)) | ((sig < Lthres) & (Shift1Right(sig) >= Lthres)) ]
peakStops = sig[ ((sig <= Hthres) & (Shift1Left(sig) > Hthres)) | ((sig >= Lthres) & (Shift1Right(sig) < Lthres)) ]
should do the trick, but I haven't yet found primitives to do the shifting.
Is there an efficient call or set of calls that allows to do this without resorting to looping over my signal? Is there a signal length/size above (or under...) which it is more efficient to write a bit of C-code containing the necessary loops?
And while I'm at it, how about more elaborate peak identification, where one tries to find the 'real' start and end of a peak found by the threshold crossing, for instance the preceding or subsequent zero-crossing?
Thanks in advance,
René