1.15 Sample a continuous time system

Given the following system, sample the input and find and plot the plant output

pict

Use sampling frequency \(f=1\) Hz and show the result for up to \(14\) seconds. Use as input the signal \(u(t)=\exp (-0.3 t) \sin (2 \pi (f/3) t)\).

Plot the input and output on separate plots, and also plot them on the same plot.

Mathematica

Clear["Global`*"]; 
 
nSamples =14; 
f =1.0; 
sampleTime =1/f; 
u[t_] := Sin[2*Pi*(f/3)*t]*Exp[-0.3*t] 
ud[n_]:= u[n*sampleTime]; 
plant = TransferFunctionModel[ 
            (3 s)/((s+1)(s+2)),s]; 
sysd  = ToDiscreteTimeModel[plant, 
         sampleTime, 
         z, 
         Method->"ZeroOrderHold"]
 

pict

 

opts = {Joined->True,PlotRange->All, 
  AspectRatio->1,InterpolationOrder->0, 
  ImageSize->200,Frame->True, 
  PlotRange->{{0,nSamples},{-0.5,0.5}}, 
  GridLines->Automatic,GridLinesStyle->Dashed}; 
 
inputPlot = ListPlot[Table[ud[k],{k,0,nSamples}], 
   Evaluate[opts], 
   FrameLabel->{{"u(t)",None}, 
             {"n","plant input u(nT)"}}, 
   PlotStyle->{Thick,Red}]; 
 
plantPlot=ListPlot[OutputResponse[sysd,Table[ud[k], 
 {k,0,nSamples}]], 
 Evaluate[opts], 
 FrameLabel->{{"y(t)",None}, 
             {"n","plant output y(nT)"}}, 
 PlotStyle->{Thick,Blue}]; 
 
Grid[{{inputPlot,plantPlot}}]
 

pict

Show[{inputPlot,plantPlot}, 
     PlotLabel->"input/output plot"]
 

pict

Matlab

clear all; close all; 
 
nSamples = 14; 
f = 1; 
T = 1/f; 
u=@(t) sin(2*pi*(f/3).*t).*exp(-0.3.*t); 
ud=@(n) u(n*T); 
U=ud(1:14);  %sampled input 
s=tf('s'); 
plant  = (3*s)/((s+1)*(s+2)); 
plantD = c2d(plant,T,'zoh')
 

plantD = 
 
     0.6976 z - 0.6976 
  ------------------------ 
  z^2 - 0.5032 z + 0.04979 
 
Sample time: 1 seconds 
Discrete-time transfer function.
 

lsim(plantD,U,0:nSamples-1) 
grid
 

pict