I am exploring the cross correlation function in Julia between two complex-valued Time Series Objects Z1 and Z2 with this simple code:

using DSP

Compute the cross-correlation between the real components

rX = xcorr(X1, X2)

Compute the cross-correlation between the imaginary components

rY = xcorr(Y1, Y2)

Compute the cross-correlation between the two complex valued time series objects

rZ = xcorr(Z1, Z2)

Plot the cross-correlation

p1 = plot(rZ, color = "powderblue", title="rZ",titlefontsize=10, xtickfontsize=7, ytickfontsize=7)

p2 = plot(rX, color = "powderblue", title="rX",titlefontsize=10, xtickfontsize=5, ytickfontsize=7)

p3 = plot(rY, color = "powderblue", title="rY",titlefontsize=10, xtickfontsize=5, ytickfontsize=7)

plot(p1,p2,p3, layout = (1,3), size = (900, 250), primary=false,)

What does it mean when the shape of the cross correlation curve is closed?

enter image description here

  • 1
    $\begingroup$ plot(rZ) mean plot(real(rZ), imag(rZ)) $\endgroup$ Commented Jan 27, 2023 at 9:11

1 Answer 1


I'm not sure what your input signals look like, so hard to say much. It looks like your rZ curve has a lot of points around (0,0).

When doing a cross-correlation on a finite signal, the vector are zero-padded to make the output of length length(X) + length(Y) - 1. So it makes sense that the start and end of your output signal is also close to 0, as you're multiplying your first signal by mostly zeros. (As can be seen in your rX and rY plots).

When plotting real(rZ),imag(rZ) you would then get a closed curve, as the curve starts and ends around (0,0).

If your signals are for example audio-recordings will little delay between the two (for a real-life example), then the cross-correlation will peak when the two channels match in time (so around the middle of your output, from your graph it looks like around 1250/2 which is about where the peaks are), and will tend to zero as the offset between the two signal increases. Again, the output will be close to zero as you move away from the zero-lag condition (when there is no offset between the two vectors).

details from Julia DSP.xcorr:

xcorr(u,v; padmode = :none)

Compute the cross-correlation of two vectors, by calculating the similarity between u and v with various offsets of v. Delaying u relative to v will shift the result to the right.

The size of the output depends on the padmode keyword argument: with padmode = :none the length of the result will be length(u) + length(v) - 1, as with conv. With padmode = :longest the shorter of the arguments will be padded so they are equal length. This gives a result with length 2*max(length(u), length(v))-1, with the zero-lag condition at the center.


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.