0% found this document useful (0 votes)
122 views26 pages

Digitalcom Lab Manual New

The document describes simulations of various digital modulation techniques using MATLAB. It includes code to simulate pulse amplitude modulation, pulse code modulation, delta modulation, amplitude shift keying and frequency shift keying. The code generates modulated signals and demodulates them to recover the original message signal. It also includes plots of the message signal, modulated signal and demodulated signal for each technique.

Uploaded by

Akanksha Dixit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views26 pages

Digitalcom Lab Manual New

The document describes simulations of various digital modulation techniques using MATLAB. It includes code to simulate pulse amplitude modulation, pulse code modulation, delta modulation, amplitude shift keying and frequency shift keying. The code generates modulated signals and demodulates them to recover the original message signal. It also includes plots of the message signal, modulated signal and demodulated signal for each technique.

Uploaded by

Akanksha Dixit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 26

Exp:1- Design & simulate the operation of sample and hold circuit using Multisim/TINA Pro & verify

modulated signal waveform.


Code:

clear all
close all
clf
fb=1000 %baseband signal freqquency in hetz
tb=1/fb
fs=40000
ns=fs/fb %number of samples in one period of the base band signal
t=linspace(0,.002,ns)
sq=(1+square(t))/2
asb=5*sin(2*pi*fb*t).*sq
subplot(211)
stem(t,sq)
axis([0 .002 0 1])
xlabel('time in seconds')
ylabel('amplitude in volts')
title('square wave output')
subplot(212)
stem(t,asb)
axis([0 .002 -5 5])
xlabel('time in seconds')
ylabel('amplitude in volts')
title('simulation of samplig process')
clear all;
close all;
clc;
fb=1000; %baseband signal
freqquency in hetz
tb=1/fb;
fs=40000;
ns=fs/fb; %number of samples in
one period of the base band signal
t=linspace(0,.002,ns);
sq=(1+square(t))/2;
x=sin(2*pi*fb*t);
asb=5*x.*sq;
subplot(311);
plot(t,x);
subplot(312);
stem(t,sq);
axis([0 .002 0 1]);
xlabel('time in seconds');
ylabel('amplitude in volts');
title('square wave output');
subplot(313);
stem(t,asb);
axis([0 .002 -5 5]);
xlabel('time in seconds');
ylabel('amplitude in volts');
title('simulation of samplig process');
Exp:2-WAP to simulate Natural Sampling technique using MATLAB & verify the received sampled
waveform.

CODE:-
clc;
clear all;
t = 0:0.001:1;
fc = input('Enter the frequency of carrier signal (square) = ');
fm = input('Enter the frequency of message signal (sine) = ');
a = input('Enter the amplitude of message signal = ');
vc = square(2*pi*fc*t);
vm = a.*sin(2*pi*fm*t);
n = length(vc);
for i = 1:n
if (vc(i)<=0)
vc(i) = 0;
else
vc(i) = 1;
end
end
y = vc.*vm;
subplot(3,1,1);
plot(t,vm);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Message Signal');
axis([0 1 -a-2 a+2]);
grid on;
subplot(3,1,2);
plot(t,vc);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Carrier Signal');
axis([0 1 0 2]);
grid on;
subplot(3,1,3);
plot(t,y);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Natural Sampled Signal');
axis([0 1 -a-2 a+2]);
grid on;

Output:

Enter the frequency of carrier signal (square) = 20


Enter the frequency of message signal (sine) = 2
Enter the amplitude of message signal = 5
Exp:3- Design & simulate the operation of PWM for a frequency less than 1Khz using Multisim/TINA-
pro & verify modulated signal waveform.

Circuit diagram:

New output
Output:
Exp:4- WAP to simulate Pulse code modualation technique using MATLAB & verify modulated signal
waveform.

Code:-
clc;
clear all;
close all;
% Signal Amplitude and Frequency
a=1;
f=2;
t=0:0.01:1;
x=a*sin(2*pi*f*t)+a;
% Plot message signal
subplot(2,1,1);
plot(t,x);
title('Input Signal');
xlabel('Time');
ylabel('Amplitude');
% Plot Sampled Signal
subplot(2,1,2);
stem(t,x);
title('Sampled Signal');
xlabel('Time');
ylabel('Amplitude');
% Modulation Process
partition=[0:0.1:2*a];
codebook=[0:0.1:((2*a)+0.1)];
[index,d]=quantiz(x,partition,codebook);
% Plot Quantized PCM Signal
figure;
subplot(2,1,1);
stairs(t,d);
title('Quantized Signal');
xlabel('Time');
ylabel('Amplitude');
% Plot 1-bit encoder output
pcm=dec2bin(d);
display(pcm);
% Demodulation Process
deco=bin2dec(pcm);
[b,a]=butter(3,0.1,'low');
recovered=filter(b,a,deco);
% Plot the Reconstructed Signal
subplot(2,1,2);
plot(t,recovered);
title('Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');

Output:
New PCM CODE

clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
L=2^n;

% % Signal Generation
% x=0:1/100:4*pi;
% y=8*sin(x); % Amplitude Of signal is 8v
% subplot(2,2,1);
% plot(x,y);grid on;
% Sampling Operation
x=0:2*pi/n1:4*pi; % n1 nuber of samples have tobe selected
s=8*sin(x);
subplot(3,1,1);
plot(s);
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);grid on; title('Sampled Sinal'); ylabel('Amplitude--->');
xlabel('Time--->');

% Quantization Process
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin
and vmax with difference of del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized valuses
[ind,q]=quantiz(s,part,code); % Quantization process
% ind
contain index number and q contain quantized values
l1=length(ind);
l2=length(q);

for i=1:l1
if(ind(i)~=0) % To make index
as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value
inbetween the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize
values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

% Encoding Process
figure
code=de2bi(ind,'left-msb'); % Cnvert the decimal to binary
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j); % convert code matrix to a coded
row vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stairs(coded); % Display the encoded signal
axis([0 100 -2 3]); title('Encoded Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

% Demodulation Of PCM signal

qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb'); % Getback the index in
decimal form
q=del*index+vmin+(del/2); % getback Quantized values
subplot(2,1,2); grid on;
plot(q); % Plot
Demodulated signal
title('Demodulated Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

Exp:5- WAP to simulate DELTA MODULATION technique using MATLAB & verify modulated signal
waveform.
Code:
clc;
clear all;
close all; % Signal Amplitude and Frequency
a=1;
f=2;
t=0:0.01:1;
y=a*sin(2*pi*f*t)+a; % Plot message signal
subplot(2,1,1);
plot(t,y);
title('Message Signal');
xlabel('Time');
ylabel('Amplitude'); % Plot Sampled Signal
subplot(2,1,2);
plot(t,y);
title('Sampled Signal');
xlabel('Time');
ylabel('Amplitude'); % Modulation Process
del=0.05; % Step Size
s(1)=0;
for i=1:100
if(y(i+1)>y(i))
s(i+1)=s(i)+del;
p(i)=1;
else
s(i+1)=s(i)-del;
p(i)=0;
end
end % Plot Quantized DM Signal
figure;
subplot(3,1,1);
stairs(t,s);
title('Quantized Signal');
xlabel('Time');
ylabel('Amplitude'); % Plot 1-bit encoder output
t1=0.01:0.01:1;
subplot(3,1,2);
stem(t1,p);
title('Delta Modulated Signal');
xlabel('Time');
ylabel('Amplitude'); % Demodulation Process
r(1)=0;
for i=1:100
if(p(i)==1)
r(i+1)=r(i)+del;
else
r(i+1)=r(i)-del;
end
end % Plot the Reconstructed Signal
[b,a]=butter(1,0.2,'low');
z=filter(b,a,r);
subplot(3,1,3);
plot(t,z);
title('Filtered Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');

Output:
Exp:6- WAP to simulate Amplitude shift keying modulation using MATLAB & verify modulated signal
waveform.
Code:
clc;
clear all;
close all; % Carrier frequency and amplitude
f=7;
a=1; %6 bits are used
n=[1 0 1 1 0 0];
l=length(n);
if n (1)==1
n(l+1)=1
else
n(l+1)=0
end
l1=length(n)
tn=0:l1-1; %plot message signal
subplot(4,1,1);
stairs(tn,n);
title('message signal');
xlabel('time');
ylabel('amplitude'); %plot carrier signal
t=0:0.01:6;
y1=a*sin(2*pi*f*t);
subplot(4,1,2);
plot(t,y1);
title('carrier signal');
xlabel('time');
ylabel('amplitude'); % Modulation Process
for i=1:6
for j=(i-1)*100:i*100
if(n(i)==1)
s(j+1)=y1(j+1);
else
s(j+1)=0;
end
end
end %plot ASK signal
subplot(4,1,3);
plot(t,s);
title('ASK modulated signal');
xlabel('time');
ylabel('amplitude'); % Demodulation process
for i=1:6
for j=(i-1)*100:i*100
if(s(j+1)==y1(j+1))
x(j+1)=1;
else
x(j+1)=0;
end
end
end %plot demodulated signal
subplot(4,1,4);
plot(t,x);
title('ASK demodulated signal');
xlabel('time');
ylabel('amplitude');

Output:
Exp:7- WAP to simulate Frequency shift keying modulation using MATLAB & verify modulated signal
waveform.
Code:
clc;
clear all;
close all; % Carrier frequency and amplitude
f1=8;
f2=2;
a=1; %6 bits are used
n=[1 0 1 1 0 0];
l=length(n);
if n (1)==1
n(l+1)=1
else
n(l+1)=0
end
l1=length(n)
tn=0:l1-1; %plot message signal
subplot(5,1,1);
stairs(tn,n);
title('message signal');
xlabel('time');
ylabel('amplitude'); %plot carrier signal
t=0:0.01:6;
y1=a*sin(2*pi*f1*t);
y2=a*sin(2*pi*f2*t);
subplot(5,1,2);
plot(t,y1);
title('carrier signal1');
xlabel('time');
ylabel('amplitude');
subplot(5,1,3);
plot(t,y2);
title('carrier signal2');
xlabel('time');
ylabel('amplitude'); % Modulation Process
for i=1:6
for j=(i-1)*100:i*100
if(n(i)==1)
s(j+1)=y1(j+1);
else
s(j+1)=y2(j+1);
end
end
end %plot FSK signal
subplot(5,1,4);
plot(t,s);
title('FSK modulated signal');
xlabel('time');
ylabel('amplitude'); % Demodulation process
for i=1:6
for j=(i-1)*100:i*100
if(s(j+1)==y1(j+1))
x(j+1)=1;
else
x(j+1)=0;
end
end
end %plot demodulated signal
subplot(5,1,5);
plot(t,x);
title('FSK demodulated signal');
xlabel('time');
ylabel('amplitude');

Output:
Exp:8- WAP to simulate Phase shift keying modulation using MATLAB & verify modulated signal
waveform.
Code:
clc;
clear all;
close all; % Carrier frequency and amplitude
f=5;
a=1; %6 bits are used
n=[1 0 1 1 0 0];
l=length(n);
if n (1)==1
n(l+1)=1
else
n(l+1)=0
end
l1=length(n)
t2=0:l1-1; %plot message signal
subplot(5,1,1);
stairs(t2,n);
title('message signal');
xlabel('time');
ylabel('amplitude'); %plot carrier signal
t=0:0.01:6;
y1=a*sin(2*pi*f*t);
y2=a*sin(2*pi*f*t);
subplot(5,1,2);
plot(t,y1);
title('carrier signal1');
xlabel('time');
ylabel('amplitude');
subplot(5,1,3);
plot(t,y2);
title('carrier signal2');
xlabel('time');
ylabel('amplitude'); % Modulation Process
for i=1:6
for j=(i-1)*100:i*100
if(n(i)==1)
s(j+1)=y1(j+1);
else
s(j+1)=y2(j+1);
end
end
end %plot PSK signal

subplot(5,1,4);
plot(t,s);
title('PSK modulated signal');
xlabel('time');
ylabel('amplitude'); % Demodulation process
for i=1:6
for j=(i-1)*100:i*100
if(s(j+1)==y1(j+1))
x(j+1)=1;
else
x(j+1)=0;
end
end
end %plot demodulated signal
subplot(5,1,5);
plot(t,x);
title('PSK demodulated signal');
xlabel('time');
ylabel('amplitude');
Output:
Exp:9- WAP to study the operation of Companding process usnig MATLAB using u-Law & verify
received signal waveform.
Code:
clear all
close all
clc
M=input('enter the signal') %enter the signal with time like sin(2*pi*[0:0.01:1]
Mmax=max(M)
Mn=M/Mmax
u=input('enter the u value') %default value is 255
Vn=log(1+u*Mn)/(log(1+u))
figure(1)
plot(Mn)
figure(2)
plot(Vn)
figure(3)
plot(Mn,Vn)
Output:
Exp:10- WAP to simulate the Probability of Bit Error rate of ASK, FSK & PSK Digital modulation
techniques.
Code:
clc;
clear all;
close all;
% for the values of SNR in dB for 0 to 10
snr_dB=0:10;
snr=10.^(snr_dB/10);
% probability of error expressions for ASK, FSK and PSK
peask=(1/2)*erfc(sqrt(snr/4));
pefsk=(1/2)*erfc(sqrt(snr/2));
pepsk=(1/2)*erfc(sqrt(snr));

% plotting all the BER curves in semilog graph paper

semilogy(snr_dB,peask,snr_dB,pefsk,snr_dB,pepsk);
legend('ASK','FSK','PSK');
xlabel('SNR in dB');
ylabel('SNR in dB');
title('BER Analysis');

Output:
Exp:11- To study the different line coding techniques.
Exp:12- WAP to study and simulate Power Spectral Density of GMSK Modulation technique.

Code:
clc;
clear all;
close all;
pi = 3.141592;
sqrpi = pi^2;

GMSK = [];
GBPSK = [];
GQPSK = [];
xaxis = [];

for i=1:1000
f = i/100;
% f is frequency normalized to to 1/(bit duration)
xaxis = [xaxis, f ];
ymsk = 16/sqrpi * (cos(6.2832 * f))^2/ (1- 16 * f^2)^2;
GMSK = [GMSK, 10 * log10(ymsk)];

ybpsk = 2 * (sin(pi*f)/(pi*f))^2;
GBPSK = [GBPSK, 10 * log10(ybpsk)];
yqpsk = 2 * (sin(2*pi* f)/(2*pi*f))^2;
GQPSK = [GQPSK, 10 * log10(yqpsk)];

end

plot(xaxis,GMSK, 'y-',xaxis,GBPSK, 'c.',xaxis,GQPSK, 'c-.');

axis([0 10 -60 10]);


ylabel('Spectral Power Level in dB');
xlabel('Frequency Offset / Bit Rate')
output:

Pwm code

clc;
clear all;
t=0:0.001:1;
fc = 20;
fm = 2;
a =5;
vc =a.*sawtooth(2*pi*fc*t);
vm = .75*a.*sin(2*pi*fm*t);
n = length(vc);
for i=1:n
if(vm(i)>=vc(i))
pwm(i)=1;
else
pwm(i)=0;
end
end
subplot(3,1,1);
plot(t,vm);
xlabel('Time------->');
ylabel('AMplitude------>');
title('Message Signal');
axis([0 1 -4 4]);
grid on;
subplot(3,1,2);
plot(t,vc);
xlabel('Time------->');
ylabel('Amplitude------>');
title('Carrier Signal');
axis([0 1 -5 5]);
grid on;
subplot(3,1,3);
plot(t,pwm);
xlabel('TIme------>');
ylabel('Amplitude------>');
title('pwm signal output');
axis([0 1 0 2]);
grid on;

You might also like