Search code examples
matlabcontrolssystemsimulink

Different result for same system with Simulink and tf()


Take a look at the following simple system

enter image description here

where Kp=7130 and Kd=59.3880. These values are designed so that the system should exhibit an overshoot of 20% and steady-state error less than 0.01. The Simulink model yields correct results whereas tf() doesn't. This is the model

enter image description here

and its result is

enter image description here

Now implementing same system with tf as follows:

clear all
clc
kp=7130;
kd=59.3880;
num=[kd kp];
den=[1 18+kd 72+kp];
F=tf(num,den);
step(F)
stepinfo(F)

yields different overshoot.

enter image description here

Any suggestions why there is an inconsistent response? Do I have to put the system in specific form in order to use tf()?


Solution

  • The error is considering correct the response of the Simulink implementation. step is giving you the correct response.

    A pure derivative does not exists in Simulink, and if out try a transfer function block with [kd, kp] as numerator and [1] as denominator you will get an error.

    The derivative is a filter with a pole when you use the fixed step integrator, the behavior with variable step is quite uncertain, and should be avoided. The closed loop system you get with your controller has relative degree one (1 zeros, 2 poles).

    If you look at the response, the Simulink implementation starts with dy/dt = 0 for t = 0, and this is not possible with this kind of closed loop system. The correct response is the one of tf (dy/dt > 0 for t = 0).

    Your closed loop transfer function is correct, and you should consider its response as correct. Try to simulate the transfer function in the image with Simulink. You will see the same response of the step command.

    Let's test this with some code:

    enter image description here

    In the image we have three test:

    • the analytic transfer function
    • an approximation of the derivative
    • the simulation with your derivative block

    Try to implement it and test the value of 0.001 in the tf s / (0.001 s + 1), you will see that if you decrease the coefficient towards 0, the response of Transfer Fnc2 will approximate the one of the analytic closed loop tf (up to a point Simulink will not evaluate the derivative and will stop the simulation). And finally, the analytic transfer function in Simulink gives the same response of the step command.

    In the comment you said you evaluated the inverse laplace, so let us check also the inverse laplace. The symbolic toolbox will do that for us:

    syms s kp kd t
    
    Plant = 1/(s^2 + 18 * s + 72)
    Reg = kp + kd * s
    
    L = Plant * Reg
    ClosedLoop = simplify(L / (1 + L))
    Step = 1/s
    
    ResponseStep = simplify(ilaplace(ClosedLoop * Step))
    
    ResponseStep_f = matlabFunction(simplify( ...
      subs( ...
        subs(ResponseStep, kp, 7130), kd, 59.3880)));
    
    t_ = linspace(0, 0.15, 200);
    y_ = arrayfun(t_closedLoop_d, t_);
    plot(t_, y_);
    

    enter image description here

    as you can see the inverse Laplace shows an overshoot of more than 25%.

    EDIT: Evaluating the inverse Laplace that you evaluated at this link

    enter image description here

    Again the overshoot is at 25.9%