forked from fantasua/PolarCodesMatLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrc_check.m
34 lines (31 loc) · 856 Bytes
/
crc_check.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function result=crc_check(x,G)
%CRC校验函数
%x为待校验的CRC码字,G为CRC生成多项式
crc_length=length(G); %CRC生成多项式的长度
code_length=length(x);
quotient=[]; %商多项式
remainder=[]; %余数多项式
register=[]; %计算时使用的临时向量
for k=1:code_length-crc_length+1
if k==1
register=x(1:crc_length);
else
register(1:crc_length-1)=remainder;
register(crc_length)=x(k+crc_length-1);
end
if register(1)~=1
quotient(k)=0;
remainder=register(2:crc_length);
continue
else
quotient(k)=1;
temp=bitxor(register,G);
remainder=temp(2:crc_length);
end
end
if(sum(remainder)==0)
result=0;
else
result=1;
end
end