PART1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Badrul Amin bin Zambri 212759

PART 1

% close all other command and clear all variables from matlab workspace
close all
clear
clc

% defines a function x(t) and h(t) and the both function will return value 1.0 when the inout
is greater than or equal to 0 and otherwise.
x=@(t) 1.0*(t>=0).*exp(-t);
h=@(t) 1.0*(t>=0).*exp(-2*t);

%Set a step size


delta=0.01;
%generates a range of time values for x(t) and h(t) which range is form -10 to 10
tx=-10:delta:10;
th=-10:delta:10;

%convolves the two functions x(t) and h(t)


y=conv(x(tx),h(th))*delta;
% generates a range of time values for y(t) based on the time ranges for x(t) and h(t)
ty=(tx(1)+th(1)):delta:(tx(end)+th(end));

%Create figure for plotting and the title


figure()
title('output y')
% Plot input signal of x(t).
subplot(3,1,1)
plot(tx,x(tx))
xlabel('n'); title('x(t)'); ylim([min(x(tx))-1,max(x(tx))+1]); grid on
% Plot impulse response of h(t)
subplot(3,1,2)
plot(th,h(th))
xlabel('n'); title('h(t)'); ylim([min(h(th))-1,max(h(th))+1]); grid on
% Plot the output signal of y
subplot(3,1,3)
plot(ty,y);
xlabel('n'); title('x(t)*h(t)');ylim([min(y)-1,max(y)+1]); grid on

You might also like