[R] reg peak detection

tom wright tom at maladmin.com
Fri Dec 9 14:20:21 CET 2005


Having missed last months thread I reinvented the wheel. I thought I'd
post my code here for fun and feedback.

getDerivation<-function(v_dataset){
    #setup a vector to hold derivations
    v_deriv<-vector(length=length(v_dataset)-1)

    for(iLoc in 2:length(v_dataset)){
        v_deriv[iLoc-1]<-v_dataset[iLoc]-v_dataset[iLoc-1]
    }
    return(v_deriv)
}
getPeaks<-function(v_deriv){
    v_deriv<-sign(as.numeric(v_deriv))
    v_temp<-vector(length=length(v_deriv)-1)

    for(iLoc in 1:length(v_deriv)-1){
        v_temp[iLoc]<-v_deriv[iLoc]+v_deriv[iLoc+1]
    }
    v_peaks<-which(abs(v_temp)<=1)+1
    return(v_peaks)
}

set.seed(2)
x <- round(rnorm(1000000), 2)
y <- cumsum(x)

system.time(deriv<-getDerivation(y))
[1] 9.61 0.03 9.90 0.00 0.00
system.time(peaks<-getPeaks(deriv))
[1] 8.76 0.12 9.11 0.00 0.00

(Times shown are on an AMD64 3400+)

Regards
Tom

**An hour in the library is worth 8 in the lab**

On Thu, 2005-08-12 at 14:25 -0800, Jim Porzak wrote:
> Ram,
> See excelent thread here last month.
> Search for "finding peaks"
> 
> On 12/8/05, SHRIRAM R SAMPAT <shriramrs31 at yahoo.co.in> wrote:
> >
> > Hallo everybody,
> >
> > I am doing a thesis in video extensometry and one my
> > approaches requires peak detection in a two
> > dimensional data.
> >
> > If would be grateful if anyone can throw some light on
> > this for me by giving me some hints on how to do it or
> > give me some links for it.
> >
> > thank very much in advance.
> >
> > Ram
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> 
> 
> 
> --
> HTH,
> Jim Porzak
> Loyalty Matrix Inc.
> San Francisco, CA
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list