clc;
clear all;
close all;
%% 6 (a)
n=[-10:0.01:10];
for i=1:length(n)
if(n(i)<-5 || n(i)>5)
tri(i)=0;
elseif(n(i)<0)
tri(i)=1+n(i)/5;
else
tri(i)=1-n(i)/5;
end
end
for i=1:length(n)
signal_exp(i)=exp(-abs(n(i)));
end
subplot(311)
plot(n,tri)
subplot(312)
plot(n,signal_exp)
y1=conv(tri,signal_exp);
subplot(313)
plot(y1)
title('Convolution Result')
%% 6 (b)
for i=1:length(n)
if(n(i)<-2)
urect1(i)=0;
elseif(n(i)>3)
rect1(i)=0;
else
rect1(i)=1;
end
end
for i=1:length(n)
if(n(i)<-3)
rect2(i)=0;
elseif(n(i)>2)
rect2(i)=0;
else
rect2(i)=1;
end
end
x1=rect1;
x2=rect2;
figure(2)
subplot(311)
plot(n,x1)
subplot(312)
plot(n,x2)
y2=conv(x1,x2);
subplot(313)
plot(y2)
title('Convolution Result')
%% 6 (c)
n1=[-2.5 -.25 0.5];
x1=[4 -4 2];
n2=[-4:0.25:10];
for i=1:length(n2)
if(n2(i)<3)
x2_n(i)=0;
else
x2_n(i)=3*exp(-2*n2(i))
end
end
figure(3)
subplot(311)
stem(n1,x1,'filled')
grid on
subplot(312)
plot(n2,x2_n)
grid on
y3=conv(x1,x2_n);
subplot(313)
% stem(y3,'filled')
plot(y3)
title('Convolution Result')
grid on