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.

  • $\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, 2015 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, 2015 at 22:09
  • $\begingroup$ @Ben Try that answer. $\endgroup$
    – Peter K.
    Dec 1, 2015 at 22:48

1 Answer 1


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


  x1 <- rnorm(1000)

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


  lines(x2, col="green",lwd=5)
  title("Original and filtered noise signals")


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

  • $\begingroup$ Hi Peter, would you be so kind to expand on the explanation "the integral of these values is used over a limited bandwidth"? Do you mean for instance in your last graph averaging the MSC values between 0 and 200 Hz? Thank you $\endgroup$
    – VMMF
    Sep 1 at 18:18
  • $\begingroup$ @VMMF Yes: If there's a known bandwidth of interest, just sum / integrate over that range to get a single number or figure of merit. $\endgroup$
    – Peter K.
    Sep 1 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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