Created
January 19, 2016 09:06
-
-
Save MrWooJ/aae4c4ab6d7294e52fff to your computer and use it in GitHub Desktop.
WJMatlab-CRC Error-Detecting Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clc; | |
clear all; | |
close all; | |
pattern = [1 0 0 0 0 0 1 1 1]; | |
dataWord = [0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; | |
dataDisplay = num2str(dataWord); | |
dataDisplay(isspace(dataDisplay)) = ''; | |
patternDisplay = num2str(pattern); | |
patternDisplay(isspace(patternDisplay)) = ''; | |
figure('Menu','none','Position', [250, 400, 1000, 300]); | |
text(0.39, 1, 'DATA WORD', 'Rotation',0, 'FontSize',20, 'Color','red'); | |
text(0, 0.85, dataDisplay, 'Rotation',0, 'FontSize',17, 'Color','black'); | |
text(0.41, 0.65, 'PATTERN', 'Rotation',0, 'FontSize',20, 'Color','red'); | |
text(0.42, 0.5, patternDisplay, 'Rotation',0, 'FontSize',18, 'Color','black'); | |
axis off | |
[first last] = size(pattern); | |
extendingDataWord = [dataWord zeros(1, last-1)]; | |
[quotient reminder] = deconv(extendingDataWord,pattern); | |
reminder = abs(reminder); | |
for i = 1 : length(reminder) | |
first = reminder(i); | |
if mod(first, 2) == 0 | |
reminder(i) = 0; | |
else | |
reminder(i) = 1; | |
end | |
end | |
crcReminderArray = reminder(length(dataWord)+1 : end); | |
codeWord = bitor(extendingDataWord, reminder); | |
output = num2str(codeWord); | |
output(isspace(output)) = ''; | |
text(0.39, 0.3, 'CODE WORD', 'Rotation',0, 'FontSize',20, 'Color','red'); | |
text(-0.1, 0.15, output, 'Rotation',0, 'FontSize',18, 'Color','black'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment