Re: [R] estimate phase shift between two signals

From: David Stoffer <dsstoffer_at_gmail.com>
Date: Thu, 05 Jun 2008 18:40:03 -0700 (PDT)

help(spec.pgram) - then look at the examples at the bottom of the page

Dylan Beaudette-3 wrote:
>
> 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.
>
>



The power of accurate observation is commonly called cynicism by those who have not got it. George Bernard Shaw
-- 
View this message in context: http://www.nabble.com/estimate-phase-shift-between-two-signals-tp17653636p17682957.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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 Fri 06 Jun 2008 - 02:16:27 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 Fri 06 Jun 2008 - 02:30:41 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