www.pudn.com > GNSS_SDR.zip > findPreambles.m, change:2009-12-07,size:7927b


function [firstSubFrame, activeChnList] = findPreambles(trackResults, ... 
                                                        settings) 
% findPreambles finds the first preamble occurrence in the bit stream of 
% each channel. The preamble is verified by check of the spacing between 
% preambles (6sec) and parity checking of the first two words in a 
% subframe. At the same time function returns list of channels, that are in 
% tracking state and with valid preambles in the nav data stream. 
% 寻找子帧起始位置 
% [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. 
%                       - 各个通道第一个子帧位置,以为开始跟踪后的时间计(ms)。 
%                       - 如果子帧未找到,则对应通道的相关结果置零。 
%       activeChnList   - list of channels containing valid preambles 
%						- 能够找到子帧的通道 
 
%-------------------------------------------------------------------------- 
%                           SoftGNSS v3.0 
%  
% Copyright (C) Darius Plausinaitis, Peter Rinder and Nicolaj Bertelsen 
% Written by Darius Plausinaitis, Peter Rinder and Nicolaj Bertelsen 
% 注释翻译:苗剑峰 
%-------------------------------------------------------------------------- 
% 
%This program is free software; you can redistribute it and/or 
%modify it under the terms of the GNU General Public License 
%as published by the Free Software Foundation; either version 2 
%of the License, or (at your option) any later version. 
% 
%This program is distributed in the hope that it will be useful, 
%but WITHOUT ANY WARRANTY; without even the implied warranty of 
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
%GNU General Public License for more details. 
% 
%You should have received a copy of the GNU General Public License 
%along with this program; if not, write to the Free Software 
%Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
%USA. 
%程序为开源程序,请在开源协议规定范围内做改动 
%-------------------------------------------------------------------------- 
 
% 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; 
 
%--- Initialize the firstSubFrame array 初始化第一个子帧数组----------------- 
firstSubFrame = zeros(1, settings.numberOfChannels); 
 
%--- Generate the preamble pattern 产生子帧头序列--------------------------- 
preamble_bits = [1 -1 -1 -1 1 -1 1 1]; 
 
% "Upsample" the preamble - make 20 vales per one bit. The preamble must be 
% found with precision of a sample. 
% 扩展子帧头序列,每一位扩展为20位 
preamble_ms = kron(preamble_bits, ones(1, 20)); 
 
%--- Make a list of channels excluding not tracking channels -------------- 
%--- 初始化结果通道 -------------------------------------------------------- 
activeChnList = find([trackResults.status] ~= '-'); 
 
%=== For all tracking channels ... 
%=== 对每个跟踪通道…… 
for channelNr = activeChnList 
 
%% Correlate tracking output with preamble 将子帧头序列和跟踪结果相关======== 
    % Read output from tracking. It contains the navigation bits. The start 
    % of record is skiped here to avoid tracking loop transients. 
	% 读入跟踪结果(跳过开头) 
    bits = trackResults(channelNr).I_P(1 + searchStartOffset : end); 
 
    % Now threshold the output and convert it to -1 and +1  
	% 将跟踪结果调整为+1和-1 
    bits(bits > 0)  =  1; 
    bits(bits <= 0) = -1; 
 
    % Correlate tracking output with the preamble 
	% 将子帧头序列和跟踪结果相关 
    tlmXcorrResult = xcorr(bits, preamble_ms); 
 
%% Find all starting points off all preamble like patterns 寻找所有相关点=== 
    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; 
 
%% Analyze detected preamble like patterns 分析所有相关点=================== 
    for i = 1:size(index) % For each occurrence 对每个可能的点 
 
        %--- 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 ------------------------------------------------- 
		%--- 先寻找间隔6000ms的相关点,然后根据GPS关键字进行校验 
         
        index2 = index - index(i); 
 
        if (~isempty(find(index2 == 6000))) 
 
            %=== Re-read bit vales for preamble verification ============== 
			%=== 重新读入跟踪结果=========================================== 
            % Preamble occurrence is verified by checking the parity of 
            % the first two words in the subframe. Now it is assumed that 
            % bit boundaries a known. Therefore the bit values over 20ms are 
            % combined to increase receiver performance for noisy signals. 
            % in Total 62 bits mast be read : 
            % 2 bits from previous subframe are needed for parity checking; 
            % 60 bits for the first two 30bit words (TLM and HOW words). 
            % The index is pointing at the start of TLM word. 
			% 先假定找到的相关点就是子帧开头,校验60位数据,判断是否真的是子帧。 
			 
            bits = trackResults(channelNr).I_P(index(i)-40 : ... 
                                               index(i) + 20 * 60 -1)'; 
 
            %--- Combine the 20 values of each bit ------------------------ 
			%--- 每20个值组合 ---------------------------------------------- 
            bits = reshape(bits, 20, (size(bits, 1) / 20)); 
            bits = sum(bits); 
 
            % Now threshold and make it -1 and +1 
			% 变换为+1和-1 
            bits(bits > 0)  = 1; 
            bits(bits <= 0) = -1; 
 
            %--- Check the parity of the TLM and HOW words ---------------- 
			%--- 校验TLM和HOW字段内容 -------------------------------------- 
            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); 
                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 
         
        % Exclude channel from further processing. It does not contain any 
        % valid preamble and therefore nothing more can be done for it. 
		% 将该通道排除 
        activeChnList = setdiff(activeChnList, channelNr); 
         
        disp(['无法在通道', ... 
                                                  num2str(channelNr),'找到子帧!']); 
    end 
     
end % for channelNr = activeChnList