Plot the impulse response of \(H(z)=z/(z^2-1.4 z+0.5)\) and using sampling period of \(T=0.5\) find continuous time approximation using zero order hold and show the impulse response of the system and compare both responses.
Mathematica
maxSimulationTime = 10; samplePeriod = 0.5; tf = TransferFunctionModel[z/(z^2-1.4 z+0.5), z, SamplingPeriod->samplePeriod];
Find its impulse response
discreteResponse=First@OutputResponse[tf,DiscreteDelta[k], {k,0,maxSimulationTime}]
{0.,1.,1.4,1.46,1.344,1.1516,0.94024,0.740536, 0.56663,0.423015,0.308905,0.22096,0.154891, 0.106368,0.0714694,0.0468732,0.0298878, 0.0184063,0.0108249,0.00595175,0.00291999}
approximate to continuous time, use ZeroOrderHold
ctf = ToContinuousTimeModel[tf, s, Method -> "ZeroOrderHold"]
Find the impulse response of the continuous time system
continouseTimeResponse=Chop@First@OutputResponse[ctf,DiracDelta[t],t]
\[ -1.25559 e^{-0.693147 t} (-13.3012 \theta (t) \sin (0.283794 t)-1. \theta (t) \cos (0.283794 t)) \]
continouseTimeResponse=Chop@First@OutputResponse[ctf,DiracDelta[t], {t,0,maxSimulationTime}]
Plot the impulse response of the discrete system
ListPlot[ discreteResponse, DataRange->{0,maxSimulationTime}, Filling->Axis, FillingStyle->{Red, PlotMarkers->Graphics[{PointSize[0.03], Point[{0,0}]}]},PlotRange->All, ImageSize->300,ImagePadding->{{45,10},{35,10}}, AspectRatio->0.9,AxesOrigin->{0,0},Frame->True,Axes->None, ImageSize->300, Frame->True ]
Plot the impulse response of the continuous system
Plot[samplePeriod *continouseTimeResponse,{t,0,maxSimulationTime}, PlotRange->All,Frame->True,ImageSize->300]
Plot both responses on the same plot
p = Show[ ListPlot[ discreteResponse, Filling -> Axis, FillingStyle -> {Red, PlotMarkers -> Graphics[{PointSize[0.03], Point[{0, 0}]}]}, PlotRange -> All, DataRange -> {0, maxSimulationTime}, ImageSize -> 300, ImagePadding -> {{45, 10}, {35, 50}}, AspectRatio -> 0.9, AxesOrigin -> {0, 0}, Frame -> True, Axes -> None], Plot[samplePeriod *continouseTimeResponse, {t, 0, maxSimulationTime}, PlotRange -> All], PlotRange -> All, FrameLabel -> {{Style["response", 10], None}, {Style["time (sec)", 10], "impulse response of discrete system \ with its continouse time approximatio"}} ]
Do the same plot above, using stair case approximation for the discrete plot
Show[ ListPlot[ discreteResponse, Filling->None,PlotRange->All,DataRange->{0,maxSimulationTime}, ImageSize->300,ImagePadding->{{45,10},{35,50}},AspectRatio->0.9, AxesOrigin->{0,0},Frame->True,Axes->None, Joined->True,InterpolationOrder->0,PlotStyle->Red], Plot[samplePeriod *continouseTimeResponse,{t,0,maxSimulationTime}, PlotRange->All], PlotRange->All,FrameLabel->{{Style["response",10],None}, {Style["time (sec)",10],"impulse response"}}]
Matlab
clear all; maxSimulationTime = 15; samplePeriod = 0.5; z=tf('z',samplePeriod); tf=z/(z^2-1.4*z+0.5) impulse(tf,0:samplePeriod:maxSimulationTime) ctf=d2c(tf,'zoh') hold on impulse(ctf,0:maxSimulationTime) title(['impulse response of discrete system with',... ' its continuous time approximation']); xlabel('time (sec)'); ylabel('response');