% a) Impulese response
% Transfer function H(s)=1/(1+s)
syms t real; syms s;
H1=1/(1+s);
in1=exp(-2*t)*heaviside(t);
imp1=ilaplace(H1,s,t)*heaviside(t);
pretty(imp1)
% Plot impulse response
n1=[0 1]; d1=[1 1];
impulse(n1,d1), title('Impulse of in1=exp(-2t)u(t)')
% b) Numeric matlab & convolution for out(t)
% Time vector for non-zero values of input
goin=-7; stopin=0; dt=.01; tin=goin:dt:stopin; in=ones(size(tin))
% Time vector for impulse response
goimp=0; stopimp=9; timp=goimp:dt:stopimp; imp=exp(-timp);
% Time vector for nat
gonat=goin+goimp; stopnat=stopin+stopimp; tnat=gonat:dt:stopnat;
% Non-zero values of solution
nat = dt*conv(in,imp);
% Plots
subplot(311),plot(tin,in),xlabel('t'),ylabel('in(t)'),title('')
subplot(312),plot(timp, imp),xlabel('t'),ylabel('imp(t)'),title('')
subplot(313),plot(tnat,nat),xlabel('t'),ylabel('nat(t)'),title('')
% c) Integration to determine out(t)
syms bob real;
out1=int(subs(in1,t,bob)*subs(imp1,t,t-bob),bob,-inf,inf);
pretty(out1)
out1=simplify(out1)
ezplot(out1)
imp1=ilaplace(H1,s,t)
imp1=ilaplace(H1,s,t)*heaviside(t);
% Plot impulse response
n1=[0 1]; d1=[1 1];
impulse(n1,d1), title('Impulse of in1=exp(-2t)u(t)')
t=0:0.05:5;
t2=0:0.05:10;
input=arrayfun(@(t) exp(-2*t),t);
imp=arrayfun(@(t) exp(-t),t);
output=conv(imp,input);
clf
plot(t,input)
hold on
plot(t,imp)
plot(t2,output)
input=arrayfun(@(t) exp(-2*t),t);
t=0:0.05:10;
bob=0:0.05:5;
out1=int(subs(in1,t,bob)*subs(imp1,t,t-bob),bob,-inf,inf);
pretty(out1)
plot(t,out1)
input=arrayfun(@(t) exp(2*t),t); % #2
input=arrayfun(@(t) exp(2*t),t); % #3
input=arrayfun(@(t) exp(2*(t-7)),t); % #4
t=0:0.05:10; % Time vector
in1=exp(-2*t)*heaviside(t); % Input
imp1=ilaplace(H1,s,t); % Impulse response
out1=int(subs(in1,t,bob)*subs(imp1,t,t-bob),bob,-inf,inf);
pretty(out1)
temp1=size(t);
temp2=size(t2);
output2=zeros(1,temp2(2));
for i=1:temp2(2)
for j=1:temp1(2)
if ((i-j)>0)&&(i-j<102)
output2(i)=output2(i)+imp(j)*input(i-j);
end
end
end
syms t s bob;
H1=1/(1+s);
imp1=ilaplace(H1,s,t);
imp1=imp1*heaviside(t);
in1=exp(-2*t)*heaviside(t);
out1=int(subs(imp1,t,bob)*subs(in1,t,t-bob),bob,0,10);
%We integrate from 0 to 10 only because this is the space of interest
%typing "out1" will show you the piecewise function that resulted from the integration.
%Select the piece that lies in the [0,10] space and create a second symbolic variable with it.
%Name it "out1inbound".
ezplot(out1inbound,[0,10])
t=-5:0.05:5;
t2=-10:0.05:10;
temp1=size(t);
temp2=size(t2);
output2=zeros(1,temp2(2));
for i=1:temp2(2)
for j=1:temp1(2)
if ((i-j)>0)&&(i-j<102)
output2(i)=output2(i)+imp(j)*input(i-j);
end
end
end
% d) Symbolic Matlab to verify (c)
syms in1 imp1 s; syms t bob real;
H1=1/(1+s); % Transfer function
in1=exp(-2*t)*heaviside(t); % Input
imp1=ilaplace(H1,s,t); % Impulse response
out1=int(subs(in1,t,bob)*subs(imp1,t,t-bob),bob,-inf,inf);
pretty(out1)
ezplot(t,out1),title('out(t) w/ symbolic matlab')