1.4 Obtain the response of a transfer function for an arbitrary input

Problem: Find the response for the continuous time system defined by the transfer function \[ H(s)=\frac {1}{s^{2}+0.2s+1}\] when the input is given by \[ u(t)=\sin (t)\] and display the response and input on the same plot.

Side note: It was easier to see the analytical form of the responses in Mathematica and Maple so it is given below the plot.

Mathematica

Clear["Global`*"]; 
SetDirectory[NotebookDirectory[]] 
sys=TransferFunctionModel[1/(s^2+2/10 s+1),s]; 
u = Sin[t]; 
y = OutputResponse[sys, u, t]; 
p = Grid[{ 
   {Plot[Evaluate@{y, u}, {t, 0, 50}, 
     PlotRange -> {{0, 50}, {-5, 5}}, 
     Frame -> True, 
     FrameLabel -> {{"y(t)", None}, 
           {"t", "input and its reponse"}}, 
     GridLines -> Automatic, 
     GridLinesStyle -> Dashed, 
     ImageSize -> {300, 300}, 
     PlotStyle -> {Red, Black}, 
     AspectRatio -> 1] 
    } 
   }, Alignment -> Left, Frame -> True]
 

pict

 

Matlab

clear all; 
close all; 
t   = 0:0.05:50; 
u   = sin(t); 
s   = tf('s'); 
sys = 1/(s^2+0.2*s+1); 
[num,den] = tfdata(sys,'v'); 
y = lsim(num,den,u,t); 
plot(t,u,'k',t,y,'r'); 
title('input and its response'); 
xlabel('t'); ylabel('y(t)'); 
xlim([0 50]); 
ylim([-5 5]); 
grid on; 
set(gcf,'Position',[10,10,310,310]);
 

pict

 

Maple

restart; 
with(inttrans):H:=1/(s^2+0.2*s+1); 
input:=sin(t); 
inputS:=laplace(input,t,s): 
y:=invlaplace(inputS*H,s,t); 
plot([y,input],t=0..25, 
 title=`system response`, 
 labels=[`time`,`y(t)`], 
 color=[black,red], 
 legend=["response","input"]);
 

pict

 

Using DynamicSystem package

restart: 
alias(DS=DynamicSystems): 
sys :=DS:-TransferFunction(1/(s^2+0.2*s+1)): 
p1:=DS:-ResponsePlot(sys, sin(t), 
 duration=25,color=black,legend="response"): 
p2:=plot(sin(t),t=0..25,color=red, 
   legend="input",size=[400,"default"]): 
plots:-display([p2,p1],axes=boxed, 
  title="step and impulse reponses", 
  legendstyle= [location=right]);
 

pict