File Exchange

image thumbnail

CRC code generator

version 1.0 (1.31 KB) by

Code generates CRC code for any binary data stream & generator polynomial

26 Downloads

Updated

View License

The standard polynomials are not used to make it more flexible.
User provide data stream and generator polynomial.

Comments and Ratings (22)

miao zhang

good job!Once I have had the code for CRC32,how can I input datastream to get my output? thanks for answering,it is the first time that I touch Matlab.

nagaraju

chandrahas

clc;
close all;
clear all;
x = input('enter data word');
y = input('enter pattern word');
p = length(y);
k = length(x);
n = p+k-1;
dw = x;
for z=1:(n-k)
    dw(k+z) = 0;
end
for z=1:p
        td(z)= dw(z);
        tr2(z)=0;
        tr3(z)=1;
end
 tr = xor(td,y);
while(1)
    z=z+1;
    if(z>n)
        break;
    end
   
    tr(p+1)=dw(z);
    for l=2:(p+1)
        tr1(l-1)=tr(l);
    end
    
    tr = tr1;
    if(tr(1)==0)
        tr=xor(tr,tr2);
    else
        tr=xor(tr,y);
    end
end
cd=x;
for z=2:p
    cd(k+z-1)=tr(z);
end
disp(cd);
      

%try this..........

rakesh

rakesh (view profile)

can any one help me to write a code for crc-6 in matlab please

dis my id:rakeshreddy255@gmail.com

regards
rakesh

ATM

ATM (view profile)

grat c> i think your calculation is worng. i hav calculated by hand as well, it gives crc=1 0 0.i think the code is correct.

thanks.

Jochen

Jochen (view profile)

does not working correct for all generator polynomials, see previous comment.
code needs review. See text bosk or wikipedia for correct (pseudo) code

grat c

grat c (view profile)

i used wiki's example to check for its correctness:
http://en.wikipedia.org/wiki/Cyclic_redundancy_check#Computation_of_CRC

msg = [1 1 0 1 0 0 1 1 1 0 1 1 0 0]; poly = [1 0 1 1];
the program gives r = 1 0 0

i've also tried to do the XORs by hand...
i found it is indeed 1 0 1, not sure where goes wrong

Jo Mateix

Was great! Thanks!

Glen Klein

Communication toolbox is not required. Another reviewer (Andrea Silvestri) is right: "the for cycle could be replaced with on single line: r=mod(r,2) "

li ming

hao

Rudheesh Raghav

Good Work..

I feel the for loop is not required..

Andrea Silvestri

Maybe the for cycle could be replaced with on single line: r=mod(r,2)

N Fine

unstable and slow with long input vectors - better do everything above Z(2)

Mohsin Shaikh )

mona sherdiwala

fred uit vosselaar

good code works fine for me. thanks a lot

jef al

your code can only work if the number of data streams are below 360 bits. any higher bits gives error. using GFCONV method works fine

sundas zahid

yeah the code is good but but it can be modified as to the input can be made real time....

daty daty

I need CRC-32 in my simulations.
Should I take this script and change
the generator polynomial to find it ??

Ahmad Wazzi

Easy to follow. For the previous comment, please understand how CRC is done and you will find the code straight forward. Code is self explanatory.

Jos x@y.z

How do ever expect someone to use this code succesfully if you do not provide any help whatsoever.

Moreover, this is a script that may override existing variables ...

MATLAB Release
MATLAB 7.0.4 (R14SP2)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video