Name: Shaheryar Alam Khan ROLL NO: FA16-ECE-102 SUBMITTED TO: Khurram Naveed
Name: Shaheryar Alam Khan ROLL NO: FA16-ECE-102 SUBMITTED TO: Khurram Naveed
Name: Shaheryar Alam Khan ROLL NO: FA16-ECE-102 SUBMITTED TO: Khurram Naveed
INFORMATION TECHNOLOGY,ISLAMABAD
DIGITAL SIGNAL PROCESSING
LAB MANUAl
LAB REPORT :03
Sigadd Code:
function [y n] = sigadd(x1,n1,x2,n2)
if n1(1)< n2(1)
a = n1(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
else
a = n2(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
end
if n1(end)>n2(end)
b = n1(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
else
b = n2(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
end
n = a:b;
y = x1+x2;
Sigsubtract Code:
function [g n] = sigsubtract(x1,n1,x2,n2)
if n1(1)< n2(1)
a = n1(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
else
a = n2(1)
x1 = [zeros(1,abs(n1(1)-n2(1))) x1]
end
if n1(end)>n2(end)
b = n1(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
else
b = n2(end)
x2 = [x2 zeros(1,abs(n1(end)-n2(end)))]
end
n = a:b;
g = x1-x2;
OUTPUT:
n1 =
-2 -1 0 1 2
y =
-5 4 -3 2 1
y =
-5 4 -3 2 1
n1 =
-2 -1 0 1 2
a =
-2
x1 =
1 2 -3 4 -5
b =
x2 =
5 2 -1 4 -5
y =
6 4 -4 8 -10
n =
-2 -1 0 1 2
y =
3 2 -2 4 -5
a =
-2
x1 =
1 2 -3 4 -5
b =
x2 =
5 2 -1 4 -5
g =
-4 0 -2 0 0
n =
-2 -1 0 1 2
g =
-2 0 -1 0 0
TASK:02
Convolution:
Code:
n11 = [-2:2];
x11 = [1 2 -3 4 -5];
n2 = [1:5];
x2 = [1 -1 2 -2 3];
d = abs(n11(end)-n2(1));
s = [];
a = [];
subplot(5,1,1)
stem(n11,x11)
title('Input Signal x[n]')
subplot(5,1,2)
stem(n2,x2)
title('Impulse Response h[n]')
[y n1] = sigfold(x2,n2)
subplot(5,1,3)
stem(n1,y)
title('Time Reverse h[n]')
[n1,x1] = sigshift(y,n1,d)
subplot(5,1,4)
stem(n1,x1)
title('Time Shift h[n]')
for i=1:length(x11)+length(n11-1)-1
[n12,x12] = sigshift(x1,n1,d)
[y23 n23] = sigmult(x11,n11,x12,n12)
subplot(5,1,5)
stem(n23,y23)
title('Convolution')
end
OUTPUT:
TASK:03
Convolution as function:
function [y23 n23] = conv(n11,x11,n2,x2)
subplot(5,1,1)
stem(n11,x11)
title('Input Signal x[n]')
subplot(5,1,2)
stem(n2,x2)
title('Impulse Response h[n]')
[y n1] = sigfold(x2,n2)
subplot(5,1,3)
stem(n1,y)
title('Time Reverse h[n]')
[n1,x1] = sigshift(y,n1,d)
subplot(5,1,4)
stem(n1,x1)
title('Time Shift h[n]')
for i=1:length(x11)+length(n11-1)-1
[n12,x12] = sigshift(x1,n1,d)
[y23 n23] = sigmult(x11,n11,x12,n12)
subplot(5,1,5)
stem(n23,y23)
title('Convolution')
end