You are on page 1of 9

1

System 195, Physical System With MATLAB For


The Graduate Course ELK 5320
Jose Eduardo Urrea Cabus, Student and Ismail H. Altas, Lecturer

Abstract—Solving systems of linear or nonlinear equations is a II. THEORETICAL BACKGROUND


relatively complicated problem in which arise a diverse range of
sciences. There are a number of different approaches that have What, then, is the motivation for turning to fuzzy con-
been proposed. In this paper, we see that standard arithmetic and trol? Basically, the difficult task of modeling and simulating
algebraic operations, which are based after all on the foundations complex real-world systems for control systems development,
of classical set theory, can be extended to fuzzy arithmetic and especially when implementation issues are considered, is well
fuzzy algebraic operations [3]. The methods for obtaining the documented [4].
results, simulation diagrams and state-space models of systems
are presented, Runge-Kutta numerical solution has been applied
as well as user-based MATLAB/Simulink software is developed to Fuzzy logic controllers (FLCs) based on fuzzy set theory
show the meaning of controlling systems as one of the application are used to represent the experience and knowledge of a
areas of FL [1]. human operator in terms of linguistic variables called fuzzy
Index Terms—Analysis, Application, Approximate, Control, rules. Since an experienced human operator adjusts the system
Fuzzy, Human, Linguistic, Logic, MATLAB, Simulink, Stability, inputs to get a desired output by just looking at the system
Variables. output without any knowledge of the system’s dynamics and
interior parameter variations, the implementation of linguistic
I. I NTRODUCTION fuzzy rules based on the procedures done by human operators

D uring the past decade, fuzzy logic control (FLC), initiated


by the pioneering work of Mamdani and Assilian [1975],
has emerged as one of the most active and fruitful areas for
does not also require a mathematical model of the system.
Therefore, an FLC becomes nonlinear and adaptive in nature
having a robust performance under parameter variations with
research in the application of fuzzy set theory, fuzzy logic, the ability to get desired control actions for complex, uncer-
and fuzzy reasoning. Its application ranges from industrial tain and nonlinear systems without the requirement of their
process control to medical diagnosis and securities trading [2]. mathematical models and parameter estimation.
Control applications are the kinds of problems for which fuzzy
logic has had the greatest success and acclaim. Many of the FL-based controllers provide a mathematical foundation for
consumer products that we use today involve fuzzy control. approximate reasoning, which has been proven to be very
And, even though fuzzy control is now a standard within successful in a variety of applications. In modern control
industry, the teaching of this subject on academic campuses techniques, uncertainty and vagueness have a great amount
is still far from being a standard offering. But, a paradigm of importance to be dealt with. Since the introduction of
shift is being realized in the area of fuzzy control, given its fuzzy set theory and its application to control systems, it has
successes for some problems where classical control has not become an important and useful tool in especially controlling
been effective or efficient [3]. nonlinear systems. As the computer and chip technologies
developed, the applications of FL-based controllers have in-
In order to control a physical systems, mainly three pa-
creased tremendously so that they have been applied in many
rameters, are overshoot, settling time and steady-state error
different systems.
are affected by the controller [1]. This paper provides an
explanation of the physical system modeling and to control the
For a physical system operator, one of the most important
system by using a fuzzy controller and PI controller. As well as
knowledge is the time response of the system. The time
we will present the basic architecture, the design methodology,
response of a physical system is important since it reflects the
and the stability analysis fo fuzzy logic controller for a
effects of the changes either in reference input or system’s
physical system. And also, show that FLC is strongly based
interior parameters. An operator knows very well how the
on the concepts of fuzzy sets and relations, linguistic variables
system responds to a change in reference input or system
and approximate reasoning, using MATLAB/Simulink.
parameters in order to make necessary adjustments so that
—————————————————————————————— system keeps operating at reference set point. In classical
This work has been done as a term project for the graduate course ELK 5320
Neural Fuzzy Systems given by Assoc. Prof. Dr. Ismail H. Altas, Department
automatic control systems, an error signal is defined as the
of Electrical and Electronics Engineering, Karadeniz technical University, difference between reference set value and actual system
Trabzon, Turkey. output.
J. E. Urrea Cabus is a graduate student at the department of Electrical
and Electronics Engineering, Karadeniz Technical University, 61080 Trabzon,
e(t) = r(t) y(t) (1)
Turkey (e-mail: 376202@ktu.edu.tr).
İ. H. Altaş is with the Department of Electrical and Electronics Engineering, A classical automatic control system uses the error signal
Karadeniz Technical University, 61080 Trabzon (e-mail: ihaltas@altas.org). in order to generate a control signal to drive the physical
2

system or process so that the actual output tracks the reference III. BASIC STRUCTURE AND OPERATION OF FUZZY LOGIC
with zero of minimum error. The error e(t) is obtained as the CONTROL SYSTEMS
difference between reference r(t) and actual system output The operation principle of an FLC is similar to the decision
y(t) as given in (1) and show in Figure 1. In a classical control process of a human operator doing the same job. It performs
system, the error signal is either amplified, integrated and/or the same actions as a human operator does by adjusting the
derived to yield the required control action. The controllers input signal looking at only the system output. The architecture
with these processes are called as proportional (P ), integral of an FLC is very similar to that of a fuzzy reasoning
(I) and derivate (D) controllers, and their combination is algorithm. The most used algorithm for FLC is the one given
called as P ID controller. as Mamdani reasoning algorithm [1].

As it was in the Mamdani fuzzy reasoning architecture, an


FLC also consists of four stages: a fuzzifier, a fuzzy rule base,
an inference engine or consequent and a defuzzifier, as shown
in Figure 3 and 4.

Figure 1. Adjustable control of a system response. Figure 3. Structure of fuzzy logic controller.

The time responses of the error signals can be used to


represent information related to the system output behavior.
As the error signals approach zero, the output signals move
toward reference set point. Depending on the performances of
the controllers used, the error signals may or may not become
zero. The dynamic responses of error signal in a controlled
system will be sufficient to derive the control rules since they
contain the necessary information about the output. Therefore,
the error signal shown in Figure 2 are used as the source of
Figure 4. Basic architecture of a fuzzy logic controller (FLC).
information for constructing the rule base systems for FLC.
These signals may represent any types of control error with a
1) A rule-base (a set of If-Then rules), which contains
step-type reference input [1].
a fuzzy logic quantification of the expert’s linguistic
description of how to achieve good control.
2) An inference mechanism (also called an “inference en-
gine” or “fuzzy inference” module), which emulates the
expert’s decision making in interpreting and applying
knowledge about how best to control the plant.
3) A fuzzification interface, which converts controller inputs
into information that the inference mechanism can easily
use to activate and apply rules.
4) A defuzzification interface, which converts the conclu-
sions of the inference mechanism into actual inputs for
the process [4].

If the output from the defuzzifier is not a control action


for a plant, then the system is a fuzzy logic decision system.
The fuzzifier has the effect of transforming crisp measured
data (e.g., speed is 10 miles per hour) intro suitable linguistic
Figure 2. Error signals of the first and second order systems for a step input.
values (i.e., fuzzy sets, for example, speed is too slow). The
fuzzy rule base stores the empirical knowledge of the operation
3

of the process of the domain experts. The inference engine is


the kernel of a FLC, and it has the capability of simulating
human decision making by performing approximate reasoning
to achieve a desired control strategy. The defuzzifier is utilized
to yield a nonfuzzy decision or control action from an inferred
fuzzy control action by the inference engine [2].

IV. DESIGN PROCESS


We shall present introductory material on state-space Figure 5. Block diagram of linear, continuous time control system represented
in state space.
analysis of control systems and Runge-Kutta Methods.

State-Space Equations: In state-space analysis we are ẏ(t) = Cx(t) + Du(t) (7)


concerned with three types of variables that are involved in
the modeling of dynamic systems: input variables, output Runge-Kutta Methods: The idea of generalizing the Euler
variables, and state variables. The number of state variables to method, by allowing for a number of evaluations of the
completely define the dynamics of the system is equal to the derivative to take place in a step, is generally attributed to
number of integrators involved in the system. Assume that a Runge [1895]. Further contributions were made by Heun
multiple-input, multiple-output system involves n integrators. [1900] and Kutta [1901]. The latter completely characterized
Assume also that there are r inputs u1 (t), u2 (t), · · · , ur (t) the set of Runge–Kutta methods of order 4, and proposed
and m outputs y1 (t), y2 (t), · · · , ym (t). Define n outputs of the the first methods of order 5. Special methods for second
integrators as state variables: x1 (t), x2 (t), · · · , xn (t). Then order differential equations were proposed by Nystrȯm [1925],
the system may be described by who also contributed to the development of methods for first
order equations. It was not until the work of Hut̂a [1956,
ẋ1 (t) = f1 (x1 , x2 , · · · , xn ; u1 , u2 , · · · , ur ; t) 1957] that sixth order methods were introduced. Since the
ẋ2 (t) = f2 (x1 , x2 , · · · , xn ; u1 , u2 , · · · , ur ; t) advent of digital computers, fresh interest has been focused
.. on Runge–Kutta methods, and a large number of research
. workers have contributed to recent extensions to the theory,
ẋn (t) = fn (x1 , x2 , · · · , xn ; u1 , u2 , · · · , ur ; t) and to the development of particular methods. Although early
studies were devoted entirely to explicit Runge–Kutta meth-
ods, interest has now moved to include implicit methods,
The outputs y1 (t), y2 (t), · · · , ym (t) of the system may be
which have become recognized as appropriate for the solution
given by
of stiff differential equations [7]. In numerical analysis, the
ẏ1 (t) = g1 (x1 , x2 , · · · , xn ; u1 , u2 , · · · , ur ; t) Runge–Kutta methods are a family of implicit and explicit
iterative methods, which include the well-known routine called
ẏ2 (t) = g2 (x1 , x2 , · · · , xn ; u1 , u2 , · · · , ur ; t)
the Euler Method, used in temporal discretization for the
.. approximate solutions of ordinary differential equations [8].
.
The following equations represent Runge–Kutta methods of
ẏm (t) = gm (x1 , x2 , · · · , xn ; u1 , u2 , · · · , ur ; t)
order 4, that is used to compute the results.

Then Equations above become k1 = T ⇤ f (tn , xn ) (8)


T k1
ẋ(t) = f(x, u, t) (2) k2 = T ⇤ f (tn + , xn + ) (9)
2 2
ẏ(t) = g(x, u, t) (3) T k2
k3 = T ⇤ f (tn + , xn + ) (10)
2 2
If Equations (2) and (3) are linearized about the operating k4 = T ⇤ f (tn + T, xn + k3 ) (11)
state, then we have the following linearized state equation and
k1 + 2(k2 + k3 ) + k4
output equation: kn+1 = xn + (12)
6
ẋ(t) = A(t)x(t) + B(t)u(t) (4) Where T is the sampling step, n is the iteration counter, t
ẏ(t) = C(t)x(t) + D(t)u(t) (5) is time, xn will be the found variable and f is x variable and
time dependent function.
where A(t) is called the state matrix, B(t) the input matrix, 1) k1 is the increment based on the slope at the beginning
C(t) the output matrix, and D(t) the direct transmission matrix. of the interval, using xn [Euler0 smethod];
Equations (4) and (5) is shown in Figure 5. 2) k2 is the increment based on the slope at the midpoint of
the interval, using xn and k1 ;
If vector functions f and g do not involve time t explicitly
3) k3 is again the increment based on the slope at the
then the system is called a time-invariant system. In this case,
midpoint, but now using xn and k2 ;
Equations (4) and (5) can be simplified to [5]:
4) k4 is the increment based on the slope at the end of the
ẋ(t) = Ax(t) + Bu(t) (6) interval, using xn and k3 .
4

Here kn+1 is the RK4 approximation of x(tn+1 ), and


the next value (kn+1 ) is determined by the present value
(xn ) plus the weighted average of four increments, where
each increment is the product of the size of the interval,
T , and an estimated slope specified by function f on the
right-hand side of the differential equation. In averaging the
four increments, greater weight is given to the increments at
the midpoint. If f is independent of xn , so that the differential
equation is equivalent to a simple integral, then RK4 is
[Simpson0 srule] [8].

The modern trend in engineering systems is toward greater


complexity, due mainly to the requirements of complex tasks
and good accuracy. Complex systems may have multiple inputs
and multiple outputs and may be time varying. Because of the Figure 6. System output.
necessity of meeting increasingly stringent requirements on
the performance of control systems, the increase in system
complexity, and easy access to large scale computers, modern VI. RESULTS
control theory, which is a new approach to the analysis and A. Uncontrolled system
design of complex control systems, has been developed since
Simulink diagram can be easily drawn from the above three
around 1960 [5].
equations for our system. This will be our uncontrolled system,
it is shown in figure 7.
V. SYSTEM MODELLING
% SISTEM 195 P h y s i c a l system
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
c l e a r ; c l g ; c l c % C l e a r memory and s c r e e n
A=[ 5 1;3 1];
B = [ 2 ; 5 ] ; C=[1 2 ] ; D=0;
% i n i t i a l s for simulation
x10 =1; x20 =1; u1 =1; u2 =1;
dt = 0 . 0 1 ; t e n d =5; t 0 =0;
k =1; % k i s d i m e n s i o n c o u n t e r .
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Our initial values of the system were shown in the MATLAB


code above. Below we show the modeling of the system, from Figure 7. Simulink diagram of the system
the equations (6) and (7) and our initial values of the system.
     There are two applied inputs whose value are u1 = 1 and
Ẋ1 5 1 X1 2 0 u u2 = 1. The system is converted into subsystem whose inputs
= ⇥ + ⇥ 1
Ẋ2 3 1 X2 5 0 u2 are given by a constants and outputs are taken at scope at
 Figure 8.
⇥ ⇤ ⇥ ⇤ X1
Y = 1 2
X2

Hence, we can get the following equations:


Ẋ1 = 5X1 X2 + 2 (13)
Ẋ2 = 3X1 X2 + 5 (14)
Y = X1 + 2X2 (15)

It is cleared from these equations that this system has two


variables X1 , X2 , and one output as Y which depends on X1
as well as X2 variables. For this reason, the output is taken Figure 8. Uncontrolled subsystem
from X1 and X2 . We have two active inputs u1 = 1 and
u2 = 1. Therefore we have two inputs and one output for our As a result of the uncontrolled system, we can get the fol-
system. From the output of the system, we got the following lowing answers for our state-space X1 and X2 approximately
graphic shown in figure 6. equal to -0.36 and 3.83, respectively, as is shown in figure 9.
From the above graphs, we can say that our steady-state value
From figure 6 we can see how our system behaves in the for X1 and X2 is after approximately 2.5 seconds. For the first
output, and after approximately 2.5 seconds it starts to be step, we compute the system without any controller using the
continuous. following MATLAB code:
5

B. System controlling with PI controller


% SISTEM 195 P h y s i c a l system
% Copyrright I s m a i l H. Alta s . A proportional-integral controller (PI controller) is a control
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
c l e a r ; c l c % C l e a r memory and s c r e e n
loop feedback mechanism (controller) widely used in indus-
A=[ 5 1;3 1]; trial control systems. A PI controller calculates an error value
B = [ 2 ; 5 ] ; C=[1 2 ] ; D=0;
% i n i t i a l s for simulation
as the difference between a measured process variable and
x10 =1; x20 =1; u1 =1; u2 =1; a desired set point. The controller attempts to minimize the
dt = 0 . 0 1 ; t e n d =5; t 0 =0;
k =1; % k i s d i m e n s i o n c o u n t e r .
error by adjusting the process through use of a manipulated
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * variable. The controller output is given by equation (16).
Z
w h i l e t0<tend dt
x11=x10 ; x21=x20 ; kp + ki dt (16)
a1=dt * ( A( 1 , 1 ) * x11 + A( 1 , 2 ) * x21 + B( 1 , 1 ) * u1 ) ;
a2=dt * ( A( 2 , 1 ) * x11 + A( 2 , 2 ) * x21 + B( 2 , 1 ) * u2 ) ;
Where kp is proportional gain, ki is integral gain, and the error
x12=x10+a1 / 2 ; x22=x20+a2 / 2 ; or deviation of actual measured value (PV) from the set point
b1=dt * ( A( 1 , 1 ) * x11 + A( 1 , 2 ) * x21 + B( 1 , 1 ) * u1 ) ; (SP) given in equation (17).
b2=dt * ( A( 2 , 1 ) * x11 + A( 2 , 2 ) * x21 + B( 2 , 1 ) * u2 ) ;
SP PV (17)
x13=x10+b1 / 2 ; x23=x20+b2 / 2 ;
The proportional term produces an output value that is propor-
c1=dt * ( A( 1 , 1 ) * x11 + A( 1 , 2 ) * x21 + B( 1 , 1 ) * u1 ) ;
c2=dt * ( A( 2 , 1 ) * x11 + A( 2 , 2 ) * x21 + B( 2 , 1 ) * u2 ) ; tional to the current error value. The proportional response can
be adjusted by multiplying the error by a constant kp , called
x14=x10+c1 ; x24=x20+c2 ;
the proportional gain constant. The proportional term is given
d1=dt * ( A( 1 , 1 ) * x11 + A( 1 , 2 ) * x21 + B( 1 , 1 ) * u1 ) ; by equation (18):
d2=dt * ( A( 2 , 1 ) * x11 + A( 2 , 2 ) * x21 + B( 2 , 1 ) * u2 ) ;
Pout = kp e(t) (18)
x1 ( k )=x10+(a1+2* b1+2* c1+d1 ) / 6 ;
x2 ( k )=x20+(a2+2* b2+2* c2+d2 ) / 6 ; The contribution from the integral term is proportional to
U( k )=u1 ; t ( k )=t 0+dt ; t 0=t ( k ) ; both the magnitude of the error and the duration of the error.
x10=x1 ( k ) ; x20=x2 ( k ) ; k=k +1; The accumulated error is then multiplied by the integral gain,
end ki and added to the controller output. The integral term is
given by equation (19):
subplot (211) Z t
p l o t ( t , x1 , ' b ' ) ;
t i t l e ( ' x1 ' ) ; Iout = ki e(t)dt (19)
x l a b e l ( ' t i m e i n s e c o n d s ' ) ; y l a b e l ( ' x1 ' ) ; grid 0
subplot (212)
p l o t ( t , x2 , ' r ' ) ; For the second step, we compute the system with PI-controller
t i t l e ( ' x2 ' ) ;
x l a b e l ( ' t i m e i n s e c o n d s ' ) ; y l a b e l ( ' x2 ' ) ; grid
using the following MATLAB code and the plotting are shown
in figure 10, 11, 12, 13 :
% SISTEM 195 P h y s i c a l system
% Copyrright I s m a i l H. Alta s .
% PI C o n t r o l l e r
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
c l e a r ; c l c % C l e a r memory and s c r e e n
A=[ 5 1;3 1];
B= [ 2 ; 5 ] ; C=[ 1 2 ] ; D=0;
% i n i t i a l s for simulation
x10 =1; x20 =1; u1 =1; u2 =1;
dt = 0 . 0 1 ; t e n d =5; t 0 =0;
k =1; % k i s d i m e n s i o n c o u n t e r .
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
%I n i t i a l v a l u e s
U0=[ u1 ; u2 ] ; y0 =0; e 1 0 =0;
BOY=s i z e (A) ; LS=BOY( 1 ) ; LK=BOY( 2 ) ;
f o r n=1:LS
x0 ( n ) =1;
end
%R e q u i r e d d a t a f o r i n s p e c t i o n
R0=i n p u t ( ' S e l e c t a r e f e r e n c e i n p u t v a l u e ( 1 7 . 3 7 )==>
') ;
KP=i n p u t ( 'KP E n t e r c o n t r o l l e r v a l u e ( 0 . 1 2 ) ==> ' ) ;
KI=i n p u t ( ' KI E n t e r c o n t r o l l e r v a l u e ( 0 . 0 1 2 ) ==> ' ) ;
%I t e r a t i v e s o l u t i o n
w h i l e t0<tend dt
i f t0 >( t e n d / 2 )
r 0=R0+0.5 * R0 ;
else
Figure 9. The uncontrolled outputs are approximately equal to -0.36 and 3.83, r 0=R0 ;
end
respectively e0=r0 y0 ; % error controller
ekp=KP* e0 ; % P controller
The system can control the output to make it stable at 2 and e1=e 1 0+dt * KI * e0 ; % Integral controller
5 by using PI and Fuzzy Logic controller. e 1 0=e1 ; U=( e1+ekp ) * U0 ;
[ x]= r u n g e (A, B , U, x0 , dt ) ;
% output c o n t r o l l e r
% Runge Kutta
u ( k )=U( 1 ) ; e ( k )=e0 ; r ( k )=r 0 ;
6

y ( k )=x ( 1 ) +2* x ( 2 ) ; y0=y ( k ) ;


t ( k )=t 0+dt ; t 0=t ( k ) ;
f o r n=1:LS
x0 ( n )=x ( n ) ; XX( k , n )=x ( n ) ;
end
k=k +1;
end
%Graphic
subplot (211)
p l o t ( t , y , 'b ' , t , r , ' r ') ;
x l a b e l ( ' Time ( sn ) ' ) ;
y l a b e l ( 'y ( t ) ' ) ; g r i d
l e g e n d ( ' Output ' , ' R e f e r e n c e ' )
subplot (212)
p l o t ( t , e , ' b ' ) ; x l a b e l ( ' Time ( sn ) ' ) ;
ylabel ( 'e ( t ) ') ; grid

Here, the output of the system is subtracted from the Figure 12. Answer using PI-controller, reference=4.5, KP=1.5 and KI=0.08
reference input and this difference is applied to PI controller.
Furthermore the Kp gain and the Ki gain are showing in
the following table I from different references values. After
proportional and integral gain the output is then added and
applied to the system as input. Here the system output becomes
stable as is shown in the following table I.
r(t)1 r(t)2 Kp Ki e(t)
7.37 11.05 1.7 1.7 3
6 9 1 1 2.5
4.5 6.75 1.5 0.08 2.5
1 1.5 2 2 2.5
Table I
PI CONTROLLER RESULTS

Figure 13. Answer using PI-controller, reference=1, KP=2 and KI=2

C. System controlling with Fuzzy Logic controller


Design and simulation of an FLC are explained in this
section. A MATLAB.m file is generated to simulate this FLC
controlled physical system. All steps of designed FLC and
its application to the system are given in detail through the
codes of MATLAB.m. As we mentioned earlier in sections
II and III, a FL based controller consists of four sections
namely fuzzifier, fuzzy rule base, an inference engine and
defuzzifier, two input signals, the main signal and its change
for each sampling, to the FL controller are converted to fuzzy
numbers first in fuzzifier. Then they are used in the rule table
Figure 10. Answer using PI-controller, reference=7.37, KP=1.7 and KI=1.7 to determine the fuzzy number of the compensated output
signal. Finally, the resultant united fuzzy subsets representing
the controller output are converted to the crisp values.

There are two inputs to the fuzzifier. One is the control error
e(k), which is the difference between the reference signal r(k)
and the output signal y(k) as we mentioned in section II, the
other one is the change in this error e(k). These two inputs,
defined as in Equation (1) and (20), are first fuzzified and
converted to fuzzy membership values that are used in the rule
base in order to execute the related rules so that an output can
be generated.

e(k) = e(k) e(k 1) (20)

Figure 11. Answer using PI-controller, reference=6, KP=1 and KI=1 The fuzzy rule base, which may also be called as the fuzzy
decision table, is the unit mapping two crisp inputs, e(k) and
e(k) to the fuzzy output space defined on the universe of
7

u(k). The crisp e and e axis are partitioned into seven k =1; % k i s d i m e n s i o n c o u n t e r .
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
fuzzy subsets as negative big (NB), negative medium (NM),
negative small (NS), zero (Z), positive small (PS), positive
medium (PM), and positive big (PB). From these values we % i n i t i a l values . .
U0=[ u1 ; u2 ] ; BOY=s i z e (A) ; LS=BOY( 1 ) ; LK=BOY( 2 ) ;
get 25 and 49 rules, those 25 and 49 rules are the used for f o r n=1:LS
decision of the controller for output. Figure 14 and 15 show end
x0 ( n ) =1;

the results of the Rule bases process after the fuzzifier process. % To e n t e r R e f e r e n c e i n p u t . .
r 0=i n p u t ( ' e n t e r r e f e r e n c e v a l u e from ( 0 t o 7 . 3 7 )===>
') ;
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
% fuzzy c o n t r o l l e r inputs . . . .

% E , DE and DU s p a c e b o u n d a r i e s . . .
EMAX = r 0 ; EMIN = EMAX;
DEMAX = EMAX/ 1 0 ; DEMIN = DEMAX;
DUMAX = 1 ; DUMIN = 1;

% FOR TRIANGLE FUNCITON


NBLe=EMIN ; NBTe=NBLe ; NBRe=EMIN/ 2 ;
NSLe=NBTe ; NSTe=NBRe ; NSRe=0;
Figure 14. A generalized symmetrical 25-rule table for FLC ZLe=NSTe ; ZTe=0; ZRe=EMAX/ 2 ;
PSLe=ZTe ; PSTe=EMAX/ 2 ; PSRe=EMAX;
PBLe=PSTe ; PBTe=EMAX; PBRe=PBTe ;

NBLde=DEMIN; NBTde=NBLde ; NBRde=DEMIN/ 2 ;


NSLde=NBTde ; NSTde=NBRde ; NSRde=0;
ZLde=NSTde ; ZTde=0; ZRde=DEMAX/ 2 ;
PSLde=ZTde ; PSTde=DEMAX/ 2 ; PSRde=DEMAX;
PBLde=PSTde ; PBTde=DEMAX; PBRde=PBTde ;

NBLdu=DUMIN; NBTdu=NBLdu ; NBRdu=DUMIN/ 2 ;


NSLdu=NBTdu ; NSTdu=DUMIN/ 2 ; NSRdu=0;
ZLdu=NSTdu ; ZTdu=0; ZRdu=DUMAX/ 2 ;
PSLdu=ZTdu ; PSTdu=DUMAX/ 2 ; PSRdu=DUMAX;
PBLdu=PSTdu ; PBTdu=DUMAX; PBRdu=PBTdu ;

% i n i t i a l v a l u e s f o r e r r o r and c o n t r o l l e r . . . .
Figure 15. A generalized symmetrical 49-rule table for FLC e e=EMAX; d e e =0; E=EMAX; dE=0;
e0=EMAX; e ( 1 ) =0; e ( 2 ) =0; de=e ( 2 ) e ( 1 ) ;
C( 1 ) =0;
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
% membership m a t r i x
The final control action is the crisp output that is defuzzified DU=[NBTdu NBTdu NSTdu NSTdu ZTdu
from the resultant fuzzy values of the fuzzy rule base. The NBTdu NSTdu NSTdu ZTdu PSTdu
NSTdu NSTdu ZTdu PSTdu PSTdu
fuzzy output of the rule base is obtained by triggering the NSTdu ZTdu PSTdu PSTdu PBTdu
active rules for the kth sampling instant corresponding to the ZTdu PSTdu PSTdu PBTdu PBTdu ] ;
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
values e(k) and e(k). The resultant membership values of w h i l e t0<t e n d
the active rules determine the weights of the fuzzy sets in E=l i m i t e r (EMIN,EMAX, e e ) ;% limit E
% blurring
the universe of u. Then the averaged value of the union of ENB=[NBLe NBTe NBRe ] ;
these shaded fuzzy sets is used to obtain final crisp output as ENS=[NSLe NSTe NSRe ] ;
EZ = [ ZLe ZTe ZRe ] ;
u(k). This final process called defuzzification of the fuzzy EPS=[PSLe PSTe PSRe ] ;
output. Several defuzzification methods have been applied in EPB=[PBLe PBTe PBRe ] ;
FSE=t r i a n g l e (ENB, ENS , EZ , EPS , EPB, E) ;
literature. However, the method called the center of area is % TRIANGULAR DEGREE FOR E
widely used in fuzzy logic control applications. Because of DE=l i m i t e r (DEMIN,DEMAX, d e e ) ;
% l i m i t DE
the fact that membership function is used in both fuzzification DENB=[NBLde NBTde NBRde ] ;
and defuzzication stages, fuzzy membership function is gen- DENS=[NSLde NSTde NSRde ] ;
DEZ =[ZLde ZTde ZRde ] ;
erated into fuzzy subsets for input and output spaces. There DEPS=[PSLde PSTde PSRde ] ;
are different membership functions like Triangular, Gaussian, DEPB=[PBLde PBTde PBRde ] ;
FSDE=t r i a n g l e (DENB, DENS, DEZ, DEPS, DEPB,DE) ; % UD
Trapezoid, Cauchy, Sinusoid etc. Here, for our purpose of FOR DE
modeling an FLC, we use the triangular function. For the
% DEFUZZIFICATION
third step, we compute the system with FL-controller using N1=l e n g t h (FSE) ;
the following MATLAB code and the plotting are shown in N2=l e n g t h (FSDE) ;
NM=N1 * N2 ;
figure 14, 15, 16, 17 : nn =1;
f o r mm=1:N1
% SISTEM 195 l i n e a r system
f o r qq =1:N2
% Copyrright I s m a i l H. Alta s .
FSDU( nn )=min ( [ FSE(mm) FSDE( qq ) ] ) ;
% Fuzzy L o g i c C o n t r o l l e r
nn=nn +1;
%* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
end
c l e a r ; c l c % C l e a r memory and s c r e e n
end
A=[ 5 1;3 1];
nn =1;
B= [ 2 ; 5 ] ; C=[1 2 ] ; D=0;
f o r mm=1:N1
% i n i t i a l s for simulation
f o r qq =1:N2
x10 =1; x20 =1; u1 =1; u2 =1;
DDU( nn )=FSDU( nn ) *DU(mm, qq ) ;
dt = 0 . 0 1 ; t e n d =5; t 0 =0;
8

nn=nn +1;
end
end
DUTOP1 = sum (DDU) ;
DUTOP2 = sum (FSDU) ;
DV = (DUTOP1/DUTOP2) ;

% PI a c t i o n
C( k+1) = C( k ) + DV;
CC=l i m i t e r ( 0 ,DUMAX, C( k+1) ) ;
UU0 = CC* U0 ;
[ x]= r u n g e (A, B , UU0, x0 , dt ) ; %s o l u t i o n w i t h r u n g e .
UU( k )=UU0( 1 ) ;
t ( k )=t 0+dt ; t 0=t ( k ) ;
r ( k )=r 0 ; y ( k )=x ( 1 ) +2* x ( 2 ) ;
e ( k )=r ( k ) y ( k ) ; de ( k )=e ( k ) e0 ;
e e=e ( k ) ; d e e=de ( k ) ;
e0=e ( k ) ; duty ( k )=CC;
f o r n=1:LS
x0 ( n )=x ( n ) ;
XX( k , n )=x ( n ) ;
end
k=k +1;
end Figure 17. Answer using FL-controller, reference=6.
% PLOTTING . . . . . . . . . . . . .
subplot (211)
p l o t ( t , y , ' r ' , t , r , 'b ') ;
x l a b e l ( 'TIME ( s c ) ' ) ;
y l a b e l ( 'y ' ) ; g r i d
l e g e n d ( ' Output ' , ' R e f e r e n c e ' )
subplot (212)
plot (t , e , 'r ') ;
x l a b e l ( 'TIME ( s c ) ' ) ;
ylabel ( 'e ') ; grid

Here, the system output becomes stable as is shown in the


following table II, for different values of reference.
Reference Time s
7.37 2
6 1.1
4.5 0.3
5 0.5
Table II
FL CONTROLLER RESULTS

Figure 18. Answer using FL-controller, reference=4.5.

Figure 16. Answer using FL-controller, reference=7.32.


Figure 19. Answer using FL-controller, reference=5.

As a result from the simulations from the given system,


firstly we simulated without any controller, it reaches 7.37 with the given system with FL-controller gives the best result in
a settling time of 2.5. Secondly, the given system is controlled time to be controllable. We can see from the table II that the
with PI controller by given different values of Kp and Ki and desired output is settled in very small time.
it reaches to values as it shown in the table I is desired with
small settling time as 2.5 seconds. The results show us that
9

VII. C ONCLUSION B IOGRAPHIES


An important component of FLCs is the set of fuzzy control José E. Urrea Cabus was
rules that describe the input-output relationship of a controlled born in Puerto Cortes, Honduras.
system. Two types of fuzzy control rules are currently being Received his B.Sc in Electrical
used in the design of FLCs. They are state evaluation and Engineering from National
object evaluation fuzzy control rules. Object evaluation fuzzy Autonomous University of
control rules predict present and future control actions and Honduras in 2015. He has served
evaluate the control objectives. as an Electrical Engineer in the
private sector in Honduras for
ACKNOWLEDGMENT more than two years. Now he
The authors are very grateful to the Department of EEE, is studying his MSc. degree
Karadeniz Technical University. in Electrical Engineering at
Karadeniz Technical University.
R EFERENCES
İsmail H. Altaş (M’1993,
[1] İsmail H. Altaş, Fuzzy Logic Control In Energy System SM’2007) was born in Ispir,
With Design Applications In MATLAB/Simulink, Published Turkey. Received his B.Sc.E
by The Institution of Engineering and Technology, London, in Electrical Engineering from
United Kingdom,Vol I, 2017, Chapters 7, 8 and 9. Yildiz University, and M.Sc.E
[2] Chin-Teng Lin and C. S. George Lee., Neural Fuzzy from Karadeniz Technical
Systems: A Neuro-Fuzzy Synergism to Intelligent Systems, University (KTU), Turkey, in
Englewood Cliffs, NJ: Prentice-Hall, 1996, 813 pp., hard- 1985 and 1988, respectively. He
bound, ISBN 0-13-235169-2, Chapters 7 and 8. obtained his Ph.D. degree from
[3] Timothy J. Ross, Fuzzy Logic With Engineering Appli- the University of New Brunswick,
cations, 3rd ed. John Wiley & Sons Ltd, The Atrium, Southern Canada, in 1993. He is currently
Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom, a full time Professor in Electrical
2010, Chapters 12 and 13. and Electronics Engineering
[4] Kevin M. Passino and Stephen Yurkovich, Fuzzy Con- Department at KTU. He was awarded as the best outstanding
trol, Addison Wesley Longman, Inc., 1998, Chapters 1-8. faculty member in engineering for the year 1997 at KTU. He
[5] Katsuhiko Ogata, Modern Control Engineering, 5th ed., is a Senior Member of IEEE Power Engineering, Industrial
Publishing as Prentice Hall, One Lake Street, Upper Saddle Electronics, and Man Machine and Cybernetics Societies. He
River, New Jersey 07458., Chapters 1-9. has been a member of the Chamber of Electrical Engineers
[6] İsmail H. Altaş, ELK 5320 Neural Fuzzy Systems in Turkey. He works on intelligent control of power systems
Lecture Notes, Karadeniz Technical University Department and utilization of renewable energy.
Of Electrical And Electronics Engineering, 61080 Trabzon,
Turkey, Chapters 6 and 7.
[7] J. C. Butcher, Numerical Methods For Ordinary Differ-
ential Equations, 2nd ed., The University of Auckland, New
Zeland, John Wiley & Sons Ltd, Chapter 2, 93-103 pp., ISBN:
978-0-470-72335-7.
[8]https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta
methods.