block codes

17
Lab Experiments Kamal Jeeth Instrumentation & Service unit LE Volume-9, No.3, Sep-2009 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: [email protected], [email protected] [email protected] 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.

Upload: bhavani-kandru

Post on 26-Oct-2014

144 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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: [email protected], [email protected]

[email protected]

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.

Page 2: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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 Code words

K-Bits K-bits r-bits

LINEAR BLOCK CODES

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 d3………dk] --------------- (1)

CHANNEL

ENCODER

Message Message check bits

Page 3: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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, 3……k -------------------- (3)

The last n-k bits in the codeword are check bits generated from

k message bits according to some predetermined rule:

dkpdpdpC

dkpdpdpC

dkpdpdpC

knkknknn

kk

kk

,2,21,1

2,2221122

1,2211111

......

.

.

.

......

......

--------------------- (4)

The coefficients Pi, j in eqn (4) is 0’s and 1’s so that Ck’s are 0’s

and 1’s. The additions in eqn (4) are modulo-2 additions.

Equations (3) and (4) can be combined to give a matrix

equation:

nXk

knppp

knppp

knppp

knppp

dddCCC

kkk

kn

,2,1,

,33231

,22221

,11211

2121

...:1....0000

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

...:0....0010

...:0....0100

...:0....1000

..........

-----(5)

Page 4: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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)

i≠j

For linear codes the minimum distance is equal to the minimum

weight of the code, defined by

wmin = min w (ci) -------------- (9)

ci≠0

that is, the minimum number of 1’s in any nonzero codeword.

PROBLEM

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

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

Page 5: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

1 1 0 1 1 1 1 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, 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

Page 6: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

1111

0111

1011

0011

1101

0101

1001

0001

1110

0110

1010

0010

1100

0100

1000

0000

D

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

1001111011

1010110110

0111000111

1110111001

1111

0111

1011

0011

1101

0101

1001

0001

1110

0110

1010

0010

1100

0100

1000

0000

C

Page 7: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

1010110011

0011001000

0000000101

1001111110

1101110100

0100001111

0111000010

1110111001

0100001010

1101110001

1110111100

0111000111

0011001101

1010110110

1001111011

0000000000

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;

Page 8: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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

Page 9: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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

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

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

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

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

1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 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

Page 10: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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

0=ii

n 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 ≤ [2

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

Consider a family of (n, k) linear block code that has the

following parameters:

Block length: n=2m-1

Page 11: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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 =

1000101

0100111

0010110

0001011

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=

1110100

0111010

1101001

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 ]

1000101

0100111

0010110

0001011

= [ 0 1 1 0 1 0 0 ] similarly we construct all the codewords.

Page 12: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

And those are given in the following table

Message codeword weight of the

Word codeword

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 1 3

0 0 1 0 1 1 1 0 0 1 0 4 0 0 1 1 0 1 0 0 0 1 1 3

0 1 0 0 0 1 1 0 1 0 0 3

0 1 0 1 1 1 0 0 1 0 1 4

0 1 1 0 1 0 0 0 1 1 1 4

0 1 1 1 0 0 1 0 1 1 1 4

1 0 0 0 1 1 0 1 0 0 0 3

1 0 0 1 0 1 1 1 0 0 1 4

1 0 1 0 0 0 1 1 0 1 0 3

1 0 1 1 1 0 0 1 0 1 1 4

1 1 0 0 1 0 1 1 1 0 0 4

1 1 0 1 0 0 0 1 1 0 1 3

1 1 1 0 0 1 0 1 1 1 0 4

1 1 1 1 1 1 1 1 1 1 1 7

Table 1: Codewords of a (7,4) Hamming code.

From table 1: The smallest of the Hamming weights for the non-

zero 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’.

Page 13: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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 =

101

111

110

011

100

010

001

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

then

S = [1 0 0 0 0 0 0]

101

111

110

011

100

010

001

= [ 1 0 0 ]

Similarly remaining syndromes are calculated as follows

Syndrome Error pattern

0 0 0

1 0 0

0 1 0

0 0 1

1 1 0

0 1 1

1 1 1

1 0 1

0 0 0 0 0 0 0

1 0 0 0 0 0 0

0 1 0 0 0 0 0

0 0 1 0 0 0 0

0 0 0 1 0 0 0

0 0 0 0 1 0 0

0 0 0 0 0 1 0

0 0 0 0 0 0 1

Page 14: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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 ]

101

111

110

011

100

010

001

= [ 0 0 0 ]

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]

101

111

110

011

100

010

001

= [ 0 1 1 ]

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 ]

Page 15: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

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 ; 0 1 0 0 0 1 1 ;

0 0 1 0 1 0 1 ; 0 0 0 1 1 1 1 ];

c=rem(u*g,2)

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

Page 16: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

Output:-

g=[1 0 0 0 1 1 0 ;

0 1 0 0 0 1 1 ;

0 0 1 0 1 0 1 ;

0 0 0 1 1 1 1 ];

c=rem(u*g,2)

c =

0 0 0 0 0 0 0

0 0 0 1 1 1 1

0 0 1 0 1 0 1

0 0 1 1 0 1 0

0 1 0 0 0 1 1

0 1 0 1 1 0 0

0 1 1 0 1 1 0

0 1 1 1 0 0 1

1 0 0 0 1 1 0

1 0 0 1 0 0 1

1 0 1 0 0 1 1

1 0 1 1 1 0 0

1 1 0 0 1 0 1

1 1 0 1 0 1 0

1 1 1 0 0 0 0

Page 17: Block Codes

Lab Experiments

Kamal Jeeth Instrumentation & Service unit

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

1 1 1 1 1 1 1

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.