0% found this document useful (0 votes)
212 views

Frequency Response With MATLAB Examples

The document discusses frequency response analysis for control system design. It introduces frequency response as a tool to analyze how a system responds to sinusoidal inputs of different frequencies. The frequency response is defined by the gain and phase lag between the input and output signals. It can be determined experimentally from a system's transfer function or by testing it with sinusoidal inputs. The document then provides examples of using MATLAB to analyze and design PI and PID controllers in both continuous and discrete time domains.

Uploaded by

Disco Jockey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views

Frequency Response With MATLAB Examples

The document discusses frequency response analysis for control system design. It introduces frequency response as a tool to analyze how a system responds to sinusoidal inputs of different frequencies. The frequency response is defined by the gain and phase lag between the input and output signals. It can be determined experimentally from a system's transfer function or by testing it with sinusoidal inputs. The document then provides examples of using MATLAB to analyze and design PI and PID controllers in both continuous and discrete time domains.

Uploaded by

Disco Jockey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

https://www.halvorsen.

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

𝑟 – Reference Value, SP (Set-point), SV (Set Value)


𝑦 – Measurement Value (MV), Process Value (PV)
𝑒 – Error between the reference value and the measurement value (𝑒 = 𝑟 – 𝑦)
𝑣 – Disturbance, makes it more complicated to control the process
𝑢 - Control Signal from the Controller
The PID Algorithm
𝐾𝑝 𝑡
𝑢 𝑡 = 𝐾𝑝 𝑒 + න 𝑒𝑑𝜏 + 𝐾𝑝 𝑇𝑑 𝑒ሶ
𝑇𝑖 0
Where 𝑢 is the controller output and 𝑒 is the Tuning Parameters:
control error:
𝑒 𝑡 = 𝑟 𝑡 − 𝑦(𝑡) 𝐾𝑝 Proportional Gain

𝑟 is the Reference Signal or Set-point


𝑇𝑖 Integral Time [sec. ]
𝑦 is the Process value, i.e., the Measured value 𝑇𝑑 Derivative Time [sec. ]
The PI Algorithm
𝐾𝑝 𝑡
𝑢 𝑡 = 𝐾𝑝 𝑒 + න 𝑒𝑑𝜏
𝑇𝑖 0
Where 𝑢 is the controller output and 𝑒 is the Tuning Parameters:
control error:
𝑒 𝑡 = 𝑟 𝑡 − 𝑦(𝑡) 𝐾𝑝 Proportional Gain

𝑟 is the Reference Signal or Set-point


𝑇𝑖 Integral Time [sec. ]
𝑦 is the Process value, i.e., the Measured value
PI(D) Algorithm in MATLAB

• We can use the pid() function in MATLAB


• We can define the PI(D) transfer function
using the tf() function in MATLAB
• We can also define and implement a discrete
PI(D) algorithm
Discrete PI Controller Algorithm
We start with:
𝐾𝑝 𝑡
𝑢 𝑡 = 𝑢0 + 𝐾𝑝 𝑒 𝑡 + න 𝑒𝑑𝜏
𝑇𝑖 0
In order to make a discrete version using, e.g., Euler, we can derive both sides of the equation:
𝐾𝑝
𝑢ሶ = 𝑢ሶ 0 + 𝐾𝑝 𝑒ሶ + 𝑒
𝑇𝑖
If we use Euler Forward we get:
𝑢𝑘 − 𝑢𝑘−1 𝑢0,𝑘 − 𝑢0,𝑘−1 𝑒𝑘 − 𝑒𝑘−1 𝐾𝑝
= + 𝐾𝑝 + 𝑒
𝑇𝑠 𝑇𝑠 𝑇𝑠 𝑇𝑖 𝑘
Then we get:
𝐾𝑝
𝑢𝑘 = 𝑢𝑘−1 + 𝑢0,𝑘 − 𝑢0,𝑘−1 + 𝐾𝑝 𝑒𝑘 − 𝑒𝑘−1 + 𝑇𝑒
𝑇𝑖 𝑠 𝑘

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

% PI Controller Transfer function


Kp = 0.52;
𝑢(𝑠) 𝐾𝑝 (𝑇𝑖 𝑠 + 1) Ti = 18;
𝐻𝑃𝐼 𝑠 = =
𝑒(𝑠) 𝑇𝑖 𝑠 num = Kp*[Ti, 1];
den = [Ti, 0];

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

Gain Phase Lag

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

𝑢 𝑡 = 𝑈 ∙ 𝑠𝑖𝑛𝜔𝑡 𝑦 𝑡 = 𝑈𝐴
ด 𝑠𝑖𝑛(𝜔𝑡 + 𝜙)
𝑌

Input Dynamic Output

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

Note! Only the


gain and phase
are different

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

frequency 2 (24 hours)


Dynamic System frequency 2 (24 hours)
Inside Temperature

Note! Only the gain and phase are different

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

Frequency Response using


Bode Diagram
Hans-Petter Halvorsen
Bode Diagram
You can find the Bode diagram from experiments on the physical process or from the transfer function (the model of the
system). A simple sketch of the Bode diagram for a given system:

The Bode diagram gives a simple Graphical


overview of the Frequency Response for a
𝜔𝑐
0𝑑𝐵 𝐿𝑜𝑔 𝜔 ω [rad/s] given system. A Tool for Analyzing the
∆𝐾
Stability properties of the Control System.

With MATLAB you can easily create Bode


diagram from the Transfer function model
using the bode() function

𝜑 𝜔180
𝐿𝑜𝑔 𝜔 ω [rad/s]
Bode Diagram from experiments
Find Data for different frequencies We find 𝐴 and 𝜙 for each of the frequencies,
e.g.:

...

Based on that we can plot the


Frequency Response in a so-called Bode
Diagram:
Bode Diagram The x-scale is logarithmic

Gain (“Forsterkningen”)
Note! The y-scale is in [𝑑𝐵]

𝑥 𝑑𝐵 = 20𝑙𝑜𝑔10 𝑥

Phase lag (“Faseforkyvningen”)


The y-scale is in [𝑑𝑒𝑔𝑟𝑒𝑒𝑠]
2𝜋 𝑟𝑎𝑑 = 360°

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

% Define Transfer function


num=[1];
den=[1, 1];
H = tf(num, den)

% 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

% Define Transfer function


num = [1];
Instead of Plotting the Bode Diagram we den = [1, 1];
H = tf(num, den)
can also use the bode function for
% Frequency Response
calculation and showing the data as well: bode(H);
grid on
freq_data =
% Get Freqquency Response Data
wlist = [0.01, 0.1, 1, 2 ,3 ,5 ,10, 100];
0.0100 -0.0004 -0.5729 [mag, phase, w] = bode(H, wlist);
0.1000 -0.0432 -5.7106
1.0000 -3.0103 -45.0000 for i=1:length(w)
2.0000 -6.9897 -63.4349 magw(i) = mag(1,1,i);
phasew(i) = phase(1,1,i);
3.0000 -10.0000 -71.5651 end
5.0000 -14.1497 -78.6901
10.0000 -20.0432 -84.2894 magdB = 20*log10(magw); % Convert to dB
100.0000 -40.0004 -89.4271
freq_data = [wlist; magdB; phasew]'
Bode Diagram – MATLAB Example
MATLAB Code:
clear, clc

% 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

1 Rectangular form of a complex number 2 Exponential/polar form of a complex number


𝐼𝑚𝑎𝑔𝑖𝑛𝑎𝑟𝑦 𝐼𝑚𝑎𝑔𝑖𝑛𝑎𝑟𝑦
𝐴𝑥𝑖𝑠 (𝐼𝑚) 𝐴𝑥𝑖𝑠 (𝐼𝑚)

𝑏 𝑧 = 𝑎 + 𝑗𝑏 𝑧 = 𝑟𝑒 𝑗𝜃
𝑏
𝑟
𝜃
𝑅𝑒𝑎𝑙 𝑅𝑒𝑎𝑙
0 𝑎 𝐴𝑥𝑖𝑠(𝑅𝑒) 0 𝑎 𝐴𝑥𝑖𝑠(𝑅𝑒)

Length (“Gain”): Angle (“Phase”):


𝑏
𝑟= 𝑧 = 𝑎2 + 𝑏 2 𝜃 = 𝑎𝑡𝑎𝑛
𝑎
https://www.halvorsen.blog

Frequency response from


Transfer function

Hans-Petter Halvorsen
Manually find the Frequency Response Theory

from the Transfer Function


For a transfer function:
𝑦(𝑠)
𝐻 𝑆 =
𝑢(𝑠)
𝑠 = 𝑗𝜔
We have that:
𝐻 𝑗𝜔 = 𝐻(𝑗𝜔) 𝑒 𝑗∠𝐻(𝑗𝜔)

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

The Frequency Response (we replace 𝑠 with 𝑗𝜔) then becomes:


𝐾 𝐾
𝐻 𝑗𝜔 = =
𝑇𝑗𝜔 + 1 ณ 1 + 𝑗 𝑇𝜔

𝑅𝑒 𝐼𝑚
Polar form:
𝐾
𝐻 𝑗𝜔 = 𝑇𝜔
12 + 𝑇𝜔 2 𝑒 𝑗 𝑎𝑟𝑐𝑡𝑎𝑛 1
𝐾
= 𝑒 𝑗 −𝑎𝑟𝑐𝑡𝑎𝑛(𝑇𝜔)
1 + 𝑇𝜔 2

Finally:
𝐾
𝐻 𝑗𝜔 = 𝑒 𝑗 −𝑎𝑟𝑐𝑡𝑎𝑛(𝑇𝜔)
1 + 𝑇𝜔 2

cont. next page


cont. from previous page

The Gain function becomes:


𝐾
𝐴 𝜔 = 𝐻(𝑗𝜔) =
1 + 𝑇𝜔 2

Or in 𝑑𝐵 (used in the Bode Plot):


𝐴 𝜔 𝑑𝐵 = 𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔𝐾 − 20𝑙𝑜𝑔 1 + 𝑇𝜔 2

The Phase function becomes ( 𝑟𝑎𝑑 ):

𝜙 𝜔 = ∠𝐻 𝑗𝜔 = 𝑎𝑟𝑔 𝐻 𝑗𝜔 = −𝑎𝑟𝑐𝑡𝑎𝑛(𝑇𝜔)

Or in degrees ° (used in the Bode plot):


180
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = −𝑎𝑟𝑐𝑡𝑎𝑛(𝑇𝜔) ∙
𝜋
Note: 2𝜋 𝑟𝑎𝑑 = 360°
Transfer function: 𝑨(𝝎) og 𝝓(𝝎):
1 𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔1 − 20𝑙𝑜𝑔 (𝜔)2 +1
𝐻 𝑠 = ∠𝐻(𝑗𝜔) = −arctan(𝜔)
𝑠+1

degrees, we have to multiply with: 𝜋


Note! In order to find the phase in
4 𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔4 − 20𝑙𝑜𝑔 (2𝜔)2 +1
𝐻 𝑠 = ∠𝐻(𝑗𝜔) = −arctan(2𝜔)
2𝑠 + 1
5 𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔5 − 20𝑙𝑜𝑔 (𝜔)2 +1 − 20𝑙𝑜𝑔 (10𝜔)2 +1
𝐻 𝑆 = ∠𝐻(𝑗𝜔) = −arctan(𝜔) − arctan(10𝜔)
𝑠 + 1 (10𝑠 + 1)
𝐻(𝑗𝜔) 𝑑𝐵 = −20𝑙𝑜𝑔 (𝜔)2 − 2𝑥20𝑙𝑜𝑔 (𝜔)2 +1
1 = 20𝑙𝑜𝑔𝜔 − 40𝑙𝑜𝑔 (𝜔)2 +1
𝐻 𝑆 = 2
𝑠 𝑠+1 ∠𝐻(𝑗𝜔) = −90 − 2 arctan(𝜔)

3.2𝑒 −2𝑠 𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔3.2 − 20𝑙𝑜𝑔 (3𝜔)2 +1


𝐻 𝑠 = ∠𝐻(𝑗𝜔) = −2𝜔 − arctan(3𝜔)
3𝑠 + 1
5𝑠 + 1 𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔 (5𝜔)2 +1 − 20𝑙𝑜𝑔 (2𝜔)2 +1 − 20𝑙𝑜𝑔 (10𝜔)2 +1
𝐻 𝑆 =

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:

The mathematical expressions for 𝐴(𝜔) and


𝜙(𝜔) become:

𝐻(𝑗𝜔) 𝑑𝐵 = 20𝑙𝑜𝑔4 − 20𝑙𝑜𝑔 (2𝜔)2 +1

∠𝐻(𝑗𝜔) = −arctan(2𝜔)

These equations can easily be implemented in MATLAB (See next slide)


clear
clc MATLAB Code
% Transfer function
num=[4]; clear
den=[2, 1]; clc
H = tf(num, den)
w = [0.1, 0.16, 0.25, 0.4, 0.625, 2.5, 10];
% Bode Plot
figure(1) % Alt 2: Use Mathematical expressions for H and <H
bode(H) disp('----- Alternative 2 -----')
grid on gain = 20*log10(4) - 20*log10(sqrt((2*w).^2+1));
phase = -atan(2*w);
% Margins and Phases for given Frequencies phasedeg = phase * 180/pi; %convert to degrees

% Alt 1: Use bode function directly mag_data2 = [w; gain]


disp('----- Alternative 1 -----') phase_data2 = [w; phasedeg]
w = [0.1, 0.16, 0.25, 0.4, 0.625, 2.5, 10];
figure(2)
[magw, phasew] = bode(H, w); subplot(2,1,1)
semilogx(w,gain)
for i=1:length(w) grid on
mag(i) = magw(1,1,i);
phase(i) = phasew(1,1,i); subplot(2,1,2)
end semilogx(w,phasedeg)
grid on
magdB = 20*log10(mag); %convert to dB
mag_data = [w; magdB]
phase_data = [w; phase]
Transfer functions
with Time delay
Transfer functions with Time delay
A general transfer function for a 1.order system with time delay is:
𝐾
𝐻 𝑠 = 𝑒 −𝑇𝑠
𝑇𝑠 + 1

Frequency Response functions for gain and phase margin becomes:

𝐴 𝜔 𝑑𝐵 = 20𝑙𝑜𝑔(𝐾) − 20𝑙𝑜𝑔 (𝑇𝜔)2 +1


𝜙 𝜔 = − 𝑎𝑟𝑐𝑡𝑎𝑛 𝑇𝜔 − 𝜔 ∙ 𝜏

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)

T = 22; [num_pade,den_pade] = pade(T,N)


Tau = 2; Hpade = tf(num_pade,den_pade);
H = H1 * H2
s = tf('s'); H = series(H1, Hpade);
bode(H) H = K*exp(-Tau*s)/(T*s+1) bode(H);

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

Poles: ∠𝐻(𝑗𝜔) = −2𝜔 − arctan(3𝜔)


1
𝑝1 = − = −0.33 180
3 Or in degrees:∠𝐻 𝑗𝜔 = −2𝜔 − arctan(3𝜔) ∙ 𝜋
Zeros:
None Break frequency:
1 1
𝜔= = = 0.33 𝑟𝑎𝑑/𝑠
𝑇 3
clear, clc or:
clear, clc
s = tf('s'); s=tf('s');
K=3.2;
T=3; K=3.2;
T=3;
Tau = 2;
H1=tf(K/(T*s+1));
num = K;
den = [T, 1];
delay = 2; H1 = tf(num, den);
H = set(H1,'inputdelay',delay)
s = tf('s')
bode(H); H2 = exp(-Tau*s);

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

Continuous-time transfer function.

p = -0.3333

z = Empty matrix: 0-by-1


https://www.halvorsen.blog

Frequency response from


Input/Output Signals

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

𝑢 𝑡 = 𝑈 ∙ 𝑠𝑖𝑛𝜔𝑡 𝑦 𝑡 = 𝑈𝐴
ด 𝑠𝑖𝑛(𝜔𝑡 + 𝜙)
𝑌

Input Dynamic Output

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

input and output signals


The input signal is given by:
𝑢 𝑡 = 𝑈 ∙ 𝑠𝑖𝑛𝜔𝑡
The steady-state output signal will then be:
𝑦 𝑡 = 𝑈𝐴 ด 𝑠𝑖𝑛(𝜔𝑡 + 𝜙)
𝑌
The gain is given by:
𝑌
𝐴=
𝑈
The phase lag is given by:
𝜙 = −𝜔Δ𝑡 [𝑟𝑎𝑑]
Frequency Response from sinusoidal Theory

input and output signals


You will get plots like this for each frequency:

The gain is given by:


𝑌
𝐴=
𝑈

The phase lag is given by:


𝜙 = −𝜔Δ𝑡 [𝑟𝑎𝑑]

t
Find the gain (𝐴) and the phase (𝜙) for the given frequency from the plot
𝜔 = 1 rad/s
Solutions
From the Plot we get:

Cont. next page ->


Solutions
Conversion to dB
𝐴 𝑑𝐵
𝐴 𝑑𝐵 = 20𝑙𝑜𝑔(𝐴) or the other way: 𝐴= 10 20
Example:

𝐴 = 0.68
𝐴 𝑑𝐵 = 20𝑙𝑜𝑔(𝐴)=20𝑙𝑜𝑔(0.68) ≈ −3.35𝑑𝐵

Or the other way:

𝐴 𝑑𝐵 = −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.

𝑇𝑐 is the time-constant of the control system which


the user must specify
Originally, Skogestad defined the factor 𝑐 = 4. This gives
good set-point tracking. But the disturbance
compensation may become quite sluggish. To obtain
Figure: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010. faster disturbance compensation, you can use 𝑐 = 1.5
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
https://www.halvorsen.blog

Controller Design/Tuning
using MATLAB
Hans-Petter Halvorsen
Controller Design/Tuning using MATLAB

• Frequency Design and Analysis


• pidtune() MATLAB function
• PID Tuner (Interactive Tools)
• ...

Validate with simulations!


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
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)

The new controller achieves the higher


crossover frequency, but at the cost of a
reduced phase margin.
MATLAB PID Tuner
Define Controller Type Tuning

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

1 The Complex domain Poles

Asymptotically stable system: 𝜔𝑐 < 𝜔180


Tracking
transfer
Marginally stable system: 𝜔𝑐 = 𝜔180
function Unstable system: 𝜔𝑐 > 𝜔180
Figure: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010.
1 Asymptotically stable system:
Poles
Each of the poles of the transfer function lies strictly in the
left half plane (has strictly negative real part).

3 Unstable system:
At least one pole lies in the right half
2 Marginally stable system: plane (has real part greater than zero).

One or more poles lies on the imaginary axis


(have real part equal to zero), and all these Or: There are multiple and coincident
poles are distinct. Besides, no poles lie in the poles on the imaginary axis.
right half plane. 1
Example: double integrator 𝐻(𝑠) = 𝑠2
Theory

Stability Analysis
Asymptotically stable system: Marginally stable system: Unstable system:
lim 𝑦 𝑡 = 𝑘 lim 𝑦 𝑡 = ∞
𝑡→∞ 𝑡→∞

Figures: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010.


0 < lim 𝑦 𝑡 < ∞
𝑡→∞

At least one pole lies in the right half plane (has


real part greater than zero).

Or: There are multiple and coincident poles


Each of the poles of the transfer function lies One or more poles lies on the imaginary axis (have
on the imaginary axis. Example: double
strictly in the left half plane (has strictly negative real part equal to zero), and all these poles are 1
real part). distinct. Besides, no poles lie in the right half plane. integrator 𝐻(𝑠) = 2
𝑠
https://www.halvorsen.blog

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)

2 The Tracking Function (“Følgeforholdet”):

L = ...
T = feedback(L, 1)

3 The Sensitivity Function (“Sensitivitetsfunksjonen”):

T = ...
S = 1-T
Frequency Response and Stability Analysis Theory

Bode Diagram 𝜔𝑐 and 𝜔180 are called the crossover-frequencies


(“kryssfrekvens”)

Δ𝐾 is the gain margin (GM) of the system (“Forsterkningsmargin”).


How much the loop gain can increase before the system becomes
unstable

𝜙 is the phase margin (PM) of the system (“Fasemargin”).


How much phase shift the system can tolerate before it becomes
unstable.

Asymptotically stable system: 𝜔𝑐 < 𝜔180


Marginally stable system: 𝜔𝑐 = 𝜔180
Unstable system: 𝜔𝑐 > 𝜔180
Frequency Response and Stability Analysis Theory

The definitions are as follows:


Gain Crossover-frequency - 𝜔𝑐 : 𝜔180 is the gain margin frequency, in
radians/second. A gain margin frequency indicates
𝐿 𝑗𝜔𝑐 = 1 = 0𝑑𝐵 where the model phase crosses -180 degrees.

GM (Δ𝐾) is the gain margin of the system.


Phase Crossover-frequency - 𝜔180 :
𝜔𝑐 is phase margin frequency, in radians/second. A
∠𝐿 𝑗𝜔180 = −180𝑜 phase margin frequency indicates where the
model magnitude crosses 0 decibels.
Gain Margin - GM (𝛥𝐾): PM (𝜑) is the phase margin of the system.
𝐺𝑀 𝑑𝐵 = − 𝐿 𝑗𝜔180 𝑑𝐵
We have that:
Phase margin PM (𝜑): 1. Asymptotically stable system: 𝜔𝑐 < 𝜔180
2. Marginally stable system: 𝜔𝑐 = 𝜔180
𝑃𝑀 = 180𝑜 + ∠𝐿(𝑗𝜔𝑐 ) 3. Unstable system: 𝜔𝑐 > 𝜔180
https://www.halvorsen.blog

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:

𝐿 𝑠 = 𝐻𝑐 𝐻𝑝 𝐻𝑚 We will use the built-in function series() in MATLAB.


Tracking transfer function: 𝑻(𝒔)
We need to find the Tracking transfer function 𝑇(𝑠) using MATLAB.
The Tracking transfer function is defined as:
𝑦(𝑠) 𝐻𝑐 𝐻𝑝 𝐻𝑚 𝐿(𝑠)
𝑇 𝑠 = = 1+𝐻 = 1+𝐿(𝑠) We will use the built-in function feedback() in MATLAB.
𝑟(𝑠) 𝑐 𝐻𝑝 𝐻𝑚
Sensitivity transfer function: 𝑺(𝒔)
We need to find the Sensitivity transfer function 𝑆(𝑠) using MATLAB.
The Sensitivity transfer function is defined as:
𝑒(𝑠) 1
𝑆 𝑠 = 𝑟(𝑠) = 1+𝐿(𝑠) = 1 − 𝑇(𝑠)
Stability Analysis
• Plot the Bode plot for the system using e.g., the bode()
function in MATLAB
• Find the crossover-frequencies (𝜔180 , 𝜔𝑐 ) and stability
margins GM (𝐴(𝜔)), PM (𝜙(𝜔)) of the system (𝐿(𝑠)) from
the Bode plot.
• Plot also Bode diagram where the crossover-frequencies,
GM and PM are illustrated. Tip! Use the margin() function
in MATLAB.
• Use also the margin() function in order to find values for
𝜔180 , 𝜔𝑐 , 𝐴(𝜔), 𝜙(𝜔) directly.
• You should compare and discuss the results.
• How much can you increase 𝐾𝑝 before the system
becomes unstable?
MATLAB Code:
clear, clc, clf

% The Process Transfer function Hp(s) bode(L)


num_p=[1];
den1=[1, 0];
den2=[1, 1];
den_p = conv(den1,den2);
Hp = tf(num_p, den_p)

% The Measurement Transfer function Hm(s)


num_m=[1];
den_m=[3, 1];
Hm = tf(num_m, den_m)
margin(L)
% The Controller Transfer function Hr(s)
Kp = 0.35;
Hr = tf(Kp)

% The Loop Transfer function


L = series(series(Hr, Hp), Hm)

% 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 °

0.1 0.3 𝜔180 = 0.58 10


1
0.2 0.5
Stable vs. Unstable System
• We will find and use different values of 𝐾𝑝 where we get a marginally
stable system, an asymptotically stable system and an unstable system.
• We will Plot the time response for the tracking function using the step()
function in MATLAB for all these 3 categories. How can we use the step
response to determine the stability of the system?
• We will find 𝜔180 , 𝜔𝑐 , 𝐴 𝜔 and 𝜙(𝜔) in all 3 cases. We will see how
we use 𝜔𝑐 and 𝜔180 to determine the stability of the system.
• We will find and plot the poles and zeros for the system for all the 3
categories mentioned above. We will see how we can we use the poles
to determine the stability of the system.
• Bandwidth: We will plot the Loop transfer function 𝐿(𝑠), the Tracking
transfer function 𝑇(𝑠) and the Sensitivity transfer function 𝑆(𝑠) in a
Bode diagram for the system for all the 3 categories mentioned above.
Stable System wc
w180
=
=
0.2649 rad/s
0.5774 rad/s
𝐾𝑝 = 0.35 gm = 3.8095
gmdB = 11.6174 dB
For what 𝐾𝑝 becomes the system marginally stable?
pm = 36.6917 degrees
𝐾𝑝𝑚 = 0.35 × Δ𝐾 = 0.35 × 3.8 ≈ 1,32

𝜔𝑐 < 𝜔180 lim 𝑦 𝑡 = 1 Poles in the left half plane


𝑡→∞
Marginally Stable System wc
w180
=
=
0.5744
0.5774
rad/s
rad/s
gm = 1.0101
𝐾𝑝 = 1.32 gmdB = 0.0873 dB
pm = 0.2500 degrees

𝜔𝑐 = 𝜔180 0 < lim 𝑦 𝑡 < ∞ Poles at the imaginary axis


𝑡→∞
wc = 0.7020
Unstable System w180 = 0.5774
gm = 0.6667
𝐾𝑝 = 2 gmdB = -3.5218
pm = -9.6664

𝜔𝑐 > 𝜔180 lim 𝑦 𝑡 = ∞ Poles in the right half plane


𝑡→∞
MATLAB Code
...
clear, clc, clf
% Bode Diagram
% The Process Transfer function Hp(s)
figure(1)
num_p=[1];
bode(L), grid on
den1=[1, 0];
den2=[1, 1];
figure(2)
den_p = conv(den1,den2);
margin(L), grid on
Hp = tf(num_p, den_p)
[gm, pm, w180, wc] = margin(L);
% The Measurement Transfer function Hm(s)
wc
num_m=[1];
w180
den_m=[3, 1];
gm
Hm = tf(num_m, den_m)
gmdB = 20*log10(gm)
pm
% The Controller Transfer function Hr(s)
Kp = 0.35; % Stable System
% Simulating step response for control system
%Kp = 1.32; % Marginally Stable System
(tracking transfer function)
%Kp = 2; % Unstable System
figure(3)
Hr = tf(Kp)
step(T)
% The Loop Transfer function
% Poles
L = series(series(Hr, Hp), Hm)
pole(T)
% Tracking transfer function
figure(4)
T=feedback(L,1);
pzmap(T)
% Sensitivity transfer function
S=1-T;
% Bandwidth
figure(5)
...
bodemag(L,T,S), grid on
Theory
“Golden rules” of Stability Margins
for a Control System Reference: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010.

Gain Margin (GM): (Norwegian: “Forsterkningsmargin”)

Phase Margin (PM): (Norwegian: “Fasemargin”)


https://www.halvorsen.blog

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

Good Set-point Tracking: |𝑆(𝑗𝜔)| ≪ 1, |𝑇 (𝑗𝜔)| ≈ 1, |𝐿(𝑗𝜔)| ≫ 1


𝐾𝑝 = 0.35 Good Set-point Tracking: |𝑆(𝑗𝜔)| ≪ 1, |𝑇 (𝑗𝜔)| ≈ 1, |𝐿(𝑗𝜔)| ≫ 1

𝜔𝑠 = 0.092 𝜔𝑐 = 0.27 𝜔𝑡 = 0.46

0.05 0.1 0.2 0.3 1


https://www.halvorsen.blog

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

Kc = 1.32; % Critical Gain


Tc = 2*pi/w180; % Tc - Critical Period

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 Process Transfer function Hp(s) % Bode Diagram


num_p=[1]; figure(1)
den1=[1, 0]; bode(L), grid on
den2=[1, 1];
den_p = conv(den1,den2); figure(2)
Hp = tf(num_p, den_p); margin(L), grid on

% 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

You might also like