# How to set a limit and initial value for transfer function in Mathematica?

This is actually a follow-up question to this one!

Assuming that I have a tf like:

ω = 2. Pi*50; Mag = 1; θ = 0;
Tαβ2dqInv22 = {{Cos[ω t], -Sin[ω t]}, \
{Sin[ω t], Cos[ω t]}};
Tαβ2dq22 = {{Cos[ω t],
Sin[ω t]}, {-Sin[ω t], Cos[ω t]}};
Inputαβ22 = {Mag Cos[ω t + θ],
Mag Cos[ω t + θ]};
(*Inputαβ22={Mag ,Mag};*)

Outαβ2dq22 =
FullSimplify[Tαβ2dq22.Inputαβ22] //
TrigReduce // Chop;

tf = TransferFunctionModel[(0.67/(0.0025 s + 1) + 1)/(0.0025 s), s];
res = Chop@
Expand@OutputResponse[
tf, #1, t] & /@ Outαβ2dq22;
Outdq2αβ22 =
FullSimplify[Tαβ2dqInv22.res] // TrigReduce // Chop;
Show[Plot[Outdq2αβ22, {t, 0, 0.1}],
Plot[res, {t, 0, 0.2}]]


Is there any way that I can set upper/lower limits on output and also initial output values?

Starting from a non-zero initial output value

TransferFunctionModel assumes zero initial conditions. To start from non-zero initial conditions, it needs to be converted to a StateSpaceModel first.

ssm = StateSpaceModel[tf];


In StateSpaceModel, the initial states can be set. Suppose you want the initial output to be 0.5, then the corresponding output equation can be solved to determine the initial states.

yinit = 0.5;
sols = Solve[Normal[ssm][[3]].{x1, x2} == yinit, x1][[1]];
inits = {x1, x2} /. sols /. x2 -> 1;


(There are an infinite number of initial state choices, because the system has less outputs than states.)

Starting from these initial conditions, the response will start at the desired value:

Chop[yinit - OutputResponse[{ssm, inits}, #, t] /.
t -> 0] & /@ Out\[Alpha]\[Beta]2dq22


{{0}, {0}}

Setting limits on the output

I don't know to what extent this is supported. But you can construct a clamp using NonlinearStateSpaceModel and put the two in series.

In what follows I limit the response between $\pm20$.

{umax, umin} = {20, -20};
sys = SystemsModelSeriesConnect[ssm,
NonlinearStateSpaceModel[{{},
Which[u > umax, umax, u < umin, umin, True, u]}, {}, u]];
Chop@Expand@OutputResponse[sys, #1, t] & /@ Out\[Alpha]\[Beta]2dq22;
Plot[%, {t, 0, 0.1}]


• Thanks, Suba! I will add these into my codes this evening. In addition, as you can see, what I want to do is to have two inputs --> ab->dq transformation --> lag compensator+integrator --> dq->ab transformation-->output. Do you think if I can combine "ab->dq transformation --> lag compensator+integrator --> dq->ab transformation" with single system model rather than spitted like I did? – Peng Dec 15 '16 at 7:18
• I am not fully understanding the notation you are using. However, I am guessing what you are proposing is something easily done. Also, take a look at the example ref/StateSpaceTransform#834745677 (StateSpaceTransform>Applications>5th example), where dq transformation is applied to a stepper motor model. – Suba Thomas Dec 15 '16 at 14:46
• It seems state space has better usability over transfer function in mathematica...I have added limit with your suggestion, and it works, but slows down the computation a lot, so will leave it for now. – Peng Dec 16 '16 at 10:11