MATLAB PID Tuner producing the wrong output?

I'm trying to apply a PID controller to my transfer function in MATLAB to get the step response, bode, pole-zero, etc. This is the code I'm using to create the Transfer Function and open the PID Tuner app:

s = tf('s');

R = 10;         % Load resistor
Rc = 130*10e-3; % Output cap ESR
C = 1410e-6;    % Output capacitance
Rl = 100e-3;    % Inductor resistance
L = 500e-6;     % Inductor value
Vi = 30;        % Input voltage

% Buck converter transfer function
G = Vi * ( (R + (s*R*Rc*C))/((s^2) * (L*C*(R+Rc)) + s*(R*Rc*C + Rl*C*(R+Rc) + L) + R + Rl) )

% PID Tuner
pidTuner(G, 'PID')


The response I get is this after some tunning (click to view it bigger):

The Kp value is really low compared to the Ki parameter which makes me thing there's something wrong? But the step response seems right so I go ahead. Now I use this program to simulate my PID controller and do some plots:

% PID Parameters from PID Tuner
Kp = 0.175
Ki = 371.22
Kd = 0

% PID Controller
H = pid(Kp,Ki,Kd)

% Close the loop
T_pid = feedback(G, H)

% Plot the step response
figure(1);
step(T_pid)
grid on
title('Respuesta transitoria en lazo cerrado (plano continuo)')
xlabel('Tiempo')
ylabel('Amplitud')


And this is the step response I'm getting:

Which is waaaaaaay different from what PID Tuner gave me before. According to the docs of the feedback() function I think I'm using it right:

But somewhere on the Internet I found it used like this:

T_pid = feedback(H*G, 1)


And this gives me the exact same step response as PID Tuner but I don't understand why! What's the proper way to use it?

Let's consider a feedback loop as:

As you can see, your 'Control' and 'Process' blocks are cascaded. Assuming you are using unity feedback, your block 'Feedback' block is 1.

Now, the feedback function in matlab is defined as you have it in your post:

T=feedback(sys1,sys2)


Where sys1 and sys2 are set up in the following manner (as you also have it in your post):

In order to properly use the function, you have to define what 'sys1' and 'sys2' are based on your model. You are using a PID block and of course you have the plant model.

If your PID block is $\text{C(s)}$, your plant block is $\text{P(s)}$, and your feedback block is $\text{H(s)}$, how can you possibly match your system to the one matlab uses?

Everything now is the s-domain, so if you can simply multiply the cascaded blocks so that

$$sys1 = \text{C(s)P(s)}$$

And just by looking at how matlab defines its control loop model,

$$sys2 = \text{H(s)}$$

Since you are using unity gain feedback, $\text{H(s)}=1$ and keep in mind that the feedback function assumes negative feedback loop, so you don't need to use a -1 inside the function.

That's why the correct way to do it becomes:

T = feedback(C*P,1)


where C and P are your PID controller definition and Plant in the s-domain. And the 1 comes from using negative feedback which is the assumption when using this fucntion.

As summary, the forward path after the error signal in the first image in this post, represents what matlab defined as 'sys1' in its feedback function and the feedback path, which comes from the output back toward the summing block, is what matlab knows as 'sys2' in regards with the feedback function. And the forward path have two blocks, so you combine them together by multiplying.

Hope it helps!

• pretty much this, it all comes downto where your output tap is with regards to using the feedback() function – JonRB Dec 17 '16 at 21:20
• @Andres I can't tell you for sure since I don't know too many of the details of your system. Your PID is basically just an integrator but it looks good as far as the step response or as far as the specs you want to meet. – Big6 Dec 18 '16 at 0:33