www.pudn.com > GNSS_SDR.zip > probeData.m, change:2010-04-01,size:4729b


function probeData(varargin) 
%Function plots raw data information: time domain plot, a frequency domain 
%plot and a histogram.  
%绘制原始数据情况:时域波形、功率谱、以及柱状图 
% 
%The function can be called in two ways: 
%调用形式有两种: 
%   probeData(settings) 
% or 
%   probeData(fileName, settings) 
% 
%   Inputs: 
%       fileName        - name of the data file. File name is read from 
%                       settings if parameter fileName is not provided. 
%                       - 数据文件路径,如果未定义则使用Settings所定义的路径 
% 
%       settings        - receiver settings. Type of data file, sampling 
%                       frequency and the default filename are specified 
%                       here.  
%                       - 初始设置。本函数使用了数据格式、采样频率和文件路径等 
 
%-------------------------------------------------------------------------- 
%                           SoftGNSS v3.0 
%  
% Copyright (C) Dennis M. Akos 
% Written by Darius Plausinaitis and Dennis M. Akos 
% 注释翻译:苗剑峰 
%-------------------------------------------------------------------------- 
%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: probeData.m,v 1.1.2.7 2006/08/22 13:46:00 dpl Exp $ 
 
%% Check the number of arguments 函数参数检测 ============================== 
if (nargin == 1) 
    settings = deal(varargin{1}); 
    fileNameStr = settings.fileName; 
elseif (nargin == 2) 
    [fileNameStr, settings] = deal(varargin{1:2}); 
    if ~ischar(fileNameStr) 
        error('文件路径必须是字符串'); 
    end 
else 
    error('函数参数错误'); 
end 
     
%% Generate plot of raw data 开始绘图 ====================================== 
[fid, message] = fopen(fileNameStr, 'rb'); 
 
if (fid > 0) 
    % Move the starting point of processing. Can be used to start the 
    % signal processing at any point in the data record (e.g. for long 
    % records). 
    % 跳过开头 
    fseek(fid, settings.skipNumberOfBytes, 'bof');     
     
    % Find number of samples per spreading code 
    % 每个码长对应的采样点数量:(每秒采样点数[个/秒])*(一个码宽[秒]) 
    %                           码宽=1/(码率[码片/秒]/码长[码片]) 
    samplesPerCode = round(settings.samplingFreq / ... 
                           (settings.codeFreqBasis / settings.codeLength)); 
                       
    % Read 10ms of signal 
    % 读10ms数据 
    [data, count] = fread(fid, [1, 10*samplesPerCode], settings.dataType); 
     
    fclose(fid); 
     
    if (count < 10*samplesPerCode) 
        % The file is to short 
        % 文件太短 
        error('文件太小,无法读取足够信息.'); 
    end 
     
    %--- Initialization 初始化 --------------------------------------------- 
    figure(100); 
    clf(100); 
     
    timeScale = 0 : 1/settings.samplingFreq : 5e-3;     
     
    %--- Time domain plot 时域波形 ----------------------------------------- 
    subplot(2, 2, 1); 
    plot(1000 * timeScale(1:round(samplesPerCode/50)), ... 
         data(1:round(samplesPerCode/50))); 
      
    axis tight; 
    grid on; 
    title ('时域波形'); 
    xlabel('时间 (ms)'); ylabel('幅值'); 
     
    %--- Frequency domain plot 功率谱- ------------------------------------ 
    subplot(2,2,2); 
    % 用Welch法估计功率谱密度  
    pwelch(data-mean(data), 16384, 1024, 2048, settings.samplingFreq/1e6) 
     
    axis tight; 
    grid on; 
    title ('功率谱'); 
    xlabel('频率 (MHz)'); ylabel('幅值'); 
     
    %--- Histogram 柱状图 -------------------------------------------------- 
    subplot(2, 2, 3.5); 
    hist(data, -128:128) 
     
    dmax = max(abs(data)) + 1; 
    axis tight; 
    adata = axis; 
    axis([-dmax dmax adata(3) adata(4)]); 
    grid on; 
    title ('幅值统计柱状图');  
    xlabel('幅值'); ylabel('出现次数'); 
else 
    %=== Error while opening the data file 文件打开错误 ==================== 
    error('无法读取文件%s: %s.', fileNameStr, message); 
end % if (fid > 0)