代码和测试数据: gitee link
1 GPS捕获原理
首先是正交混频,剥离载波,CA码不做介绍(参考谢钢那本GPS原理和接收机设计)。将CA码重采样,对于GPS L1CA,考虑计算量,采用2倍采样率,即2.046MHz。利用matlab的xcorr做1ms并行相关,N次相干积分,M次非相干积分,寻找大于阈值的非相干结果的峰值,即可实现捕获。
2 Matlab代码
gnss_main.m
%%
clear
close all
%% gps L1 bds B1I prn and doppler
% 4 7 8 9 16 21 26 27
% -2272 3143 777 -385 -1963 3126 -2332 -1556
% 1 2 3 4 5 6 7 9 10 16 27 30
% 10 -4 24 25 4 -1021 -138 -446 -60 -1019 -1255 1757
%% datapath and read data
ifdata_path = 'IFData\\';
codepath = 'OutCACodeResult\\';
pathname = 'ifdata_2bit_20ms.txt';
dataformat = 2; %% 1: txt IQ, with header, 2: txt no header
system_type = 1; %% 0: GPS L1CA 1: BDS: B1I
%% read raw ifdata
switch dataformat
case 1
filename = [ifdata_path,pathname];
readdata = importdata(filename);
gnss_ifdata = readdata.data;
case 2
filename = [ifdata_path,pathname];
readdata = importdata(filename);
gnss_ifdata = readdata;
end
%% read code data
switch system_type
case 0
filename1 = 'GPSCACode.txt';
f1 = [codepath,filename1];
gnss_code = importdata(f1);
case 1
filename1 = 'BDSCACode.txt';
f1 = [codepath,filename1];
gnss_code = importdata(f1);
case 2
disp("error system!!!")
case 3
disp("error system!!!")
otherwise
disp("error system!!!")
end
%% gnss config init
gnss_config = set_gnss_config(system_type);
%% acq
tic
acq_result = gnss_acq(gnss_config.acq_config, gnss_ifdata, gnss_code);
toc
if acq_result.acq_status == 1
%% show result
dop_list = gnss_config.acq_config.acq_fre_min : gnss_config.acq_config.acq_fre_step : gnss_config.acq_config.acq_fre_max;
code_phase_step = gnss_config.acq_config.code_phase_step;
system_name = gnss_config.acq_config.system_name;
x = acq_result.acq_check_list{
1,1}.x * code_phase_step;
acq_noncoh_result = acq_result.acq_check_list{
1,1}.temp_noncoh_result;
PRN = acq_result.acq_check_list{
1,1}.prn;
%% 2D plot
figure(1)
plot(x, acq_noncoh_result(:, acq_result.acq_check_list{
1, 1}.acq_check_result.dop_cnt))
xlabel('Codephase/chip')
ylabel('Amplitude')
titlename = [system_name, ' PRN-', num2str(PRN),' ','Result'];
title(titlename)
grid on
% 3D plot, note: gnss_acq not save result, please config
if 1
h = figure(2);
mesh(dop_list, x, acq_noncoh_result)
titlename = [system_name, ' PRN-', num2str(PRN),' '