Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Program code for PCM:

clc;
clear all;
t=0:0.001:2;
y=sin(2*pi*t);
subplot(311)
plot(t,y);
xlabel('time');
ylabel('amp');
title('message signal');
x=square(2*pi*20*t);
subplot(312)
plot(t,x);
xlabel('time');
ylabel('amp');
title('pulse train');
s=y.*(x+1)/2;
subplot(313)
plot(t,s);
xlabel('time');
ylabel('amp');
title('sampled signal');
gtext('Rajesh kumar')
figure(2)
q=uencode(s,6);
subplot(211)
plot(t,q);
xlabel('time');
ylabel('amp');
title('encoded signal');
d=udecode(q,6);
subplot(212)
plot(t,d);
xlabel('time');
ylabel('amp');
title('decoded signal');
gtext('Rajesh Kumar');
Output:
Program code for PCM using A law:
clc;
clear all;
close all;
t=0:0.01:10;
x=exp(t);
figure
for A=1:10:80
y=compand(x,A,50,'A/compressor');
hold on
plot(t,y)
title('compressed signal');
end
gtext('Rajesh Kumar');
figure
for A=1:10:80
y1=compand(x,A,50,'A/expander');
hold
plot(t,y1);
title('expanded signal');
end
gtext('Rajesh Kumar');

Program code for PCM using MU law:

clc
clear all;
close all;
mu=255;
t=-4:0.1:4;
x=exp(t)
v=max(x)
c=compand(x,mu,v,'mu/compander');
e=compand(x,mu,v,'mu/expander');
subplot(311)
plot(t,x);
title('input signal');
xlabel('t');
ylabel('amp')
subplot(312)
plot(t,c);
title('compressor')
xlabel('t');
ylabel('amp');
subplot(313)
plot(t,e);
title('expander');
xlabel('t');
ylabel('amp');
gtext('Rajesh Kumar');

Program code for ASK:

clc;
clear all;
close all;
b=input('enter bit stream');
n=length(b);
t=0:0.01:n;
x=1:1:(n+1)*100;
for i=1:n
bw(x(i*100:(i+1)*100))=b(i)
end;
bw=bw(100:end);
sint=sin(2*pi*t);
st=bw.*sint;
subplot(311)
plot(t,bw)
xlabel('t');
ylabel('amp');
title('input signal');
subplot(312)
plot(t,sint)
xlabel('t');
ylabel('amp');
title('carrier signal');
subplot(313)
plot(t,st)
xlabel('t');
ylabel('amp');
title('ask');
gtext('Rajesh Kumar')

Program code for DPCM:

clc;
clear all;
close all;
intervals=[-1:0.1:0.9];
codes=[-1:0.1:1];
mu=1;
max=4;
t=[0:pi/50:2*pi];
x=sin(3*t);
in=compand(x,mu,max,'mu/compressor');
[predictor,codes,intervals]=dpcmopt(in,1,length(codes));
enco_in=dpcmenco(in,codes,intervals,predictor);
deco_in=dpcmdeco(enco_in,codes,predictor);
out=compand(deco_in,mu,max,'mu/expander');
subplot(311)
plot(t,x);
xlabel('time->');
ylabel('amp->');
title('input signal');
subplot(312)
plot(t,enco_in);
xlabel('time->');
ylabel('amp->');
title('encoded signal');
subplot(313)
plot(t,deco_in);
xlabel('time->');
ylabel('amp->');
title('decoded signal');
gtext('Rajesh Kumar');

output:
exponential input:
Sine input:
Output:
Sine input:

Exponential input:
Output:
Output:

You might also like