Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

PLC Level Control of Two Tanks

This is PLC Program for Level Control of Two Tanks

Problem Description
Two simultaneous process are to be performed in two separate tanks which are connected
through a valve. First Process takes place in process tank 1 and second process takes place in
tank 2. Write the ladder program for level controlling of two tanks in PLC.

Problem Diagram

Problem Solution

 Arrange two pressure controlled tanks for processes. Process 1 will be done in process
1 tank and process 2 will be done in process 2 tank.
 Use an inlet vale for material inlet in process 1 tank. Add one more valve between
two tanks as a connecting valve.
 Consider two sensors (High and Low) for process 1 tank and consider only low sensor
for process 2 tank.
 For this application we can use PLC, we will write PLC program for this application.

List of inputs/outputs

Digital Inputs

 Cycle START :- I0.0


 Cycle STOP :- I0.1
 Low level process 1 tank (LL1) :- I0.3
 Low level process 2 tank (LL2) :- I0.4
 High level process tank 1 (LH1) :- I0.5
 Process 1 done :- I1.0
 Process 2 done :- I1.1

Digital Outputs

 Inlet valve :- Q0.0


 Connecting valve :- Q0.1
 Outlet Valve :- Q0.2

M memory

 Cycle ON bit :- M0.0

PLC Ladder diagram for level controlling of two tanks


Program Description

For this application we used S7-300 PLC and TIA portal software for programming. We can
implement this logic by using other PLC also.

Network 1 :-

Network 1 is for latching circuit. Whenever START button is pressed (I0.0), Cycle ON
(M0.0) bit will be ON. Cycle can be STOP by pressing STOP PB (I0.1).

Network 2 :-

If LL1 (I0.2) is detected and cycle START is pressed, an inlet valve (Q0.0) will be ON.
Consider LH 1(I0.3) interlock during this function.

Network 3 :-

When the level of material of process tank 1 goes high hence LH 1(I0.3) is detected and level
of material in process 2 tank goes low, connecting valve (Q0.1) will be ON. This function
takes place while PLC is detecting process 1 done command.

Network 4 :-

When process 2 is completed and process 2 tank is not low, an outlet valve (Q0.2) will be
ON. Cycle ON bit (M0.0) should be ON during the whole cycle.

Note :- Above application may be different from actual application. This example is only for
explanation purpose only. We can implement this logic in other PLC also.

Runtime Test Cases

Author : Bhavesh
State Feedback Controller Design Using
Pole Placement Technique
3 Replies

Description: Aim is:

To design full state feedback control


To determine gain matrix K to meet the requirement
To plot response of each state Variable

Pre-Requisitive: Knowledge of State Space Model and Pole Placement Technique.

Full State Feedback or Pole Placement is a method employed in feedback control system
theory to place the closed loop poles of a plant in a pre determined locations in the s-plane 
placing poles is desirable because the location of the poles corresponds directly to the eigen
values of system which control the characterstics of the response of the system, the system
must be considered controllable to implement this method.

If the closed loop input-output transfer function can be represented by a state space equation
as :

where,
A = System Matrix
X = State Vector
B = Control input Matrix
U = Input Vector
C = Output Matrix
Y = Output Vector
D = Direct Matrix
Then the poles of the system are the roots of the characteristic equation given by

Full state feedback is utilized by commanding the input vector u. Consider an input
proportional to the state vector u = -Kx
Substituting in state space equation we get:

y = (C-DK)x[\latex]

The roots of Full state feedback system is given by: |𝑠I−(𝐴−𝐵K)|[\latex]

Comparing the terms of this equation with those of the desired characterstic equation yields
the value of the feedback matrix K which force the closed loop eigen values to the pole
locations specified by the desired characterstic equation.
Close Loop Control with U = -Kx

Matlab Program
Design the full state feedback controller of the given system using pole placement technique
with desired poles as given. Find the initial response of each state variable. (The Bold part in
the program is the given portion of the question)

Advertisement
REPORT THIS AD

%--------------------------------------------------------------------------
% Experiment 8 - State Feedback Controller Design Using Pole Placement
% Technique
% By Siddharth Kaul
%--------------------------------------------------------------------------
%
% x. = Ax + Bu
% y = Cx + Du
%
% Given -------------------------------------------------------------------
MatrixA = [0 1 0;0 0 1;-1 -5 -6];
MatrixB = [0; 0; 1];
MatrixC = [1 0 0];
MatrixD = [0];
initialX = [1;0;0];
% Desired Poles are -------------------------------------------------------
desiredPoles = [-2+4i -2-4i -10];
% Feedback controller K becomes -------------------------------------------
% Note:- Using Ackerman Formula instead of Place to remove mismatching
% -------------------------------------------------------------------------
GainK = acker(MatrixA,MatrixB,desiredPoles);
disp('Feedback Gain Matrix: ');
disp(GainK);
% -------------------------------------------------------------------------
% Using this GainK in formula sI - (A- BK) we will get a new MatrixA. Using
% this new MatrixA finding our new System with this feedback controller
% gain.
% -------------------------------------------------------------------------
newMatrixA = MatrixA - (MatrixB*GainK);
newMatrixB = eye(3);
newMatrixC = eye(3);
newMatrixD = eye(3);
mysys = ss(newMatrixA,newMatrixB,newMatrixC,newMatrixD);
% Now Initial REsponse with the GainK -------------------------------------
timeT = 0:.1:10;
x = initial(mysys,initialX,timeT);
x1 = [1 0 0]*x';
x2 = [0 1 0]*x';
x3 = [0 0 1]*x';
% Plotting the response ---------------------------------------------------
plot(timeT,x1,'r',timeT,x2,'b',timeT,x3,'g');
title('Response to initial Condition of State Variables');
xlabel('Time -->');
ylabel('Magnitude -->');
% -------------------------------------------------------------------------
% End of Program. Created By Siddharth Kaul
% -------------------------------------------------------------------------

Output:
Feedback Gain Matrix:
199 55 8
State Variable Responses to initial Condition

Controllability and Observabillity of State


Space Model
2 Replies

Objectives of Experiment:

1. To find system is controllable or not.


2. To find system is observable or not.
3. To find rank of matrix and using rank comment on system controllability and
observability

Background:
Controllabilty
A system is said to be controllable if all the states are completely controllable. A system can
also be considered as controllable, if every state of system can be excerised control in such a
manner that the state are transferred from an initial state to desired state in some finite time.
System given by:

where,
A = System Matrix
X = State Vector
B = Control input Matrix
U = Input Vector
C = Output Matrix
Y = Output Vector
D = Direct Matrix
The state x(t) at t=0 is said to be controllable, if the state can be driven to a desired state x(tf)
in some finite time t = tf by application of continous control input u(t).

Testing for controllability


Controllable matrix Qc

and

Observability
A system is said to be observable if the state can be determined from the knowledge of the
input U(t)
and the output Y(t) over a finite interval of time. Again the system given by:

where,
A = System Matrix
X = State Vector
B = Control input Matrix
U = Input Vector
C = Output Matrix
Y = Output Vector
D = Direct Matrix
The state x(t0) at t= t0 for a system is said to be observable if for a desired finite time t=
tf>t0, knowledge of input u(t) and output y(t) over the interval t0<t<tf can be calculated.
Testing for Observability
Observable matrix Qb

and

Matlab Program
%-------------------------------------------------------------------------
-
% Experiment 3 - Controllability and Observability
% By Siddharth Kaul
%-------------------------------------------------------------------------
-
%
% State Space Representation
% x' = Ax + Bu
% y = Cx + Du
%
% Problem 1
---------------------------------------------------------------
% Check Controllability and Observability of a 2nd order System
% Given
-------------------------------------------------------------------
MatrixA = [0 1;-2 -3];
MatrixB = [0;1];
MatrixC = [1 -1];
MatrixD = 0;
% Objective
---------------------------------------------------------------
% 1) To Find Controllable Matrix Qc, its rank and check controllability
% 2) To Find Observable Matrix Qb, its rank and check observability
%-------------------------------------------------------------------------
-
% Controllable Matrix
-----------------------------------------------------
Qc = ctrb(MatrixA,MatrixB);
rankQc = rank(Qc);
disp('Controllable Matrix is Qc = ');
disp(Qc);
if(rankQc == rank(MatrixA))
disp('Given System is Controllable.');
else
disp('Given System is Uncontrollable');
end
% Observable Matrix
-------------------------------------------------------
Qb = obsv(MatrixA, MatrixC);
rankQb = rank(Qb);
disp('Observable Matrix is Qb = ');
disp(Qb);
if(rankQb == rank(MatrixA))
disp('Given System is Observable.');
else
disp('Given System is Unobservable');
end
% End of Program
----------------------------------------------------------

Output
Controllable Matrix is Qc =
0 1
1 ‐3
Given System is Controllable.
Observable Matrix is Qb =
1 ‐1
2 4
Given System is Observable.

Matlab Program
%-------------------------------------------------------------------------
-
% Experiment 3 - Controllability and Observability
% By Siddharth Kaul
%-------------------------------------------------------------------------
-
%
% State Space Representation
% x' = Ax + Bu
% y = Cx + Du
%
% Problem 2
---------------------------------------------------------------
% Check Controllability and Observability of a 3rd order System
% Given
-------------------------------------------------------------------
MatrixA = [-1 1 0;4 0 -3;-6 8 10];
MatrixB = [1;0;-1];
MatrixC = [1 2 1];
MatrixD = 0;
% Objective
---------------------------------------------------------------
% 1) To Find Controllable Matrix Qc, its rank and check controllability
% 2) To Find Observable Matrix Qb, its rank and check observability
%-------------------------------------------------------------------------
-
% Controllable Matrix
-----------------------------------------------------
Qc = ctrb(MatrixA,MatrixB);
rankQc = rank(Qc);
disp('Controllable Matrix is Qc = ');
disp(Qc);
if(rankQc == rank(MatrixA))
disp('Given System is Controllable.');
else
disp('Given System is Uncontrollable');
end
% Observable Matrix
-------------------------------------------------------
Qb = obsv(MatrixA, MatrixC);
rankQb = rank(Qb);
disp('Observable Matrix is Qb = ');
disp(Qb);
if(rankQb == rank(MatrixA))
disp('Given System is Observable.');
else
disp('Given System is Unobservable');
end
% End of Program
----------------------------------------------------------

Output
Controllable Matrix is Qc =
1 ‐1 8
0 7 44
‐1 ‐16 ‐98
Given System is Controllable.
Observable Matrix is Qb =
1 2 1
1 9 4
11 33 13
Given System is Observable.

Matlab Program
%-------------------------------------------------------------------------
-
% Experiment 3 - Controllability and Observability
% By Siddharth Kaul
%-------------------------------------------------------------------------
-
%
% State Space Representation
% x' = Ax + Bu
% y = Cx + Du
%
% Problem 3
---------------------------------------------------------------
% Check Controllability and Observability of a 3rd order System
% Given
-------------------------------------------------------------------
MatrixA = [-3 -1 0;2 0 0;0 -1 -1];
MatrixB = [1;0;1];
MatrixC = [1 0 1];
MatrixD = 0;
% Objective
---------------------------------------------------------------
% 1) To Find Controllable Matrix Qc, its rank and check controllability
% 2) To Find Observable Matrix Qb, its rank and check observability
%-------------------------------------------------------------------------
-
% Controllable Matrix
-----------------------------------------------------
Qc = ctrb(MatrixA,MatrixB);
rankQc = rank(Qc);
disp('Controllable Matrix is Qc = ');
disp(Qc);
if(rankQc == rank(MatrixA))
disp('Given System is Controllable.');
else
disp('Given System is Uncontrollable');
end
% Observable Matrix
-------------------------------------------------------
Qb = obsv(MatrixA, MatrixC);
rankQb = rank(Qb);
disp('Observable Matrix is Qb = ');
disp(Qb);
if(rankQb == rank(MatrixA))
disp('Given System is Observable.');
else
disp('Given System is Unobservable');
end
% End of Program
----------------------------------------------------------

Output
Controllable Matrix is Qc =
1 ‐3 7
0 2 ‐6
1 ‐1 ‐1
Given System is Controllable.
Observable Matrix is Qb =
1 0 1
‐3 ‐2 ‐1
5 4 1
Given System is Unobservable

To perform a block diagram reduction


using MATLAB
6 Replies

It’s not convenient to derive a complex transfer function for a complex control system,
therefore, the transfer function of each element of a control system is represented by a block
diagram and the concerned system mentioned in the block represents the transfer function of
the element. This symbolic representation in short form gives a pictorial representation
relating the output and the input of a control system based on cause and effect approach.

Simple Block Diagram

Block diagram shown above. Here G1(s) and G2(s) represents the transfer function of the
individual elements of a control system. The system given is a feedback system or can also be
called a closed loop system. The output signal C(s) is fed back to be compared with the input
R(s) , the difference E(s)=[R(s)– C(S)] is actuating signal or error signal.

Problem: To reduce the given block diagram using sumblk and find impulse,step and ramp
response.
Given Block Diagram

Matlab Program
%--------------------------------------------------------------------------
% Experiment 2 - Block Diagram Reduction
% By Siddharth Kaul

%--------------------------------------------------------------------------
%
% Reduce the given Block Diagram using sumblk function.
% [see the image attached]
%
% Given
-------------------------------------------------------------------
s = tf('s');
G1 = 1/(s+1);
G2 = 2/((s^2) + (5*s) + 100);
G3 = 10/((2*s) +1);
G4 = 100/(s+1);

%--------------------------------------------------------------------------
% Now we are required to define all the blocks input and output. As shown
% below. Using these defined input output we will be using sumblk
---------
G1.InputName = 'r';
G1.OutputName = 'ug1';
G2.InputName = 'e';
G2.OutputName = 'ug2';
G3.InputName = 'ym';
G3.OutputName = 'y';
G4.InputName = 'u';
G4.OutputName = 'ym';

%--------------------------------------------------------------------------
% Note: Now we are required to relate all these inputs and outputs. Why??
% Because there are two summing points in our block diagram. This way
% matlab will be able to relate the transfer fuction with each other.
% You can notice ym is our output and its not attached to any summing
point
% hence it is not included in the summing.

%--------------------------------------------------------------------------
sum1 = sumblk('e','r','y','+-'); % e = r - y
sum2 = sumblk('u','ug1','ug2'); % u = ug1 + ug2
% Rest is pretty simple
---------------------------------------------------
% we have to find the relationship between r and ym for our output
transfer
% function.
---------------------------------------------------------------
OutputTF = connect(G1,G2,G4,G3,sum1,sum2,'r','ym');

%--------------------------------------------------------------------------
% Calculating responses. Responses taken into account are step and
% ramp. Others can also be included. A generalised form has been given
% below.

%--------------------------------------------------------------------------
% First Impulse
-----------------------------------------------------------
inputTime = [0:.1:10];
[outputResp, time] = impulse(OutputTF, inputTime);
subplot(3,1,1);
plot(time, outputResp);
title('Impulse Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Step Response
-----------------------------------------------------------
inputTime = [0:.1:10];
inputSignal = ones(size(inputTime));
[outputResp, time] = step(OutputTF);%, inputSignal, inputTime);
subplot(3,1,2);
plot(time,outputResp);
title('Step Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Ramp Response
-----------------------------------------------------------
inputTime = [0:.1:10];
inputSignal = 1*inputTime;
[outputResp, time] = lsim(OutputTF, inputSignal, inputTime);
subplot(3,1,3);
plot(time,outputResp);
title('Ramp Response');
xlabel('Time -->');
ylabel('Magnitude -->');
%
-------------------------------------------------------------------------
% End of Program. Created By Siddharth Kaul
%
-------------------------------------------------------------------------
Output:

Given Block Diagram’s Output Response

Design of Full Order and Reduced


Order Observer
1 Reply

A Little Theory:
If the closed loop input-output transfer function can be represented by a state space equation
as :

where,
A = System Matrix
X = State Vector
B = Control input Matrix
U = Input Vector
C = Output Matrix
Y = Output Vector
D = Direct Matrix

Block Diagram of system and a full order observer

In the problem of pole placement by state feedback, the control law is U = -Kx + r.
The control system design problem of pole placement by state feedback requires feedback of
all the state variables. In practice, however not all state variables are available for
measurement and feedback. In such situation we need to estimate unmeasurable state
variables.
The estimation of unmeasurable state variables is commonly called observation. A device (or
a computer program) that estimates or observes the state variables is called State Observer. If
the state observes, all the state variables of the system, its called a full order state observer.
The observer is basically a copy of the plant; it has the same input and almost the same
differential equation. An extra term compares the actual measured output y to the estimated
output ŷ; this will cause the estimated states to approach the values of the actual states x. The
error dynamics of the observer are given by the poles of (A-L*C).

Reduced Order Observer


The observers discussed thus far are designed to reconstruct all the state variables. In
practice, some of the state variables may be accurately measured. Such accurately measurable
state variables need not be estimated. Suppose that the state vector x is an n-vector and the
output vector y is an m-vector that can be measured. Since m output variables are linear
combinations of the state variables, m state variables need not be estimated. We need to
estimate only n-m state variables. Then the reducedorder observer becomes an (n-m)th-order
observer. Such an (n-m)th-order observer is the minimum-order observer.
Problem:
Design a full order and a reduced order observer for the given transfer function. The Observer
should be 10 times faster than the state feedback controller with 20.8% overshoot and 4
seconds settling time.

at poles = -100,-10,-10

Matlab Program
%--------------------------------------------------------------------------
% Experiment 10 - Full Order and Reduced Order Observer Design
% By Siddharth Kaul

%--------------------------------------------------------------------------
%
% Given
-------------------------------------------------------------------
num = [1 4];
den = [1 8 17 10];
sys = tf(num,den);
desiredPoles = [-100 -10 -10];
disp('Given Transfer Function: ');
sys
% Now finding whether observable or not
-----------------------------------
[MatrixA,MatrixB,MatrixC,MatrixD] = tf2ss(num,den);
mysys = canon(ss(MatrixA,MatrixB,MatrixC,MatrixD),'companion');
% If observable then only continue other wise no oberver design possible
--
if(rank(MatrixA)==rank(mysys.A))
disp('System is Observable');
% Observer Design Possible --------------------------------------------
observerGain = acker(MatrixA.',MatrixC.',desiredPoles.').';
disp('Observer Gain Matrix');
disp(observerGain);
% New System with observer --------------------------------------------
newMatrixA = MatrixA - (observerGain*MatrixC);
newMatrixB = eye(rank(MatrixA));
newMatrixC = eye(rank(MatrixA));
newMatrixD = eye(rank(MatrixA));
mysys = ss(newMatrixA,newMatrixB,newMatrixC,newMatrixD);
mysys;
timeT = 0:.1:2;
initialX = [1 0 0];
x = initial(mysys, initialX,timeT);
x1 = [1 0 0]*x';
x2 = [0 1 0]*x';
x3 = [0 0 1]*x';
subplot(3,1,1);
plot(timeT,x1,'r',timeT,x2,'g',timeT,x3,'b');
title('Response to initial Condition of State Variables Observer');
xlabel('Time -->');
ylabel('Magnitude -->');
disp('New System Matrix A');
disp(newMatrixA);
else
disp('System is Unobservable');
% No observer design possible -----------------------------------------
end
%--------------------------------------------------------------------------
% Now first we need to make controller with given specification of 20.8%
% overshoot and 4 seconds settling time. For such a controller we
% calculated the required poles to be
% [-1+.637i -1-.637i -4]
%--------------------------------------------------------------------------
% So ----------------------------------------------------------------------
% we already have MatrixA -------------------------------------------------
desiredPoles = [-1+.637i -1-.637i -4];
controllerGain = acker(MatrixA,MatrixB,desiredPoles);
disp('Controller Gain is ');
disp(controllerGain);
newMatrixA = MatrixA - (MatrixB*controllerGain);
newMatrixB = eye(3);
newMatrixC = eye(3);
newMatrixD = eye(3);
initialX = [1 0 0];
timeT = 0:.1:5;
mysys = ss(MatrixA,newMatrixB,newMatrixC,newMatrixD);
x = initial(mysys, initialX,timeT);
x1 = [1 0 0]*x';
x2 = [0 1 0]*x';
x3 = [0 0 1]*x';
subplot(3,1,2);
plot(timeT,x1,'r',timeT,x2,'g',timeT,x3,'b');
title('Response to initial Condition of State Variables Controller');
xlabel('Time -->');
ylabel('Magnitude -->');
%--------------------------------------------------------------------------
% Now finding the reduced order observer that is 10 times faster than the
% designed controller.
% With this criteria in mind we can get the MatrixAaa, MatrixAb and so on
% and the desired observer poles becomes -10+6.377i -10-6.477i
%--------------------------------------------------------------------------
% So ----------------------------------------------------------------------
MatrixAaa = [0];
MatrixAab = [1 0];
MatrixAba = [0;-10];
MatrixAbb = [0 1;-17 -8];
desiredObserverPoles = [-10+6.377i -10-6.377i];
observerGain = acker(MatrixAbb.',MatrixAab.',desiredObserverPoles.').'
newMatrixAAbb = MatrixAbb - (observerGain*MatrixAab);
newMatrixB = eye(2);
newMatrixC = eye(2);
newMatrixD = eye(2);
mysys = ss(newMatrixAAbb,newMatrixB,newMatrixC,newMatrixD);
initialX = [1 0];
timeT = 0:.1:2;
x = initial(mysys,initialX,timeT);
x1 = [1 0]*x';
x2 = [0 1]*x';
subplot(3,1,3);
plot(timeT,x1,'r',timeT,x2,'g');
title('Response to initial Condition of State Variables Reduced Observer');
xlabel('Time -->');
ylabel('Magnitude -->');
% -------------------------------------------------------------------------
% End of Program. Created By Siddharth Kaul
% -------------------------------------------------------------------------

Output:

Observer Output

To find solution of state space equation


10 Replies

Example Objectives: To find solution of state space equation

1. To find state transition matrix


2. To find zero input response
3. To find zero state response
4. To find complete response

Background: Zero input and zero state solution of a system can be found if the state space
representation of system is known. A state space system is defined as follows:

where,
A = System Matrix
X = State Vector
B = Control input Matrix
U = Input Vector
C = Output Matrix
Y = Output Vector
D = Direct Matrix

The State Transition Matrix


It is an important part of both zero input and zero state response of a system represented as
state space. Denoted as:

This matrix exponential carries out the transition of state during time t.

The Complete Response 


Lets solve. Modifying equation we get:

Multiplying both sides by . We get:

Integrating between 0 and t. We get


The solution x(t) is clearly the sum of a zero input response and zero state response. The zero
state response rises from input vector. For simple calculation lets take laplace transform of
above equation:

The last equation can be used to simplify our solution and then after simplification we can
take the laplace inverse to get our required response.

Matlab Program
%-------------------------------------------------------------------------
-
% Experiment - Solution of State Space
% By Siddharth Kaul
%-------------------------------------------------------------------------
-
%
% State Space Representation
% x' = Ax + Bu
% y = Cx + Du
%
% Practice Problem
--------------------------------------------------------
% Find State transition matrix of given state space system
% Given
-------------------------------------------------------------------
MatrixA = [0 1;-2 -3];
MatrixB = [0;1];
MatrixC = [1 -1];
MatrixD = 0;
InitialX = [1;2];
MatrixI = [1 0;0 1];
sys = ss(MatrixA,MatrixB,MatrixC,MatrixD);
% Create Symbolic Object s
------------------------------------------------
syms s;
% Assume
------------------------------------------------------------------
% MatrixSTM as state transition matrix order 2x2 with elements of inverse
% of resilient matrix ILT.
%
-------------------------------------------------------------------------
ILT = (((s*MatrixI) - MatrixA)^-1);
MatrixSTM = [ilaplace(ILT(1,1)) ilaplace(ILT(1,2));ilaplace(ILT(2,1))
ilaplace(ILT(2,2))];
simplify(MatrixSTM);
% Display State Transition Matrix
-----------------------------------------
disp('State Transition Matrix is = ');
disp(MatrixSTM);
% Calculating Zero Input Response
-----------------------------------------
zeroResP = MatrixSTM*InitialX;
disp('Zero Input Response is = ');
disp(zeroResP);
% Plotting Zero Input Response
--------------------------------------------
timeT = linspace(0,10);
u = ones(size(timeT));
ZeroIPResp = initial(sys,InitialX,timeT);
subplot(3,1,1);
plot(timeT,ZeroIPResp);
grid on;
title('Zero Input Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Calculating Zero State Response
-----------------------------------------
zeroStateResP = laplace(MatrixSTM)*MatrixB*1; % assuming step input hence
1
disp('Zero State Response is = ');
disp(ilaplace(zeroStateResP));
% Plotting Zero State Response
--------------------------------------------
ZeroStateResP = lsim(sys,u,timeT);
subplot(3,1,2);
plot(timeT,ZeroStateResP);
grid on;
title('Zero State Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Calculating Complete Response
-------------------------------------------
compResP = zeroResP + ilaplace(zeroStateResP);
disp('Complete Response is = ');
disp(compResP);
% Plotting Complete Response
----------------------------------------------
CompleteResP = ZeroIPResp + ZeroStateResP;
subplot(3,1,3);
plot(timeT,CompleteResP);
grid on;
title('Complete Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Combining All Plots
-----------------------------------------------------
subplot(1,1,1);
plot(timeT,ZeroIPResp, timeT,ZeroStateResP, timeT,CompleteResP);
grid on;
title('Combine Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% End of Program
----------------------------------------------------------

Output
State Transition Matrix is =
[ 2/exp(t) ‐ 1/exp(2*t), 1/exp(t) ‐ 1/exp(2*t)]
[ 2/exp(2*t) ‐ 2/exp(t), 2/exp(2*t) ‐ 1/exp(t)]
Zero Input Response is =
4/exp(t) ‐ 3/exp(2*t)
6/exp(2*t) ‐ 4/exp(t)
Zero State Response is =
1/exp(t) ‐ 1/exp(2*t)
2/exp(2*t) ‐ 1/exp(t)
Complete Response is =
5/exp(t) ‐ 4/exp(2*t)
8/exp(2*t) ‐ 5/exp(t)

Independent Responses
Combined Responses

Another Problem for Reference

Matlab Program
%-------------------------------------------------------------------------
-
% Experiment 2 - Solution of State Space
% By Siddharth Kaul
%-------------------------------------------------------------------------
-
%
% Practice Problem
--------------------------------------------------------
% Find State transition matrix of given state space system and find zero
% input and zero state response and plot their graph.
% Given
-------------------------------------------------------------------
MatrixA = [0 1;-8 -6];
MatrixB = [0;1];
MatrixC = [0 1];
MatrixD = 0;
InitialX = [1;0];
MatrixI = [1 0;0 1];
sys = ss(MatrixA,MatrixB,MatrixC,MatrixD);
% Create Symbolic Object s
------------------------------------------------
syms s;
% Assume
------------------------------------------------------------------
% MatrixSTM as state transition matrix order 2x2 with elements of inverse
% of resilient matrix ILT.
%
-------------------------------------------------------------------------
ILT = (((s*MatrixI) - MatrixA)^-1);
MatrixSTM = [ilaplace(ILT(1,1)) ilaplace(ILT(1,2));ilaplace(ILT(2,1))
ilaplace(ILT(2,2))];
simplify(MatrixSTM);
% Display State Transition Matrix
-----------------------------------------
disp('State Transition Matrix is = ');
disp(MatrixSTM);
% Calculating Zero Input Response
-----------------------------------------
zeroResP = MatrixSTM*InitialX;
disp('Zero Input Response is = ');
disp(zeroResP);
% Plotting Zero Input Response
--------------------------------------------
timeT = linspace(0,10);
u = ones(size(timeT));
ZeroIPResp = initial(sys,InitialX,timeT);
subplot(3,1,1);
plot(timeT,ZeroIPResp);
grid on;
title('Zero Input Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Calculating Zero State Response
-----------------------------------------
zeroStateResP = laplace(MatrixSTM)*MatrixB*1; % assuming step input hence
1
disp('Zero State Response is = ');
disp(ilaplace(zeroStateResP));
% Plotting Zero State Response
--------------------------------------------
ZeroStateResP = lsim(sys,u,timeT);
subplot(3,1,2);
plot(timeT,ZeroStateResP);
grid on;
title('Zero State Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Calculating Complete Response
-------------------------------------------
compResP = zeroResP + ilaplace(zeroStateResP);
disp('Complete Response is = ');
disp(compResP);
% Plotting Complete Response
----------------------------------------------
CompleteResP = ZeroIPResp + ZeroStateResP;
subplot(3,1,3);
plot(timeT,CompleteResP);
grid on;
title('Complete Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% Combining All Plots
-----------------------------------------------------
subplot(1,1,1);
plot(timeT,ZeroIPResp, timeT,ZeroStateResP, timeT,CompleteResP);
grid on;
title('Combine Response');
xlabel('Time -->');
ylabel('Magnitude -->');
% End of Program
----------------------------------------------------------

Output
State Transition Matrix is =
[ 2/exp(2*t) ‐ 1/exp(4*t), 1/(2*exp(2*t)) ‐ 1/(2*exp(4*t))]
[ 4/exp(4*t) ‐ 4/exp(2*t), 2/exp(4*t) ‐ 1/exp(2*t)]
Zero Input Response is =
2/exp(2*t) ‐ 1/exp(4*t)
4/exp(4*t) ‐ 4/exp(2*t)
Zero State Response is =
1/(2*exp(2*t)) ‐ 1/(2*exp(4*t))
2/exp(4*t) ‐ 1/exp(2*t)
Complete Response is =
5/(2*exp(2*t)) ‐ 3/(2*exp(4*t))
6/exp(4*t) ‐ 5/exp(2*t)
Independent Output
Combined Output

Design of Full Order and Reduced


Order Observer
1 Reply

A Little Theory:
If the closed loop input-output transfer function can be represented by a state space equation
as :

where,
A = System Matrix
X = State Vector
B = Control input Matrix
U = Input Vector
C = Output Matrix
Y = Output Vector
D = Direct Matrix

Block Diagram of system and a full order observer

In the problem of pole placement by state feedback, the control law is U = -Kx + r.
The control system design problem of pole placement by state feedback requires feedback of
all the state variables. In practice, however not all state variables are available for
measurement and feedback. In such situation we need to estimate unmeasurable state
variables.
The estimation of unmeasurable state variables is commonly called observation. A device (or
a computer program) that estimates or observes the state variables is called State Observer. If
the state observes, all the state variables of the system, its called a full order state observer.
The observer is basically a copy of the plant; it has the same input and almost the same
differential equation. An extra term compares the actual measured output y to the estimated
output ŷ; this will cause the estimated states to approach the values of the actual states x. The
error dynamics of the observer are given by the poles of (A-L*C).

Reduced Order Observer


The observers discussed thus far are designed to reconstruct all the state variables. In
practice, some of the state variables may be accurately measured. Such accurately measurable
state variables need not be estimated. Suppose that the state vector x is an n-vector and the
output vector y is an m-vector that can be measured. Since m output variables are linear
combinations of the state variables, m state variables need not be estimated. We need to
estimate only n-m state variables. Then the reducedorder observer becomes an (n-m)th-order
observer. Such an (n-m)th-order observer is the minimum-order observer.

Problem:
Design a full order and a reduced order observer for the given transfer function. The Observer
should be 10 times faster than the state feedback controller with 20.8% overshoot and 4
seconds settling time.

at poles = -100,-10,-10

Matlab Program
%--------------------------------------------------------------------------
% Experiment 10 - Full Order and Reduced Order Observer Design
% By Siddharth Kaul

%--------------------------------------------------------------------------
%
% Given
-------------------------------------------------------------------
num = [1 4];
den = [1 8 17 10];
sys = tf(num,den);
desiredPoles = [-100 -10 -10];
disp('Given Transfer Function: ');
sys
% Now finding whether observable or not
-----------------------------------
[MatrixA,MatrixB,MatrixC,MatrixD] = tf2ss(num,den);
mysys = canon(ss(MatrixA,MatrixB,MatrixC,MatrixD),'companion');
% If observable then only continue other wise no oberver design possible
--
if(rank(MatrixA)==rank(mysys.A))
disp('System is Observable');
% Observer Design Possible --------------------------------------------
observerGain = acker(MatrixA.',MatrixC.',desiredPoles.').';
disp('Observer Gain Matrix');
disp(observerGain);
% New System with observer --------------------------------------------
newMatrixA = MatrixA - (observerGain*MatrixC);
newMatrixB = eye(rank(MatrixA));
newMatrixC = eye(rank(MatrixA));
newMatrixD = eye(rank(MatrixA));
mysys = ss(newMatrixA,newMatrixB,newMatrixC,newMatrixD);
mysys;
timeT = 0:.1:2;
initialX = [1 0 0];
x = initial(mysys, initialX,timeT);
x1 = [1 0 0]*x';
x2 = [0 1 0]*x';
x3 = [0 0 1]*x';
subplot(3,1,1);
plot(timeT,x1,'r',timeT,x2,'g',timeT,x3,'b');
title('Response to initial Condition of State Variables Observer');
xlabel('Time -->');
ylabel('Magnitude -->');
disp('New System Matrix A');
disp(newMatrixA);
else
disp('System is Unobservable');
% No observer design possible -----------------------------------------
end
%--------------------------------------------------------------------------
% Now first we need to make controller with given specification of 20.8%
% overshoot and 4 seconds settling time. For such a controller we
% calculated the required poles to be
% [-1+.637i -1-.637i -4]
%--------------------------------------------------------------------------
% So ----------------------------------------------------------------------
% we already have MatrixA -------------------------------------------------
desiredPoles = [-1+.637i -1-.637i -4];
controllerGain = acker(MatrixA,MatrixB,desiredPoles);
disp('Controller Gain is ');
disp(controllerGain);
newMatrixA = MatrixA - (MatrixB*controllerGain);
newMatrixB = eye(3);
newMatrixC = eye(3);
newMatrixD = eye(3);
initialX = [1 0 0];
timeT = 0:.1:5;
mysys = ss(MatrixA,newMatrixB,newMatrixC,newMatrixD);
x = initial(mysys, initialX,timeT);
x1 = [1 0 0]*x';
x2 = [0 1 0]*x';
x3 = [0 0 1]*x';
subplot(3,1,2);
plot(timeT,x1,'r',timeT,x2,'g',timeT,x3,'b');
title('Response to initial Condition of State Variables Controller');
xlabel('Time -->');
ylabel('Magnitude -->');
%--------------------------------------------------------------------------
% Now finding the reduced order observer that is 10 times faster than the
% designed controller.
% With this criteria in mind we can get the MatrixAaa, MatrixAb and so on
% and the desired observer poles becomes -10+6.377i -10-6.477i
%--------------------------------------------------------------------------
% So ----------------------------------------------------------------------
MatrixAaa = [0];
MatrixAab = [1 0];
MatrixAba = [0;-10];
MatrixAbb = [0 1;-17 -8];
desiredObserverPoles = [-10+6.377i -10-6.377i];
observerGain = acker(MatrixAbb.',MatrixAab.',desiredObserverPoles.').'
newMatrixAAbb = MatrixAbb - (observerGain*MatrixAab);
newMatrixB = eye(2);
newMatrixC = eye(2);
newMatrixD = eye(2);
mysys = ss(newMatrixAAbb,newMatrixB,newMatrixC,newMatrixD);
initialX = [1 0];
timeT = 0:.1:2;
x = initial(mysys,initialX,timeT);
x1 = [1 0]*x';
x2 = [0 1]*x';
subplot(3,1,3);
plot(timeT,x1,'r',timeT,x2,'g');
title('Response to initial Condition of State Variables Reduced Observer');
xlabel('Time -->');
ylabel('Magnitude -->');
% -------------------------------------------------------------------------
% End of Program. Created By Siddharth Kaul
% -------------------------------------------------------------------------

Output:

Observer Output

EE544 Matlab/Simulink Example 8: State-Space Observer Design and


Control

Initial Matlab Commands (before running Simulink):


% clear matlab memory and close all figures
clear all; close all;

% define motor parameters


L = 1e-3; R = 1; J = 5e-5; B = 1e-4; K = 0.1;

% define motor state variable model


A = [-R/L, 0, -K/L; 0, 0, 1; K/J, 0, -B/J];
B = [1/L; 0; 0];
C = [0, 1, 0];
D = [0];

% check observability
O = obsv(A,C);
rank(O)

% design observer by placing poles of A-LC at -500+j250, -500-j250, -200


Lt = acker(A.',C.',[-500+250j, -500-250j, -2000]);
L = Lt.'

% check poles of estimator-error dynamics


est_poles = eig(A - L*C)

% redefine C,D to get all states out of DC motor block -


% use only y = x_2 for observer
C = [1, 0, 0; 0, 1, 0; 0, 0, 1];
D = [0; 0; 0];

% define DC motor intial conditions for use in Simulink


x0 = [0, 0, 0];

% define estimator state variable model and initial conditions


Ahat = A;
Bhat = [B, L];
Chat = [1, 0, 0; 0, 1, 0; 0, 0, 1];
Dhat = [0, 0; 0, 0; 0, 0];
xhat0 = [5, 5, 5];

Matlab Response:

ans =
3

L =
56450
1998
108504

est_poles =
1.0e+003 *
-0.5000 + 0.2500i
-0.5000 - 0.2500i
-2.0000

Simulink File
Matlab Plot Commands (after Simulink):

figure(1);
subplot(3,1,1); plot(tout, states(:,1), tout, states(:,4), '--');
xlabel('time (sec)'); legend('x_1 = i_a', 'xhat_1');
title('States x and their Estimates xhat');
subplot(3,1,2); plot(tout, states(:,2), tout, states(:,5), '--');
xlabel('time (sec)'); legend('x_2 = \theta', 'xhat_2');
subplot(3,1,3); plot(tout, states(:,3), tout, states(:,6), '--');
xlabel('time (sec)'); legend('x_3 = \theta_{dot}', 'xhat_3');

Plots Generated:

You might also like