Itc Practicle
Itc Practicle
PRACTICAL1
Output
p = .3
p = .1
p = .2
ans =
p = .4
ans =
Practical 1 B
AIM: - Write a MATLAB to plot the capacity of band limited AWGN channel with
input constraint S and bandwidth B given by
C=B log (1+S/N)
PROCEDURE :-
PROGRAM:-
clc;
s=input('enter signal power');
w=input('enter the value of white power per unit
bandwidth');
b=0:0.1:100;
d=w.*b;
e=s./d;
c=b.*log2(1+e);
plot(b,c);
xlabel('Bandwidth --->');
ylabel('Capicaty--->');
grid;
OUTPUT:
14
12
10
Capicaty--->
0
0 10 20 30 40 50 60 70 80 90 100
Bandwidth --->
PRACTICAL 2-A
AIM : Determine the error correcting capability of given (n,k) code using
hamming bound.
clc;
clear all;
close all;
n=input('enter the code bits : n :');
k=input('enter the data bits : k :');
m=n-k; disp(m);
z=2^m; disp (z);
i=0;
for j=0:1:n
sum=0;
for i=0:1:j
c=factorial(n)/(factorial(n-i)*factorial(i));
sum=sum+c;
end
if sum >=z
j=j-1;
sum=sum-c;
break;
end
end
OUTPUT
(7,4) can correct all combinations of 0 errors and it can also correct 7
combinations of 1 errors
PRACTICAL 2-B
AIM : Determine all the codewords and minimum weights of (n,k) linear
block code.
clc;
clear all;
close all;
n=input('enter the code digits');
k=input('enter the data digits');
p=input('enter the parity matrix it must bei k rows and m
coloums'); disp(p)
z=input('enter 1 for systmetic and 0 for nonsystmetic');
msg=[];
for i=0:2^k-1
msg=[msg;de2bi(i,k,'left-msb')];
end
if z==1
%p=[1 0 1;0 1 1;1 1 0];
i=eye([k k])
g=[i p]
else
g=input('enter the generator matrix in k*n ');
end
code =rem(msg*g,2)
disp('difference matrix');
for i=1:2^k,
for j=1:n,
if c(i,j)==c(i+1,j)
x(i)=x(i);
else
x(i)=(x(i)+1);
end;
%x(i)=7-x(i);
end;
end;
disp(x);
a=x(1);
for i=2:16,
if(x(i)>0)
if(a>=x(i))
a=x(i);
end
end
end
disp('Dmin');
disp(a);
disp('no of error that can be corrected');
t=(a-1)/2;
disp(t);
OUTPUT
Data matrix
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
genmarix =
1 0 0 0 1 1 1
0 1 0 0 1 0 1
0 0 1 0 1 1 0
0 0 0 1 0 1 1
codewords =
0 0 0 0 0 0 0
0 0 0 1 0 1 1
0 0 1 0 1 1 0
0 0 1 1 1 0 1
0 1 0 0 1 0 1
0 1 0 1 1 1 0
0 1 1 0 0 1 1
0 1 1 1 0 0 0
1 0 0 0 1 1 1
1 0 0 1 1 0 0
1 0 1 0 0 0 1
1 0 1 1 0 1 0
1 1 0 0 0 1 0
1 1 0 1 0 0 1
1 1 1 0 1 0 0
1 1 1 1 1 1 1
PRACTICAL 2-C
AIM : Find syndrome for each possible error vector & prepare a suitable
decoding table for (n,k) systematic linear block code.
clc;
clear all;
close all;
n=input('enter the code digits');
k=input('enter the data digits');
i=eye([k k])
d = de2bi(0:2^k-1,3,'left-msb');
a = input('to generate systematic code press 1 or any
other to generate non systematic code: ');
if(a ==1 )
g=[i p];
h=[p i];
c=rem(d*g,2)
else
sprintf('enter generator matrix of size %dX%d',k,n)
ns = input('generator matrix: ');
c1=rem(d*ns,2)
h=ns;
end
OUTPUT
parity matrix: [1 1 1; 1 0 1; 1 1 0; 0 1 1]
c=
0 0 0 0 0 0 0
0 0 0 1 0 1 1
0 0 1 0 1 1 0
0 0 1 1 1 0 1
0 1 0 0 1 0 1
0 1 0 1 1 1 0
0 1 1 0 0 1 1
0 1 1 1 0 0 0
1 0 0 0 1 1 1
1 0 0 1 1 0 0
1 0 1 0 0 0 1
1 0 1 1 0 1 0
1 1 0 0 0 1 0
1 1 0 1 0 0 1
1 1 1 0 1 0 0
1 1 1 1 1 1 1
received code: [1 1 1 1 0 0 1]
corrvect =
0 0 0 0 0 0 1
correctedcode =
1 1 1 1 0 0 0
Syndrome table
0 0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 0 0 0 1 0
1 0 1 0 0 0 0
0 0 0 0 1 0 0
1 1 0 0 0 0 0
1 0 0 1 0 0 0
1 1 0 0 0 1 0
0 0 0 1 0 0 0
0 1 0 0 0 1 0
1 0 0 0 1 0 0
0 1 0 0 0 0 0
1 0 0 0 0 1 0
0 0 1 0 0 0 0
1 0 0 0 0 0 0
1 0 0 0 0 0 1
PRACTICAL 2-D
AIM : Write a MATLAB code to decode all the received words for (n,k)
linear block code.
clc;
clear all;
close all;
n=input('enter the code digits');
k=input('enter the data digits');
p=input('enter the parity matrix it must bei k rows and m
coloums'); disp(p)
z=input('enter 1 for systmetic and 0 for nonsystmetic');
msg=[];
for i=0:2^k-1
msg=[msg;de2bi(i,k,'left-msb')];
end
if z==1
%p=[1 0 1;0 1 1;1 1 0];
i=eye([k k])
g=[i p]
else
g=input('enter the generator matrix in k*n ');
end
code =rem(msg*g,2)
decmsg=decode(code ,n,k,'linear',g)
OUTPUT
generator matrix =
1 0 0 0 1 1 1
0 1 0 0 1 0 1
0 0 1 0 1 1 0
0 0 0 1 0 1 1
Code words =
0 0 0 0 0 0 0
0 0 0 1 0 1 1
0 0 1 0 1 1 0
0 0 1 1 1 0 1
0 1 0 0 1 0 1
0 1 0 1 1 1 0
0 1 1 0 0 1 1
0 1 1 1 0 0 0
1 0 0 0 1 1 1
1 0 0 1 1 0 0
1 0 1 0 0 0 1
1 0 1 1 0 1 0
1 1 0 0 0 1 0
1 1 0 1 0 0 1
1 1 1 0 1 0 0
1 1 1 1 1 1 1
decodedmsg =
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
PRACTICAL : 3
clc;
clear all;
close all;
n=7;
k=4;
gx=[1 1 0 1]
d=de2bi(0:2^k-1,'left-msb')
[i,px]= cyclgen(7,gx,'system')
g= circshift(px, [0, 4])
c=rem(d*g,2)
OUTPUT:
Generator Poly:
gx =
1 1 0 1
Data Matrix:
d=
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
Generator Matrix:
g=
1 0 0 0 1 1 0
0 1 0 0 0 1 1
0 0 1 0 1 1 1
0 0 0 1 1 0 1
CodeWord :
c=
0 0 0 0 0 0 0
0 0 0 1 1 0 1
0 0 1 0 1 1 1
0 0 1 1 0 1 0
0 1 0 0 0 1 1
0 1 0 1 1 1 0
0 1 1 0 1 0 0
0 1 1 1 0 0 1
1 0 0 0 1 1 0
1 0 0 1 0 1 1
1 0 1 0 0 0 1
1 0 1 1 1 0 0
1 1 0 0 1 0 1
1 1 0 1 0 0 0
1 1 1 0 0 1 0
1 1 1 1 1 1 1
PRACTICAL : 4
Syntax
code = convenc(msg,trellis)
code = convenc(msg,trellis,puncpat)
code = convenc(msg,trellis,...,init_state)
[code,final_state] = convenc(...)
Description
PRACTICAL : 4 – A
clc;
clear all;
close all;
a=input('enter the input stream :');
a=[a 0 0]
s2=0;
s3=0;
v=[];
for i=1:length(a)
s1=a(i);
v1=rem((s1+s2+s3),2);
v2=rem((s1+s3),2);
v=[v v1 v2];
s3=s2;
s2=s1;
end
disp('code vector')
v
OUTPUT
Here v1= s1 + s2 + s3
And v2=s1+s3
a=
1 0 1 0 0 0 0
code vector
v=
1 1 1 0 0 0 1 0 1 1 0 0 0 0
PRACTICAL : 4 – B
AIM : Decode the convolution code using viterbi decoding algorithm and
the check the bit error rate.
OUTPUT
PRACTICAL : 5
rsenc
Reed-Solomon encoder
Syntax
code = rsenc(msg,n,k)
code = rsenc(msg,n,k,genpoly)
code = rsenc(...,paritypos)
Description
rsgenpoly
Generator Polynomial
r = rsgenpoly(15,13)
Array elements =
1 6 8
rsdec
Reed-Solomon decoder
Syntax
decoded = rsdec(code,n,k)
decoded = rsdec(code,n,k,genpoly)
decoded = rsdec(...,paritypos)
[decoded,cnumerr] = rsdec(...)
[decoded,cnumerr,ccode] = rsdec(...)
Description
In the Galois array decoded, each row represents the attempt at decoding the
corresponding row in code. A decoding failure occurs if rsdec detects more
than (n-k)/2 errors in a row of code. In this case, rsdec forms the
corresponding row of decoded by merely removing n-k symbols from the end
of the row of code.
The example below illustrates multiple ways to encode and decode data using
a [15,13] Reed-Solomon code. The example shows that you can
Vary the generator polynomial for the code, using rsgenpoly to produce a
different generator polynomial.
Vary the primitive polynomial for the Galois field that contains the symbols,
using an input argument in gf.
Vary the position of the parity symbols within the codewords, choosing
either the end (default) or beginning.
This example also shows that corresponding syntaxes of rsenc and rsdec use
the same input arguments, except for the first input argument.
c4 = rsenc(msg,n,k,'beginning');
d4 = rsdec(c4,n,k,'beginning');
OUTPUT :
data =
0 2 4 7 13 13 13 4 4 6 7 13 5
5 3 3 14 8 0 8 3 8 13 14 10 8
13 3 0 7 3 10 11 3 2 13 13 5 11
0 9 11 6 10 6 6 10 11 9 10 4 4
Array elements =
Columns 1 through 8
0 2 4 7 13 13 13 4
5 3 3 14 8 0 8 3
13 3 0 7 3 10 11 3
0 9 11 6 10 6 6 10
Columns 9 through 13
4 6 7 13 5
8 13 14 10 8
2 13 13 5 11
11 9 10 4 4
Array elements =
Columns 1 through 8
0 2 4 7 13 13 13 4
5 3 3 14 8 0 8 3
13 3 0 7 3 10 11 3
0 9 11 6 10 6 6 10
Columns 9 through 15
4 6 7 13 5 14 5
8 13 14 10 8 3 7
2 13 13 5 11 3 12
11 9 10 4 4 1 15
PRACTICAL : 6
bchenc
BCH encoder
Syntax
code = bchenc(msg,n,k)
code = bchenc(...,paritypos)
Description
bchdec
BCH decoder
Syntax
decoded = bchdec(code,n,k)
decoded = bchdec(...,paritypos)
[decoded,cnumerr] = bchdec(...)
[decoded,cnumerr,ccode] = bchdec(...)
Description
In the Galois array decoded, each row represents the attempt at decoding the
corresponding row in code. A decoding failure occurs if bchdec detects more
than t errors in a row of code, where t is the number of correctable errors as
reported by bchgenpoly. In the case of a decoding failure, bchdec forms the
corresponding row of decoded by merely removing n-k symbols from the end
of the row of code.
A message for an [n,k] BCH code must be a k-column binary Galois array.
The code that corresponds to that message is an n-column binary Galois
array. Each row of these Galois arrays represents one word.
The example below illustrates how to represent words for a [15, 11] BCH
code.
The output is
cbch = GF(2) array.
Array elements =
Columns 1 through 5
1 0 0 1 0
1 0 1 1 1
Columns 6 through 10
0 0 1 1 1
0 0 0 0 1
Columns 11 through 15
1 0 1 0 1
0 1 0 0 1
The example below illustrates how to encode and decode data using a [15, 5]
Reed-Solomon code. The example shows that
You can vary the position of the parity symbols within the codewords,
choosing either the end (default) or beginning.
OUTPUT:
dat =
1 1 1 1 1
0 1 0 1 1
1 0 1 0 0
0 0 1 0 1
c1 = GF(2) array.
Array elements =
Columns 1 through 8
1 1 1 1 1 1 1 1
0 1 0 1 1 0 0 1
1 0 1 0 0 1 1 0
0 0 1 0 1 0 0 1
Columns 9 through 15
1 1 1 1 1 1 1
0 0 0 1 1 1 1
1 1 1 0 0 0 0
1 0 1 1 1 0 0
c2 = GF(2) array.
Array elements =
Columns 1 through 8
1 1 1 1 1 1 1 1
0 0 1 0 0 0 1 1
1 1 0 1 1 1 0 0
0 0 1 1 0 1 1 1
Columns 9 through 15
1 1 1 1 1 1 1
1 1 0 1 0 1 1
0 0 1 0 1 0 0
0 0 0 0 1 0 1
PRACTICAL : 7
The output below shows that the most probable data symbol, 3, is
associated with a one-digit codeword, while less probable data symbols are
associated with two-digit codewords. The output also shows, for example, that
a Huffman encoder receiving the data symbol 1 should substitute the
sequence 11.
dict =
OUTPUT
ans =
ans =
1 0 1
ans =
ans =
1 0 0
ans =
ans =
0 0
ans =
ans =
0 1
ans =
ans =
1 1
PRACTICAL : 8
Arithmetic Coding
Arithmetic coding offers a way to compress data and can be useful for
data sources having a small alphabet. The length of an arithmetic code,
instead of being fixed relative to the number of symbols being encoded,
depends on the statistical frequency with which the source produces each
symbol from its alphabet. For long sequences from sources having skewed
distributions and small alphabets, arithmetic coding compresses better than
Huffman coding.
For example, before encoding data from a source that produces 10 x's,
10 y's, and 80 z's in a typical 100-symbol set of test data, define
Alternatively, if a larger set of test data from the source contains 22 x's, 23 y's,
and 185 z's, then define
code = arithenco(seq,counts);
code;
dseq = arithdeco(code,counts,length(seq));
dseq;
OUTPUT:
0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0
Columns 17 through 32
0 1 1 0 1 1 0 1 1 1 1 1 1 1 0 0
Columns 33 through 37
0 0 0 0 0
dseq =
Columns 1 through 16
1 2 3 1 2 3 1 1 1 2 3 2 3 2 3 3
Columns 17 through 20
3 3 3 3