Matlab Code Functions Used I.) CRC Modulo 2 Division: Function
Matlab Code Functions Used I.) CRC Modulo 2 Division: Function
Functions used
i.)CRC modulo 2 division
function rem=crcdiv(data_d,gen)
msgs=size_t(data_d,2);
ds=size_t(gen,2);
temp=0;
rem=0;
for i=1:msgs
temp = ( bitsrl(uint16(data_d),msgs-i) );
temp=mod(temp,2);
rem=bitsll(uint16(rem),1);
rem=rem+double(temp);
if(size_t(rem,2) == ds)
rem=bitxor(rem,gen);
end
end
');
gen_d=gen_d+gen(i)*w;
w=w*2;
end
code=input('Enter the code word received ');
code_d=0;
w=1;
for i=length(code):-1:1
code_d=code_d+code(i)*w;
w=w*2;
end
for i=1:n
dtab(i)=crcdiv(2^(i-1),gen_d);
%disp(dtab(i))
end
syn=crcdiv(code_d,gen_d);
if(syn==0)
disp('No errors in received codeword')
end
for i=1:n
if(dtab(i)==syn)
fprintf('Bit error at position %d\n',n-i+1);
end
end
OUTPUT
Cyclic encoder
i.)Data word [1 0 0 1]
Enter n 7
Enter k 4
Enter the data word [1 0 0 1]
Generator:
1011
Code word generated:
1001110
OUTPUT:
Cyclic decoder
i.) Received Codeword : 1001110
Original Codeword : 1001110
Enter n 7
Enter k 4
Enter the generator [1 0 1 1]
Enter the code word received [1 0 0 1 1 1 0]
No errors in received codeword
ii.) Received Codeword : 1001010
Original Codeword : 1001110
Enter n 7
Enter k 4
Enter the generator [1 0 1 1]
Enter the code word received [1 0 0 1 0 1 0]
Bit error at position 5