0% found this document useful (0 votes)
2 views30 pages

DSP File 37-1

The document is a lab file for the Data Communication and Networks course at Maharaja Surajmal Institute of Technology, detailing various experiments conducted using MATLAB 7.0. It includes programming tasks for plotting signals, performing linear and circular convolution, and calculating the Discrete Fourier Transform (DFT) and its properties. Each experiment outlines the aim, software used, program code, and results achieved.

Uploaded by

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

DSP File 37-1

The document is a lab file for the Data Communication and Networks course at Maharaja Surajmal Institute of Technology, detailing various experiments conducted using MATLAB 7.0. It includes programming tasks for plotting signals, performing linear and circular convolution, and calculating the Discrete Fourier Transform (DFT) and its properties. Each experiment outlines the aim, software used, program code, and results achieved.

Uploaded by

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

Department of Electronics & Communication Engineering

MAHARAJA SURAJMAL INSTITUTE OF


TECHNOLOGY
(Janakpuri)

Data Communication and Networks


Lab File
th
6 Semester

Submitted to : Submitted by :
Mr. Sandeep Sheoran Name : Siddharth Singh
Assistant Professor Branch : ECE – 3
ECE Department Enrol. No: 04496302820
MSIT Class Sr. No. : 37
INDEX

SERIAL NAME OF EXPRIMENTS DATE TEACHER’S


NO. SIGN.
Experiment 1

Aim : Write a program to Plot unit step, Unit Impulse, ramp, exponential, Sine & cosine
Signal in both continuous and discrete form.
Software used : MATLAB 7.0
Program :
clc;
clear all;
close all;
x=-pi:0.2:pi;
% Sine Function
subplot(2,6,1);
plot(x,sin(x));
xlabel('time');
ylabel('amplitude');
title('sine continuous');
subplot(2,6,2);

stem(x,sin(x));
xlabel('time');
ylabel('amplitude');
title('sine discrete');
% Cosine Function
subplot(2,6,3);

1
plot(x,cos(x));
xlabel('time');
ylabel('amplitude');
title('cos continuous');
subplot(2,6,4);
stem(x,cos(x));
xlabel('time');
ylabel('amplitude');
title('cos discrete');
% Unit Step Function
t=0:1:10;
y=ones(1,11);
subplot(2,6,5);
plot(t,y);
xlabel('time');
ylabel('amplitude');
title('step continuous');
subplot(2,6,6);
stem(t,y);
xlabel('time');
ylabel('amplitude');
title('step discrete');

2
% Ramp Function
n=0:1:10;
a=1:1:11;
subplot(2,6,7);
plot(n,a);
xlabel('time');
ylabel('amplitude');
title('ramp continuous');
subplot(2,6,8);
stem(n,a);
xlabel('time');
ylabel('amplitude');
title('ramp discrete');
% Exponential Function
m=-pi:0.1:pi;
b=exp(m);
subplot(2,6,9);

plot(m,b);
xlabel('time');
ylabel('amplitude');
title('exp continuous');
subplot(2,6,10);
stem(m,b);

3
xlabel('time');
ylabel('amplitude');
title('exp discrete');
% Impulse Function
p=-3:1:3;
c=[0,0,0,1,0,0,0];

subplot(2,6,11);
plot(p,c);
xlabel('time');
ylabel('amplitude');
title('Impulse continuous');
subplot(2,6,12);
stem(p,c);
xlabel('time');
ylabel('amplitude');
title('Impulse discrete');

Result : Unit step, Unit Impulse, ramp, exponential, Sine & cosine Signal in both
continuous and discrete form is plotted using MATLAB7.0.

4
Output

5
Experiment 2
Aim : Write a program to find Convolution.

(A) Linear Convolution (B) Circular Convolution


Software used : MATLAB 7.0
Program : (A) Linear Convolution
clc;
clear all;
close all;
x1=input('enter the first sequence x1(n):');
x2=input('enter the second sequence x2(n):');
L=length(x1);
M=length(x2);
N=L+M-1;
Yn=conv2(x1,x2);
disp('the values of Yn are');
disp(Yn);
N1=0:L-1;
subplot(3,1,1);
stem(N1,x1);
grid on;
xlabel('N1----->');
ylabel('amplitude- - - ->');
title('first sequence');
N2=0:M-1;

6
subplot(3,1,2);
stem(N2,x2);
grid on;
xlabel('N2----->');
ylabel('amplitude- - - ->');
title('second sequence');
N3=0:N-1;
subplot(3,1,3);
stem(N3,Yn);
grid on;
xlabel('N3----->');
ylabel('amplitude- - - ->');
title('output convolution sequence');

Result : Linear Convolution has been performed using MATLAB7.0.

Output

7
Output

8
Program : (B) Circular Convolution
clc;
close all;
clear all;
x=input('enter the first sequence x(n)');
h=input('enter the second sequence h(n)');
m=length(x);
n=length(h);
N=max(m,n);
x=[x,zeros(1,N-m)];
h=[h,zeros(1,N-n)];
for n=1:N y(n)=0;
for i=1:N j=n-i+1;
if(j<=0) j=N+j;
end
y(n)=[y(n)+x(i)*h(j)];
end
end
n=0:N-1;
subplot(3,1,1);
disp('first sequence x is : ');
disp(x);
stem(n,x);
xlabel('n');
ylabel('x(n)');

9
title('first sequence');
grid on;
subplot(3,1,2);
disp('second sequence h is :');
disp(h);
stem(n,h);
xlabel('n');
ylabel('h(n)'); title('second
sequence : '); grid on;
subplot(3,1,3);
disp('convoluted sequence y(n) is :');
disp(y);
stem(n,y);
xlabel('n');
ylabel('y(n)');
title('circular convoluted sequence ');
grid on;
Result : Circular Convolution has been performed using MATLAB7.0.
Output

10
Output

11
Experiment 3

Aim : Write a program to perform Linear convolution using circular convolution and
Vice Versa.
Software used : MATLAB 7.0
Program : (A) Linear convolution using circular convolution.
clc;
clear all;
close all;
x1 = input(‘Enter the 1st Sequence: ’ );
x2=input(‘Enter the 2nd Sequence: ’);
l1=length(x1);
l2=length (x2);
n=l1+l2-1;
subplot(3,1,1);
stem(x1);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘first Sequence’);
subplot(3,1,2);
stem(x2);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘second Sequence’);

12
if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
elseif l2>l1
l3=l2-l1;
x1=[x1,zeros(1,l3)];
end
n=l1+l2-1;
f=count(x1,x2,n);
disp(‘The convoluted sequence is:’);
disp(f);
Subplot(3,1,3);
stem(f);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title (‘Convoluted Sequence:’);

Result : Linear convolution using circular convolution has been performed successfully.

13
Output

14
(B) Circular convolution using Linear convolution.
clc;
clear all;
close all;

x =input (‘Enter the first


sequence’); n1=length(x);

h=input('Enter the second


sequence’); n2=length(h);

n=0:1:n1-1; subplot
(3, 1, 1); stem(n,x);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘first
Sequence’);
n=n1+n2-1;
if n1>n2
n3=n1-n2;
h=[h,zeros(1,n3)];
elseif n2>n1
n3=n2-n1;
x=[x,zeros(1,n3)];
end
x=[x,zeros(1,n-n1)];

15
h=[h,zeros(1,n-n2)];
for n=1:n y(n)=0;
for i=1:n j=n-i+1;
if(j<=0) j=n+j;
end
y(n)=[y(n)+x(i)*h(j)];
end
end
disp(‘circular convolution of x&h is:’);
disp(y);
Subplot(3,1,3);
stem(y);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title (‘Circular Convoluted Sequence’);

Result : Circular convolution using Linear convolution has been performed successfully.

16
Output

17
Experiment 4

Aim : Write a program to find


(A) 8 point DFT, it’s magnitude and phase plot and inverse DFT.
(B) 16 point DFT, it’s magnitude and phase plot and inverse DFT.
Software used : MATLAB 7.0
Program :

clc;
clear all;
close all;
xn= input(‘Enter the Sequence x(n): ’); % Get 8 point sequence
ln=length(xn); % from user for 8 point DFT
xk=zeros(1,ln); % Get 16 point sequence
ixk=zeros(1,ln); % from user for 16 point DFT
for k=0:ln-1
for n=0:ln-1

xk(k+1)=xk(k+1)+( xn(n + 1)*exp(1i*2*pi*k*n /ln));


end
end

t =0:ln-1;
Subplot(2,2,1);
stem(t,xn);
xlabel(‘Time’);

18
ylabel(‘Amplitude’);
title (‘input Sequence’);
magnitude=abs(xk);
subplot (2, 2, 2);
stem(t,magnitude);
xlabel(‘k’);
ylabel(‘amplitude’);
title(‘Magnitude response’);
magnitude=abs(xK);
phase=angle(xk);
subplot(2, 2, 3);
stem(t, phase);
xlabel(‘k’);
ylabel('amplitude’);
title(‘Phase response’);
for k=0:ln-1
for n=0:ln-1

ixk(n+1)=ixk(n+1)+(xk(k+ 1)*exp(1i*2*pi*k*n /ln));


end
end
ixk=ixk./ln;
subplot(2,2,4);
stem(t,ixk);
xlabel(‘time index’);

19
ylabel(‘amplitude’);
title (‘IDFT sequence’);

Result : 8 point DFT ,16 point DFT and their magnitude, phase plot and inverse DFT has
been performed successfully.

for 8 point DFT: 8 point sequence [1, 2, 3, 4, 5, 6, 7, 8]

for 16 point DFT: 16 point sequence [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7,8]

20
Output
for 8 point DFT

21
Output
for 16 point DFT

22
Experiment 5

Aim : Perform the following properties of DFT


(A) Circular shift of a sequence
(B) Circular fold of a sequence
Software used : MATLAB 7.0
Program : (A) Circular shift of a sequence
clc;
close all;
clear all;
x=input('enter the squence');
n=input('n point dft');
z=fft(x,n);
l=2;
f=circshift(x,[1,l]);
subplot(3,1,1);
stem(f);
title('shifted sequence');
y=0;
for p=1:n;
y(p)=0;
k=p;
y(p)=(z(k)*exp(-1i*2*pi*(k-1)*1/n));
end

23
subplot(3,1,2);
stem(y);
title('DFT of shifted sequence');
W=fft(f);
subplot(3,1,3);
stem(W);
title('LDFT of shifted sequence by function');
disp(W);

Result : Circular shift of a sequence has been performed successfully.

Command window :

24
Output

25
(B) Circular fold of a sequence
clc;
close all;
clear all;
X=input('Enter the sequence');
a=length(X);
n=1:1:a;
subplot(2, 1, 1);
stem(n,X);
xlabel('number of samples');
ylabel('amplitude');
title('Input signal');
m=-a:1:-1;

y = X (a-n+1); subplot
(2,1,2); stem(m,y);
xlabel('number of
samples');
ylabel('amplitude');
title('folded signal');
display(X); display(y);
display(n);
display(m);

Result : Circular fold of a sequence has been performed successfully.

26
Command window

27
Output

28

You might also like