# Transforming digitized noisy signal before applying cross-correlation

I'm trying to grasp the concept of cross-correlation as it applies to CDMA in the GPS C/A signal where noise is involved and the SNR is low.

My understanding is that before calculating the cross-correlation with the C/A code one has to transform (just shift by its average value?) the digitized and demodulated received signal so that there are both positive and negative values in the sequence and the sum of these on average should be zero, is this correct?

(I understand that there's much more to acquiring the GPS C/A signal, but I'm trying to grasp how cross-correlation can be applied to a digitized signal)

To offset or not is simply in your definitions on how you want to do the math involved and can be convenient for further processing. Subtracting a constant, or otherwise scaling the waveform, does not change the signal to noise ratio.

Correlation is to multiply and accumulate, and the cross-correlation and auto-correlation functions show this correlation as the sequences are shifted in time relative to each other. Cross-correlation is between two different functions, and auto-correlation is between a function and itself.

The cross-correlation of x[n] and y[n], with a shift index m, can be given as:

$$\rho_{xy}[m] = \Sigma_n x[n]y[n+m]$$

(Note: For complex signals, the product must be complex conjugate product)

With that said, consider this very simple example using an 11 chip barker code to demonstrate my first statement. This Barker code has a similar property to C/A codes in that a correlation with shifted versions with itself (autocorrelation) will have a very low correlation relative to when the code is aligned.

1 0 1 1 0 1 1 1 0 0 0

This code written with 1's and 0's has a mean of approximately 1/2, so you can optionally remove the mean and similarly for convenience scale by a factor of two by mapping 0 to -1 such that the code is:

1 -1 1 1 -1 1 1 1 -1 -1 1

This results in the following correlation when the sequences are aligned in time (which could be used in direct-sequence-spread-spectrum, DSSS, to send a data symbol with value = "1"):

And the following if the code was inverted (which could be used in DSSS to send a data symbol with value = "0"):

And the following for any other shift (I did a rotational shift of one sample here, corresponding to m = -1):

With the following autocorrelation result as a plot:

We could similarly instead perform the correlation with the following operations for multiplication (basically XOR function, could do the same with XNOR and get an inverterted result):

1 x 0 = 0

0 x 1 = 1

1 x 1 = 1

0 x 0 = 0

Resulting in a similar result with an offset and scaling in the correlation output instead of an offset and scaling the correlation input. So in this case the maximum correlation would be 11, the maximum correlation when inverted is 0 and the autocorrelation for any other offset would be 5. Double this and subtract 11 and you get the same result as before.

(Note unlike maximum-length pseudo-random sequences which will also cross-correlate to -1 at all offsets when you use +1 and -1 values, C/A codes have cross-correlation values of either 1, +63 or -65, which is still significantly less than the 1023 value when aligned).

The reason this works for GPS in the case of low SNR is when you add each of the 1023 chips with noise present, if the noise on each chip is independent ("white noise"), then the signal magnitude will accumulate by a factor of $$1023$$, but the standard deviation of the noise will only accumulate by a factor of $$\sqrt{1023}$$ thus in terms of SNR you get a $$10Log_{10}(N)$$ processing gain. Consider a simpler case of adding two independent Gaussian random variables with equal distribution and equal but non-zero mean: The mean will double but the standard deviation will only increase by the $$\sqrt{2}$$.

My understanding is that before calculating the cross-correlation with the C/A code one has to transform (just shift by its average value?) the digitized and demodulated received signal so that there are both positive and negative values in the sequence and the sum of these on average should be zero, is this correct?

No, at least not strictly so.

Think about it: a shift in amplitude is just an addition of a constant. That is something that you can see as offset in the cross-correlation, too, which is a linear operation.

So, there's no strict reason you'd do this beforehand. There might be numerical reasons, but no signal reasons in themselves.

Generally, I find it much easier to understand what a correlation coefficient is if you consider it an inner product between signal vectors. A lot of the statements (orthogonality, linearity) we use to deal with signals become way more intuitive that way.