function [ output ] = crc_add( input, crc_no )
% the function is proposed for adding crc bits to the input sequence
k = size(input,2);
generator = zeros(1,crc_no + 1);
output = zeros(1,k + crc_no);
switch crc_no
case 3
generator = [1 0 1 1];
case 8
generator = [1 0 0 0 0 0 1 1 1];%D^8+D^2+D+1
%generator = [1 1 0 0 1 1 0 0 1]; %D^8+D^7+D^4+D^3+D+1
%generator = [1 0 0 1 1 1 0 0 1]; %D^8+D^5+D^4+D^3+1
case 12
generator = [1 1 0 0 0 0 0 0 0 1 1 1 1]; %D^12+D^11+D^3+D^2+D+1
case 16
generator = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1];%D^16+D^15+D^2+1
case 24
generator = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1]; %D^24+D^23+d^6+D^5+D+1
case 32
generator = [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];
%D^32+D^26+D^23+D^22+D^16+D^12+D^11+D^10+D^8+D^7+D^5+D^4+D^2+D+1
otherwise
fprintf('\nPlease the number of crc bits should be 8 12 16 24\n');
end
output(1:k) = input;
for ii = 1:k
if(output(1) == 1)
output(1:crc_no + 1) = mod((output(1:crc_no + 1) + generator),2);
end
output = [output(2:end) output(1)];
end
output(1:crc_no);
output = [input output(1:crc_no)];