# How to Compensate for Frequency Offset in single carrier transmission Using Coarse and Fine Compensation?

How to compensate for the frequency offset of a PAM, PSK, or QAM signal when we are using single carrier transmission, I am looking for algorithms, explanations to be able to carry out the implementation on matlab

To compensate for a frequency offset first it needs to be measured, let us take the example of PSK.

At the trasnmitter : Suppose the signal is upconverted at the transmitter to $$F_c$$, then the received signal is given by $$s(t)e^{j2\pi F_ct}$$ here $$s(t)$$ is the baseband PSK signal.

At the Receiver: Suppose the received signal has a frequency offset, either due to doppler shift or inaccuracy of the receiver clock, let this offset be $$\Delta_f$$, after downconversion at the receiver, the signal sent to the ADC is $$s(t)e^{j2\pi F_ct}s^{*}(t)e^{j2\pi( F_c - \Delta_f)t}$$

$$\vert s(t) \vert^2 e^{-j2\pi\Delta_ft}$$

Where for the sake of simplicity, let us normalize $$\vert s(t) \vert^2 = 1$$

After going through the ADC the digitized samples are given by $$y[n] = e^{j2\pi\Delta_fnT_s}$$ where $$T_s$$ is the sampling interval

Let us now correlate adjacent samples of this digitized signal, we get

$$y[n+1]y[n]^* = e^{j2\pi\Delta_f(n+1)T_s}e^{-j2\pi\Delta_fnT_s}$$

$$y[n+1]y[n]^* = e^{j2\pi\Delta_fT_s}$$

Everything other than $$\Delta_f$$ is known in the above equation, which can be found out using the following relation, let us denote the phase resulting from the correlation of samples as following:

$$y[n+1]y[n]^* = u_k$$ then $$\Delta_f = \frac{\Phi_k}{2\pi T_s} \tag{1}$$

Where $$\Phi_k = arctan\left( \frac{Img(u_k)}{Real(u_k)} \right)$$

For a good result which is less impacted by noise, take average over a larger number of such correlations between incoming samples.

For the case when $$\vert s(t) \vert^2$$ is not unity or unit power, the value $$E(s[n+1]s[n])$$ is decided by the constellation. Usually a pilot is sent with a known constellation point to the receiver and trasnmitter to determine the frequency offset and channel.

For ex: in 4 QAM, you could send the constellation point/symbol $$\sqrt{\frac{1}{2}} + j\sqrt{\frac{1}{2}}$$

If however the SINR is low, the envelope of the signal $$\vert s(t) \vert^2$$, might not be predictable at the receiver in such cases it is better to work with the demodulated symbols and not the samples. The upside is better offset estimation, the downside is a longer convergence loop, because of need to demodulate and then recover offset.

In such cases, the receiver will first try to demodulate the symbol with the frequency offset (hopefully it's not too big and can be demodulated correctly). The rotation in complex plane is directly linked to the offset as in equations above.

Now $$T_s$$ would be replaced by the symbol time in the above equation (1), because we would be correlating between adjacent symbols and not samples, rest of the analysis will remain exactly the same.

Once the frequency offset is estimated it can then be corrected at the receiver by applying the adjustment to the PLL at the receiver.

However, the decision to correct the offset also depends on the SINR and quality of measurements. If the SINR is low (that means the measured frequency offset is not fully trust worthy, then correct only a part of the measured frequency offset, ex : 75% in one estimation cycle, and successful estimations will then converge to the actual offset over a period of time). So the amount of total correction once the estimation of the offset is done should be reflected in the confidence in the estimate decided by the SINR and other physical layer parameters.

Coarse and fine compensation are talking about first fixing the impairment using a rough estimate then again fix/fine-tune using a better estimate. One way to do this is by using the so called $$M^{th}$$ power estimator for PSK signals. The version I'm talking about will use the received symbols after timing synchronization is done. That is, the input constellation would look like this: It is spinning according to frequency offset $$\Delta f$$. There are multiple constellation points mixed in there so the trick is to collapse all of them to a single point, then that single point will be rotating at a frequency $$\Delta f$$. For a $$M$$-PSK signal, the constellation points are $$e^{j\frac{2\pi m}{M}}$$ for an integer $$m \in [0, M-1]$$. By raising this to the $$M^{th}$$ power, we get: $$e^{j2\pi m}=1$$. Now, consider this same operation in the presence of a frequency offset: $$e^{j\big( \frac{2\pi m}{M} +2\pi \Delta f \big)} \rightarrow e^{j2\pi M \Delta f}$$. The coarse estimate steps go like this:

1. Raise the signal to the $$M^{th}$$ power.
2. Take the FFT of the result.
3. Find the frequency where the peak occurs. That frequency will be $$f^M_{\text{coarse}}=2\pi M \Delta f$$.
4. Coarse estimate is then $$f_{\text{coarse}}=\frac{f^M_{\text{coarse}}}{M}$$.

It should be noted that you control how coarse the coarse step is since you choose the length of the FFT. Choosing to zero pad more will interpolate in the gaps and each bin is $$\frac{2\pi}{N_{FFT}}$$. Of course, nothing is stopping you from cranking up $$N_{FFT}$$ to a very large value to the point where the next part might not be of any benefit.

The coarse step can be followed by a fine search where a gradient step approach is taken. Starting from the previous coarse estimate, this part essentially wiggles your estimate ever so closer to the true frequency of the tone signal we created corresponding to the peak in the FFT. A typical stopping criteria might be stop when frequency offset estimate isn't changing enough and always include a maximum iteration count to guarantee it eventually stops. When this search finally stops, you should have an estimate of the frequency offset with less error than if you just stopped after the coarse step. You can see what the fine step gains you by looking at what the constellation looks like after using the coarse or fine estimate for the correction. In my case, you can see using the coarse estimate still resulted in small rotation of the constellation indicating that there was substantial error. ## Edit

A picture to better explain where the coarse and fine steps get you. You can two FFTs plotted on top of each other. The blue one is computed to have 64 times more frequency resolution as to show an approximate "truth" spectrum. You can see during the coarse step, we use the orange FFT to get the coarse estimate by finding the frequency where the peak occurs. As you can see from the blue plot though, this is not close enough to the "true" peak! During the fine search we are essentially climbing up until we eventually get to the true peak.