[R] estimate phase shift between two signals

From: Dylan Beaudette <dylan.beaudette_at_gmail.com>
Date: Wed, 04 Jun 2008 10:38:47 -0700


Hi,

Are there any functions in R that could be used to estimate the phase-shift between two semi-sinusoidal vectors? Here is what I have tried so far, using the spectrum() function -- possibly incorrectly:

# generate some fake data, normalized to unit circle
x <- jitter(seq(-2*pi, 2*pi, by=0.1), amount=pi/8)

# functions defining two out-of-phase phenomena
f1 <- function(x) jitter(sin(x), amount=0.25) f2 <- function(x, a) jitter(sin(x + a), amount=0.25)

# compute y-values
# we are setting the phase shift arbitrarily
s <- pi/1.5632198
y1 <- f1(x)
y2 <- f2(x, s)

# plot:

plot(x, y1, type='p', col='red', cex=0.5) lines(lowess(x, y1, f=0.25), col='red')

points(x, y2, col='blue', cex=0.5)
lines(lowess(x, y2, f=0.25), col='blue')

# generate time series object

comb.ts <- ts(matrix(c(y1, y2), ncol=2))

# multivariate spectral decomposition

spec <- spectrum(comb.ts, detrend=FALSE)

# but how to interpret the phase estimate?
mean(spec$phase)

the mean 'phase' as returned from spectrum() does not seem to match the value used to generate the data... Am I mis-interpreting the use or output from spectrum() here? If so, is there a general procedure for estimating a phase-shift between two noisy signals? Would I first have to fit a smooth function in order to solve this analytically?

Thanks in advance,

-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 04 Jun 2008 - 18:48:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 04 Jun 2008 - 20:31:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive