Question? Leave a message!




Applications of fuzzy control systems

applications of fuzzy algorithm for control a simple dynamic plant and a survey on industrial applications of fuzzy control application of fuzzy control systems to industrial processes
Dr.NaveenBansal Profile Pic
Dr.NaveenBansal,India,Teacher
Published Date:25-10-2017
Your Website URL(Optional)
Comment
CHAPTER 7 Some Applications of Fuzzy Control This chapter introduces some engineering applications of fuzzy logic and fuzzy control systems. The purpose of this introduction is mainly to illustrate workability and applicability of fuzzy logic and fuzzy control in real-life situations, based on the fuzzy systems theories developed in the previous chapters of the book. Three main applications are introduced in the following order: a fuzzy rule-based expert system for a health care diagnostic system monitoring vital signs of a human patient, a fuzzy control system for an autofocus camera lens system, and a fuzzy modeling and design of a fuzzy controller for a servo system. For each application, a description of the functionality of the system is given, followed by the fuzzy logic rules and computer simulation results. I. HEALTH MONITORING FUZZY DIAGNOSTIC SYSTEMS Diagnostic systems are used to monitor the behavior of a process and identify certain pre-defined patterns that associate with well-known problems. These problems, once identified, imply suggestions for specific treatment. Most diagnostic systems are in the form of a rule-based expert system: a set of rules is used to describe certain patterns. Observed data are collected and used to evaluate these rules. If the rules are logically satisfied, the pattern is identified, and a problem associated with that pattern is suggested. Each particular problem might imply a specific treatment. In general, the diagnostic systems are used for consultation rather than replacement of human expert. Therefore, the final decision is still with the human expert to determine the cause and to prescribe the treatment. Most current health monitoring systems only check the body’s temperature, blood pressure, and heart rate against individual upper and lower limits and start an audible alarm should each signal move out of its predefined range (either above the upper limit or below the lower limit). Then, human experts (nurses or physicians) will have to examine the patient and probe the patient’s body further for additional data that lead to proper diagnosis and its corresponding treatment. Other more complicated systems normally involve more sensors that provide more data but still follow the same pattern of independently checking individual sets of data against some upper and lower limits. The warning alarm from these systems only carries a meaning that there is something wrong with the patient. Thus, attending staff would have to wait for the physician to make a diagnostic examination before they could properly prepare necessary equipment for a corresponding treatment. In a life- threatening situation, reducing the physician’s reaction time (the time between the warning and the time proper treatment is given to the patient) by preparing272 Some Applications of Fuzzy Control •• 7 proper equipment for specific treatment in advance would significantly increase the patient’s chance of surviving. In the field of exploration where a team of humans is sent to a distant and isolated location, it is important to have a health monitoring system that can give early diagnostic data of each explorer’s health status to prepare for the continuation of the mission. In space exploration missions, an astronaut who suddenly gets sick will be diagnosed and the data reviewed by the onboard physician as well as the physician team on earth to determine if a proper treatment onboard is possible (for the continuation of the mission) or if specific treatment on earth is required (for the abortion of the mission). Therefore, the health monitoring system is playing two roles in every space mission: to monitor the health of the astronaut, and to aid in determining if a mission should be continued or aborted (due to serious illness). This section presents a simple implementation of a health monitoring expert system utilizing fuzzy rules for its rule base. This health monitoring expert system consists of a set of sensors monitoring three vital signs of a patient: body temperature, blood pressure, and heart rate. A. Fuzzy Rule-Based Health Monitoring Expert Systems In this system, we will implement a fuzzy rule-based expert health monitoring system with three basic sensors: body temperature, heart rate, and blood pressure. Note that the blood pressure is measured in two readings: systolic pressure (the maximum pressure that the blood exerts on the blood vessel, i.e., the aorta, when the pumping chamber of the heart contracts), and diastolic pressure (the lowest pressure that remains in the small blood vessel when the pumping chamber of the heart relaxes). For simplicity of discussion, only diastolic pressure is used, with the understanding that an additional reading can be easily added to the system and the number of diagnostic cases will increase accordingly. The expert system will check for combinations of data instead of individual data and thus will identify twenty-seven different scenarios instead of three in the conventional system. Individual sensors can identify three isolated cases: (i) high body temperature indicates high fever normally associated with the body fighting against some infectious virus or bacteria, some hormone disorder such as hyperthyroidism, some autoimmune disorder such as rheumatoid arthritis, or some damage to the hypothalamus; (ii) high blood pressure indicates hypertension normally associated with some kidney disease, hormonal disorder such as hyperaldoteronism, or acute lead poisoning; and (iii) high heart rate indicates rapid heart beat normally associated with an increase in adrenaline (a hormone produced by the adrenal glands) production. In addition, three more cases can be identified: (iv) low body temperature indicates hypothermia; (v) low blood pressure normally associates with excess bleeding, muscle damage, heart valve disorder, or excessive sweating/urination; and (vi) low heart rate normally associates with abnormal pacemaker or with the blockage between the pacemaker and the atria where pacemaker signal is received to stimulate heartbeats.7•• Some Applications of Fuzzy Control 273 µ L N H 1 1 1 1 0 x 1 96°F 98°F 100°F Figure 7.1 Definitions and membership functions of three different ranges for body temperatures. µ L N H 2 2 2 1 0 x 2 100 120 140 Figure 7.2 Definitions and membership functions of three different ranges for blood pressure. µ L N H 3 3 3 1 0 x 3 40 70 100 Figure 7.3 Definitions and membership functions of three different ranges for heart rate. However, the three individual sensors, each with three settings (normal, high, and low), can be combined to give 27 different scenarios. With the perfectly normal case (where all three give normal readings) and the six cases defined above, there are additionally 20 more cases where combinations of abnormal readings can be observed. For example, low blood pressure and high body temperature might indicate severe exposure to heat, a severe loss of blood, or lack of body fluid. Let x be the body temperature, x the (systolic) blood pressure, x the heart 1 2 3 rate, and y the diagnostic statement. Let L , N , and H represent the three sets i i i of low range, normal range, and high range for sensor data x , where i = 1, 2, i or 3. Furthermore, let C , C , C , ..., C be the individual scenarios that could 0 1 2 26 happen for each combination of the different data sets.274 Some Applications of Fuzzy Control •• 7 The low range for the body temperature can be defined as below 98°F. Similarly, the normal range is 98°F, and high range is above 98°F. One can define three ranges and three membership functions as in Figure 7.1. These functions have the mathematical representation as follows: ⎧ 1 if −∞ x ≤ 96°F, 1 ⎪ µ (x ) = (98− x ) / 2 if 96°F x ≤ 98°F, L 1 ⎨ 1 1 1 ⎪ 0 if 98°F x ∞, 1 ⎩ ⎧ (x − 96) / 2 if 96°F x ≤ 98°F, 1 1 ⎪ µ (x ) = (100− x ) / 2 if 98°F x ≤100°F, N 1 ⎨ 1 1 1 ⎪ 0 else, ⎩ ⎧ 0 if −∞ x ≤ 98°F, 1 ⎪ µ (x ) = (x − 98) / 2 if 98°F x ≤ 100°F, H 1 ⎨ 1 1 1 ⎪ 1 if 100°F x ∞, 1 ⎩ ⎧ 1 if −∞ x ≤ 100 Hg, 2 ⎪ µ (x ) = (120− x ) / 20 if 100 Hg x ≤ 120 Hg, L 2 ⎨ 2 2 2 ⎪ 0 if 120 Hg x ∞, 2 ⎩ ⎧ (x −100) / 20 if 100 Hg x ≤ 120 Hg, 2 2 ⎪ µ (x ) = (140− x ) / 20 if 120 Hg x ≤ 140 Hg, N 2 ⎨ 2 2 2 ⎪ 0 else, ⎩ ⎧ 0 if −∞ x ≤ 120 Hg, 2 ⎪ µ (x ) = (x −120) / 20 if 120 Hg x ≤ 140 Hg, H 2 ⎨ 2 2 2 ⎪ 1 if 140 Hg x ∞, 2 ⎩ ⎧ 1 if −∞ x ≤ 40 Hz, 3 ⎪ µ (x ) = (70− x ) / 30 if 40 Hz x ≤ 70 Hz, L 3 ⎨ 3 3 3 ⎪ 0 if 70 Hz x ∞, 3 ⎩ ⎧ (x − 40) / 30 if 40 Hz x ≤ 70 Hz, 3 3 ⎪ µ (x ) = (100− x ) / 30 if 70 Hz x ≤ 100 Hz, N 3 ⎨ 3 3 3 ⎪ 0 else, ⎩ ⎧ 0 if −∞ x ≤ 70 Hz, 3 ⎪ µ (x ) = (x − 70) / 30 if 70 Hz x ≤ 100 Hz, H 3 ⎨ 1 3 3 ⎪ 1 if 100 Hz x ∞. 3 ⎩ From this knowledge, four basic rules can be defined as follows: (0) R :IF x is N AND x is N AND x is N THEN y is C 1 1 2 2 3 3 0 (1) R :IF x is H AND x is N AND x is N THEN y is C 1 1 2 2 3 3 1 (2) R :IF x is N AND x is H AND x is N THEN y is C 1 1 2 2 3 3 2 (3) R :IF x is N AND x is N AND x is H THEN y is C . 1 1 2 2 3 3 37•• Some Applications of Fuzzy Control 275 In addition, three scenarios can be identified when only one sensor provides data that are lower than the lower limit: (4) R :IF x is L AND x is N AND x is N THEN y is C 1 1 2 2 3 3 4 (5) R :IF x is N AND x is L AND x is N THEN y is C 1 1 2 2 3 3 5 (6) R :IF x is N AND x is N AND x is L THEN y is C . 1 1 2 2 3 3 6 It can be seen that C corresponds to normal condition, C high fever, C 0 1 2 hypertension, C rapid heart rate, C hypothermia, C low blood pressure, and 3 4 5 C low heart rate. The remaining 20 cases can be defined as follows: 6 (7) R :IF x is L AND x is L AND x is L THEN y is C 1 1 2 2 3 3 7 (8) R :IF x is L AND x is L AND x is N THEN y is C 1 1 2 2 3 3 8 (9) R :IF x is L AND x is L AND x is H THEN y is C 1 1 2 2 3 3 9 (10) R :IF x is L AND x is N AND x is L THEN y is C 1 1 2 2 3 3 10 (11) R :IF x is L AND x is N AND x is H THEN y is C 1 1 2 2 3 3 11 (12) R :IF x is L AND x is H AND x is L THEN y is C 1 1 2 2 3 3 12 (13) R :IF x is L AND x is H AND x is N THEN y is C 1 1 2 2 3 3 13 (14) R :IF x is L AND x is H AND x is H THEN y is C 1 1 2 2 3 3 14 (15) R :IF x is N AND x is L AND x is L THEN y is C 1 1 2 2 3 3 15 (16) R :IF x is N AND x is L AND x is H THEN y is C 1 1 2 2 3 3 16 (17) R :IF x is N AND x is H AND x is L THEN y is C 1 1 2 2 3 3 17 (18) R :IF x is N AND x is H AND x is H THEN y is C 1 1 2 2 3 3 18 (19) R :IF x is H AND x is L AND x is L THEN y is C 1 1 2 2 3 3 19 (20) R :IF x is H AND x is L AND x is N THEN y is C 1 1 2 2 3 3 20 (21) R :IF x is H AND x is L AND x is H THEN y is C 1 1 2 2 3 3 21 (22) R :IF x is H AND x is N AND x is L THEN y is C 1 1 2 2 3 3 22 (23) R :IF x is H AND x is N AND x is H THEN y is C 1 1 2 2 3 3 23 (24) R :IF x is H AND x is H AND x is L THEN y is C 1 1 2 2 3 3 24 (25) R :IF x is H AND x is H AND x is N THEN y is C 1 1 2 2 3 3 25 (26) R :IF x is H AND x is H AND x is H THEN y is C . 1 1 2 2 3 3 26 Physicians can provide their knowledge in medical science to label individual cases C for i = 7, 8, ..., 26. For example, the condition C with i 26 high body temperature, high blood pressure, and high heart rate might indicate hyperthyroidism (a condition in which excess thyroid hormone is produced); the condition C with high body temperature, high blood pressure, and 25 normal heart rate might indicate pheochromocytoma (a tumor in the adrenal gland causing overproduction of a hormone that triggers high blood pressure and raises body temperature), or the condition C with high body 20 temperature, low blood pressure, and normal heart rate might indicate heat stroke (a condition associated with prolonged exposure to heat). The membership function for a rule is calculated as a minimum of the memberships of individual conditions, i.e., the membership functions for rules (0) (1) (2) (3) R , R , R , and R are: µ (0)(x ,x ,x ) = min µ (x ),µ (x ),µ (x ) , 1 2 3 1 2 3 R N N N 1 2 3 µ (1)(x ,x ,x ) = min µ (x ),µ (x ),µ (x ) , 1 2 3 1 2 3 R H N N 1 2 3 µ (2)(x ,x ,x ) = min µ (x ),µ (x ),µ (x ) , 1 2 3 1 2 3 R N H N 1 2 3 µ (3)(x ,x ,x ) = min µ (x ),µ (x ),µ (x ) . 1 2 3 1 2 3 R N N H 1 2 3276 Some Applications of Fuzzy Control •• 7 (4) (26) The membership functions for rules R through R can be similarly established according to their corresponding rules given earlier. B. Computer Simulations In this section, numerical simulations are created to demonstrate the workability of the 27 rules given in the previous section representing a health monitoring expert system. (1) (2) Example 7.1. In this example, the rules R for high fever, R for (3) hypertension, and R for rapid heart rate are tested. The temperature profile x (t), blood pressure profile x (t), and heart rate profile x (t) are generated 1 2 3 according to the following formulas: π x (t) = 98 + 4 sin( t) e(t) + n(t), 1 20 π x (t) = 120 + 40 sin( t) e(t – 20) + n(t), 2 20 π x (t) = 70 + 60 sin( t) e(t – 40) + n(t), 3 20 where the function n(t) is random white noise and e(t) the rectangular envelop function of the form: ⎧ 1 if 0≤ x≤ 20, e(t) = . ⎨ 0 else. ⎩ These three formulas for x (t), x (t), and x (t) create three separate time 1 2 3 intervals, I ≈ 7,13), I ≈ 27,33), and I ≈ 47,53). These data profiles will 1 2 3 (1) (2) (3) result in rule R being valid in I , rule R valid in I , and rule R valid in I . 1 2 3 (1) Thus, the expected membership function µ (x ,x ,x ) should yield the value 1 R 1 2 3 for t ∈ I and the value 0 for everywhere else. Similarly, the expected 1 (2) membership function µ (x ,x ,x ) should yield the value 1 for t ∈ I and the R 1 2 3 2 (3) value 0 for everywhere else, and the membership function µ (x ,x ,x ) should R 1 2 3 yield the value 1 for t∈ I and the value 0 for everywhere else. 3 (20) Example 7.2. In this example, the rule R for heat stroke condition (high body temperature, low blood pressure, and normal heart rate) is tested. The temperature profile x (t), blood pressure profile x (t), and heart rate profile 1 2 x (t) are generated according to the following formulas: 3 π x (t) = 98 + 4 sin( t) e(t) + n(t), 1 40 π x (t) = 120 – 40 sin( t) e(t) + n(t), 2 40 x (t) = 70 + n(t), 3 where the function n(t) is random white noise and e(t) the rectangular envelop function described in the previous example. These three formulas for x (t), 1 (20) x (t), and x (t) create an interval I ≈ 10,30) where the rule R will be valid, 2 3 4 (20) i.e., the membership function µ (x ,x ,x ) should yield the value 1 for t ∈ I R 1 2 3 4 and the value 0 for everywhere else.7•• Some Applications of Fuzzy Control 277 (26) Example 7.3. In this example, the rule R for hyperthyroidism (high body temperature, high blood pressure, and rapid heart rate) is tested. The temperature profile x (t), blood pressure profile x (t), and heart rate profile 1 2 x (t) are generated according to the following formulas: 3 π x (t) = 98 + 4 sin( t) e(t) + n(t), 1 40 π x (t) = 120 + 40 sin( t) e(t) + n(t), 2 40 π x (t) = 70 + 60 sin( t) e(t) + n(t), 3 40 where the function n(t) is random white noise and e(t) the rectangular envelop function described in Example 7.1. These three formulas for x (t), x (t), and 1 2 (26) x (t) create an interval I ≈ 10,30) where the rule R will be valid, i.e., the 3 5 (26) membership function µ (x ,x ,x ) should yield the value 1 for t ∈ I and the R 1 2 3 5 value 0 for everywhere else. C. Numerical Results In this section, computer simulations are created for the three examples listed in the previous section. Data are generated at the rate of one sample per second for the duration of 75 seconds. For each example, three sets of data, X 1 = x (n) n = 0, 1, 2, …, 74 , X = x (n) n = 0, 1, 2, …, 74 , and X = 1 2 2 3 x (n) n = 0, 1, 2, …, 74 , are generated. In Example 7.1, the membership 3 (1) (2) (3) functions µ (x (n),x (n),x (n)), µ (x (n),x (n),x (n)), µ (x (n),x (n),x (n)) R 1 2 3 R 1 2 3 R 1 2 3 are generated for n = 0, 1, 2, …, 74. In Examples 7.2 and 7.3, the membership (20) (26) functions µ (x (n),x (n),x (n)) and µ (x (n),x (n),x (n)) are also generated R 1 2 3 R 1 2 3 for n = 0, 1, 2, …, 74. Figures 7.4, 7.5, and 7.6 show the plot of the data x (t) for body 1 temperature, x (t) for blood pressure, and x (t) for heart rate generated for 2 3 Example 7.1. Figure 7.8 shows the resulting membership functions of the three conditions C , C , and C tested in Example 7.1. The data are generated 1 2 3 at the beginning of each time interval of 1 second, for 75 seconds. In the first 20 seconds, x (t) and x (t) are in normal range, and x (t) is gradually moving 2 3 1 toward the high range, causing the membership function of condition C to 1 rise toward 1. Similarly, during the time interval 20,40, x (t) and x (t) are in 1 3 normal range, and x (t) is gradually moving toward the high range, causing the 2 membership function of condition C to rise toward 1; and during the time 2 interval 40,60, x (t) and x (t) are in normal range, and x (t) is gradually 1 2 3 moving toward the high range, causing the membership function of condition C to rise toward 1. After that, all three signals go back to normal, causing the 3 membership function for condition C to rise toward 1. 0 Figures 7.8, 7.9, and 7.10 show the plot of the data x (t), x (t), and x (t) 1 2 3 generated for Example 7.2. Figure 7.11 shows the resulting membership function for condition C . Here, conditions for x (t) to be high, x (t) to be low, 20 1 2 and x (t) to be normal are simulated. The corresponding membership for 3 (20) condition C is shown to confirm that the rule R is valid. 20278 Some Applications of Fuzzy Control •• 7 103 102 101 100 99 98 97 0 10 2030 4050 6070 80 Figure 7.4 Body temperature profile for Example 7.1. 170 150 130 110 0 10 2030 4050 6070 80 Figure 7.5 Blood pressure profile for Example 7.1. 140 120 100 80 60 0 10 2030 4050 6070 80 Figure 7.6 Heart rate profile for Example 7.1. 1.2 1 0.8 0.6 0.4 0.2 0 0 10 2030 4050 607080 -0.2 Figure 7.7 Membership functions of conditions C , C , and C for Example 1 2 3 7.1.7•• Some Applications of Fuzzy Control 279 103 102 101 100 99 98 97 0 10 2030 4050 6070 80 Figure 7.8 Body temperature profile for Example 7.2. 130 120 110 100 90 80 70 0 10 2030 4050 6070 80 Figure 7.9 Blood pressure profile for Example 7.2. 80 75 70 65 60 0 102030 40 50607080 Figure 7.10 Heart rate profile for Example 7.2. 1 0.8 0.6 0.4 0.2 0 0 102030 4050607080 Figure 7.11 Membership function of condition C for Example 7.2. 20280 Some Applications of Fuzzy Control •• 7 103 102 101 100 99 98 97 0 10 2030 4050 6070 80 Figure 7.12 Body temperature profile for Example 7.3. 170 160 150 140 130 120 110 0 10 2030 4050 6070 80 Figure 7.13 Blood pressure profile for Example 7.3. 140 120 100 80 60 0 10 2030 4050 6070 80 Figure 7.14 Heart rate profile for Example 7.3. 1 0.5 0 0 10 2030 4050 6070 80 Figure 7.15 Membership function of condition C for Example 7.3. 267•• Some Applications of Fuzzy Control 281 Figures 7.12, 7.13, and 7.14 show the plot of the data x (t), x (t), and x (t) 1 2 3 generated for Example 7.3. Here, conditions for x (t) to be high, x (t) to be 1 2 high, and x (t) to be high are simulated. The corresponding membership for 3 (26) condition C is shown in Figure 7.15 to confirm that the rule R is valid. 26 II. FUZZY CONTROL OF IMAGE SHARPNESS FOR AUTOFOCUS CAMERAS Recent implementation of fuzzy logic in popular household items has increased the public awareness of fuzzy logic. One of such applications is the use of fuzzy logic rules to control a focus ring of a camera to allow automatic focusing for a sharp image. A camera is an imaging system consisting of a set of lens that projects an image of a scene onto a sensor (either a film plate for conventional cameras or a set of CCD sensors for digital cameras). Traditional cameras require humans to manually adjust the focus control ring to obtain a sharp picture, i.e., the focusing position where the film plate (or sensor plate) coincides with the projected image. If the film plate is not at the position the image is projected, the captured picture on the film plate (or sensor plate) appears to be blurry; this phenomenon is called “out-of-focus.” Image-processing techniques have been developed to help determine the quality of a digital picture. The quality of a picture can be the color balance, the smoothness of spatial picture elements, the sharpness of the image, etc. For the purpose of controlling the focusing ring, the sharpness of an image is used as the determining factor. This quality determination technique for a digital image is used to help control the focusing ring of the lens system, so that the film plate is placed precisely at the distance an image is projected and a sharp picture is thus obtained. It is understood that the image is in-focus when its sharpness is at maximum level. From a control standpoint, a servomotor is connected to the internal gear that controls the focusing ring to adjust the focal point and projected image point. The position of this focusing ring determines the position of each lens element to put the image (of an object) at the film plate located at a fixed distance behind the lens system. This automatic control system constitutes an autofocus lens of a camera. In this section, the use of fuzzy logic to control the focusing ring in an autofocus lens system is outlined. This control scheme is a combination of position fuzzy control rules and the calculated sharpness of a picture as feedback. The calculation effort involved in this procedure is relatively simple; therefore, it is easy to be implemented on an inexpensive system with little computing power. The operating cycle can be summarized in four steps: (i) a digital image is captured, (ii) the sharpness index is calculated, (iii) the new position of the focusing ring is calculated and sent to the mechanical servo, and (iv) the servo controls the ring to the desired position. 282 Some Applications of Fuzzy Control •• 7 calculate the compare this difference in value difference against a if higher, the pixel of a pixel and its predetermined represents an edge neighbor pixel threshold update the counter if lower, the pixel to keep track of how represents an inner many pixels are region representing edges Figure 7.16 Algorithm for calculating sharpness index of a digital picture. This section describes a procedure to calculate the sharpness of a digital image, and the fuzzy control algorithm that uses this sharpness index as feedback to control the focusing ring to maximize the sharpness index. A. Basic Image Processing Techniques A digital picture consists of a two-dimensional array of picture elements (or pixels). Each pixel represents light intensity at a spatial location. Together, the pixels represent the image of an object (or a scene of several objects). There are several numerical techniques to determine if a digital picture is sharp (or in focus). This section describes a basic technique based on the edge-detection algorithm. The edge-detection algorithm will determine the edge of the object. It is assumed that a sharp picture will yield clearly defined edges around the objects. Therefore, a sharp picture will yield more edges than a blurred picture (of the same scenario or of the same object). This edge- detection technique is introduced here because it is simple to understand, computationally efficient for real-time implementation, and effective enough for determining the sharpness of a digital picture. Edge-detection algorithm is a numerical method performed on the spatial relations between adjacent pixels to determine the boundary between two distinct regions on a two-dimensional space. The method consists of two steps: (i) calculation of the difference between two adjacent pixels, and (ii) applying a threshold filter to determine if this difference represents an edge of an object. Let i(n,m) represents a gray-scaled digital picture of dimension N×M. The edge-detection algorithm will calculate a binary image e(n,m) (with pixels of values of either zero or one) representing the edges of the objects in the digital picture i(n,m). The edge-detection algorithm can be represented by the formula: ⎧ 1 if i(n, m)− i(n+ 1, m) ≥θ e(n,m) = (7.1) ⎨ 0 else, ⎩7•• Some Applications of Fuzzy Control 283 int sharpnessIndex( int image, int Ndim, intMdim, int t ) int sIndex = 0; for( int n = 1; n = Ndim; n++ ) for( int m = 1; m = Mdim; m++ ) if( abs(imagenm-imagen+1m) t ) sIndex++ return( sIndex ); Figure 7.17 Implementation of sharpness index using C-programming language. where θ is a pre-determined numerical constant representing a threshold that distinguishes between edge and non-edge. A digital picture is considered sharp if the edges are distinctive, i.e., the number of pixels representing the edges calculated in (7.1) is at its maximum. A blurred picture will not produce so many distinct edges. Therefore, a scalar variable s can be formulated as follows to determine the sharpness of a digital picture: N M s = e(n, m) . (7.2) ∑∑ n== 11 m The variable s is sometimes referred to as a sharpness index. The higher the sharpness index, the more focused the picture becomes. This quantity can also be normalized so that its range is standardized at between the value of zero and one. The normalized sharpness is calculated as N M 1 s = e(n,m) . ∑∑ NM n== 11 m The higher the value of s, the more contrast is the image. It is reasoned that for the same scene, the image which contains more contrast is assumed to be the one correctly focused. When incorrectly focused, the image becomes blurred. This effect is similar to that of a smooth filter. Therefore, the contrast is less for images that are off-focused. Figure 7.16 depicts an algorithm for calculating the sharpness index of a digital picture. A typical implementation of this calculation using C- programming language is listed in Figure 7.17 to illustrate the development efficiency of the algorithm. B. Fuzzy Control Model The fuzzy control model is relatively simple for a position control. The rules can be intuitively derived with minor adjustment to improve the performance. 1. Fixed Rate. This is the simplest form of position control. For each control cycle, the position of the focusing ring is moved by a fixed constant in either direction. The focusing ring can also stay where it was. Thus, there are only three choices: (i) move the focusing ring counterclockwise by an angle ∆θ , (ii) move the focusing ring clockwise by an angle ∆θ , or (iii) do not move 284 Some Applications of Fuzzy Control •• 7 µ µ µ NEGATIVE POSITIVE µ ZERO R –∞ ∞ –α 0 α Figure 7.18 Membership functions µ (⋅),µ (⋅), and µ (⋅). POSITIVE NEGATIVE ZERO the focusing ring at all. These selections are similar to that of a bang-bang control, where the fixed control measure is either positive or negative. When the system is in a deadband, the control measure is zero. Basically, the three rules above can be applied to the three situations: when the focusing is moving in the right direction, i.e., the sharpness index is increasing, keep moving in that direction; when the focusing ring is moving in the wrong direction, i.e., the sharpness index is decreasing, start moving in the opposite direction; and when there is no improvement in the sharpness index, stop. Let σ be the current sharpness index, σ the previous sharpness index, now prev θ the current position of the focusing ring, θ the previous position of the now now focusing ring, D (which can be either +1 or –1) the previous direction of prev the ring movement, and ∆θ the fixed step that the focusing ring can move for each control cycle. Then these three rules can be given as follows: (1) R : IF (σ –σ ) is POSITIVE now prev THEN D = D AND θ = θ + D ∆θ , now prev now prev now (2) R : IF (σ –σ ) is NEGATIVE now prev THEN D = –D AND θ = θ + D ∆θ , now prev now prev now (3) R : IF (σ –σ ) is ZERO now prev THEN D = D AND θ = θ . now prev now prev For each description POSITIVE, NEGATIVE, and ZERO, there associate three ranges R = x ,∞), R = –x ,–∞), and R = –x ,x , and POSITIVE 1 NEGATIVE 1 ZERO 2 2 three membership functions µ (⋅), µ (⋅), and µ (⋅). These POSITIVE NEGATIVE ZERO ranges and membership functions will determine the final numerical angle that the focusing ring should be rotated to. Figure 7.18 shows a typical setup for the three ranges R , R , POSITIVE NEGATIVE and R , and their corresponding membership functions µ (⋅), ZERO POSITIVE µ (⋅), and µ (⋅). In this setup, the constant x is set to be equal to x , NEGATIVE ZERO 1 2 i.e., x = x = α. The membership functions in Figure 7.18 can be expressed 1 2 mathematically as:7•• Some Applications of Fuzzy Control 285 1 if −∞ x≤α, ⎧ ⎪ µ (x) = − x /α if α x≤ 0, (7.3) NEGATIVE ⎨ ⎪ 0 else, ⎩ (x+α) /α if −α x≤ 0, ⎧ ⎪ µ (x) = (α− x) /α if 0 x≤α, (7.4) ZERO ⎨ ⎪ 0 else, ⎩ x /α if 0≤ xα, ⎧ ⎪ µ (x) = 1 if α≤ x∞, (7.5) POSITIVE ⎨ ⎪ 0 else. ⎩ These specific definitions, along with the weighted average method of defuzzification, lead to the exact formulation of D and θ as follows: now now D if (σ −σ ) 0, ⎧ prev now prev D = (7.6) now ⎨ − D if (σ −σ )≥ 0, prev now prev ⎩ θ + D ∆ θ if (σ −σ )−α, ⎧ prev now now prev ⎪ θ −βD ∆ θ if −α≤ (σ −σ ) 0, ⎪ prev now now prev θ = (7.7) now ⎨ θ +βD ∆ θ if 0≤ (σ −σ )α, prev now now prev ⎪ ⎪ θ + D ∆ θ if α≤ (σ −σ ), prev now now prev ⎩ where σ −σ now prev β = . (7.8) α 2. Adjustable Control Rate. It was reasoned that the fixed rate control above might be sped up faster if step ∆θ is initially set at a large value and thus moves the focusing ring closer and faster to the right setting. As it moves past the right setting, the focusing ring will be moved back in the opposite direction, similar to the situation of overshooting. Here, when this change of direction occurs, step ∆θ will be adjusted to be smaller, thus providing a finer control at the range closer to the right setting. The same three rules in the fixed rate control above can be modified to reflect this variable rate strategy: (1) R : IF (σ –σ ) is POSITIVE now prev THEN D = D AND θ = θ + D ∆θ , now prev now prev prev (2) R : IF (σ –σ ) is NEGATIVE now prev THEN D = –D AND θ = θ + γD ∆θ , now prev now prev now (3) R : IF (σ –σ ) is ZERO now prev THEN D = D AND θ = θ . now prev now prev Again, for each description POSITIVE, NEGATIVE, and ZERO, there associate three ranges R = x ,∞), R = –x ,–∞), and R = POSITIVE 1 NEGATIVE 1 ZERO –x ,x, and three membership functions µ (⋅), µ (⋅), and 2 2 POSITIVE NEGATIVE µ (⋅). These ranges and membership functions will determine the final ZERO numerical angle that the focusing ring should be rotated to.286 Some Applications of Fuzzy Control •• 7 (2) The constant γ in Rule R is between zero and one (or γ∈(0,1). When one selects γ = 1, the rules converge to the fixed rate control presented earlier. When one selects any arbitrary 0 γ 1, the steps are refined smaller each time the focusing ring goes past its targeted setting. One can also select a scheme to calculate different values for the parameter γ for every control cycle according to the adaptive scheme discussed in Chapter 6. If the definitions for R , R , and R , and their POSITIVE NEGATIVE ZERO corresponding membership functions µ (⋅), µ (⋅), and µ (⋅) POSITIVE NEGATIVE ZERO defined in Sections B.1, B.2, and B.3 of Chapter 2 are used, the (1) (2) (3) defuzzification process of the three fuzzy rules R , R , and R will lead directly to the following closed-form formulas: D if (σ −σ ) 0, ⎧ prev now prev D = (7.9) now ⎨ − D if (σ −σ )≥ 0, prev now prev ⎩ θ + D ∆ θ if (σ −σ )−α, ⎧ prev now now prev ⎪ θ −βD ∆ θ if −α≤ (σ −σ ) 0, ⎪ prev now now prev θ = (7.10) now ⎨ θ +βD ∆ θ if 0≤ (σ −σ )α, prev now now prev ⎪ ⎪ θ + D ∆ θ if α≤ (σ −σ ), prev now now prev ⎩ where σ −σ now prev β = . (7.11) α C. Computer Simulation Results In this computer simulation, simulation of a lens system is developed to show that a correctly focused image blurs away as the focusing ring is rotated away from the right position. A fuzzy control system is implemented to control the position of the focusing ring on the lens system. Sharpness of an image is used as feedback to the fuzzy control system. 1. Focusing System. A focusing system is simulated so that when the focusing ring is not in the correct position, in this case, the image is blurred. The more the focusing ring is off target, the more the image is blurred. In order to create the blurring effect, one can use the smoothing filter to apply to the original image (the one in focus). Let the in-focus image be I (n,m); in-focus the off-focus image I (n,m) can be generated according to the difference off-focus δ between the correct distance and the estimated distance as follows: δ δ 1 I (n,m) = I (n+ j, m+ k) . (7.12) off-focus in−focus ∑∑ 2 (2δ+ 1) jk =−δ =−δ The formula above is the smoothing filter base on the average value of the pixels inside the square area around a pixel of indices (n,m). The larger the size of this square area, the more blurred the resulting image. Therefore, to create the blurring effect, we use the difference δ between the correct distance 7•• Some Applications of Fuzzy Control 287 and the estimated distance to determine the size of the square area used in the smoothing filter in (7.12). 2. Fuzzy Control System. The fuzzy control system will use the fuzzy rules described earlier, with the index of sharpness calculated from the formulation for edge detection used as feedback to control the focusing ring of the camera. 3. Computer Simulation Results. Three experiments are performed in the simulation. The first experiment demonstrates the fixed rate control algorithm. The second and third experiments demonstrate the adjustable control algorithm. The results are shown in Figures 7.19, 7.20, and 7.21. The corresponding control data are listed in Tables 7.1, 7.2, and 7.3. Experiment 1. An object (the fireworks) is at a large distance (infinity setting) from the lens. The control algorithm initializes the system to start at the closest distance allowable on the lens system. This distance represents the macro setting. From this distance, the lens focusing ring is moved one step at a time at a fixed rate of 10° for each control cycle. The time duration between two consecutive control cycles is 100 milliseconds. Experiment 2. An object (the astronaut) is at a moderate distance (between the macro setting and infinity setting) from the lens. The control algorithm also initializes the system to start at the macro setting. From this distance, the lens focusing ring is moved one step at a time at an initial rate of 20° for each control cycle. The time duration between two consecutive control cycles is 100 milliseconds. At the first overshoot, the control algorithm reverses the direction of the focusing ring and reduces the control step to the rate of 10° for each control cycle. This reduction corresponds to the selection of the constant γ = 0.5 in the adjustable rate algorithm. Experiment 3. This is an extension of automatic focusing to a microscope. This application is particularly useful for the space program where biological experiments are often conducted in the space shuttle (or in the future space station) with little supervision. In this scenario, data are collected automatically and sent back to Earth for analysis by humans. The object for this experiment is a slide of plant cells. This is a biological experiment in which microscopic lives are observed unattended through a microscope. The condition for growth is dependent on the nature of the experiment. The microscope is used in such a way that cells’ lives are preserved. This life-preservation requirement is normally satisfied by using the phase-contrast microscope (a special kind of microscope that uses the difference in the refraction indices instead of the intensity of the reflected light). The phase-contrast microscope only records images in black-and-white data, which is the format used in this example. For color images, one can convert it into gray-level by applying the average filter that calculates the average of the three main colors (namely, red, green, and blue) representing each color pixel into a single scalar quantity representing a gray-level pixel.288 Some Applications of Fuzzy Control •• 7 (a) t = 100 msec (b) t = 200 msec (c) t = 300 msec σ = 104 σ = 223 σ = 542 θ = 10°θ = 20°θ = 30° (d) t = 400 msec (e) t = 500 msec (f) t = 600 msec σ = 1077 σ = 1855 σ = 4286 θ = 40°θ = 50°θ = 60° (g) t = 700 msec (h) t = 800 msec (i) t = 900 msec σ = 9384 σ = 30247 σ = 30247 θ = 70°θ = 80°θ = 80° Figure 7.19 Automatic control of an autofocus lens system for an image of the fireworks display at distance of infinity (from the lens). The control ring is starting at the macro end, i.e., at the smallest distance allowed. The angle is adjusted by 10° in either direction every cycle. Table 7.1 Numerical Data and Results for Experiment 1 (1) (2) (3) time t rule R rule R rule R sharpnessσ positionθ 100 msec 104 10° 10 0 200 msec 223 10 0 20° 300 msec 542 30° 10 0 400 msec 1077 10 0 40° 500 msec 1855 50° 10 0 600 msec 4266 10 0 60° 700 msec 9384 70° 10 0 800 msec 30247 10 0 80° 900 msec 30247 80° 00 17•• Some Applications of Fuzzy Control 289 (a) t = 100 msec (b) t = 200 msec (c) t = 300 msec σ = 2069 σ = 3878 σ = 7596 θ = 10°θ = 30°θ = 50° (c) t = 400 msec (d) t = 500 msec (e) t = 600 msec σ = 10279 σ = 8977 σ = 12023 θ = 70°θ = 90°θ = 80° (f) t = 700 msec (g) t = 800 msec (h) t = 900 msec σ = 14177 σ = 22021 σ = 22021 θ = 75°θ = 77°θ = 78° Figure 7.20 Automatic control of an autofocus lens system for an image of an astronaut. Table 7.2 Numerical Data and Results for Experiment 2 (1) (2) (3) time t rule R rule R rule R sharpnessσ positionθ 100 msec 104 10° 10 0 200 msec 223 10 0 30° 300 msec 542 50° 10 0 400 msec 1077 10 0 70° 500 msec 1855 90° 10 0 600 msec 4266 01 0 80° 700 msec 9384 01 0 75° 800 msec 30247 01 0 77° 900 msec 30247 00 1 78°290 Some Applications of Fuzzy Control •• 7 (a) t = 200 msec (b) t = 400 msec (c) t = 600 msec σ = 820 σ = 930 σ = 5437 θ = 120° θ = 100° θ = 80° (c) t = 800 msec (d) t = 1000 msec (e) t = 1200 msec σ = 1492 σ = 2798 σ = 5437 θ = 60° θ = 40° θ = 30° (f) t = 1400 msec (g) t = 1600 msec (h) t = 1800 msec σ = 11488 σ = 21031 σ = 30893 θ = 20° θ = 10° θ = 0° Figure 7.21 Automatic control of an autofocus lens system for an image of a set of plant cells on a microscope. Table 7.3 Numerical Data and Results for Experiment 3 (1) (2) (3) time t rule R rule R rule R sharpnessσ positionθ 200 msec 820 120° 10 0 400 msec 930 10 0 100° 600 msec 5437 80° 10 0 800 msec 1492 10 0 60° 1000 msec 2798 01 0 40° 1200 msec 5437 01 0 30° 1400 msec 11488 01 0 20° 1600 msec 21031 01 0 10° 1800 msec 30893 00 1 0°