www.gusucode.com > GPS信号捕获程序,信号源为东方联星Newstar210M采集到的中频数字信号(含GUI界面)- > sourcode/generatecacode.m

    function CAOutput=generatecacode(SatelliteID)

%a function to generate C/A code for accomplishing the circular correlation;

%SatelliteID            is the No. of the SV

%Created 4/15/05, Hao Yu, sendtoyuhao@yahoo.com.cn 
%Copy right olinkstar corp. Bejing China

%**************initial condition******************************************
% clear Cyc G1 G2 N Output PhaseSelector SatelliteID geedback g2CodePhase i i2 register temp;
% clc;
N=10;                       %**********  2*10 bits shift register;
Cyc=1023;                   %**********  sequence cycle
g2CodePhase=[2 6;        3 7;        4 8;        5 9;     1 9;       2 10;        1 8;        2 9;      %****the 32 different 
            3 10;        2 3;        3 4;        5 6;     6 7;        7 8;        8 9;       9 10;                   %****phase selectors
             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];
%********get the satellite ID number;    
% SatelliteID=input('Input the Satellite ID(1-31):');    
%***********G1 generator;
register=[1 1 1 1 1 1 1 1 1 1];          %******load the initial value
G1=zeros(1,Cyc);
for i=1:Cyc,                             %******get the 1023 C/A code              
    G1(i)=register(10);                    %******each time we can get a new code from register1(10)
    feedback=xor(register(3), register(10));
    temp=N;
    for i2=2:1:N                                %******run the shift register1 to get a new sequence
        register(temp)=register(temp-1);
        temp=temp-1;
    end;
    register(1)=feedback;    
end,
%***********G2 generator;
register=[1 1 1 1 1 1 1 1 1 1];
G2=zeros(1,Cyc);
PhaseSelector=[0 0];                                              %******   the 2 Phase Selector No. in the shift registers
switch SatelliteID
    case {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}          %***the satellite ID
            PhaseSelector(1)=g2CodePhase(SatelliteID,1);          %******   match the Phase Selector to
            PhaseSelector(2)=g2CodePhase(SatelliteID,2);          %******   the selected satellite ID
        otherwise 
            disp('ID is wrong ,you may execute the program once again');               %********get the satellite ID number
end,
for i=1:Cyc,    
    G2(i)=xor(register(PhaseSelector(1)),register(PhaseSelector(2)));           %*******the G2 output is the XOR result of the 2 phase selectors
    feedback=xor(register(2),xor( register(3) , xor (register(6) ,xor( register(8) ,xor( register(9),register(10))))));
    temp=N;
    for i2=2:1:N                             %******run the shift register2
        register(temp)=register(temp-1);
        temp=temp-1;
    end;
    register(1)=feedback;     
end
%*********output is the result of G1(1) xor G2(2)
i=1:Cyc;
temp=xor(G1(i),  G2(i));
CAOutput=zeros(1,Cyc);
for i=1:Cyc,
    CAOutput(i)=temp(i);
    if CAOutput(i)==0,
        CAOutput(i)=-1;
%     if CAOutput(i)==1,
%         CAOutput(i)=3;
    end
end
%*******end of file