GPS接收机设计(4)——帧同步
发布时间
阅读量:
阅读量
帧同步的过程比较简单,第一步将已知的同步码与跟踪截断获得的导航电文进行互相关,相关值最大时即子帧的起始位置;第二步是奇偶校验过程,获取当前子帧的前两个字与上一个子帧的最后两个数据比特进行奇偶校验,校验通过则说明上一步骤中获得的子帧起始位置是正确的。
function [firstSubFrame, activeChnList] = findPreambles(trackResults, ...
settings)
%[firstSubFrame, activeChnList] = findPreambles(trackResults, settings)
%
% Inputs:
% trackResults - output from the tracking function
% settings - Receiver settings.
%
% Outputs:
% firstSubframe - the array contains positions of the first
% preamble in each channel. The position is ms count
% since start of tracking. Corresponding value will
% be set to 0 if no valid preambles were detected in
% the channel.
% activeChnList - list of channels containing valid preambles
%--------------------------------------------------------------------------
% CVS record:
% $Id: findPreambles.m,v 1.1.2.10 2006/08/14 11:38:22 dpl Exp $
% Preamble search can be delayed to a later point in the tracking results
% to avoid noise due to tracking loop transients
searchStartOffset = 0;
%--- 初始化子帧序列-----------------------------------
firstSubFrame = zeros(1, settings.numberOfChannels);
%--- 生成同步码 ----------------------------------------
preamble_bits = [1 -1 -1 -1 1 -1 1 1];
%重采样子帧
preamble_ms = kron(preamble_bits, ones(1, 20));%每一比特对应20ms(20个)C/A码周期
activeChnList = find([trackResults.status] ~= '-');%寻找出跟踪到的通道序号
for channelNr = activeChnList
bits = trackResults(channelNr).I_P(1 + searchStartOffset : end);%及时码的相关结果是导航电文
% Now threshold the output and convert it to -1 and +1 ,以获得更好的相关特性
bits(bits > 0) = 1;
bits(bits <= 0) = -1;
tlmXcorrResult = xcorr(bits, preamble_ms);%互相关,维度不同则补0
%% 寻找所有子帧的起始相位 ================
clear index
clear index2
xcorrLength = (length(tlmXcorrResult) + 1) /2;
%--- Find at what index/ms the preambles start ------------------------
index = find(...
abs(tlmXcorrResult(xcorrLength : xcorrLength * 2 - 1)) > 153)' + ...
searchStartOffset;%理论互相关最大值为160,考虑了偏差,设定互相关阈值为153
59. %% Analyze detected preamble like patterns ================================
for i = 1:size(index) % For each occurrence
62. %--- Find distances in time between this occurrence and the rest of
%preambles like patterns. If the distance is 6000 milliseconds (one
%subframe), the do further verifications by validating the parities
%of two GPS words
index2 = index - index(i); %寻找相邻子帧之间的间隔(以ms为单位)
69. if (~isempty(find(index2 == 6000)))%判断数组index2中是否存在数值6000
71. %读取遥测字和交接字以及上1子帧最后两个比特用于奇偶校验
bits = trackResults(channelNr).I_P(index(i)-40 : ...
index(i) + 20 * 60 -1)';
%读取遥测字和交接字以及上1子帧最后两个比特
%--- 将每20个值合成一个比特 ------------------------
bits = reshape(bits, 20, (size(bits, 1) / 20));
bits = sum(bits);
% Now threshold and make it -1 and +1
bits(bits > 0) = 1;
bits(bits <= 0) = -1;
%--- Check the parity of the TLM and HOW words ----------------
if (navPartyChk(bits(1:32)) ~= 0) && ...
(navPartyChk(bits(31:62)) ~= 0)%奇偶校验
% Parity was OK. Record the preamble start position. Skip
% the rest of preamble pattern checking for this channel
% and process next channel.
firstSubFrame(channelNr) = index(i);%第一子帧的位置为index(i)
break;
end % if parity is OK ...
end % if (~isempty(find(index2 == 6000)))
end % for i = 1:size(index)
% Exclude channel from the active channel list if no valid preamble was
% detected
if firstSubFrame(channelNr) == 0%如果第一子帧参数恒为初始值,则说明帧同步失败
activeChnList = setdiff(activeChnList, channelNr);
%返回activeChnList中存在,channelNr不存在的数据;下一次循环排除channelNr通道
disp(['Could not find valid preambles in channel ', ...
num2str(channelNr),'!']);
end
end % for channelNr = activeChnList
全部评论 (0)
还没有任何评论哟~
