Skip to content

Instantly share code, notes, and snippets.

@jsantanders
Created November 27, 2016 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsantanders/c183d7dcb0e2e1749fec2d3b15320cb2 to your computer and use it in GitHub Desktop.
Save jsantanders/c183d7dcb0e2e1749fec2d3b15320cb2 to your computer and use it in GitHub Desktop.
cyclic redundancy check MATLAB implementation
function CRC = mod2 (word, G)
m = zeros (1,length(G));
wordext = [word m];
while length (G) <= length (wordext)
for i = 1:length(G)
wordext(i) = xor(wordext(i),G(i));
end
while wordext(1) == 0
wordext = wordext(2:end);
if not (wordext)
wordext = 0;
break
end
end
end
CRC = [zeros(1:length(G)-length(wordext)) wordext];
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment