目录
1.算法概述
2.部分程序
3.算法部分仿真结果图
4.完整程序获取
1.算法概述
全球定位系统(gps)是一种全天候、全球覆盖、高精度、自动化的卫星导航定位系统,该系统向有适当接收设备的全球范围用户提供精确、连续的三维位置和速度信息。gps自投入运行以来,已经发展成为一个涵盖各领域的服务系统。
卫星信号的捕获算法是卫星定位接收机的关键,传统的捕获算法通常采用基于fft的相干积分和非相干积分相结合的方法,例如在使用gps信号进行定位和导航前首先需要对卫星信号进行捕获,gps卫星信号的传统捕获算法一般为频域并行捕获算法,频域并行捕获算法的原理框图如图3所示,频域并行捕获算法是一种基于fft的捕获算法,搜索覆盖全部搜索频点和全部伪码序列,对于正常功率的gps信号,通常只需要处理lms的导航数据,就能够完成gps信号的捕获,但是对于gps弱信号而言,通常处理lms的导航数据所获得的判决量并不可靠,难以实现捕获,此时就需要通过增加捕获算法所用的数据长度,采用相关积分和非相关积分相结合的方法,来提高捕获灵敏度,但同时导致fft相关运算的计算量将成倍增长,从而造成捕获速度降低。
为了跟踪和解码GPS信号,首先要捕获到GPS信号。将捕获到的GPS信号的必要参数立刻传递给跟踪过程,再通过跟踪过程便可得到卫星的导航电文。GPS卫星处于高速运动中,因此,其频率会产生多普勒频移。载波频率与C/A码的多普勒频移将在下面详细讲述。
GPS卫星发送的信号一般由3个分量组成:载波、伪码和导航电文,其中伪码和导航电文采用BPSK技术去调制载波。
为了跟踪和解码GPS信号,首先要捕获到GPS信号。将捕获到的GPS信号的数据传递给跟踪过程,再通过跟踪过程便可得到卫星的导航电文。传统的GPS捕获方法有:串行搜索捕获、滑动相关法、循环相关法、PMF算法。
GPS卫星信号是发生在两个L波段频率的载波信号L1和L2,两个载波频率分别是L1的主频率fL1和L2的次频率fL2。在L波段进行调制可以避免拥挤,因为L波段的频率占据使用比率和其他波段相比要低一些,有助于全球性观测;L波段上更容易进行扩频(将低比特率的电文转换成高比特率的组合码,有利于卫星信号的保密性),发送宽带信号;L波段大气偏差和电离偏差小,接收设备可以更简单、更经济地接收和测量。每一颗卫星均有唯一的扩频码或伪随机序列,由此调制出载波频率。
2.部分程序
clc;
clear;
close all;
warning off;
addpath(genpath(pwd));rng('default')
%%
%11111111111111111111111111111111111111111111111111111111111
isnoise = 0;%1:add noise;0 good signal
%nosie awgn
SNR = -19;%Q1
satellite = [1,12,14,22];
satellitenumber = length(satellite);
fs = 16.368e6; %sampling freq
IF = 4.092e6;%centered
fIFD = IF + 5e3 - 10e3*rand(1,satellitenumber);%no more than 5 KHz in absolute value
Fai = 2*pi*rand(1,satellitenumber);%random values
Ai = 0.7+0.3*rand(1,satellitenumber);%random between 1 and 0.7 for different satellites
taoi = floor(4e5*rand(1,satellitenumber)) + 2e5; %random between 1 and
Dur = 20;%bit duration,20ms
Len = 50;%data bit length,1s
%
CHIP_TIME = 977.5e-9; % chip time in seconds
ts = 1/fs;
n = fs/1000;
nn = [0:n-1];
millisecond = 1000;x_bound = (ts/2)/CHIP_TIME; % Maximum offset
d_samp = 6; % sample offset between correlators
d = (d_samp*ts)/CHIP_TIME;
msSamp = 16368;for i = 1:satellitenumberi%C%1ms with 16 samplescode0 = digitizg(fs/1000,fs,0,satellite(i));%20mscode1 = [code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0,code0];%lenCA = [];for j = 1:LenCA = [CA,code1];end%DDi0 = 2*double(rand(1,Len)>=0.5)-1;%output the datafor j = 1:LenDout2{i}(Dur*(j-1)+1:Dur*j) = Di0(j);endfor j = 1:length(Dout2{i})Di2(length(code0)*(j-1)+1:length(code0)*j) = Dout2{i}(j);end%Ssignal0 = Ai(i).*CA.*Di2;%16times%delay taoi/61delays = floor(taoi(i)/61);signal3 = [zeros(1,delays),signal0(1:end-delays)];%carriert = 0:1/fs:(length(signal3)-1)/fs;carrier{i} = cos(2*pi*fIFD(i)*t+Fai(i));Si0{i} = signal3.*carrier{i};
end
%noise awgn
if isnoise==0Si_ = Si0;
elsefor i = 1:satellitenumberSi_{i} = awgn(Si0{i},SNR,'measured');end
end%combine
Si= Si_{1};
for i = 1:satellitenumber-1Si = Si + Si_{i+1};
endfigure;
subplot(221);
stem(Dout2{1});
title('data bits of satelite 1');
axis([0,1000,-2,2]);
subplot(222);
stem(Dout2{2});
title('data bits of satelite 12');
axis([0,1000,-2,2]);
subplot(223);
stem(Dout2{3});
title('data bits of satelite 14');
axis([0,1000,-2,2]);
subplot(224);
stem(Dout2{4});
title('data bits of satelite 22');
axis([0,1000,-2,2]);ttt = 0:1000/(length(Si)-1):1000;
figure;
plot(ttt,Si);
title('Combined Si');figure;
plot(ttt(10000:10200),Si(10000:10200));
title('Combined Si local');%%
%22222222222222222222222222222222222222222222222222
%fine frequency estimation
segment=5;
for a=1:satellitenumberfor b=1:segmentoutput = acquisition(Si',satellite(a),b);correlation(:,a,b) = output{1};correlationpeak(:,a) = output{2};frequency(:,a,b) = output{3};finefrequency(a,b) = output{4}; endfinefrequencyaverage(a) = mean(finefrequency(a,:));
end
finefrequencyaverage
fIFD
err = finefrequencyaverage-fIFDX=[fIFD;finefrequencyaverage]';
figure;
bar(X);
axis([0,5,4.0e6,4.2e6]);
legend('Blue:real frequency','Red:fine frequency estimation');
xlabel('4 different satellite');
ylabel('frequency est');%code phase
segment=5;
for a=1:satellitenumberData = [Si]';for b=1:segmentoutput = acquisition(Data,satellite(a),b);correlation(:,a,b) = output{1};correlationpeak(:,a) = output{2};frequency(:,a,b) = output{3};finefrequency(a,b) = output{4}; endfinefrequencyaverage(a) = mean(finefrequency(a,:));
endfigure;
codephases = [];
for a=1:satellitenumberPdata = correlation(:,a,1);subplot(4,1,a);plot(Pdata);[V,I] = max(Pdata);hold onplot(I,V,'r*');xlabel('times');ylabel('correlation');title(['satellite',num2str(satellite(a))]);codephases = [codephases,I];
end%code phase of 4
codephases
taois=codephases*61
taoi%%
%3
for a=1:satellitenumberaData = [Si]';for c=1:millisecond%BASS method.%use the same C/A code from BASS to correlate all 1 ms segments one at a timecacode(:,a) = digitizg(n,fs,0,satellite(a)); %fine frequencylc(:,a) = exp(sqrt(-1)*2*pi*finefrequencyaverage(a)*ts*nn);lsi(:,a) = cacode(:,a).*lc(:,a);lcf(:,a) = fft(lsi(:,a));xf = fft(Data((c-1)*n+1:c*n));f(:,a) = ifft(exp(-sqrt(-1)*2*pi*finefrequencyaverage(a)*ts*(c-1))*xf.* conj(lcf(:,a))); [amp(c,a),ccn(c,a)] = max(abs(f(:,a))); codephase(c,a) = angle((f(ccn(c,a),a)));correlationphase(c,a) = angle((lsi(ccn(c,a),a)));endccnmax(a) = max(ccn(:,a));tmps = find(ccn(:,a)==ccnmax(a));location(a) = tmps(1);
endfigure
for a=1:satellitenumbersubplot(4,1,a);stem(codephase(:,a));title('Correlation result');
end
figure
for a=1:satellitenumbersubplot(4,1,a);stem(correlationphase(:,a));title('Correlation Phase');
end
figure
for a=1:satellitenumbersubplot(4,1,a);stem(amp(:,a));title('Correlation Magnitude');
end%Fine time estimate
for a=1:satellitenumberfor tt = 1:millisecondcacode(:,a) = digitizg(n,fs,0,satellite(a)); ffreq = finefrequencyaverage(a);code_phase = ccn(c,a);local_carrier = exp(1i*2*pi*ffreq*ts*nn); Data_carrier_off = [Data((tt-1)*n+1:tt*n)]'.*local_carrier; input_ms_tt = Data_carrier_off; corrs = ifft(fft(input_ms_tt).* [conj(fft(cacode(:,a)))]'); early = corrs(code_phase - d_samp);late = corrs(code_phase + d_samp); r(tt,a) = abs(late)/abs(early); x(tt,a) = ((1-r(tt,a))*(1-d))/(1+r(tt,a)); if mod(tt,10) == 0 xx(tt/10,a) = mean(x(tt-9:tt,a)); % Average the past 10 fine time estimates end end
endfigure;
for i=1:satellitenumber
subplot(4,1,i);
stem(xx(:,i)*CHIP_TIME);
title('Averaged Fine Time Estimates for 10ms segments of data');
xlabel('10ms');
ylabel('Fine time Est (s)');
endfigure;
for i=1:satellitenumber
subplot(4,1,i);
stem(x(:,i)*CHIP_TIME);
title('Fine Time Estimates for 1 ms segments of data');
xlabel('1ms ');
%xlim([0,13]);
ylabel('Fine time Est (s)');
end
%%
%456together
%phase transitions
for sj=1:satellitenumbertmps = find(amp(:,sj)>0);start(sj) = tmps(1);fprintf(['The initial data bits boundary from satellite ',num2str(satellite(sj)),' is : ',num2str(start(sj)),'ms\n\n']);Recive_bits(:,sj) = Dout2{sj}(1)*ones(Len*Dur,1);
end
for sj=1:satellitenumber%enhance the special pointcorrd = [amp(:,sj)].*[amp(:,sj)].*[amp(:,sj)].*[amp(:,sj)];corrd = corrd-min(corrd);%find the transitions positionCount1=0;Count2=0;for j = 3:length(corrd)-2if corrd(j)>2*corrd(j-1) & corrd(j)>2*corrd(j+1) & corrd(j)>2*corrd(j-2) & corrd(j)>2*corrd(j+2) Count1=Count1+1; endif corrd(j)<0.4*corrd(j-1) & corrd(j)<0.4*corrd(j+1) & corrd(j)<0.4*corrd(j-2) & corrd(j)<0.4*corrd(j+2) Count2=Count2+1; end endif Count1 < Count2threshold = 0.4*mean(corrd);Pos = find(corrd<=threshold);elsethreshold = 1.5*mean(corrd);Pos = find(corrd>=threshold);endif isempty(Pos)==1if sj == 1 ;disp('satellite 1 failed.....'); endif sj == 12;disp('satellite 12 failed.....'); endif sj == 14;disp('satellite 14 failed.....'); endif sj == 22;disp('satellite 22 failed.....'); endelseif Pos(1)==1for j = 3:length(Pos);Recive_bits(Pos(j-1)+1:Pos(j),sj) = -1*Recive_bits(Pos(j-1),sj);%transitionsendelsefor j = 2:length(Pos);Recive_bits(Pos(j-1)+1:Pos(j),sj) = -1*Recive_bits(Pos(j-1),sj);%transitionsendendRecive_bits(Pos(end)+1:end,sj) = -1*Recive_bits(Pos(end),sj);end
endfigure;
subplot(221);
stem(Recive_bits(:,1));title('The data bits of satellite 1');
axis([0,1000,-2,2]);
subplot(222);
stem(Recive_bits(:,2));title('The data bits of satellite 12');
axis([0,1000,-2,2]);
subplot(223);
stem(Recive_bits(:,3));title('The data bits of satellite 14');
axis([0,1000,-2,2]);
subplot(224);
stem(Recive_bits(:,4));title('The data bits of satellite 22');
axis([0,1000,-2,2]);
3.算法部分仿真结果图
01-155m
4.完整程序获取
使用版本matlab2022a
解压密码:C+123456
获得方式1:
m基于matlab的GPS卫星信号捕获和数据解析仿真
获取方式2:
如果下载链接失效,加博主微信,或私信。