addcrc.m

来自「小区初搜为GSM系统中的一个关键过程」· M 代码 · 共 39 行

M
39
字号
function output=addcrc(infor,g)
% infor is the input data.
% g is the coefficient array of ploy genarator
% output is the infor added crc codes
% infor = [ 0     0     1     0     1     1     0     0     0     1     1     0  ...
%     0       1    1     0     0     0     1     0     0     0     1     1     1 ];          % for 20070817_13  
%  infor = [  1     0     1     0     1     1     0     0     0     1     0     1 ...
%      1     0     1     0     1     0     0     0     0     0     1     0   0  ];          % for 22  
%   infor = [   1     0     1     0     1     1     0     0     1     0     0     1     0 ...
%      0     1     1     1     0     1     0     1     0     1     0     0    ];          %for  \20070824_35.
% %  infor = [ 1 0 1 1 0 0 1 0 1];
% 
%   infor = [   1     0     1     0     1     1     0     0     1     0     1     1     1 ...
%      0     1     1     0     1     0     0     0     0     1     1     0  ];          %for  \20070824_31.
%  
% g = [1 0 1 0 1 1 1 0 1 0 1];
% g = [1 0 0 1];

a=length(infor);
b=length(g);
x=[infor zeros(1,b-1)]; % add g '0s'to the infor
len=length(x);
for i=1:a
    if x(i)~=0
        x(i:(i+b-1))=xor(x(i:(i+b-1)),g);
    end
end
% output=[infor x((len):(-1):(len-b+2))];
output=[infor x((len-b+2):(len))];
% CRC = [x((len-b+2):(len))]
%  crcr =      [  0    1     0     1     1     1     0     1     1     0 ];    % for 20070817_13  
%  crcr =      [ 1   1     0     0     1     0     0     1     1     0 ];    %for  \20070824_35.
 
%  crcr =      [ 1    0     1     0     1     0     0     0     1     0 ];    %for  \20070824_31.
% 
% % crcr =      [  0     1     1     1     0     0     1     0     1     1 ];    % for 22
% %  crcr =      [    1     1     0     1     0     0     1     1     1     0 ];    % for 22
% xor( CRC,crcr)

⌨️ 快捷键说明

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