44
06/12/22 MATLAB 1

7/2/2015MATLAB1. MATLAB MATLAB and Toolboxes MATLAB and Control Control System Toolbox Simulink 7/2/2015MATLAB Control Toolbox2

Embed Size (px)

Citation preview

Page 1: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB 1

Page 2: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

MATLAB MATLAB and Toolboxes MATLAB and Control Control System Toolbox Simulink

04/19/23 MATLAB Control Toolbox 2

Page 3: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Aerospace and Defense Automotive Biotech, Medical, and

Pharmaceutical Chemical and

Petroleum Communications Computers and Office

Equipment Education Electronics and

Semiconductor Financial Services Industrial Equipment

and Machinery Instrumentation Utilities and Energy

04/19/23 MATLAB Control Toolbox 3

Page 4: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 4

The MathWorks Product Family

Page 5: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 5

MATLAB

Math and optimization

Toolboxes

Optimization Symbolic Math Partial Diff. Eq.…

Signal Processingand communications

ToolboxesSignal Processing Communications Filter Design Filter Design HDL Coder …

SimulinkProduct Family

Simulink® Simulink Accelerator Simulink Report Generator

….. Control System Design and Analysis

Toolboxes

Simulink Control Design Simulink ResponseSimulink Parameter …

Page 6: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 6

MATLAB-Toolboxes for Control

Linear Control

Control System ToolboxSimulink®Mu Toolbox

Nonlinear Control

Nonlinear Control ToolboxFuzzy ToolboxSimulink®

Identification

Identification ToolboxFrequency-Domain ID ToolboxSimulink®

Page 7: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Control Design Process

04/19/23 MATLAB Control Toolbox 7

Page 8: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Modeling Tools

04/19/23 MATLAB Control Toolbox 8

Page 9: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Design and Analysis

04/19/23 MATLAB Control Toolbox 9

Page 10: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Core Features Tools to manipulate LTI models

Classical analysis and design Bode, Nyquist, Nichols diagrams Step and impulse response Gain/phase margins Root locus design

Modern state-space techniques Pole placement LQG regulation

04/19/23 MATLAB Control Toolbox 10

Page 11: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

LTI Objects (Linear Time Invariant)

4 basic types of LTI models Transfer Function (TF) Zero-pole-gain model (ZPK) State-Space models (SS) Frequency response data model (FRD)

Conversion between models

Model properties (dynamics)

04/19/23 MATLAB Control Toolbox 11

Page 12: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

1

1 2 1

1

1 1 1

1 2 1

1 1 1

...( )

...

, ... numerator coefficients

, ... denominator coefficients

n n

n

m m

m

n

m

p s p s pH s

q s q s q

where

p p p

q q q

04/19/23 MATLAB Control Toolbox 12

Transfer Function

Page 13: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Consider a linear time invariant (LTI) single-input/single-output system

Applying Laplace Transform to both sides with zero initial conditions

'' 6 ' 5 4 ' 3y y y u u

2

( ) 4 3( )

( ) 6 5

Y s sG s

U s s s

04/19/23 MATLAB Control Toolbox 13

Transfer Function

Page 14: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 14

>> num = [4 3];

>> den = [1 6 5];

>> sys = tf(num,den)Transfer function:

4 s + 3

-----------------

s^2 + 6 s + 5

Transfer Function

>> [num,den] = tfdata(sys,'v') num = 0 4 3 den = 1 6 5

Page 15: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 15

Zero-pole-gain model (ZPK)

1 2

1 2

1 2 1

1 1 1

( )( ) ... ( )( )

( )( ) ... ( )

, ... the zeros of H(s)

, ... the poles of H(s)

n

m

n

m

s p s p s pH s K

s q s q s q

where

p p p

q q q

Page 16: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

'' 6 ' 5 4 ' 3y y y u u

04/19/23 MATLAB Control Toolbox 16

Consider a Linear time invariant (LTI) single-input/single-output system

Applying Laplace Transform to both sides with zero initial conditions

2

( ) 4 3 4( 0.75)( )

( ) ( 1)( 5)6 5

Y s s sG s

U s s ss s

Zero-pole-gain model (ZPK)

Page 17: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 17

Zero-pole-gain model (ZPK)

>> sys1 = zpk(-0.75,[-1 -5],4) Zero/pole/gain:4 (s+0.75)-----------(s+1) (s+5)

>> [ze,po,k] = zpkdata(sys1,'v')

ze =

-0.7500

po =

-1

-5

k =

4

Page 18: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

.

state vector

input and output vectors

, , state-space matrices

x A x B u

y C x D u

where

x

u and y

A B C and D

04/19/23 MATLAB Control Toolbox 18

State-Space Model (SS)

Page 19: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Consider a Linear time invariant (LTI) single-input/single-output system

State-space model for this system is'' 6 ' 5 4 '' 3y y y u u

1 1

2 2

' 0 1 0

' 5 6 1

x xu

x x

04/19/23 MATLAB Control Toolbox 19

1

2

(0) 0

(0) 0

x

x

1

2

3 4x

yx

Control System Toolbox

Page 20: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

>> sys = ss([0 1; -5 -6],[0;1],[3,4],0) a = x1 x2 x1 0 1 x2 -5 -6 b = u1 x1 0 x2 1

04/19/23 MATLAB Control Toolbox 20

c = x1 x2 y1 3 4

d = u1 y1 0

State-Space Models

Page 21: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

State Space Models rss, drss - Random stable state-space models. ss2ss - State coordinate transformation. canon - State-space canonical forms. ctrb - Controllability matrix. obsv - Observability matrix. gram - Controllability and observability gramians. ssbal - Diagonal balancing of state-space realizations. balreal - Gramian-based input/output balancing. modred - Model state reduction. minreal - Minimal realization and pole/zero cancellation. sminreal - Structurally minimal realization.

04/19/23 MATLAB Control Toolbox 21

Page 22: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 22

Transfer function State Space

Zero-pole-gain

tf2ss

ss2tf

tf2zpzp2tf ss2zp

zp2ss

Page 23: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

pzmap: Pole-zero map of LTI models. pole, eig - System poles zero - System (transmission) zeros. dcgain: DC gain of LTI models. bandwidth - System bandwidth. iopzmap - Input/Output Pole-zero map. damp - Natural frequency and damping of

system esort - Sort continuous poles by real part. dsort - Sort discrete poles by magnitude. covar - Covariance of response to white

noise.

04/19/23 MATLAB Control Toolbox 23

Page 24: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Impulse Response (impulse) Step Response (step) General Time Response (lsim) Polynomial multiplication (conv) Polynomial division (deconv) Partial Fraction Expansion (residue) gensig - Generate input signal for lsim.

04/19/23 MATLAB Control Toolbox 24

Control System Toolbox

Page 25: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 25

The impulse response of a system is its output when the input is a unit impulse.

The step response of a system is its output when the input is a unit step.

The general response of a system to any input can be computed using the lsim command.

Control System Toolbox

Page 26: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

1s5s4s2

2s3)s(G

23

)t5.0sin()t(u

04/19/23 MATLAB Control Toolbox 26

ProblemProblem Given the LTI systemGiven the LTI system

Plot the following responses for:Plot the following responses for: The impulse response using the The impulse response using the impulseimpulse command. command. The step response using the The step response using the stepstep command. command. The response to the input calculated using The response to the input calculated using

both the both the lsimlsim commands commands

Time Response of Systems

Page 27: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 27

Time Response of Systems

Page 28: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Root locus analysisRoot locus analysis Frequency response plotsFrequency response plots

BodeBode Phase MarginPhase Margin Gain MarginGain Margin

NyquistNyquist

04/19/23 MATLAB Control Toolbox 28

Page 29: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 29

Root Locus The root locus is a plot in the s-plane of all The root locus is a plot in the s-plane of all

possible locations of the poles of a closed-loop possible locations of the poles of a closed-loop system, as one parameter, usually the gain, is system, as one parameter, usually the gain, is varied from 0 to varied from 0 to ..

By examining that plot, the designer can make By examining that plot, the designer can make choices of values of the controller’s parameters, choices of values of the controller’s parameters, and can infer the performance of the controlled and can infer the performance of the controlled closed-loop system. closed-loop system.

Page 30: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Plot the root locus of the following Plot the root locus of the following systemsystem

04/19/23 MATLAB Control Toolbox 30

2

( 8)( )

( 2)( 8 32)

K sG s

s s s s

Root Locus

Page 31: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 31

Root Locus>> rlocus(tf([1 8], conv(conv([1 0],[1 2]),[1 8 32])))>> rlocus(tf([1 8], conv(conv([1 0],[1 2]),[1 8 32])))

Page 32: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Typically, the analysis and design of a Typically, the analysis and design of a control system requires an examination of control system requires an examination of its frequency response over a range of its frequency response over a range of frequencies of interest.frequencies of interest.

The MATLAB Control System Toolbox The MATLAB Control System Toolbox provides functions to generate two of the provides functions to generate two of the most common frequency response plots: most common frequency response plots: Bode Plot (bode command) and Nyquist Plot Bode Plot (bode command) and Nyquist Plot (nyquist command).(nyquist command).

04/19/23 MATLAB Control Toolbox 32

Frequency Response: Bode and Nyquist Plots

Page 33: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Problem Problem Given the LTI systemGiven the LTI system

Draw the Bode diagram for 100 values of Draw the Bode diagram for 100 values of frequency in the interval .frequency in the interval .

04/19/23 MATLAB Control Toolbox 33

1G(s )

s(s 1)

110 10

Control System ToolboxFrequency Response: Bode Plot

Page 34: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

>>bode(tf(1, [1 1 0]), logspace(-1,1,100));>>bode(tf(1, [1 1 0]), logspace(-1,1,100));

04/19/23 MATLAB Control Toolbox 34

Frequency Response: Bode Plot

Page 35: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 35

The loop gain Transfer function The loop gain Transfer function G(s)G(s) The The gain margingain margin is defined as the multiplicative is defined as the multiplicative

amount that the magnitude of amount that the magnitude of G(s) G(s) can be increased can be increased before the closed loop system goes unstablebefore the closed loop system goes unstable

Phase marginPhase margin is defined as the amount of additional is defined as the amount of additional phase lag that can be associated with phase lag that can be associated with G(s)G(s) before the before the closed-loop system goes unstableclosed-loop system goes unstable

Frequency Response: Nyquist Plot

Page 36: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

16s24.320s81.1604s2.24s

640s1280)s(G

234

4 310 10

04/19/23 MATLAB Control Toolbox 36

ProblemProblem Given the LTI systemGiven the LTI system

Draw the bode and nyquist plots for 100 values of frequencies Draw the bode and nyquist plots for 100 values of frequencies in the interval . In addition, find the gain and phase in the interval . In addition, find the gain and phase margins. margins.

Control System ToolboxFrequency Response: Nyquist Plot

Page 37: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

w=logspace(-4,3,100);w=logspace(-4,3,100);

sys=tf([1280 640], [1 24.2 1604.81 320.24 16]);sys=tf([1280 640], [1 24.2 1604.81 320.24 16]);

bode(sys,w)bode(sys,w)

[Gm,Pm,Wcg,Wcp]=margin(sys)[Gm,Pm,Wcg,Wcp]=margin(sys)

%Nyquist plot%Nyquist plot

figurefigure

nyquist(sys,w)nyquist(sys,w)

04/19/23 MATLAB Control Toolbox 37

Frequency Response: Nyquist Plot

Page 38: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 38

Frequency Response: Nyquist Plot

The values of gain and phase margin and corresponding frequencies are The values of gain and phase margin and corresponding frequencies are

Gm = 29.8637 Pm = 72.8960 Wcg = 39.9099 Wcp = 0.9036Gm = 29.8637 Pm = 72.8960 Wcg = 39.9099 Wcp = 0.9036

Page 39: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 39

Frequency Response Plots

bode - Bode diagrams of the frequency response.bodemag - Bode magnitude diagram only.sigma - Singular value frequency plot.Nyquist - Nyquist plot.nichols - Nichols plot.margin - Gain and phase margins.allmargin - All crossover frequencies and related gain/phase margins.freqresp - Frequency response over a frequency grid.evalfr - Evaluate frequency response at given frequency.interp - Interpolates frequency response data.

Page 40: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Design: Pole Placement place - MIMO pole placement. acker - SISO pole placement. estim - Form estimator given estimator gain. reg - Form regulator given state-feedback and

estimator gains.

04/19/23 MATLAB Control Toolbox 40

Page 41: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

Design : LQR/LQG design lqr, dlqr - Linear-quadratic (LQ) state-feedback

regulator. lqry - LQ regulator with output weighting. lqrd - Discrete LQ regulator for continuous

plant. kalman - Kalman estimator. kalmd - Discrete Kalman estimator for

continuous plant. lqgreg - Form LQG regulator given LQ gain and Kalman estimator. augstate - Augment output by appending

states.

04/19/23 MATLAB Control Toolbox 41

Page 42: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 42

Analysis Tool: ltiview

File->Import to import system from Matlab workspace

Page 43: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

04/19/23 MATLAB Control Toolbox 43

Design Tool: sisotool

Design with root locus, Bode, and Nichols plots of the open-loop system.Cannot handle continuous models with time delay.

Control System Toolbox

Page 44: 7/2/2015MATLAB1.  MATLAB  MATLAB and Toolboxes  MATLAB and Control  Control System Toolbox  Simulink 7/2/2015MATLAB Control Toolbox2

%Define the transfer function of a plantG=tf([4 3],[1 6 5])

%Get data from the transfer function[n,d]=tfdata(G,'v')

[p,z,k]=zpkdata(G,'v')

[a,b,c,d]=ssdata(G)

%Check the controllability and observability of the system

ro=rank(obsv(a,c))rc=rank(ctrb(a,b))

%find the eigenvalues of the systemdamp(a)

%multiply the transfer function with another transfer function

T=series(G,zpk([-1],[-10 -2j +2j],5))

%plot the poles and zeros of the new systemiopzmap(T)

%find the bandwidth of the new systemwb=bandwidth(T)

%plot the step responsestep(T)

%plot the rootlocusrlocus(T)

%obtain the bode plotsbode(T)margin(T)

%use the LTI viewerltiview({'step';'bode';'nyquist'},T)

%start the SISO toolsisotool(T)

04/19/23 MATLAB Control Toolbox 44

M-File Example