Control Theory with MathScript Exampleshome.hit.no/~hansha/documents/control/Documents/Lecture...
Transcript of Control Theory with MathScript Exampleshome.hit.no/~hansha/documents/control/Documents/Lecture...
UniversityCollegeofSoutheastNorway
http://home.hit.no/~hansha
ControlTheorywithMathScriptExamples
Hans-PetterHalvorsen,2016.10.26
ii
TableofContentsTableofContents....................................................................................................................................ii
1 Introduction....................................................................................................................................1
1.1 MathScript...............................................................................................................................1
2 MathScriptBasics...........................................................................................................................2
2.1 Introduction.............................................................................................................................2
2.2 HowdoyoustartusingMathScript?.......................................................................................2
2.3 BasicOperations......................................................................................................................3
2.4 VectorsandMatrices..............................................................................................................4
2.5 LinearAlgebra.........................................................................................................................7
2.6 Plotting....................................................................................................................................8
2.6.1 Subplots...........................................................................................................................9
2.7 User-DefinedFunctionsinMathScript..................................................................................12
2.8 Scripts....................................................................................................................................12
2.9 FlowControl..........................................................................................................................15
2.10 ControlDesigninMathScript................................................................................................15
3 TransferFunctions........................................................................................................................17
3.1 Introduction...........................................................................................................................17
3.1.1 1.ordersystem...............................................................................................................17
3.1.2 1.ordersystemwithtime-delay....................................................................................18
3.1.3 2.ordersystem...............................................................................................................18
3.2 MathScript.............................................................................................................................19
3.3 FirstorderTransferFunction.................................................................................................21
3.3.1 1.ordersystemwithtime-delay....................................................................................23
iii TableofContents
Control Theory with MathScript Examples
3.4 SecondorderTransferFunction............................................................................................25
3.5 Simulation.............................................................................................................................26
3.6 BlockDiagrams......................................................................................................................26
3.7 AnalysisofStandardFunctions..............................................................................................27
3.7.1 Integrator......................................................................................................................28
3.7.2 1.ordersystem..............................................................................................................30
3.7.3 2.ordersystem..............................................................................................................33
4 State-spaceModels......................................................................................................................35
4.1 Introduction...........................................................................................................................35
4.2 MathScript.............................................................................................................................36
5 Time-delayandPade’-approximations.........................................................................................39
5.1 Introduction...........................................................................................................................39
5.2 MathScript.............................................................................................................................40
6 StabilityAnalysis...........................................................................................................................45
6.1 Introduction...........................................................................................................................45
6.2 Poles......................................................................................................................................46
6.3 FeedbackSystems.................................................................................................................49
6.3.1 LoopTransferfunction..................................................................................................49
6.3.2 Trackingtransferfunction.............................................................................................50
6.3.3 Sensitivitytransferfunction..........................................................................................50
6.3.4 CharacteristicPolynomial..............................................................................................50
7 FrequencyResponse.....................................................................................................................52
7.1 Introduction...........................................................................................................................52
7.2 MathScript.............................................................................................................................53
7.3 Examples...............................................................................................................................54
7.4 StandardTransferfunctions..................................................................................................61
7.4.1 Amplifier(Norwegian:“Forsterker”):............................................................................61
iv TableofContents
Control Theory with MathScript Examples
7.4.2 Integrator......................................................................................................................62
7.4.3 Derivator........................................................................................................................63
7.4.4 1.Ordersystem.............................................................................................................64
7.4.5 2.Ordersystem.............................................................................................................65
7.4.6 Zeropart(Norwegian:“Nullpunktsledd”).....................................................................66
7.4.7 Timedelay(Norwegian:“Tidsforsinkelse”)...................................................................66
8 FrequencyresponseAnalysis........................................................................................................68
8.1 Introduction...........................................................................................................................68
8.2 MathScript.............................................................................................................................70
9 StabilityAnalysisintheFrequencyDomain..................................................................................74
9.1 Introduction...........................................................................................................................74
9.2 MathScript.............................................................................................................................75
AppendixA–MathScriptFunctions......................................................................................................80
BasicFunctions.................................................................................................................................80
BasicPlottingFunctions....................................................................................................................80
FunctionsusedforControlandSimulation......................................................................................81
1
1 IntroductionThisdocumentpresentssomecontroltheoryandlotsofexamplesofhowyoumayimplementitinMathScript.
Thisdocumentgivesanintroductiontothefollowingtopics:
• TransferFunctionsandBlockDiagrams• State-SpaceModels• Time-delayandPade’approximations• FrequencyResponse• FrequencyResponseAnalysis• StabilityAnalysis
MathScripthaslotsofbuilt-infunctionalityfortheseapplications.Ineachchapterwewillgiveashortoverviewtothetheorybehind,beforewedigintotheMathScriptExamples.SinceMathScriptisalmostidenticaltoMATLAB,youcanuseMATLABinsteadinmostoftheexamplesshown.
1.1 MathScriptMathScriptisahigh-level,text-basedprogramminglanguage.MathScriptincludesmorethan800built-infunctionsandthesyntaxissimilartoMATLAB.Youmayalsocreatecustom-madem-filelikeyoudoinMATLAB.
MathScriptiswellsuitedforpracticalimplementationsofcontroltheory.
MathScript(LabVIEWMathScriptRTModule)isanadd-onmoduletoLabVIEWbutyoudon’tneedtoknowLabVIEWprogramminginordertouseMathScript,becauseMathScriptisatext-basedlanguagesimilartoMATLAB.
FormoreinformationaboutMathScript,pleasereadtheTutorial“LabVIEWMathScript”(http://home.hit.no/~hansha/?tutorial=mathscript).
Additionalexercisesaregiveninthecourse“SoYouThinkYouCanMathScript”(http://home.hit.no/~hansha/?lab=mathscript).
2
2 MathScriptBasics
2.1 IntroductionMathScriptisahigh-level,text-basedprogramminglanguage.MathScriptincludesmorethan800built-infunctionsandthesyntaxissimilartoMATLAB.Youmayalsocreatecustom-madem-filelikeyoudoinMATLAB.
MathScriptisanadd-onmoduletoLabVIEWbutyoudon’tneedtoknowLabVIEWprogramminginordertouseMathScript.
FormoreinformationaboutMathScript,pleasereadtheTutorial“LabVIEWMathScript”.
2.2 HowdoyoustartusingMathScript? YouneedtoinstallLabVIEWandtheLabVIEWMathScriptRTModule.Whennecessarysoftwareisinstalled,startMathScriptbyopenLabVIEW:
3 MathScriptBasics
Control Theory with MathScript Examples
IntheGettingStartedwindow,selectTools->MathScriptWindow...:
2.3 BasicOperationsVariables:
Variablesaredefinedwiththeassignmentoperator,“=”.MathScriptisdynamicallytyped,meaningthatvariablescanbeassignedwithoutdeclaringtheirtype,andthattheirtypecanchange.Valuescancomefromconstants,fromcomputationinvolvingvaluesofothervariables,orfromtheoutputofafunction.
Example:
4 MathScriptBasics
Control Theory with MathScript Examples
>> x = 17 x = 17 >> x = 'hat' x = hat >> x = [3*4, pi/2] x = 12.0000 1.5708 >> y = 3*sin(x) y = -1.6097 3.0000
[EndofExample]
Note!MathScriptiscasesensitive!ThevariablesxandXarenotthesame.
Note!Unlikemanyotherlanguages,wherethesemicolonisusedtoterminatecommands,inMathScriptthesemicolonservestosuppresstheoutputofthelinethatitconcludes.
Trythefollowing:
>> a=5 a = 5 >> a=6; >>
Asyousee,whenyoutypeasemicolon(;)afterthecommand,MathScriptwillnotrespond.
Itisnormalitenteronecommandineachline,likethis:
x = [0:0.1:1]; y = sin(x)
Butwecanalsoentermorethanonecommandononeline:
x = [0:0.1:1]; y = sin(x)
or:
x = [0:0.1:1], y = sin(x)
2.4 VectorsandMatricesVectors:
5 MathScriptBasics
Control Theory with MathScript Examples
Giventhefollowingvector:
𝑥 =123
ThiscanbeimplementedinMathScriptlikethis:
x =[1 2 3]
The“colonnotation”isveryusefulforcreatingvectors:
Example:
Thisexampleshowshowtousethecolonnotationcreatingavectoranddosomecalculations.
Matrices:
Giventhefollowingmatrix:
6 MathScriptBasics
Control Theory with MathScript Examples
𝐴 = 0 1−2 −3
MathScriptCode:
A=[0 1; -2 -3]
Giventhefollowingmatrix:
𝐶 =−1 2 04 10 −21 0 6
MathScriptCode:
C=[-1 2 0; 4 10 -2; 1 0 6]
Howtogetasubsetofamatrix:
→FindthevalueinthesecondrowandthethirdcolumnofmatrixC:
C(2,3)
Thisgives:
ans = -2
→FindthesecondrowofmatrixC:
C(2,:)
Thisgives:
ans =
4 10 -2
→FindthethirdcolumnofmatrixC:
C(:,3)
Thisgives:
ans = 0
-2
6
7 MathScriptBasics
Control Theory with MathScript Examples
DeletingRowsandColumns:
Youcandeleterowsandcolumnsfromamatrixusingjustapairofsquarebrackets[].
Example:
Given
𝐴 = 0 1−2 −3
WedefinethematrixA:
>>A=[0 1; -2 -3];
TodeletethesecondcolumnofamatrixA,weuse:
>>A(:,2) = [] A = 0 -2
[EndofExample]
2.5 LinearAlgebraLinearalgebraisabranchofmathematicsconcernedwiththestudyofmatrices,vectors,vectorspaces(alsocalledlinearspaces),linearmaps(alsocalledlineartransformations),andsystemsoflinearequations.
MathScriptarewellsuitedforLinearAlgebra.HerearesomeusefulfunctionsforLinearAlgebrainMathScript:
Function Description Examplerank Findtherankofamatrix.Providesanestimateofthenumberof
linearlyindependentrowsorcolumnsofamatrixA.>>A=[1 2; 3 4] >>rank(A)
det Findthedeterminantofasquarematrix >>A=[1 2; 3 4] >>det(A)
inv Findtheinverseofasquarematrix >>A=[1 2; 3 4] >>inv(A)
eig Findtheeigenvaluesofasquarematrix >>A=[1 2; 3 4] >>eig(A)
ones Createsanarrayormatrixwithonlyones >>ones(2) >>ones(2,1)
eye Createsanidentitymatrix >>eye(2)
diag Findthediagonalelementsinamatrix >>A=[1 2; 3 4] >>diag(A)
Type“helpmatfun”(Matrixfunctions-numericallinearalgebra)intheCommandWindowformoreinformation,ortype“helpelmat”(Elementarymatricesandmatrixmanipulation).
Youmayalsotype“help<functionname>”forhelpaboutaspecificfunction.
8 MathScriptBasics
Control Theory with MathScript Examples
2.6 PlottingMathScripthaslotsoffunctionalityforPlotting.Thesimplestandmostusedistheplotfunction.
Example:
>>t=[0:0.1:10]; >>y=cos(t); >>plot(t,y)
Thisgivesthefollowingplot:
[EndofExample]
MathScripthaslotsofbuilt-infunctionsforplotting:
Function Description Exampleplot Generatesaplot.plot(y)plotsthecolumnsofyagainstthe
indexesofthecolumns.>X = [0:0.01:1]; >Y = X.*X; >plot(X, Y)
figure Createanewfigurewindow >>figure >>figure(1)
subplot CreatesubplotsinaFigure.subplot(m,n,p)orsubplot(mnp),breakstheFigurewindowintoanm-by-nmatrixofsmallaxes,selectsthep-thaxesforthecurrentplot.TheaxesarecountedalongthetoprowoftheFigurewindow,thenthesecondrow,etc.
>>subplot(2,2,1)
grid Createsgridlinesinaplot.“gridon”addsmajorgridlinestothecurrentplot.“gridoff”removesmajorandminorgridlinesfromthecurrentplot.
>>grid >>grid on >>grid off
axis Controlaxisscalingandappearance.“axis([xminxmaxyminymax])”setsthelimitsforthex-andy-axisofthecurrentaxes.
>>axis([xmin xmax ymin ymax]) >>axis off >>axis on
title Addtitletocurrentplottitle('string')
>>title('this is a title')
xlabel Addxlabeltocurrentplot >> xlabel('time')
9 MathScriptBasics
Control Theory with MathScript Examples
xlabel('string')ylabel Addylabeltocurrentplot
ylabel('string')>> ylabel('temperature')
legend Createsalegendinthecorner(orataspecifiedposition)oftheplot
>> legend('temperature')
hold Freezesthecurrentplot,sothatadditionalplotscanbeoverlaid >>hold on >>hold off
Example:
Hereweseesomeexamplesofhowtousethedifferentplotfunctions:
[Figure:R.C.DorfandR.H.Bishop,ModernControlSystems,EleventhEdition:PearsonPrenticeHall]
[EndofExample]
2.6.1 Subplots
Thesubplotcommandenablesyoutodisplaymultipleplotsinthesamewindoworprintthemonthesamepieceofpaper.Typing“subplot(m,n,p)”partitionsthefigurewindowintoanm-by-nmatrixofsmallsubplotsandselectsthepthsubplotforthecurrentplot.Theplotsarenumberedalongthefirstrowofthefigurewindow,thenthesecondrow,andsoon.
10 MathScriptBasics
Control Theory with MathScript Examples
Thesyntaxisasfollows:
subplot(m,n,p)
Example:
x=0:0.1:2*pi; subplot(2,1,1) y=sin(x); plot(x,y) subplot(2,1,2) z=cos(x); plot(x,z)
Thisgivesthefollowingplot:
11 MathScriptBasics
Control Theory with MathScript Examples
[EndofExample]
12 MathScriptBasics
Control Theory with MathScript Examples
2.7 User-DefinedFunctionsinMathScriptMathScriptincludesmorethan800built-infunctionsthatyoucanusebutsometimesyouneedtocreateyourownfunctions.
TodefineyourownfunctioninMathScript,usethefollowingsyntax:
function outputs = function_name(inputs) % documentation …
ThefigurebelowillustrateshowtocreateandusefunctionsinMathScript:
2.8 ScriptsAscriptisasequenceofMathScriptcommandsthatyouwanttoperformtoaccomplishatask.Whenyouhavecreatedthescriptyoumaysaveitasam-fileforlateruse.
13 MathScriptBasics
Control Theory with MathScript Examples
YoumayalsohavemultipleScriptWindowsopenatthesametimebyselecting“NewScriptEditor”intheFilemenu:
Thisgives:
14 MathScriptBasics
Control Theory with MathScript Examples
15 MathScriptBasics
Control Theory with MathScript Examples
2.9 FlowControlYoumayusedifferentloopsinMathScript
• Forloop• Whileloop
Ifyouwanttocontroltheflowinyourprogram,youmaywanttouseoneofthefollowing:
• If-elsestatement• Switchandcasestatement
Example:
function av = calc_average2(x) %This function calculates the average of a vector x N=length(x); tot=0; for i=1:N tot=tot+x(i); end av=tot;
[EndofExample]
2.10 ControlDesigninMathScriptType“helpcdt”intheCommandWindowintheMathScriptenvironment.TheLabVIEWHelpwindowappears:
16 MathScriptBasics
Control Theory with MathScript Examples
UsetheHelpwindowandreadaboutsomeofthefunctionsavailableforcontroldesignandsimulation.
SeeAppendixAforalistofsomeofthemostusedfunctionswithdescriptionandexamples.
17
3 TransferFunctions3.1 IntroductionTransferfunctionsareamodelformbasedontheLaplacetransform.Transferfunctionsareveryusefulinanalysisanddesignoflineardynamicsystems.
AgeneralTransferfunctionisontheform:
𝐻 𝑆 =𝑦(𝑠)𝑢(𝑠)
Whereyistheoutputanduistheinput.
Ageneraltransferfunctioncanbewrittenonthefollowinggeneralform:
𝐻 𝑠 =𝑛𝑢𝑚𝑒𝑟𝑎𝑡𝑜𝑟(𝑠)𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑜𝑟(𝑠)
=𝑏=𝑠= + 𝑏=?@𝑠=?@ + ⋯+𝑏@𝑠 + 𝑏C𝑎D𝑠D + 𝑎D?@𝑠D?@ + ⋯+𝑎@𝑠 + 𝑎C
TheNumeratorsoftransferfunctionmodelsdescribethelocationsofthezerosofthesystem,whiletheDenominatorsoftransferfunctionmodelsdescribethelocationsofthepolesofthesystem.
Belowwewilllearnmoreabout2importantspecialcasesofthisgeneralform,namelythe1.ordertransferfunctionandthe2.ordertransferfunction.
3.1.1 1.ordersystem
A1.ordertransferfunction:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1
Where 𝐾 istheGainand 𝑇 istheTimeconstant.
Astepresponseofsuchatransferfunctionhasthefollowingcharacteristics:
18 TransferFunctions
Control Theory with MathScript Examples
3.1.2 1.ordersystemwithtime-delay
A1.ordertransferfunctionwithtime-delaymaybewrittenas:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1𝑒?GH
Astepresponseofsuchatransferfunctionhasthefollowingcharacteristics:
[Figure:F.Haugen,AdvancedDynamicsandControl:TechTeach,2010]
Fromthestepresponseofsuchasystemwecaneasilyfind 𝐾, 𝑇 and 𝜏.
Moreabouttime-delaysinalaterchapter.
3.1.3 2.ordersystem
19 TransferFunctions
Control Theory with MathScript Examples
A2.ordertransferfunction:
𝐻 𝑠 =𝐾
𝑠𝜔C
K+ 2𝜁 𝑠
𝜔C+ 1
Moreabout1.orderand2.ordertransferfunctionslaterinthischapter.
3.2 MathScriptMathScripthasseveralfunctionsforcreatingtransferfunctions:
Function Description Exampletf Createssystemmodelintransferfunctionform.Youalsocan
usethisfunctiontostate-spacemodelstotransferfunctionform.
>num=[1]; >den=[1, 1, 1]; >H = tf(num, den)
Sys_order1 Constructsthecomponentsofafirst-ordersystemmodelbasedonagain,timeconstant,anddelaythatyouspecify.Youcanusethisfunctiontocreateeitherastate-spacemodeloratransferfunctionmodel,dependingontheoutputparametersyouspecify.
>K = 1; >tau = 1; >H = sys_order1(K, tau)
Sys_order2 Constructsthecomponentsofasecond-ordersystemmodelbasedonadampingratioandnaturalfrequencyyouspecify.Youcanusethisfunctiontocreateeitherastate-spacemodeloratransferfunctionmodel,dependingontheoutputparametersyouspecify.
>dr = 0.5 >wn = 20 >[num, den] = sys_order2(wn, dr) >SysTF = tf(num, den)
pid Constructsaproportional-integral-derivative(PID)controllermodelinparallel,series,oracademicform.RefertotheLabVIEWControlDesignUserManualforinformationaboutthesethreeforms.
>Kc = 0.5; >Ti = 0.25; >SysOutTF = pid(Kc, Ti, 'academic');
Giventhegeneraltransferfunction:
𝐻 𝑠 =𝑛𝑢𝑚𝑒𝑟𝑎𝑡𝑜𝑟(𝑠)𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑜𝑟(𝑠)
=𝑏=𝑠= + 𝑏=?@𝑠=?@ + ⋯+𝑏@𝑠 + 𝑏C𝑎D𝑠D + 𝑎D?@𝑠D?@ + ⋯+𝑎@𝑠 + 𝑎C
InMathScriptwecandefinesuchatransferfunctionusingthebuilt-intffunctionasfollows:
num=[bm, bm_1, bm_2, … , b1, b0]; den=[an, an_1, an_2, … , a1, a0]; H = tf(num, den)
Example:
1.Giventhefollowingtransferfunction:
𝐻(𝑠) =2𝑠K + 3𝑠 + 4
5𝑠 + 9
MathScriptCode:
num=[2, 3, 4]; den=[5, 9]; H = tf(num, den)
20 TransferFunctions
Control Theory with MathScript Examples
2.Giventhefollowingtransferfunction:
𝐻(𝑠) =4𝑠O + 3𝑠 + 45𝑠K + 9
MathScriptCode:
num=[4, 0, 0, 3, 4]; den=[5, 0, 9]; H = tf(num, den)
Note!Ifsomeoftheordersaremissing,wejustputinzeros.Thetransferfunctionabovecanberewrittenas:
𝐻(𝑠) =4𝑠O + 0 ∙ 𝑠Q + 0 ∙ 𝑠K + 3𝑠 + 4
5𝑠K + 0 ∙ 𝑠 + 9
3.Giventhefollowingtransferfunction:
𝐻(𝑠) =7 + 3𝑠 + 2𝑠K
5𝑠 + 6𝑠K
Weneedtorewritethetransferfunctiontogetitincorrectorders:
𝐻(𝑠) =2𝑠K + 3𝑠 + 76𝑠K + 5𝑠
MathScriptCode:
num=[2, 3, 7]; den=[6, 5, 0]; H = tf(num, den)
[EndofExample]
Forcreatingmorecomplextransferfunctions,someofthefollowingfunctionsareuseful:
Function Description Exampleconv Computestheconvolutionoftwovectorsormatrices.Example:
𝐻 𝑠 =𝐾
2𝑠 + 1 (3𝑠 + 1)
>den1 = [2, 1]; >den2 = [3, 1]; >C = conv(den1, den2)
series ConnectstwosystemmodelsinseriestoproduceamodelSysSerwithinputandoutputconnectionsyouspecify.Example:
𝐻 𝑠 = 𝐻@ 𝑠 𝐻K(𝑠)
>Hseries = series(H1,H2)
feedback Connectstwosystemmodelstogethertoproduceaclosed-loopmodelusingnegativeorpositivefeedbackconnections
>SysClosed = feedback(SysIn_1, SysIn_2)
21 TransferFunctions
Control Theory with MathScript Examples
3.3 FirstorderTransferFunctionAfirstordertransferfunctionisgivenontheform:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1
Where
𝐾 istheGain
𝑇 istheTimeconstant
Inthetimedomainwegetthefollowingdifferentialequation(usingInverseLaplace):
𝑥 =1𝑇(−𝑥 + 𝐾𝑢)
Wecandrawthefollowingblockdiagramofthesystem:
Example:
WewillusethetffunctioninMathScripttodefinethetransferfunction:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1
Weset 𝐾 = 1 and 𝑇 = 1.
MathScriptCodeusingthetffunction:
K=1; T=1; num=[K]; den=[T, 1]; H = tf(num, den)
WeenterthecodeshownaboveintheScriptwindowasshownbelow:
22 TransferFunctions
Control Theory with MathScript Examples
MathScriptCodeusingthesys_order1function:
K = 1; T = 1; H = sys_order1(K, T)
[EndofExample]
StepResponse:
Thestepresponsefora1.ordertransferfunctionhasthefollowingcharacteristics(astep 𝑈 at 𝑡 =0):
ThetimeconstantTisdefinedasthetimewheretheresponsereaches63%ofthesteadystatevalue.
Example:
Giventhefollowing1.ordertransferfunction:
𝐻 𝑠 =1
𝑠 + 1
23 TransferFunctions
Control Theory with MathScript Examples
(𝐾 = 1, 𝑇 = 1)
Wecreatethefollowingcodeinordertoplotthestepresponseforthissystem:
K=1; T=1; num=[K]; den=[T, 1]; H = tf(num, den); Step(H)
Thisgivesthefollowingstepresponse:
[EndofExample]
3.3.1 1.ordersystemwithtime-delay
A1.ordersystemwithtime-delayhasthefollowingtransferfunction:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1𝑒?GH
Inthetimedomainwegetthefollowingdifferentialequation(usingInverseLaplace):
𝑥 =1𝑇(−𝑥 + 𝐾𝑢(𝑡 − 𝜏))
Wecandrawthefollowingblockdiagramofthesystem:
24 TransferFunctions
Control Theory with MathScript Examples
StepResponse:
[Figure:F.Haugen,AdvancedDynamicsandControl:TechTeach,2010]
Example:
𝐻 𝑠 =1
2𝑠 + 1𝑒?QH
(𝐾 = 1, 𝑇 = 2, 𝜏 = 3)
TheMathScriptcodebecomes(usingthebuilt-insys_order1function):
K = 1; T = 2; delay=3; H = sys_order1(K, T, delay) step(H)
Theplotofthestepresponsebecomes:
25 TransferFunctions
Control Theory with MathScript Examples
[EndofExample]
3.4 SecondorderTransferFunctionAsecondordertransferfunctionisgivenontheform:
𝐻 𝑠 =𝐾
𝑠𝜔C
K+ 2𝜁 𝑠
𝜔C+ 1
Where
𝐾 isthegain
𝜁 zetaistherelativedampingfactor
𝜔C[rad/s]istheundampedresonancefrequency.
Example:
DefinethetransferfunctioninMathScript.Set 𝐾 = 1, 𝜁 = 1, 𝜔C = 1
Usethetffunctionorthesys_order2functioninMathScript
MathScriptCode:
num=[1]; den=[1, 2, 1]; H = tf(num, den)
26 TransferFunctions
Control Theory with MathScript Examples
or:
dr = 1 wn = 1 [num, den] = sys_order2(wn, dr) H = tf(num, den)
[EndofExample]
2.ordersystem-specialcase:When 𝜻 > 0 andthepolesarerealanddistinctwehave:
𝐻 𝑠 =𝐾
(𝑇@𝑠 + 1)(𝑇K𝑠 + 1)
Weseethatthissystemcanbeconsideredastwo1.ordersystemsinseries.
𝐻 𝑠 = 𝐻@ 𝑠 𝐻@ 𝑠 =𝐾
(𝑇@𝑠 + 1)∙
1(𝑇K𝑠 + 1)
=𝐾
(𝑇@𝑠 + 1)(𝑇K𝑠 + 1)
3.5 SimulationMathScripthasseveralfunctionsusedforsimulationpurposes:
Function Description Exampleplot Generatesaplot.plot(y)plotsthecolumnsofyagainstthe
indexesofthecolumns.>X = [0:0.01:1]; >Y = X.*X; >plot(X, Y)
step Createsastepresponseplotofthesystemmodel.Youalsocanusethisfunctiontoreturnthestepresponseofthemodeloutputs.Ifthemodelisinstate-spaceform,youalsocanusethisfunctiontoreturnthestepresponseofthemodelstates.Thisfunctionassumestheinitialmodelstatesarezero.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>num=[1,1]; >den=[1,-1,3]; >H=tf(num,den); >t=[0:0.01:10]; >step(H,t);
lsim Createsthelinearsimulationplotofasystemmodel.Thisfunctioncalculatestheoutputofasystemmodelwhenasetofinputsexcitethemodel,usingdiscretesimulation.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>t = [0:0.1:10] >u = sin(0.1*pi*t)' >lsim(SysIn, u, t)
Plotsfunctions:Herearesomeusefulfunctionsforcreatingplots:plot,figure,subplot,grid,axis,title,xlabel,ylabel,semilogx–formoreinformationabouttheplotsfunction,type“helpplots”.Ortype“help<functionname>”.
3.6 BlockDiagramsMathScripthavebuilt-infunctionsformanipulatingblockdiagramsandtransferfunctions.
Serial:
27 TransferFunctions
Control Theory with MathScript Examples
MathScript:
… H = series(h1,h2)
Parallel:
MathScript:
… H = parallel(h1,h2)
Feedback:
MathScript:
… H = feedback(h1,h2)
3.7 AnalysisofStandardFunctionsHerewewilltakeacloserlookatthefollowingstandardfunctions:
28 TransferFunctions
Control Theory with MathScript Examples
• Integrator• 1.Ordersystem• 2.Ordersystem
3.7.1 Integrator
ThetransferfunctionforanIntegratorisasfollows:
𝐻 𝑠 =𝐾𝑠
Pole(s):
TheIntegratorhasapoleinorigo: 𝑝 = 0
InMathScriptyoumayusethepolesfunctioninordertofindthepoles.
Example:
K=1; T=1; num=[K]; den=[T 1]; H=tf(num,den); p=poles(H)
[EndofExample]
Stepresponse:
Note!InMathScriptwecanusethestepfunctionforthispurpose.
Herewewillfindthemathematicalexpressionforthestepresponse(𝒚(𝒕)):
TheLaplaceTransformationpairforastepisasfollows:
1𝑠⇔ 1
Thestepresponseofanintegratorthenbecomes:
Im(s)
Re(s)
29 TransferFunctions
Control Theory with MathScript Examples
𝑦 𝑠 = 𝐻 𝑠 𝑢 𝑠 =𝐾𝑠∙𝑈𝑠= 𝐾𝑈
1𝑠K
WeusethefollowingLaplaceTransformationpairinordertofind 𝑦(𝑡):
1𝑠K⇔ 𝑡
Thenweget:
𝑦 𝑡 = 𝐾𝑈𝑡
→WeseethatthestepresponseoftheintegratorisaRamp.
Conclusion:AbiggerKwillgiveabiggerslope(InNorwegian:“stigningstall”)andtheintegrationwillgofaster.ThesimulationinMathScriptbelowwillalsoshowthis.
BelowwewillshowthisbyusingthestepfunctioninMathScript:
Example:
InMathScriptweusethestepfunctionforsimulationofastepresponse.WesetK=0.2,1,5.
MathScriptCode:
t=[0:0.5:5]; K=0.2 num=[K]; den=[1 0]; H1=tf(num,den); K=1 num=[K]; den=[1 0]; H2=tf(num,den); K=5 num=[K]; den=[1 0]; H3=tf(num,den); step(H1,H2,H3,t) axis([0, 5, 0, 5])
Note!UsingaForLoopinthiscasewouldbeabetterapproach.
Plot:
30 TransferFunctions
Control Theory with MathScript Examples
[EndofExample]
3.7.2 1.ordersystem
Thetransferfunctionfora1.ordersystemisasfollows:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1
Pole(s):
A1.ordersystemhasapole: 𝑝 = − @[
InMathScriptyoumayusethepolesfunctioninordertofindthepoles.Thefunctionpzgraphplotsthepolesandzeros
Stepresponse:
Note!InMathScriptwecanusethestepfunctionforthispurpose.
Herewewillfindthemathematicalexpressionforthestepresponse(𝒚(𝒕)):
𝑦 𝑠 = 𝐻 𝑠 𝑢(𝑠)
Im(s)
Re(s)-1/T
31 TransferFunctions
Control Theory with MathScript Examples
Where
𝑢 𝑠 =𝑈𝑠
WeuseinverseLaplaceandfindthecorrespondingtransformationpairinordertofind 𝑦(𝑡)).
𝑦 𝑠 =𝐾
𝑇𝑠 + 1∙𝑈𝑠
WeusethefollowingLaplacetransformpair:
𝑘𝑇𝑠 + 1 𝑠
⇔ 𝑘(1 − 𝑒?]/[)
Thisgives:
𝑦 𝑡 = 𝐾𝑈(1 − 𝑒?]/[)
Thestepresponseisasfollows:
BelowwewillshowthisbyusingthestepfunctioninMathScript:
Example:
FordifferentvaluesforK,eg.,K=0.5,1,2andT=1.WeusethestepfunctioninMathScript.
t=[0:0.5:10]; den=[1 1]; K=0.5; num=[K]; H1=tf(num,den);
32 TransferFunctions
Control Theory with MathScript Examples
K=1; num=[K]; H2=tf(num,den); K=2; num=[K]; H3=tf(num,den); step(H1,H2,H3,t); axis([0, 10, 0, 2]);
Note!UsingaForLoopinthiscasewouldbeabetterapproach.
Belowweseetheplotforthis:
[EndofExample]
Example:
FordifferentvaluesforT:T=0.2,0.5,1,2,4andK=1
33 TransferFunctions
Control Theory with MathScript Examples
Note!UsingaForLoopinthiscasewouldbeabetterapproach.
WeseefromFigureabovethatsmallerT(Timeconstant)givesfasterresponse.
[EndofExample]
3.7.3 2.ordersystem
Thetransferfunctionfora2.ordersystemisasfollows:
𝐻 𝑠 =𝐾𝜔CK
𝑠K + 2𝜁𝜔C𝑠 + 𝜔CK=
𝐾𝑠𝜔C
K+ 2𝜁 𝑠
𝜔C+ 1
Where
• 𝐾 isthegain• 𝜁 zetaistherelativedampingfactor• 𝜔C[rad/s]istheundampedresonancefrequency.
Wehavethat:
34 TransferFunctions
Control Theory with MathScript Examples
Figure:F.Haugen,AdvancedDynamicsandControl:TechTeach,2010.
→ShowthisinMathScript
Specialcase:When 𝜻 > 0 andthepolesarerealanddistinctwehave:
𝐻 𝑠 =𝐾
(𝑇@𝑠 + 1)(𝑇K𝑠 + 1)
Weseethatthissystemcanbeconsideredastwo1.ordersystemsinseries:
𝐻 𝑠 = 𝐻@ 𝑠 𝐻@ 𝑠 =𝐾
(𝑇@𝑠 + 1)∙
1(𝑇K𝑠 + 1)
=𝐾
(𝑇@𝑠 + 1)(𝑇K𝑠 + 1)
35
4 State-spaceModels
4.1 IntroductionAstate-spacemodelisastructuredformorrepresentationofasetofdifferentialequations.State-spacemodelsareveryusefulinControltheoryanddesign.Thedifferentialequationsareconvertedinmatricesandvectors,whichisthebasicelementsinMathScript.
Wehavethefollowingequations:
𝑥@ = 𝑎@@𝑥@ + 𝑎K@𝑥K + ⋯+ 𝑎D@𝑥D + 𝑏@@𝑢@ + 𝑏K@𝑢K + ⋯+ 𝑏D@𝑢D
⋮
𝑥D = 𝑎@=𝑥@ + 𝑎K=𝑥K + ⋯+ 𝑎D=𝑥D +𝑏@=𝑢@ + 𝑏K=𝑢K + ⋯+ 𝑏D@𝑢D
⋮
Thisgivesonvectorform:
𝑥@𝑥K⋮𝑥D`
=𝑎@@ ⋯ 𝑎D@⋮ ⋱ ⋮
𝑎@= ⋯ 𝑎D=b
𝑥@𝑥K⋮𝑥D`
+𝑏@@ ⋯ 𝑏D@⋮ ⋱ ⋮
𝑏@= ⋯ 𝑏D=c
𝑢@𝑢K⋮𝑢Dd
𝑦@𝑦K⋮𝑦De
=𝑐@@ ⋯ 𝑐D@⋮ ⋱ ⋮𝑐@= ⋯ 𝑐D=
g
𝑥@𝑥K⋮𝑥D`
+𝑑@@ ⋯ 𝑑D@⋮ ⋱ ⋮
𝑑@= ⋯ 𝑑D=h
𝑢@𝑢K⋮𝑢Dd
ThisgivesthefollowingcompactformofagenerallinearState-spacemodel:
𝑥 = 𝐴𝑥 + 𝐵𝑢
𝑦 = 𝐶𝑥 + 𝐷𝑢
Example:
Wehavethefollowingsystem:
𝑥@ = 𝑥K
36 State-spaceModels
Control Theory with MathScript Examples
2𝑥K = −2𝑥@−6𝑥K+4𝑢@+8𝑢K
𝑦 = 5𝑥@+6𝑥K+7𝑢@
Converttothefollowingstate-spaceform:
𝑥 = 𝐴𝑥 + 𝐵𝑢
𝑦 = 𝐶𝑥 + 𝐷𝑢
Firstwedo:
𝑥@ = 𝑥K
𝑥K = −𝑥@−3𝑥K+2𝑢@+4𝑢K
𝑦 = 5𝑥@+6𝑥K+7𝑢@
Thisgives:
𝑥@𝑥K
= 0 1−1 −3
b
𝑥@𝑥K + 0 0
2 4c
𝑢@𝑢K
𝑦 = 5 6g
𝑥@𝑥K + 7 0
h
𝑢@𝑢K
→TrytodefinethisState-SpacemodelinMathScript.
[EndofExample]
4.2 MathScriptMathScripthasseveralfunctionsforcreatingstate-spacemodels:
Function Description Exampless Constructsamodelinstate-spaceform.Youalsocanusethis
functiontoconverttransferfunctionmodelstostate-spaceform.
>A = [1 2; 3 4] >B = [0; 1] >C = B' >SysOutSS = ss(A, B, C)
Sys_order1 Constructsthecomponentsofafirst-ordersystemmodelbasedonagain,timeconstant,anddelaythatyouspecify.Youcanusethisfunctiontocreateeitherastate-spacemodeloratransferfunctionmodel,dependingontheoutputparametersyouspecify.
>K = 1; >tau = 1; > [A, B, C, D] = sys_order1(K, tau)
Sys_order2 Constructsthecomponentsofasecond-ordersystemmodelbasedonadampingratioandnaturalfrequencyyouspecify.Youcanusethisfunctiontocreateeitherastate-spacemodeloratransferfunctionmodel,dependingontheoutputparametersyouspecify.
>dr = 0.5 >wn = 20 >[A, B, C, D] = sys_order2(wn, dr) >SysSS = ss(A, B, C, D)
Example:
37 State-spaceModels
Control Theory with MathScript Examples
Givenamass-spring-dampersystem:
Wherec=dampingconstant,m=mass,k=springconstant,F=u=force
Thestate-spacemodelforthesystemis:
𝑥@𝑥K
=0 1
−𝑘𝑚
−𝑐𝑚
𝑥@𝑥K +
01𝑚
𝑢
𝑦 = 1 0𝑥@𝑥K
Definethestate-spacemodelaboveusingthessfunctioninMathScript.Setsomearbitraryvaluesforc=dampingconstant,m=mass,k=springconstant.
WewilluseMathScripttodefinethestatespacemodel:
MathScriptCode:
c=1; m=1; k=1; A = [0 1; -k/m -c/m]; B = [0; 1/m]; C = [1 0]; SysOutSS = ss(A, B, C)
WeusethestepfunctioninMathScriptinordertosimulatethestepresponse:
38 State-spaceModels
Control Theory with MathScript Examples
Trywithdifferentvaluesofc,mandkandwatchtheresults.
[EndofExample]
39
5 Time-delayandPade’-approximations
5.1 IntroductionTime-delaysareverycommonincontrolsystems.TheTransferfunctionofatime-delayis:
𝐻 𝑠 = 𝑒?GH
A1.ordertransferfunctionwithtime-delaymaybewrittenas:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1𝑒?GH
Insomesituationsitisnecessarytosubstitute 𝑒?GH withanapproximation,e.g.,thePadé-approximation:
𝑒?GH ≈1 − 𝑘@𝑠 + 𝑘K𝑠K + ⋯± 𝑘D𝑠D
1 + 𝑘@𝑠 + 𝑘K𝑠K + ⋯+ 𝑘D𝑠D
Belowweseea1.orderanda2.orderPadé-approximation:
40 Time-delayandPade’-approximations
Control Theory with MathScript Examples
5.2 MathScriptMathScripthasabuilt-infunctioncalledpadeforcreatingtransferfunctionsfortime-delays:
Function Description Examplepade IncorporatestimedelaysintoasystemmodelusingthePade
approximationmethod,whichconvertsallresiduals.Youmustspecifythedelayusingthesetfunction.Youalsocanusethisfunctiontocalculatecoefficientsofnumeratoranddenominatorpolynomialfunctionswithaspecifieddelay.
>[num, den] = pade(delay, order) >[A, B, C, D] = pade(delay, order)
Sys_order1 >K=4; T=3; delay=5; >H = sys_order1(K, T, delay)
set >H = set(H1, 'inputdelay', delay);
series >H = series(H1,H2);
Example:
Herearesomeexamplesofhowtousethepadefunction:
SysCon = zpk(1, 3.2, 6) SysCon = set(SysCon, 'inputdelay', 6, 'outputdelay', 1.1) SysDel = pade(SysCon, 2) delay = 1.2 order = 3 [num, den] = pade(delay, order)
Orherisanalternativewithoutusingthepadefunction:
s=tf('s'); %Defines s to be the Laplace variable used in transfer functions K=1; T=1; %Gain and time-constant
41 Time-delayandPade’-approximations
Control Theory with MathScript Examples
H1=tf(K/(T*s+1)); %Creates H as a transfer function delay=1; %Time-delay H2=set(H1,'inputdelay',delay);%Defines H2 as H1 but with time-delay figure(1) %Plot of simulated responses will shown in Figure 1 step(H1,H2) %Simulates with unit step as input, and plots responses.
[EndofExample]
Example:
ThisexampleshowsPade’approximationswithdifferentorders:
[EndofExample]
Ifwehavea1.ordersystem,wecanalsousethefunctionsys_order1().
Example:
Giventhefollowingtransferfunction:
𝐻 𝑠 =3
2𝑠 + 1𝑒?OH
Wedefinethetransferfunctionusingsys_order1withthefollowingcode:
K = 3; T = 2;
42 Time-delayandPade’-approximations
Control Theory with MathScript Examples
delay = 4; H = sys_order1(K, T, delay)
Inadditionwefindthestepresponse:
step(H)
Thisgivesthefollowingplot:
Weknowthatastepresponseofsuchatransferfunctionhasthefollowingcharacteristics:
[Figure:F.Haugen,AdvancedDynamicsandControl:TechTeach,2010]
43 Time-delayandPade’-approximations
Control Theory with MathScript Examples
Sowecaneasilyfind 𝐾, 𝑇 and 𝜏 fromthegraph:
Anotherwaytodefine 𝐻 𝑠 = QKHn@
𝑒?OH isusingthetf()andset()functions:
s = tf('s') H1 = tf(K/(T*s+1)); H = set(H1, 'inputdelay', delay); step(H)
Wecanalsocombinetf()andthepade()functionlikethis:
num = [K]; den = [T, 1]; H1 = tf(num, den); order = 5; H2 = pade(delay, order) H = series(H1, H2) step(H)
Inthelastexamplewefirstdefinedthetransferfunction QKHn@
usingthetf()function,thenwe
definedthetimedelay 𝑒?OH usingthepade()function.Finallywehavecombinedthese2functionsusingtheseries()function.
Inthelastexamplewegetthefollowingplot:
44 Time-delayandPade’-approximations
Control Theory with MathScript Examples
[EndofExample]
45
6 StabilityAnalysis6.1 IntroductionAdynamicsystemhasoneofthefollowingstabilityproperties:
• Asymptoticallystablesystem• Marginallystablesystem• Unstablesystem
Belowweseethebehaviorofthese3differentsystemsafteranimpulse[F.Haugen,AdvancedDynamicsandControl:TechTeach,2010]:
Asymptoticallystablesystem:
lim]→s
ℎ 𝑡 = 0
Marginallystablesystem:
0< lim]→s
ℎ 𝑡 < ∞
Unstablesystem:
lim]→s
ℎ 𝑡 = ∞
46 StabilityAnalysis
Control Theory with MathScript Examples
6.2 PolesThepolesareimportantwhenanalysisthestabilityofasystem.Thefigurebelowgivesanoverviewofthepolesimpactonthestabilityofasystem:
[Figure:F.Haugen,AdvancedDynamicsandControl:TechTeach,2010]
Thus,wehavethefollowing:
Asymptoticallystablesystem:
Eachofthepolesofthetransferfunctionliesstrictlyinthelefthalfplane(hasstrictlynegativerealpart).
Marginallystablesystem:
Oneormorepolesliesontheimaginaryaxis(haverealpartequaltozero),andallthesepolesaredistinct.Besides,nopoleslieintherighthalfplane.
47 StabilityAnalysis
Control Theory with MathScript Examples
Unstablesystem:
Atleastonepoleliesintherighthalfplane(hasrealpartgreaterthanzero).
Or:Therearemultipleandcoincidentpolesontheimaginaryaxis.
Example:doubleintegrator 𝐻(𝑠) = @Hw
Example:
Giventhefollowingsystem:
𝐻 𝑠 =𝑠 + 1
𝑠K − 𝑠 + 3
Wewillanalyzethestabilityofthissystem.Inordertodothatwewillplotthestepresponseandfindthepolesforthissystem.
Westartbydefiningthetransferfunctionandplottingtheimpulseresponse:
clear clc % Define Transfer Function num=[1,1]; den=[1,-1,3]; H=tf(num,den); % Step Response t=[0:0.01:10]; impulse(H,t);
Theimpulsebecomes:
48 StabilityAnalysis
Control Theory with MathScript Examples
→Fromtheplotweseethatthesystemisunstable.
Nextwefindthepolesforthesystem:
poles(H) pzgraph(H)
Thepolesareasfollows(foundfromthebuilt-inpolesfunction):
0.5 + 1.6583i
0.5 - 1.6583i
Wehavealsousedthebuilt-inpzgraphfunctioninordertoplotthepoles(andzeros):
49 StabilityAnalysis
Control Theory with MathScript Examples
→Weseefromtheplotthatthepoles(redcross)liesintherighthalfplane(hasrealpartgreaterthanzero)andthattherearemultiplepolesontheimaginaryaxis,whichindicatethatthesystemisunstable.
[EndofExample]
6.3 FeedbackSystemsHerearesomeimportanttransferfunctionstodeterminethestabilityofafeedbacksystem.Belowweseeatypicalfeedbacksystem.
6.3.1 LoopTransferfunction
TheLooptransferfunction 𝑳(𝒔) (Norwegian:“Sløyfetransferfunksjonen”)isdefinedasfollows:
𝐿 𝑠 = 𝐻{ 𝑠 𝐻|(𝑠)𝐻=(𝑠)
50 StabilityAnalysis
Control Theory with MathScript Examples
Where
𝐻{(𝑠) istheControllertransferfunction
𝐻|(𝑠) istheProcesstransferfunction
𝐻=(𝑠) istheMeasurement(sensor)transferfunction
Note!Anothernotationfor 𝐿 is 𝐻C
6.3.2 Trackingtransferfunction
TheTrackingtransferfunction 𝑻(𝒔) (Norwegian:“Følgeforholdet”)isdefinedasfollows:
𝑇 𝑠 =𝑦(𝑠)𝑟(𝑠)
=𝐻{𝐻|𝐻=
1 + 𝐻{𝐻|𝐻==
𝐿(𝑠)1 + 𝐿(𝑠)
= 1 − 𝑆(𝑠)
TheTrackingProperty(Norwegian:“følgeegenskaper”)isgoodifthetrackingfunctionThasvalueequaltoorcloseto1:
𝑇 ≈ 1
6.3.3 Sensitivitytransferfunction
TheSensitivitytransferfunction 𝑺(𝒔) (Norwegian:“Sensitivitetsfunksjonen/avviksforholdet”)isdefinedasfollows:
𝑆 𝑠 =𝑒(𝑠)𝑟(𝑠)
=1
1 + 𝐿(𝑠)= 1 − 𝑇(𝑠)
TheCompensationPropertyisgoodifthesensitivityfunctionShasasmallvalueclosetozero:
𝑆 ≈ 0𝑜𝑟 𝑆 ≪ 1
Note!
𝑇 𝑠 + 𝑆 𝑠 =𝐿(𝑠)
1 + 𝐿(𝑠)+
11 + 𝐿(𝑠)
≡ 1
6.3.4 CharacteristicPolynomial
Wehavethat:
𝐿 𝑠 =𝑛�(𝑠)𝑑�(𝑠)
And:
51 StabilityAnalysis
Control Theory with MathScript Examples
𝑇 𝑠 =𝑦(𝑠)𝑟(𝑠)
=𝐿(𝑠)
1 + 𝐿(𝑠)=
𝑛�(𝑠)𝑑�(𝑠)
1 + 𝑛�(𝑠)𝑑�(𝑠)
=𝑛�(𝑠)
𝑑� 𝑠 + 𝑛�(𝑠)
Where 𝑛�(𝑠) and 𝑑� 𝑠 numeratorandthedenominatoroftheLooptransferfunction 𝐿(𝑠).
TheCharacteristicPolynomialforthecontrolsystemthenbecomes:
𝑎(𝑠) = 𝑑� 𝑠 + 𝑛�(𝑠)
52
7 FrequencyResponse7.1 IntroductionThefrequencyresponseofasystemisafrequencydependentfunctionwhichexpresseshowasinusoidalsignalofagivenfrequencyonthesysteminputistransferredthroughthesystem.Eachfrequencycomponentisasinusoidalsignalhavingacertainamplitudeandacertainfrequency.
Thefrequencyresponseisanimportanttoolforanalysisanddesignofsignalfiltersandforanalysisanddesignofcontrolsystems.Thefrequencyresponsecanbefoundexperimentallyorfromatransferfunctionmodel.
WecanfindthefrequencyresponseofasystembyexcitingthesystemwithasinusoidalsignalofamplitudeAandfrequencyω[rad/s](Note: 𝜔 = 2𝜋𝑓)andobservingtheresponseintheoutputvariableofthesystem.
Thefrequencyresponseofasystemisdefinedasthesteady-stateresponseofthesystemtoasinusoidalinputsignal.Whenthesystemisinsteady-stateitdiffersfromtheinputsignalonlyinamplitude/gain(A)andphaselag(𝜙).
Ifwehavetheinputsignal:
𝑢 𝑡 = 𝑈𝑠𝑖𝑛𝜔𝑡
Thesteady-stateoutputsignalwillbe:
𝑦 𝑡 = 𝑈𝐴�sin(𝜔𝑡 + 𝜙)
Where 𝐴 = ��
is theratiobetweentheamplitudesoftheoutputsignalandtheinputsignal(in
steady-state).
Aand 𝜙 isafunctionofthefrequencyωsowemaywrite 𝐴 = 𝐴 𝜔 , 𝜙 = 𝜙(𝜔)
Foratransferfunction
𝐻 𝑆 =𝑦(𝑠)𝑢(𝑠)
Wehavethat:
𝐻 𝑗𝜔 = 𝐻(𝑗𝜔) 𝑒�∠�(��)
53 FrequencyResponse
Control Theory with MathScript Examples
Where 𝐻(𝑗𝜔) isthefrequencyresponseofthesystem,i.e.,wemayfindthefrequencyresponsebysetting 𝑠 = 𝑗𝜔 inthetransferfunction.Bodediagramsareusefulinfrequencyresponseanalysis.TheBodediagramconsistsof2diagrams,theBodemagnitudediagram, 𝐴(𝜔) andtheBodephasediagram, 𝜙(𝜔).
TheGainfunction:
𝐴 𝜔 = 𝐻(𝑗𝜔)
ThePhasefunction:
𝜙 𝜔 = ∠𝐻(𝑗𝜔)
The 𝐴(𝜔)-axisisindecibel(dB),wherethedecibelvalueofxiscalculatedas: 𝒙 𝒅𝑩 = 𝟐𝟎𝒍𝒐𝒈𝟏𝟎𝒙
The 𝜙(𝜔)-axisisindegrees(notradians!)
HereyouwilllearntoplotthefrequencyresponseinaBodediagram.
BelowweseeanexampleofaBodeplotcreatedinMathScript:
7.2 MathScriptMathScripthasseveralfunctionsforFrequencyresponses:
Function Description Examplebode CreatestheBodemagnitudeandBodephaseplotsofasystem
model.Youalsocanusethisfunctiontoreturnthemagnitudeandphasevaluesofamodelatfrequenciesyouspecify.Ifyou
>num=[4]; >den=[2, 1]; >H = tf(num, den) >bode(H)
54 FrequencyResponse
Control Theory with MathScript Examples
donotspecifyanoutput,thisfunctioncreatesaplot.bodemag CreatestheBodemagnitudeplotofasystemmodel.Ifyoudo
notspecifyanoutput,thisfunctioncreatesaplot.>[mag, wout] = bodemag(SysIn) >[mag, wout] = bodemag(SysIn, [wmin wmax]) >[mag, wout] = bodemag(SysIn, wlist)
margin Calculatesand/orplotsthesmallestgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginindicateswherethefrequencyresponsecrossesat0decibels.Thephasemarginindicateswherethefrequencyresponsecrosses-180degrees.UsethemarginsfunctiontoreturnallgainandphasemarginsofaSISOmodel.
>num = [1] >den = [1, 5, 6] >H = tf(num, den) margin(H)
margins Calculatesallgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginsindicatewherethefrequencyresponsecrossesat0decibels.Thephasemarginsindicatewherethefrequencyresponsecrosses-180degrees.UsethemarginfunctiontoreturnonlythesmallestgainandphasemarginsofaSISOmodel.
>[gmf, gm, pmf, pm] = margins(H)
7.3 Examples
Example:
Wehavethefollowingtransferfunction
𝐻 𝑠 =𝑦(𝑠)𝑢(𝑠)
=1
𝑠 + 1
BelowweseethescriptforcreatingthefrequencyresponseofthesysteminabodeplotusingthebodefunctioninMathScript.Usethegridfunctiontoapplyagridtotheplot.
% Transfer function H=1/(s+1) num=[1]; den=[1, 1]; H = tf(num, den) bode (H);
[EndofExample]
Example:
Ithisexamplewewilluse3differentmethodstofind 𝐴 and 𝜙 foragivenfrequency 𝜔.
Giventhefollowingsystem:
𝐻 =𝐾
𝑇𝑠 + 1
Set 𝐾 = 1, 𝑇 = 1
Theinputsignalisgivenby:
u t = Usinωt
Thesteady-stateoutputsignalwillthenbe:
55 FrequencyResponse
Control Theory with MathScript Examples
y t = UA¢sin(ωt + ϕ)
Thegainisgivenby:
𝐴 =𝑌𝑈
Thephaselagisgivenby:
𝜙 = −𝜔Δ𝑡[𝑟𝑎𝑑/𝑠]
Method1:WecreateaMathScriptprogramwherewedefinethetransferfunctionanddefinetheinputsignalandplotit.
WewillthenusethelsimfunctionisMathScripttoplottheoutputsignalforagivenfrequency, 𝜔 =1,inthesameplot.Weset 𝑈 = 1 inthisexample.
Thefollowingcodewilldothis:
% Define Transfer function K = 1; T = 1; num = [K]; den = [T, 1]; H = tf(num, den); % Define input signal t = [1: 0.1 : 12]; w = 1; U = 1; u = U*sin(w*t); figure(1) plot(t, u) % Output signal hold on lsim(H, 'r', u, t) grid on hold off legend('input signal', 'output signal')
Thisgivesthefollowingplot
56 FrequencyResponse
Control Theory with MathScript Examples
Fromtheplotabovewegetthefollowingvalues:
𝑌 = 0.68
Δ𝑡 = 0.8
WeusethefollowingScripttocalculate 𝐴©c and 𝜙©ª«¬ªªH:
% Values found from plot1 for w=1 Y = 0.68; A = Y/U; AdB = 20*log10(A) dt = 0.8; phi = -w*dt; %[rad] phi_degrees = phi*180/pi %[degrees]
Thisgives:
𝐴 = 0.68, 𝐴©c = −3.35[𝑑𝐵]
𝜙 = −0.8𝑟𝑎𝑑, 𝜙©ª« = −45.9𝑑𝑒𝑔𝑟𝑒𝑒𝑠
Method2:Nextwewillusethebodefunctiontoplotthefrequencyresponse/Bodeplottoseeifwegetthesameresults.
Thecodeforthisis:
% Define Transfer function K = 1; T = 1;
57 FrequencyResponse
Control Theory with MathScript Examples
num = [K]; den = [T, 1]; H = tf(num, den); %Bode plot figure(2) bode(H) subplot(2,1,1) grid on subplot(2,1,2) grid on
Thisgives:
WeusetheBodeplottofind 𝐴©c and 𝜙©ª«¬ªªH for 𝜔 = 1
→Asyoucanseefromtheplotabovewegetthesameresults.
Method3:Herewewillusethebodefunctiontocalculatetheexactvaluesandcomparewiththeothermethods.
TheMathScriptbecomes:
% Define Transfer function K = 1; T = 1; num = [K]; den = [T, 1]; H = tf(num, den);
58 FrequencyResponse
Control Theory with MathScript Examples
%Calculated magnitude and phase values for some given frequencies wlist = [0.001, 0.01, 0.1, 1, 3, 5, 10, 100]; [mag, phase, wout] = bode(H, wlist); magdB = 20*log10(mag) phase
Thisgives:
magdB = -4.3429e-006 -0.0004 -0.0432 -3.0103 -10 -14.1497 -20.0432 -40.0004 phase = -0.0573 -0.5729 -5.7106 -45 -71.5651 -78.6901 -84.2894 -89.4271
→wegetthesameresultsherealso(asexpected).
[EndofExample]
Example:
Wehavethefollowingtransferfunction:
𝐻 𝑆 =4
2𝑠 + 1
Breakfrequency:
𝜔 =1𝑇=12= 0.5
Themathematicalexpressionsfor 𝐴(𝜔) and 𝜙(𝜔):
𝐻(𝑗𝜔) ©c = 20𝑙𝑜𝑔4 − 20𝑙𝑜𝑔 (2𝜔)K + 1
∠𝐻(𝑗𝜔) = −arctan(2𝜔)
59 FrequencyResponse
Control Theory with MathScript Examples
FrequencyresponseofthesysteminabodeplotusingthebodefunctioninMathScript:
MathScriptCode:
% Transfer function num=[4]; den=[2, 1]; H = tf(num, den) % Bode Plot bode(H) % Margins and Phases wlist=[0.1, 0.16, 0.25, 0.4, 0.625,2.5]; [mag, phase,w] = bode(H, wlist); magdB=20*log10(mag); %convert to dB mag_data = [w, magdB] phase_data = [w, phase]
Thisgives:
Fromthecodeaboveweget 𝐴(𝜔) and 𝜙(𝜔) forthefollowingfrequenciesusingMathScriptcode:
60 FrequencyResponse
Control Theory with MathScript Examples
𝜔 𝐴(𝜔) 𝜙(𝜔)
0.1 11.9 -11.3
0.16 11.6 -17.7
0.25 11.1 -26.5
0.4 9.9 -38.7
0.625 7.8 -51.3
2.5 -2.1 -78.6
Wefind 𝐴(𝜔) and 𝜙(𝜔) forthesamefrequenciesaboveusingthemathematicalexpressionsfor𝐴(𝜔) and 𝜙(𝜔) andaForLoopinMathScript.Wedefineavectorw=[0.1,0.16,0.25,0.4,0.625,2.5].
→Weseetheresultsarethesameastheresultfoundusingthebodefunction.
[EndofExample]
61 FrequencyResponse
Control Theory with MathScript Examples
7.4 StandardTransferfunctionsHerewewillfindthefrequencyresponseforthefollowingtransferfunctions:
• Amplifier• Integrator• Derivator• 1.ordersystem• 2.ordersystem• Zero-part• Timedelay
7.4.1 Amplifier(Norwegian:“Forsterker”):
ThetransferfunctionforanAmplifierisasfollows:
𝐻(𝑠) = 𝐾
Where
𝐾 isthegain
Themathematicalexpressionsfor 𝐴(𝜔) and 𝜙(𝜔) isasfollows:
Gain:
𝐴 𝜔 = 𝐻(𝑗𝜔) = 𝐾
orindB:
𝐻(𝑗𝜔) ©c = 20𝑙𝑜𝑔𝐾
Phase:
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = 0
Example:
WeplottheBodeplotfortheAmplifierusingthebodefunctioninMathScript(K=1):
62 FrequencyResponse
Control Theory with MathScript Examples
→Weseethatboth 𝐴(𝜔) and 𝜙(𝜔) areindependentofthefrequency𝜔.
[EndofExample]
7.4.2 Integrator
ThetransferfunctionforanIntegratorisasfollows:
𝐻 𝑠 =𝐾𝑠
Where
𝐾 isthegain
Themathematicalexpressionsfor 𝐴(𝜔) and 𝜙(𝜔) isasfollows:
Gain:
𝐴 𝜔 = 𝐻(𝑗𝜔) =𝐾𝜔
orindB:
𝐻(𝑗𝜔) ©c = 20𝑙𝑜𝑔𝐾𝜔
Phase:
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = −𝜋2𝑟𝑎𝑑 = −90°
63 FrequencyResponse
Control Theory with MathScript Examples
Example:
WeplottheBodeplotfortheIntegratorusingthebodefunctioninMathScript:
[EndofExample]
7.4.3 Derivator
ThetransferfunctionforanDerivatorisasfollows:
𝐻 𝑠 = 𝐾𝑠
Where
𝐾 isthegain
Themathematicalexpressionsfor 𝐴(𝜔) and 𝜙(𝜔) isasfollows:
Gain:
𝐴 𝜔 = 𝐻(𝑗𝜔) = 𝐾𝜔
orindB:
𝐻(𝑗𝜔) ©c = 20𝑙𝑜𝑔𝐾𝜔
Phase:
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = +𝜋2𝑟𝑎𝑑 = +90°
Example:
64 FrequencyResponse
Control Theory with MathScript Examples
WeplottheBodeplotfortheDerivatorusingthebodefunctioninMathScript:
[EndofExample]
7.4.4 1.Ordersystem
Thetransferfunctionfora1.ordersystemisasfollows:
𝐻 𝑠 =𝐾
𝑇𝑠 + 1
Where
𝐾 isthegain
TistheTimeconstant
Themathematicalexpressionsfor 𝐴(𝜔) and 𝜙(𝜔) isasfollows:
𝐴 𝜔 = 𝐻(𝑗𝜔) =𝐾
𝜔K𝑇K + 1
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = −arctan(𝜔𝑇)
Example:
WeplottheBodeplotforthe1.ordersystemusingthebodefunctioninMathScript:
65 FrequencyResponse
Control Theory with MathScript Examples
[EndofExample]
7.4.5 2.Ordersystem
Thetransferfunctionfora2.ordersystemisasfollows:
𝐻 𝑠 =𝐾𝜔CK
𝑠K + 2𝜁𝜔C𝑠 + 𝜔CK=
𝐾𝑠𝜔C
K+ 2𝜁 𝑠
𝜔C+ 1
Where
𝐾 isthegain
𝜁 zetaistherelativedampingfactor
𝜔C[rad/s]istheundampedresonancefrequency.
Example:
WeplottheBodeplotforthe2.ordersystemusingthebodefunctioninMathScript:
66 FrequencyResponse
Control Theory with MathScript Examples
[EndofExample]
7.4.6 Zeropart(Norwegian:“Nullpunktsledd”)
ThetransferfunctionforaZeropartsystemisasfollows:
𝐻 𝑠 = 𝐾(𝑇𝑠 + 1)
Where
𝐾 isthegain
TistheTimeconstant
Themathematicalexpressionsfor 𝐴(𝜔) and 𝜙(𝜔) isasfollows:
Gain:
𝐴 𝜔 = 𝐻(𝑗𝜔) = 𝐾 𝜔𝑇 K + 1
orindB:
𝐻(𝑗𝜔) ©c = 20𝑙𝑜𝑔𝐾 𝜔𝑇 K + 1
Phase:
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = +arctan(𝜔𝑇)
7.4.7 Timedelay(Norwegian:“Tidsforsinkelse”)
ThetransferfunctionforaTimeDelayisasfollows:
67 FrequencyResponse
Control Theory with MathScript Examples
𝐻 𝑠 = 𝐾𝑒?GH
Where
𝐾 isthegain
𝜏 isthetime-delay
Themathematicalexpressionsfor 𝐴(𝜔) and 𝜙(𝜔) isasfollows:
Gain:
𝐴 𝜔 = 𝐻(𝑗𝜔) = 𝐾
Phase:
𝜙 𝜔 = ∠𝐻 𝑗𝜔 = −𝜔𝜏𝑟𝑎𝑑 = −𝜔𝜏180𝜋
𝑑𝑒𝑔𝑟𝑒𝑒𝑠
Note!
2𝜋𝑟𝑎𝑑 = 360°
𝜋𝑟𝑎𝑑 = 180°
Example:
WeplottheBodeplotfortheTimedelayusingthebodefunctioninMathScript:
[EndofExample]
68
8 FrequencyresponseAnalysis
8.1 IntroductionHerearesomeimportanttransferfunctionstodeterminethestabilityofafeedbacksystem.Belowweseeatypicalfeedbacksystem.
TheLooptransferfunction 𝑳(𝒔) (Norwegian:“Sløyfetransferfunksjonen”)isdefinedasfollows:
𝐿 𝑠 = 𝐻{𝐻|𝐻=
Where
𝐻{ istheControllertransferfunction
𝐻| istheProcesstransferfunction
𝐻= istheMeasurement(sensor)transferfunction
Note!Anothernotationfor 𝐿 is 𝐻C
TheTrackingtransferfunction 𝑻(𝒔) (Norwegian:“Følgeforholdet”)isdefinedasfollows:
𝑇 𝑠 =𝑦(𝑠)𝑟(𝑠)
=𝐻{𝐻|𝐻=
1 + 𝐻{𝐻|𝐻==
𝐿(𝑠)1 + 𝐿(𝑠)
= 1 − 𝑆(𝑠)
TheTrackingProperty(Norwegian:“følgeegenskaper”)isgoodifthetrackingfunctionThasvalueequaltoorcloseto1:
69 FrequencyresponseAnalysis
Control Theory with MathScript Examples
𝑇 ≈ 1
TheSensitivitytransferfunction 𝑺(𝒔) (Norwegian:“Sensitivitetsfunksjonen/avviksforholdet”)isdefinedasfollows:
𝑆 𝑠 =𝑒(𝑠)𝑟(𝑠)
=1
1 + 𝐿(𝑠)= 1 − 𝑇(𝑠)
TheCompensationPropertyisgoodifthesensitivityfunctionShasasmallvalueclosetozero:
𝑆 ≈ 0𝑜𝑟 𝑆 ≪ 1
Note!
𝑇 𝑠 + 𝑆 𝑠 =𝐿(𝑠)
1 + 𝐿(𝑠)+
11 + 𝐿(𝑠)
≡ 1
FrequencyResponseAnalysisoftheTrackingProperty:
Fromtheequationsabovewefind:
TheTrackingProperty(Norwegian:“følgeegenskaper”)isgoodif:
𝐿(𝑗𝜔) ≫ 1
TheTrackingProperty(Norwegian:“følgeegenskaper”)ispoorif:
𝐿(𝑗𝜔) ≪ 1
Bandwidths 𝝎𝒕,𝝎𝒄, 𝝎𝒔 (seethesketchbelow)
70 FrequencyresponseAnalysis
Control Theory with MathScript Examples
𝝎𝒄 –crossover-frequency–thefrequencywherethegainoftheLooptransferfunction 𝐿(𝑗𝜔) hasthevalue:
1 = 0𝑑𝐵
𝝎𝒕 –thefrequencywherethegainoftheTrackingfunction 𝑇(𝑗𝜔) hasthevalue:
12≈ 0.71 = −3𝑑𝐵
𝝎𝒔 -thefrequencywherethegainoftheSensitivitytransferfunction 𝑆(𝑗𝜔) hasthevalue:
1 −12≈ 0.29 = −11𝑑𝐵
8.2 MathScriptMathScripthasseveralfunctionsforfrequencyresponseanalysis:
Function Description Exampletf Createssystemmodelintransferfunctionform.Youalsocan
usethisfunctiontostate-spacemodelstotransferfunctionform.
>num=[1]; >den=[1, 1, 1]; >H = tf(num, den)
poles Returnsthelocationsoftheclosed-looppolesofasystemmodel.
>num=[1] >den=[1,1] >H=tf(num,den) >poles(H)
tfinfo Returnsinformationaboutatransferfunctionsystemmodel. >[num, den, delay, Ts] = tfinfo(SysInTF)
series ConnectstwosystemmodelsinseriestoproduceamodelSysSerwithinputandoutputconnectionsyouspecify
>Hseries = series(H1,H2)
feedback Connectstwosystemmodelstogethertoproduceaclosed-loopmodelusingnegativeorpositivefeedbackconnections
>SysClosed = feedback(SysIn_1, SysIn_2)
71 FrequencyresponseAnalysis
Control Theory with MathScript Examples
bode CreatestheBodemagnitudeandBodephaseplotsofasystemmodel.Youalsocanusethisfunctiontoreturnthemagnitudeandphasevaluesofamodelatfrequenciesyouspecify.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>num=[4]; >den=[2, 1]; >H = tf(num, den) >bode(H)
bodemag CreatestheBodemagnitudeplotofasystemmodel.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>[mag, wout] = bodemag(SysIn) >[mag, wout] = bodemag(SysIn, [wmin wmax]) >[mag, wout] = bodemag(SysIn, wlist)
margin Calculatesand/orplotsthesmallestgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginindicateswherethefrequencyresponsecrossesat0decibels.Thephasemarginindicateswherethefrequencyresponsecrosses-180degrees.UsethemarginsfunctiontoreturnallgainandphasemarginsofaSISOmodel.
>num = [1] >den = [1, 5, 6] >H = tf(num, den) margin(H)
margins Calculatesallgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginsindicatewherethefrequencyresponsecrossesat0decibels.Thephasemarginsindicatewherethefrequencyresponsecrosses-180degrees.UsethemarginfunctiontoreturnonlythesmallestgainandphasemarginsofaSISOmodel.
>[gmf, gm, pmf, pm] = margins(H)
Example:
Giventhefollowingsystem:
Processtransferfunction:
𝐻| =𝐾𝑠𝑒?GH
Where 𝐾 = µ́¶b,where 𝐾H = 0,556, 𝐴 = 13,4, 𝜚 = 145 and 𝜏 = 250
Measurement(sensor)transferfunction:
𝐻= = 𝐾=
WhereKm=6,67%/m.
Controllertransferfunction(PIController):
𝐻{ = 𝐾| +𝐾|𝑇 𝑠
SetKp=1,5ogTi=1000sec.
WeshallfindtheLooptransferfunction (𝒔) ,Sensitivitytransferfunction 𝑺(𝒔),Trackingtransferfunction 𝑻(𝒔) usingtheseriesandfeedbackfunctionsinMathScript.
MathScriptCode:
%Calculating control system transfer functions: L=series(Hc,series(Hp,Hs)); %Calculating loop tranfer function T=feedback(L,1); %Calculating tracking transfer function S=1-T; %Calculating sensitivity transfer function
72 FrequencyresponseAnalysis
Control Theory with MathScript Examples
WeplottheBodeplotforL,TandSandfindtheBandwidths 𝜔], 𝜔{, 𝜔H:
MathScriptCode:
bodemag(L,T,S), grid %Plots maginitude of L, T, and S in Bode diagram
Bodeplot(Magnitudeonly)ofL,TandS:
Wefindthestabilitymargins(GM,PM)ofthesystem(𝐿(𝑠)):
margin(L), grid %Plotting L and stability margins and crossover frequencies in Bode diagram
Bodeplotwiththestabilitymargins(GM,PM)markedontheplot:
73 FrequencyresponseAnalysis
Control Theory with MathScript Examples
[EndofExample]
74
9 StabilityAnalysisintheFrequencyDomain
9.1 IntroductionGainMargin(GM)andPhaseMargin(PM)areimportantdesigncriteriaforanalysisoffeedbackcontrolsystems.
Adynamicsystemhasoneofthefollowingstabilityproperties:
• Asymptoticallystablesystem• Marginallystablesystem• Unstablesystem
TheGainMargin–GM(Δ𝐾)ishowmuchtheloopgaincanincreasebeforethesystembecomeunstable.
ThePhaseMargin-PM(𝜑)ishowmuchthephaselagfunctionoftheloopcanbereducedbeforetheloopbecomesunstable.
Where:
75 StabilityAnalysisintheFrequencyDomain
Control Theory with MathScript Examples
• 𝝎𝟏𝟖𝟎(gainmarginfrequency-gmf)isthegainmarginfrequency/frequencies,inradians/second.Againmarginfrequencyindicateswherethemodelphasecrosses-180degrees.
• GM(Δ𝐾)isthegainmargin(s)ofthesystem. • 𝝎𝒄 (phasemarginfrequency-pmf)returnsthephasemarginfrequency/frequencies,in
radians/second.Aphasemarginfrequencyindicateswherethemodelmagnitudecrosses0decibels.
• PM(𝜑)isthephasemargin(s)ofthesystem.
Note! 𝝎𝟏𝟖𝟎 and 𝝎𝒄arecalledthecrossover-frequencies
Thedefinitionsareasfollows:
GainCrossover-frequency- 𝝎𝒄:
𝐿 𝑗𝜔{ = 1 = 0𝑑𝐵
PhaseCrossover-frequency- 𝝎𝟏𝟖𝟎:
∠𝐿 𝑗𝜔@»C = −180°
GainMargin-GM(𝚫𝑲):
𝐺𝑀 = @� ��ÀÁÂ
or:
𝐺𝑀 𝑑𝐵 = − 𝐿 𝑗𝜔@»C 𝑑𝐵
PhasemarginPM(𝝋):
𝑃𝑀 = 180° + ∠𝐿(𝑗𝜔{)
Wehavethat:
• Asymptoticallystablesystem: 𝝎𝒄 < 𝝎𝟏𝟖𝟎• Marginallystablesystem: 𝝎𝒄 = 𝝎𝟏𝟖𝟎• Unstablesystem: 𝝎𝒄 > 𝝎𝟏𝟖𝟎
9.2 MathScriptMathScripthasseveralfunctionsforstabilityanalysis:
Function Description Examplebode CreatestheBodemagnitudeandBodephaseplotsofasystem
model.Youalsocanusethisfunctiontoreturnthemagnitudeandphasevaluesofamodelatfrequenciesyouspecify.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>num=[4]; >den=[2, 1]; >H = tf(num, den) >bode(H)
bodemag CreatestheBodemagnitudeplotofasystemmodel.Ifyoudo >[mag, wout] = bodemag(SysIn)
76 StabilityAnalysisintheFrequencyDomain
Control Theory with MathScript Examples
notspecifyanoutput,thisfunctioncreatesaplot. >[mag, wout] = bodemag(SysIn, [wmin wmax]) >[mag, wout] = bodemag(SysIn, wlist)
margin Calculatesand/orplotsthesmallestgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginindicateswherethefrequencyresponsecrossesat0decibels.Thephasemarginindicateswherethefrequencyresponsecrosses-180degrees.UsethemarginsfunctiontoreturnallgainandphasemarginsofaSISOmodel.
>num = [1] >den = [1, 5, 6] >H = tf(num, den) margin(H)
margins Calculatesallgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginsindicatewherethefrequencyresponsecrossesat0decibels.Thephasemarginsindicatewherethefrequencyresponsecrosses-180degrees.UsethemarginfunctiontoreturnonlythesmallestgainandphasemarginsofaSISOmodel.
>[gmf, gm, pmf, pm] = margins(H)
Example:
Giventhefollowingsystem:
𝐻 𝑆 =1
𝑠 𝑠 + 1 K
Wewillfindthecrossover-frequenciesforthesystemusingMathScript.Wewillalsofindalsothegainmarginsandphasemarginsforthesystem.
Weget:
77 StabilityAnalysisintheFrequencyDomain
Control Theory with MathScript Examples
BelowweseetheBodediagramwiththecrossover-frequencyandthegainmarginandphasemarginforthesystemplottedin:
[EndofExample]
Example:
Giventhefollowingsystem:
𝐻 𝑠 =𝑠 + 1
𝑠K − 𝑠 + 3
→ThesystemisunstableandFrequencyResponsegivesmeaningonlyforstablesystems.
Note!Thefrequencyresponseofasystemisdefinedasthesteady-stateresponseofthesystemtoasinusoidalinputsignal.
TheBodediagramforunstablesystemsdon’tshowwhathappenswiththesinusoidalsignalofagivenfrequencywhenthesysteminputistransferredthroughthesystembecauseitneverreachsteadystate.
Weseethatthesystemisunstablebecausesomeofthecoefficientsinthedenominatorpolynomial𝑠K − 𝑠 + 3 arenegative.
78 StabilityAnalysisintheFrequencyDomain
Control Theory with MathScript Examples
Weconfirmthisbysomesimulationsandfindingthepolesforthesystem:
poles(H) pzgraph(H)
Thisgives:
→Weseethepolesarecomplexconjugateandthattheyliesintherighthalf-plane.
Weplotthestepresponseforthetransferfunctionusingthestepfunction:
num=[1,1]; den=[1,-1,3]; H=tf(num,den); t=[0:0.01:10]; step(H,t);
Thisgivesthefollowingplot:
79 StabilityAnalysisintheFrequencyDomain
Control Theory with MathScript Examples
→Weseethesystemisunstable
[EndofExample]
80
AppendixA–MathScriptFunctions
BasicFunctionsHerearesomedescriptionsforthemostusedbasicMathScriptfunctions.
Function Description Examplehelp MathScriptdisplaysthehelpinformationavailable >>help
help<function>
Displayhelpaboutaspecificfunction >>help plot
who,whos wholistsinalphabeticalorderallvariablesinthecurrentlyactiveworkspace.
>>who >>whos
clear Clearvariablesandfunctionsfrommemory. >>clear >>clear x
size Sizeofarrays,matrices >>x=[1 2 ; 3 4]; >>size(A)
length Lengthofavector >>x=[1:1:10]; >>length(x)
format Setoutputformat
disp Displaytextorarray >>A=[1 2;3 4]; >>disp(A)
plot Thisfunctionisusedtocreateaplot >>x=[1:1:10]; >>plot(x) >>y=sin(x); >>plot(x,y)
clc CleartheCommandwindow >>cls
rand Createsarandomnumber,vectorormatrix >>rand >>rand(2,1)
max Findthelargestnumberinavector >>x=[1:1:10] >>max(x)
min Findthesmallestnumberinavector >>x=[1:1:10] >>min(x)
mean Averageormeanvalue >>x=[1:1:10] >>mean(x)
std Standarddeviation >>x=[1:1:10] >>std(x)
BasicPlottingFunctionsFunction Description Exampleplot Generatesaplot.plot(y)plotsthecolumnsofyagainstthe
indexesofthecolumns.>X = [0:0.01:1]; >Y = X.*X; >plot(X, Y)
figure Createanewfigurewindow >>figure >>figure(1)
subplot CreatesubplotsinaFigure.subplot(m,n,p)orsubplot(mnp),breakstheFigurewindowintoanm-by-nmatrixofsmallaxes,selectsthep-thaxesforthecurrentplot.TheaxesarecountedalongthetoprowoftheFigurewindow,thenthesecondrow,etc.
>>subplot(2,2,1)
81 AppendixA–MathScriptFunctions
Control Theory with MathScript Examples
grid Createsgridlinesinaplot.“gridon”addsmajorgridlinestothecurrentplot.“gridoff”removesmajorandminorgridlinesfromthecurrentplot.
>>grid >>grid on >>grid off
axis Controlaxisscalingandappearance.“axis([xminxmaxyminymax])”setsthelimitsforthex-andy-axisofthecurrentaxes.
>>axis([xmin xmax ymin ymax]) >>axis off >>axis on
title Addtitletocurrentplottitle('string')
>>title('this is a title')
xlabel Addxlabeltocurrentplotxlabel('string')
>> xlabel('time')
ylabel Addylabeltocurrentplotylabel('string')
>> ylabel('temperature')
legend Createsalegendinthecorner(orataspecifiedposition)oftheplot
>> legend('temperature')
hold Freezesthecurrentplot,sothatadditionalplotscanbeoverlaid >>hold on >>hold off
Formoreinformationabouttheplotsfunction,type“helpplots”.
FunctionsusedforControlandSimulationFunction Description Example
plot Generatesaplot.plot(y)plotsthecolumnsofyagainsttheindexesofthecolumns.
>X = [0:0.01:1]; >Y = X.*X; >plot(X, Y)
tf Createssystemmodelintransferfunctionform.Youalsocanusethisfunctiontostate-spacemodelstotransferfunctionform.
>num=[1]; >den=[1, 1, 1]; >H = tf(num, den)
poles Returnsthelocationsoftheclosed-looppolesofasystemmodel.
>num=[1] >den=[1,1] >H=tf(num,den) >poles(H)
tfinfo Returnsinformationaboutatransferfunctionsystemmodel. >[num, den, delay, Ts] = tfinfo(SysInTF)
step Createsastepresponseplotofthesystemmodel.Youalsocanusethisfunctiontoreturnthestepresponseofthemodeloutputs.Ifthemodelisinstate-spaceform,youalsocanusethisfunctiontoreturnthestepresponseofthemodelstates.Thisfunctionassumestheinitialmodelstatesarezero.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>num=[1,1]; >den=[1,-1,3]; >H=tf(num,den); >t=[0:0.01:10]; >step(H,t);
lsim Createsthelinearsimulationplotofasystemmodel.Thisfunctioncalculatestheoutputofasystemmodelwhenasetofinputsexcitethemodel,usingdiscretesimulation.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>t = [0:0.1:10] >u = sin(0.1*pi*t)' >lsim(SysIn, u, t)
Sys_order1 Constructsthecomponentsofafirst-ordersystemmodelbasedonagain,timeconstant,anddelaythatyouspecify.Youcanusethisfunctiontocreateeitherastate-spacemodeloratransferfunctionmodel,dependingontheoutputparametersyouspecify.
>K = 1; >tau = 1; >H = sys_order1(K, tau)
Sys_order2 Constructsthecomponentsofasecond-ordersystemmodelbasedonadampingratioandnaturalfrequencyyouspecify.Youcanusethisfunctiontocreateeitherastate-spacemodeloratransferfunctionmodel,dependingontheoutputparametersyouspecify.
>dr = 0.5 >wn = 20 >[num, den] = sys_order2(wn, dr) >SysTF = tf(num, den) >[A, B, C, D] = sys_order2(wn, dr) >SysSS = ss(A, B, C, D)
damp Returnsthedampingratiosandnaturalfrequenciesofthepolesofasystemmodel.
>[dr, wn, p] = damp(SysIn)
pid Constructsaproportional-integral-derivative(PID)controllermodelineitherparallel,series,oracademicform.RefertotheLabVIEWControlDesignUserManualforinformationaboutthesethreeforms.
>Kc = 0.5; >Ti = 0.25; >SysOutTF = pid(Kc, Ti, 'academic');
conv Computestheconvolutionoftwovectorsormatrices. >C1 = [1, 2, 3]; >C2 = [3, 4]; >C = conv(C1, C2)
82 AppendixA–MathScriptFunctions
Control Theory with MathScript Examples
series ConnectstwosystemmodelsinseriestoproduceamodelSysSerwithinputandoutputconnectionsyouspecify
>Hseries = series(H1,H2)
feedback Connectstwosystemmodelstogethertoproduceaclosed-loopmodelusingnegativeorpositivefeedbackconnections
>SysClosed = feedback(SysIn_1, SysIn_2)
ss Constructsamodelinstate-spaceform.Youalsocanusethisfunctiontoconverttransferfunctionmodelstostate-spaceform.
>A = eye(2) >B = [0; 1] >C = B' >SysOutSS = ss(A, B, C)
ssinfo Returnsinformationaboutastate-spacesystemmodel. >A = [1, 1; -1, 2] >B = [1, 2]' >C = [2, 1] >D = 0 >SysInSS = ss(A, B, C, D) >[A, B, C, D, Ts] = ssinfo(SysInSS)
pade IncorporatestimedelaysintoasystemmodelusingthePadeapproximationmethod,whichconvertsallresiduals.Youmustspecifythedelayusingthesetfunction.Youalsocanusethisfunctiontocalculatecoefficientsofnumeratoranddenominatorpolynomialfunctionswithaspecifieddelay.
>[num, den] = pade(delay, order) >[A, B, C, D] = pade(delay, order)
bode CreatestheBodemagnitudeandBodephaseplotsofasystemmodel.Youalsocanusethisfunctiontoreturnthemagnitudeandphasevaluesofamodelatfrequenciesyouspecify.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>num=[4]; >den=[2, 1]; >H = tf(num, den) >bode(H)
bodemag CreatestheBodemagnitudeplotofasystemmodel.Ifyoudonotspecifyanoutput,thisfunctioncreatesaplot.
>[mag, wout] = bodemag(SysIn) >[mag, wout] = bodemag(SysIn, [wmin wmax]) >[mag, wout] = bodemag(SysIn, wlist)
margin Calculatesand/orplotsthesmallestgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginindicateswherethefrequencyresponsecrossesat0decibels.Thephasemarginindicateswherethefrequencyresponsecrosses-180degrees.UsethemarginsfunctiontoreturnallgainandphasemarginsofaSISOmodel.
>num = [1] >den = [1, 5, 6] >H = tf(num, den) margin(H)
margins Calculatesallgainandphasemarginsofasingle-inputsingle-output(SISO)systemmodel.Thegainmarginsindicatewherethefrequencyresponsecrossesat0decibels.Thephasemarginsindicatewherethefrequencyresponsecrosses-180degrees.UsethemarginfunctiontoreturnonlythesmallestgainandphasemarginsofaSISOmodel.
>[gmf, gm, pmf, pm] = margins(H)
Formoredetailsaboutthesefunctions,type“helpcdt”togetanoverviewofallthefunctionsusedforControlDesignandSimulation.Fordetailedhelpaboutonespecificfunction,type“help<function_name>”.
Hans-PetterHalvorsen,M.Sc.
E-mail:[email protected]
Blog:http://home.hit.no/~hansha/
UniversityCollegeofSoutheastNorway
www.usn.no