Digital Signal Processing: Name:-Ayush Yadav REG. NO.:-17BEC0555 SLOT: - G1+TG1
Digital Signal Processing: Name:-Ayush Yadav REG. NO.:-17BEC0555 SLOT: - G1+TG1
LAB ASSIGNMENT –I
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=1:1:10;
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:
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=-10:1:10;
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:
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
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