from
CRC control simulation
by Suayb Arslan
This simulation is intended to decide whether or not a given GP accomplishes the targeted task.
|
| crccontrol.m |
% The following program is written to simulate a randomly generated message
% under BSC(p) channel. It examines whether or not the generator polynomial
% to be strong enough to be used at a given packet size and crossover probability p.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% I recommend you guyz run 2-3 times at least to make sure about the final
% decision whether or not the generator polynimal is strong enough for a
% given BSC(p). This is because there is always a chance where the error
% pattern cannot be detected by the CRC.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For CRC appendance, I heavily suggest you take a look at:
% REFERENCE: DATA and COMPUTER COMMUNICATIONS by WILLIAM STALLINGS 7th Edition Prentice Hall 2004.
% -Academic Use ONLY-
% S. S. Arslan UC San Diego Wireless Comm Lab.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all%These commands can be removed depending on what purpose you use the script for.
packetsize=512;%Determine the packet size you use.
msg=floor(rand(1,packetsize).*2); % generate the data bits
%SEVERAL CRC`s are given below to help give you a flavour.
%poly=[1 1 0 0 0 0 0 0 0 1 1 1 1]; %Generate ploynomial CRC-12 used in telecom systems
poly=[1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0]; %CRC-16-CCIT used in CDMA Bluettooth etc
%poly=[1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1]; %CRC-32 IEEE 802.3 also in MPEG-2.
[x y]=size(poly); %Find the size
m=[msg zeros(1,y-1)]; %Pad 0s!
[q r]=deconv(m,poly); %find quotient and remainder
r=mod(abs(r),2);
crc=r(length(msg)+1:end);%find the corresponding CRC
newm=[msg crc];%New mesagge is constructed! Ready to send over the channel -->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%CHANNEL: Put thru a BSC with cross over probability p
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:length(newm)
if rand(1)<0.05 %let us take the cross over probability to be 1/20.
newmod(i)= mod(newm(i)+1,2); %flip the bits and create a modified version of newm. Use smaller p to challange the CRC!
else
newmod(i)=newm(i); %no change otherwise!
end;
end;
%Now determine whether or not there is an error that CRC is able to capture:
[q r]=deconv(newmod,poly);
%Check the remainder:
r=mod(abs(r),2);
if r == zeros(1,length(newm))
detect=0;% No Error is detected
else
detect=1;% Error is detected
end;
%Now determine whether or not there is ``actually`` an error:
detect2=0;%NO error case!
newmod=newmod(1:length(msg));
for i=1:length(msg)
if msg(i)~=newmod(i)
detect2=1;
end;
end;
if detect~=detect2%Now is the time for a decision!
disp(' CRC/Generator polynomial IS NOT strong enough! ');
else
disp(' CRC/Generator polynomial IS strong enough! ');
end;
|
|
Contact us at files@mathworks.com