gpsnavigation.m

来自「获取导航电文」· M 代码 · 共 117 行

M
117
字号
clear;
clc;
load GPSsignal.mat
SvNum=12;
Temp=fGenerateCAcode3(SvNum);
index1=find(Temp==0);
Temp(index1)=-ones(1,length(index1));
SinWave=sin([0:2*pi/8:2*pi*7/8]);
SinWave=single(SinWave);
GpsMatch=zeros(1,1);
SinWave=[SinWave SinWave SinWave SinWave SinWave];
for i=1:length(Temp)
    GpsMatch=[GpsMatch Temp(1,i)*SinWave];
end
GpsMatch=GpsMatch(2:length(GpsMatch));
n=length(GpsMatch);
m=50000;
for i=1:m
    Res(i)=GpsMatch*GPSsignal(1,i:i+n-1)';
end 
plot(1:m,Res);
Res2=abs(Res);
for i=1:100;
    [C I]=max(Res2);
    Res2(1,I)=0;
    Index(1,i)=I;
end
 
w=length(GpsMatch);
m=1;
for i=Index(1,1):w:(length(GPSsignal)-w+1)
    NavigationBit(m)=(GPSsignal(i:i+w-1)*GpsMatch')/w;
    m=m+1;
end
NavigationCode=zeros(1,1);
NavigationCode(1,1)=NavigationBit(1,1);
m=2;Count=0;
for i=2:length(NavigationBit)
    if(NavigationBit(1,i)~=NavigationBit(1,i-1))
        NavigationCode(1,m)=NavigationBit(1,i);
        m=m+1;
        Count=0;
    else
        Count=Count+1;
        if(Count>=5)
            NavigationCode(1,m)=NavigationBit(1,i);
            m=m+1;
            Count=0;
        end
    end
end 
NavigationCode=NavigationCode./abs(NavigationCode);
index1=find(NavigationCode<0);
NavigationCode(index1)=zeros(1,length(index1));
Table1=[0 0 0 0;
       0 0 0 1;
       0 0 1 0;
       0 0 1 1;
       0 1 0 0;
       0 1 0 1;
       0 1 1 0;
       0 1 1 1;
       1 0 0 0;
       1 0 0 1;
       1 0 1 0;
       1 0 1 1;
       1 1 0 0;
       1 1 0 1;
       1 1 1 0;
       1 1 1 1;];
   Result=[];
   for i=1:4:length(NavigationCode);
       TT=NavigationCode(i:i+3);
       MatchTable=Table1(:,1:4)-[TT;TT;TT;TT;TT;TT;TT;TT;
                                TT;TT;TT;TT;TT;TT;TT;TT;];
       MatchTable=sum(abs(MatchTable)');
       TempChar='0';
       BestMatch=find(MatchTable==min(MatchTable));
       switch (BestMatch)
           case 1
               TempChar='0';
               case 1
               TempChar='1';
               case 1
               TempChar='2';
               case 1
               TempChar='3';
               case 1
               TempChar='4';
               case 1
               TempChar='5';
               case 1
               TempChar='6';
               case 1
               TempChar='7';
               case 1
               TempChar='8';
               case 1
               TempChar='a';
               case 1
               TempChar='b';
               case 1
               TempChar='c';
               case 1
               TempChar='d';
               case 1
               TempChar='e';
               case 1
               TempChar='f';
           otherwise
       end
       Result=strcat(Result,TempChar);
   end
   Num1=hex2num(Result(1:16));
   Num2=hex2num(Result(17:32));
   Num3=hex2num(Result(33:48));  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?