clc;
clear;
close all;
k = 3;
n = 6;
G = [1 0 0 1 1 1;
0 1 0 0 1 1;
0 0 1 1 1 0];
fprintf('Generator Matrix G =\n');
disp(G);
P = G(:,k+1:n);
fprintf('Parity Matrix P =\n');
disp(P);
H = [P' eye(n-k)];
fprintf('Parity Check Matrix H =\n');
disp(H);
check = mod(G * H',2);
fprintf('G * H'' mod 2 =\n');
disp(check);
d = [1 0 1];
c = mod(d * G,2);
fprintf('Message Bits d =\n');
disp(d);
fprintf('Codeword c =\n');
disp(c);
Generator Matrix G =
1 0 0 1 1 1
0 1 0 0 1 1
0 0 1 1 1 0
Parity Matrix P =
1 1 1
0 1 1
1 1 0
Parity Check Matrix H =
1 0 1 1 0 0
1 1 1 0 1 0
1 1 0 0 0 1
1
G * H' mod 2 =
0 0 0
0 0 0
0 0 0
Message Bits d =
1 0 1
Codeword c =
1 0 1 0 0 1
Published with MATLAB® R2025b