Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Lab Experiments Kamal Jeeth Instrumentation & Service unit

EXPERIMENTAL VERIFICATION OF LINEAR BLOCK CODES AND HAMMING CODES USING MATLAB CODING

B.T.P.Madhav, M.Ravi Kumar, K.V.L.Bhavani Department of Electronics and Communication Engineering K.L.University, Vaddeswaram, Guntur(D.T), A.P-522502 Email: madhav.mtech@gmail.com, ravikumar28383@gmail.com Kbhavani29@gmail.com

Abstract In this paper, we discussed about the coding techniques for reliable communication over communication channels. We discussed the most commonly used coding methods, namely, linear block and hamming codes. We implemented a Matlab coding to generate the codewords for generator matrix and minimum distance between any two distinct codewords.

INTRODUCTION:The probability of error for a particular signaling scheme is a function of signal to noise ratio at the receiver input and the information rate. The practical alternative for reducing the probability of error is the use of error control coding. The channel encoder systematically adds digits to the transmitted message digits. These digits convey no new information, they make it possible for the channel decoder to detect and correct the errors in the information bearing digits. Error control codes are divided into two categories: Block codes and Convolution codes. In block codes, a group of r check bits are derived from a block of k information bits. The structure of block code is such that the information bits are followed by the check bits. The check bits are then used to verify the information bits at the receiver.

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

BLOCK CODES In block codes each block of k-message bits is encoded into a block of n-bits (n>k). The check bits are derived from the message bits and are added to them. The n-bit block of channel encoder output is called a codeword and the codes in which the message bits appear at the beginning of codeword, are called systematic codes.

Message blocks

CHANNEL ENCODER

Code words

Message

Message

check bits

K-Bits LINEAR BLOCK CODES

K-bits

r-bits

If each of the 2k codewords of a systematic code can be expressed as a linear combinations of k linearly independent code vectors, the code is called a linear block code or systematic linear block code. There are two steps in the encoding procedure for linear block codes. 1) The information sequence is segmented into message blocks of k successive information bits. 2) Each message block is transformed into a large block of n bits by an encoder according to some predetermined set of rules. The n-k additional bits are generated from linear combinations of the message bits. Let message block be a row vector D =[d1 d2 d3dk] --------------- (1)

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

Where each message bit can be a 0 or a 1. Thus, we have 2k distinct message blocks. Each message block is transformed into a codeword C of length n bits by the encoder, and there are 2k distinct codewords. C = [C1 C2 C3.Cn] ------------------ (2) There is one unique codeword for each distinct message block. This set of 2k codewords, also known as code vectors, is called an (n, k) block code. The rate efficiency of this code is k/n. In a systematic linear block, the first k-bits of the codeword are the message bits, i.e. Ci = di, i=1, 2, 3k -------------------- (3)

The last n-k bits in the codeword are check bits generated from k message bits according to some predetermined rule:

Ck Ck

1 2

p11d1 p12d1

p21d 2 p22d 2

...... ......

pk ,1dk pk , 2 dk
--------------------- (4)

. . . Cn p1,n k d1

p2 , n k d 2

......

pk ,n k dk

The coefficients Pi, j in eqn (4) is 0s and 1s so that Cks are 0s and 1s. The additions in eqn (4) are modulo-2 additions. Equations (3) and (4) can be combined to give a matrix equation:

1000 .... 0 : p11 p12 ... p1 , n k 0100 .... 0 : p 21 p 22 ... p 2 , n k C1 C 2 .....C n d 1 d 2 .....d k 0010 .... 0 : p 31 p 32 ... p 3 , n k ...... .... .. .. .... .... .... .... ..... 0000 .... 1 : p k ,1 p k , 2 ... p k , n k
-----(5) LE Volume-9, No.3, Sep-2009

kXn

Lab Experiments Kamal Jeeth Instrumentation & Service unit

Or

C = DG ----------------------- (6)

Where G is the k X n matrix on the RHS of eqn (5). It is called the generator matrix of the code and is used in encoding operation. It has the form G = [I k : p]
kXn-------------------

(7)

Where D is the binary data sequence of length k. An important parameter in a linear block code, which determines its error correcting capabilities, is the minimum (hamming) distance of the code, which is defined as the minimum hamming distance between any two distinct codewords. The minimum distance of a code is denoted by dmin and we have dmin = min dH (ci, cj) ----------- (8) ij For linear codes the minimum distance is equal to the minimum weight of the code, defined by wmin = min w (ci) -------------- (9) ci0 that is, the minimum number of 1s in any nonzero codeword.

PROBLEM The generator matrix for a (10,4) linear block code is taken by

G=

1001110111 1110001110 0110110101 LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

1101111001 Here we will determine all the codewords and the minimum weight of the code.

SOLUTION The message block size k for this code is 4, and the length of the code vector n is 10. In order to obtain all codewords, we have to use all information sequences of length 4 and find the corresponding encoded sequences. Since there is a total of 16 binary sequences of length 4, there will be 16 codewords. Let D denote 2k x k matrix whose rows are all possible binary sequences of length k, starting from the all 0 sequence and ending with all 1 sequence. The rows are chosen in such a way that the decimal representation of each row is smaller than the decimal representation of all rows below it. For the case of k = 4, the matrix D is given by

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

We have C = DG, where C is a matrix of codewords, which in this case is a 16x10 matrix whose rows are the codewords. The matrix of codewords is given by

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

1 0 0 111 0 111 111 0 0 0 111 0 0 11 0 11 0 1 0 1 11 0 1111 0 0 1

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

0000000000 11 0 1 11 1 0 0 1 0 11 0 11 0 1 0 1 1 0 11 0 0 1 1 0 0 111 0 0 0 1 11 0 00 1 1 1 1 0 111 1 0 0 0 1 11 0 11 0 1 0 1 0 0 0 01 0 1 0 0 11 1 0 111 0 1 0 00 0 111 0 1111 0 0 0 0 1 0 0 0 1 0 111 0 11 0 111111 0 0 1 1 0 1 00 00 0 00 0 0 0 1 0 0 11 0 0 11 0 0 11 0 1 0 1

Matlab Coding clc; close all; clear all; k=4; for i=1:2^k for j=k:-1:1 if rem (i-1,2^(-j+k+1))>=2^(-j+k) u(i,j)=1; else u(i,j)=0; end echo off; LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

end end echo on; g=[1 0 0 1 1 1 0 1 1 1; 1 1 1 0 0 0 1 1 1 0; 0 1 1 0 1 1 0 1 0 1; 1 1 0 1 1 1 1 0 0 1]; c=rem(u*g,2) w_min=min(sum((c(2:2^k,:))'))

Output g=[1 0 0 1 1 1 0 1 1 1; 1 1 1 0 0 0 1 1 1 0; 0 1 1 0 1 1 0 1 0 1; 1 1 0 1 1 1 1 0 0 1]; c=rem(u*g,2) c= 0 0 0 0 0 0 0 0 0 0

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

1 0 1 1 0 1 0 1 0 1 0 0 1 0 1

1 1 0 1 0 0 1 0 1 1 0 1 0 0 1

0 1 1 1 1 0 0 0 0 1 1 1 1 0 0

1 0 1 0 1 0 1 1 0 1 0 1 0 1 0

1 1 0 0 1 1 0 1 0 0 1 1 0 0 1

1 1 0 0 1 1 0 1 0 0 1 1 0 0 1

1 0 1 1 0 1 0 0 1 0 1 1 0 1 0

0 1 1 1 1 0 0 1 1 0 0 0 0 1 1

0 0 0 1 1 1 1 1 1 1 1 0 0 0 0

1 1 0 0 1 1 0 1 0 0 1 1 0 0 1

w_min=min(sum((c(2:2^k,:))')) w_min = 2

HAMMING CODES INTRODUCTION: Consider a pair of code vectors x and y that have the same number of elements. The hamming distance d(x,y) between such a

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

pair of code vectors is defined as the number of locations in which their respective elements differ. Hamming weight w(x) of a code vector x is defined as the number of non zero elements in the code vector. The minimum distance dmin of a linear block code is defined as the smallest hamming distance between any pair of code vectors in the code (or) dmin is smallest hamming weight of the non zero code vectors in the code.(or) it is the minimum number of columns of the matrix H that sum to 0. Hamming codes are (2m-1,2m-m-1) linear block codes with minimum distance 3 & a very simple parity check matrix, which is of m (2m-1).Hamming weight w(x) of a code vector x is defined as the number of non-zero elements in the code vector. The minimum distance dmin of a linear block code is defined as the smallest Hamming distance between any pair of code vectors in the code. Where hamming distance is nothing but the number of locations in which their respective elements differ. An (n,k) linear block code, correct up to t errors/codeword provided that (n,k)satisfy the hamming bound. An important property of hamming codes is that they satisfy the condition of 2n-k
t n

i =0

with the equality sign assuming that t=1,

means that Hamming code is a single error correcting binary perfect code. And it is confirmed by also t [

1 (dmin-1)] for dmin = 3&t=1 with equal sign. 2

Consider a family of (n, k) linear block code that has the following parameters: Block length: n=2m-1 LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

Number of message bits: k=2m-m-1 Number of parity bits: n-k=m Where m 3. So called Hamming codes. PROBLEM: The generator matrix for a (7,4) Hamming code is taken by

G=

1 0 1 1

1 1 1 0

0 1 1 1

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

Here we will determine all the codewords and the minimum weight of the code. SOLUTION The message block size k for this code is 4, the length of the code vector n is 7 and parity bits length m is 3. Since G=[ P Ik ] and H= [ I P T ] Therefore The parity check matrix will be H=

1 0 0 1 0 1 1 0 1 0 1 1 1 0 0 0 1 0 1 1 1

With K=4 there are 2k = 16 distinct message words. For a given message word, the corresponding code word is obtained by C = mG So for ex: if m=[0 1 0 0] the codeword can be found as follows

C =[ 0 1 0 0 ]

1 0 1 1

1 1 1 0

0 1 1 1

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

= [ 0 1 1 0 1 0 0 ] similarly we construct all the codewords. LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

And those are given in the following table Message Word 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 codeword weight of the codeword 0 1 0 1 0 3 4 3 3 4 4 4 3 4 3 4 4 3 4 7

0 0 1 1

0 1 1 0

0 0 0 0

0 0 0 0

0 0 1 1

0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

0110100 1100101 1000111 0010111 1101000 0111001 0011010 1001011 1011100 0001101 0101110 1111111

Table 1: Codewords of a (7,4) Hamming code. From table 1: The smallest of the Hamming weights for the nonzero code words is 3, it follows that the minimum digits of the code is 3. Indeed, Hamming codes have the property that the minimum distance dmin=3, independent of the value assigned to m.

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

Decoding of hamming code: Error syndrome helps to identify and correct single error. Syndrome for different bit error pattern is given in table 2. Since S= EHT For the above example problem

HT =

1 0 0 1 0 1 1

0 1 0 1 1 1 0

0 0 1 0 1 1 1

if E=[1 0 0 0 0 0 0] then

S = [1 0 0 0 0 0 0]

1 0 0 1 0 1 1

0 1 0 1 1 1 0

0 0 1 0 1 1 1

=[100] Similarly remaining syndromes are calculated as follows Syndrome 000 100 010 001 110 011 111 101 Error pattern 0000000 1000000 0100000 0010000 0001000 0000100 0000010 0000001 LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

Table 2: Decoding table for the (7,4) Hamming code.

If the transmitted code word x is [0110100] At the receiver we will check syndrome S=[received code word ]HT For error free transmission syndrome equals to zero. Case 1:If the received code word y is same as x Then Syndrome for the above example problem is

S= [ 0 1 1 0 1 0 0 ]

1 0 0 1 0 1 1

0 1 0 1 1 1 0

0 0 1 0 1 1 1

=[000] Case 2:If the received code word y has single error at 5th position. X is [ 0 1 1 0 1 0 0 ] and y =[ 0 1 1 0 0 0 0 ] Syndrome for y is

S= [y][HT] = [ 0 1 1 0 0 0 0]

1 0 0 1 0 1 1

0 1 0 1 1 1 0

0 0 1 0 1 1 1

=[011] From the Table2 it is clear that error is in 5th position so we made it correct by changing bit 0 to bit 1.so the correct code word transmitted was found as [ 0 1 1 0 1 0 0 ]

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

Matlab implementation: clc; close all; clear all; k=4; for i=1:2^k for j=k:-1:1 if rem (i-1,2^(-j+k+1))>=2^(-j+k) u(i,j)=1; else u(i,j)=0; end echo off; end end echo on; g=[1 0 0 0 1 1 0 ; 0100011; 0010101; 0 0 0 1 1 1 1 ]; c=rem(u*g,2) w_min=min(sum((c(2:2^k,:))'))

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

Output:g=[1 0 0 0 1 1 0 ; 0100011; 0010101; 0 0 0 1 1 1 1 ]; c=rem(u*g,2) c= 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0

LE Volume-9, No.3, Sep-2009

Lab Experiments Kamal Jeeth Instrumentation & Service unit

w_min=min(sum((c(2:2^k,:))')) w_min = 3

Conclusion:This Experiment gives the knowledge about the generation of codewords from the generator matrix and its minimum weight of the code or minimum distance by using the Matlab coding. The output will be generated at the command window of the Matlab and it is given in the systematic manner for the verification purpose. References:1) Communication systems by R.P.Singh 2) Digital communications by John.G.Proakis 3) Principles of Digital Communication and Coding by Andrew J. Viterbi. 4) An Introduction to Analog and Digital Communications by Simon Haykin. 5) Introduction to MATLAB, by Rudrapratap.

LE Volume-9, No.3, Sep-2009

You might also like