⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc_decode.m

📁 WCDMA Release-7系统的CRC译码
💻 M
字号:
function [data1,CrcCheck] = crc_decode(Input,CrcLength)
%function [data,CrcCheck] = crc_decode(Input,CrcLength);
%Copyright huwenli,ZTE 
% Parameters
%   Input
%      Input          matrix   (0,1)matrix,nrow=block number,
%                               每一行代表一个传输块,得出一个CrcCheck
%      CrcLength      scalar   CRC length
%   Output
%      data           matrix   de crc data sources matrix,nrow=block number,
%                               每一行代表一个传输块
%      CrcCheck      vecotor   行向量输出,长度等于传输块数

% This model do crccheck ,reverse operate of crc_encode
%length(input)=length(data)+crclength;
%CRC24: gcrc24(D)=D24+D23+D6+D5+D+1;
%CRC16: gcrc16(D)=D16+D12+D5+1;
%CRC12: gcrc12(D)=D12+D11+D3+D2+D+1;
%CRC8: gcrc8(D)=D8+D7+D4+D3+D+1;
switch CrcLength
    case 8
        g=[1 1 0 1 1 0 0 1];%inint the state g,from g(0),g(7),no g(8). write as g(1) ..g(8)
    case 12
        g=[1 1 1 1 0 0 0 0 0 0 0 1];
    case 16
        g=[1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0];
    case 24
        g=[1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1];
    otherwise 
        error(['CrcLength = ',CrcLength,': CrcLength must be a 8,12,16,24'])
end
%对各个传输块分别进行
CrcCheck=zeros(1,size(Input,1));
for n=1:size(Input,1)
    %separate the data bits and the crc bits from the input sequence 
    data = Input(n,1:(length(Input)-CrcLength));
    crc_received = Input(n,(length(Input)-CrcLength)+1:length(Input));
    %Re-crcencode on the separated data bits,just as the crcencoded function
    shift=zeros(1,CrcLength);%inint the start shift,from shift(0),shift(7),write as shift(1) ..shift(8)
    for i = 1:length(data)
        feedback = xor(data(i),shift(CrcLength));
        %shift left 1 bit 
        shift=[shift(CrcLength) shift(1:CrcLength-1)];%是循环移位
        %XOR in the position g=1
        shift(find(g==1))=xor(shift(find(g==1)),feedback);
        shift(1)=feedback;%shift(0) write as shift(1)
    end
    %compare the separated bits and reproduced crcbits to do crccheck
    if(sum(xor(shift,crc_received))==0)
        CrcCheck(n) = 0;
    else
        CrcCheck(n) = 1;%means wrong
    end
    data1(n,:) = data;
end

⌨️ 快捷键说明

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