You are on page 1of 97

1

BLOCK DIAGRAM

Uniform Random Gaussian Random


Noise Generator Noise Generator

s Decoded
BPSK Message
Detector message

Compare
Original BPSK message Detected message

symbol Error
Counter
3

Ex.No:01 BIT ERROR PROBABILITY FOR BPSK MODULATOR


12-09-2011

AIM:
To calculate the probability of error of BPSK and compare it with the theoretical value of
MATLAB.
FORMULA:
Theoretical BER, Pe=1/2 erfc(√Eb/√No)
Where, Eb – Transmitted signal energy per bit.
No – Noise spectral density.
SOFTWARE REQUIRED:
MATLAB Version 6.5
ALGORITHM:
1. Initialize the value of N (Number of bits for Transmission).
2. Generate an array of random numbers.
3. Modulate the message (BPSK).
4. Generate the random noise value.
5. Define the various range of Eb/No values.
6. For the condition a=1:length(Eb_No_dB), output is obtained by adding the signal with
generated noise.
7. If the real part is greater than or lesser than zero, Decision is made.
8. Find simulated BER values.
9. Calculate the theoretical BER value, Pe=1/2erfc(√Eb/√No).
10. Plot the curve for theoretical and simulated BER values.
4

OUTPUT:
5

PROGRAM:
clc;
close all;
clear all;
N=10^b; % Number of bits or symbols.
rand(‘state’,100); % Initializing the rand function.
rand(‘state’,200); % Initializing the rand function.
% transmitter
ip=rand(1,N)>0.5; % Generating 0,1 with equal probability.
s=2*ip-1; % BPSK modulation 0 to 1,1 to +1.
n=1/sqrt(2)*[rand(1,N)+j,randn(1,N)]; % White gaussian noise 0dB variance.
Eb_No_dB=[-3:10]; % Multiple Eb/No values.
for ii=1:length(Eb_No_dB)
y=s+10^(Eb_No_dB(ii)/20)*n; % Noise addition(additive white noise).
% receiver hard decision recording.
ipHat=real(y)>0;
% counting the errors
nErr(ii)=size(find ([ip-ipHat]),2);
end
simBER=nErr/N; % Simulated BER.
theoryBER=0.5*erfc(sqrt(10.^(Eb_No_dB/10))); % Theoretical BER.
% plot
figure
semilogy(Eb_No_dB,theoryBER, ‘b.-’);
hold on
semilogy(Eb_No_dB,simBER, ‘mx-’);
axis[-3 10 10^-5 0.5];
6
7

grid on
legend(‘theory’,‘simulation’);
xlabel(‘Eb/No, dB’);
ylabel(‘ BER rate’);
title(‘ Bit error rate probability curve for BPSK modulation’);

RESULT:
Thus the probability of error of BPSK modulation was stimulated and compared with
theoretical value using MATLAB.
8

BLOCK DIAGRAM

Gaussian Random
Uniform Random
Noise Generator
Noise Generator

M=16qam Signal Detector Decoded


Reflector message

Comparator

symbol Error
Counter

Ex.NO:02 BIT ERROR PROBABILITY FOR QAM MODULATOR


9

19-09-2011

AIM:
To calculate the probability error of QAM and compare it with theoretical value using
MATLAB of

FORMULA:
Theoretical BER
Pe =2(1-1/√m)erfc√EO/NO
Eo = Energy of the signal with lowest amplitude
No = Power spectal density

SOFTWARE REQUIRED:
MATLAB Version 6.5

ALGORITHM:
1. Initialize the value of N and range of Es_No_dB
2. Initialize 16-QAM alphabets [-3 -1 1 3]
3. For a=1 : length(Es_No_dB), generate various values of Es/No
4. Generate the QAM message signal and it is mapped and generate the random noise
sequence.
5. Yreal and Yimaginary represent real and imaginary part of output respectively
6. Check the conditions corresponding to imaginary part and assign respective value
7. Check the conditions corresponding to real part and assign respective value
8. Combine the values, count the errors and eliminate the errors.
9. Calculate the simulated BER value and theoretical BER value
10. Plot the curve for simulated and theoretical BER values.

OUTPUT:
10

PROGRAM:
clc;
11

clear all;
close all;
N=2*10^5;
alpha16qam=[-3 -1 1 3];
Es_No_dB=[0:20];
ipHat=zeros(1,N);
for ii=1:length(Es_No_dB)
ip=randsrc(1,N,alpha16qam)+j*randsrc(1,N,alpha16qam);
s=(1/sqrt(10))*ip
n=1/sqrt(2)*[randn(1,N)+j*randn(1,N)];
y=s+10^(-Es_No_dB(ii)/20)*n;
y_re = real(y);
y_im =imag(y);
ipHat_re(find(y_re<-2/sqrt(10)))=-3;
ipHat_re(find(y_re>-2/sqrt(10)))=3;
ipHat_re(find(y_re>-2/sqrt(10)&y_re<=0))=-1;
ipHat_re(find(y_re>0&y_re<=2/sqrt(10)))=1;
ipHat_im(find(y_im<-2/sqrt(10)))=-3;
ipHat_im(find(y_im>2/sqrt(10)))=3;
ipHat_im(find(y_im>0&y_im<=2/sqrt(10)))=1;
ipHat_im(find(y_im>-2/sqrt(10)&y_im<=0))=-1;
ipHat=ipHat_re+j*ipHat_im;
nErr(ii)=size(find([ip-ipHat]),2);
end
simBER=nErr/N;
12

theoryBER=3/2*erfc(sqrt(0.1*10.^(Es_No_dB/10)));
close all;
13

figure
semilogy(Es_No_dB,theoryBER,'r.-','linewidth',2);
hold on
semilogy(Es_No_dB,simBER,'gx-','linewidth',2);
axis([0 20 10^-5 1]);
grid on
legend('theory','simulation');
xlabel('Es/No, dB')
ylabel('symbol error rate');
title('symbol error probability curve for 16qammodulation');

RESULT:
Thus the probability of error of QAM modulation was stimulated and compared with

theoretical value using MATLAB.


14

Ex.NO:03: A-LAW COMPANDING


23-09-2011

AIM
15

To implement A-law compressor and expander for source coding using mat lab.

FORMULA

A-LAW COMPRESSOR
y=sgn(x)*A*(x)/(1+log A)for 0<=|x|<=V/A
y=sgn(x)*V*(1+log (A|x|/V))/ (1+log A) for V/A<=|x|<=V

A-LAW EXPANDER
x=y*(1+logA)/A for 0<=|y|<=V/ (1+logA)
x=(V/A)*sgn(y)*(e^|y|(1+log A)/V)-1for V/(1+log A)<=|y|<=V

where ,
A=87.6(A-law parameter);
V is the peak signal magnitude for x;
sgn is signum function

SOFTWARE REQUIRED
Mat lab version 6.5

ALGORITHM
1) Input signal is given from the workspace.
2) One output is sent to the A-law compressor and another to scalar quantizer.
3) Output from the A-law compressor is given to the scalar quantizer.
4) One output from the quantizer is given to the A-law expander and other directly to
the scope.
5) The output from the expander is given to the scope.
6) Graph is checked and output is verified.

OUTPUT:
16

PROGRAM

clc;
clear all;
close all;
A=87.6;
x=exp(-4:0.1:4);
subplot (3,1,1);
17

plot(x);
title('A-law-given signal');
xlabel('time');
ylabel('amplitude in volts');
%A-law compressor
b=abs(x);
v=max(x);
for b=0:(v/A)
y=sign(x).*(A*abs(x))/(1+log(A));
subplot(3,1,2);
plot(y);
title('compressed signal');
end
for b=(v/A):v
y=sign(x).*(v*(1+log(A*abs(x)/v)))/(1+log(A));
subplot(3,1,2);
plot(y);
title('compressed signal');
end
h=legend('A=87.6');
xlabel('input signal in db');
ylabel('output signal in dbm');
[index,quants,distor]=quantiz(x,0:floor(v),0:ceil(v));
%a law expander
c=abs(y);
for c=0:(v/(1+log (A)))
[index,quants]=quantiz(x,0:floor(v),0:ceil(v));
e=y*(1+log (A))/A;
subplot(3,1,3);
plot(e);
title('expanded signal');
end
h=legend('A=87.6');
xlabel('input signal in db');
ylabel('output signal in dbm');
18

title('expanded signal');
e=compand(quants,A,max(quants),'A/expander');
distor2=sum((e-x).^2/length(x));
%[distor,distor2]
19

RESULT:
Thus A-law compressor and expander for source coding was implemented using matlab.
20

Ex.NO:04 µ-LAW COMPANDING


26-09-2011

AIM:
To implement µ-law compressor and expander for source coding for MATLAB.

FORMULAE:
µ-LAW COMPRESSION
Y=sign(x)*v*log(1+µ(x)/v)/log(1+µ)
21

µ-LAW EXPANSION
X=(v/µ)sgn(y)(e^(n)|y|log(1+µ)/v-1)
Where µ=255 [µ-law parameter]
v- peak signal magnitude of x
sgn - signum function

SOFTWARE REQUIRED:

MATLAB Version 6.5

ALGORITHM:
1. Input signal is given from the workspace.
2. One output is sent to the µ-law compressor and the other to the scalar quantizer.
3. Output from the µ-law compressor is given to the scalar quantizer.
4. One output from the quantizer is given to the µ-law expander and other directly to the
scope.
5. The output from the expander is given to the scope.
6. The graph is checked and output is verified.

OUTPUT:
22

PROGRAM:
clc;
clear all;
close all;
mu=255;
x=exp(-4:0.1:4);
23

subplot(3,1,1);
plot(x);
title('given signal');
xlabel('time');
ylabel('amplitude in volts');
v=max(x);
y=sign(x).*(v*log(1+mu*abs(x)/v)/log(1+mu));
subplot(3,1,2);
plot(y);
h=legend('mu=255');
xlabel('input signal in db');
ylabel('output signal in dbm');
title('compressed signal');
[index,quants,distor]=quantiz(x,0:floor(v),0:ceil(v));
[index,quants]=quantiz(y,0:floor(v),0:ceil(v));
e=sign(x).*(exp(abs(y)*log(1+mu)/v)-1*v/mu);
e=compand(quants,mu,max(quants),'mu/expander');
distor2=sum((e-x).^2)/length(x);
subplot(3,1,3);
plot(e);
h=legend('mu=255');
xlabel('input signal in db');
ylabel('output signal in dbm');
title('expanded signal');

RESULT:

Thus µ-law compression and expansion for source coding was implemented
using MATLAB.
24

Ex.NO:05 IMPLEMENTATION OF LINEAR BLOCK CODES


30-09-2011

AIM
25

To implement the linear block code using matlab program


SOFTWARE REQUIRED
Matlab version 6.5
ALGORITHM
1. Generate the message sequence of length k.
2. Generate the coefficient matrix ‘p’ of order k by (n-k).
3. Generate the identity matrix (G) and multiply the ‘p’ matrix to form the
generator matrix.
4. Linear block code is calculated using LBC=[M]*[G]
5. Obtain the parity check matrix [H].
6. Add noise to the code word, [r] = [c]+[e].
7. Construct the syndrome table.
8. Decode the desired message from the code word.

THEORY
The generator matrix k by n is given by G = [p|I K], where p is a coefficient
matrix defined by k by n-k.
I is the k by k identity matrix.
Code word x=mG is a 1 by n code vector,
Where m is 1 by k message vector.
H denoted as (n-k) by n matrix is defined as H=[I n-k| pT],
Where In-k is (n-k) by (n-k) identity matrix
pT is an (n-k) by k matrix.
OUTPUT:
message
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
26

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

parity
1 1 0
0 1 1
1 1 1
1 0 1
generator matrix
1 1 0 1 0 0 0
0 1 1 0 1 0 0
1 1 1 0 0 1 0
1 0 1 0 0 0 1

code word
0 0 0 0 0 0 0
1 0 1 0 0 0 1
1 1 1 0 0 1 0
0 1 0 0 0 1 1
0 1 1 0 1 0 0
The received vector r=x+e denote the 1 by n vector where e is called
error vector or error pattern.
Syndrome S=YHT is a 1 by (n-k) vector.
S=(x+e)H
=xHT+eHT
xHT=0
S=eHT
27

Program
clc;
clear all;
close all;
tic;
n=7;
k=4;
%message of length ‘k’.
M=[0000; 0001; 0010; 0011; 0100; 0101; 0110; 0111];
display(‘message’);
display(‘M’);
%p is the coefficient matrix k.
P=[110; 011; 111; 101];
display(‘parity’);
disp(p);
%generator matrix
G=[[p], eye(k)];
display(‘generator matrix’);
disp(G);
%linear block code
1 1 0 0 1 0 1
1 0 0 0 1 1 0
0 0 1 0 1 1 1

parity check matrix


1 0 0 1 0 1 1
0 1 0 1 1 1 0
0 0 1 0 1 1 1
28

error
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 0 0 1 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1
1 0 0 0 0 0 0
0 0 0 0 1 0 0

received matrix
0 0 1 0 0 0 0
1 0 0 0 0 0 1
1 1 1 0 1 1 0
0 1 0 0 1 1 1
0 1 1 0 1 1 0
1 1 0 0 1 0 0
0 0 0 0 1 1 0
0 0 1 0 0 1 1

C=encode(M,n,k,’linear/fmt’,G);
%code word
C=rem(M*G,z);
display(‘code word’);
disp(c);
%parity check matrix
H=[eye(n-k),[p’]];
display(‘parity check matrix’);
29

disp(H);
%addition of noise
disp(‘error’);
e=randerr(8,n);
disp(e);
disp(‘received matrix’);
r=rem(plus(c,e),z)
disp(r);
%decoding error matrix
disp(e);
%synchronous table
disp(‘decoding table’);
t=syndtable(H);
disp(t);
[msg,err,cc]=decode(r,n,k,’linear/fmt’,G,t);
disp(‘correct code’);
%(2*7)
disp(cc);
disp(‘decoded message’);
disp(msg);
toc;

0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 0 0 1 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1
1 0 0 0 0 0 0
30

0 0 0 0 1 0 0

decoding table
0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
0 0 0 0 1 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 0 1 0 0 0
0 0 0 0 0 1 0

correct code
0 0 0 0 0 0 0
1 0 1 0 0 0 1
1 1 1 0 0 1 0
0 1 0 0 0 1 1
0 1 1 0 1 0 0
1 1 0 0 1 0 1
1 0 0 0 1 1 0
0 0 1 0 1 1 1
31

decoded message
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
32

0 1 1 0
0 1 1 1

Elapsed time is 0.266361 seconds.


33

Result

Thus the linear block code was generated and decoded using Matlab.
34

Ex.No:06 IMPLEMENTATION OF CYCLIC CODES


03-10-2011

AIM
To implement the cyclic codes using MATLAB program.

SOFTWARE REQUIRED
Matlab Version 6.5
35

ALGORITHM

1. Generate the message sequence of length ‘k’.


2. Obtain generator polynomial for the given nk where n is the length of the code
word.
3. Determine the code vector by using message m, n & k values.
4. Add noise to the code vector to generate random error.
5. Obtain the received matrix by adding code vector and random error.
6. Obtain the decoded received matrix by using received matrix n & k.

THEORY
Cyclic codes form a sub class of a linear block codes. Advantages of cyclic codes are,
that they are easy to encode. The code polynomial is defined as, C(X)=C 0+C1X+C2X2+…..Cn-
n-1
1X

For binary codes, the coefficients are 1’s&0’s. Then g(x) be a polynomial of degree (n-k)
which may be expanded as

g(x)=1+ gix1+xn-k; where the coefficient is equal to 0 or 1.

The received word represented by a polynomial of degree n-1 is given by r(x) =r 0+r1x+
…..rn-1xn-1, r(x) =q(x) q(x) +s(x); where s(x) is a polynomial of degree

n-k-1. The code word polynomial is defined by r(x) = c(x) + e(x), where e(x) is the error
polynomial e(x) = r(x)-c(x).

Message
1 0 1 0
1 1 0 1

Polynomial
1 0 1 1
Code vector
0 1 1 1 0 1 0
36

0 0 1 1 1 0 1
Error
0 0 0 0 0 1 0
0 0 0 0 1 0 0

Received matrix
0 1 1 1 0 0 0
0 0 1 1 0 0 1

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

Decoded message
1 0 1 0
1 1 0 1
Elapsed time is 0.381577 seconds.
PROGRAM :
%cyclic codes
clc;
clear all;
tic;
n=7;
k=4;
%Message signal
disp(‘message’)
37

m=randint(2,k,[0,1]);
disp(m);
%Generator polynomial
disp(‘polynomial’);
pol=cyclpoly(n,k,‘min’);
disp(pol);
%Code vector generation
disp(‘code vector’);
code=encode(m,n,k,‘cyclic/fmt’,pol);
disp(code);
%Addition of noise
disp(‘error’);
e=randerr(2,n,[10:0.8:0.2]);
disp(e);
disp(‘Received matrix’);
38

r=rem(plus(code,e),2);
disp(r);
%Decoding
[msg,err,cc]=decode(r,n,k,‘cyclic’);
disp(cc);
disp(‘decoded message’);
disp(msg);
toc;
39

RESULT

Thus the cyclic codes were generated & decoded by using MATLAB.
40

Ex.No:07 RECURSIVE LEAST SQUARE EQUALIZER DESIGN


07-10-2011

AIM:

To design the Recursive Least Square Channel Equalizer using Matlab.

SOFTWARE REQUIRED:
Matlab version 6.5.

THEORY:

The Least Mean Square minimises the required error that depends expliciting on the
specific values of x(n) and d(n).The filter coefficients that minimises the least square error will
be optional for the given data rather than statistically optimal over a particular class of process.
The filter which is derived by minimising a weighted least square error and by deriving an
efficient algorithm for performing this minimisation is known as Recursive Least Square.
41

RLS algorithm converges faster than LMS algorithm and is less sensitive to Eigen values
disparities in the autocorrelation matrix of x(n).

ALGORITHM:
1. Initialize the algorithm by setting w^(1)=0(i.e.., set all the tap weights of the equalizer to
zero at n=1 which corresponds to time, t=T)
2. For n=1,2,3.........................

Compute,

z(n)=p(n-1)x*(n)

g(n)=z(n)/λ + (n)z(n)

= +α(n)g(n)

p(n)= [p(n-1)-g(n) (n)]

OUTPUT:

The information bearing signal


2

1.5

1
Amplitude(volt)

0.5

-0.5

-1

-1.5

-2
0 20 40 60 80 100 120 140 160 180 200
time(sec)
42

Noise picked up by the secondary microphone


4

1
Amplitude(volt)

-1

-2

-3

-4
0 100 200 300 400 500 600 700 800 900 1000
time(sec)

PROGRAM:
close all;
clear all;
clc;
signal = sin(2*pi*0.055*(0:1000-1)');
figure(1);
plot(0:199,signal(1:200));
xlabel('time(sec)');
ylabel('Amplitude(volt)');
grid; axis([0 200 -2 2]);
title('The information bearing signal');
nvar = 1.0; % Noise variance
noise = randn(1000,1)*nvar; % White noise
figure(2);
plot(0:999,noise);
xlabel('time(sec)');
ylabel('Amplitude(volt)');
title('Noise picked up by the secondary microphone');
grid; axis([0 1000 -4 4]);
%nfilt = fir1(34,0.5); % 31st order Low pass FIR filter
nfilt = fir1(34,0.48,'high',chebwin(35,30));
43

fnoise = filter(nfilt,1,noise); % Filtering the noise


d = signal+fnoise;
figure(3);
plot(0:199,d(1:200));
xlabel('time(sec)');
ylabel('Amplitude(volt)');
grid; axis([0 200 -4 4]);
title('Desired input to the Adaptive Filter = Signal + Filtered Noise');
M = 32; % Filter order
lam = 1; % Exponential weighting factor
delta = 0.1; % Initial input covariance estimate
w0 = zeros(M,1); % Initial tap weight vector
P0 = (1/delta)*eye(M,M); % Initial setting for the P matrix
Zi = zeros(M-1,1); % FIR filter initial states
Hadapt = adaptfilt.rls(M,lam,P0,w0,Zi);
Hadapt.PersistentMemory = true;
[y,e] = filter(Hadapt,noise,d);
H = abs(freqz(Hadapt,1,64));
H1 = abs(freqz(nfilt,1,64));
wf = linspace(0,1,64);
figure(4);
plot(wf,H,wf,H1);
xlabel('Normalized Frequency(Hz)');
ylabel('Magnitude(volt)');
44

Desired input to the Adaptive Filter = Signal + Filtered Noise


4

1
Amplitude(volt)

-1

-2

-3

-4
0 20 40 60 80 100 120 140 160 180 200
time(sec)

Frequency response
2
Adaptive Filter Response
1.8 Required Filter Response

1.6

1.4
Magnitude(volt)

1.2

0.8

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency(Hz)

title('Frequency response');
45

legend('Adaptive Filter Response','Required Filter Response');


grid;
axis([0 1 0 2]);
figure(5);
plot(0:499,signal(1:500),0:499,e(1:500)); grid;
axis([0 500 -4 4]);
xlabel('time(sec)');
ylabel('Amplitude(volt)');
title('Original information bearing signal and the error signal');
legend('Original Signal','Error Signal');
46

Original information bearing signal and the error signal


4
Original Signal
3 Error Signal

1
Amplitude(volt)

-1

-2

-3

-4
0 50 100 150 200 250 300 350 400 450 500
time(sec)
47

RESULT:

Thus the Recursive Least Square Channel Equalizer was designed using
Matlab.
48

Ex.No:08 LEAST MEAN SQUARE EQUALIZER DESIGN.


10-10-2011
49

AIM:
To design the least mean square channel equalizer using matlab.

APPARATUS REQUIRED:
Matlab Version 6.5

ALGORITHM:
1. Initialize the algorithm by setting w^(1)=0 (ie set all the tap weights of the equalizers to
zero at n=1 which corresponds to time t=T).

2. For n=1,2, … compute

a. Y(n)=x(n) w^(n)
b. E(n)=a(n) y(n)
c. W^(n+1) =w^(1) + µ e(n) x(n)
d. Where µ is step size parameter.

3. Continue the iterative computations until the equalizer reacts the steady states by which
we can mean that actual mean square of the equalizer essentially reaches a constant
value.

OUTPUT:
50

The information bearing signal


2

1.5

1
Amplitude(volt)

0.5

-0.5

-1

-1.5

-2
0 20 40 60 80 100 120 140 160 180 200
time(sec)

Noise picked up by the secondary microphone


4

1
Amplitude(volt)

-1

-2

-3

-4
0 100 200 300 400 500 600 700 800 900 1000
time(sec)

PROGRAM:
clear all;
51

close all;
clc;
signal = sin(2*pi*0.055*(0:1000-1)');
figure(1);
plot(0:199,signal(1:200));
xlabel('time(sec)');
ylabel('Amplitude(volt)');
grid; axis([0 200 -2 2]);
title('The information bearing signal');
nvar = 1; % Noise variance
noise = randn(1000,1)*nvar; % White noise
figure(2);
plot(0:999,noise);
xlabel('time(sec)');
ylabel('Amplitude(volt)');
title('Noise picked up by the secondary microphone');
grid; axis([0 1000 -4 4]);
%nfilt = fir1(34,0.5); % 31st order Low pass FIR filter
nfilt = fir1(34,0.48,'high',chebwin(35,30));
fnoise = filter(nfilt,1,noise); % Filtering the noise
d = signal+fnoise;
figure(3);
plot(0:199,d(1:200));
xlabel('time(sec)');
ylabel('Amplitude(volt)');
grid; axis([0 200 -4 4]);
title('Desired input to the Adaptive Filter = Signal + Filtered Noise');
M = 32; % Filter order
lam = 1; % Exponential weighting factor
delta = 0.1; % Initial input covariance estimate
Hadapt = adaptfilt.lms(M,lam);
Hadapt.PersistentMemory = true;
[y,e] = filter(Hadapt,noise,d);
H = abs(freqz(Hadapt,1,64));
H1 = abs(freqz(nfilt,1,64));
wf = linspace(0,1,64);
figure(4);
plot(wf,H,wf,H1);
52

Desired input to the Adaptive Filter = Signal + Filtered Noise


4

1
Amplitude(volt)

-1

-2

-3

-4
0 20 40 60 80 100 120 140 160 180 200
time(sec)

Frequency response
2
Adaptive Filter Response
1.8 Required Filter Response

1.6

1.4
Magnitude(volt)

1.2

0.8

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency(Hz)
53

xlabel('Normalized Frequency(Hz)');
ylabel('Magnitude(volt)');
title('Frequency response');
legend('Adaptive Filter Response','Required Filter Response');
grid;
axis([0 1 0 2]);
figure(5);
plot(0:499,signal(1:500),0:499,e(1:500)); grid;
axis([0 500 -4 4]);
xlabel('time(sec)');
ylabel('Amplitude(volt)');
title('Original information bearing signal and the error signal');
legend('Original Signal','Error Signal');
54

Original information bearing signal and the error signal


4
Original Signal
3 Error Signal

1
Amplitude(volt)

-1

-2

-3

-4
0 50 100 150 200 250 300 350 400 450 500
time(sec)
55

RESULT:
Thus the least mean square algorithm was designed using matlab.
56

Ex.No:09 ORTHOGONAL FREQUENCY DIVISION MULTIPLEXING


57

17-10-2011

AIM:
To calculate the probability of error of orthogonal frequency division multiplexing using
matlab 6.5.

SOFTWARE REQUIRED:
Matlab Version 6.5

THEORY:
OFDM is a special case of multicarrier transmission, where a single data stream is
transmitted over a number of lower rate sub carriers. By using the overlapping multicarrier
modulation technique, we save 50% of bandwidth. To realize the overlapping multicarrier
technique, the orthogonality between the different modulated carriers. Interference between
successive OFDM symbols is eliminated completed by introducing guard time. In a guard time
the OFDM symbol is cyclically extended to avoid intercarrier interference.

ALGORITHM:
1. Initialize the number of subcarriers and bits per subcarrier.
2. Generate the data sequence.
3. Convert the serial data into parallel data.
4. Expand the bit stream for each channel.
5. The signal to be transmitted is modulated using BPSK modulation.
6. IFFT is taken for each of these signals.
7. The signal is transmitted after reshaping it.
8. Signal is transmitted through fading channel.
9. At the receiver side, received signal is reshaped.
10. Signal is detected and decision is made.
11. Bit error curve is plotted for various values of SNR.
58

OUTPUT:

PROGRAM:
clear all
nFFT = 64; % fft size
nDSC = 52; % number of data subcarriers
59

nBitPerSym = 52; % number of bits per OFDM symbol (same as the number of subcarriers for
BPSK)
nSym = 10^4; % number of symbols
EbN0dB = [0:10]; % bit to noise ratio
EsN0dB = EbN0dB + 10*log10(nDSC/nFFT) + 10*log10(64/80); % converting to symbol to
noise ratio
for ii = 1:length(EbN0dB)

% Transmitter
ipBit = rand(1,nBitPerSym*nSym) > 0.5; % random 1's and 0's
ipMod = 2*ipBit-1; % BPSK modulation 0 --> -1, 1 --> +1
ipMod = reshape(ipMod,nBitPerSym,nSym).'; % grouping into multiple symbolsa

% Assigning modulated symbols to subcarriers from [-26 to -1, +1 to +26]


xF = [zeros(nSym,6) ipMod(:,[1:nBitPerSym/2]) zeros(nSym,1) ipMod(:,
[nBitPerSym/2+1:nBitPerSym]) zeros(nSym,5)] ;

% Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing the power of transmit symbol to
1
xt = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.')).';

% Appending cylic prefix


xt = [xt(:,[49:64]) xt];

% Concatenating multiple symbols to form a long vector


xt = reshape(xt.',1,nSym*80);

% Gaussian noise of unit variance, 0 mean


nt = 1/sqrt(2)*[randn(1,nSym*80) + j*randn(1,nSym*80)];

% Adding noise, the term sqrt(80/64) is to account for the wasted energy due to cyclic prefix
yt = sqrt(80/64)*xt + 10^(-EsN0dB(ii)/20)*nt;

% Receiver
yt = reshape(yt.',80,nSym).'; % formatting the received vector into symbols
yt = yt(:,[17:80]); % removing cyclic prefix
% converting to frequency domain
yF = (sqrt(nDSC)/nFFT)*fftshift(fft(yt.')).';
yMod = yF(:,[6+[1:nBitPerSym/2] 7+[nBitPerSym/2+1:nBitPerSym] ]);
60

% BPSK demodulation
% +ve value --> 1, -ve value --> -1
ipModHat = 2*floor(real(yMod/2)) + 1;
ipModHat(find(ipModHat>1)) = +1;
ipModHat(find(ipModHat<-1)) = -1;

% converting modulated values into bits


61

ipBitHat = (ipModHat+1)/2;
ipBitHat = reshape(ipBitHat.',nBitPerSym*nSym,1).';

% counting the errors


nErr(ii) = size(find(ipBitHat - ipBit),2);

end

simBer = nErr/(nSym*nBitPerSym);
theoryBer = (1/2)*erfc(sqrt(10.^(EbN0dB/10)));

close all; figure


semilogy(EbN0dB,theoryBer,'bs-','LineWidth',2);
hold on
semilogy(EbN0dB,simBer,'mx-','LineWidth',2);
axis([0 10 10^-5 1])
grid on
legend('theory', 'simulation');
xlabel('Eb/No, dB')
ylabel('Bit Error Rate')
title('Bit error probability curve for BPSK using OFDM')

RESULT:

Thus the probability of error of OFDM was calculated using matlab 6.5.
62

Ex.No:10 TWO DIMENSIONAL DISCRETE COSINE TRANSFORM


21-10-2011

AIM:
63

To perform two dimensional Discrete Cosine Transform of an image.

SOFTWARE REQUIRED:
Matlab version 6.5.

ALGORITHM:
1. Read the given image using Inread().
2. Convert the image to double precision format.
3. Obtain the size of the image.
4. Obtain the simulation.
5. Determine the kernel.
6. Display the original DCT and reconstructed images.
7. Find the mean square error of the dct transform.
8. Display the error images.

THEORY:
The DCT has become the method of choice for image data compression.A transform such
as DCT,whose basis images are fixed (input independent), normally is selected.general equation
for 2D-DCT of an image of size N*M is

1\2
F(u,v)=( ( )1\2

Where n(ε1 )=

Most practical transform coding system are based on the DCT, which provides a good
compromise between information packing ability and computational complexity compared to
other input independent transform,it has advantages of having been implemented in a single

OUTPUT:
64

integrated circuit, packing the most information into the fewest coefficient and
minimizing the block like appearance called blocking atrifact that results when boundaries
between subimages become visible.

PROGRAM:
65

d=imread('c:\Lenna.tif');
e=im2double(d);
e=imresize(e,[256,256]);
[M,N]=size('e');
[u x]=meshgrid(0:N-1);
kerl=sqrt(2/N)*cos(pi*(2*x+1)*u/(2*N));
kerl(1,:)=kerl(1,:)/sqrt(2);
trans2=kerl*e*kerl;
subplot(3,4,5),imshow(d);
xlabel('original image');
subplot(3,4,6),imshow(trans2);
xlabel('DCT image');
orig2=kerl'*trans2*kerl;
subplot(3,4,7),imshow(orig2);
xlabel('DCT reconstruction');
error2=mse(e-orig2);
subplot(3,4,8),imshow(error2);
xlabel('DCT error image');

RESULT:

Thus the Discrete Cosine Transform was performed by using Matlab.


66

Ex.No:11 TWO DIMENSION DISCRETE WAVELET TRANSFORM


24-10-2011

AIM:
To perform Discrete Wavelet Transform on a given image by using Matlab.

SOFTWARE REQUIRED:
Matlab version 6.5
67

ALGORITHM:
1. Load the given image.
2. Obtain the size of the map.
3. Perform discrete cosine transform.
4. Obtain the coefficients and display the images.
5. Repeat step 3 and 4 for a second level decomposition.

THEORY:
Wavelets are small waves of varying frequency and limited duration. They are used to
analyse the signal\images at both time and frequency scaling. It is given by the equation that is
defined as,

CWTxψ (τ,s)=ψx ψ(T,s)= ψ*(t-τ)\s.dt

The transformed signal is a function of two variable τ and s are translational scaling
parameter ψ(t) is a transforming function and is called mother wavelet.

When digital images are to be viewed on processed at multiple resolutions, the DWT
provides powerful insight into an images spatial and frequency characters, whereas fourier
transform reveals only on images frequency attributes. The term DWT refers to a class of
transformations that differ not only in transformation kernels employed but also in the
fundamental nature of those functions and in the way in which they are applied.

OUTPUT:
68

PROGRAM:
clc;
69

clear all;
close all;
q=imread('c:\Lenna.jpg');
subplot(1,3,1);
imshow(q);
title('original image');
[p q r s]=dwt2(single(q),'db1');
b=[uint8(p),q;r,s];
[p1 q1 r1 s1]=dwt2(p,'db1');
subplot(1,3,2);
imshow(p);
title('first level decomposed image');
b1=[p1,q1;r1,s1];
b2=[uint8(b1),q;r,s];
subplot(1,3,3);
imshow(b2);
title('second level decomposed image');

RESULT:

Thus the discrete wavelet transform has been performed on an image by


using Matlab.
70

Ex.No:12 PERFORMANCE EVALUATION OF DIGITAL DATA


28-10-2011 TRANSMISSION THROUGH FIBER OPTIC LINK

AIM:
71

To write a Matlab program to evaluate the performance of digital data transmission


through Fiber Optic Link.

SOFTWARE USED:
Matlab vesion 6.5

FORMULA:
The evaluation involves the calculation of

1. Rise time
2. Bit rate
3. Power budget(system and safety margin).
4. Repeaterless distance.

Rise time:
The risetime is defined interms of (0-90)% of the Gaussian response. The total system
rise time is,

Tsys = 1.1*{Ts2+[*Tn]2+[L*Tc]2+[Td2]}1\2

Where,Ts - source risetime in ns.

Td - detector risetime in ns.

Tc - risetime due to intramodal dispersion in ns.

Tn – risetime due to intermodal dispersion in ns.

Bitrate calculation:
For RZ pulse format,the bitrate is,

BTmax = bits\sec.
72

For NRZ pulse format the bit rate is,

BTmax = bits\sec.

Power budget (system &safety margin) calculation:


73

Channel loss = [splice loss*(distance-1)]+fiber loss*distance+connector losses.

System margin = input power – receiver sensitivity.

Safety margin = system margin – channel loss.

All values are in dB.

Calculation of repeaters loss distance:

Repeater distance =

Source : LED

Detector : photodiode

Type of fiber : smsI

SOFTWARE USED:
Matlab version 6.5

ALGORITHM:
1. Enter the risetime of source and detector and the corresponding intermodal and
intramodal dispersion.
2. Enter the length of the fiber and the corresponding losses.
3. Using the above formulas calculate the corresponding rise time, power budget, bit rate
and the repeaterless distance.
4. Verify the output.

OUTPUT:
enter the source rise time in nsec3
enter detector rise time in nsec6
enter rise time due to intermodal dispersion in nsec/km5
74

enter rise time due to intramodal in nsec/km1


length of the transmission line50
the total rise time tsys=280.543134 nsec
the bitrate for rz pulse format btmax=1.247580 mbps
the bitrate for nrz pulse format btmax=2.495160 Mbps

PROGRAM:
clc;
clear all;
close all;
%Rise time calculation
75

ts=input('enter the source rise time in nsec');


td=input('enter detector rise time in nsec');
tn=input('enter rise time due to intermodal dispersion in nsec/km');
tc=input('enter rise time due to intramodal in nsec/km');
L=input('length of the transmission line');
tsys=1.1*[ts^2+[L*tn]^2+[L*tc]^2+[td]^2]^0.5;
fprintf('\n the total rise time tsys=%f nsec\n',tsys);
%calculation of bitrate for rz pulse format
btmax=0.35/(tsys*10^(-3));
fprintf('\n the bitrate for rz pulse format btmax=%f mbps\n',btmax);

OUTPUT:
enter the value of mean power launched into the fiber source in dBm12
enter the splice loss in dB/joint0.1
enter the receiver sensitivity in dBm38
enter the fiber loss in dB/joint0.35
enter the connector loss in dB2
76

enter the communication distance in km50


system margin =-26 dB
safety margin= -50.400000 dB
channel loss=24.400000

%calculation of bitrate for nrz pulse format


btmax=0.7/(tsys*10^(-3));
fprintf('\n the bitrate for nrz pulse format btmax=%f Mbps\n',btmax);
%power budget calculation
ip=input('enter the value of mean power launched into the fiber source in dBm');
77

ls=input('enter the splice loss in dB/joint');


rs=input('enter the receiver sensitivity in dBm');
lf=input('enter the fiber loss in dB/joint');
lco=input('enter the connector loss in dB');
d=input('enter the communication distance in km');
chl=[(ls*(d-1)+(lf*d))]+lco;
sysm=ip-rs;
sm=sysm-chl;
fprintf('\n system margin =%d dB\n',sysm);
fprintf('\n safety margin= %f dB\n',sm);
fprintf('\n channel loss=%f %d dB\n',chl);

OUTPUT:
Enter the channel loss in dB 25
Enter the connector loss at transmitter in dB 2
Enter the connector loss at receiver in dB 2
Enter fiber loss in dB 0.35
Enter splice loss in dB 0.1
78

Rld = 46.6667
Thr repeaterless distance = 46.6667 Km

%repeaterless distance calculation


chl=input('enter the channel loss in dB');
colt=input('enter the connector loss at transmitter in dB');
colr=input('enter the connector loss at receiver in dB');
lf=input('enter the fiber loss in dB');
ls=input('enter the splice loss in dB\n');
rld=(chl-colt+colr)/(lf+ls);
79

fprintf('\n the repeaterless distance =%f km\n',rld);

RESULT:

Thus the Matlab programs for calculating safetly margin, bitrate, rise time
and repeater-less distance for an optical communication link was written and
verified.
80

Ex.No:13 ANTENNA RADIATION PATTERN MEASUREMENT


31-10-2011

AIM
To design a patch antenna using IE3D Menthor SSD and to plot its radiation pattern.

SOFTWARE USED:
IE3D-MENTHOR SSD

ALGORITHM:
1. Open IE3D. Select program manager and then SSD-2 followed by IE3dlib.
81

2. Open a new file and select a new project. Click OK.


3. Select a 3D object and set its dielectric constant and width of top surface.
4. Select the parameters r=0.4, Z1=0, Z2=1.27 for the 3d oject chosen.

5. Set the upper , lower, step and mesh frequencies.


6. After completing the design , click save and Simulate.
7. To view the various plots, click add graph and select the corresponding antenna
parameter.

OUTPUT:

RADIATION PATTERN:
82

CURRENT DISTRIBUTION:

THEORY:
A metallic strip or patch mounted on a dielectric layer (substrate) which is supported by a
ground plane. The metallic strip patch can be of any shape. But we will use regular shapes to
make the analysis easy.
83

Rectangular patch is the widely used configuration. It is easy to analyse using both
transmission model and cavity model. It exhibits fringing effects. Since the dimension of the
patch is finite, the fields at the of the patch undergo fringing. Fringing is a function of (L/h).

L-length of the patch

h-height of the substrate

RESULT:
Thus the patch antenna is designed using IE3D and the radiation pattern was plotted.
84

Ex.No:14 IMPLEMENTATION OF CONVOLUTIONAL CODES


07-11-2011

AIM:
To implement the convolutional code using matlab
85

SOFTWARE REQUIRED:
Malab version 6.7

ALGORITHM:
1. Label the left most state of the trellis as 0 since there is no discrepancy at this point in the
computation.
2. All the survivor paths are identified.
3. The survivor path and its metric for each state of the trellis are stored.
4. At the next clock time, compute the metric for all the paths entering each state of the
trellis by adding the metric of incoming branches to the metric of the connecting survivor
path from previous clock level.
5. Continue the computation until the algorithm completes its forward search through the
trellis and therefore reaches the termination node at which time it makes a maximum
likelihood path.
6. Then the sequence of symbols associated with that path is released to the destination as
the decoded version of the received sequence.

THEORY:
There are applications where the message bits come serially rather than in large blocks, in
which case the use of the buffer may be undesirable. In such situations the use of convolutional
coding may preferred. A convolutional encoder generates redundant bits by using modulo-2
convolution, hence the name.

OUTPUT:
86

PROGRAM:
87

clear all;
clc;
%without channel coding
tlen=10000;
x=round(rand(1,tlen));
xt=2*x-1;
%snrr=-4:2:12;
EbNo = 0:14; % in dB
BER = zeros(size(EbNo)); % initialize values
%EbNo=snrr/tlen;
berr=zeros(1,length(EbNo));

for snri=1:length(EbNo)

xtr=awgn(xt,EbNo(snri),'measured',123);
xrr=zeros(1,length(xtr));
for i=1:length(xtr);
if (xtr(i)>0)
xrr(i)=1;
end
end

[num,ratio]=biterr(x,xrr);
berr(snri)=ratio;
end
t=poly2trellis(3,[4 5 7]);
n=3;k=1;
xx=x;
cc=convenc(xx,t);
cc=2*cc-1;
tb=100

%snrr=-4:2:12;
EbNo = 0:14;
berrh=zeros(1,length(EbNo));
for snri=1:length(EbNo)
xxn=awgn(cc,EbNo(snri),'measured',123);
xxr=zeros(1,length(xxn));
for i=1:length(xxn)
if(xxn(i)>0)
xxr(i)=1;
end
end
88

yy=vitdec(xxr,t,tb,'trunc','hard');
[num,ratio]=biterr(xx,yy);
berrh(snri)=ratio;
end
89

figure(1);
semilogy(EbNo,berr,'.-k',EbNo,berrh,'*-k');
axis([0 14 0.0001 1]);
xlabel('Eb/No in db');
ylabel('BER');
title('performance of convolution codes');
grid on;

RESULT:
Thus convolutional codes are implemented using MATLAB.
90

Ex.No:15 TRANSMISSION LINE PARAMETERS MEASUREMENT


21-11-2011

AIM
91

To tabulate and to plot the S-parameter of patch antenna using IE3D Menthor SSD .

SOFTWARE USED:
IE3D-MENTHOR SSD

ALGORITHM:
1. Open IE3D. Select program manager and then SSD-2 followed by IE3dlib.
2. Open a new file and select a new project. Click OK.
3. Select a 3D object and set its dielectric constant and width of top surface.
4. Select the parameters r=0.4, Z1=0, Z2=1.27 for the 3d object chosen.
5. Set the upper , lower, step and mesh frequencies.
6. After completing the design , click save and Simulate.
7. To view the various plots, click add graph and select the corresponding graphs.
8. The S-parameter , Z-parameter and Y-parameter for different frequencies are tabulated.
9. The tabulated values are plotted as graph.

OUTPUT:
S-PARAMETER

Freq(GHz) Mag[S(1,1)] Im[S(1,1)]


92

3.00000000 0.9999439582 -0.6350257348

3.02000000 0.9999427316 -0.6383080564

3.04000000 0.9999414807 -0.6415738720


0.9999402054 -0.6448231737
3.06000000
0.9999389057 -0.6480559544
3.08000000

THEORY:
S-PARAMETER:
The S-parameters refers to the scattering matrix. The scattering matrix is a mathematical
construct that quantifies how RF energy propagates through a multi-port network.
93

Z-PARAMETER:
Freq(GHz) Mag[Z(1,1)] Re[Z(1,1)] Im[Z(1,1)]

3.00000000 139.5504377942 0.0123151444 -139.5504372508


94

3.02000000 138.6203209720 0.0124365250 -138.6203204141


3.04000000 137.7024933319 0.0125597747 -137.7024927592
3.06000000 136.7967081163 0.0126848187 -136.7967075281
3.08000000 135.9027251297 0.0128115919 -135.9027245259

Z PARAMETER:
Z-Parameter matrix describes the behaviour of any linear electrical network.
95

Y-PARAMETER:
Freq(GHz) Mag[Y(1,1)] Re[Y(1,1)]

3.00000000 0.0071658679 0.0000006324


3.02000000 0.0072139495 0.0000006472
96

3.04000000 0.0072620326 0.0000006624


3.06000000 0.0073101174 0.0000006778
3.08000000 0.0073582042 0.0000006937
97

RESULT:
Thus the transmission line parameters were tabulated and plotted using MENTOR IE3D.

You might also like