simulink fuzzy logic library - Semantic Scholar

5 downloads 0 Views 125KB Size Report
E-mail: [email protected], Fax: (202) 2850617. ** Assistant Professor ... obtain a crisp output) and other blocks to simulate easily the fuzzy systems.
SIMULINK FUZZY LOGIC LIBRARY

W. GHARIEB*, Member, IEEE, G. NAGIB** * Assistant Professor, Computer and Systems Engineering Dept., Faculty of Engineering - Ain Shams University, 1 El-Sarayat st., 11517 Abbassia, Cairo EGYPT E-mail: [email protected], Fax: (202) 2850617 ** Assistant Professor, Electrical Engineering Dept., Faculty of Engineering Cairo University - Fayoum Branch, EGYPT, Fax: (202) 084- 334031

Abstract: This paper presents the development of a fuzzy logic library using the dynamic simulation software SIMULINK under MATLAB environment. The developed library includes the main blocks: MIN (minimum operation), MAX (maximum operation), MFG (membership function generator), FUZ (fuzzifier to convert a crisp input into a fuzzy labels), F-RULES (fuzzy rules matrix), F-INF (Min-Max fuzzy inference), DEFUZ (defuzzifier to obtain a crisp output) and other blocks to simulate easily the fuzzy systems. The developed fuzzy logic library provides additional features for: education of fuzzy logic concepts for undergraduate engineeing students, simulation of fuzzy logic controllers with ease and verifying the analog hardware implementation of fuzzy logic components. Simulation examples are included to show the potential of the developed simulink fuzzy logic library. 1. INTRODUCTION

F

UZZY logic is the pioneering work of Lotfi A. Zadeh who invented the theory of fuzzy sets[1]. Fuzzy logic has two different meanings. In a narrow sense, it is an extension of multivalued logic. But in a wider sense, it is almost synonymous with the theory of fuzzy sets, a theory that relates to classes of objects with unsharp boundaries in which membership is a matter of degree. The past decade has witnessed a rapid growth in the number and variety of applications of fuzzy logic. The applications range from consumer products such as cameras, camcorders, washing machines, and microwave ovens to industrial process control, medical instrumentation, and decision-support systems[2-3]. In this paper, a fuzzy logic library is developed using the dynamic system simulation software simulink 1.2c under matlab 4.0 environment. SIMULINK is built on MATLAB numeric computation software system. This software is able to offer immediate access to a comprehensive selection of mathematical and engineering techniques for further analysis of dynamic systems. Using simulink, a new library is added in order to analyze and design fuzzy systems. The fuzzy logic library is implemented by using the existing linear and nonlinear block libraries in simulink.

The choice of using simulink offer the following advantages: Build block diagram models using familiar point-and-click manipulations. Conduct live simulations that display results during the simulation. Change the system parameters interactively and see the results immediately. The available fuzzy logic toolbox for matlab mask the technical details during implementation to simplify the simulation interface with users who are familiar and understand well the fuzzy logic. But for education, it is much better to integrate in step by step the fuzzy blocks to implement a higher level functions like fuzzy inference mechanisms. Therefore, The simulation using the developed fuzzy bolcks library enables the students and beginners to learn more and more about fuzzy logic. The paper is organized as follows: Section 1 presents the motivation to design fuzzy logic library in simulink. Section 2 is devoted to the development of fuzzy logic library where main blocks are demonstrated and design details are given. In section 3, illustrative examples are considered and presented such as fuzzy inference and fuzzy logic controller. Some concluding remarks given in section 4 end this paper. 2. FUZZY LOGIC LIBRARY The fuzzy logic library includes the following blocks as shown in Fig.1.

Fig.1. Fuzzy logic block library The developed library includes the following blocks and unlimited to add more blocks: MIN MAX MAX(4) MFG FUZ(5) FUZ(7) FILTER(5)

Compute the output as the minimum value of its 2 input signals Compute the output as the maximum value of its 2 inputs signals Compute the output as the maximum value of its 4 input signals Membership function generator of a desired fuzzy set Fuzzifier which maps a crisp input into 5 fuzzy labels (NB,NS,ZE,PS,PB) Fuzzifier which maps a crisp input into 7 labels (NB,NM,NS,ZE,PS,PM,PB) Output the 2 contiguous non-zero values of the fuzzifier output FUZ(5)

FILTER(7) F-RULES(5) F-RULES(7) XY-P GH-P R-DEC(5) S-CELLS F-INF(5) F-INF(7) DEFUZ(5) DEFUZ(7)

Output the 2 contiguous non-zero values of the fuzzifier output FUZ(7) Look-up tables to locate the applicable rules in the rules matrix 5x5 Look-up tables to locate the applicable rules in the rules matrix 7x7 Column pointers for non-zero values in the rules matrix Row pointers for non-zero values in the rules matrix Determines to which output fuzzy set the rule premise value belongs to Sliding cells to determine the applicable 4 rules in the rules matrix Min-Max fuzzy inference to generate a vector of 5 output fuzzy sets Min-Max fuzzy inference to generate a vector of 7 output fuzzy sets Defuzzifier block to transform a 5 output fuzzy sets into a crisp value Defuzzifier block to transform a 7 output fuzzy sets into a crisp value

The above blocks can be extended to any number of used fuzzy sets based on the application. Each block parameters can be entered easily using the masking option of simulink. The following subsections demonstrate the design of main blocks to explain the main idea and to show the details of implementation. 2.1 MIN block This block is designed to output the minimum value of two input signals as shown in Fig.2.

Fig.2. MIN block diagram The design of this block is based on using the existing switch block in simulink. The switch block allows a signal to select between two signals. If the switch second input is greater than or equal to zero, the first input (in_1) is propagated to the output. If the switch second input is less than zero, the third input (in_2) is produced. Parallel and cascade blocks can be used to design a MIN block for number of input signals more than two. 2.2 MAX block This block is designed to output the maximum value of two input signals as shown in Fig.3. the design is similar to the MIN block but the polarity of summer inputs is reversed. Parallel and cascade blocks can be used to design a MAX block for number of input signals more than two. MAX(4) block computs the maximum of 4 input signals using this method.

Fig.3. MAX block diagram 2.3 MFG block MFG block is designed to generate a membership function and to output the value of suitable grade. This block can be tuned easily to obtain any piece-wise linear characteristics such as: triangular, trapezoidal and singleton forms. Fuzzy set can be represented as one of {NB, NM, NS, ZE, PS, PM, PB} using the MFG block. Therefore, the fuzzifier is an array of MFG’s as the number of fuzzy sets specified. Fig.4 represents the membership function µ of the used fuzzy set. A triangular form is obtained by adjusting P2=P3 and a singleton is obtained by adjusting (P1=P4 & P2=P3). Furthermore, these parameters can be tuned to generate any one of the above fuzzy sets by shifting its scope on the universe of a normalized discourse between the values (-1, +1). This block gives the positive and the negative slope characteristics as illustrated in Fig.4. Positive slope characteristic generates the positive part which can be tuned by adjusting points (P3&P4) and clipping element (saturation block) is used to provide only the characteristics between (0, 1). Negative slope characteristic is generated by adjusting (P1&P2) and the clipping element (saturation block). µ

-1

P2

P3

+1

P4

P1

+1

scope

Universe of discourse Fig.4. Membership function

The complete characteristics is obtained using simulink as in Fig.5. by setting: lower limit of saturation = -1, lower limit of saturation1= 0, lower limit of saturation2= 0, Gain1= 1/(P3-P4), Gain2= -1/(P1-P2),

upper limit of saturation = +1 upper limit of saturation1= +1 upper limit of saturation2= +1 Const1= -P4/(P3-P4) Const2= P1/(P1-P2)

Fig.5. Membership function generator 2.4 FUZ block This block is used to perform the fuzzification interface. It converts the input crisp signal into suitable linguistic variables which may be viewed as labels of fuzzy sets. Fig.6. shows the fuzzifier block using 5 fuzzy labels NB, NS, ZE, PS, PB. Each of these labels is generated using MFG block with apropriate tuning of the parameters P1, P2, P3 and P4. The output fuzzy vector is multiplexed to make easily the interface between other fuzzy blocks.

Fig.6. Fuzzifier block 2.5 DEFUZ block This block is used to perform the defuzzification interface. It converts the fuzzy output into a crisp value using center of gravity method. This method takes the average of the control action values weighted by the grade of membership[4]. Fig.7 shows the design concept using the support values of a five fuzzy singleton MF’s (NB,NS,ZE,PS,PB). These support values are feded to five multipliers in pair groups where the second input of each multiplier is the rule premise value. Then, the outputs of the multipliers are added to be divided by the sum of rules premise values.

Fig.7. Defuzzifier block 3. SIMULATION EXAMPLES 3.1 Membership function generator In this example, a demonstration to a membership function generator is exposed. Fig.8. shows the block diagram of the example where the input signal is chosen as a repeating sequence to represente the normalized crisp input between (-1, +1). Both input and output signals of the MFG block are connected to xy graph display block, where the crisp input (repeated sequence) is x and the output from MFG is y. MFG is masked and the user can enter the parameters P1, P2, P3 and P4 and modifying them during simulation to show many membership functions (triangular, trapezoidal, singleton, ... etc).

Fig.8. Membership function generation

3.2 Fuzzy inference The concept of min-max fuzzy inference is shown in Fig.9. For each crisp value of error E and error change DE there are always 2 contiguous non-zero grade values in the output fuzzification vector. So, the fuzzification vector of error can be connected to the input (in_2) which is followed by a filter. The filter outputs the 2 contiguous non-zero values. A similar operation is performed to the input (in_3) which is connected to the fuzzification vector of DE. Therefor, 4 rules only can be applied which are the intersection of 2 rows and 2 columns in the rules matrix. The S-CELLS block determines the premise value of each applicable rule (minimum operation), While the look-up tables in F-RULES block determines the corresponding label index (NB=1, NS=2, ZE=3, PS=4, PB=5). An array of Ruels decoders are used to connect each rule premise value to the MAX block corresponding to the output fuzzy label. Finally, all outputs are multiplexed to connect easily this block in different applications.

Fig.9. Fuzzy inference block 3.3 Fuzzy controller The Fuzzy controller consists mainly of 4 blocks as shown in Fig.10: FUZ block to fuzzify the error signal E FUZ block to fuzzify the error variation DE F-INF block to generate the fuzzy controller output DEFUZ block to generate a crisp output Three gains GE, GDE, GU are used to scale the inputs and output signals according to the application, where the basic controller structure uses a normalized scales (-1, +1).

Fig.10. Fuzzy controller structure 4. CONCLUDING REMARKS Fuzzy logic library provides the following features for: • Education of a basic fuzzy logic course for undergraduate engineering students, that means, the concepts of fuzzy sets theory and fuzzy logic can be demonstrated through a group of experiments such as, - Study the different membership functions - Implement fuzzification vector to mapp a crisp variable into a degree of memebership - Implement the fuzzy inference - Study the different defuzzification methods - ...etc. • Simulation of fuzzy logic controller and test its performance on different dynamic models using the simulink graphic editor to implement the closed loop system. • Implementation of analog hardware fuzzy logic components in verifying their logic functions and investigating their performance[5].

REFERENCES [1]

L. A. Zadeh, “Fuzzy Sets”, Inform. and Contr., Vol.8, pp.338-353, 1965.

[2]

J. Maiers and Y. S. Sherif, “Applications of Fuzzy Set Theory”, IEEE Trans. on Systems, Man and Cybernetics, Vol. SMC-15, n°1, Jan./Feb. 1985.

[3]

H.-J Zimmermann, “Fuzzy Set Theory and Its Applications”, Kluwer Academic Publishers, 2nd edition, 6th printing, 1993.

[4]

C.C. Lee, “Fuzzy Logic in Control Systems: Fuzzy Logic Controller, Part II”, IEEE Trans. Syst. Man. Cybern., vol.20, n°2, pp.419-435, 1990.

[5]

W. Gharieb, “Hardware Fuzzy Logic Kit Design”, 6th IEEE Int. Conf. on Fuzzy Systems, vol.n° 2/3, pp.1039-1043, Barcelona SPAIN, July 1-5, 1997.