Frequency Response With MATLAB Examples

Transcription

https://www.halvorsen.blogFrequency Responsewith MATLAB ExamplesControl Design and AnalysisHans-Petter Halvorsen

Contents Introduction to PID ControlIntroduction to Frequency ResponseFrequency Response using Bode DiagramIntroduction to Complex Numbers (which Frequency Response Theory isbased on)Frequency Response from Transfer FunctionsFrequency Response from Input/output SignalsPID Controller Design and Tuning (Theory)PID Controller Design and Tuning using MATLABStability Analysis using MATLABStability Analysis of Feedback SystemsStability Analysis of Feedback Systems – a Practical ExampleThe Bandwidth of the Control SystemPractical PI Controller Example

https://www.halvorsen.blogPID ControlHans-Petter Halvorsen

Control Systemπ‘Ÿπ‘’ ControllerFiltering𝑒ActuatorsSensorsπ‘Ÿ – 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𝑣Process𝑦

The PID Algorithm𝑑𝐾𝑝ࢱ π‘’π‘‘πœ 𝐾𝑝 𝑇𝑑 π‘’αˆΆπ‘’ 𝑑 𝐾𝑝 𝑒 𝑇𝑖 0Where 𝑒 is the controller output and 𝑒 is thecontrol error:𝑒 𝑑 π‘Ÿ 𝑑 𝑦(𝑑)π‘Ÿ is the Reference Signal or Set-point𝑦 is the Process value, i.e., the Measured valueTuning Parameters:𝐾𝑝𝑇𝑖𝑇𝑑Proportional GainIntegral Time [sec. ]Derivative Time [sec. ]

The PI Algorithm𝑑𝐾𝑝ࢱ π‘’π‘‘πœπ‘’ 𝑑 𝐾𝑝 𝑒 𝑇𝑖 0Where 𝑒 is the controller output and 𝑒 is thecontrol error:𝑒 𝑑 π‘Ÿ 𝑑 𝑦(𝑑)π‘Ÿ is the Reference Signal or Set-point𝑦 is the Process value, i.e., the Measured valueTuning Parameters:𝐾𝑝𝑇𝑖Proportional GainIntegral Time [sec. ]

PI(D) Algorithm in MATLAB We can use the pid() function in MATLAB We can define the PI(D) transfer functionusing the tf() function in MATLAB We can also define and implement a discretePI(D) algorithm

Discrete PI Controller AlgorithmWe start with:𝐾𝑝 𝑑ࢱ π‘’π‘‘πœπ‘‡π‘– 0In 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 𝑇𝑒𝑇𝑖 𝑠 π‘˜π‘’ 𝑑 𝑒0 𝐾𝑝 𝑒 𝑑 Whereπ‘’π‘˜ π‘Ÿπ‘˜ π‘¦π‘˜We can also split the equation above in 2 different parts by setting: π‘’π‘˜ π‘’π‘˜ π‘’π‘˜ 1This gives the following PI control algorithm:π‘’π‘˜ π‘Ÿπ‘˜ π‘¦π‘˜ π‘’π‘˜ 𝑒0,π‘˜ 𝑒0,π‘˜ 1 𝐾𝑝 π‘’π‘˜ π‘’π‘˜ 1 π‘’π‘˜ π‘’π‘˜ 1 π‘’π‘˜This algorithm can easily be implemented in MATLAB𝐾𝑝𝑇𝑒𝑇𝑖 𝑠 π‘˜

Discrete PI Controller AlgorithmDiscrete PI control algorithm:π‘’π‘˜ π‘Ÿπ‘˜ π‘¦π‘˜ π‘’π‘˜ 𝑒0,π‘˜ 𝑒0,π‘˜ 1 𝐾𝑝 π‘’π‘˜ π‘’π‘˜ 1π‘’π‘˜ π‘’π‘˜ 1 π‘’π‘˜πΎπ‘ 𝑇𝑠 π‘’π‘˜π‘‡π‘–

PID Controller –Transfer FunctionWe have:𝐾𝑝 𝑑𝑒 𝑑 𝐾𝑝 𝑒 ΰΆ± π‘’π‘‘πœ 𝐾𝑝 𝑇𝑑 π‘’αˆΆπ‘‡π‘– 0Laplace gives:𝐻𝑃𝐼𝐷𝐾𝑝𝑒(𝑠)𝑠 𝐾𝑝 𝐾𝑝 𝑇𝑑 𝑠𝑒(𝑠)𝑇𝑖 𝑠𝐻𝑃𝐼𝐷𝑒(𝑠) 𝐾𝑝 (𝑇𝑑 𝑇𝑖 𝑠 2 𝑇𝑖 𝑠 1)𝑠 𝑒(𝑠)𝑇𝑖 𝑠or:

PI Controller –Transfer FunctionWe have:𝐾𝑝 𝑑𝑒 𝑑 𝐾𝑝 𝑒 ΰΆ± π‘’π‘‘πœπ‘‡π‘– 0Laplace gives:𝐻𝑃𝐼𝐾𝑝 𝐾𝑝 𝑇𝑖 𝑠 𝐾𝑝 𝐾𝑝 (𝑇𝑖 𝑠 1)𝑒(𝑠)𝑠 𝐾𝑝 𝑒(𝑠)𝑇𝑖 𝑠𝑇𝑖 𝑠𝑇𝑖 𝑠Finally:𝐻𝑃𝐼𝑒(𝑠) 𝐾𝑝 (𝑇𝑖 𝑠 1)𝑠 𝑒(𝑠)𝑇𝑖 𝑠

Define PI Transfer function in MATLABclear, clc𝐻𝑃𝐼𝑒(𝑠) 𝐾𝑝 (𝑇𝑖 𝑠 1)𝑠 𝑒(𝑠)𝑇𝑖 𝑠% PI Controller Transfer functionKp 0.52;Ti 18;num Kp*[Ti, 1];den [Ti, 0];Hpi tf(num,den).

PI Controller – State space modelGiven:𝐾𝑝𝑒 𝑠 𝐾𝑝 𝑒 𝑠 𝑒 𝑠𝑇𝑖 𝑠1We set 𝑧 𝑒 𝑠𝑧 𝑒 π‘§αˆΆ 𝑒𝑠This gives:π‘§αˆΆ 𝑒𝐾𝑝𝑒 𝐾𝑝 𝑒 𝑧𝑇𝑖Where𝑒 π‘Ÿ 𝑦

PI Controller – Discrete State space modelUsing Euler:π‘§αˆΆ Where 𝑇𝑠 is the Sampling Time.This gives:π‘§π‘˜ 1 π‘§π‘˜π‘‡π‘ π‘§π‘˜ 1 π‘§π‘˜ π‘’π‘˜π‘‡π‘ πΎπ‘π‘’π‘˜ 𝐾𝑝 π‘’π‘˜ 𝑧𝑇𝑖 π‘˜Finally:π‘’π‘˜ π‘Ÿπ‘˜ π‘¦π‘˜πΎπ‘π‘’π‘˜ 𝐾𝑝 π‘’π‘˜ 𝑧𝑇𝑖 π‘˜π‘§π‘˜ 1 π‘§π‘˜ 𝑇𝑠 π‘’π‘˜

PI Controller – Discrete State space modelimplemented in MATLABclear, clc.for i 1:N.e r - y;u Kp*e z;z z dt*Kp*e/Ti;.endplot(.)

https://www.halvorsen.blogFrequency ResponseHans-Petter Halvorsen

Frequency ResponseTheory The frequency response of a system is a frequency dependentfunction which expresses how a sinusoidal signal of a given frequencyon the system input is transferred through the system. Eachfrequency component is a sinusoidal signal having certain amplitudeand a certain frequency. The frequency response is an important tool for analysis and designof signal filters and for analysis and design of control systems. The frequency response can be found experimentally or from atransfer function model. The frequency response of a system is defined as the steady-stateresponse of the system to a sinusoidal input signal. When the systemis in steady-state, it differs from the input signal only inamplitude/gain (A) and phase lag (πœ™).

TheoryFrequencyResponseInput Signal𝑒 𝑑 π‘ˆ π‘ π‘–π‘›πœ”π‘‘AmplitudeInput SignalDynamicSystemOutput SignalOutput Signal𝑦 𝑑 π‘ˆπ΄ΰΈ” 𝑠𝑖𝑛(πœ”π‘‘ πœ™)π‘ŒFrequencyGainPhase LagThe frequency response of a system expresses how a sinusoidal signal of a given frequency on the systeminput is transferred through the system. The only difference is the gain and the phase lag.

Frequency Response - DefinitionTheory𝑦 𝑑 π‘ˆπ΄ΰΈ” 𝑠𝑖𝑛(πœ”π‘‘ πœ™)𝑒 𝑑 π‘ˆ οΏ½οΏ½ 1 π‘Ÿπ‘Žπ‘‘/𝑠and the same for Frequency 2, 3, 4, 5, 6, etc. πœ” 1 π‘Ÿπ‘Žπ‘‘/𝑠The frequency response of a system is defined as the steady-state response of the system to a sinusoidalinput 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 ExampleTheoryOutside TemperatureT 1 yearfrequency 1 (year)Dynamic Systemfrequency 1 (year)Inside TemperatureNote! Only thegain and phaseare differentAssume 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 ExampleTheoryOutside TemperatureT 24 hoursfrequency 2 (24 hours)Dynamic SystemInside Temperaturefrequency 2 (24 hours)Note! Only the gain and phase are differentAssume 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.blogFrequency Response usingBode DiagramHans-Petter Halvorsen

Bode DiagramYou can find the Bode diagram from experiments on the physical process or from the transfer function (the model of thesystem). A simple sketch of the Bode diagram for a given system:πœ”π‘0𝑑𝐡 πΎπΏπ‘œπ‘” πœ”Ο‰ [rad/s]The Bode diagram gives a simple Graphicaloverview of the Frequency Response for agiven system. A Tool for Analyzing theStability properties of the Control System.With MATLAB you can easily create Bodediagram from the Transfer function modelusing the bode() functionπœ‘πœ”180πΏπ‘œπ‘” πœ”Ο‰ [rad/s]

Bode Diagram from experimentsFind Data for different frequencies.Based on that we can plot theFrequency Response in a so-called BodeDiagram:We find 𝐴 and πœ™ for each of the frequencies,e.g.:

Bode DiagramThe x-scale is logarithmicGain (β€œ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 Bodediagrams we use radians Ο‰ [rad/s]. The relationship between these are as follows:πœ” 2πœ‹π‘“

Frequency Response – MATLABTransfer Function:MATLAB Code:clearclcclose all% Define Transfer functionnum [1];den [1, 1];H tf(num, den)% Frequency Responsebode(H);grid onThe frequency response is an important tool for analysis and designof signal filters and for analysis and design of control systems.

Frequency Response – MATLABTransfer Function:clearclcclose allInstead of Plotting the Bode Diagram wecan also use the bode function forcalculation and showing the data as well:freq data 78.6901-84.2894-89.4271% Define Transfer functionnum [1];den [1, 1];H tf(num, den)% Frequency Responsebode(H);grid on% Get Freqquency Response Datawlist [0.01, 0.1, 1, 2 ,3 ,5 ,10, 100];[mag, phase, w] bode(H, wlist);for i 1:length(w)magw(i) mag(1,1,i);phasew(i) phase(1,1,i);endmagdB 20*log10(magw); % Convert to dBfreq data [wlist; magdB; phasew]'

Bode Diagram – MATLAB ExampleMATLAB Code:clear, clc% Transfer functionnum [1];den1 [1,0];den2 [1,1]den3 [1,1]den conv(den1,conv(den2,den3));H tf(num, den)clear, clc% Bode Diagrambode(H)subplot(2,1,1)grid onsubplot(2,1,2)grid on% Transfer functionnum [1];den [1,2,1,0];H tf(num, den)or:% Bode Diagrambode(H)subplot(2,1,1)grid onsubplot(2,1,2)grid on

ExampleWe will use the following system as an example:1𝐻𝑝 𝑠(𝑠 1)𝐻𝑐 πΎπ‘π‘Ÿπ‘’ Controller𝑒Sensors1π»π‘š 3𝑠 1Process𝑦

Bode Diagram – MATLAB ExampleMATLAB Code:clearclcnum 1;den [1,1,0];Hp tf(num,den)bode(Hp)grid on1𝐻𝑝 𝑠(𝑠 1)

https://www.halvorsen.blogComplex NumbersBackground Theory for Frequency ResponseHans-Petter Halvorsen

Complex NumbersA Complex Number is given by:𝑧 π‘Ž 𝑗𝑏Where𝑗 οΏ½οΏ½οΏ½ (πΌπ‘š)We have that:π‘Ž 𝑅𝑒 𝑧𝑧 π‘Ž 𝑗𝑏𝑏𝑏 οΏ½(𝑅𝑒)

Complex Numbers𝑗 1Polar form:𝑧 π‘Ÿπ‘’ π‘—πœƒWhere:π‘Ž2 𝑏2π‘πœƒ π‘Žπ‘‘π‘Žπ‘›π‘Žπ‘Ÿ 𝑧 Note!π‘Ž π‘Ÿ cos ��𝑠 (πΌπ‘š)𝑧 π‘Ÿπ‘’ π‘—πœƒπ‘π‘Ÿπ‘ π‘Ÿ sin 𝑒)

Complex Numbers1Rectangular form of a complex 𝑖𝑠 (πΌπ‘š)2Exponential/polar form of a complex 𝑖𝑠 (πΌπ‘š)𝑧 π‘Ž 𝑗𝑏𝑏𝑧 π‘Ÿπ‘’ οΏ½οΏ½οΏ½(𝑅𝑒)Length (β€œGain”):π‘Ÿ 𝑧 𝑗 1πœƒ0Angle (β€œPhase”):π‘Ž2 𝑏 οΏ½πœƒ π‘Žπ‘‘π‘Žπ‘›π‘Ž

https://www.halvorsen.blogFrequency response fromTransfer functionHans-Petter Halvorsen

Manually find the Frequency Responsefrom the Transfer FunctionTheoryFor 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 functiongiven by:𝑦(𝑠)𝐾𝐻 𝑠 𝑒(𝑠) 𝑇𝑠 1The Frequency Response (we replace 𝑠 with π‘—πœ”) then becomes:𝐾𝐾𝐻 π‘—πœ” π‘‡π‘—πœ” 1 ΰΈ“1 𝑗 π‘‡πœ”ΰΈ”π‘…π‘’πΌπ‘šPolar form:𝐾𝐻 π‘—πœ” 12 π‘‡πœ”πΎ1 π‘‡πœ”2π‘‡πœ”2 𝑒 𝑗 π‘Žπ‘Ÿπ‘π‘‘π‘Žπ‘› 1𝑒 𝑗 π‘Žπ‘Ÿπ‘π‘‘π‘Žπ‘›(π‘‡πœ”)Finally:𝐻 π‘—πœ” 𝐾1 π‘‡πœ”2𝑒 𝑗 π‘Žπ‘Ÿπ‘π‘‘π‘Žπ‘›(π‘‡πœ”)cont. next page

cont. from previous pageThe Gain function becomes:𝐴 πœ” 𝐻(π‘—πœ”) 𝐾1 π‘‡πœ”2Or in 𝑑𝐡 (used in the Bode Plot):𝐴 πœ” 𝑑𝐡 𝐻(π‘—πœ”) 𝑑𝐡 20π‘™π‘œπ‘”πΎ 20π‘™π‘œπ‘” 1 π‘‡πœ”2The Phase function becomes ( π‘Ÿπ‘Žπ‘‘ ):πœ™ πœ” 𝐻 π‘—πœ” π‘Žπ‘Ÿπ‘” 𝐻 π‘—πœ” π‘Žπ‘Ÿπ‘π‘‘π‘Žπ‘›(π‘‡πœ”)Or in degrees (used in the Bode plot):πœ™ πœ” 𝐻 π‘—πœ” π‘Žπ‘Ÿπ‘π‘‘π‘Žπ‘›(π‘‡πœ”) 180πœ‹Note: 2πœ‹ π‘Ÿπ‘Žπ‘‘ 360

𝑨(𝝎) og 𝝓(𝝎):Transfer function:1𝐻 𝑠 𝑠 14𝐻 𝑠 2𝑠 11𝐻 𝑆 𝑠 𝑠 1𝑑𝐡 20π‘™π‘œπ‘”1 20π‘™π‘œπ‘” (πœ”)2 1 𝐻(π‘—πœ”) arctan(πœ”)𝐻(π‘—πœ”)𝑑𝐡 20π‘™π‘œπ‘”4 20π‘™π‘œπ‘” (2πœ”)2 1 𝐻(π‘—πœ”) arctan(2πœ”)𝐻(π‘—πœ”)𝑑𝐡 20π‘™π‘œπ‘”5 20π‘™π‘œπ‘” (πœ”)2 1 20π‘™π‘œπ‘” (10πœ”)2 1 𝐻(π‘—πœ”) arctan(πœ”) arctan(10πœ”)𝐻(π‘—πœ”)𝑑𝐡 20π‘™π‘œπ‘” (πœ”)2 2π‘₯20π‘™π‘œπ‘” (πœ”)2 1 20π‘™π‘œπ‘”πœ” 40π‘™π‘œπ‘” (πœ”)2 12 𝐻(π‘—πœ”) 90 2 arctan(πœ”)3.2𝑒 2𝑠𝐻 𝑠 3𝑠 15𝑠 1𝐻 𝑆 2𝑠 1 (10𝑠 1)𝐻(π‘—πœ”)𝑑𝐡 20π‘™π‘œπ‘”3.2 20π‘™π‘œπ‘” (3πœ”)2 1 𝐻(π‘—πœ”) 2πœ” arctan(3πœ”)𝐻(π‘—πœ”)𝑑𝐡 20π‘™π‘œπ‘” (5πœ”)2 1 20π‘™π‘œπ‘” (2πœ”)2 1 20π‘™π‘œπ‘” (10πœ”)2 1 𝐻(π‘—πœ”) arctan(5πœ”) arctan(2πœ”) arctan(10πœ”)Note! In order to find the phase in180degrees, we have to multiply with: πœ‹5𝐻 𝑆 𝑠 1 (10𝑠 1)𝐻(π‘—πœ”)

Manually find the Frequency Responsefrom the Transfer FunctionGiven the following transfer function:4𝐻 𝑆 2𝑠 1Bode 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)

clearclc% Transfer functionnum [4];den [2, 1];H tf(num, den)% Bode Plotfigure(1)bode(H)grid on% Margins and Phases for given Frequencies% Alt 1: Use bode function directlydisp('----- Alternative 1 -----')w [0.1, 0.16, 0.25, 0.4, 0.625, 2.5, 10];[magw, phasew] bode(H, w);for i 1:length(w)mag(i) magw(1,1,i);phase(i) phasew(1,1,i);endmagdB 20*log10(mag); %convert to dBmag data [w; magdB]phase data [w; phase]MATLAB Codeclearclcw [0.1, 0.16, 0.25, 0.4, 0.625, 2.5, 10];% Alt 2: Use Mathematical expressions for H and Hdisp('----- Alternative 2 -----')gain 20*log10(4) - 20*log10(sqrt((2*w). 2 1));phase -atan(2*w);phasedeg phase * 180/pi; %convert to degreesmag data2 [w; gain]phase data2 [w; id onsubplot(2,1,2)semilogx(w,phasedeg)grid on

Transfer functionswith Time delay

Transfer functions with Time delayA general transfer function for a 1.order system with time delay is:𝐻 𝑠 𝐾𝑒 𝑇𝑠𝑇𝑠 1Frequency Response functions for gain and phase margin becomes:𝐴 πœ” 𝑑𝐡 20π‘™π‘œπ‘”(𝐾) 20π‘™π‘œπ‘” (π‘‡πœ”)2 1πœ™ πœ” π‘Žπ‘Ÿπ‘π‘‘π‘Žπ‘› π‘‡πœ” πœ” 𝜏Or πœ™ πœ” in degrees:180πœ™ πœ” [π‘‘π‘’π‘”π‘Ÿπ‘’π‘’π‘ ] arctan π‘‡πœ” πœ” πœπœ‹

Transfer functions with Time delay in MATLABDifferent ways to implement a time delay in MATLAB:Alt 1K 3.5;T 22;Tau 2;num [K];den [T, 1];H1 tf(num, den);s tf('s')H2 exp(-Tau*s);H H1 * H2bode(H)Alt 2K 3.5;T 22;Tau 2;num [K];den [T, 1];H1 tf(num, den);H set(H1,'inputdelay',Tau)bode(H);Alt 3K 3.5;T 22;Tau 2;s tf('s');H K*exp(-Tau*s)/(T*s 1)bode(H);Alt 4: Use Pade approximationK 3.5;T 22;Tau 2;num [K];den [T, 1];H1 tf(num, den);N 5;H2 pade(Tau, N)[num pade,den pade] pade(T,N)Hpade tf(num pade,den pade);H series(H1, Hpade);bode(H);

1. order system with Time delayGiven the following transfer function: 2𝑠𝐻 𝑠 3.2𝑒3𝑠 1Poles:1𝑝1 0.333Zeros:NoneThe mathematical expressions for 𝐴(πœ”) and πœ™(πœ”):𝐻(π‘—πœ”)𝑑𝐡 20π‘™π‘œπ‘”3.2 20π‘™π‘œπ‘” (3πœ”)2 1 𝐻(π‘—πœ”) 2πœ” arctan(3πœ”)Or in degrees: 𝐻 π‘—πœ” 2πœ” arctan(3πœ”) Break frequency:πœ” 1 1 0.33 π‘Ÿπ‘Žπ‘‘/𝑠𝑇 3180πœ‹

clear, clcor:clear, clcs tf('s');K 3.2;T 3;H1 tf(K/(T*s 1));delay 2;H set(H1,'inputdelay',delay)bode(H);p pole(H)z zero (H)H 3.2exp(-2*s) * ------3 s 1Continuous-time transfer function.p -0.3333z Empty matrix: 0-by-1s tf('s');K 3.2;T 3;Tau 2;num K;den [T, 1];H1 tf(num, den);s tf('s')H2 exp(-Tau*s);H H1 * H2bode(H);p pole(H)z zero (H)

https://www.halvorsen.blogFrequency response fromInput/Output SignalsHans-Petter Halvorsen

Frequency Response from sinusoidalinput and output signalsTheoryWe can find the frequency response of a systemby exciting the system (either the real system or amodel of the system) with a sinusoidal signal ofamplitude 𝐴 and frequency πœ” [π‘Ÿπ‘Žπ‘‘/𝑠] (Note:πœ” 2πœ‹π‘“) and observing the response in theoutput variable of the system.

Frequency Response - DefinitionTheory𝑦 𝑑 π‘ˆπ΄ΰΈ” 𝑠𝑖𝑛(πœ”π‘‘ πœ™)𝑒 𝑑 π‘ˆ οΏ½οΏ½ 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 sinusoidalinput 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 sinusoidalinput and output signalsThe input signal is given by:𝑒 𝑑 π‘ˆ π‘ π‘–π‘›πœ”π‘‘The steady-state output signal will then be:𝑦 𝑑 π‘ˆπ΄ΰΈ” 𝑠𝑖𝑛(πœ”π‘‘ πœ™)The gain is given by:π‘Œπ΄ π‘Œπ‘ˆThe phase lag is given by:πœ™ πœ”Ξ”π‘‘ [π‘Ÿπ‘Žπ‘‘]Theory

Frequency Response from sinusoidalinput and output signalsTheoryYou 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

SolutionsFrom the Plot we get:tCont. next page -

Solutions

Conversion to dB𝐴 𝑑𝐡 20π‘™π‘œπ‘”(𝐴)or the other way:Example:𝐴 0.68𝐴 𝑑𝐡 20π‘™π‘œπ‘”(𝐴) 20π‘™π‘œπ‘”(0.68) 3.35𝑑𝐡Or the other way:𝐴 𝑑𝐡 3.35𝑑𝐡𝐴 𝑑𝐡 3.3510 20 0.68𝐴 𝐴 𝑑𝐡10 20

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, clcK T numdenH 1;1; [K]; [T, 1];tf(num, den);figure(1)bode(H), grid on% Define input signalt [1: 0.1 : 12];w 1;U 1;u U*sin(w*t);figure(2)plot(t, u)% Output signalhold onlsim(H, ':r', u, t)grid onhold offlegend('input signal', 'output signal')We use the following transfer function:𝐻 𝑠 1𝑠 1The Frequency used:πœ” 1 rad/s

https://www.halvorsen.blogPID ControllerDesign/TuningHans-Petter Halvorsen

PID Controller DesignA 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 canuse the following Skogestad’s formulas for finding the PI(D)parameters directly.𝑇𝑐 is the time-constant of the control system whichthe user must specifyFigure: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010.Originally, Skogestad defined the factor 𝑐 4. This givesgood set-point tracking. But the disturbancecompensation may become quite sluggish. To obtainfaster disturbance compensation, you can use 𝑐 1.5

Ziegler–Nichols Frequency Response methodTheoryAssume you use a P controller only 𝑇𝑖 , 𝑇𝑑 0. Then you need to find forwhich 𝐾𝑝 the closed loop system is a marginally stable system (πœ”π‘ πœ”180 ). This 𝐾𝑝is called 𝐾𝑐 (critical gain). The 𝑇𝑐 (critical period) can be found from the dampedoscillations of the closed loop system. Then calculate the PI(D) parameters usingthe formulas below.Marginally stable system:Controllerπ‘‡π‘–π‘‡π‘‘πΎπ‘πœ”π‘ πœ”180P0.5𝐾𝑐 ��𝑐 PID0.6πΎπ‘πœ”180𝑇𝑐82𝐾𝑐 - Critical Gain𝑇𝑐 - Critical ols method

https://www.halvorsen.blogController Design/Tuningusing MATLABHans-Petter Halvorsen

Controller Design/Tuning using MATLAB Frequency Design and Analysispidtune() MATLAB functionPID Tuner (Interactive Tools).Validate with simulations!

pidtune() MATLAB functionclear, clc%Define Processnum 1;den [1,1,0];Hp tf(num,den)% Find PI Controller[Hpi,info] pidtune(Hp,'PI')%Bode Plotsfigure(1)bode(Hp)grid onfigure(2)bode(Hpi)grid on% Feedback SystemT feedback(Hpi*Hp, 1);figure(3)step(T)𝐾𝑝 0.3311𝑇𝑖 43.5𝑠𝐾𝑖 0.023

pidtune() MATLAB functionTo improve the response time, you can set a highertarget crossover frequency than the result that pidtune()automatically selects, 0.32. Increase the crossoverfrequency to 1.0.[Hpi,info] pidtune(Hp,'PI', 1.0)The new controller achieves the highercrossover frequency, but at the cost of areduced phase margin.

MATLAB PID TunerDefine Controller TypeTuningDefine yourProcessAdd AdditionalPlotsStep Response and otherPlots can be shownPID Parameters

https://www.halvorsen.blogStability Analysisusing MATLABHans-Petter Halvorsen

Stability AnalysisHow do we figure out that the Feedback Systemis stable before we test it on the real System?1. Poles2. Frequency Response/Bode3. Simulations (Step Response)We will do all these things using MATLAB

3 Time domainStability Analysis2 Frequency domainAsymptotically stable systemlim 𝑦 𝑑 π‘˜π‘‘ ally stable systemUnstable system1 The Complex domainPolesTrackingtransferfunctionFigure: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010.Asymptotically stable system: πœ”π‘ πœ”180Marginally stable system: πœ”π‘ πœ”180Unstable system: πœ”π‘ πœ”180

1 Asymptotically stable system:PolesEach of the poles of the transfer function lies strictly in theleft half plane (has strictly negative real part).3 Unstable system:2 Marginally stable system:One or more poles lies on the imaginary axis(have real part equal to zero), and all thesepoles are distinct. Besides, no poles lie in theright half plane.At least one pole lies in the right halfplane (has real part greater than zero).Or: There are multiple and coincidentpoles on the imaginary axis.1Example: double integrator 𝐻(𝑠) 𝑠2

TheoryStability AnalysisAsymptotically 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 (hasreal part greater than zero).Each of the poles of the transfer function liesstrictly in the left half plane (has strictly negativereal part).One or more poles lies on the imaginary axis (havereal part equal to zero), and all these poles aredistinct. Besides, no poles lie in the right half plane.Or: There are multiple and coincident poleson the imaginary axis. Example: double1integrator 𝐻(𝑠) 2𝑠

https://www.halvorsen.blogStability Analysis ofFeedback SystemsHans-Petter Halvorsen

Stability Analysis ofFeedback Systems1Loop Transfer Function(β€œSlΓΈyfetransferfunksjonen”):Hr .Hp .Hm .L series(series(Hr, Hp), Hm)2The Tracking Function (β€œFΓΈlgeforholdet”):L .T feedback(L, 1)3The Sensitivity Function (β€œSensitivitetsfunksjonen”):T .S 1-TTheory

Frequency Response and Stability AnalysisBode DiagramTheoryπœ”π‘ 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 becomesunstableπœ™ is the phase margin (PM) of the system (β€œFasemargin”).How much phase shift the system can tolerate before it becomesunstable.Asymptotically stable system: πœ”π‘ πœ”180Marginally stable system: πœ”π‘ πœ”180Unstable system: πœ”π‘ πœ”180

Frequency Response and Stability AnalysisTheoryThe definitions are as follows:Gain Crossover-frequency - πœ”π‘ :𝐿 π‘—πœ”π‘πœ”180 is the gain margin frequency, inradians/second. A gain margin frequency indicateswhere the model phase crosses -180 degrees. 1 0𝑑𝐡Phase Crossover-frequency - πœ”180 : 𝐿 π‘—πœ”180 πœ”π‘ is phase margin frequency, in radians/second. Aphase margin frequency indicates where themodel magnitude crosses 0 decibels. 180π‘œGain Margin - GM (π›₯𝐾):𝐺𝑀 𝑑𝐡 𝐿 π‘—πœ”180GM (Δ𝐾) is the gain margin of the system.PM (πœ‘) is the phase margin of the system.𝑑𝐡Phase margin PM (πœ‘):𝑃𝑀 180π‘œ 𝐿(π‘—πœ”π‘ )We have that:1. Asymptotically stable system: πœ”π‘ πœ”1802. Marginally stable system: πœ”π‘ πœ”1803. Unstable system: πœ”π‘ πœ”180

https://www.halvorsen.blogStability Analysis ofFeedback System - ExampleHans-Petter Halvorsen

ExampleWe will use the following system as an example:1𝐻𝑝 𝑠(𝑠 1)𝐻𝑐 πΎπ‘π‘Ÿπ‘’ Controller𝑒Sensors1π»π‘š 3𝑠 1𝑦Process

Analysis of the Feedback SystemLoop 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 stabilitymargins GM (𝐴(πœ”)), PM (πœ™(πœ”)) of the system (𝐿(𝑠)) fromthe Bode plot. Plot also Bode diagram where the crossover-frequencies,GM and PM are illustrated. Tip! Use the margin() functionin 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 systembecomes unstable?

MATLAB Code:clear, clc, clfbode(L)% The Process Transfer function Hp(s)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 functionL series(series(Hr, Hp), Hm)% Bode Diagramfigure(1)bode(L),grid onfigure(2)margin(L)[gm, pm, w180, wc] margin(L);wcw180gmgmdB 20*log10(gm)pmwcw180gmgmdBpm 0.2649 rad/s0.5774 rad/s3.809511.6174 dB36.6917 degrees

From the Bode plot we can get: 𝐾 11.6 π‘‘π΅πœ”π‘ 0.26πœ™ 37 0.10.30.2πœ”180 0.5810.510

Stable vs. Unstable System We will find and use different values of 𝐾𝑝 where we get a marginallystable 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 stepresponse to determine the stability of the system? We will find πœ”180 , πœ”π‘ , 𝐴 πœ” and πœ™(πœ”) in all 3 cases. We will see howwe 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 3categories mentioned above. We will see how we can we use the polesto determine the stability of the system. Bandwidth: We will plot the Loop transfer function 𝐿(𝑠), the Trackingtransfer function 𝑇(𝑠) and the Sensitivity transfer function 𝑆(𝑠) in aBode diagram for the system for all the 3 categories mentioned above.

Stable System𝐾𝑝 0.35For what 𝐾𝑝 becomes the system marginally stable?πΎπ‘π‘š 0.35 Δ𝐾 0.35 3.8 1,32πœ”π‘ πœ”180wcw180gmgmdBpmlim 𝑦 𝑑 1𝑑 0.2649 rad/s0.5774 rad/s3.809511.6174 dB36.6917 degreesPoles in the left half plane

Marginally Stable System𝐾𝑝 1.32πœ”π‘ πœ”1800 lim 𝑦 𝑑 𝑑 wcw180gmgmdBpm oles at the imaginary axis

Unstable System𝐾𝑝 2πœ”π‘ πœ”180lim 𝑦 𝑑 𝑑 wcw180gmgmdBpm 0.7020 0.5774 0.6667 -3.5218 -9.6664Poles in the right half plane

MATLAB Codeclear, clc, clf% The Process Transfer function Hp(s)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)% The Controller Transfer function Hr(s)Kp 0.35; % Stable System%Kp 1.32; % Marginally Stable System%Kp 2; % Unstable SystemHr tf(Kp)% The Loop Transfer functionL series(series(Hr, Hp), Hm)% Tracking transfer functionT feedback(L,1);% Sensitivity transfer functionS 1-T;.% Bode Diagramfigure(1)bode(L), grid onfigure(2)margin(L), grid on[gm, pm, w180, wc] margin(L);wcw180gmgmdB 20*log10(gm)pm% Simulating step response for control system(tracking transfer function)figure(3)step(T)% Polespole(T)figure(4)pzmap(T)% Bandwidthfigure(5)bodemag(L,T,S), grid on

β€œGolden rules” of Stability Marginsfor a Control SystemTheoryReference: F. Haugen, Advanced Dynamics and Control: TechTeach, 2010.Gain Margin (GM): (Norwegian: β€œForsterkningsmargin”)Phase Margin (PM): (Norwegian: β€œFasemargin”)

https://www.halvorsen.blogThe Bandwidth ofthe Control SystemHans-Petter Halvorsen

The Bandwidth of the Control System𝐿𝑇𝑆 You should plot the Loop transfer function𝐿(𝑠), the Tracking transfer function 𝑇(𝑠)and the Sensitivity transfer function 𝑆(𝑠) inthe same Bode diagram. Use, e.g., the bodemag() function inMATLAB (only the gain diagram is ofinterest in this case, not the phasediagram). Use the values for 𝐾𝑝 and 𝑇𝑖 found in aprevious Tasks. You need to find the different bandwidthsπŽπ’• , πŽπ’„ , πŽπ’” (see the sketch below).

The Bandwidth of the Control SystemTheoryThe bandwidth of a control system is the frequency which divides the frequencyrange of good tracking and poor tracking.3 different Bandwidth Good Set-point Tracking: 𝑆(π‘—πœ”) 1, 𝑇 (π‘—πœ”) 1, 𝐿(π‘—πœ”) 1

𝐾𝑝 0.35Good Set-point Tracking: 𝑆(π‘—πœ”) 1, 𝑇 (π‘—πœ”) 1, 𝐿(π‘—πœ”) 1πΏπ‘‡π‘†πœ”π‘  0.0920.050.1πœ”π‘ 0.270.20.3πœ”π‘‘ 0.461

https://www.halvorsen.blogPI ControllerExampleHans-Petter Halvorsen

PI Controller - ExampleWe will use the following system as an example:𝐾𝑝 (𝑇𝑖 𝑠 1)𝐻𝑐 𝑇𝑖 π‘ π‘Ÿπ‘’ Controller𝑒Sensors1π»π‘š 3𝑠 11𝐻𝑝 𝑠(𝑠 1)Process𝑦

Ziegler–Nichols Frequency Response methodTheoryAssume you use a P controller only 𝑇𝑖 , 𝑇𝑑 0. Then you need to find forwhich 𝐾𝑝 the closed loop system is a marginally stable system (πœ”π‘ πœ”180 ). This 𝐾𝑝is called 𝐾𝑐 (critical gain). The 𝑇𝑐 (critical period) can be found from the dampedoscillations of the closed loop system. Then calculate the PI(D) parameters usingthe formulas below.Marginally stable system:Controllerπ‘‡π‘–π‘‡π‘‘πΎπ‘πœ”π‘ πœ”180P0.5𝐾𝑐 ��𝑐 PID0.6πΎπ‘πœ”180𝑇𝑐82𝐾𝑐 - Critical Gain𝑇𝑐 - Critical ols method

PI Controller using Ziegler–NicholsZiegler–Nichols (PI Controller):𝐾𝑝 0.45𝐾𝑐𝑇𝑐𝑇𝑖 1.2From previous Simulations:𝐾𝑐 1.322πœ‹2πœ‹π‘‡π‘ πœ”180 0.58This gives the following PI Parameters:𝐾𝑝 0.45𝐾𝑐 0.45 1.32 0.62πœ‹π‘‡π‘π‘‡π‘– 0.58 9𝑠1.21.2

Skogestad’s method The Skogestad’s method assumes you apply a step on the input (𝑒) and thenobserve 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 thefollowing 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 specifyWe set, e.g., 𝑇𝐢 5 𝑠 and 𝑐 1.5:𝐾𝑝 111 0.2𝐾(𝑇𝑐 𝜏) 1(10 0) 5𝐾 1, 𝑇 1, 𝜏 0𝑇𝑖 𝑐 𝑇𝑐 𝜏 1.5 5 0 7.5𝑠

MATLABZiegler–Nichols and Skogestad’s Formulas:% Ziegler-Nicols MethodKc 1.32; % Critical GainTc 2*pi/w180; % Tc - Critical PeriodKp 0.45 * KcTi Tc/1.2% Skogestad's MethodTc 5; % time-constant of

Frequency Response –MATLAB clear clc close all % Define Transfer function num [1]; den [1, 1]; H tf(num, den) % Frequency Response bode(H); grid on The frequency response is an important tool for analysis and design of signal filters and for analysis and design of control