2
$\begingroup$

I don't really know anything about signal processing. I need to find similairty between two 1-dimensional time series. I read somewhere that spectral coherence could be used to find similarity between two time series. But i am not able to get around how to use it. Can some one tell how i can use it to compute similarity between time series.

$\endgroup$
  • $\begingroup$ did you ever get this issue resolved because I have the same problem and I would like to source C code for this analysis? $\endgroup$ – user18552 Dec 1 '15 at 21:54
  • $\begingroup$ @Ben : I will try to answer this question shortly, perhaps you can add a comment here (or edit your deleted "answer") about what your requirements are? $\endgroup$ – Peter K. Dec 1 '15 at 22:09
  • $\begingroup$ @Ben Try that answer. $\endgroup$ – Peter K. Dec 1 '15 at 22:48
2
$\begingroup$

One way to check for similarity between time series is to use the cross-correlation: $$ \rho_{xy}(\tau) = \frac{1}{\sigma_x \sigma_y} E[ (x[n] - \mu_x)(y[n] - \mu_y) ] $$ where $\mu_{x,y}$ is the mean of $x$ or $y$ and $\sigma_{x,y}$ is the standard deviation of $x$ or $y$.

This gives us a value between -1 (completely anti-correlated) and +1 (completely correlated).

Sometimes, this doesn't work as well as we'd like because there is some filtering operation relating the two time series, so while there is a strong relationship between the two time series, the cross-correlation is not very close to 1.

As a result, the spectral coherence is sometimes used: $$ C_{xy}(f) = \frac{|G_{xy}(f)|^2}{G_{xx}(f)G_{yy}(f)} $$ where $G_{km}$ is the cross-spectral density between $k$ and $m$.

This is now a function of frequency, and the closer it is to 1 at a given frequency, the closer the two signals are related.

I've put together a simple example in R which illustrates the difference between cross-correlation and (spectral) coherence.

The top graph shows the two time series. The middle graph shows the cross-correlation is less than 1. The bottom graph shows the spectral coherence as a function of frequency.

enter image description here

You can see that the time series are not as similar in the higher frequencies as they are at low frequency.

Sometimes, the integral of these values is used over a limited bandwidth so that a single figure of similarity is arrived at.


R Code Below

  #15466

  x1 <- rnorm(1000)

  h <- c(1,3,2,1)/7
  x2 <- filter(x1,h, circular=TRUE) + rnorm(1000)/10

  par(mfrow=c(3,1))

  plot(x1,type="l",col="blue")
  lines(x2, col="green",lwd=5)
  title("Original and filtered noise signals")

  ccf(x1,x2)

  Ixy <- spectrum(cbind(x1,x2), plot=FALSE,spans=c(5,7))

  plot(Ixy$coh)h)
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.