📄 cacode.m
字号:
function CA= cacode(n, chiprate, fs, n_samples)
%The function CA= cacode(n, chiprate, fs, n_samples) returns the gold code
% for GPS satellite ID n =1...32.
% chiprate = number of chips per second
% fs = sampling frequency
% n_samples = number of samples
% The code is represented at levels : -1 for bit =0 and 1 for bit =1
%phase assignments
phase=[2 6; 3 7; 4 8; 5 9; 1 9; 2 10; 1 8; 2 9; 3 10; 2 3; 3 4; 5 6;
6 7; 7 8; 8 9; 9 10; 1 4; 2 5; 3 6; 4 7; 5 8; 6 9; 1 3; 4 6; 5 7; 6 8;
7 9; 8 10; 1 6; 2 7; 3 8; 4 9];
% Initial state - all ones
G1 = -1*ones(1,10);
G2 = G1;
%select taps for G2 delay
s1 = phase(n,1);
s2 = phase(n,2);
tmp =0;
for i =1:1023;
%gold-code
G(i)= G2(s1)*G2(s2)*G1(10);
% generator1 -shift reg1
tmp=G1(1);
G1(1)=G1(3)*G1(10);
G1(2:10)=[tmp G1(2:9)];
% Generator2 - shift reg2
tmp=G2(1);
G2(1)=G2(2)*G2(3)*G2(6)*G2(8)*G2(9)*G2(10);
G2(2:10)=[tmp G2(2:9)];
end;
% Resample - doesn't work for (i*chiprate/fs)>1023
% but replica chiprate is constant in this implementation
G=[G G G G G G G G G G];
%G=[G G];
%G=[G -1*G G -1*G G ];
i=1:n_samples;
CA(i) = G(ceil(i*chiprate/fs));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -