# What is the actual coherence value between two simple signals, one a cosine and the other a sine?

Suppose $$f=300$$ and I sample from $$x=\cos(2\pi f t)$$ and $$y=\sin(2\pi f t)$$ for a period of one second with sampling frequency $$f_s=1000$$. Then the number of samples is $$N=1000$$ and the DFT's for $$x$$ and $$y$$, in this particular example, are given by $$X_f=\frac{N}{2}\left(\delta(f-300)+\delta(f-700)\right)$$ and $$Y_f=\frac{1}{i}X_f$$. I'm assuming here that $$f$$ is a frequency taking the form $$m f_s/N$$ for some integer $$m$$ and thus corresponds to bin $$m$$. (Apologies for the nonstandard notation.)

Different means show the magnitude-squared coherence between $$x$$ and $$y$$ equals one at $$f=300$$. One way is to use the usual definition of ratio of magnitude cross-spectral density divided to the product of power spectral densities, along with the formulas above. A plot using matplotlib's cohere yields the same result (although it shows the coherence is one at all other frequencies, where it should be undefined.)

However, at $$f=300$$, we can't obtain $$x$$ from $$y$$ via a linear transformation (in the superposition sense). The plot of $$x$$ versus $$y$$ is merely a circle. This suggests to me that the coherence is zero at $$f=300$$. The signals merely differ by a horizontal shift along the time axis.

I think the heart of the issue might be whether "linear relationship" between signals is in the sense of linear transformation or affine transformation. I'd appreciate some clarity on this matter.

... what is the actual coherence value?

It's 1.

$$Y_f=X_f\cdot e^{- i\pi /2} = -i \cdot X_f$$. (Is that correct?)

No. You are mixing discrete and continuous notation. Secondly, the value at the negative frequencies is the conjugate of the value at positive frequencies. A better way to write this would be

$$Y[k]=\frac{N}{2}\left(-i\cdot \delta[k-k_{300}]+i\cdot \delta[k-k_{700}]\right), k \in \mathbb{Z}$$

where $$\delta[k]$$ is the discrete unit impulse response and $$k_f$$ the index of the bin index that corresponds to the frequency $$f$$. This would be given as

$$k_f = \frac{f\cdot N}{f_s}$$

where $$N$$ is the FFT length and $$f_s$$ the sample rate. In your case $$k_{300} = 300$$ but that's only because you chose the FFT length and the sample rate to be the same.

The Coherence is the ratio of the cross spectrum energy divided by product of the signal spectrum energies. We can write this.

$$C[k] = \frac{|X[k]\cdot Y^*[k]|^2}{|X[k]|^2\cdot |Y[k]|^2 +\epsilon}$$

where $$^*$$ is the conjugate complex operator and $$\epsilon$$ a sufficiently small number to avoid "divide by zero" issues that we will otherwise ignore (Ask a separate question if you want to know what this is about).

Since both $$X[k]$$ and $$Y[k]$$ are only non-zero at $$k = 300$$ and $$k = 700$$, so is the coherence. At these frequencies all magnitudes are the same to the ratio simple becomes 1.

$$C[k]= \delta[k-k_{300}]+ \delta[k-k_{700}]$$

• I have edited my question substantially to clarify my intended notation. If the edits are too much, let me know if I should post a new question. I'm aware of the "division by zero" issue and actually posted a question about it quite some time ago. (Can't locate the post though). Your including $\epsilon$ in the denominator gives me a better sense of the issue is addressed. Thanks. Jan 12, 2023 at 16:48
• I see now the error in my thinking, with regard to the negative frequencies, as you pointed, "Secondly, the value at the negative frequencies is the conjugate of the value at positive frequencies." Thanks Jan 14, 2023 at 14:49