CDI PL Fuzzy Toolbox

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

CONTROLO E DECISO INTELIGENTE 08/09

PL #2 MatLab Fuzzy Toolbox


Alexandra Moutinho

Problem:

Safe distance

You are driving a 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.

Solution:

1.

Fuzzy variables. Consider the simple case: INPUT: distance d, range [0,30] m OUTPUT: brake b, range [0,100] % Three membership functions are chosen for both input and output: distance d : short, medium, long brake b : soft, medium, hard We will use the MATLAB fuzzy toolbox to define the system by giving numerical values for the variables indicated. To open the Fuzzy Inference System GUI, in MATLAB type: >> fuzzy The input and output windows are activated by clicking once on them, and symbolized by a red frame. Switching between the input and output windows, name the corresponding variables as shown in Fig. 1.

Fig. 1 Name the input and output variables. To open the membership function (MF) editor window, click twice on the input/output windows. Change the range of the variable as in Fig. 2.

Fig. 2 Set the range of the input and output variables. You can either keep the default MF or delete those (EDITREMOVE ALL MFs) and add new ones (EDITADD MFs). Lets do this. Fig. 3 shows the MF window where we can choose the type and number of the MF. Choose 3 triangular membership functions (trimf) and click CLOSE.

Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho

Fig. 3 Set membership functions. Back in the MF editor window, we can select each of the MF and name them (see Fig. 4).

Fig. 4 Name membership functions. Repeat the procedure for the MF of the output brake. 2. What is missing from the fuzzy system now is the rule base. The rule editor window (Fig. 5) is called with EDITRULES. The left-hand side contains the MF of the input distance. The right-hand side has the MF of the output brake. If the input side has several variables, connected either by and or or, the Connection block in the lower left corner is used. In this case it is not necessary. 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 rules are: If distance is short then brake is hard. If distance is medium then brake is medium. If distance is long then brake is soft. With the mouse select the MF short for the distance and hard for the brake and then click ADD RULE. This procedure is shown in Fig. 5 for the second rule. Now the design of the fuzzy system is complete. The Toolbox provides two more interesting ways of expressing the rule base. Check under OPTIONSFORMAT. Under that you can see that the
Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho 3

rules are shown in VERBOSE. The other formats are SYMBOLIC and INDEXED. Check in what form the rule base is given in each case. After finishing click CLOSE.

Fig. 5 The rule editor. 3. Viewing the rules gives you the overall picture of the developed fuzzy system. From the main FIS editor choose VIEWRULES to open the rule viewer represented in Fig. 6. On the left-hand side you can see the input distance, with the corresponding MF, and on the right-hand side you have the output brake. In the lower right corner is the result of fuzzy reasoning or defuzzification.

Result of fuzzy reasoning or defuzzification

Fig. 6 The rule viewer.

Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho

Different input values can be tried by moving the distance red vertical line. Fig. 7 represents the brake result for maximum distance input.

Fig. 7 Brake result for maximum distance input. Notice that maximum distance does not correspond to minimum brake. This is due to the defuzzification method used. By default it is centroid. You may change this in the main FIS editor window (Fig. 8).

Fig. 8 Changing the defuzzification method.

Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho

Finally, the input-output mapping can be observed by choosing VIEWSURFACE (Fig. 9). It is clear that the mapping is nonlinear. This is where the power of fuzzy is strong. Try seeing what happens to the mapping when you change between the different defuzzification methods. You may save your model for future use by choosing FILEEXPORTTO FILE.

Fig. 9 Surface viewer window.

Problem: What is missing in the previous formulation of the problem?

Relative speed! Safe distance

Correct the previous fuzzy system to take into account the relative speed of the vehicles.

Solution: Set up a new rule base with two inputs, distance and speed, and one output, brake. Only the main steps will be shown here. Add the second input, speed, by choosing EDITADD VARIABLEINPUT. Call it speed (Fig. 10). Define the range of the relative speed as [-40,40] km/h and 3 triangular membership functions: slow, medium, fast (Fig. 11).

Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho

Define the new base rule considering now the 2 inputs, distance and speed, and one output, brake.

Fig. 10 Add new input variable, speed.

Fig. 11 Add range and membership functions for relative speed. Nine rules may be constructed (Fig. 12). You may either change the existing ones or delete them and add new ones. Obviously, the rules are not unique. You may consider different ones. The rule base must be viewed and tested to see its effectiveness and how well the system specifications are satisfied (Fig. 13). Again the system may be tested by choosing different values for the two inputs. If the result is not satisfactory, then refine the system. For instance, it seems that the area of short distance and fast speed does not give hard enough brake response.
Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho 7

Fig. 12 New rule base.

Fig. 13 Rule base viewer with the new input, speed. The input-output mapping may be viewed in Fig. 14. You may change the grid points of the graphic changing the X grids and Y grids numbers. You may also change the view point of the graphic by clicking on it and rotating it. Note that the right side corner is practically flat, with small brake value over a fairly large area. You can change that by introducing a new MF little for brake and changing the rule base.

Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho

Fig. 14 Surface view of the rules.

Controlo e Deciso Inteligente PL #2 MatLab Fuzzy Toolbox - Alexandra Moutinho

You might also like