In Binary Block Encoding binary message are encoded in blocks of length k into codewords of length n. Here an illustration of C(6,3) block encoding is provided using Matlab. In the illustrating first binary message signal is defined then codewords are generated using a generator matrix. Errors are added to the encoded blocks to generated corrupted codewords and finally syndrome is calculated using the error vectors and received signal vectors. The syndrome with both the vectors are the same.
Let suppose we have binary message as follows-
m1=[0 0 0];
m2=[1 0 0];
m3=[0 1 0];
m4=[1 1 0];
m5=[0 0 1];
m6=[1 0 1];
m7=[0 1 1];
m8=[1 1 1];
The actual stream of message is- m=[m1 m2 m3 m4 m5 m6 m7 m8]
The codewords C{c1,c2,c3,c4,c5,c6} are generated by multiplying the Generator with the message blocks. Thus we need the generator block first. Let it be defined as follows-
G=[1 1 0 1 0 0; 0 1 1 0 1 0;1 0 1 0 0 1];
The the codewords is generated using the equation-
C=m*G
The matlab code that does this is-
c1=mod(double(m1)*double(G),2);
c2=mod(double(m2)*double(G),2);
c3=mod(double(m3)*double(G),2);
c4=mod(double(m4)*double(G),2);
c5=mod(double(m5)*double(G),2);
c6=mod(double(m6)*double(G),2);
c7=mod(double(m7)*double(G),2);
c8=mod(double(m8)*double(G),2);
The actual binary stream is C=[c1 c2 c3 c4 c5 c6 c7]. This encoded binary stream is modulated and transmitted over the noisy channel to the receiver. The received signal is demodulated and then sampled to get a binary received signal as follows-
r=c+e
where e=e1...e6 are errors introduced by the channel and added to the codewords. The errors are random and the codes for these errors are-
e1=round(rand(1,6));
e2=round(rand(1,6));
e3=round(rand(1,6));
e4=round(rand(1,6));
e5=round(rand(1,6));
e6=round(rand(1,6));
These errors are added to the transmitted codewords and the matlab code for the received binary bits are-
r1 = bsxfun(@plus,c1,e1);
r2 = bsxfun(@plus,c2,e2);
r3 = bsxfun(@plus,c3,e3);
r4 = bsxfun(@plus,c4,e4);
r5 = bsxfun(@plus,c5,e5);
r6 = bsxfun(@plus,c6,e6);
Once we have the received noise corrupted codewords we want to determine where and which bit is in error and correct the error bit if possible. To do this we can use Syndrome parameter. This parameter can be determined using two methods as follows-
S=r*H'
or
S=e*H'
Here H' is the transpose of a matrix H called the parity check matrix. The H matrix can be found out from the generator matrix by requiring that-
G*H'=0
Matlab has a special function called gentopar( ) that calculates the Parity check matrix from the Generator Matrix-
H=gen2par(G);
Once we know H and r(or e) we can determine the Syndrome. The two methods to calculate Syndrome gives the same value of syndrome(that is either using r or e). The matlab code for this is-
Sr1=mod(double(r1)*double(H'),2);
Sr2=mod(double(r2)*double(H'),2);
Sr3=mod(double(r3)*double(H'),2);
Sr4=mod(double(r4)*double(H'),2);
Sr5=mod(double(r5)*double(H'),2);
Sr6=mod(double(r6)*double(H'),2);
and,
Se1=mod(double(e1)*double(H'),2);
Se2=mod(double(e2)*double(H'),2);
Se3=mod(double(e3)*double(H'),2);
Se4=mod(double(e4)*double(H'),2);
Se5=mod(double(e5)*double(H'),2);
Se6=mod(double(e6)*double(H'),2);
We can check that the Syndrome calculated using received vector r and error vector e are the same. That is for example Sr5 and Se5 are the same or Sr2 and Se2 are the same and likewise others.
A Syndrome of all zero vector implies no error and a non-zero vector implies error. For example the following Matlab code outputs syndrome of Sr2 = [0 1 1] showing that there are errors.
-------------------------------------------------------------------------------------------------------------------
Complete Matlab Code
-------------------------------------------------------------------------------------------------------------------
% Block Encoding Decoding for (6,3)
clear all;
clc
% Define block of message sequences
m1=[0 0 0];
m2=[1 0 0];
m3=[0 1 0];
m4=[1 1 0];
m5=[0 0 1];
m6=[1 0 1];
m7=[0 1 1];
m8=[1 1 1];
m=[m1 m2 m3 m4 m5 m6 m7 m8];
% Define Generator matrix G
G=[1 1 0 1 0 0; 0 1 1 0 1 0;1 0 1 0 0 1];
%Generate Codewords C
c1=mod(double(m1)*double(G),2);
c2=mod(double(m2)*double(G),2);
c3=mod(double(m3)*double(G),2);
c4=mod(double(m4)*double(G),2);
c5=mod(double(m5)*double(G),2);
c6=mod(double(m6)*double(G),2);
c7=mod(double(m7)*double(G),2);
c8=mod(double(m8)*double(G),2);
% Define Noise
e1=round(rand(1,6));
e2=round(rand(1,6));
e3=round(rand(1,6));
e4=round(rand(1,6));
e5=round(rand(1,6));
e6=round(rand(1,6));
% Generate Received Signal with Noise
r1 = bsxfun(@plus,c1,e1);
r2 = bsxfun(@plus,c2,e2);
r3 = bsxfun(@plus,c3,e3);
r4 = bsxfun(@plus,c4,e4);
r5 = bsxfun(@plus,c5,e5);
r6 = bsxfun(@plus,c6,e6);
% Generate Parity check Matrix H
H=gen2par(G);
% Generate Syndrome using r vectors
Sr1=mod(double(r1)*double(H'),2);
Sr2=mod(double(r2)*double(H'),2);
Sr3=mod(double(r3)*double(H'),2);
Sr4=mod(double(r4)*double(H'),2);
Sr5=mod(double(r5)*double(H'),2);
Sr6=mod(double(r6)*double(H'),2);
% Generate Syndrome using e vectors
Se1=mod(double(e1)*double(H'),2);
Se2=mod(double(e2)*double(H'),2);
Se3=mod(double(e3)*double(H'),2);
Se4=mod(double(e4)*double(H'),2);
Se5=mod(double(e5)*double(H'),2);
Se6=mod(double(e6)*double(H'),2);
-------------------------------------------------------------------------------------------------------------------
Let suppose we have binary message as follows-
m1=[0 0 0];
m2=[1 0 0];
m3=[0 1 0];
m4=[1 1 0];
m5=[0 0 1];
m6=[1 0 1];
m7=[0 1 1];
m8=[1 1 1];
The actual stream of message is- m=[m1 m2 m3 m4 m5 m6 m7 m8]
The codewords C{c1,c2,c3,c4,c5,c6} are generated by multiplying the Generator with the message blocks. Thus we need the generator block first. Let it be defined as follows-
G=[1 1 0 1 0 0; 0 1 1 0 1 0;1 0 1 0 0 1];
The the codewords is generated using the equation-
C=m*G
The matlab code that does this is-
c1=mod(double(m1)*double(G),2);
c2=mod(double(m2)*double(G),2);
c3=mod(double(m3)*double(G),2);
c4=mod(double(m4)*double(G),2);
c5=mod(double(m5)*double(G),2);
c6=mod(double(m6)*double(G),2);
c7=mod(double(m7)*double(G),2);
c8=mod(double(m8)*double(G),2);
The actual binary stream is C=[c1 c2 c3 c4 c5 c6 c7]. This encoded binary stream is modulated and transmitted over the noisy channel to the receiver. The received signal is demodulated and then sampled to get a binary received signal as follows-
r=c+e
where e=e1...e6 are errors introduced by the channel and added to the codewords. The errors are random and the codes for these errors are-
e1=round(rand(1,6));
e2=round(rand(1,6));
e3=round(rand(1,6));
e4=round(rand(1,6));
e5=round(rand(1,6));
e6=round(rand(1,6));
These errors are added to the transmitted codewords and the matlab code for the received binary bits are-
r1 = bsxfun(@plus,c1,e1);
r2 = bsxfun(@plus,c2,e2);
r3 = bsxfun(@plus,c3,e3);
r4 = bsxfun(@plus,c4,e4);
r5 = bsxfun(@plus,c5,e5);
r6 = bsxfun(@plus,c6,e6);
Once we have the received noise corrupted codewords we want to determine where and which bit is in error and correct the error bit if possible. To do this we can use Syndrome parameter. This parameter can be determined using two methods as follows-
S=r*H'
or
S=e*H'
Here H' is the transpose of a matrix H called the parity check matrix. The H matrix can be found out from the generator matrix by requiring that-
G*H'=0
Matlab has a special function called gentopar( ) that calculates the Parity check matrix from the Generator Matrix-
H=gen2par(G);
Once we know H and r(or e) we can determine the Syndrome. The two methods to calculate Syndrome gives the same value of syndrome(that is either using r or e). The matlab code for this is-
Sr1=mod(double(r1)*double(H'),2);
Sr2=mod(double(r2)*double(H'),2);
Sr3=mod(double(r3)*double(H'),2);
Sr4=mod(double(r4)*double(H'),2);
Sr5=mod(double(r5)*double(H'),2);
Sr6=mod(double(r6)*double(H'),2);
and,
Se1=mod(double(e1)*double(H'),2);
Se2=mod(double(e2)*double(H'),2);
Se3=mod(double(e3)*double(H'),2);
Se4=mod(double(e4)*double(H'),2);
Se5=mod(double(e5)*double(H'),2);
Se6=mod(double(e6)*double(H'),2);
We can check that the Syndrome calculated using received vector r and error vector e are the same. That is for example Sr5 and Se5 are the same or Sr2 and Se2 are the same and likewise others.
A Syndrome of all zero vector implies no error and a non-zero vector implies error. For example the following Matlab code outputs syndrome of Sr2 = [0 1 1] showing that there are errors.
-------------------------------------------------------------------------------------------------------------------
Complete Matlab Code
-------------------------------------------------------------------------------------------------------------------
% Block Encoding Decoding for (6,3)
clear all;
clc
% Define block of message sequences
m1=[0 0 0];
m2=[1 0 0];
m3=[0 1 0];
m4=[1 1 0];
m5=[0 0 1];
m6=[1 0 1];
m7=[0 1 1];
m8=[1 1 1];
m=[m1 m2 m3 m4 m5 m6 m7 m8];
% Define Generator matrix G
G=[1 1 0 1 0 0; 0 1 1 0 1 0;1 0 1 0 0 1];
%Generate Codewords C
c1=mod(double(m1)*double(G),2);
c2=mod(double(m2)*double(G),2);
c3=mod(double(m3)*double(G),2);
c4=mod(double(m4)*double(G),2);
c5=mod(double(m5)*double(G),2);
c6=mod(double(m6)*double(G),2);
c7=mod(double(m7)*double(G),2);
c8=mod(double(m8)*double(G),2);
% Define Noise
e1=round(rand(1,6));
e2=round(rand(1,6));
e3=round(rand(1,6));
e4=round(rand(1,6));
e5=round(rand(1,6));
e6=round(rand(1,6));
% Generate Received Signal with Noise
r1 = bsxfun(@plus,c1,e1);
r2 = bsxfun(@plus,c2,e2);
r3 = bsxfun(@plus,c3,e3);
r4 = bsxfun(@plus,c4,e4);
r5 = bsxfun(@plus,c5,e5);
r6 = bsxfun(@plus,c6,e6);
% Generate Parity check Matrix H
H=gen2par(G);
% Generate Syndrome using r vectors
Sr1=mod(double(r1)*double(H'),2);
Sr2=mod(double(r2)*double(H'),2);
Sr3=mod(double(r3)*double(H'),2);
Sr4=mod(double(r4)*double(H'),2);
Sr5=mod(double(r5)*double(H'),2);
Sr6=mod(double(r6)*double(H'),2);
% Generate Syndrome using e vectors
Se1=mod(double(e1)*double(H'),2);
Se2=mod(double(e2)*double(H'),2);
Se3=mod(double(e3)*double(H'),2);
Se4=mod(double(e4)*double(H'),2);
Se5=mod(double(e5)*double(H'),2);
Se6=mod(double(e6)*double(H'),2);
-------------------------------------------------------------------------------------------------------------------