crcbitnew.m

来自「gsm的物理层仿真实现」· M 代码 · 共 50 行

M
50
字号
%****************************************************************
% 内容概述:the whole process of new_CRC defined in GSM
% 创 建 人:李彩
% 单    位:Starpoint
% 创建时间:2008年
%参考TS 45.003
%****************************************************************
function crcoutput=newcrcbit(data,CRCNo)
len_crc = size(data,2);
switch (CRCNo)
case 3,
    crcpoly=[1 0 1 1];
case 6,
    crcpoly=[1 1 0 1 1 1 1];
case 10,
    crcpoly=[1 0 1 0 1 1 1 0 1 0 1];
case 40,
    crcpoly = zeros[1,41];
    crcpoly(1) = 1;
    crcpoly(15) = 1;
    crcpoly(18) = 1;
    crcpoly(24) = 1;
    crcpoly(38) = 1;
    crcpoly(41) = 1;    
otherwise,
    disp('CRC位数错误!请重新调用函数');
end
%crcdata=[data zeros(1,CRCNo)];       
temp(1:len_crc)=data;
temp(len_crc+1:len_crc+CRCNo) = 0;
for ii=1:(len_crc)
    
    temp(ii:ii+CRCNo)=mod(temp(ii:ii+CRCNo)+temp(ii)*crcpoly,2);
    
    %  temp=[temp(2:CRCNo+1),crcdata(ii+CRCNo+1)];
end
switch(CRCNo)
    case 3,
        parity = bitxor(temp(len_crc+1:len_crc+CRCNo),[1 1 1]);
    case 6,
        parity = bitxor(temp(len_crc+1:len_crc+CRCNo),[1 1 1 1 1 1]);
    case 10,
        parity = bitxor(temp(len_crc+1:len_crc+CRCNo),[1 1 1 1 1 1 1 1 1 1]);
    case 40,
        a(1:40) = 1;
        parity = bitxor(temp(len_crc+1:len_crc+CRCNo),a);
    otherwise,
    disp('CRC位数错误!请重新调用函数');
end    
crcoutput = [data,parity];

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?