Simulate any System with Arbitrary Input in MATLAB
August 26, 2016
Institute of Space Technology, Islamabad.
Flight Dynamics & Controls Center
Department of Aeronautics & Astronautics
Institute of Space Technology, Islamabad
1. Consider the following flight control system and define aircraft and its parameters in
MATLAB.
𝛽𝛽̇
⎡ ⎤ −0.1245 0.0350 0.0414 −0.9962 ⎡ 𝛽𝛽 (deg) ⎤
⎢ 𝑝𝑝̇ ⎥ = �−15.2138 −2.0587 0.0032 0.6458 ⎢ 𝑝𝑝 (deg/s) ⎥
�
⎢𝜙𝜙̇⎥ 0 1 0 0 ⎢𝜙𝜙 (deg)⎥
⎣ 𝑟𝑟̇ ⎦ 1.6447 −0.0447 −0.0022 −0.1416 ⎣ 𝑟𝑟 (deg/s) ⎦
−0.0049 0.0237
−4.0379 0.9613 𝛿𝛿𝐴𝐴
+� �� �
0 0 𝛿𝛿𝑅𝑅
−0.0568 −1.2168
Φ p
p
ψref ψerr Φref Φerr pref
perr δA
Kψ KΦ KP Φ
ψ
sys TF
βref βerr rref rerr δR β
Kβ Kr
r
β r
A = [ -0.1245 0.0350 0.0414 -0.9962;...
-15.2138 -2.0587 0.0032 0.6458;...
0.0000 1.0000 0.0000 0.0357;...
1.6447 -0.0447 -0.0022 -0.1416];
B = [ -0.0049 0.0237;...
-4.0379 0.9613;...
0.0000 0.0000;...
-0.0568 -1.2168];
V = 890; %(ft/s) % velocity
g = 32.066; %(ft/s^2) % gravity
h = 35000; %(ft) % altitude
Page 1 of 3
Flight Dynamics & Controls Center
Department of Aeronautics & Astronautics
Institute of Space Technology, Islamabad
2. Now define each block and its inputs and outputs.
sys = ss(A,B,eye(4),zeros(4,2));
sys.u = {'delta_A','delta_R'}; sys.y = {'beta','p','phi','r'};
TF = tf([g],[V 0]); TF.u = 'phi'; TF.y = 'psi';
Kp = tf(-10); Kp.u = 'p_err'; Kp.y = 'delta_A';
Kphi = tf(0.5); Kphi.u = 'phi_err'; Kphi.y = 'p_ref';
Kpsi = tf(5); Kpsi.u = 'psi_err'; Kpsi.y = 'phi_ref';
Kr = tf(-1); Kr.u = 'r_err'; Kr.y = 'delta_R';
Kbeta = tf(0.5); Kbeta.u = 'beta_err'; Kbeta.y = 'r_ref';
3. Define sum blocks
sum1 = sumblk('p_err = p_ref - p');
sum2 = sumblk('phi_err = phi_ref - phi');
sum3 = sumblk('psi_err = psi_ref - psi');
sum4 = sumblk('r_err = r_ref - r');
sum5 = sumblk('beta_err = beta_ref - beta');
4. Define inputs and outputs of complete systems and connect the blocks.
Y = {'beta','p','phi','psi','r'};
U = {'psi_ref','beta_ref'};
T = connect(sys,TF,Kp,Kphi,Kpsi,Kr,Kbeta,sum1,sum2,sum3,sum4,sum5,U,Y);
5. Simulate the system
%% Define Input signal
t=(0:0.01:50)'; % Time
beta_ref = zeros(size(t)); % Zero (Constant)
psi_ref = step(tf(1),t); % Step input
input = [psi_ref,beta_ref];
Page 2 of 3
Flight Dynamics & Controls Center
Department of Aeronautics & Astronautics
Institute of Space Technology, Islamabad
%% Simulate
[y,t] = lsim(T,input,t); % Simulate the system
plot(t,y(:,[2,3,4])); % Plot 'p', 'phi' and 'psi'
Info = lsiminfo(y,t,[0,0,0,1,0]); % find response characteristics
Settling Time
Maximum Value
Page 3 of 3