# how to sample and modulate a gps gold code

I am trying to simulate the data transmission of a GPS satellite. Telecommunications is not my field so I am struggling a bit with some concepts. I managed to generate the Gold code of the GPS transmitter using shift registers. This creates a pseudorandom 1023-vector with [-1 1] values. Now I want to create a sampled version of this signal up to 5.714Hz assuming the clock of the codes work at 1.023 Mchip/s and then modulate this signal with a sinusoidal carrier of 4.309 MHz sampled at the same frequency. I am not sure how to sample the signal. From what I've understood, I wrote something like this in Matlab but it's not right :

a = [1 1 1 1 1 1 1 1 1 1 ]
b = [1 1 1 1 1 1 1 1 1 1 ]
for k = 1: 1023
A(k) = a(10) ;
B(k) = mod(b(2)+b(6),2) ;
C_A(k) = mod(A(j)+B(j),2) ;
Af = mod(a(3)+a(10),2) ;
Bf = mod(b(2)+b(3)+b(6)+b(8)+b(9)+b(10),2) ;
% shifting
sg_1 = [ Af a(1:n-1) ] ;
sg_2 = [ Bf b(1:n-1) ] ;
end
code_vect = (C_A-0.5)*2 ;
% UP TO HERE IT'S OK, I GOT THE C/A CODE, how to modulate it?
code_vect = code_vect(index,:) % this is 1x1023 Gold code vector
sa_fq = 5.714e6     %sampling freq
ca_fq = 4.309e6     %carrier freq
cd_fq = 1.023e6   %code frequency (I am right?)
clk = 1.023e6   %clock rate
time = 1/sa_fq : 1/sa_fq :1023/sa_fq   %time vector
for i = 1:1023
%sampled signal, I'm sure this is wrong but don't know how to do it
code_vect_sa((ceil(sa_fq)*i)-(ceil(sa_fq)-1):(ceil(sa_fq)*i))=code_vect(i)*ones(1,ceil(sa_fq))
end
carr = cos(2*pi*(ca_fq+cd_fq)*time) %carrier
sig_mod = code_vect_sa*carr ; modulated signal


Can you guys give a hint on how to solve it. Thanks in advance

• what do you try to do here: code_vect_sa((ceil(sa_fq)*i)-(ceil(sa_fq)-1):(ceil(sa_fq)*i))=code_vect(i)*ones(1,ceil(sa_fq))? The rest looks ok – Behind The Sciences Apr 14 '16 at 18:28
• Hi, that is the section I don't exactly know how to do. I am trying to get a sampled version of the Gold code where the samplig frequency is 5.714MHz, just the signal before modulation. I don't know how to do it, so I thought just to make the frequency an integer and "replicate" the code values 6 times per code – Wobbler28 Apr 14 '16 at 18:42
• I think you don't need that line of code, as you sample when you do carr = cos(2*pi*(ca_fq+cd_fq)*time). Your time axis indicates the samples that you are going to take. Does this make sense? – Behind The Sciences Apr 14 '16 at 18:44
• Well I am not completely sure. What I got is that I should multiply the modulated signal by the modulated carrier; actually my professor asks me the modulated C/A code as one of my results, but I don't know how to do it, for the carrier is more straightforward. – Wobbler28 Apr 14 '16 at 18:48

## 1 Answer

Have a look to the definition of the C/A signal here: where it says t you need to put your time, where it says i, you need to put your index i from the for loop, so that concept is correct.

I think your confusion comes from using the frequency in the equation instead of the sampling time which is your time vector.

• I am sorry I am confused with the time now. As far as I understand, I have already generated the C/A code by using the shift registers process. In may code, it would be code_vect, a 1x1023 vector. My result (C/A in the wiki) is just a sequence of ones and minus ones. Once I have this, I have to sample it using sa_fq...so I calculate time, but then I don't really know how to use it. With the wiki notation, I feel I already calculated C/A, then don't know which A and B are. – Wobbler28 Apr 14 '16 at 19:10
• I just edited the code to show the C/A calculation – Wobbler28 Apr 14 '16 at 19:37
• The main problem that I see is that you are writing the C/A as a function of the frequency, but it should be a function of the time, isn't? – Behind The Sciences Apr 16 '16 at 7:03