Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

MATLAB Programming Lecture 4

Uploaded by

Ahmed Lasheen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

MATLAB Programming Lecture 4

Uploaded by

Ahmed Lasheen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

for internal use only Automation

Dr./ Essam and


Nabil
Drives

Lecture No.“4”
SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction

MATLAB
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis
The Language of
Curve fitting Technical Computing
Symbolic math.

Signal processing
Prepared by:
Function m-file
Dr./ Essam Nabil
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Flow Control
SIMATIC HMI
MATLAB
The Human
Programming
This section covers those MATLAB
Machine Interface
Introduction
functions that provide conditional program
MATLAB Basics
control and program control over program
Vectors & Arrays loops.
Math. Functions

Polynomials
Flow Control Statements
MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis Conditional


Curve fitting Control Loop Control
Symbolic math. if, else - for -statement
Signal processing statement while -
Function m-file switch, case - statement
MATLAB Simulink statement
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Flow Control
SIMATIC HMI
MATLAB
The Human
Relational Operators:
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis
Logical Operators:
Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Conditional Control Statements


SIMATIC HMI
if statement
MATLAB
The Human
Programming
Machine Interface
if statement used to execute code once
Introduction when the logical test (expression) returns a
MATLAB Basics true value (1). An "else" statement
Vectors & Arrays
following an if statement is executed if the
Math. Functions
same expression  isDiscount
false (0). in Sales
Polynomials
Syntax1: application
MATLAB plotting

2-D & 3-D Graphics


if expression price=input(‘Enter the
Flow Control
Statements1; price=‘)
System analysis
else if price>1000
Curve fitting
Statements2; discount=30/100
Symbolic math.
end else
Signal processing

Function m-file
discount=5/100
MATLAB Simulink
end
Final Test Faculty of Electronic Engineering
cost=price-price*discount
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Conditional Control Statements


Discount in Sales
SIMATIC HMI
MATLAB
The Human
Syntax2: application:
Programming
Machine Interface
price=input(‘Enter the total
Introduction
if expression1 price=‘);
MATLAB Basics
Statements1; if price>1000
Vectors & Arrays

Math. Functions
elseif discount=30/100
Polynomials
expression2 elseif price>900
MATLAB plotting
Statements2; discount=25/100
2-D & 3-D Graphics
elseif elseif price>800
Flow Control
expression3 discount=20/100
System analysis
statements3; elseif price>500
Curve fitting
… discount=10/100
Symbolic math. else else
Signal processing Statementsn; discount=5/100
Function m-file end end
MATLAB Simulink cost = price -
Final Test Faculty of Electronic Engineering price*discount
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Conditional Control Statements


SIMATIC HMI Note:
MATLAB
The Human
Programming To write multiple conditions in the expression we use
Machine Interface
Introduction
logical operators as: if
MATLAB Basics (x>0
switch-case ) & (x<=1)statement
Vectors & Arrays
switch statement executes one set of
Math. Functions
statements selected from an arbitrary
Polynomials
number of alternatives. Each alternative is
MATLAB plotting
called a case.
2-D & 3-D Graphics

Flow Control
Syntax1:
System analysis
switch expression (scalar or string)
Curve fitting
case value1
Symbolic math.
statement1;
Signal processing …
Function m-file otherwise
MATLAB Simulink statement, ..., statement
Final Test end
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Conditional Control Statements


Unit conversion to “centimeter”
SIMATIC HMI
MATLAB
The Human
Programming
application:
Machine Interface
value=input(‘Enter the value =‘);
Introduction
unit=input(‘Enter the unit =‘);
MATLAB Basics

Vectors & Arrays


switch unit
Math. Functions
case {‘inch’ , ‘in’}
output = value * 2.54
Polynomials
case {‘feet’ , ‘ft’}
MATLAB plotting
output = value * 2.54 *12
2-D & 3-D Graphics
case {‘meter’ , ‘m’}
Flow Control
output = value * 100
System analysis
case {‘centimeter’ , ‘cm’}
Curve fitting output = value
Symbolic math.
case {‘millimeter’ , ‘mm’}
Signal processing
output = value /10
Function m-file otherwise
MATLAB Simulink output=NaN
Final Test Faculty ofend
Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Loop Control Statements


SIMATIC HMI
MATLAB
for loop statement
The Human
Programming
Machine Interface For loop statement repeatedly executes
Introduction one or more MATLAB statements in a loop
MATLAB Basics
for a number of times.
Vectors & Arrays
Syntax1:
Math. Functions
for x=start : increment : end
Polynomials
statements; Y=[ ];
MATLAB plotting
end T =[ ];
2-D & 3-D Graphics for i= 1 :
Flow Control for i= 1 : 100 0.01 :10
System analysis y(i) = y = cos(pi*i);
Curve fitting cos(pi*i); Y=[Y y ];
Symbolic math.
t(i)=i; t=i;
Signal processing
end T =[T t ];
Function m-file
plot(t,y) end
MATLAB Simulink

Final Test
plot(T,Y)
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Loop Control Statements


SIMATIC HMI
while loop statement
MATLAB
The Human
Programming
Machine Interface while loop statement repeatedly executes
Introduction one or more MATLAB statements in a loop,
MATLAB Basics continuing until expression no longer holds
Vectors & Arrays
true (1) or until MATLAB encounters a
Math. Functions
break, or return instruction. thus forcing
Polynomials
an immediately exit of the loop.
MATLAB plotting
Syntax1:
2-D & 3-D Graphics

Flow Control
while expression n=0;
System analysis
Statements; while 2^n < 10
Curve fitting
end n=n+1
Symbolic math.

Signal processing
end
Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

System analysis
SIMATIC HMI
MATLAB
The Human
Any dynamical system are described by
Programming
Machine Interface set of differential equations that can be
Introduction
modeled in time-domain using state space
MATLAB Basics

Vectors & Arrays


representation or s-domain using transfer
Math. Functions
function.
Polynomials System model
MATLAB plotting

2-D & 3-D Graphics


State-space
Flow Control
Transfer function representation
System analysis
-used for SISO -used for MIMO
Curve fitting

Symbolic math. systems systems


Signal processing -Zero initial -Non zero initial
Function m-file conditions. conditions.
MATLAB Simulink -Linear system -Linear and
Final Test models
Faculty only.
of Electronic Engineering nonlinear
Industrial system
Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
Transfer functions are frequency-domain
Programming
Machine Interface representations of LTI systems. A SISO transfer
Introduction function is a ratio of polynomials:
MATLAB Basics

Vectors & Arrays

Math. Functions
To enter transfer function specify the
Polynomials
numerator and denominator polynomials:
MATLAB plotting
5
2-D & 3-D Graphics
G(s)=
Flow Control
-------------
System analysis

Curve fitting
s^2 + 2 s + 5
Symbolic math.
>>n=5;
Signal processing
>>d=[1 2 5];
Function m-file
>>printsys(n,d)
MATLAB Simulink
num/den =
Final Test
5
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
OR:
Programming
Machine Interface use tf function to construct the system
Introduction
transfer function :
MATLAB Basics
>> n=5;
Vectors & Arrays
>> d=[1 2 5];
Math. Functions
>> G=tf(n,d)
Polynomials
Transfer function:
MATLAB plotting
5
2-D & 3-D Graphics
-------------
Flow Control s^2 + 2 s + 5
Ex.1: 3 (s + 2)
System analysis
G(s)= -----------------------
Curve fitting

Symbolic math.
(s^2 + 4 s+ 5)
Signal processing
(s+3)
Function m-file
>> n=3*[1 2];
MATLAB Simulink
>> d=conv([1 4 5],[1 3]);
Final Test >> G=tf(n,d)
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface Ex.2:
Introduction
10 (s + 2)
MATLAB Basics

Vectors & Arrays


G(s)= -----------------------
Math. Functions
(s+1)(s+3)(s+5)
Polynomials
(s+10)
MATLAB plotting >> n=10*[1 2];
2-D & 3-D Graphics >> d=poly([-1 -3 -5 -10]);
Flow Control >> G=tf(n,d)
System analysis

Curve fitting OR:


Symbolic math. >> n=10*[1 2];
Signal processing >> d=conv( conv([1 1],[1 3]) , conv
Function m-file ([1 1],[1 3]) );
MATLAB Simulink >> G=tf(n,d)
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
Creation of Zero-Pole-Gain Models:
Programming
Machine Interface zpk function is used to create zero-pole-gain
Introduction
models (ZPK objects) or to convert TF or SS
MATLAB Basics
models to zero-pole-gain form.
Vectors & Arrays

Math. Functions
Syntax
Polynomials
sys = zpk ( z, p, k) %creates a
MATLAB plotting
continuous-time zero
2-D & 3-D Graphics
pole-gain model
Flow Control
with zeros z, poles
System analysis p, and gain(s) k.
Curve fitting Ex.2: 10 (s + 3)
Symbolic math. G(s)= ------------------
Signal processing (s+1)(s+2)(s+5)
Function m-file >> z=-3;
MATLAB Simulink >> p=[-1 -2 -5];
Final Test >>of Electronic
Faculty k=10; Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
System Response:
Programming
Machine Interface 1. Time response:
Introduction
 Impulse response:-
MATLAB Basics

Vectors & Arrays


>>impulse(G) %Plot impulse
Math. Functions
response with
Polynomials confidence
MATLAB plotting interval.
2-D & 3-D Graphics >>[y,t] = impulse(sys) %Calculate
Flow Control impulse response for
System analysis model object.
Curve fitting >>[y,t,x] = impulse(sys) % for state-
Symbolic math. space models only.
Signal processing

Function m-file  Step response:-


MATLAB Simulink >>step(G) %Plot step response
Final Test
with confidence
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
50 (s + 2)
Programming
Machine Interface G(s)= --------------------
Introduction
(s^2 + 4 s+ 25)(s+3)
MATLAB Basics

Vectors & Arrays


n=50*[1 2];
Math. Functions
d=conv([1 4 25],[1 3]);
Polynomials
G=tf(n,d)
MATLAB plotting
subplot(211)
2-D & 3-D Graphics
impulse(G)
xlabel( ‘Time (sec)’ )
Flow Control
ylabel( ‘System Output’ )
System analysis
title( ‘Impulse Response’ )
Curve fitting
subplot(212)
Symbolic math.
step(G)
Signal processing
xlabel( ‘Time (sec)’ )
Function m-file
ylabel( ‘System Output’ )
MATLAB Simulink title( ‘Step Response’ )
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human  Root locus diagram:-
Programming
Machine Interface
The root locus gives the closed-loop pole
Introduction
MATLAB Basics
trajectories as a function of the feedback gain
Vectors & Arrays
K (assuming negative feedback). Root locus
Math. Functions
are used to study the effects of varying
Polynomials
feedback gains on closed-loop pole locations.
In turn, these locations provide indirect
MATLAB plotting
information on the time and frequency
2-D & 3-D Graphics
responses.
Flow Control

System analysis
>>rlocus(G) %calculates and plots
Curve fitting

Symbolic math.
the root locus of
Signal processing
the open-loop SISO
Function m-file
model sys.
MATLAB Simulink
>>[r,k] = rlocus(sys) % return the
Final Test vector k of selected Industrial Electronics and Automatic Control Engineering
Faculty of Electronic Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
50 (s + 2)
Programming
Machine Interface G(s)= --------------------
Introduction
(s^2 + 4 s+
MATLAB Basics

Vectors & Arrays


25)(s+3)
Math. Functions
n=50*[1 2];
Polynomials
d=conv([1 4 25],[1 3]);
MATLAB plotting
G=tf(n,d)
2-D & 3-D Graphics
rlocus(G)
Flow Control
sgrid
System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
Programming
2. Frequency response:
Machine Interface  Bode plots:-
Introduction
MATLAB Basics
>>bode(G) % plots Bode
Vectors & Arrays
plot for the model G
Math. Functions >>[mag,phase,w] = bode(G) %
Polynomials computes the magnitude
MATLAB plotting mag and
2-D & 3-D Graphics phase values of the
Flow Control

System analysis frequency response.


Curve fitting >>[Gm,Pm,Wg,Wp] = margin(G)
Symbolic math. %computes the gain
Signal processing
margin Gm, the phase
Function m-file
margin Pm, and
MATLAB Simulink
the corresponding
Final Test
crossover frequencies Industrial Electronics and Automatic Control Engineering
Faculty of Electronic Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
50 (s + 2)
Programming
Machine Interface G(s)= --------------------
Introduction
(s^2 + 4 s+
MATLAB Basics

Vectors & Arrays


25)(s+3)
Math. Functions
n=50*[1 2];
Polynomials
d=conv([1 4 25],[1 3]);
MATLAB plotting
G=tf(n,d)
2-D & 3-D Graphics
bode(G)
Flow Control
grid on
System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
50 (s + 2)
Programming
Machine Interface G(s)= --------------------
Introduction
(s^2 + 4 s+
MATLAB Basics

Vectors & Arrays


25)(s+3)
Math. Functions
n=50*[1 2];
Polynomials
d=conv([1 4 25],[1 3]);
MATLAB plotting
G=tf(n,d)
2-D & 3-D Graphics
nyquist(G)
Flow Control
grid on
System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
Discrete-Time System Models
Programming
Machine Interface The discrete-time system models are
Introduction representational schemes for digital filters. The
MATLAB Basics
transfer function is a basic z-domain
Vectors & Arrays
representation of a digital filter, expressing the
Math. Functions
filter as a ratio of two polynomials.
Polynomials

MATLAB plotting >>n =1;


2-D & 3-D Graphics >>d= [1 0.3];
Flow Control >>Ts = 0.2;
System analysis >>H = tf(n,d,Ts)
Curve fitting Transfer function:
Symbolic math. 1
Signal processing
-------
Function m-file
z + 0.3
MATLAB Simulink
Sampling time: 0.2
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB Transforming Between Discrete-Time
The Human
Programming
Machine Interface and Continuous-Time Representations:
Introduction
>>sysd = c2d(sysc,Ts) %discretizes the
MATLAB Basics

Vectors & Arrays


continuous-time
Math. Functions
LTI model sys
Polynomials
using zero-order
MATLAB plotting
hold on the
2-D & 3-D Graphics inputs and a sample
Flow Control time of Ts
System analysis seconds.
Curve fitting >>sysd = c2d(sysc,Ts,method) %gives
Symbolic math. access to alternative discretization schemes.
Signal processing The string method selects the discretization
Function m-file method among the following:
MATLAB Simulink ‘zoh‘--------Zero-order hold. The control inputs
Final Test are
Facultyassumed
of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human s-1
Programming
Machine Interface
G(s)= --------------
Introduction
MATLAB Basics
s^2 + 4 s +
Vectors & Arrays
5
Math. Functions >>n= [1 -1];
Polynomials >>d= [1 4 5];
MATLAB plotting >>H=tf(n,d);
2-D & 3-D Graphics >>Hd =
Flow Control c2d(H,0.1,'foh')
System analysis Transfer function:
Curve fitting 0.04226 z^2 -
Symbolic math. 0.01093 z - 0.03954
Signal processing ----------------------------
Function m-file -----
MATLAB Simulink
z^2 - 1.629 z +
Final Test
0.6703
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
Programming >>sysc = d2c(sysd) %produces a
Machine Interface
Introduction
continuous-time model
MATLAB Basics sysc that is
Vectors & Arrays equivalent to the discrete
Math. Functions time LTI model sysd
Polynomials using zero-order
MATLAB plotting hold on the inputs.
2-D & 3-D Graphics >>sysc = d2c(sysd,method) %gives
Flow Control access to alternative
System analysis
conversion schemes.
Curve fitting
The string method
Symbolic math.
selects the conversion
Signal processing
method among
Function m-file
the following:
MATLAB Simulink
‘zoh‘ -----Zero-order hold on the inputs. The
Final Test Industrial Electronics and Automatic Control Engineering
control inputs
Faculty of Electronic Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human
(z+0.2)
Programming
Machine Interface
Introduction
H(z)=-------------------------
MATLAB Basics

Vectors & Arrays


(z+0.5) (z^2
Math. Functions
+ z + 0.4)
Polynomials
>>Ts = 0.1;
MATLAB plotting
>>H=tf([1 0.2],conv([1 0.5],[1 1
2-D & 3-D Graphics
0.4]),Ts);
Flow Control >>Hc = d2c(H)
System analysis Transfer function:
Curve fitting -33.66 s^3 - 741 s^2 -
Symbolic math. 2.908e004 s + 2.199e005
Signal processing -----------------------------------------------
Function m-file -----
MATLAB Simulink s^4 + 23.03 s^3 + 1799 s^2 +
Final Test 1.832e004 s + 6.596e005
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Transfer Function
SIMATIC HMI
MATLAB
The Human >>sysd2 = d2d(sysd1,Ts,method)
Programming
Machine Interface
%resamples the discrete
Introduction
time model sys to produce an
MATLAB Basics

Vectors & Arrays


equivalent
Math. Functions discrete-time model sys1 with
Polynomials new sample
MATLAB plotting time Ts (in seconds) using
2-D & 3-D Graphics resampling method
Flow Control among the following:
System analysis 'zoh' ---- Zero-order hold on the inputs
Curve fitting 'tustin' ---- Bilinear (Tustin) approximation
Symbolic math. 'prewarp' ---- Tustin approximation with
Signal processing frequency warping.
Function m-file Specify the critical frequency Wc
MATLAB Simulink (in rad/s) as a
Final Test Faculty of Electronic Engineering fourth input byElectronics
Industrial sysand=Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State Space Model


SIMATIC HMI
MATLAB
The Human
State space models are models that use
Programming
Machine Interface state variables to describe a system by a set of
Introduction first-order differential or difference equations.
MATLAB Basics State equation
Vectors & Arrays

Math. Functions
Output equation
Polynomials where
MATLAB plotting x :is the state vector ∈Rnx1
2-D & 3-D Graphics n :system order
Flow Control A :is the system matrix ∈Rnxn
System analysis B :is the control matrix ∈Rnxp
Curve fitting p :no. of inputs
Symbolic math. u :is the input control vector ∈Rpx1
Signal processing y :is the measured output ∈Rqx1
Function m-file
C :is the output matrix ∈Rqxn
MATLAB Simulink
q :no. of outputs
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State Space Model


SIMATIC HMI
MATLAB
The Human state-space model block diagram:
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State Space Model


SIMATIC HMI
MATLAB
The Human
>> sys = ss(A,B,C,D) %creates a State
Programming
Machine Interface space object
Introduction
representing the
MATLAB Basics

Vectors & Arrays


continuous-time
Math. Functions
state-space model.
Polynomials
>> [n,d] = ss2tf(A,B,C,D,iu) % converts a
state-space
MATLAB plotting
representation of a given system
2-D & 3-D Graphics
to an equivalent
Flow Control transfer function representation
System analysis from the iu-th input.
Curve fitting >> [A,B,C,D] = tf2ss(n,d) % converts the
Symbolic math. parameters of a
>>sys = ss([0 1;-5 -2],
Signal processing transfer function representation
[0;3],[0 1],0); to
of a given system
Function m-file
>> step(sys) those of an equivalent state-
MATLAB Simulink
space representation.
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State feedback controller design


using pole-placement method
SIMATIC HMI
MATLAB
The Human Controllability matrix
Programming
Machine Interface
Introduction
MATLAB Basics

The system is said to be completely controllable if


Vectors & Arrays

Math. Functions

Polynomials
rank(Cm) =n
MATLAB plotting

2-D & 3-D Graphics Synatx:


Flow Control

System analysis >>Cm = ctrb(A,B) %calculates the


Curve fitting controllability
Symbolic math.
matrix of the
Signal processing
state-space model
Function m-file

MATLAB Simulink
OR:
Final Test
>> Cm = ctrb(sys) Industrial%calculates the
Electronics and Automatic Control Engineering
Faculty of Electronic Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State feedback controller design


using pole-placement method
SIMATIC HMI
MATLAB
The Human state-feedback controller design:
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting Control law


Symbolic math.

Signal processing where


Function m-file K :is controller gain matrix ∈Rpxn
MATLAB Simulink r :is the reference input
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State feedback controller design


using pole-placement method
SIMATIC HMI
MATLAB
The Human
Programming
The closed-loop system equation will be:
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays


 The closed-loop system characteristic equation:
Math. Functions

Polynomials

MATLAB plotting -------


2-D & 3-D Graphics (1)
 The desired characteristic equation is given as:
Flow Control

System analysis

-------
Curve fitting

Symbolic math.

Signal processing
Equating coefficients of (2)
Function m-file
equations (1) and (2) and solving
MATLAB Simulink

Final Test
for the controller gain matrix K
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State feedback controller design


using pole-placement method
SIMATIC HMI
MATLAB
The Human Pole placement design using MATLAB:
Programming
Machine Interface
Introduction >>K = place(A,B,p) %computes a
MATLAB Basics feedback gain matrix
Vectors & Arrays
K that achieves
Math. Functions
the desired closed
Polynomials
loop pole
MATLAB plotting
locations p
2-D & 3-D Graphics
OR:
Flow Control
>>K = acker(A,B,p) %computes a
System analysis
feedback gain matrix
Curve fitting

Symbolic math.
K for the desired
Signal processing
closed loop pole
Function m-file
p, using
MATLAB Simulink
Ackermann's formula.
Final Test Notes:
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

State feedback controller design


using pole-placement method
SIMATIC HMI
MATLAB
The Human Application example:
Programming
Machine Interface
Introduction
clear,clc
MATLAB Basics
%The system state-space model
Vectors & Arrays parameters
Math. Functions A = [0 1 0;0 0 1;-12 -19 -8];
Polynomials
B = [0;0;1];
MATLAB plotting
C = [1 0 0];
2-D & 3-D Graphics
Cm = ctrb(A,B) %computes
Flow Control
Controllability matrix
System analysis
Cm_test=det(Cm)
Curve fitting
%controllability test
Symbolic math.

Signal processing
if(Cm_test~=0)
Function m-file
p=[-1 -2 -3]; %The desired
MATLAB Simulink
closed-loop poles i.e. p
Final Test
K = place(A,B,p) Industrial%finds
Faculty of Electronic Engineering
controller
Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Observer design
using pole-placement method
SIMATIC HMI
MATLAB
The Human Observability matrix
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting
The system is said to be completely
2-D & 3-D Graphics
state observable
Flow Control
if only: rank(Om) =n
Synatx:
System analysis
>>Om = obsv(A,B) %calculates the
Curve fitting

Symbolic math.
observability
Signal processing
matrix of the
Function m-file
state-space model
MATLAB Simulink OR:
Final Test >> Om = obsv (sys) %calculates
Industrial Electronics
Faculty of Electronic Engineering and Automatic Controlthe
Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Observer design
using pole-placement method
SIMATIC HMI
MATLAB
The Human
Programming
Observer schematic diagram:
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Observer design
using pole-placement method
SIMATIC HMI
MATLAB
The Human
The observer state equations will be:
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions
State estimation error is given by:
Polynomials

MATLAB plotting

2-D & 3-D Graphics


 The observer characteristic equation:
Flow Control

System analysis -------


 The desired characteristic equation is given as:
Curve fitting

Symbolic math.
(1)
-------
Signal processing

Function m-file
Equating coefficients of equations (1) and
MATLAB Simulink (2) L
(2) and solving for observer gain matrix
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Observer design
using pole-placement method
SIMATIC HMI
MATLAB
The Human Observer design using MATLAB:
Programming
Machine Interface
Introduction >>L = place(A’,C’,p) %computes
MATLAB Basics observer gain matrix
Vectors & Arrays
L for the
Math. Functions
desired poles locations p
Polynomials
OR:
MATLAB plotting

2-D & 3-D Graphics


>>L = acker(A’,C’,p) %computes
Flow Control
observer gain matrix
System analysis
L for the
Curve fitting

Symbolic math.
desired poles locations p
Signal processing
using
Function m-file
Ackermann's formula.
MATLAB Simulink
Notes:
Final Test
 The length of p must
Faculty of Electronic Engineering
match the row
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Observer design
using pole-placement method
SIMATIC HMI
MATLAB
The Human Application example:
Programming
Machine Interface
Introduction
clear,clc
MATLAB Basics
%The system state-space model
Vectors & Arrays parameters
Math. Functions A = [0 1 0;0 0 1;-12 -19 -8];
Polynomials
B = [0;0;1];
MATLAB plotting
C = [1 0 0];
2-D & 3-D Graphics
Om = obsv(A,C) %computes
Flow Control
Observability matrix
System analysis
Om_test=det(Om)
Curve fitting
%Observability test
Symbolic math.

Signal processing
if(Om_test~=0)
Function m-file
p=[-5 -10 -30]; %The desired
MATLAB Simulink
Observer poles i.e. p
Final Test
L = place(A’,C’,p) Industrial Electronics
Faculty of Electronic Engineering
%finds and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

End of Lecture No. “4”


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering

You might also like