https://github.com/cran/season
Raw File
Tip revision: 2c210d12a3968c93e922ec61ba016704a7f9668e authored by Adrian Barnett on 03 March 2010, 00:00:00 UTC
version 0.2-4
Tip revision: 2c210d1
phasecalc.R
# phasecalc.R
# calculate phase given cosine and sine estimates
# returns results on scale [0,2pi]
# equivalent to page 31 of Fisher

phasecalc<-function(cosine,sine){
 if(cosine==0){cosine=cosine+0.000000001} # avoid zeros
 div<- sine/cosine
 if (cosine>=0){phaser<-atan(div)}
 if (cosine<0&sine>=0){phaser<-atan(div)+pi}
 if (cosine<0&sine<0){phaser<-atan(div)-pi}
# put in 0 to 2pi range
 if (phaser<0) { phaser<-phaser+(2*pi)} 
 if (phaser>(2*pi)) { phaser<-phaser-(2*pi)}
 return(phaser)
}
back to top