Professional Documents
Culture Documents
Code:
1
Experiment 2
Code:
clc; axis([1 10 -1.5 1.5]);
close all; subplot(4,2,5);
clear all; plot(t,ami_nrz);
x=round(rand(1,10)) ylabel('AMI NRZ');
nx=length(x); hold on;
sign=1; grid on;
for i=1:nx axis([1 10 -1.5 1.5]);
t = i:0.001:i+1-0.001; subplot(4,2,2);
if x(i)==1 plot(t,unipolar_rz);
unipolar_nrz=square(t*2*pi,100); ylabel('unipolar RZ');
bipolar_nrz=square(t*2*pi,100); hold on;
ami_nrz=sign*square(t*2*pi,100); grid on;
unipolar_rz=(1+square(t*2*pi,50))/2; axis([1 10 -1.5 1.5]);
polar_rz=(1+square(t*2*pi,50))/2; subplot(4,2,4);
ami_rz=sign*(1+square(t*2*pi,50))/2; plot(t,polar_rz);
nrz_m=sign*square(2*pi*t,100); ylabel('polar RZ');
sign=sign*-1; hold on;
manchester_code=square(t*2*pi,50); grid on;
else axis([1 10 -1.5 1.5]);
unipolar_nrz=0; subplot(4,2,6);
bipolar_nrz=-square(t*2*pi,100); plot(t,ami_rz);
ami_nrz=0; ylabel('AMI RZ');
unipolar_rz=0; hold on;
polar_rz=-(1+square(t*2*pi,50))/2; grid on;
ami_rz=0; axis([1 10 -1.5 1.5]);
manchester_code=-square(t*2*pi,50); subplot(4,2,8);
end plot(t,manchester_code);
subplot(4,2,1); ylabel('manchester code');
plot(t,unipolar_nrz); hold on;
ylabel('unipolar NRZ'); grid on;
hold on; axis([1 10 -1.5 1.5]);
grid on; subplot(4,2,7);
axis([1 10 -1.5 1.5]); plot(t,nrz_m);
subplot(4,2,3); ylabel('NRZ-M code');
plot(t,bipolar_nrz); hold on;
ylabel('bipolar NRZ'); grid on;
hold on; axis([1 10 -1.5 1.5]);
grid on; end
Output:
x= 1 1 0 1 1 0 0 1 1 1
2
Experiment 3
[ind,q]=quantiz(s,part,code); index=bi2de(quant','left-msb');
% Quantization process
% ind contain index number and q contain % Getback the index in decimal form
quantized values q=del*index+vmin+(del/2);
3
Output:
Figure 1
Figure 2
4
Experiment 5
Code:
clc; subplot(2,1,2);
clear all; stairs(t,d);
close all; ylim([-0.2 1.2]);
a=2; title(‘Encoded Bit stream’);
t=0:1/100:1; r=0;
x=a*sin(2*pi*t); for i=1:length(d)
l=length(x); if d(i)==0
delta=input('Required Step Size: '); r(i+1)=r(i)-delta;
%variation of this step size results else
%in the problems of delta modulation r(i+1)=r(i)+delta;
%like granular noise and slope end
%overload noise leading to improper end
%reconstruction [p, q] = butter(2,1/20);
xn=0; rec = filter(p,q,r);
for i=1:l figure;
if x(i)>=xn(i) subplot(2,1,1);
d(i)=1; stairs(t,r(1:l));
xn(i+1)=xn(i)+delta; hold on
else plot(t,x,'--');
d(i)=0; legend('Recovered
xn(i+1)=xn(i)-delta; approximation','Original Signal');
end title('DELTA MODULATION /
end DEMODULATION ')
subplot(2,1,1); subplot(2,1,2);
stairs(t,xn(1:l)); plot(t,rec(1:l));
title('Staircase approximation') title('Recovered Analog waveform');
Output:
5
Required Step Size: pi/25
6
Experiment 6
Aim: To plot and analyse the PDFs of Gaussian, Uniform and Binomial Random Variables
Code:
clc; else
clear all; U(i) = 0;
close all; end
% Gaussian end
display('Gaussian Random Variable'); figure(2);
u=input('Mean : '); plot(x,U);
v=input('variance : '); axis([a-5 b+5 -0.5 1])
x = -10: 0.001: 10; title(‘Uniform PDF’);
N = (1/(sqrt(2*pi*v)))*exp(-(x-u).^2/(2*v)); % Binomial
figure(1); display('Binomial Distribution');
plot(x,N); p = input('Probability of event success : ');
title(‘Gaussian PDF’); n = input('Number of test cases : ');
% Uniform for k=0:1:n
display('Uniform Random Variable') nCr =
a = input('minimum value of RV : '); factorial(n)/(factorial(k)*factorial(n-k));
b = input('maximum value of RV : '); B(k+1) = nCr*(p^k)*((1-p)^(n-k));
x = a-5:0.001:b+5; end
for i=1:length(x) figure(3);
if x(i)>= a && x(i)<=b stem(0:n,B);
U(i) = 1/(b-a); title(‘Binomial PDF’);
Output:
7
Experiment 7
Code:
% A template is given
temp = randn(100,1);
% Find matches
matches = n(y>thresh*u);
Output:
matches = 300
8
Experiment 8
Code:
clc
clear all
close all
x=round(rand(1,10));
t=0:0.001:0.999;
s=sin(2*pi*t);
ask=[];
for i=1:10
if x(i)==1
ask=[ask s];
else
ask=[ask zeros(size(s))];
end
end
subplot(211)
stairs(0:10,[x x(10)]);
axis([0,10,-0.2,1.2]);
subplot(212)
plot(0:0.001:9.999,ask);
Output
x= 1 0 1 1 0 0 1 1 1 1
9
Experiment 9
Code:
clc
clear all
close all
x=round(rand(1,10));
t=0:0.001:0.999;
s0=sin(2*pi*2*t);
s1=sin(2*pi*5*t)
fsk=[];
for i=1:10
if x(i)==1
fsk=[fsk s1];
else
fsk=[fsk s0];
end
end
subplot(211)
stairs(0:10,[x x(10)]);
axis([0,10,-0.2,1.2]);
subplot(212)
plot(0:0.001:9.999,fsk);
Output:
x= 0 0 1 0 1 1 1 1 0 0
10
Experiment 10
Code:
clc
clear all
close all
x=round(rand(1,10))
t=0:0.001:0.999;
s=sin(2*pi*t);
psk=[];
for i=1:10
if x(i)==1
psk=[psk s];
else
psk=[psk -s];
end
end
subplot(211)
stairs(0:10,[x x(10)]);
axis([0,10,-0.2,1.2]);
subplot(212)
plot(0:0.001:9.999,psk);
Output:
x= 1 1 0 0 1 0 0 0 0 1
11
Experiment 12
Code:
clear all
close all
clc
b=round(rand(1,12));
t=0:1/60:2-1/60;
s00=cos(2*pi*t+3*pi/4);
s01=cos(2*pi*t+5*pi/4);
s10=cos(2*pi*t+pi/4);
s11=cos(2*pi*t+7*pi/4);
qpsk_1=[];
for i=1:2:12
if [b(i) b(i+1)] == [0 0]
qpsk_1 = [qpsk_1 s00];
elseif [b(i) b(i+1)] == [0 1]
qpsk_1 = [qpsk_1 s01];
elseif [b(i) b(i+1)] == [1 0]
qpsk_1 = [qpsk_1 s10];
elseif [b(i) b(i+1)] == [1 1]
qpsk_1 = [qpsk_1 s11];
end
end
n=length(b);
subplot(2,1,1);
stairs(0:12,[b b(12)]);
subplot(2,1,2);
tb=0:1/60:12-1/60;
plot(tb, qpsk_1);
Output:
b = 1 0 1 0 0 1 1 0 1 1 0 0
12