# In what way does the cross-spectral density of two signals describe their similarities?

I’m trying to gain a deeper understanding of what the cross-spectral density of two signals represents. I know how to compute it, and I know it represents a covariance of sorts, as it appears in the formula for coherence. It’s the nature of the “similarity” that I’m unclear about.

As an example, I'm sampling from two continuous signals at a rate of $$f_s=100$$ Hz for a period of one second.

t  = np.arange(0, 1, 0.01);
N = len(t)
dt = t[1] - t[0]
fs=1/dt

f0=3
f1=5
x=np.cos(2*np.pi*f0*t)+np.cos(2*np.pi*f1*t)

phase_shift=.7*dt
phase_shift_noisy=phase_shift+np.random.uniform(low=-.055, high=.055, size=(N,))
y=np.cos(2*np.pi*f0*(t-phase_shift))+np.cos(2*np.pi*f1*(t-phase_shift_noisy))


So the phase difference between $$x$$ and $$y$$ at the frequency 3 Hz is constant, whereas the phase difference at 5 Hz is not constant due to the added noise. The plot of the signals looks as follows:

The plot of the cross-correlation of the signals:

The plot of $$|P_{xy}|$$ from 0 to 50 Hz, where $$P_{xy}$$ denotes the cross-spectral density:

I obtained the same plot two ways: By computing the DFT of the cross-correlation and by computing the product $$|X_f \overline{Y}_f |$$, where $$X_f$$ and $$Y_f$$ denote the DFT of $$x$$ and $$y$$, respectively.

The graph of $$|P_{xy}|$$ has spikes at 3 Hz and 5 Hz, as I would expect. However, the height at 5 Hz is smaller, which I attribute to the fact the phase difference at that frequency is not constant.

Question 1: In general, does the magnitude of $$P_{xy}$$ at a frequency describe how close the lag between the two signals at that frequency is to being constant? If so, am I correct that the coherence between $$x$$ and $$y$$ at 3 Hz is one, whereas the coherence at 5 Hz is less than one? (Since coherence is obtained by dividing $$|P_{xy}|^2$$ by the product $$P_{xx}P_{yy}$$?)

Question 2: Given that $$P_{xy}$$ at a frequency is complex, what does its argument tell me?

• +1 for a great question!
– Jdip
Dec 9, 2022 at 16:34

Answer to Question 1: No it does not describe the lag as that is a time domain quantity. The lag is given by the cross-correlation (which has a time domain horizontal axis). You are however correct that the coherence between x and y will have a magnitude of one for this specific case where the 3 Hz is identical in both waveforms (and would be even if they were scaled or time shifted) and less than one for 5 Hz. It is less than one for 5 Hz as the added noise has phase modulated the 5 Hz tone, so in doing that some of the power at 5 Hz specifically has been spread away to adjacent frequencies.

Answer to Question 2: The lag at any given frequency is a phase shift for that frequency and thus would be the resulting argument for that frequency sample in the Cross Power Spectral Density result. For example, if we added 45 degrees to the 3 Hz signal (as a constant phase offset as coded below), the resulting CSD would have an argument of $$\pi/4$$ at 3 Hz instead of $$0$$ as it does currently.

x=np.cos(2*np.pi*f0*t + np.pi/4) + np.cos(2*np.pi*f1*t)