DIGITAL SIGNAL PROCESSING
LAB ASSIGNMENT –I
NAME :- AYUSH YADAV
REG. NO. :-17BEC0555
SLOT :- G1+TG1
Task-1:
(i) Using MATLAB
delayed unit step sequence u(n-N) where N=5, unit ramp sequence
r(n). Take time indices from -10 to 10.
OBJECTIVE: To generate unit sample sequence delta(n), unit step
sequence u(n), delayed unit step sequence u(n-N) where N=5, unit
ramp sequence r(n).
PROGRAM:
clc;
clear all;
close all;
n=-10:10;
x=[Link];
d=[zeros(1,10),ones(1,1),zeros(1,10)];
u1=[zeros(1,10),ones(1,11)];
u2=[zeros(1,15),ones(1,6)];
r=[zeros(1,11),x];
subplot(2,2,1);
stem(n,d);
subplot(2,2,2);
stem(n,u1);
subplot(2,2,3);
stem(n,u2);
Experimental Result:
(b) Generate a real exponential sequence for 0<a<1, a>1, -1< a<0,
a<-1. Use ‘for’ loop and subplot.
OBJECTIVE-To plot graph for 0<a<1, a>1, -1< a<0, a<-1.
PROGRAM-
clc;
clear all;
close all;
n=-10:10;
for i=1:4;
a=input('Enter a value:')
y=a.^n;
subplot(2,2,i);
stem(n,y)
end
Experimental Result:
(c) Generate a 7Hz continuous sinusoid plot of amplitude 0.8 and
15Hz continuous sinusoid plot of amplitude 0.6. Comment on the
sampling frequency.
Objective: To generate a 7Hz continuous sinusoid plot of amplitude
0.8 and 15Hz continuous sinusoid plot of amplitude 0.6.
Program:
clc;
clear all;
close all;
t=0:.01:pi;
title('Case 1:A=0.8 and f=7 Hz Case 2:A=0.6 and
f=15Hz')
a=input('Enter amplitude of signal:');
f=input('Enter frequency of signal:');
T=1/f;
y=a*sin(2*pi*f*t);
subplot(2,1,1);
plot(t,y)
hold on
a=input('Enter amplitude of signal:');
f=input('Enter frequency of signal:');
T=1/f;
y=a*sin(2*pi*f*t);
subplot(2,1,2);
plot(t,y)
Experimental Result:
Enter amplitude of signal:.8
Enter frequency of signal:6
Enter amplitude of signal:.6
Enter frequency of signal:15
(d) Plot 𝑢(𝑛 − 3),𝑢(𝑛 + 5),𝑢(−𝑛 − 3),𝑢(−𝑛 + 5) from -10 to 10 time
indices. Indicate which signal is causal, anti-causal and non-causal.
Objective: To plot 𝑢(𝑛 − 3),𝑢(𝑛 + 5),𝑢(−𝑛 − 3),𝑢(−𝑛 + 5) from -10 to
10 time indices and to check whether it is causal, anti-causal and non-
causal.
Program:
clc;
clear all;
close all;
n=-[Link];
u1=[zeros(1,13),ones(1,8)];
u2=[zeros(1,5),ones(1,16)];
u3=[ones(1,8),zeros(1,13)];
u4=[ones(1,16),zeros(1,5)];
subplot(2,2,1);
stem(n,u1);
subplot(2,2,2);
stem(n,u2);
subplot(2,2,3);
stem(n,u3);
subplot(2,2,4);
stem(n,u4);
Experimental Result:
(ii) Using MATLAB perform the linear convolution between input
x(n) and impulse response h(n) to obtain the response of LTI system
y(n) in the time domain without using the inbuilt function ‘conv’.
Verify the result using ‘conv’.
METHOD I:
OBJECTIVE-To verify Circular Convolution
Algorithm / Procedure-
PROGRAM-
clc
clear all
close all
n=input('Enter the length of x:');
for i=1:n;
x(i)=input('Enter elements of x:');
end
X=x;
m=input('Enter the length of impulse function h:');
for i=1:m;
h(i)=input('Enter elements of h:');
end
H=h;
p=n+m-1;
for i=(n+1):p;
x(i)=0;
end
x=x';
for i=(m+1):p;
h(i)=0;
end
for i=1:p;
if(i>1)
x=circshift(x,[1,0]);
end
for j=1:p;
f(j,i)=x(j);
end
end
y=h';
conv0=f*y;
display(conv0.');
%To verify using convolution function
w = conv(X,H)
Manual Calculation:
Experimental result & inference:
Enter the length of x:3
Enter element of x:1
Enter element of x:2
Enter element of x:3
Enter the length of h:3
Enter element of h:4
Enter element of h:5
Enter element of h:6
f=
1 0 0 3 2
2 1 0 0 3
3 2 1 0 0
0 3 2 1 0
0 0 3 2 1
Result:
4 13 28 27 18
w=
4 13 28 27 18
METHOD 2:
OBJECTIVE-To verify Circular Convolution
Algorithm / Procedure-
PROGRAM-
clc
clear all
close all
n=input('Enter the length of x:');
for i=1:n;
x(i)=input('Enter element of x:');
end
m=input('Enter the length of h:');
for i=1:m;
h(i)=input('Enter element of h:');
end
H=h;
X=x;
p=n+m-1;
for i=(n+1):p;
x(i)=0
end
for i=(m+1):p;
h(i)=0
end
f=x'.*h
s=2;
sum=0;
for k=1:p;
for i=1:p;
for j=1:p;
if(i+j==s)
sum=sum+f(i,j);
end
end
end
c(k)=sum;
sum=0;
s=s+1;
end
display(c)
%To verify using conv function
w = conv(X,H)
Manual Calculation
Experimental result & inference
Enter the length of x:3
Enter element of x:1
Enter element of x:2
Enter element of x:3
Enter the length of h:3
Enter element of h:4
Enter element of h:5
Enter element of h:6
f=
4 5 6 0 0
8 10 12 0 0
12 15 18 0 0
0 0 0 0 0
0 0 0 0 0
c=
4 13 28 27 18
w=
4 13 28 27 18