Exercise 9: Frequency Response Analysis (Solutions)

advertisement
EE4107 -­โ€ Cybernetics Advanced Exercise 9: Frequency Response Analysis (Solutions) The Gain Margin, GM (Δ๐พ), the Phase Margin, PM (๐œ‘) and the cross-­โ€over frequencies, ๐œ”! and ๐œ”!"# are found in a Bode diagram as illustrated below: ๐Ž๐Ÿ๐Ÿ–๐ŸŽ is the gain margin frequency, in radians/second. A gain margin frequency indicates where the model phase crosses -­โ€180 degrees. GM (Δ๐พ) is the gain margin of the system. ๐Ž๐’„ is phase margin frequency, in radians/second. A phase margin frequency indicates where the model magnitude crosses 0 decibels. PM (๐œ‘) is the phase margin of the system. Note! ๐Ž๐Ÿ๐Ÿ–๐ŸŽ and ๐Ž๐’„ are called the crossover-­โ€frequencies The definitions are as follows: Gain Crossover-­โ€frequency -­โ€ ๐Ž๐’„ : ๐ฟ ๐‘—๐œ”!
= 1 = 0๐‘‘๐ต Phase Crossover-­โ€frequency -­โ€ ๐Ž๐Ÿ๐Ÿ–๐ŸŽ : ∠๐ฟ ๐‘—๐œ”!"# = −180! Gain Margin -­โ€ GM (๐šซ๐‘ฒ): ๐บ๐‘€ ๐‘‘๐ต = − ๐ฟ ๐‘—๐œ”!"# ๐‘‘๐ต Phase margin PM (๐‹): Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
2 ๐‘ƒ๐‘€ = 180! + ∠๐ฟ(๐‘—๐œ”! ) We have that: 1. Asymptotically stable system: ๐Ž๐’„ < ๐Ž๐Ÿ๐Ÿ–๐ŸŽ 2. Marginally stable system: ๐Ž๐’„ = ๐Ž๐Ÿ๐Ÿ–๐ŸŽ 3. Unstable system: ๐Ž๐’„ > ๐Ž๐Ÿ๐Ÿ–๐ŸŽ MathScript has several built-­โ€in functions for Frequency response, e.g.: Function tf bode bodemag semilogx log10 atan series feedback bode bodemag margin Description Example Creates system model in transfer function form. You also can use this function to state-­โ€space models to transfer function form. Creates the Bode magnitude and Bode phase plots of a system model. You also can use this function to return the magnitude and phase values of a model at frequencies you specify. If you do not specify an output, this function creates a plot. Creates the Bode magnitude plot of a system model. If you do not specify an output, this function creates a plot. Generates a plot with a logarithmic x-­โ€scale. >num=[1];
>den=[1, 1, 1];
>H = tf(num, den)
>num=[4];
>den=[2, 1];
>H = tf(num, den)
>bode(H)
>[mag, wout]
>[mag, wout]
[wmin wmax])
>[mag, wout]
wlist)
>semilogx(w,
= bodemag(SysIn)
= bodemag(SysIn,
= bodemag(SysIn,
gain)
Computes the base 10 logarithm of the input elements. The base 10 logarithm of zero is -­โ€inf. Computes the arctangent of x >log(x)
Connects two system models in series to produce a model SysSer with input and output connections you specify Connects two system models together to produce a closed-­โ€loop model using negative or positive feedback connections Creates the Bode magnitude and Bode phase plots of a system model. You also can use this function to return the magnitude and phase values of a model at frequencies you specify. If you do not specify an output, this function creates a plot. Creates the Bode magnitude plot of a system model. If you do not specify an output, this function creates a plot. >Hseries = series(H1,H2)
Calculates and/or plots the smallest gain and phase margins of a single-­โ€input single-­โ€output (SISO) system model. The gain margin indicates where the frequency response crosses at 0 decibels. The phase margin indicates where the frequency response crosses -­โ€180 degrees. Use the margins function to return all gain and phase margins of a SISO model. >atan(x)
>SysClosed = feedback(SysIn_1,
SysIn_2)
>num=[4];
>den=[2, 1];
>H = tf(num, den)
>bode(H)
>[mag, wout] = bodemag(SysIn)
>[mag, wout] = bodemag(SysIn,
[wmin wmax])
>[mag, wout] = bodemag(SysIn,
wlist)
>num = [1]
>den = [1, 5, 6]
>H = tf(num, den)
margin(H)
>[gmf, gm, pmf, pm] = margin(H)
Task 1: Stability Analysis Given the following transfer function: ๐ฟ ๐‘† =
1
๐‘  ๐‘ +1 !
Task 1.1 Use the standard bode function in MathScript to plot the frequency response in a Bode diagram. EE4107 -­โ€ Cybernetics Advanced 3 Find the following: •
•
•
The crossover-­โ€frequencies ๐œ”! and ๐œ”!"# The gain margin, GM (Δ๐พ) The phase margin, PM (๐œ‘) Print out the Bode diagram and illustrate how you find ๐œ”! , ๐œ”!"# Δ๐พ, ๐œ‘ from the diagram Solutions: MathScript Code for creating Bode diagram: clear
clc
% Transfer unction
num=[1];
den1=[1,0];
den2=[1,1]
den3=[1,1]
den = conv(den1,conv(den2,den3));
H = tf(num, den)
% Bode Diagram
bode(H)
subplot(2,1,1)
grid on
subplot(2,1,2)
grid on
Note! In order to define the denominator (๐‘  ๐‘  + 1 ! ), we can use the conv function as shown above, or we can manually calculate: ๐‘  ๐‘ +1
!
= ๐‘  ! + 2๐‘  ! + ๐‘  and use like this: den=[1,2,1,0]
Since we are going to find ๐œ”! , ๐œ”!"# , Δ๐พ and ๐œ‘ from the plot, it is a good idea to rescale the ๐‘ฅ and ๐‘ฆ axes: bode(H)
subplot(2,1,1)
grid on
axis([0.1, 10, -40, 50])
subplot(2,1,2)
grid on
axis([0.1, 10, -200, -100])
EE4107 -­โ€ Cybernetics Advanced 4 Note! You can also do this manually by clicking on the ๐‘ฅ and ๐‘ฆ axes on the plot. From the graph above we find the following (an image editor is used to draw on the chart): So the results are as follows: ๐œ”! ≈ 0.7 ๐œ”!"# ≈ 1 ๐บ๐‘€ ≈ 6 ๐‘‘๐ต ๐‘ƒ๐‘€ ≈ 20° Task 1.2 Now you shall use the margin function in MathScript instead. Example: margin(H);
→ Here you will plot a Bode diagram where ๐œ”! , ๐œ”!"# Δ๐พ, ๐œ‘ will be illustrated and: [gm, pm, w180, wc] = margin(H);
→ Here you will get the numerical values for ๐œ”! , ๐œ”!"# Δ๐พ, ๐œ‘ . EE4107 -­โ€ Cybernetics Advanced 5 Compare your results with the previous subtask. Solutions: We use margin in 2 different ways: …
margin(H)
[gm, pm, w180, wc] = margin(H);
Note! Using “help margin” in MathScript does not give the correct information about the return parameters return by the margin function!! The correct is: [gm, pm, w180, wc] = margin(H);
Using margin(H) makes the gm, fm, gmf and pmf automatically plotted in the Bode diagram: Using [gm, pm, w180, wc] = margin(H) gives numerical values: wc =
0.6823
w180 =
0.9993
gm_dB =
EE4107 -­โ€ Cybernetics Advanced 6 6.0086
pm =
21.3864
Note! gm has to be converted to dB. gm_dB = 20*log10(gm)
Summarizing, the results are as follows: ๐Ž๐’„ = ๐ŸŽ. ๐Ÿ”๐Ÿ– ๐Ž๐Ÿ๐Ÿ–๐ŸŽ = ๐Ÿ ๐‘ฎ๐‘ด = ๐Ÿ” ๐’…๐‘ฉ ๐‘ท๐‘ด = ๐Ÿ๐Ÿ° Note! We see that the system is an asymptotically stable system because ๐Ž๐’„ < ๐Ž๐Ÿ๐Ÿ–๐ŸŽ Task 1.3 Find the poles for the system. Draw the poles in the imaginary plane. Is the system stable? Discuss the results. Solutions: Poles: ๐‘! = 0, ๐‘! = ๐‘! = −1 In the imaginary plane: MathScript code: …
poles(H)
EE4107 -­โ€ Cybernetics Advanced 7 pzmap(H)
Note! We see from the poles as well that the system is an asymptotically stable system. Total MathScript Code for Task 1.1-­โ€1.3: 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)
poles(H)
figure(1)
pzmap(H)
% Bode Plot
figure(2)
bode(H)
subplot(2,1,1)
grid on
subplot(2,1,2)
grid on
% Margins and Phases
wlist=[0.01, 0.1, 0.2, 0.5, 1, 10, 100];
[mag, phase,w] = bode(H, wlist);
magdB=20*log10(mag); %convert to dB
% [mag, phase,w] = bode(H);
mag_data = [w, magdB]
phase_data = [w, phase]
% Crossover Frequency------------------------------------figure(3)
margin(H)
[gm, pm, w180, wc] = margin(H);
wc
EE4107 -­โ€ Cybernetics Advanced 8 w180
% Convert to dB.
gm_dB = 20*log10(gm)
pm
Task 2: Stability Analysis with time-­โ€delay Given the following system with time-­โ€delay: 2.5๐‘’ !!
๐ฟ ๐‘  =
3๐‘  + 1
Task 2.1 Use the standard bode function in MathScript to plot the frequency response in a Bode diagram. Find the following: •
•
•
The crossover-­โ€frequencies ๐œ”! and ๐œ”!"# The gain margin, GM (Δ๐พ) The phase margin, PM (๐œ‘) Print out the Bode diagram and illustrate how you find ๐œ”! , ๐œ”!"# Δ๐พ, ๐œ‘ from the diagram Task 2.2 Now you shall use the margin function in MathScript instead. Compare your results with the previous subtask. Task 2.3 Find the poles for the system. Draw the poles in the imaginary plane. Is the system stable? Discuss the results. Solutions for Task 2.1-­โ€2.3: MathScript Code: clear, clc
s=tf('s');
K=2.5;
T=3;
H1=tf(K/(T*s+1));
delay=1;
H=set(H1,'inputdelay',delay);
EE4107 -­โ€ Cybernetics Advanced 9 bode(H);
subplot(2,1,1)
grid on
subplot(2,1,2)
grid on
margin(H)
[gm, pm, w180, wc] = margin(H);
wc
w180
% Convert to dB.
gm_dB = 20*log10(gm)
pm
Ordinary Bode Plot using the bode function (I have manually adjusted the scaling): → We have to find GM, PM, wc and w180 manually from the plot. We can use the margin function (gm, fm, gmf and pmf are automatically plotted in the Bode chart) as well: EE4107 -­โ€ Cybernetics Advanced 10 Using [gm, pm, w180, wc] = margin(H);
gives: wc =
0.7638
w180 =
1.756
gm_dB =
6.6279
pm =
69.8178
Note! gm has to be converted to dB. gm_dB = 20*log10(gm)
So the results are as follows: ๐Ž๐’„ = ๐ŸŽ. ๐Ÿ•๐Ÿ” ๐Ž๐Ÿ๐Ÿ–๐ŸŽ = ๐Ÿ. ๐Ÿ•๐Ÿ” ๐‘ฎ๐‘ด = ๐Ÿ”. ๐Ÿ” ๐’…๐‘ฉ ๐‘ท๐‘ด = ๐Ÿ•๐ŸŽ° EE4107 -­โ€ Cybernetics Advanced 11 We see that the system is an asymptotically stable system because ๐Ž๐’„ < ๐Ž๐Ÿ๐Ÿ–๐ŸŽ Task 3: Control System Given the following system: Process transfer function: ๐ป! =
Where ๐พ =
!!
!"
๐พ !!"
๐‘’
๐‘ 
, where ๐พ! = 0,556, ๐ด = 13,4, ๐œš = 145 and ๐œ = 250 Measurement (sensor) transfer function: ๐ป! = ๐พ! Where Km = 1 %/m. Controller transfer function (PI Controller): ๐ป! = ๐พ! +
๐พ!
๐‘‡! ๐‘ 
Set ๐พ๐‘ = 1.5 og ๐‘‡๐‘– = 1000๐‘ . Task 3.1 Define the different transfer functions in MathScript. ๐ป! ๐ป! ๐ป! Solutions: We define the different transfer functions. There are multiple ways to define the different transfer functions, and we will show some alternative solutions. The tricky part is the time delay ๐‘’ !!" in the process transfer function. Here we can use different approaches and different functions. We can use the built-­โ€in sys_order1, we can use the built-­โ€in pade function or create our own Pade’ approximation (e.g. a 1.order or 2.order approximation). Method1: Here we use combinations of functions tf and sys_order1. EE4107 -­โ€ Cybernetics Advanced 12 clear
clc
close all
% Model parameters:
Ks=0.556; %(kg/s)/%
A=13.4; %m2
rho=145; %kg/m3
transportdelay=250; %sec
%Defining the process transfer function:
K=Ks/(rho*A);
num1 = [K];
den1 = [1, 0];
H1 = tf(num1, den1);
H2 = sys_order1(1, 0, transportdelay);
disp('Process:')
Hp = series(H1, H2)
% Defining sensor transfer function:
Km=1; %percent per meter
disp('Sensor:')
Hs=tf(Km)
% Defining controller transfer function:
Kp=1.5;
Ti=1000;
num = Kp*[Ti, 1];
den = [Ti, 0];
disp('Controller:')
Hc = tf(num,den)
Note! ๐ป! = ๐พ! +
๐พ! ๐พ! ๐‘‡! ๐‘  + ๐พ! ๐พ! (๐‘‡! ๐‘  + 1)
=
=
๐‘‡! ๐‘ 
๐‘‡! ๐‘ 
๐‘‡! ๐‘ 
We can also use the pade function in order to create a Pade’approximation: n=5; % Order of Pade approximation
H2 = pade(transportdelay, n)
Or we can create our own Pade approximation and then use the tf function: % 2.order approx. using tf
k1=transportdelay/2;
k2=transportdelay^2/12;
num=[k2, -k1, 1];
EE4107 -­โ€ Cybernetics Advanced 13 den=[k2, k1, 1];
H2=tf(num, den)
For a 2.order Pade’ approximation (๐’ = ๐Ÿ) we get the following transfer function: We get: ๐‘’ !!" ≈
1 − ๐‘˜! ๐‘  + ๐‘˜! ๐‘  !
1 + ๐‘˜! ๐‘  + ๐‘˜! ๐‘  !
Where: ๐œ
๐‘˜! = 2
๐‘˜! =
๐œ!
12
Method 2: This is a new method we haven’t used before. We define s as the Laplace operator and then we can use s directly in our equations. clear
clc
close all
s=tf('s');
%Model parameters:
Ks=0.556; %(kg/s)/%
A=13.4; %m2
rho=145; %kg/m3
transportdelay=250; %sec
%Defining the process transfer function:
K=Ks/(rho*A);
padeorder=5; %Order of Pade-approximation of time-delay. Order 5 is
usually ok.
Hp1=set(tf(K/s),'inputdelay',transportdelay);%Including
transportdelay in process transfer function
Hp=pade(Hp1,padeorder);%Deriving process transfer function incl.
Pade-approx of time-delay
%Defining sensor transfer function:
Km=1; Hs=tf(Km); %Defining sensor transfer function (just a gain in
this example)
%Defining controller transfer function:
Kp=1.5; Ti=1000;
Hc=Kp+Kp/(Ti*s); %PI controller transfer function
Task 3.2 EE4107 -­โ€ Cybernetics Advanced 14 Set up the mathematical expression and define the Loop transfer function ๐‘ณ(๐’”). Tip! Use the built-­โ€in function series in Mathscript. Set up the mathematical expression and define the Sensitivity transfer function ๐‘บ(๐’”) Tip! Use the built-­โ€in function feedback in Mathscript. Set up the mathematical expression and define the Tracking transfer function ๐‘ป(๐’”) Solutions: Control system: Defining ๐ฟ (๐‘ ): ๐ฟ ๐‘  = ๐ป! ๐ป! ๐ป! We get the following compact system: MathScript Code: EE4107 -­โ€ Cybernetics Advanced 15 % Calculating loop tranfer function
L=series(Hc,series(Hp,Hs));
%Calculating tracking transfer function
T=feedback(L,1);
% Calculating sensitivity transfer function
S=1-T;
Task 3.3 Plot the Loop transfer function ๐ฟ (๐‘ ), the Tracking transfer function ๐‘‡ (๐‘ ) and the Sensitivity transfer function ๐‘†(๐‘ ) in a Bode diagram. Use, e.g., the bodemag function in MathScript. Discuss the results. Solutions: Code: % Bode Diagram
figure(1)
bodemag(L,T,S)
grid
Bode diagram: Task 3.4 Based on the Bode diagram of ๐ฟ (๐‘ ), ๐‘‡ (๐‘ ) ๐‘†(๐‘ ), find the different bandwidths ๐œ”! , ๐œ”! , ๐œ”! (see the sketch below). EE4107 -­โ€ Cybernetics Advanced 16 Where we have the following definitions: ๐Ž๐’„ – crossover-­โ€frequency – the frequency where the gain of the Loop transfer function ๐ฟ (๐‘—๐œ”) has the value: 1 = 0๐‘‘๐ต ๐Ž๐’• – the frequency where the gain of the Tracking function ๐‘‡ (๐‘—๐œ”) has the value: 1
≈ 0.71 = −3๐‘‘๐ต 2
๐Ž๐’” -­โ€ the frequency where the gain of the Sensitivity transfer function ๐‘†(๐‘—๐œ”) has the value: 1−
1
2
≈ 0.29 = −11๐‘‘๐ต Discuss the results. Solutions: Values for ๐œ”! , ๐œ”! , ๐œ”! can be found in the plot as shown below (We change the scaling for more details): EE4107 -­โ€ Cybernetics Advanced 17 We get the following values: ๐Ž๐’„ = ๐ŸŽ. ๐ŸŽ๐ŸŽ๐ŸŽ๐Ÿ•๐Ÿ‘ ๐’“๐’‚๐’…/๐’” ๐Ž๐’” = ๐ŸŽ. ๐ŸŽ๐ŸŽ๐ŸŽ๐Ÿ‘๐Ÿ ๐’“๐’‚๐’…/๐’” ๐Ž๐’• = ๐ŸŽ. ๐ŸŽ๐ŸŽ๐Ÿ๐Ÿ ๐’“๐’‚๐’…/๐’” Task 3.5 Plot the step response for the Tracking transfer function ๐‘‡ (๐‘ ) Discuss the results. Solutions: MathScript Code: % Simulating step response for control system (tracking transfer
function)
figure(2)
step(T)
grid
Plot: EE4107 -­โ€ Cybernetics Advanced 18 We see that the system is asymptotically stable. Task 3.6 Find the stability margins (GM, PM) of the system (๐ฟ(๐‘ )). Discuss the results. Solutions: MathScript Code: % Calcutating stability margins and crossover frequencies:
[gm, pm, w180, wc] = margin(L)
% Plotting L and stability margins and crossover frequencies in Bode
diagram
figure(3)
margin(L)
grid
This gives: EE4107 -­โ€ Cybernetics Advanced 19 Shown in the Output Window of Mathscript: GM=12.764, and PM = 25.645 deg. ๐œ”! < ๐œ”!"# → The system is asymptotically stable GM is ok, but PM somewhat too small (should have been at least 30 deg). May try to increase ๐‘‡! to e.g. 1200s. Decreasing ๐พ! does not help (normally it does, but it can be shown that for this system, containing two integrators in series (PI controller and process), reducing gain may actually reduce stability (normally the stability is increased if gain is reduced). Below we see the complete code for the Task: clear
clc
close all
EE4107 -­โ€ Cybernetics Advanced 20 % Model parameters:
Ks=0.556; %(kg/s)/%
A=13.4; %m2
rho=145; %kg/m3
transportdelay=250; %sec
%Defining the process transfer function:
K=Ks/(rho*A);
num1 = [K];
den1 = [1, 0];
H1 = tf(num1, den1);
H2 = sys_order1(1, 0, transportdelay);
disp('Process:')
Hp = series(H1, H2)
% Defining sensor transfer function:
Km=1; %percent per meter
disp('Sensor:')
Hs=tf(Km)
% Defining controller transfer function:
Kp=1.5;
Ti=1000;
num = Kp*[Ti, 1];
den = [Ti, 0];
disp('Controller:')
Hc = tf(num,den)
% Calculating loop tranfer function
L=series(Hc,series(Hp,Hs));
%Calculating tracking transfer function
T=feedback(L,1);
% Calculating sensitivity transfer function
S=1-T;
% Bode Diagram
figure(1)
bodemag(L,T,S)
grid
% Simulating step response for control system (tracking transfer
function)
figure(2)
EE4107 -­โ€ Cybernetics Advanced 21 step(T)
grid
% Calcutating stability margins and crossover frequencies:
[gm, pm, w180, wc] = margin(L)
% Plotting L and stability margins and crossover frequencies in Bode
diagram
figure(3)
margin(L)
grid
Additional Resources •
http://home.hit.no/~hansha/?lab=mathscript
Here you will find tutorials, additional exercises, etc.
EE4107 -­โ€ Cybernetics Advanced 
Download