www.pudn.com > GNSS_SDR.zip > acquisition.asv, change:2010-02-03,size:12300b


function acqResults = acquisition(longSignal, settings) 
%Function performs cold start acquisition on the collected "data". It 
%searches for GPS signals of all satellites, which are listed in field 
%"acqSatelliteList" in the settings structure. Function saves code phase 
%and frequency of the detected signals in the "acqResults" structure. 
%根据‘data’的数据开始冷启动捕获,搜索settings.acqSatelliteList中 
%所有GPS卫星。最终将码相位和载波频率存入acqResults结构体中 
% 
%acqResults = acquisition(longSignal, settings) 
% 
%   Inputs: 
%    
%       longSignal		- 11 ms of raw signal from the front-end  
%                       - 11ms的中频数据 
%       settings		- Receiver settings. Provides information about 
%                       sampling and intermediate frequencies and other 
%                       parameters including the list of the satellites to 
%                       be acquired. 
%                       - 初始设置 
%   Outputs: 
%       acqResults		- Function saves code phases and frequencies of the  
%                       detected signals in the "acqResults" structure. The 
%                       field "carrFreq" is set to 0 if the signal is not 
%                       detected for the given PRN number.  
%                       - 其中包括码相位和载波频率,不可见星设置为0 
  
%-------------------------------------------------------------------------- 
%                           SoftGNSS v3.0 
%  
% Copyright (C) Darius Plausinaitis and Dennis M. Akos 
% Written by Darius Plausinaitis and Dennis M. Akos 
% Based on 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: acquisition.m,v 1.1.2.12 2006/08/14 12:08:03 dpl Exp $ 
 
%% Initialization 初始化========================================================= 
 
% Find number of samples per spreading code 
% 每个码长对应的采样点数量 
samplesPerCode = round(settings.samplingFreq / ... 
                        (settings.codeFreqBasis / settings.codeLength)); 
 
% Create two 1msec vectors of data to correlate with and one with zero DC 
% 产生两个1ms的数据进行相关,并且产生一组直流输入 
signal1 = longSignal(1 : samplesPerCode); 
signal2 = longSignal(samplesPerCode+1 : 2*samplesPerCode); 
 
signal0DC = longSignal - mean(longSignal);  
 
% Find sampling period 
% 采样周期 
ts = 1 / settings.samplingFreq; 
 
% Find phase points of the local carrier wave  
% 本地载波采样点 %% 用于生成当地载波 sin(phasePoints);cos(phasePoints)_XR 
phasePoints = (0 : (samplesPerCode-1)) * 2 * pi * ts;  
 
% Number of the frequency bins for the given acquisition band (500Hz steps) 
% 载波频率搜索点(步长500Hz) %=(14000/500)+1_XR; acqSearchBand*1000/500+1 
numberOfFrqBins = round(settings.acqSearchBand * 2) + 1; 
 
% Generate all C/A codes and sample them according to the sampling freq. 
% 产生C/A码并根据采样频率对其进行采样 
caCodesTable = makeCaTable(settings); 
 
 
%--- Initialize arrays to speed up the code 初始化向量---------------------- 
% Search results of all frequency bins and code shifts (for one satellite) 
% 单一卫星的搜索结果(所有频率和码偏移) 
results     = zeros(numberOfFrqBins, samplesPerCode); 
 
% Carrier frequencies of the frequency bins 
% 需要搜索的载波频率 
frqBins     = zeros(1, numberOfFrqBins); 
 
 
%--- Initialize acqResults 初始化捕获结果----------------------------------- 
% Carrier frequencies of detected signals 
% 32颗卫星的载波频率 
acqResults.carrFreq     = zeros(1, 32); 
% C/A code phases of detected signals 
% 32颗卫星的C/A码相位 
acqResults.codePhase    = zeros(1, 32); 
% Correlation peak ratios of the detected signals 
% 32颗卫星的相关峰值比率 
acqResults.peakMetric   = zeros(1, 32); 
 
fprintf('('); 
 
% Perform search for all listed PRN numbers ... 
% 对所有列出的卫星进行搜索 ... 
for PRN = settings.acqSatelliteList 
 
%% Correlate signals 对信号进行相关========================================= 
    %--- Perform DFT of C/A code ------------------------------------------ 
    %--- C/A码FFT共轭 ----------------------------------------------------- 
    caCodeFreqDom = conj(fft(caCodesTable(PRN, :))); 
 
    %--- Make the correlation for whole frequency band (for all freq. bins) 
    %--- 对各个频率进行相关 ------------------------------------------------ 
    for frqBinIndex = 1:numberOfFrqBins 
 
        %--- Generate carrier wave frequency grid (0.5kHz step) ----------- 
        %--- 产生载波频率(步长500Hz) --------------------------------------     
        % 在IF左右搜索7kHz_XR 
        frqBins(frqBinIndex) = settings.IF - ... 
                               (settings.acqSearchBand/2) * 1000 + ... % 单位从kHz转换到Hz 
                               0.5e3 * (frqBinIndex - 1);  %非对称? 
 
        %--- Generate local sine and cosine ------------------------------- 
        %--- 产生本地载波(sin & cos) ------------------------------------- 
        sinCarr = sin(frqBins(frqBinIndex) * phasePoints); 
        cosCarr = cos(frqBins(frqBinIndex) * phasePoints); 
 
        %--- "Remove carrier" from the signal ----------------------------- 
        %--- 解调 --------------------------------------------------------- 
        I1      = sinCarr .* signal1; 
        Q1      = cosCarr .* signal1; 
        I2      = sinCarr .* signal2; 
        Q2      = cosCarr .* signal2; 
 
        %--- Convert the baseband signal to frequency domain -------------- 
        %--- 输入信号变换入频域 --------------------------------------------- 
        IQfreqDom1 = fft(I1 + j*Q1); 
        IQfreqDom2 = fft(I2 + j*Q2); 
 
        %--- Multiplication in the frequency domain (correlation in time 
        %domain) ---------------------------------------------------------- 
        %--- 频域相乘(时域相关) ------------------------------------------- 
        convCodeIQ1 = IQfreqDom1 .* caCodeFreqDom; 
        convCodeIQ2 = IQfreqDom2 .* caCodeFreqDom; 
 
        %--- Perform inverse DFT and store correlation results ------------ 
        %--- IDFT并保存相关结果 -------------------------------------------- 
        acqRes1 = abs(ifft(convCodeIQ1)) .^ 2; 
        acqRes2 = abs(ifft(convCodeIQ2)) .^ 2; 
         
        %--- Check which msec had the greater power and save that, will 
        %"blend" 1st and 2nd msec but will correct data bit issues -------- 
        %--- 选择相邻信号的较大值(解决数据位变化引起的问题) ----------------- 
        if (max(acqRes1) > max(acqRes2)) 
            results(frqBinIndex, :) = acqRes1; 
        else 
            results(frqBinIndex, :) = acqRes2; 
        end 
         
    end % frqBinIndex = 1:numberOfFrqBins  
 
%% Look for correlation peaks in the results 选择结果中的相关峰值============ 
    % Find the highest peak and compare it to the second highest peak 
    % The second peak is chosen not closer than 1 chip to the highest peak 
    % 找到最高峰值并和次高值比较(次高值不能和最高值相邻一个码片内) 
     
    %--- Find the correlation peak and the carrier frequency -------------- 
    %--- 寻找相关峰值和载波频率 ---------------------------------------------     
    [peakSize frequencyBinIndex] = max(max(results, [], 2));  % 列检测 
 
    %--- Find code phase of the same correlation peak --------------------- 
    %--- 选择相关峰对应的码相位 --------------------------------------------- 
    [peakSize codePhase] = max(max(results));  % 行检测 
 
    %--- Find 1 chip wide C/A code phase exclude range around the peak ---- 
    %--- 找到相关峰值一码片以外的码相位 -------------------------------------- 
    samplesPerCodeChip   = round(settings.samplingFreq / settings.codeFreqBasis); 
    excludeRangeIndex1 = codePhase - samplesPerCodeChip; 
    excludeRangeIndex2 = codePhase + samplesPerCodeChip; 
 
    %--- Correct C/A code phase exclude range if the range includes array 
    %boundaries ----------------------------------------------------------- 
    %--- 修正相关峰值一码片以外的码相位 -------------------------------------- 
    if excludeRangeIndex1 < 2 
        codePhaseRange = excludeRangeIndex2 : ... 
                         (samplesPerCode + excludeRangeIndex1); 
                          
    elseif excludeRangeIndex2 >= samplesPerCode 
        codePhaseRange = (excludeRangeIndex2 - samplesPerCode) : ... 
                         excludeRangeIndex1; 
    else 
        codePhaseRange = [1:excludeRangeIndex1, ... 
                          excludeRangeIndex2 : samplesPerCode]; 
    end 
 
    %--- Find the second highest correlation peak in the same freq. bin --- 
    %--- 找到次峰值 -------------------------------------------------------- 
    secondPeakSize = max(results(frequencyBinIndex, codePhaseRange)); 
 
    %--- Store result ----------------------------------------------------- 
    %--- 保存结果 ---------------------------------------------------------- 
    acqResults.peakMetric(PRN) = peakSize/secondPeakSize; 
     
    % If the result is above threshold, then there is a signal ... 
    % 超过门限,则卫星可见 ... 
    if (peakSize/secondPeakSize) > settings.acqThreshold 
 
%% Fine resolution frequency search 精频捕获========== 
         
        %--- Indicate PRN number of the detected signal ------------------- 
        %--- 显示可见星号码 ------------------------------------------------ 
        fprintf('%02d ', PRN); 
         
        %--- Generate 10msec long C/A codes sequence for given PRN -------- 
        %--- 产生10msC/A码 ------------------------------------------------ 
        caCode = generateCAcode(PRN); 
         
        codeValueIndex = floor((ts * (1:10*samplesPerCode)) / ... 
                               (1/settings.codeFreqBasis)); 
                            
        longCaCode = caCode((rem(codeValueIndex, 1023) + 1)); 
     
        %--- Remove C/A code modulation from the original signal ---------- 
        % (Using detected C/A code phase) 
        %--- 根据码相位解调掉原始信号的C/A码 -------------------------------- 
        xCarrier = ... 
            signal0DC(codePhase:(codePhase + 10*samplesPerCode-1)) ... 
            .* longCaCode; 
         
        %--- Find the next highest power of two and increase by 8x -------- 
        %--- 找到最近的2的指数次位数并以8×步长采样(方便后续FFT和频率解算) --- 
        fftNumPts = 8*(2^(nextpow2(length(xCarrier)))); 
         
        %--- Compute the magnitude of the FFT, find maximum and the 
        %associated carrier frequency ------------------------------------- 
        %--- 计算频谱并求出对应载波频率 ------------------------------------- 
        fftxc = abs(fft(xCarrier, fftNumPts));  
         
        uniqFftPts = ceil((fftNumPts + 1) / 2); 
        [fftMax, fftMaxIndex] = max(fftxc(5 : uniqFftPts-5)); 
         
        fftFreqBins = (0 : uniqFftPts-1) * settings.samplingFreq/fftNumPts; 
         
        %--- Save properties of the detected satellite signal ------------- 
        %--- 保存可见卫星信号捕获结果 --------------------------------------- 
        acqResults.carrFreq(PRN)  = fftFreqBins(fftMaxIndex); 
        acqResults.codePhase(PRN) = codePhase; 
     
    else 
        %--- No signal with this PRN -------------------------------------- 
        %--- 不可见 ------------------------------------------------------- 
        fprintf('. '); 
    end   % if (peakSize/secondPeakSize) > settings.acqThreshold 
     
end    % for PRN = satelliteList 
 
%=== Acquisition is over 捕获结束=========================================== 
fprintf(')\n');