Simulink and Matlab PID time response difference

Hi everyone,
I'm working on a flight dynamics assignment (pitch angle control for a UAV) and I am facing an issue where my MATLAB script and my Simulink model yield completely different step responses for the exact same system and gains.
I am designing a PID controller. The plant is a 4x4 state-space model (A, B, Ctheta, D), and I generated the transfer function tf_theta.
  • My gains are: Kp = 12, Ti = 0.5, Td = 0.2.
  • The reference step is theta_0 = 0.1571 rad.
The issue:
  1. In MATLAB: Using the pid object with a derivative filter (Tf = 0.01), the step response is extremely fast (settling time < 0.2s). (See attached MATLAB plot).
  2. In Simulink: I built the PID manually using a Derivative block (set to numerical derivative $\frac{\Delta u}{\Delta t}$ with c = inf). The step response is much slower, settling around 3 to 4 seconds. (See attached Simulink plot).
Here is the relevant part of my MATLAB code:
% Plant Transfer Function
theta_ss = ss(A, B, [0 0 0 1], 0);
tf_theta = tf(-theta_ss); % Minus sign required by assignment for positive DC gain
% Controller Gains
theta_0 = 0.1571;
Kp = 12;
Ti = 0.5;
Td = 0.2;
c = 0.01; % Derivative filter time constant
% PID Definition (Ideal format)
K_pid = pid(Kp, Kp/Ti, Kp*Td, c);
% Closed Loop
CL = feedback(K_pid * tf_theta, 1);
% Plot
figure;
step(CL * theta_0);
grid on;
title('Step response: Closed Loop Pitch angle');
Here are the screens :

 采纳的回答

Paul
Paul 2026-11-7,17:09
Hi Nicolas,
Based on a quick glance I suggest comparing the implementation of the PID controller in the Matlab script (K_pid) with the implementation in the Simulink model. They don't look the same (I'm not referring to the implementation of derivative filter in the former that's not in the latter).
A few other things to consider:
There's no reason to convert the state-space model into a transfer function. If you have a state-space model that's typically the preferred implementation in the Control System Toolbox. Simulink offers a State-Space - Model continuous linear system as system of explicit state-space equations - Simulink block that can be used.
The Derivative block in Simulink is not recommended. See its doc page for a discussion.
Simulink does offer a PID Controller - Continuous-time or discrete-time PID controller - Simulink block that may be of interest.

更多回答(0 个)

产品

版本

R2025b

标签

提问:

2026-11-7,16:39

回答:

2026-11-7,17:09

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by