Two CDMA Codes or Gold Codes or PRN Sequencies, i.e. a pattern in time, are cross correlated in the time domain. However one of them is delayed compared to the other.

How is the phase argument of the peak of the cross correlation related to the sample time lag or the location of the peak in the cross correlation result.

For example visually one result of tor in XCorr function:

enter image description here

The XCorr peak is the sum of the conjugate products at one value of tor, if pairs of samples of the waveforms are applied in a conjugate products and if the samples pairs (one from each waveform) are not perfect conjugates of each other then the result is not a real number and its complex which has a phase argument in the image as angle z. So for a given Correlation length, this vector or sum of sample pairs as a conjugate product builds up (visualising the conjugate product vectors adding continually) to the point where the phase of the resultant vector says how mis-aligned these signals are in phase as phase argument z - which I see as indirectly saying how off in time they are from each other.

This is then performed for many overlaps of the variable tor in the Xcorr function. The max value of all tor overlaps is the XCorr peak and its location or index or bin in the result gives the sample delay but its argument also gives phase - which I think is related to sample delay.

I am struggling to find how these are related mathematically - they must be but what’s the vigor here… Especially if that correlation max vector has summed so the phase is more than 2 pi radians.


1 Answer 1


To be sure there is no conflation between "phase" and "delay" in the time domain, I refer to a phase shift in time as:

$$y(t) = x(t)e^{j\theta}$$

Whereas a time shift (delay) is given as:

$$y(t) = x(t-\tau)$$

As detailed below they are related, but not the same. The answer below uses "phase" and "time offset" as represented above, and in the context of GPS C/A codes and PRN codes at complex baseband where correlation would typically be applied (not passband signals).

A phase in the cross-correlation of two CDMA Gold Code sequences or PRN sequences indicates a frequency offset, not a time offset of the baseband signal. If the two sequences are real, with no frequency offset, the autocorrelation function (which is the correlation for each delay between the sequences) will be real.

For small frequency offsets, the phase change of the correlation between a PRN sequence and a frequency shifted copy of itself at 0 delay between the two is approximately given by:

$$\Delta\phi = -2\pi f_o T \tag{1} \label{1}$$

Where $\phi$ is the change in phase in radians,
$f_o$ is the frequency offset in Hz, and
$T$ is the time duration of the correlation in seconds.

Where "small frequency offset" is $f_o << 1/T$ (the correlation magnitude goes to 0 at $f_o=1/T$, and then continues as a Sinc function with frequency offset.)

(Also as a side to note of possible interest, as @vml points out in the comments, this is directly related to the coherence time, as the correlation time duration $T$ gets longer the amount of tolerable frequency offset for the signals to still be correlated gets smaller; for more details on that see this post and it's linked post).

The sign is negative vs frequency offset assuming the correlation is computed according to:

$$\rho = \int_0^T x(t) g^*(t) dt\tag{2} \label{2}$$

With $g(t)$ as the frequency shifted version of $x(t)$ as $g(t)=x(t)e^{j2\pi f_o t}$.

The relationship given in \ref{1} is understood from the correlation formula and the Fourier relationships for frequency and time offsets:

A delay (time offset) in time will be a phase in the frequency domain, given the Fourier relationship:

$$x(t-\tau) \leftrightarrow X(f)e^{j2\pi f \tau}$$

This relationship also explains how the phase is unaffected by the time delay a baseband signal with no carrier frequency offset (when $f=0$), while a static phase would be introduced for the case of a passband signal where $f \ne 0$.

An similarly an offset in frequency will be a phase in the time domain:

$$x(t)e^{j2 \pi f_o t} \leftrightarrow X(f-f_o)$$

Which would then appear in the autocorrelation function as a phase offset between the C/A code and the same C/A code with a frequency offset using the relationship above.

From \ref{2} consider a case when the waveform is correlated to itself with a frequency offset starting from a condition where the phase of the two is zero at $t=0$, the peak correlation is given as:

$$\rho = \int_0^T x(t) x^*(t)e^{-j2\pi f_o t} dt\tag{3} \label{3}$$

The conjugate product $x(t)x^*(t)$ will always be real, and thus zero phase. Therefore the phase of $\rho$ is the result of integrating over the complex trajectory given by $e^{-j2\pi f_o t}$. This phase of this trajectory proceeds linearly from $0$ radians to $-2\pi f_o T$ radians, and thus the phase of the resulting integral of a phase ramp will be $(-2\pi f_o T)/2 = -\pi f_o T$.

For the $\Delta \phi$ as given above, which is the change in phase from one correlation interval to the next (assuming we did block by block correlations over time $T$), the phase trajectory would go from $-2\pi f_o T$ to $-4\pi f_o T$ over the next correlation duration (integrating from $T$ to $2T$), with the resulting phase $-3\pi f_o T$ (and thus the change in phase is as given in $\ref{1}$.) Also if we were to do the correlation over a moving window $T$ long, the phase that we observe versus time would be consistent with the frequency offset as frequency is a change in phase over a change in time (time derivative of phase.

Confirming this is a plot below showing the real and imaginary output of the correlator for GPS C/A SV24:

Autocorrelation SV24

Repeating the above as a cross-correlation of the CA-Code for SV24 with the same but having a 20 Hz frequency offset results in the an imaginary component for the correlation (Note, this is a frequency offset in the signal itself, not the sampling clock. When the sampled signal is not exactly at baseband meaning zero frequency offset, an offset in the sampling clock would also modify that frequency offset in the signal, as a ratio proportional to the frequency offset of the signal over the sampling rate - I go into more details of the relationship between the two in my answer to DSP.SE #67990):

Cross corr with frequency offset

The amplitude of the real component is 1020.3 and the imaginary component is -64.2, thus the resulting angle is $\tan^{-1}(-64.2/1020.3) =0.0628$ radians. The correlation time $T$ was over 1 C/A code sequence or 1 mS, so the predicted angle given by \ref{1} with $f_o=20$ Hz is:

$$\phi = -\pi f_o T = \pi (20)(1e-3) = 0.063 \text{ radians}$$

Note how for small frequency offsets how the imaginary portion of the correlator output will be directly proportional to the frequency offset, and thus can be used as a frequency discriminator in a carrier recovery loop.

Continuing the above example where the correlation over a time duration $T$ of 1 C/A code sequence (1 ms) to a received GPS signal with 4 consecutive C/A code sequences (4 ms of a GPS capture), with and without the 20 Hz frequency offset condition, starting from the condition of no carrier phase offset:

Corr 4x SV24 no carrier offset

Corr 4x SV 24 20 Hz offset

The above plot is the real and imaginary components of the correlator output for the 4 consecutive C/A code sequences with a carrier offset, correlated against the reference code in the receiver. If we plotted that same result on a complex IQ plane, we can see how the phase rotation with $\Delta \phi$ between each result is consistent with the explanation provided above (we can measure precise carrier phase and frequency offsets from the correlator result, given a change in carrier phase versus time IS frequency offset, while time offset at baseband is the result we see when we shift right or left along the time axis given above):

GPS correlation result - complex IQ

  • $\begingroup$ A delay in either signal or LO (TX vs RX) causes a constant phase shift. This can be used for ranging but has problems with imaging/aliasing as the phase rolls around at $2\pi$ (there is a JPL publication from early 70's that shows how to use Viterbi on phase-based range-finding with discrete tones - if your spacecraft can only send tones...). A frequency offset will cause varying phase offset; a time shift will cause a fixed phase offset in the xcor (in time). $\endgroup$
    – vml
    Commented May 11 at 17:29
  • $\begingroup$ The xcor peak gives resolution related to bandwidth and SNR of the broadband signal; phase shift due to time offset (assuming precise frequency and time offset match of the TX and RX LO) gives resolution over $2\pi$ range, relative to the carrier frequency used. $\endgroup$
    – vml
    Commented May 11 at 17:30
  • $\begingroup$ @vml I wasn't referring to the delay of the local oscillator, which is a phase shift in the carrier, which would then lead to a constant phase rotation in the correlation as you describe (and very similar to the phase rotation I describe for the frequency offset, since a change of that phase with time is frequency). I was referring to the delay of the C/A code sequence itself. As you see in the test case I did for Autocorrelation (which is the cross correlation for every possible delay), the result has zero phase everywhere. $\endgroup$ Commented May 11 at 21:19
  • $\begingroup$ To clarify, I meant that a delay in either the LO as it is applied on TX vs RX and/or a time delay in the modulated signal will cause a phase delta. Conversely, a phase delta applied to the modulated signal will be a good approximation to a time delay in the modulated signal. This is used routinely for beamforming of antenna array outputs, of course. That said, the phase typically wraps many cycles of $2\pi$ over the resolution range of a broadband signal such as a pseudo-random sequence (assuming BW is much less than carrier frequency). $\endgroup$
    – vml
    Commented May 11 at 22:27
  • 1
    $\begingroup$ Great, thanks! Two related points are (1) the notion of coherence time when we talk about frequency error and integrating over a spreading code; (2) the difference between frequency error of the carrier (LO) versus frequency error of sampling (chip rate or some multiple of chip rate). For 20 Hz out of 1500 MHz carrier frequency offset, the corresponding sample drift is quite low, though. Since you bring up carrier offset, it might be good to add a note about coherence. $\endgroup$
    – vml
    Commented May 12 at 5:30

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.