**3.1. Introduction**

In any standard book on fuzzy control, fuzzy logic control is defined to be a practical alternative for a variety of challenging control applications since it provides a convenient method for constructing non-linear controllers via the use of heuristic information. Since heuristic information may come from an operator who has acted as "a human in the loop" controller for a process. In the fuzzy control design methodology, a set of rules on how to control the process is written down and then it is incorporated into a fuzzy controller that emulates the decision making process of the human. In other cases, the heuristic information may come from a control engineer who has performed extensive mathematical modelling, analysis and development of control algorithms for a particular process. The ultimate objective of using fuzzy control is to provide a user-friendly formalism for representing and implementing the ideas we have about how to achieve high performance control. Apart from being a heavily used technology these days, fuzzy logic control is simple, effective and efficient. In this section, the structure, working and design of a fuzzy controller is discussed in detail through an in-depth analysis of the development and functioning of a fuzzy logic pH controller.

The general block diagram of a fuzzy controller is shown in figure (19). The controller is composed of four elements:


**Figure 19.** Fuzzy Controller

## **RULE BASE**

260 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

In any standard book on fuzzy control, fuzzy logic control is defined to be a practical alternative for a variety of challenging control applications since it provides a convenient method for constructing non-linear controllers via the use of heuristic information. Since heuristic information may come from an operator who has acted as "a human in the loop" controller for a process. In the fuzzy control design methodology, a set of rules on how to control the process is written down and then it is incorporated into a fuzzy controller that emulates the decision making process of the human. In other cases, the heuristic information may come from a control engineer who has performed extensive mathematical modelling, analysis and development of control algorithms for a particular process. The ultimate objective of using fuzzy control is to provide a user-friendly formalism for representing and implementing the ideas we have about how to achieve high performance control. Apart from being a heavily used technology these days, fuzzy logic control is simple, effective and efficient. In this section, the structure, working and design of a fuzzy controller is discussed in detail through an in-depth analysis of the development and functioning of a fuzzy logic

The general block diagram of a fuzzy controller is shown in figure (19). The controller is

**Figure 18.** Self tunung online test

**3. Fuzzy logic control** 

**3.1. Introduction** 

pH controller.

A Rule Base

composed of four elements:

 An Inference Mechanism A Fuzzification Interface A Defuzzification Interface This is a set of "If ……..then….." rules which contains a fuzzy logic quantification of the expert's linguistic description of how to achieve good control.

### **INFERENCE MECHANISM**

This emulates the expert's decision making in interpreting and applying knowledge about how best to control the plant.

#### **FUZZIFICATION INTERFACE**

This converts controller inputs into information that the inference mechanism can easily use to activate and apply rules.

### **DEFUZZIFICATION INTERFACE**

It converts controller inputs into information that the inference mechanism converts into actual inputs for the process.

### **SELECTION OF INPUTS AND OUTPUTS**

It should be made sure that the controller will have the proper information available to be able to make good decisions and have proper control inputs to be able to steer the system in the directions needed to be able to achieve high-performance operation.

The fuzzy controller is to be designed to automate how a human expert who is successful at this task would control the system. Such a fuzzy controller can be successfully developed using high-level languages like C, Fortran, etc. Packages like MATLAB® also support Fuzzy Logic.

### **Fuzzy Sets and Membership Function**

Given a linguistic variable Ui with a linguistic value Aij and membership function μ Aij(Ui) that maps Ui to [0,1], a 'fuzzy set is defined as

$$\text{Aii} = \left\{ \left( \text{Ui}, \,\mu \text{ Aij} \left( \text{Ui} \right) \right); \text{ Ui } \varepsilon \text{ } \nu \text{i} \right\} $$

The above written concept can be clearly understood by going through the following example. Suppose we assign Ui="PH" and linguistic value A11="base", then A11 is a fuzzy set whose membership function describes the degree of certainty that the numeric value of the temperature, Ui ε υi, possesses the property characterized by A11. This is made even clearer by the fig (20).

**Figure 20.** Membership Function

In the above example, the membership function chosen is of triangular form. There are many other membership functions like Gaussian, Trapezoidal, Sharp peak, Skewed etc. Depending on the application and choice of the designer, one could choose the shape which suits his application. Figure(21) shows just few.

**Figure 21.** 1)Triangular, 2)Trapezoidal, 3)Skewed triangular, 4)Sharp peak

In the project in hand, the fuzzy controller has two inputs, the first one is the signal from the pH transmitter and the other one is the set point. The controller has a single output which goes through saturation, Quantizer and Weighted moving average. The saturation limiter is used to protect against over range of control valve and the Quantizer and Weighted moving average are used to hold the control valve(figure (22)).

#### PH Control Using MATLAB 263

**Figure 22.** SIMULINK block diagram of the PH controller

A detailed description of the design and functioning of the fuzzy controller is given in the following section. The different sections in the fuzzy controller used in this PH controller are:


262 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

clearer by the fig (20).

**Figure 20.** Membership Function

suits his application. Figure(21) shows just few.

**Figure 21.** 1)Triangular, 2)Trapezoidal, 3)Skewed triangular, 4)Sharp peak

average are used to hold the control valve(figure (22)).

The above written concept can be clearly understood by going through the following example. Suppose we assign Ui="PH" and linguistic value A11="base", then A11 is a fuzzy set whose membership function describes the degree of certainty that the numeric value of the temperature, Ui ε υi, possesses the property characterized by A11. This is made even

In the above example, the membership function chosen is of triangular form. There are many other membership functions like Gaussian, Trapezoidal, Sharp peak, Skewed etc. Depending on the application and choice of the designer, one could choose the shape which

In the project in hand, the fuzzy controller has two inputs, the first one is the signal from the pH transmitter and the other one is the set point. The controller has a single output which goes through saturation, Quantizer and Weighted moving average. The saturation limiter is used to protect against over range of control valve and the Quantizer and Weighted moving


#### **3.2. Fuzzification section**

The variables pH, set point and percentage of opening are selected for Fuzzification. In this section, the action performed is obtaining a value of the input variable and finding the numerical values of the membership function defined for that variable. As a result of Fuzzification, the situation currently sensed (input) is converted into such a form that, it can be used by the inference mechanism to trigger the rules in the rule base.

After fuzzification, the fuzzy sets obtained are labelled using the following term set, T={**LAD, MAD, SAD, SP, SAL, MAL, LAL, FULLY CLOSED, 3Q, M, Q, FULLY OPEN , #N0**, }

*3.2.1. Input 1* 


#### *3.2.2. Input 2*

#N0(1-14 PH) = SETPOINT

*3.2.3. Output* 


The membership functions of input variables PH and output variable percentage opening shown in figures 23, 24 and 25 respectively. μi is the membership function of output. In the current work the triangular membership is chosen.

**Figure 23.** membership Function of input of PH

**Figure 24.** Membership Function of set point (input2)

**Figure 25.** Membership Function of output pH

As a result of Fuzzification, we get the names of fuzzy sets to which the input belongs and to what extent they belong to these sets, their membership functions.
