I had two vectors of data and I computed their correlation using corr(f,g) = ifft( fft(f) .* conj(fft(g)) ) / cov(f,g). I cannot figure out whether to use the real or absolute of the result.

The two vectors are observation data, not signals. From their individual plots, I can see that they are negatively correlated but I want to visualise how the correlation property works (correlation in the time domain to the product in frequency domain).

The value of cov(f,g) is negative. When I take the absolute the entire correlation vector is negative since the numerator is always positive, and if I take real then half of the points in the correlation vector are negative and the other half positive.

Which one should I take, and is the formula I'm using to calculate it correct?

  • $\begingroup$ The method you implement implements circular correlation, not linear correlation. $\endgroup$
    – Hilmar
    Jan 1, 2022 at 14:21
  • $\begingroup$ I am trying to find the time varying correlation of the two vectors. The index of the element represents the sample number. $\endgroup$
    – newToDSP
    Jan 1, 2022 at 15:33

1 Answer 1


You would use the complex result which shows the magnitude and phase of the cross correlation (both are important depending on the use of the result). For example, if this was used to determine carrier phase in a receiver where there is an offset in frequency between the transmitted signal and the first estimate of its carrier in the receiver, then by measuring the change in phase over successive correlations, we can accurately determine the frequency offset (since frequency is the derivative of phase). If we have no concern for the phase difference and only want to measure similarity independent of phase offsets, then the magnitude of the correlation result would be the one to choose (otherwise if the phase offset was 90°, we would get a minimum correlation even if the waveforms were identical other than that phase offset).

I recommend reviewing both the magnitude and phase of the correlation to understand its properties and how to use it. For the case where the signals are negatively correlated, the phase will be 180 degrees.

  • $\begingroup$ I am simply trying to find the correlation of the two vectors. I get the entire correlation as positive when using abs() even though it is obvious from the data that they are negatively correlated. $\endgroup$
    – newToDSP
    Jan 1, 2022 at 14:53
  • $\begingroup$ If you take abs of anything it will be positive by definition. As I explained the cross-correlation is a complex quantity so it will have magnitude and phase. To review any complex number you need two real numbers: one representing the magnitude (given by abs()) and one representing the phase (given by angle()). Alternatively you can use two real numbers as one representing the real component and the other representing the imaginary component as I and Q in I+jQ. So if you want to know the correlation then you need to look at both the real and imaginary components, or the magnitude and phase. $\endgroup$ Jan 1, 2022 at 15:25

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.