0% found this document useful (0 votes)
9 views

Lec.9

Fuzzy Logic 9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lec.9

Fuzzy Logic 9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Almughtaribeen University

ALMUGHTARIBEEN UNIVERSITY

College of Engineering
Cnt 521
Fuzzy Logic Control
Lecture 9

Fuzzy Systems Using MATLAB Fuzzy Toolbox

Dr. Abusabah I. A. Ahmed

[email protected]
1
Lecture Outline
 Introduction
ALMUGHTARIBEEN UNIVERSITY

 Member ship functions


 Fuzzy Sets by Fuzzy Toolbox GUI
 Car Driving

Almughtaribeen University – [ Abusabah I. A. Ahmed]


2
ALMUGHTARIBEEN UNIVERSITY
Introduction

Almughtaribeen University – [ Abusabah I. A. Ahmed]


3
Trapezoid Membership Function
0 xa
 xa a xb
ALMUGHTARIBEEN UNIVERSITY

 b  a
trapezoid ( x, a, b, c, d )   1 bxc
 d x cxd
 d c
𝑇𝑟𝑎𝑝𝑒𝑧𝑜𝑖𝑑 𝑥, 10,20,60,95  0 xd

Almughtaribeen University – [ Abusabah I. A. Ahmed]


4
Triangular Membership Function
 0 xa
 xa a xb

ALMUGHTARIBEEN UNIVERSITY

triangle( x, a, b, c)   cbxa
 c b bxc
 0 cx
𝑇𝑟𝑖𝑎𝑛𝑔𝑙𝑒 𝑥, 20,60,80

Almughtaribeen University – [ Abusabah I. A. Ahmed]


5
ALMUGHTARIBEEN UNIVERSITY
Fuzzy Sets by Fuzzy Toolbox GUI

Let the room temperature T be a fuzzy variable.


Characterize it with three different (fuzzy)
temperatures: cold, warm, hot.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


6
ALMUGHTARIBEEN UNIVERSITY
Fuzzy Sets by Fuzzy Toolbox GUI

Open MATLAB and type


fuzzy. This opens the
Graphical User Interface
(GUI) of the FUZZY
Toolbox.
2. Define the membership
functions on the input side of
the GUI. Click input1 block
twice or choose
Membership functions from
Edit menu.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


7
ALMUGHTARIBEEN UNIVERSITY
Fuzzy Sets by Fuzzy Toolbox GUI

First define the temperature


range, e.g. to [𝟎𝟎 , 𝟒𝟎𝟎 ].

Define new membership


functions (MF). Choose Add
MF's from EDIT menu.
Choose default values: 3
triangular (trimf) shape MFs

Almughtaribeen University – [ Abusabah I. A. Ahmed]


8
ALMUGHTARIBEEN UNIVERSITY
Fuzzy Sets by Fuzzy Toolbox GUI

Resulting set of MFs.

Activate mf1 by clicking it.


It becomes red. Type cold
in the Name area. Final
result on the right.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


9
ALMUGHTARIBEEN UNIVERSITY
Car Driving

You are driving car A on a highway. You want to keep a


safe distance to car B in front of you. Design a (simplified)
fuzzy-logic system, which satisfies the requirements.
Proceed as follows:
1. Determine the required fuzzy variables (input/output)
and their ranges.
2. Form the rule base.
3. Use fuzzy reasoning to check the operability of the rule base.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


10
Car Driving
1. Fuzzy variables. Start with a simple case.
INPUT: Distance d
ALMUGHTARIBEEN UNIVERSITY

OUTPUT: Breaking power b (gas pedal)


Three (3) membership functions are chosen for both input
and output. Membership functions for INPUT:
Distance d (meters): short, medium, long.
Membership functions for OUTPUT:
Breaking power b (%): large, medium, none
We will use the fuzzy toolbox to define the fuzzy system by
giving numerical values for the variables indicated.

In MATLAB type
» fuzzy
This opens the GUI. Activate the input window.
Almughtaribeen University – [ Abusabah I. A. Ahmed]
11
Car Driving
Give a name to the fuzzy input variable. Call it distance.
Click Close.
ALMUGHTARIBEEN UNIVERSITY

Almughtaribeen University – [ Abusabah I. A. Ahmed]


12
Car Driving
Next click the input block twice with mouse to open the
ALMUGHTARIBEEN UNIVERSITY

membership function window. First define the range, say from 0


to 30 m/s.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


13
Car Driving
Next choose from Edit Add MFs. Pick the default values:
ALMUGHTARIBEEN UNIVERSITY

3 triangular membership functions. Give a name to each:


Call them high, medium, and short. When you are
finished, click Close.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


14
Car Driving
Repeat the same procedure with the output b, breaking power.
ALMUGHTARIBEEN UNIVERSITY

Define the name of the output, break, and its range. Use three
membership functions: hard, medium and no. The following
GUI display is obtained.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


15
Car Driving
What is missing from the fuzzy system now is the rule base.
ALMUGHTARIBEEN UNIVERSITY

Open View menu and click Edit rules. Then the following
display opens.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


16
Car Driving
The left-hand side contains the membership functions of the
ALMUGHTARIBEEN UNIVERSITY

input, distance. The right-hand side has the membership


functions of the output, brake. If the input side has several
variables, which are connected either by and or or, the
Connection block is in the lower left-hand corner. In this case we
only have one input variable, so the connective is not used. The
weight factor (default value = 1), indicates the importance of the
rule in question.
The construction of the rule base is the hardest part of the design
task. Here a simple-minded rule base is constructed based on
driving experience. Typical rule is

If distance is low, then brake is hard.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


17
Car Driving
With mouse choose the membership function low for the
distance and hard for brake. Then click Add rule. The result is
ALMUGHTARIBEEN UNIVERSITY

seen below.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


18
Car Driving
Let us set two other rules, one for medium distance and the
ALMUGHTARIBEEN UNIVERSITY

other for long distance. Our simple, rule base is now complete.
Click Close.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


19
Car Driving
Now the design of the fuzzy system is complete. The Toolbox
ALMUGHTARIBEEN UNIVERSITY

provides two more interesting ways expressing the rule base.


Check under Options and there
choose Format. Under
that you can see that the rules as
shown are given verbose.
The other forms are symbolic and
indexed. Check in what
form the rule base is given in each
case.
Viewing rules gives you the overall
picture of the
developed fuzzy system. From the
main FIS editor,
choose from View menu View rules.
Almughtaribeen University – [ Abusabah I. A. Ahmed]
20
Car Driving
By choosing View the rule base can be viewed differently.
ALMUGHTARIBEEN UNIVERSITY

Almughtaribeen University – [ Abusabah I. A. Ahmed]


21
Car Driving
The display View rules is shown below.
ALMUGHTARIBEEN UNIVERSITY

Almughtaribeen University – [ Abusabah I. A. Ahmed]


22
Car Driving
On the left-hand side you can see the input, distance side and on
ALMUGHTARIBEEN UNIVERSITY

the left the output, brake side. There are three rules and the
corresponding triangular membership functions
displayed. In the right-hand side lower corner is the result of fuzzy
reasoning. At this point it is a fuzzy set. Applying defuzzification
method, in the figure center of gravity has been chosen, a crisp
value is obtained.

Almughtaribeen University – [ Abusabah I. A. Ahmed]


23
Car Driving
Different input values can be tried by moving the red, vertical
ALMUGHTARIBEEN UNIVERSITY

line on the left-hand side

Almughtaribeen University – [ Abusabah I. A. Ahmed]


24
Car Driving
Finally, the input-output mapping can be observed by viewing
ALMUGHTARIBEEN UNIVERSITY

surface. Choose View menu and under it View surface. It is clear


that our map is nonlinear. This is where
the power of fuzzy systems is strong

Almughtaribeen University – [ Abusabah I. A. Ahmed]


25
ALMUGHTARIBEEN UNIVERSITY

Almughtaribeen University – [ Abusabah I. A. Ahmed]


26

You might also like