I've a C# program that generates a GPS C/A code consisting of -1s and +1s.
Auto correlating the code with rotated versions of itself shows that the peak is 1023 and the next maximum value is 63 which agrees with what I expect.
Now my understanding is that in the GPS C/A signal the SNR is -30dB and the receiver is still able to detect a strong auto-correlation peak.
So I'm adding a random numbers between 0 and 30 (roughly 30dB) to one of the signals before the auto-correlation and now there's no strong peaks.
Where is the mistake in my reasoning?
using System;
using System.Collections.Generic;
using System.Linq;
namespace CrosssCorrelationTest
{
class Program
{
static void Main(string[] args)
{
List<int> caCode = GenerateCaCode();
var shiftedCaCode = new Queue<int>(caCode);
AddNoise(caCode);
double correlation = 0;
double max1 = 0, max2 = 0;
for(int i=1; i<1023; i++)
{
correlation = CrossCorrelate(caCode, shiftedCaCode.ToList());
if(correlation > max1)
{
max2 = max1;
max1 = correlation;
}
else if(correlation > max2)
{
max2 = correlation;
}
RotateBy1(shiftedCaCode);
}
Console.WriteLine($"max1={max1}; max2={max2}");
Console.ReadKey(true);
}
private static void AddNoise(List<int> caCode)
{
var r = new Random();
for(int i=0; i<caCode.Count; i++)
{
caCode[i] += r.Next(30);
}
}
private static double CrossCorrelate(List<int> caCode, List<int> caCode1)
{
int sum = 0;
for(int i =0; i<caCode.Count; i++)
{
sum += caCode[i] * caCode1[i];
}
return sum;
}
private static void RotateBy1(Queue<int> shiftedCaCode)
{
int chip = shiftedCaCode.Dequeue();
shiftedCaCode.Enqueue(chip);
}
private static List<int> GenerateCaCode()
{
int g1 = 1023; //10b'1111111111;
int g2 = 1023; //10b'1111111111;
var caCode = new List<int>();
for (int i=1; i<=1023; i++)
{
int chip = (g1 ^ ((g2 >> 4) ^ (g2 >> 8))) & 1;
caCode.Add(chip == 1 ? 1 : -1);
g1 = (g1 >> 1) | (((g1 << 2) ^ (g1 << 9)) & 512);
g2 = (g2 >> 1) | (((g2 << 9) ^ (g2 << 8) ^ (g2 << 7) ^ (g2 << 5) ^ (g2 << 2) ^ (g2 << 1)) & 512);
}
return caCode;
}
}
}