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]


phase_shift_noisy=phase_shift+np.random.uniform(low=-.055, high=.055, size=(N,))

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:

enter image description here

The plot of the cross-correlation of the signals:

enter image description here

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

enter image description here

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?

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

1 Answer 1


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) 

Further Comments on CSD:

The Cross Spectral Density shows the linear relationship in the frequency domain between two waveforms at each specific frequency given. In the OP's case the 3 Hz signal is completely related; in the time domain for every sample the 3 Hz component is the same in both waveforms. This would be the case even if the waveform was scaled or time shifted (by a constant amount over the duration of the waveform); the normalized result (coherence) would have a magnitude of one, and the argument would be the relative phase between the two.

One application for the CSD is to determine the frequency response of noisy systems when the noise at the output of the system is not related to (independent of) the noise at the input and in addition we have a correlated signal applied to the input that fills the spectrum of interest (such as a frequency chirp or a pseudo-random sequence). The CSD between the input and output of such a system (and specifically when normalized as coherence) would tell us for each frequency the relative magnitude and phase for the system transfer function while attenuating the noise components (which would not be the case if we simply used a ratio of the power spectral densities).

In general, when we want to know how much of one signal is linearly related to another in the frequency domain (in terms of relative magnitude and phase for each frequency component), that would be a good application for using the CSD.

  • 1
    $\begingroup$ I would just add to those last two paragraphs that transfer functions can be estimated using CSD and PSDs. Different estimates can indeed be used depending on noise assumptions made on the input, output, or both. tfestimate is a Matlab function based on this framework for example. How well the estimate matches the true transfer function is directly related to the coherence of course. $\endgroup$
    – Jdip
    Dec 10, 2022 at 6:44
  • 1
    $\begingroup$ @Dan Boschen : Thanks for such insightful help! $\endgroup$
    – fishbacp
    Dec 10, 2022 at 19:46
  • $\begingroup$ Suppose I sample from x=cos(2pi*3*f(t)) and y=cos(2pi*3*g(t)), where f and g are functions of t. Is the coherence at f0=3 related to the linear regression coefficient obtained by plotting the ordered pairs (f(t_k),g(t_k)) using my discrete times, t_k? $\endgroup$
    – fishbacp
    Dec 11, 2022 at 14:36
  • 1
    $\begingroup$ @fishbacp Please post this as another question where you can add details plots etc to support what you are asking… we’re discouraged from having a longer discussion in the comments other than clarifying the question and answer on this forum $\endgroup$ Dec 11, 2022 at 20:15

Your Answer

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

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