GPS导航电文 IODC

function [eph, TOW] = ephemeris(bits, D30Star)
%Function decodes ephemerides and TOW from the given bit stream. The stream
%(array) in the parameter BITS must contain 1500 bits. The first element in
%the array must be the first bit of a subframe. The subframe ID of the
%first subframe in the array is not important.
%
%Function does not check parity!
%
%[eph, TOW] = ephemeris(bits, D30Star)
%
%   Inputs:
%       bits        - bits of the navigation messages (5 subframes).
%                   Type is character array and it must contain only
%                   characters '0' or '1'.
%       D30Star     - The last bit of the previous nav-word. Refer to the
%                   GPS interface control document ICD (IS-GPS-200D) for
%                   more details on the parity checking. Parameter type is
%                   char. It must contain only characters '0' or '1'.
%   Outputs:
%       TOW         - Time Of Week (TOW) of the first sub-frame in the bit
%                   stream (in seconds)
%       eph         - SV ephemeris

%--------------------------------------------------------------------------
%                           SoftGNSS v3.0
% 
% Copyright (C) Darius Plausinaitis and Kristin Larson
% Written by Darius Plausinaitis and Kristin Larson
%--------------------------------------------------------------------------
%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: ephemeris.m,v 1.1.2.7 2006/08/14 11:38:22 dpl Exp $


%% Check if there is enough data ==========================================
if length(bits) < 1500
    error('The parameter BITS must contain 1500 bits!');
end

%% Check if the parameters are strings ====================================
if ~ischar(bits)
    error('The parameter BITS must be a character array!');
end

if ~ischar(D30Star)
    error('The parameter D30Star must be a char!');
end

% Pi used in the GPS coordinate system
gpsPi = 3.1415926535898; 

%% Decode all 5 sub-frames ================================================
for i = 1:5%5个子帧,每个子帧300比特

    %--- "Cut" one sub-frame's bits ---------------------------------------
    subframe = bits(300*(i-1)+1 : 300*i);

    %--- Correct polarity of the data bits in all 10 words ----------------
    for j = 1:10%每个子帧10个字,每个字30比特
        [subframe(30*(j-1)+1 : 30*j)] = ...
            checkPhase(subframe(30*(j-1)+1 : 30*j), D30Star);
        
        D30Star = subframe(30*j);
    end
%收到的D,要恢复d,d为原始信息比特
    %--- Decode the sub-frame id ------------------------------------------
    % For more details on sub-frame contents please refer to GPS IS.
    subframeID = bin2dec(subframe(50:52));%交接字HOW的第20-22比特是子帧识别标志
    %其共有5个有效二进制值,001表示该子帧是第一子帧,以此类推。。。

    %--- Decode sub-frame based on the sub-frames id ----------------------
    % The task is to select the necessary bits and convert them to decimal
    % numbers. For more details on sub-frame contents please refer to GPS
    % ICD (IS-GPS-200D).
    switch subframeID
        case 1  %--- It is subframe 1 -------------------------------------
            % It contains WN, SV clock corrections, health and accuracy
            eph.weekNumber  = bin2dec(subframe(61:70)) + 1024;
            %每一子帧的第三个字的前10位,即Z计数器的高10位,指示当前GPS星期
            %因为星期数最大为2……10-1=1023,其计时起点可能不是这次星期数循环
            %的起点,所以就加1024了
            eph.accuracy    = bin2dec(subframe(73:76));
            %用户测距精度,是对有GPS地面监控部分和空间星座部分引起的误差的一个
            %统计值,值越大表示测距值精度越低。N=15时,此时用户要自己承担使用该卫星的风险
            eph.health      = bin2dec(subframe(77:82));
            %卫星健康状况,最高位为0表示完全正确,为1表示出错了,低5位指示出错情况
            eph.T_GD        = twosComp2dec(subframe(197:204)) * 2^(-31);
            %T_GD群波延时校正值
           
            eph.IODC        = bin2dec([subframe(83:84) subframe(197:204)]);
            %IODC时钟数据期号。一个IODC值对应一套时钟校正参数
            %IODC至少7天不会重复,是连续变化的。依据IODC值是否变化,判断卫星是否更新时钟校正参数;
            %若没变化,则不必每30s去重复读解这一数据块中的时钟校正参数
            eph.t_oc        = bin2dec(subframe(219:234)) * 2^4;
            %t_oc是第一数据块的参考时间,它在时钟校正模型中被用作时间参考点
            eph.a_f2        = twosComp2dec(subframe(241:248)) * 2^(-55);
            eph.a_f1        = twosComp2dec(subframe(249:264)) * 2^(-43);
            eph.a_f0        = twosComp2dec(subframe(271:292)) * 2^(-31);
            %a_f0f1f2是卫星时钟校正模型方程中的三个系数
            
        case 2  %--- It is subframe 2 -------------------------------------
            % It contains first part of ephemeris parameters
            eph.IODE_sf2    = bin2dec(subframe(61:68));
            %星历数据期号,6小时之内不会出现重复类似于上面IODC
            eph.C_rs        = twosComp2dec(subframe(69: 84)) * 2^(-5);
            %轨道半径的正弦调和修正项的幅度
            eph.deltan      = ...
                twosComp2dec(subframe(91:106)) * 2^(-43) * gpsPi;
            %计算值的平均移动误差
            eph.M_0         = ...
                twosComp2dec([subframe(107:114) subframe(121:144)]) ...
                * 2^(-31) * gpsPi;
            %t_oe时的平近地点
            eph.C_uc        = twosComp2dec(subframe(151:166)) * 2^(-29);
           %升交点角距余弦调和校正振幅
            eph.e           = ...
                bin2dec([subframe(167:174) subframe(181:204)]) ...
                * 2^(-33);
            %轨道偏心率
            eph.C_us        = twosComp2dec(subframe(211:226)) * 2^(-29);
          %升交点角距正弦调和校正振幅
            eph.sqrtA       = ...
                bin2dec([subframe(227:234) subframe(241:264)]) ...
                * 2^(-19);
            %轨道长半轴的平方根
            eph.t_oe        = bin2dec(subframe(271:286)) * 2^4;
           %星历参考时间
        case 3  %--- It is subframe 3 -------------------------------------
            % It contains second part of ephemeris parameters
            eph.C_ic        = twosComp2dec(subframe(61:76)) * 2^(-29);
            %倾斜角的余弦调和修正项的幅度
            eph.omega_0     = ...
                twosComp2dec([subframe(77:84) subframe(91:114)]) ...
                * 2^(-31) * gpsPi;
            %在每星期历元轨道平面上的升点经度
            eph.C_is        = twosComp2dec(subframe(121:136)) * 2^(-29);
           %倾斜角的正弦调和修正项的幅度
            eph.i_0         = ...
                twosComp2dec([subframe(137:144) subframe(151:174)]) ...
                * 2^(-31) * gpsPi;
            %参考时间的轨道倾角
            eph.C_rc        = twosComp2dec(subframe(181:196)) * 2^(-5);
           %轨道半径的正弦调和修正项的幅度
            eph.omega       = ...
                twosComp2dec([subframe(197:204) subframe(211:234)]) ...
                * 2^(-31) * gpsPi;
          %近地点的辐角
            eph.omegaDot    = twosComp2dec(subframe(241:264)) * 2^(-43) * gpsPi;
            %赤经的速率
            eph.IODE_sf3    = bin2dec(subframe(271:278));
            %数据与星历发布号
            eph.iDot        = twosComp2dec(subframe(279:292)) * 2^(-43) * gpsPi;
            %倾斜角的速率
        case 4  %--- It is subframe 4 -------------------------------------
            % Almanac, ionospheric model, UTC parameters.
            % SV health (PRN: 25-32).
            % Not decoded at the moment.

        case 5  %--- It is subframe 5 -------------------------------------
            % SV almanac and health (PRN: 1-24).
            % Almanac reference week number and time.
            % Not decoded at the moment.

    end % switch subframeID ...

end % for all 5 sub-frames ...

%% Compute the time of week (TOW) of the first sub-frames in the array ====
% Also correct the TOW. The transmitted TOW is actual TOW of the next
% subframe and we need the TOW of the first subframe in this data block
% (the variable subframe at this point contains bits of the last subframe). 
TOW = bin2dec(subframe(31:47)) * 6 - 30;
%乘以6得到下一子帧起始的GPS时间,减6是当前子帧的GPS时间,减30为啥阿阿  
%我知道了。这里得到TOW用的子帧是第五个子帧,所以得到的下一子帧起始时间是第6子帧的
%起始时间,-30s,是得到接收到的第一子帧的开始时间。

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值