
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 푇 Integral Time [sec. ] 푟 is the Reference Signal or Set-point 푖 푦 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 푇 Integral Time [sec. ] 푟 is the Reference Signal or Set-point 푖 푦 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 (휙). Input Signal Theory 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 휔푐 퐿표푔 휔 ω [rad/s] given system. A Tool for Analyzing the 0푑퐵 ∆퐾 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.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages107 Page
-
File Size-