2
$\begingroup$

I'm sampling from the functions $x(t)=\cos(2\pi f_0t)$ and $y(t)=\cos(2\pi f_0t^{1.005})$, for one second, where $f_0=300$ and my sampling rate is $f_s=1000$. ($N=1000$).

A plot of the coherence between the signal samples, $x$ and $y$ is shown below, which indicates a maximum coherence of 0.74 bin $m=299$, which is what I would expect.

enter image description here

My signal samples for $x$ can be viewed as a vector, $\vec{x}$ in $\mathbb{R}^{1000}$ and can be expressed as a linear combination of the columns of the Fourier matrix $W=\begin{bmatrix} \vec{w}_0 & \vec{w}_1 & \vec{w}_2 & \cdots & \vec{w}_{N-1} \end{bmatrix}$, whose columns are pairwise orthogonal and have squared-norms equal to $N$:

\begin{equation*} \vec{x}=\overline{\frac{\vec{x} \bullet \vec{w}_0}{N} }\cdot \vec{w}_0+ \overline{\frac{\vec{x} \bullet \vec{w}_1}{N} }\cdot \vec{w}_1+ \cdots+ \overline{\frac{\vec{x} \bullet \vec{w}_{N-1}}{N}} \cdot \vec{w}_{N-1}. \end{equation*}

A similar formula exists for the signal samples for $y$. In linear algebra language, I have interpreted the coherence between $x$ and $y$ at bin $m$ to represent the degree to which there exists a linear relationship between the orthogonal projections $\displaystyle \overline{\frac{\vec{x} \bullet \vec{w}_m}{N} }\cdot \vec{w}_m$ and $\displaystyle \overline{\frac{\vec{y} \bullet \vec{w}_m}{N} }\cdot \vec{w}_m$. In this case, when I calculated the ratios of corresponding pairs of complex numbers in these projection vectors, they are constant, as demonstrated below, which is not what I would expect since the coherence is significantly less than one. I'm seeking guidance regarding where my misconception lies. (I'm trying to think of coherence not in terms of ratios of power spectral densities but in terms of linear algebra, ideas which are accessible to my undergraduate students.)

dt = .001
t = np.arange(0, 1, dt)
N=len(t)
fs=int(1/dt)

x=np.cos(2 * np.pi * f0 * t)
y=np.cos(2 * np.pi * f0 * t**(1.005))

def DFT_matrix(N):
    i, j = np.meshgrid(np.arange(N), np.arange(N))
    omega = np.exp( - 2 * np.pi * 1J / N )
    W = np.power( omega, i * j )
    return W

W=DFT_matrix(N)
m=299
w_m=W[:,m]

x_m=np.dot(x,w_m )*w_m/N
y_m=np.dot(y,w_m)*w_m/N
ratios=np.divide(x_m,y_m)
print(ratios[90:100])

[-1.38423982+1.00824419j -1.38423982+1.00824419j -1.38423982+1.00824419j
 -1.38423982+1.00824419j -1.38423982+1.00824419j -1.38423982+1.00824419j
 -1.38423982+1.00824419j -1.38423982+1.00824419j -1.38423982+1.00824419j
 -1.38423982+1.00824419j]
$\endgroup$
2
  • $\begingroup$ How did you calculate the coherence, can you share the code? $\endgroup$
    – learner
    Feb 6, 2023 at 18:15
  • $\begingroup$ I used f,Coh_xy=coherence(x,y,fs=fs,nfft=len(x)), where coherence was imported from scipy.signal. Perhaps my misunderstanding centers on how I'm thinking of coherence in the first place? $\endgroup$
    – fishbacp
    Feb 6, 2023 at 20:49

0

Your Answer

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

Browse other questions tagged or ask your own question.