# Extraction of the phase lag form cross-correlation function

I would like to find out the phase offset that my signal contains at the receiver side. For this, I use the cross-correlation function, where I cross-correlate signal before and after matched filter. The resulting cross-correlation function is represented in the figure below:

In the figure we can see that there is a pronounced peak at approximately 0.3 * 10^6 samples. I want to use this information to remove the phase error and my approach is following:

1. calculate the time lag
2. calculate the phase lag

this I code in the following way

time_lag = peak[0]/Fs # Fs - sampling frequency
phase = 2*np.pi*f_symb*time_lag # f_symb is symbol frequncy
print(phase)

out: 549160.4489439873


then I want to use this phase lag to shift the constellation, however even after the shift, the constellation is still tilted, which indicates phase error.

Can you point out, where I make a mistake?

Thanks!

The rotation of the constellation is due to carrier phase offset, which is not the same as a time delay. What the OP is seeing with the additional peaks is evidence that portions of the waveform itself repeat every 0.3x10^6 samples. Since the entire correlation is going down toward the edge of the plot, I assume the OP has done a linear cross-correlation and we are just seeing the effect from less overlap between the two waveforms that are being correlated.

Regardless of that, the carrier phase offset (constellation rotation) can be determined from the cross-correlation with zero time lag (the direct correlation function as a sum of complex conjugate products) as demonstrated below:

Consider such a correlation between the received $$y[n]$$ and known $$x[n]$$ signal where the only difference between the two signals is a phase rotation with

$$x[n] = e^{j\theta[n] n}$$

$$y[n] = e^{j\theta[n] n}e^{j\phi}$$

Where $$\theta[n]$$ is the known modulation of the carrier, while $$\phi$$ is an unknown phase offset (rotation).

The generalized correlation $$r_{xy}[n]$$ is a sum of complex conjugate products (the cross correlation function re-computes this at all delay offsets, but delay is NOT phase):

$$r_{xy}[n] = \sum_{n=0}^{N-1}x[n]y^*[n]$$

$$= \sum_{n=0}^{N-1}e^{j\theta[n] n}e^{j\phi}Ae^{-j\theta[n] n}$$

$$= Ne^{j\theta}$$

As we see, the phase of $$r_{xy}[n]$$ is the carrier phase offset we are trying to determine. Further, we have the advantage of processing gain in the correlation to optimally (in the presence of white noise) increase the SNR and therefore our estimate of the phase. The process is to use the cross-correlation function to align the received and transmitted waveforms, and once aligned (as evidenced by the largest peak) we can continue to use the generalized correlation function at that offset to determine the phase offset. Since the OP's cross-correlation function is maximum at offset = 0, the transmit and receive waveforms are already aligned, so the generalized correlation function can be used directly to determine phase (which would match the phase of that peak correlation at zero, since these would be the same).

I demonstrate this in this graphic pasted below showing correlation versus phase and frequency offset, with the added contributions of noise.