FUZZY LOGIC
Menoufia University
Faculty of Electronic Engineering
4/2020
2of 57
References08
07Fuzzy on Simulink
05Fuzzy at the Cmd line
06PID –Fuzzy controller
Agenda
Introductionto Fuzzy01
Fuzzification &
Defuzzification
02
Fuzzy application03
04FIS tool
3of 57
0
0.5
1
0 1 2 3 4 5 6 7 8 910
??????
(x)
x
Classical control
theory
1 0
On off
YesNo
4of 57
Classical set
theory
�=0.1,0.3,0.5&�={0.2,0.3,0.5,0.7}
�����∶�∪�={0.1,0.2,0.3,0.5,0.7}
������������∶�∩�={0.3,0.5}
����������∶�−�={0.1}
����������:ҧ�=0.9,0.7,0.5
����������������∶�×�
��������
′
����∶�∩�
′
=�′∪�′
0.1
0.3
0.5
A
0.7
0.2
B
5of 57
Crisp set VsFuzzy set
6of 57
What Fuzzy Systems?
Confused
vague
blurred
7of 57
Fuzzy
hewrotethattohandlebiologicalsystems"weneedaradically
differentkindofmathematics,themathematicsoffuzzyorcloudy
quantitieswhicharenotdescribableintermsofprobabilitydistributions"
1962
1965
Classical
control
Is a 160 m person is tall ?
True
Possibly True
9of 57
speed [m/s]
Human
knowledge-based
Rule-based
Fuzzy
IF AND
THEN
distance
speed
acceleration
small
speedis declining
maintain
IF distanceperfect AND
speedis declining
THEN increase acceleration
10of 57
aself-parkingcarin1983
Nissanhasapatentsaves
fuel
FUZZY
App.
The fuzzy washing machines
were the first major consumer
products in Japan around
1990
themostadvancedsubway
systemonearthin1987
11of 57
Fuzzy Logic
Controller
Sensor
Fuzzification
Fuzzy
Inference
System
to be
controlled
Defuzzification
Membership
function of
input fuzzy set
Rule Base
Membership
function of
output fuzzy set
Feedback
12of 57
Defuzzification Methods
Centre of
largest area
Mean–max
membership
Maxima
(MOM)
Max-membership Centre
of sums
Centroid
method
Approx. Centroid
method
13of 57
Mean of Maxima (MOM) 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 1 2 3 4 5 6 7 8
??????
Z
�
∗
=
�+�
� �
∗
=
�+�
�
=�.��
14of 57
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0 1 2 3 4 5 6 7 8
??????
Z
Centroid Method 2
also called center of area, center of gravity).
it is the most prevalent and physically appealing
of all the defuzzification methods
�
∗
=
�.�×(�+�+�)+�.�×(�+�)+�×(�+�)
(�.��)+(�.��)+(��)
�
∗
=�.���
�
∗
=
σ??????(�)�
σ??????(�)
16of 57
Autonomous driving car
distance
speed
acceleration
13 m
-2.5 m/s
?
Knowledge
Rule base
Distance to next car [ m ]
v.small small perfect big v.big
Speed
Change
[�
�
]
declining-vesmall zero +vesmall+vebig +vebig
constant -vebig-vesmall zero +vesmall+vebig
growing -vebig -vebig-vesmall zero +vesmall
speed [m/s]
17of 57
speed [m/s]
Knowledge
Rule base
Distance to next car [ m ]
v.small small perfect big v.big
Speed
Change
[�
�
]
declining-vesmallzero +vesmall+vebig+vebig
constant-vebig-vesmall zero +vesmall+vebig
growing -vebig-vebig-vesmall zero +vesmall
0.4 0.25
0.4
0.6
0.6
0.75
0.75
0.25
0.25
0.4
0.25
0.6
Rule 1:IF distance is smallAND speed is declining
THENacceleration zero
Rule 2:IF distance issmallAND speed is constant
THEN acceleration negative small
Rule 3:IF distance isperfectAND speed is declining
THEN acceleration positive small
Rule 4:IF distance is perfectAND speed is constant
THEN acceleration zero
max
Take
min
18of 57
Defuzzification using approximate COA
19of 57
Washing Machine
20of 57
Washing Machine
40
30
?
0
0.2
0.4
0.6
0.8
1
0102030405060708090100
??????
(weight)
Weight (g)
v.LightlightHeavy V.heavy
0
0.2
0.4
0.6
0.8
1
0102030405060708090100
μ
(Dirtiness)
Dirtiness (%)
Almost Clean DirtySoiled Filthy
0
0.2
0.4
0.6
0.8
1
0102030405060708090100
μ
(detergent)
Detergent (%)
v.LightlittleMuch V.MuchMaximum
Knowledge
Rule base
Weight [ Kg ]
V.LightLightHeavy V.Heavy
Dirtiness
Almost
Clean
V.LittleLittleMuch Much
Dirty LittleLittleMuch V.Much
Soiled Much Much V.MuchMaximum
FilthyV.Much Much V.MuchMaximum
weight
dirtiness
amount of
detergent output
21of 57
heavy dirty Much
heavy soiled V.Much
0
0.2
0.4
0.6
0.8
1
0102030405060708090100
μ
(Dirtiness)
Dirtiness (%)
Almost Clean DirtySoiled Filthy
0
0.2
0.4
0.6
0.8
1
0102030405060708090100
??????
(weight)
Weight (g)
v.LightlightHeavy V.heavy
Light dirty little
Light soiled Much
0.4
0.4
0.40.8 0.80.6
0.60.2 0.20.2
0.6
0.2
Little 0.4
Much 0.6
V.Much 0.2
IF weightislight(0.4) AND dirtinessis dirty(0.8)
THEN detergentis little(0.4)
IF weightislight(0.4) AND dirtinessis soiled(0.2)
THEN detergentis Much(0.2)
IF weightisheavy(0.6) AND dirtinessis dirty(0.8)
THEN detergentis Much(0.6)
IF weightisheavy(0.6) AND dirtinessis soiled(0.2)
THEN detergentis V.Much(0.2)
22of 57
0
0.2
0.4
0.6
0.8
1
0102030405060708090100
μ
(detergent)
detergent
v.Light little Much V.Much Maximum
�
∗
=
��+��
�
=��%
�
∗
=
�+�
�
�
∗
=
�.���+�.���+(�.���)
�.�+�.�+�.�
�
∗
=��.��%
�
∗
=
σ??????(�)�
σ??????(�)
0
0.2
0.4
0.6
0.8
1
0 102030405060708090100
μ
(detergent)
Detergent (%)
v.Light little Much V.Much Maximum
approximate
COA
MOM
(Mean of Maxima )
23of 57
24of 57
Inputs
Output
25of 57
Service = 3
Food = 8
Rule 1 :IF Service is poor ORFood is rancid
THENTip is cheap
Rule 2 :IFService is goodTHENTip is average
Rule 3 : IFService is excellentORFood is
deliciousTHENTip is generous
0.125
0.4
0
0
0.5
0.5
0.4
0.125
26of 57
Build Fuzzy
using
Fuzzy Logic Designer
27of 57
28of 57
Build Fuzzy
at
the Command Line
29of 57
Generate new fuzzy01
Add the first input (service)02
Add its membership functions03
30of 57
04
31of 57
Add the rules to the FIS05
Rule 1 :IF Service is poor ORFood is rancid
THENTip is cheap
Rule 2 :IFService is goodTHENTip is average
Rule 3 : IFService is excellentORFood is
deliciousTHENTip is generous
1-Index of membershipfunction for first input
5-Fuzzy operator (1for AND, 2for OR)
2 -Index of membershipfunction forsecondinput
3-Index of membershipfunction for output
4-Rule weight
41of 57
Considerasystemmodelisdescribeby:
??????(??????)=�.??????×??????(??????−�)+??????(??????−�)
PI-LikeFLCisdesignedtoregulatethissystemaroundasetpointofR=2.Fivefuzzysetsareused
torepresentthelinguisticvariablesNB,NS,Z,PSandPBforthecontrollerbothinputandoutput
variables.Triangularmembershipfunctionsareusedtorepresentthesefuzzysetsanddefinedonthe
normalizeddomain[-1,1]asshowninFig.1.Thesuggestedrule-baseisdepictedintable.Ifthe
measuredparametersareobtainedasy(k-1)=1.5andu(k-1)=0.5,findthecontrolleroutputsignal
takingintoaccounttheactualdomainofthecontrollervariablesis[-2,2].
Knowledge
Rule base
e(k)
NB NS Z PS PB
∆�(�)
NB NB NB NB NS Z
NS NB NB NS Z PS
Z NB NS Z PS PB
PS NS Z PS PB PB
PB Z PS PB PB PB
45of 57
PS Z PS
PS PS PB
Z Z Z
Z PS PS
0.1
0.1
0.10.85 0.850.9
0.90.15 0.150.1
0.85
0.15
IF e (k)isZ(0.1) AND ∆??????(??????) is Z(0.85)
THEN ∆u(??????) is Z (0.1)
IF e (k)isZ (0.1) AND ∆??????(??????) is PS (0.15)
THEN ∆u(??????) is PS (0.1)
IF e (k)isPS (0.9) AND ∆??????(??????) is Z (0.85)
THEN ∆u(??????) is PS (0.85)
IF e (k)isPS (0.9) AND ∆??????(??????) is PS (0.15)
THEN ∆u(??????) is PB (0.15)
Knowledge
Rule base
e(k)
NBNS Z PS PB
∆�(�)
NB NB NB NB NS Z
NS NB NB NS Z PS
Z NB NS Z PS PB
PS NS Z PS PB PB
PB Z PS PB PB PB
Z 0.1
PS 0.85
PB 0.15
48of 57
Tank Level Control System
5 cm ?
0
0.25
0.5
0.75
1
1.25
01234567891011121314
??????
(Level)
Liquid level (cm)
low okay high
0
0.5
1
-30-25-20-15-10-5051015202530
??????
(valve control)
Valve control signal (%/s)
close fastno change open fast
Rule 1 :IF level is okayTHENvalve is no change
Rule 2 :IFlevel is lowTHENvalve is open fast
Rule 3 : IFlevel is highTHENvalve is close fast
Liquid level
Valve control
signal
52of 57
��������������������
With reference
55of 57
References
[1]L.-X. Wang, A Course in Fuzzy Systems and Control. Prentice Hall PTR, 1997.
[2]S. N. Sivanandam, S. Sumathi, and S. N. Deepa, Introduction to Fuzzy Logic using MATLAB.
Springer, 2006.
[3]T. J. Ross, Fuzzy Logic with Engineering Applications, 2nd ed. Wiley, 2004.
[4]EssamNabil, “Autonomous driving car,” March,2019, pp. 1–13.[presentation].
[5]EssamNabil, “Fuzzy logic control system applications,” March,2019, pp. 1-30 .[presentation].
[6]EssamNabil, “Tipping problem,” March,2019, pp. 1–18.[presentation].
56of 57
References
[7]“Build Fuzzy Systems Using Fuzzy Logic Designer -MATLAB & Simulink.” [Online]. Available:
https://www.mathworks.com/help/fuzzy/building-systems-with-fuzzy-logic-toolbox-
software.html. [Accessed: 22-Nov-2019].
[8]“Build Fuzzy Systems at the Command Line -MATLAB & Simulink.” [Online]. Available:
https://www.mathworks.com/help/fuzzy/working-from-the-command-line.html.
[Accessed: 22-Nov-2019]
[9]EssamNabil, “Tank control system” March,2019, pp. 1–18.[presentation].
[10]EssamNabil, “PID -Like Fuzzy Logic control” March,2019, pp. 1–39.[presentation].