# RST controller in Mathematica

I was wondering, if it is possible to simulate an RST controller using Mathematica ?

This is what I tried, but the computation of the closed loop does not work:

G = TransferFunctionModel[(0.1*z^-1 - 0.2*z^-2)/(1 - 1.3 z^-1 +
0.42*z^-2), z];
R = TransferFunctionModel[3 - 3.94 z^-1 + 1.3141 z^-2, z];
S = TransferFunctionModel[1 - 0.3742 z^-1 - 0.6258 z^-2, z];
T = 0.3741;

HclosedLoop = T/(1 + R/S);

OutputResponse[HclosedLoop, UnitStep[t], t]

• Of course... yes it is. May 12, 2017 at 18:32
• @DavidG.Stork Thank you... and how could I implement it in Mathematica ? May 12, 2017 at 19:21
• @DavidG.Stork Please have a look at my updated question. May 13, 2017 at 5:47
• Is this what you wanted? SystemsModelFeedbackConnect[SystemsModelSeriesConnect[G, R], S] Oct 15, 2017 at 20:44
• If not please describe what is G. Oct 15, 2017 at 20:51

You have to add a few things to your code: Mathematica has to know that these are discrete time transfer functions and the constant T(z) has to be a TransferFunctionModel object as well.

plant = TransferFunctionModel[(0.1*z^-1 - 0.2*z^-2)/(1 - 1.3 z^-1 +
0.42*z^-2), z, SamplingPeriod -> Td];
controller =
TransferFunctionModel[1/(3 - 3.94 z^-1 + 1.3141 z^-2), z,
SamplingPeriod -> Td];
sensor = TransferFunctionModel[1 - 0.3742 z^-1 - 0.6258 z^-2, z,
SamplingPeriod -> Td];
filter = TransferFunctionModel[0.3741, z, SamplingPeriod -> Td];


compute the complimentary sensitivity transfer function T(z) of the system (do not confuse this with your filter)

sys1 = SystemsModelSeriesConnect[controller, plant];
sys2 = SystemsModelFeedbackConnect[sys1, sensor];
Tz = SystemsModelSeriesConnect[filter, sys2]


Now you can simulate and plot the step response

 resp = OutputResponse[Tz, Table[UnitStep[k], {k, 0, 20}]]


{{0.,0.01247,0.0197026,0.00735946,-0.0285393,-0.0852061,-0.157573,-0.240705,-0.330457,-0.423374,-0.516477,-0.607158,-0.693166,-0.772637,-0.844107,-0.906522,-0.959212,-1.00187,-1.03451,-1.05744,-1.07118,-1.07648,-1.07422,-1.06539,-1.05104,-1.03225,-1.01011,-0.985661,-0.95987,-0.93364,-0.90777,-0.882952,-0.859762,-0.83866,-0.819991,-0.803987,-0.790778,-0.780396,-0.77279,-0.767837,-0.765353,-0.765106,-0.76683,-0.770232,-0.775013,-0.780866,-0.787494,-0.794614,-0.801963,-0.809304,-0.816429,-0.823162,-0.82936,-0.834912,-0.839739,-0.843793,-0.847053,-0.849524,-0.851232,-0.852222,-0.852553,-0.852298,-0.851534,-0.850347,-0.848821,-0.847042,-0.845091,-0.843044,-0.840972,-0.838937,-0.836991,-0.83518,-0.833538,-0.832091,-0.830857,-0.829844,-0.829055,-0.828484,-0.82812,-0.82795,-0.827953,-0.828109,-0.828394,-0.828785,-0.829257,-0.829788,-0.830354,-0.830936,-0.831514,-0.832074,-0.8326,-0.833083,-0.833514,-0.833888,-0.834199,-0.834448,-0.834635,-0.834762,-0.834832,-0.834852,-0.834826}}

ListPlot[resp, Filling -> Axis, PlotRange -> All]


Or with the code from the example page

ListPlot[Map[Thread[{Range[Length[#]] - 1, #}] &, resp],
Joined -> True, InterpolationOrder -> 0, PlotRange -> All]


I hope this helps.

• Great answer! Thanks a lot ! Feb 26, 2018 at 18:03