top of page

Objectives

1) To understand how to write MATLAB code of Fan Speed Control.

2) To understand how Implication Ralation works.

3) To understand steps of Fuzzy Logic Approach.

Fan Speed Control

     R1;                         IF temperature is cool           THEN fan speed is low             ELSE

     R2;                         IF temperature is medium   THEN fan speed is medium     ELSE

     R3;                         IF temperature is hot            THEN fan speed is high

 Step 1. Define Fuzzy Input and Fuzzy Output

              x=0:1:120;                                                                                                    y=0:1:10;

                   coolT          = trapmf  (x,[0 0 30 50]);                                                        lowS          = trapmf (y,[0 0 2 5]);

                   mediumT  = trimf     (x,[30 55 80]);                                                         mediumS  = trapmf (y,[2 4 6 8]);

                   hotT            = trapmf (x,[60 80 120 120]);                                                highS         = trapmf (y,[5 8 10 10]);

                   Temp          = [coolT;  mediumT;  hotT];                                                  Fanspeed  = [lowS; mediumS; highS];

    

     

 

         

Step 2. Input Crisp Value of Temperature and Fuzzify Input

               Input         =  input('Input Temperature = ');

               Acool         =  coolT         (x==Input);

               Amedium =  mediumT (x==Input);

               Ahot           =  hotT          (x==Input);

               Dinput       =  [Acool; Amedium; Ahot];

 

 

* Acool is degree of membership of fuzzy input in cool temperature set

* Amedium is degree of membership of fuzzy input in medium temperature set

* Ahot is degree of membership of fuzzy input in hot temperature set

 

Step 3. Apply Implication Relation >> Mamdani-Min

             Relation1 = mamdani (x, y, coolT,   lowS);

             Relation2 = mamdani (x, y, mediumT, mediumS); 

             Relation3 = mamdani (x, y, hotT,    highS);

             ELSE         = max(max(Relation1,Relation2),Relation3);  

 

          Select Mamdani-min Implication to find relation between antecedent part and consequent part of each rule by minimum of two membership functions instead of IF/THEN rule and connect all rules by maximum instead of ELSE

 

* Relation1 is relation of rule 1 

                     IF temperature is cool THEN fan speed is low

* Relation2 is relation of rule 2 

                     IF temperature is medium THEN fan speed is medium

* Relation3 is relation of rule 3 

                     IF temperature is hot THEN fan speed is high

 

 

 

 

 

function R = mamdani(x,y,A,C)

                 % R is relation of IP, OP each rule (R1 ,R2, R3) 

                 % x is universe of input (x=0:120)

                 % y is universe of output (y=0:10)

                 % A is Antecedent Part (cool, medium, hot)

                 % C is Consequent Part (low, medium, high)

                 R = zeros(length(A),length(C));      

        for m = 1:length(A)            

               for n = 1:length(C) 

                     R(m,n) = min(A(m),C(n));

               end

        end

end

 

Step 4. Apply Composition >> Max-Min Composition

          ClowS             =  min(Acool,   lowS);

          CmediumS    =  min(Amedium, mediumS);

          ChighS           =  min(Ahot,    highS);

          Coutput         =  [ClowS; CmediumS; ChighS];

          Speed             =  max(ClowS, max(CmediumS,ChighS));

 

 

* ClowS is fuzzy output of rule 1 

               IF temperature is cool THEN fan speed is low

* CmediumS is fuzzy output of rule 2 

               IF temperature is medium THEN fan speed is medium

* ChighS is fuzzy output of rule 3 

               IF temperature is hot THEN fan speed is high

* Speed is maximum of all fuzzy output

Step 5. Defuzzification by COA and MOM method

          Fan_Speed_COA    = (y*Speed') / sum(Speed);

          maxFuzzyOutput  = find(Speed==max(Speed));

          Fan_Speed_MOM  = (sum(maxFuzzyOutput)-length(maxFuzzyOutput))/length(maxFuzzyOutput);

 

* Fan_Speed_COA is crisp output of fan speed from COA method

* Fan_Speed_MOM is crisp output of fan speed from MOM method

Discussion

          Fuzzy control help people to decide or thinking easily. It has 5 steps to do it and each steps have many method to computed. In this fan speed control use Mamdani min implication, Max-min composition, COA and MOM defuzzification methods but it also has Zadeh max-min implication, Lasen product implication, Max-product composition, Max-average composition and so on to do fuzzy control.

          In this fuzzy control, i have somethings that very confused and not sure that i understand it correctly like i should do maximum all fuzzy output before defuzzy or i should defuzzy to get 3 COA and then maximum it.

         So if it has some mistakes i will improve it again in next time.

bottom of page