In the example below, I am plotting the coherence between time series and itself. The time series do has one frequency.The coherence magnitude was one for all frequencies. I wonder why it is not zero at all frequencies except at the time series frequency. I found that if I include random variable, I get zero coherence at most frequencies except the time series and its surrounding frequencies. Here is my questions:

  1. Why the coherence is unit for all frequencies however the time series have only single frequency.
  2. Why I got more realistic (coherence values at the time series frequency, and zero else where) values when I add noise to the time series.
  3. Why the coherence (with the noise added case) show more unity for more that one frequency. It looks like that the coherence have unit at the time series frequency and the surrounding frequencies.

enter image description here enter image description here

import matplotlib.pyplot as plt
from scipy import signal



for t in np.arange(nt):



#f,coh = signal.coherence(xp_pre,yp_pre,window=signal.get_window('hanning',200),noverlap=100)
f,coh = signal.coherence(xp_pre,yp_pre)



According to the documentation, the coherence between two signals $x(t)$ and $y(t)$ is defined as $C_{xy}(w) = \frac{|P_{xy}(w)|^2}{P_x(w) P_y(w)}$, where $P_x(w)$ and $P_y(w)$ are power spectral density estimates of $x$ and $y$ and $P_{xy}(w)$ is an estimate of the cross-spectral density.

  • In your first experiment, you put in two identical signals $x(t) = y(t) = \cos(2\pi w_1 t)$. Since $x(t)=y(t)$, what you should expect is that $P_x (w)= P_y(w) = P_{xy}(w)$ for all $w$. Therefore, $C_{xy} = \frac{|P_{xy}(w)|^2}{P_x(w) P_y(w)}= 1$ for all $w$.
  • You might want to argue that the signal(s) only contains a single frequency. In this case we would expect that $P_x(w) =P_y(w) = P_{xy}(w) =0$ for $w \neq w_1$. However:
    • This would mean that $C_{xy}(w) = \frac{0}{0} = $undefined for $w\neq w_1$.
    • This wouldn't happen numerically, as due to rounding errors you'd have some epsilons left that could still make this fraction equal to one
    • You're not dividing power densities but (Welch) estimates of the power densities of a finite window of the signal, hence $P(w)$ will not be exactly zero anywhere. It will contain estimation artifacts and the truncation effects. Since $x(t)$ and $y(t)$ are exactly equal, the artifacts are exactly equal and the coherence is one.
  • When you add noise to $x(t)$ and $y(t)$ in your second experiment you're adding "signal content" to the frequencies outside $w=w_1$. Since the noise contributions are drawn independently, they are uncorrelated which means that $P_{xy}(w)$ will indeed be zero there, while $P_x(w)$ as well as $P_y(w)$ will not be. Hence the coherence does go to zero.
| improve this answer | |
  • $\begingroup$ Thanks a lot for your helpful answer. Any idea why after I add the noise, I get coherence for frequencies around the signal frequency as show in the second figure. $\endgroup$ – Kernel Sep 10 '19 at 16:06
  • $\begingroup$ @Ahmed: That's due to the fact that your power estimate is not perfect. You've only considered a finite window, so the power does leak from $w_1$ to its neighborhood as a result of the effect of the window function. Let's also not forget that the function uses the Welch method to estimate the spectrum, which divides the signal into even smaller windows. This could pronounce the windowing effect further. $\endgroup$ – Florian Sep 10 '19 at 16:10
  • $\begingroup$ Thanks, any ideas how to get sharper coherence? do you think that trying different windows might be helpful. $\endgroup$ – Kernel Sep 10 '19 at 16:19
  • $\begingroup$ @Ahmed: Sure, you can control the way the function does the Welch estimate. In particular, the parameters nperseg and noverlap can be used to control the window size. Try increasing nperseg a bit, that should give wider windows and thus sharper peaks. As for the windowing functions: the rectangular window gives the sharpest peaks possible (at the price of higher sidelobes). $\endgroup$ – Florian Sep 11 '19 at 8:18
  • $\begingroup$ Thanks for the spectrum coherence recipes (wider + rectangular window). $\endgroup$ – Kernel Sep 11 '19 at 17:21

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.