Frequency Response With MATLAB Examples
Frequency Response With MATLAB Examples
blog
Frequency Response
with MATLAB Examples
Control Design and Analysis
Hans-Petter Halvorsen
Contents
• Introduction to PID Control
• Introduction to Frequency Response
• Frequency Response using Bode Diagram
• Introduction to Complex Numbers (which Frequency Response Theory is
based on)
• Frequency Response from Transfer Functions
• Frequency Response from Input/output Signals
• PID Controller Design and Tuning (Theory)
• PID Controller Design and Tuning using MATLAB
• Stability Analysis using MATLAB
• Stability Analysis of Feedback Systems
• Stability Analysis of Feedback Systems – a Practical Example
• The Bandwidth of the Control System
• Practical PI Controller Example
https://www.halvorsen.blog
PID Control
Hans-Petter Halvorsen
Control System 𝑣
𝑟 𝑒 𝑢
Controller Actuators Process
− 𝑦
Filtering Sensors
Where
𝑒𝑘 = 𝑟𝑘 − 𝑦𝑘
We can also split the equation above in 2 different parts by setting:
∆𝑢𝑘 = 𝑢𝑘 − 𝑢𝑘−1
This gives the following PI control algorithm:
𝑒𝑘 = 𝑟𝑘 − 𝑦𝑘
𝐾𝑝
∆𝑢𝑘 = 𝑢0,𝑘 − 𝑢0,𝑘−1 + 𝐾𝑝 𝑒𝑘 − 𝑒𝑘−1 + 𝑇𝑒
𝑇𝑖 𝑠 𝑘
𝑢𝑘 = 𝑢𝑘−1 + ∆𝑢𝑘
This algorithm can easily be implemented in MATLAB
Discrete PI Controller Algorithm
Discrete PI control algorithm:
𝑒𝑘 = 𝑟𝑘 − 𝑦𝑘
𝐾𝑝
∆𝑢𝑘 = 𝑢0,𝑘 − 𝑢0,𝑘−1 + 𝐾𝑝 𝑒𝑘 − 𝑒𝑘−1 + 𝑇𝑠 𝑒𝑘
𝑇𝑖
𝑢𝑘 = 𝑢𝑘−1 + ∆𝑢𝑘
PID Controller –Transfer Function
We have:
𝐾𝑝 𝑡
𝑢 𝑡 = 𝐾𝑝 𝑒 + න 𝑒𝑑𝜏 + 𝐾𝑝 𝑇𝑑 𝑒ሶ
𝑇𝑖 0
Laplace gives:
𝑢(𝑠) 𝐾𝑝
𝐻𝑃𝐼𝐷 𝑠 = = 𝐾𝑝 + + 𝐾𝑝 𝑇𝑑 𝑠
𝑒(𝑠) 𝑇𝑖 𝑠
or:
𝑢(𝑠) 𝐾𝑝 (𝑇𝑑 𝑇𝑖 𝑠 2 + 𝑇𝑖 𝑠 + 1)
𝐻𝑃𝐼𝐷 𝑠 = =
𝑒(𝑠) 𝑇𝑖 𝑠
PI Controller –Transfer Function
We have:
𝐾𝑝 𝑡
𝑢 𝑡 = 𝐾𝑝 𝑒 + න 𝑒𝑑𝜏
𝑇𝑖 0
Laplace gives:
𝑢(𝑠) 𝐾𝑝 𝐾𝑝 𝑇𝑖 𝑠 + 𝐾𝑝 𝐾𝑝 (𝑇𝑖 𝑠 + 1)
𝐻𝑃𝐼 𝑠 = = 𝐾𝑝 + = =
𝑒(𝑠) 𝑇𝑖 𝑠 𝑇𝑖 𝑠 𝑇𝑖 𝑠
Finally:
𝑢(𝑠) 𝐾𝑝 (𝑇𝑖 𝑠 + 1)
𝐻𝑃𝐼 𝑠 = =
𝑒(𝑠) 𝑇𝑖 𝑠
Define PI Transfer function in MATLAB
clear, clc
Hpi = tf(num,den)
...
PI Controller – State space model
Given:
𝐾𝑝
𝑢 𝑠 = 𝐾𝑝 𝑒 𝑠 + 𝑒 𝑠
𝑇𝑖 𝑠
1
We set 𝑧 = 𝑒 ⇒ 𝑠𝑧 = 𝑒 ⇒ 𝑧ሶ = 𝑒
𝑠
This gives:
𝑧ሶ = 𝑒
𝐾𝑝
𝑢 = 𝐾𝑝 𝑒 + 𝑧
𝑇𝑖
Where
𝑒 =𝑟−𝑦
PI Controller – Discrete State space model
Using Euler:
𝑧𝑘+1 − 𝑧𝑘
𝑧ሶ ≈
𝑇𝑠
Where 𝑇𝑠 is the Sampling Time.
This gives:
𝑧𝑘+1 − 𝑧𝑘
= 𝑒𝑘
𝑇𝑠
𝐾𝑝
𝑢𝑘 = 𝐾𝑝 𝑒𝑘 + 𝑧
𝑇𝑖 𝑘
Finally:
𝑒𝑘 = 𝑟𝑘 − 𝑦𝑘
𝐾𝑝
𝑢𝑘 = 𝐾𝑝 𝑒𝑘 + 𝑧
𝑇𝑖 𝑘
𝑧𝑘+1 = 𝑧𝑘 + 𝑇𝑠 𝑒𝑘
PI Controller – Discrete State space model
implemented in MATLAB clear, clc
...
for i=1:N
...
e = r - y;
u = Kp*e + z;
z = z + dt*Kp*e/Ti;
...
end
plot(...)
https://www.halvorsen.blog
Frequency Response
Hans-Petter Halvorsen
Theory
Frequency Response
• The frequency response of a system is a frequency dependent
function which expresses how a sinusoidal signal of a given frequency
on the system input is transferred through the system. Each
frequency component is a sinusoidal signal having certain amplitude
and a certain frequency.
• The frequency response is an important tool for analysis and design
of signal filters and for analysis and design of control systems.
• The frequency response can be found experimentally or from a
transfer function model.
• The frequency response of a system is defined as the steady-state
response of the system to a sinusoidal input signal. When the system
is in steady-state, it differs from the input signal only in
amplitude/gain (A) and phase lag (𝜙).
Theory Input Signal
Frequency
Response Output Signal
Input Signal
Dynamic Output Signal
𝑢 𝑡 = 𝑈 ∙ 𝑠𝑖𝑛𝜔𝑡 System 𝑦 𝑡 = 𝑈𝐴
ด 𝑠𝑖𝑛(𝜔𝑡 + 𝜙)
𝑌
Amplitude Frequency
The frequency response of a system expresses how a sinusoidal signal of a given frequency on the system
input is transferred through the system. The only difference is the gain and the phase lag.
Frequency Response - Definition Theory
𝑢 𝑡 = 𝑈 ∙ 𝑠𝑖𝑛𝜔𝑡 𝑦 𝑡 = 𝑈𝐴
ด 𝑠𝑖𝑛(𝜔𝑡 + 𝜙)
𝑌
System
𝜔 = 1 𝑟𝑎𝑑/𝑠
𝜔 = 1 𝑟𝑎𝑑/𝑠
and the same for Frequency 2, 3, 4, 5, 6, etc.
• The frequency response of a system is defined as the steady-state response of the system to a sinusoidal
input signal.
• When the system is in steady-state, it differs from the input signal only in amplitude/gain (A) (Norwegian:
“forsterkning”) and phase lag (ϕ) (Norwegian: “faseforskyvning”).
Frequency Response - Simple Example Theory
Outside Temperature
T = 1 year
frequency 1 (year)
Dynamic System frequency 1 (year)
Inside Temperature
Assume the outdoor temperature is varying like a sine function during a year (frequency 1) or during 24 hours (frequency 2).
Then the indoor temperature will be a sine as well, but with different gain. In addition it will have a phase lag.
Frequency Response - Simple Example Theory
Outside Temperature
T = 24 hours
Assume the outdoor temperature is varying like a sine function during a year (frequency 1) or during 24 hours (frequency 2).
Then the indoor temperature will be a sine as well, but with different gain. In addition it will have a phase lag.
https://www.halvorsen.blog
𝜑 𝜔180
𝐿𝑜𝑔 𝜔 ω [rad/s]
Bode Diagram from experiments
Find Data for different frequencies We find 𝐴 and 𝜙 for each of the frequencies,
e.g.:
...
Gain (“Forsterkningen”)
Note! The y-scale is in [𝑑𝐵]
𝑥 𝑑𝐵 = 20𝑙𝑜𝑔10 𝑥
Normally, the unit for frequency is Hertz [Hz], but in frequency response and Bode 𝜔 = 2𝜋𝑓
diagrams we use radians ω [rad/s]. The relationship between these are as follows:
Frequency Response – MATLAB
Transfer Function:
MATLAB Code:
clear
clc
close all
% Frequency Response
bode(H); The frequency response is an important tool for analysis and design
grid on of signal filters and for analysis and design of control systems.
Frequency Response – MATLAB
Transfer Function: clear
clc
close all
% Transfer function
num=[1];
den1=[1,0];
den2=[1,1]
den3=[1,1]
den = conv(den1,conv(den2,den3));
H = tf(num, den)
clear, clc
% Bode Diagram
bode(H) % Transfer function
subplot(2,1,1) num=[1];
den=[1,2,1,0];
grid on H = tf(num, den)
subplot(2,1,2)
grid on % Bode Diagram
bode(H)
subplot(2,1,1)
or: grid on
subplot(2,1,2)
grid on
Example
We will use the following system as an example:
1
𝐻𝑐 = 𝐾𝑝 𝐻𝑝 =
𝑠(𝑠 + 1)
𝑟 𝑒 𝑢
Controller Process
− 𝑦
Sensors
1
𝐻𝑚 =
3𝑠 + 1
Bode Diagram – MATLAB Example
MATLAB Code: 1
clear
𝐻𝑝 =
clc 𝑠(𝑠 + 1)
num = 1;
den = [1,1,0];
Hp = tf(num,den)
bode(Hp)
grid on
https://www.halvorsen.blog
Complex Numbers
Background Theory for Frequency Response
Hans-Petter Halvorsen
Complex Numbers
A Complex Number is given by:
𝑧 = 𝑎 + 𝑗𝑏
Where
𝑗 = −1
𝐼𝑚𝑎𝑔𝑖𝑛𝑎𝑟𝑦
𝐴𝑥𝑖𝑠 (𝐼𝑚)
We have that:
𝑎 = 𝑅𝑒 𝑧
𝑏 𝑧 = 𝑎 + 𝑗𝑏
𝑏 = 𝐼𝑚(𝑧)
𝑅𝑒𝑎𝑙
0 𝑎 𝐴𝑥𝑖𝑠(𝑅𝑒)
Complex Numbers 𝑗 = −1
Polar form:
𝑧 = 𝑟𝑒 𝑗𝜃
Where:
𝑟= 𝑧 = 𝑎2 +𝑏2
𝑏
𝜃 = 𝑎𝑡𝑎𝑛
𝑎 𝐼𝑚𝑎𝑔𝑖𝑛𝑎𝑟𝑦
𝐴𝑥𝑖𝑠 (𝐼𝑚)
Note!
𝑎 = 𝑟 cos 𝜃 𝑏 𝑧 = 𝑟𝑒 𝑗𝜃
𝑟
𝑏 = 𝑟 sin 𝜃 𝜃
𝑅𝑒𝑎𝑙
0 𝑎 𝐴𝑥𝑖𝑠(𝑅𝑒)
Complex Numbers 𝑗 = −1
𝑏 𝑧 = 𝑎 + 𝑗𝑏 𝑧 = 𝑟𝑒 𝑗𝜃
𝑏
𝑟
𝜃
𝑅𝑒𝑎𝑙 𝑅𝑒𝑎𝑙
0 𝑎 𝐴𝑥𝑖𝑠(𝑅𝑒) 0 𝑎 𝐴𝑥𝑖𝑠(𝑅𝑒)
Hans-Petter Halvorsen
Manually find the Frequency Response Theory
Where 𝐻(𝑗𝜔) is the frequency response of the system, i.e., we may find the frequency response by setting 𝑠 = 𝑗𝜔
in the transfer function. Bode diagrams are useful in frequency response analysis.
The Bode diagram consists of 2 diagrams, the Bode magnitude diagram, 𝐴(𝜔) and the Bode phase diagram,
𝜙(𝜔).
The Gain function:
𝐴 𝜔 = 𝐻(𝑗𝜔)
The Phase function:
𝜙 𝜔 = ∠𝐻(𝑗𝜔)
The 𝐴(𝜔)-axis is in decibel (dB), where the decibel value of x is calculated as: 𝑥 𝑑𝐵 = 20𝑙𝑜𝑔10 𝑥
The 𝜙(𝜔)-axis is in degrees (not radians!)
Mathematical expressions for 𝐴(𝜔) and 𝜙(𝜔)
We find the Mathematical expressions for 𝐴(𝜔) and 𝜙(𝜔) by setting 𝑠 = 𝑗𝜔 in the transfer function
given by:
𝑦(𝑠) 𝐾
𝐻 𝑠 = =
𝑢(𝑠) 𝑇𝑠 + 1
Finally:
𝐾
𝐻 𝑗𝜔 = 𝑒 𝑗 −𝑎𝑟𝑐𝑡𝑎𝑛(𝑇𝜔)
1 + 𝑇𝜔 2
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = 𝑎𝑟𝑔 𝐻 𝑗𝜔 = −𝑎𝑟𝑐𝑡𝑎𝑛(𝑇𝜔)
180
2𝑠 + 1 (10𝑠 + 1) ∠𝐻(𝑗𝜔) = arctan(5𝜔) − arctan(2𝜔) − arctan(10𝜔)
Manually find the Frequency Response
from the Transfer Function
Given the following transfer function:
4
𝐻 𝑆 =
2𝑠 + 1 Bode Plot:
∠𝐻(𝑗𝜔) = −arctan(2𝜔)
Or 𝜙 𝜔 in degrees:
180
𝜙 𝜔 [𝑑𝑒𝑔𝑟𝑒𝑒𝑠] = − arctan 𝑇𝜔 − 𝜔 ∙ 𝜏
𝜋
Transfer functions with Time delay in MATLAB
Different ways to implement a time delay in MATLAB:
Alt 2 K = 3.5;
Alt 1 T = 22;
K = 3.5; Tau = 2;
T = 22; Alt 4: Use Pade approximation
num = [K];
Tau = 2; den = [T, 1]; K = 3.5;
T = 22;
H1 = tf(num, den);
Tau = 2;
num = [K];
den = [T, 1]; H = set(H1,'inputdelay',Tau) num = [K];
den = [T, 1];
H1 = tf(num, den); H1 = tf(num, den);
bode(H);
s = tf('s') N=5;
H2 = exp(-Tau*s); Alt 3 K = 3.5; H2 = pade(Tau, N)
bode(H);
1. order system with Time delay
Given the following transfer function:
The mathematical expressions for 𝐴(𝜔) and 𝜙(𝜔):
−2𝑠
3.2𝑒
𝐻 𝑠 =
3𝑠 + 1 𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔3.2 − 20𝑙𝑜𝑔 (3𝜔)2 +1
H = H1 * H2
p = pole(H)
z = zero (H) bode(H);
p = pole(H)
H =
z = zero (H)
3.2
exp(-2*s) * -------
3 s + 1
p = -0.3333
Hans-Petter Halvorsen
Theory
Frequency Response from sinusoidal
input and output signals
We can find the frequency response of a system
by exciting the system (either the real system or a
model of the system) with a sinusoidal signal of
amplitude 𝐴 and frequency 𝜔 [𝑟𝑎𝑑/𝑠] (Note:
𝜔 = 2𝜋𝑓) and observing the response in the
output variable of the system.
Frequency Response - Definition Theory
𝑢 𝑡 = 𝑈 ∙ 𝑠𝑖𝑛𝜔𝑡 𝑦 𝑡 = 𝑈𝐴
ด 𝑠𝑖𝑛(𝜔𝑡 + 𝜙)
𝑌
System
𝜔 = 1 𝑟𝑎𝑑/𝑠
𝜔 = 1 𝑟𝑎𝑑/𝑠
and the same for Frequency 2, 3, 4, 5, 6, etc.
• The frequency response of a system is defined as the steady-state response of the system to a sinusoidal
input signal.
• When the system is in steady-state, it differs from the input signal only in amplitude/gain (A) (Norwegian:
“forsterkning”) and phase lag (ϕ) (Norwegian: “faseforskyvning”).
Frequency Response from sinusoidal Theory
t
Find the gain (𝐴) and the phase (𝜙) for the given frequency from the plot
𝜔 = 1 rad/s
Solutions
From the Plot we get:
𝐴 = 0.68
𝐴 𝑑𝐵 = 20𝑙𝑜𝑔(𝐴)=20𝑙𝑜𝑔(0.68) ≈ −3.35𝑑𝐵
𝐴 𝑑𝐵 = −3.35𝑑𝐵
−3.35
𝐴 𝑑𝐵 = 10 20 ≈ 0.68
From the Bode diagram we can verify that our calculations are correct:
𝐴 = −3.35 𝑑𝐵
𝜙 = −45.9 °
𝜔 = 1 rad/s
The following MATLAB Code is used to create the Plot:
clear, clc
K = 1;
T = 1;
num = [K];
den = [T, 1]; We use the following transfer function:
H = tf(num, den);
figure(1)
bode(H), grid on
1
𝐻 𝑠 =
% Define input signal
𝑠+1
t = [1: 0.1 : 12];
w = 1;
U = 1;
u = U*sin(w*t); The Frequency used:
figure(2)
plot(t, u)
% Output signal
𝜔 = 1 rad/s
hold on
lsim(H, ':r', u, t)
grid on
hold off
legend('input signal', 'output signal')
https://www.halvorsen.blog
PID Controller
Design/Tuning
Hans-Petter Halvorsen
PID Controller Design
A lot of PID Tuning methods exist, e.g.,
• Skogestad's method
• Ziegler-Nichols’ methods
• Trial and Error Methods
• PID Tuning functionality built into MATLAB
• Auto-tuning built into commercial PID controllers
• ...
Skogestad’s method
• The Skogestad’s method assumes you apply a step on the input (𝑢)
and then observe the response and the output (𝑦), as shown below.
• If we have a model of the system (which we have in our case), we can
use the following Skogestad’s formulas for finding the PI(D)
parameters directly.
Controller Design/Tuning
using MATLAB
Hans-Petter Halvorsen
Controller Design/Tuning using MATLAB
%Define Process
num = 1;
den = [1,1,0];
Hp = tf(num,den)
% Find PI Controller
[Hpi,info] = pidtune(Hp,'PI')
%Bode Plots
figure(1)
bode(Hp)
grid on
figure(2)
bode(Hpi)
grid on
𝐾𝑝 = 0.33
% Feedback System
T = feedback(Hpi*Hp, 1); 1 1
figure(3) 𝑇𝑖 = = ≈ 43.5𝑠
step(T) 𝐾𝑖 0.023
pidtune() MATLAB function
To improve the response time, you can set a higher
target crossover frequency than the result that pidtune()
automatically selects, 0.32. Increase the crossover
frequency to 1.0.
[Hpi,info] = pidtune(Hp,'PI', 1.0)
Define your
Process
Add Additional
Plots
Step Response and other
Plots can be shown
PID Parameters
https://www.halvorsen.blog
Stability Analysis
using MATLAB
Hans-Petter Halvorsen
Stability Analysis
How do we figure out that the Feedback System
is stable before we test it on the real System?
1. Poles
2. Frequency Response/Bode
3. Simulations (Step Response)
We will do all these things using MATLAB
3 Time domain
Stability Analysis
Asymptotically stable system
2 Frequency domain Loop
lim 𝑦 𝑡 = 𝑘 transfer
𝑡→∞ function
Tracking Marginally stable system
transfer
function
Unstable system
3 Unstable system:
At least one pole lies in the right half
2 Marginally stable system: plane (has real part greater than zero).
Stability Analysis
Asymptotically stable system: Marginally stable system: Unstable system:
lim 𝑦 𝑡 = 𝑘 lim 𝑦 𝑡 = ∞
𝑡→∞ 𝑡→∞
Stability Analysis of
Feedback Systems
Hans-Petter Halvorsen
Stability Analysis of 1 Loop Transfer Function
Theory
(“Sløyfetransferfunksjonen”):
Feedback Systems
Hr = ...
Hp = ...
Hm = ...
L = series(series(Hr, Hp), Hm)
L = ...
T = feedback(L, 1)
T = ...
S = 1-T
Frequency Response and Stability Analysis Theory
Stability Analysis of
Feedback System - Example
Hans-Petter Halvorsen
Example
We will use the following system as an example:
1
𝐻𝑐 = 𝐾𝑝 𝐻𝑝 =
𝑠(𝑠 + 1)
𝑟 𝑒 𝑢 𝑦
Controller Process
−
Sensors
1
𝐻𝑚 =
3𝑠 + 1
Analysis of the Feedback System
Loop transfer function: 𝑳(𝒔)
We need to find the Loop transfer function 𝐿(𝑠) using MATLAB.
The Loop transfer function is defined as:
% Bode Diagram
figure(1)
bode(L),grid on
figure(2)
margin(L)
wc = 0.2649 rad/s
[gm, pm, w180, wc] = margin(L);
w180 = 0.5774 rad/s
wc
gm = 3.8095
w180
gm
gmdB = 11.6174 dB
gmdB = 20*log10(gm)
pm
pm = 36.6917 degrees
From the Bode plot we can get:
∆𝐾 = 11.6 𝑑𝐵
𝜔𝑐 = 0.26
𝜙 = 37 °
The Bandwidth of
the Control System
Hans-Petter Halvorsen
The Bandwidth of the Control System
• You should plot the Loop transfer function
𝐿(𝑠), the Tracking transfer function 𝑇(𝑠)
and the Sensitivity transfer function 𝑆(𝑠) in
the same Bode diagram.
𝐿 • Use, e.g., the bodemag() function in
MATLAB (only the gain diagram is of
𝑇 interest in this case, not the phase
diagram).
• Use the values for 𝐾𝑝 and 𝑇𝑖 found in a
𝑆
previous Tasks.
• You need to find the different bandwidths
𝝎𝒕 , 𝝎𝒄 , 𝝎𝒔 (see the sketch below).
Theory
The Bandwidth of the Control System
The bandwidth of a control system is the frequency which divides the frequency
range of good tracking and poor tracking.
3 different Bandwidth definitions:
Good Poor
𝑆 Tracking Tracking
BW
PI Controller
Example
Hans-Petter Halvorsen
PI Controller - Example
We will use the following system as an example:
𝐾𝑝 (𝑇𝑖 𝑠 + 1) 1
𝐻𝑐 = 𝐻𝑝 =
𝑇𝑖 𝑠 𝑠(𝑠 + 1)
𝑟 𝑒 𝑢
Controller Process
− 𝑦
Sensors
1
𝐻𝑚 =
3𝑠 + 1
Ziegler–Nichols Frequency Response method
Assume you use a P controller only 𝑇𝑖 = ∞, 𝑇𝑑 = 0. Then you need to find for Theory
which 𝐾𝑝 the closed loop system is a marginally stable system (𝜔𝑐 = 𝜔180 ). This 𝐾𝑝
is called 𝐾𝑐 (critical gain). The 𝑇𝑐 (critical period) can be found from the damped
oscillations of the closed loop system. Then calculate the PI(D) parameters using
the formulas below.
𝑇𝑖 𝑇𝑑 Marginally stable system:
Controller 𝐾𝑝 𝜔𝑐 = 𝜔180
P 0.5𝐾𝑐 ∞ 0
𝑇𝑐
PI 0.45𝐾𝑐 0
1.2
2𝜋
𝑇𝑐 𝑇𝑐 𝑇𝑐 =
PID 0.6𝐾𝑐 𝑇𝑐 𝜔180
2 8
𝐾𝑐 - Critical Gain
𝑇𝑐 - Critical Period https://en.wikipedia.org/wiki/Ziegler–Nichols_method
PI Controller using Ziegler–Nichols
Ziegler–Nichols (PI Controller):
𝐾𝑝 = 0.45𝐾𝑐
This gives the following PI Parameters:
𝑇𝑐
𝑇𝑖 = 𝐾𝑝 = 0.45𝐾𝑐 = 0.45 ∙ 1.32 ≈ 0.6
1.2
2𝜋
From previous Simulations: 𝑇𝑐
𝑇𝑖 = = 0.58 ≈ 9𝑠
1.2 1.2
𝐾𝑐 = 1.32
2𝜋 2𝜋
𝑇𝑐 = =
𝜔180 0.58
Skogestad’s method
• The Skogestad’s method assumes you apply a step on the input (𝑢) and then
observe the response and the output (𝑦), as shown below.
• If we have a model of the system (which we have in our case), we can use the
following Skogestad’s formulas for finding the PI(D) parameters directly.
Figure: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010.
Our Process:
1
𝐻𝑝 =
𝑠(𝑠 + 1)
𝑇𝑐 is the time-constant of the control system which the user must specify
𝐾 = 1, 𝑇 = 1, 𝜏 = 0
We set, e.g., 𝑇𝐶 = 5 𝑠 and 𝑐 = 1.5:
1 1 1
𝐾𝑝 = = = = 0.2 𝑇𝑖 = 𝑐 𝑇𝑐 + 𝜏 = 1.5 5 + 0 = 7.5𝑠
𝐾(𝑇𝑐 + 𝜏) 1(10 + 0) 5
MATLAB
Ziegler–Nichols and Skogestad’s Formulas:
% Ziegler-Nicols Method
Kp = 0.45 * Kc
Ti = Tc/1.2
% Skogestad's Method
Tc = 5; % time-constant of the control system which the user must specify
c = 1.5;
% H=K*e(-Tau*s)/(T*s+1)*s
Kp = 1/K*(Tc)
Ti = c*(Tc+Tau)
pidtune() MATLAB function
clear, clc
%Define Process
num = 1;
den = [1,1,0];
Hp = tf(num,den)
% Find PI Controller
[Hpi,info] = pidtune(Hp,'PI')
%Bode Plots
figure(1)
bode(Hp)
grid on
figure(2)
bode(Hpi)
grid on
𝐾𝑝 = 0.33
% Feedback System
T = feedback(Hpi*Hp, 1); 1 1
figure(3) 𝑇𝑖 = = ≈ 43.5𝑠
step(T) 𝐾𝑖 0.023
MATLAB PID Tuner
Define Controller Type Tuning
Define your
Process
Add Additional
Plots
Step Response and other
Plots can be shown
PID Parameters
MATLAB Simulations
𝐾𝑝 = 0.33, 𝑇𝑖 = 43.5𝑠
𝐺𝑀 = 11.3𝑑𝐵, 𝑃𝑀 = 33.1°
clear, clc, clf
MATLAB Simulations ...
% The Measurement Transfer function Hm(s) [gm, pm, w180, wc] = margin(L);
num_m=[1];
den_m=[3, 1]; wc
Hm = tf(num_m, den_m); w180
gm
% The PI Controller Transfer function Hc(s) gmdB = 20*log10(gm)
%Kp = 0.6; Ti = 9; % Ziegler?Nichols pm
%Kp = 0.2; Ti = 7.5; % Skogestad
Kp = 0.33; Ti = 43.5; % MATLAB pidtune() function % Simulating step response for control system
(tracking transfer function)
num = Kp*[Ti, 1]; figure(3)
den = [Ti, 0]; step(T)
Hc = tf(num,den);
% Poles
% The Loop Transfer function pole(T)
L = series(series(Hc, Hp), Hm); figure(4)
% Tracking transfer function pzmap(T)
T=feedback(L,1);
% Sensitivity transfer function % Bandwidth
S=1-T; figure(5)
bodemag(L,T,S), grid on
...
References
1. D. Ruscio, System Theory - State Space Analysis
and Control Theory, Lecture Notes, 2015
2. F. Haugen, Advanced Dynamics and Control:
TechTeach, 2010.
3. R. C. Dorf and R. H. Bishop, Modern Control
Systems. Eleventh Edition: Pearson Prentice Hall.
4. https://www.halvorsen.blog
Hans-Petter Halvorsen
University of South-Eastern Norway
www.usn.no
E-mail: [email protected]
Web: https://www.halvorsen.blog