Fuzzy Logic


ntroduction
Welcome to the wonderful world of fuzzy logic, the science you can use to powerfully get things done.   Add the ability to utilize personal computer based fuzzy logic analysis and control to your technical and management skills and you can do things that humans and machines cannot otherwise do.   Get a competitive edge!
Following is the base on which fuzzy logic is built:
As the complexity of a system increases, it becomes more difficult and eventually impossible to make a precise statement about its behavior, eventually arriving at a point of complexity where the fuzzy logic method born in humans is the only way to get at the problem.  
(Originally identified and set forth by Lotfi A. Zadeh, Ph.D., University of California, Berkeley)
Fuzzy logic is used in system control and analysis design, because it shortens the time for engineering development and sometimes, in the case of highly complex systems, is the only way to solve the problem.
E.H. Mamdani is credited with building the world's first fuzzy logic controller, after reading Dr. Zadeh's paper on the subject (see Ch. 2 of this tutorial). Dr. Mamdani, London University, U.K., stated firmly and unequivocally that utilizing a fuzzy logic controller for speed control of a steam engine was much superior to controlling the engine by conventional mathematically based control systems and logic control hardware. Dr. Mamdani found that, using the conventional approach, extensive trial and error work was necessary to arrive at successful control for a specific speed set-point. Further, due to the non-linearity of the steam engine operating characteristics, as soon as the speed set-point was changed, the trial and error effort had to be done all over again to arrive at effective control. This did not occur with the fuzzy logic controller, which adapted much better to changes, variations and non-linearity in the system.

The following chapters of this tutorial attempt to explain for us "Just Plain Folks" how the "fuzzy logic method born in humans" is used to evaluate and control complex systems.   Although most of the time we think of fuzzy logic "control" as having to do with controlling a physical system, there is no such limitation in the concept as initially presented by Dr. Zadeh.   Fuzzy logic can apply also to economics, psychology, marketing, weather forecasting, biology, politics ...... to any large complex system.
The term "fuzzy" was first used by Dr. Lotfi Zadeh in the engineering journal, "Proceedings of the IRE," a leading engineering journal, in 1962.   Dr. Zadeh became, in 1963, the Chairman of the Electrical Engineering department of the University of California at Berkeley.   That is about as high as you can go in the electrical engineering field.   Dr. Zadeh’s thoughts are not to be taken lightly.
Fuzzy logic is not the wave of the future.   It is now! There are already hundreds of millions of dollars of successful, fuzzy logic based commercial products, everything from self-focusing cameras to washing machines that adjust themselves according to how dirty the clothes are, automobile engine controls, anti-lock braking systems, color-film developing systems, subway control systems and computer programs trading successfully in the financial markets.
Note that when you go searching for fuzzy-logic applications in the United States, it is difficult to impossible to find a control system acknowledged as based on fuzzy logic.   Just imagine the impact on sales if General Motors announced their anti-lock braking was accomplished with fuzzy logic! The general public is not ready for such an announcement.
Objectives of the following chapters include:
1.   To introduce to individuals in the fields of business, industry, science, invention and day-to-day living the power and benefits available to them through the fuzzy logic method and to help them understand how fuzzy logic works.
2.   To provide a fuzzy logic "how-to-do-it" guide, in terms everyone can understand, so everyone can put fuzzy logic to work doing something useful for them.  
This tutorial is being written so "Just Plain Folks" can understand the concept of fuzzy logic sufficiently to utilize it, or to at least determine if they need to dig deeply into the subject in the great quantity of Ph.D. level literature existing on the subject.   This tutorial is a guide, so you can do something with fuzzy logic, even if you are not a Ph.D. specializing in the field or an advanced digital systems electronics engineer.
The paragraphs below say in a few short words, "what fuzzy logic is." But, reading this tutorial and other publications on the subject will be helpful for a fuller understanding.  
Fuzzy Logic Analysis and Control
A major contributor to Homo sapiens success and dominance of this planet is our innate ability to exercise analysis and control based on the fuzzy logic method.   Here is an example:
Suppose you are driving down a typical, two way, 6 lane street in a large city, one mile between signal lights.   The speed limit is posted at 45 Mph.   It is usually optimum and safest to "drive with the traffic," which will usually be going about 45 Mph.   How do you define with specific, precise instructions "driving with the traffic?" It is difficult.   But, it is the kind of thing humans do every day and do well.  
There will be some drivers weaving in and out and going more than 45 Mph and a few drivers driving less than 45 Mph.   But, most drivers will be driving 45 Mph.   They do this by exercising "fuzzy logic" - receiving a large number of fuzzy inputs, somehow evaluating all the inputs in their human brains and summarizing, weighting and averaging all these inputs to yield an optimum output decision.   Inputs being evaluated may include several images and considerations such as: What are the cars in front doing?   How fast are they driving.   Any drivers going real slow?   Any trucks holding up one of the lanes.   How about side traffic entering from side streets.   What do you see in the rear view mirror.   Even with all this, and more, to think about, those who are driving with the traffic will all be going along together at very nearly the same speed.
The same ability you have to drive down a modern city street was used by our ancestors to successfully organize and strategically carry out chases to drive wooly mammoths into pits, to obtain food, clothing and bone tools.
Human beings have the ability to take in and evaluate all sorts of information from the physical world they are in contact with and to mentally analyze, average and summarize all this input data into an optimum course of action.   All living things do this, but humans do it more and do it better and have become the dominant species of the planet.
If you think about it, much of the information you take in is not very precisely defined, such as evaluation of the behavior of a vehicle entering from a side street and the likelihood of the vehicle pulling in front of you.   We call this fuzzy input.   However, some of your "input" is reasonably precise and non-fuzzy such as the speedometer reading.   Your processing of all this information is not very precisely definable.   We call this fuzzy processing.   Fuzzy logic theorists would call it using fuzzy algorithms (algorithm is another word for procedure or program, as in a computer program).
Fuzzy logic is the way the human brain works, and we can mimic this in machines so they will perform somewhat like humans, not to be confused with Artificial Intelligence, where the so far unattainable goal is for machines to perform EXACTLY like humans.   See Forbes Magazine, December 2009, Digital Tools, "Why Computers Can't Mimic The Brain: Our gray matter is far too complex for machines to simulate."
Fuzzy logic control and analysis systems may be electro-mechanical in nature, or concerned only with data, for example economic data, in all cases guided by "If-Then rules" stated in human language.
The Fuzzy Logic Method
The fuzzy logic analysis and control method is, therefore:
1. Receiving of one, or a large number, of measurement or other assessment of conditions existing in some system we wish to analyze or control.
2. Processing all these inputs according to human based, fuzzy "If-Then" rules, which can be expressed in plain language words.
3. Averaging and weighting the resulting outputs from all the individual rules into one single output decision or signal which decides what to do or tells a controlled system what to do.   The output signal eventually arrived at is a precise appearing, defuzzified, "crisp" value.  Please see the following Fuzzy Logic Control/Analysis Method diagram:


Fuzzy Perception
A fuzzy perception is an assessment of a physical condition that is not measured with precision, but is assigned an intuitive value.   It will be seen below that fuzzy perceptions can serve as a basis for processing and analysis in a fuzzy logic control system.
Measured, non-fuzzy data is the input for the fuzzy logic method.   Examples:   temperature measured by a temperature transducer, motor speed, economic data, financial markets data, etc.   Then humans with their fuzzy perceptions and fuzzy rules take over. Human perceptions and rules are placed in-the-loop in the fuzzy logic based control system.

Fuzzy Sets
"Fuzzy sets" can be a complex mathematical term in multivalued logic. For our purposes in considering electro-mechanical systems control, a fuzzy set is an object with elements, or members, which can belong to it in degrees.
Examples of fuzzy sets are: motor speed, boiler pressure, shower-water temperature, etc.   Too high motor speed, very low boiler pressure and hot shower water are sub-sets of the fuzzy sets.
Assigning Zero to One Values to Fuzzy Sub-Sets
When implementing fuzzy logic control with human originated rules in the loop, we must have a way to assign some numeric value to humans' intuitive assessments of fuzzy sets.   We must translate from human fuzziness to numbers that can be used by a computer.   We do this by assigning fuzzy sub-set conditions a value from zero to 1.0.   In setting up a control system for room temperature, for example, we could assign a membership of "1.0" in the sub-set of "just right" when the temperature is 75 degrees F. Then, if the temperature drops to 70 degrees F, we might design the system for a membership in the "just right" sub-set of ".8". This becomes clearer in Chapter 3 when plans for an actual fuzzy control system are presented.
Fuzzy logic makes use of human common sense.   This common sense is either applied from what seems reasonable, for a new system, or from experience, for a system that has previously had a human operator.
Here is an example of converting human experience for use in a control system:   In Italy, a project was undertaken to automate a cement plant.   Cement manufacturing is a lot more difficult than you would think.   Through the centuries it has evolved with human "feel" being absolutely necessary.   Engineers were not able to automate with conventional control.   Eventually, they translated the human "feel" into lots and lots of fuzzy logic "If-Then" rules based on human experience.   Success was thereby obtained in automating the plant.  
Objects of fuzzy logic analysis and control may include: physical control, such as machine speed, or operating a cement plant; financial and economic decisions; physiological conditions; safety conditions; security conditions; production improvement and much more.
This tutorial will talk about fuzzy logic in control applications - controlling machines, physical conditions, processing plants, etc.   It should be noted that when Dr. Zadeh invented fuzzy logic, it appears he had in mind applying fuzzy logic in many applications in addition to controlling machines, such as economics, politics, biology, etc.
Thank You Wozniak (Apple Computer), Jobs (Apple Computer), Gates (Microsoft) and Ed Roberts (the MITS, Altair entrepreneur) for the Personal Computer!
The availability of the fuzzy logic method to us "Just Plain Folks" has been made possible by the availability of the personal computer.   Without personal computers, it would be difficult to use fuzzy logic to control machines and production plants, or do other analyses.   Without the speed and versatility of the personal computer, we could not handle the complexity, millions of calculations, speed and endurance needed for machine control.
Standard programmable logic controllers have their place! They are simple, reliable and keep American industry operating where the application is relatively simple, linear and on-off in nature.
For a more complicated system control application, an optimum solution may be patching things together with a personal computer and fuzzy logic rules, especially if the project is being done by someone who is not a professional control systems engineer.
A Milestone Passed for Intelligent Life On Earth
Where intelligent life has appeared in the universe, "they" are probably using fuzzy logic.   It is a universal principle and concept.   Becoming aware of, defining and starting to use fuzzy logic is an important moment in the development of an intelligent civilization.   On earth, we have just arrived at that important moment.
Fuzzy Logic Terms Found in Books and Articles
The discussion so far does not adequately prepare us for reading and understanding most books and articles about fuzzy logic, because of the terminology used by sophisticated authors.   Following are explanations of some terms which should help in this regard.   This terminology was initially established by Dr.   Zadeh when he originated the fuzzy logic concept.  
Fuzzy - The degree of fuzziness of a system control rule can vary between being very precise, in which case we would not call it "fuzzy", to being based on an intuitive opinion held by a human, which would be "fuzzy.
A system control rule need not be based on human fuzzy perception.   For example, you could have a rule, "If the boiler pressure rises to a danger point of 600 Psi as measured by a 1% accuracy pressure transducer, then turn everything off.   That rule is not fuzzy.

Principle of Incompatibility (previously stated; repeated here) -
As the complexity of a system increases, it becomes more difficult and eventually impossible to make a precise statement about its behavior, eventually arriving at a point of complexity where the fuzzy logic method born in humans is the only way to get at the problem.
Fuzzy Sets - A fuzzy set is almost any condition for which we have words: short men, tall women, hot day, cold climate, new building, ripe bananas, high intelligence, low speed, overweight, etc., where the condition can be given a value between 0 and 1.   Example: A woman is 6 feet, 3 inches tall.   In my experience, I think she is one of the tallest women I have ever met, so I rate her height at .98.   A great number of things can be given a value between 0 and 1.
Degree of Membership - The degree of membership is the placement in the transition from 0 to 1 of conditions within a fuzzy set.   If a particular building's placement on the scale is a rating of .7 in its position in newness among new buildings, then we say its degree of membership in new buildings is .7.
In fuzzy logic method control systems, degree of membership is used in the following way.   A measurement of speed, for example, might be found to have a degree of membership in "too fast of" .6 and a degree of membership in "no change needed" of .2.   The system program would then calculate the center of mass between "too fast" and "no change needed" to determine feedback action to send to the input of the control system.   This is discussed in more detail in subsequent chapters.  
Summarizing Information - Human processing of information is not based on two-valued, off-on, either-or logic.   It is based on fuzzy perceptions, fuzzy truths, fuzzy inferences, etc., all resulting in an averaged, summarized, normalized output, which is given by the human a precise number or decision value which he or she verbalizes, writes down or acts on. It is the goal of fuzzy logic control systems to also do this.
The input may be large masses of data, but humans can handle it.   The ability to analyze fuzzy sets and the subsequent summarizing capability to arrive at an output we can act on is one of the greatest assets of the human brain.   This characteristic is the big difference between humans and digital computers.   Emulating this human ability is the challenge facing those who would create computer based artificial intelligence.   It is proving very, very difficult to program a computer to have human-like intelligence.  
Fuzzy Variable - Words like red, blue, etc., are fuzzy and can have many shades and tints.   They are just human opinions, not based on precise measurement in angstroms. These words are fuzzy variables.
If, for example, speed of a system is the attrribute being evaluated by "fuzzy" rules, then "speed" is a fuzzy variable.
Linguistic Variable - Linguistic means relating to language, in our case plain language words and statements.
Speed is a fuzzy variable.   Throttle setting is a fuzzy variable.   Examples of linguistic variables are: somewhat fast speed, very high speed, real slow speed, high rate of positive pressure change, throttle setting about right, etc.  
A fuzzy variable becomes a linguistic variable when we modify it with descriptive words, such as somewhat fast, very high, real slow, positive big, negative small etc.
The main function of linguistic variables is to provide a means of working with the complex systems mentioned above as being too complex to handle by conventional mathematics and engineering formulas.
Linguistic variables appear in control systems with feedback loop control and can be related to each other with conditional, "if-then" statements.   Example: If the speed is too fast, then back off on the high accelerator setting.  
Universe of Discourse - Let us make controlling steam engine speed a project.   Operating characteristics and parameters related to the steam engine would be our universe of discourse.
Fuzzy Algorithm - An algorithm is a procedure, such as the steps in a computer program.   A fuzzy algorithm, then, is a procedure, usually a computer program, made up of statements relating linguistic variables and control actions.
Example:

If the pressure and positive rate of pressure change of the steam engine boiler is much too high then turn the heater down a lot.
Defuzzify - Evaluate several sub-sets established by the designer for a fuzzy logic based control system, such as "speed too fast," "speed too slow" and "speed about right" at a specific input value (Example: 2,390 RPM) to determine a crisp output which will be the input for the system being controlled.

The World's First Fuzzy Logic Controller
In England in 1973 at the University of London, a professor and student were trying to stabilize the speed of a small steam engine the student had built.   They had a lot going for them, sophisticated equipment like a PDP-8 minicomputer and conventional digital control equipment.   But, they could not control the engine as well as they wanted.   Engine speed would either overshoot the target speed and arrive at the target speed after a series of oscillations, or the speed control would be too sluggish, taking too long for the speed to arrive at the desired setting, as in Figure 1, below.


The professor, E. Mamdani, had read of a control method proposed by Dr. Lotfi Zadeh, head of the electrical engineering department at the University of California at Berkeley, in the United States.   Dr. Zadeh is the originator of the designation "fuzzy", which everyone suspects was selected to throw a little "pie in the face" of his more orthodox engineering colleagues, some of whom strongly opposed the fuzzy logic concept under any name.

Professor Mamdani and the student, S. Assilian, decided to give fuzzy logic a try.   They spent a weekend setting their steam engine up with the world's first ever fuzzy logic control system ....... and went directly into the history books by harnessing the power of a force in use by humans for 3 million years, but never before defined and used for the control of machines.

The controller worked right away, and worked better than anything they had done with any other method.   The steam engine speed control graph using the fuzzy logic controller appeared as in Figure 2, below.


As you can see, the speed approached the desired value very quickly, did not overshoot and remained stable.   It was an exciting and important moment in the history of scientific development.
Dr. Mamdani stated firmly and unequivocally in his writeup on the experiment that utilizing a fuzzy logic controller for speed control of a steam engine was much superior to controlling the engine by conventional mathematically based control systems and logic control hardware. Dr. Mamdani found that, using the conventional approach, extensive trial and error work was necessary to arrive at successful control for a specific speed set-point. Further, due to the non-linearity of the steam engine operating characteristics, as soon as the speed set-point was changed, the trial and error effort had to be done all over again to arrive at effective control. This did not occur with the fuzzy logic controller, which adapted much better to changes, variations and non-linearity in the system.
The Mamdani project made use of four inputs:   boiler pressure error (how many temperature degrees away from the set point), rate of change of boiler pressure error, engine speed error and rate of change of engine speed error.   There were two outputs:   control of heat to the boiler and control of the throttle.   The outputs operated independently.

A fuzzy logic system does not have to be directed toward electro-mechanical systems.   The fuzzy logic system could be, for example, to provide buy-sell decisions to trade 30 million US dollars against the Japanese yen.

Controllers typically have several inputs and outputs.   The handling of various tasks, such as monitoring and commanding a control loop and monitoring various inputs, with commands issued as appropriate, would all be sequenced in the computer program.   The program would step from one task to the other, the program receiving inputs from and sending commands to the converter/controller.

Inputs for a fuzzy logic controlled mechanical/physical system could be derived from any of thousands of real world, physical sensors/transducers.   The Thomas Register has over 110 pages of these devices.   Inputs for financial trading could come from personal assessments or from an ASCII data communication feed provided by a financial markets quote service.

Progress in Fuzzy Logic
From a slow beginning, fuzzy logic grew in applications and importance, until now it is a significant concept worldwide.   Intelligent beings on the other side of our galaxy and throughout the universe have probably noted and defined the concept.

Personal computer based fuzzy control enables novices to build control systems that work in places where even the best mathematicians and engineers, using conventional approaches to control, cannot define and solve the problem.

A control system is an electronic or mechanical system that causes the output of the controlled system to automatically remain at some desired output (the "set point") set by the operator.   The thermostat on your air conditioner is a control system.   Your car's cruise control is a control system.   Control may be an on-off signal or a continuous feedback loop.
In Japan, a professor built a fuzzy logic control system that will fly a helicopter with one of the rotor blades off!   Human helicopter pilots cannot do that.   And, the Japanese went further and built a fuzzy logic controlled subway that is as smooth as walking in your living room.   You do not have to hang on to a strap to keep your balance.   If you did not look out the window at things flashing by, you would hardly know you had started and were in motion.
In the United States, fuzzy logic control is gaining popularity, but is not as widely used as in Japan, where it is a multi-million dollar industry.   Japan sells fuzzy logic controlled cameras, washing machines and more.   One Internet search engine returns over 16,000 pages when you search on "fuzzy+logic.
Personal computer based fuzzy logic control follows the pattern of human "fuzzy" activity.   However, humans usually receive, process and act on more inputs than the typical computer based fuzzy logic controller.   (This is not necessarily so; a computer based fuzzy logic control system in Japan trades in the financial markets and utilizes 800 inputs.)

Fuzzy Logic Control Input - Human and Computer
Computer based fuzzy logic machine control is like human fuzzy logic control, but there is a difference when the nature of the computer's input is considered.
Humans evaluate input from their surroundings in a fuzzy manner, whereas machines/computers obtain precise appearing values, such as 112 degrees F, obtained with a transducer and an analog to digital converter.   The computer input would be the computer measuring, let's say, 112 degrees F.   The human input would be a fuzzy feeling of being too warm.

The human says, "The shower water is too hot." The computer as a result of analog input measurement says, "The shower water is 112 degrees F and 'If-Then' statements in my program tell me the water is too warm." A human says, "I see two tall people and one short one." The computer says, "I measure two people, 6' 6" and 6' 9", respectively, and one person 5' 1" tall, and 'If-Then' statements in my program tell me there are two tall people and one short person."

Even though transducer derived, measured inputs for computers appear to be more precise, from the point of input forward we still use them in a fuzzy logic method approach that follows our fuzzy, human intuitive approach to control.

For a human, if the shower water gets too warm, the valve handle is turned to make the temperature go down a little.   For a computer, an "If-Then" statement in the program would initiate the lowering of temperature based on a human provided "If-Then" rule, with a command output operating a valve.

More About How Fuzzy Logic Works
To create a personal computer based fuzzy logic control system, we:

1.   Determine the inputs.
2.   Describe the cause and effect action of the system with "fuzzy rules" stated in plain English words.
3.   Write a computer program to act on the inputs and determine the output, considering each input separately.   The rules become "If-Then" statements in the program.   (As will be seen below, where feedback loop control is involved, use of graphical triangles can help visualize and compute this input-output action.)
4.   In the program, use a weighted average to merge the various actions called for by the individual inputs into one crisp output acting on the controlled system.   (In the event there is only one output, then merging is not necessary, only scaling the output as needed.)
The fuzzy logic approach makes it easier to conceptualize and implement control systems.   The process is reduced to a set of visualizable steps.   This is a very important point.   Actually implementing a control system, even a simple control system, is more difficult than it appears.   Unexpected aberrations and physical anomalies inevitably occur.   Getting the process working correctly ends up being a "cut and try" effort.

Experienced, professional digital control engineers using conventional control might know how to proceed to fine tune a system.   But, it can be difficult for us just plain folks.   Fuzzy logic control makes it easier to visualize and set up a system and proceed through the cut and try process.   It is only necessary to change a few plain English rules resulting in changing a few numbers in the program.
In reading about fuzzy logic control applications in industry, one of the significant points that stands out is:   fuzzy logic is used because it shortens the time for engineering development.   Fuzzy logic enables engineers to configure systems quickly without extensive experimentation and to make use of information from expert human operators who have been performing the task manually.
Perhaps your control need is something a lot more down to earth than flying helicopters or running subways.   Maybe all you want to do is keep your small business sawmill running smoothly, with the wood changing and the blade sharpness changing.   Or, perhaps you operate a natural gas compressor for some stripper wells that are always coming on and going off, and you need to have the compressor automatically adjust in order to stay on line and keep the suction pressure low to get optimum production.   Perhaps you dream of a race car that would automatically adjust to changing conditions, the setup remaining optimum as effectively as the above mentioned helicopter adjusts to being without a rotor blade.
There are a million stories, and we cannot guess what yours is, but chances are, if there is something you want to control, and you are not an experienced, full time, professional control engineer financed by a multi-million dollar corporation, then fuzzy logic may be for you.   If you are all those things, it still may be for you.
A conventional programmable logic controller monitors the process variable (the pressure, temperature, speed, etc., that we want to control).   If it is too high, a decrease signal is sent out.   If it is too low, an increase signal is sent out.   This is effective up to a point.   But, consider how much more effective a control system would be if we use a computer to calculate the rate of change of the process variable in addition to how far away it is from the set point.   If the control system acts on both these inputs, we have a better control system.   And, that could be just the beginning; we can have a large number of inputs all being analyzed according to common sense and experience rules for their contribution to the averaged crisp output controlling the system.

Further, whereas conventional control systems are usually smooth and linear in performance, we sometimes encounter aberrations or discontinuous conditions, something that does not make good scientific sense and cannot be predicted by a formula, but it's there.   If this happens, the fuzzy logic method helps us visualize a solution, put the solution in words and translate to "If - Then" statements, thereby obtaining the desired result.   That is a very difficult thing to do with conventional programmable logic controllers (known as PLC's).   PLC's are programmable, but are far more limited than the program control available from a very simple BASIC program in a personal computer.
Fuzzy logic control is not based on mathematical formulas.   This is a good thing, because, as easy as it might seem, it is difficult to impossible to write formulas that do what nature does.   This is why novices using fuzzy logic can beat Ph.D. mathematicians using formulas.   Fuzzy logic control makes use of human common sense.   This common sense is either applied from what seems reasonable, for a new system, or from experience, for a system that has previously had a human operator.

For us "Just Plain Folks," fuzzy logic works, works better than expensive and complicated systems and is understandable and affordable.

Building a System to Gain Understanding and Familiarity
The easiest and quickest way to understand fuzzy logic control is to build a fuzzy logic control system; following is one example:

This is a fuzzy logic speed control example, using the same techniques as used by Professor Mamdani, that you can build for yourself to get experience with fuzzy logic control.   I recommend you do build some kind of system.   I found I began more and more to understand what fuzzy logic was all about as I tried to make the system work.   The following example system has been reduced in complexity to make it easier to understand, but the concepts are the same as those used by Mamdani.

If your application is more demanding than the following example, you add inputs and "rules"; you do not have to learn new things or change the approach.   In considering this reduced complexity example, it may be observed that control could have been effected without going through the fuzzy control exercise we are about to go through.   This would be correct, but only because we are working with a simple system, only one input and no discontinuities or aberrations requiring patching.

Following is a system diagram, Figure 3, for a "getting acquainted with fuzzy" project that provides speed control and regulation for a DC motor.   The motor maintains "set point" speed, controlled by a stand-alone converter-controller, directed by a BASIC fuzzy logic control program in a personal computer.


Parts List
(1) IBM or compatible personal computer equipped to run Microsoft Quick BASIC.   IBM is a registered trademark of IBM Corporation.   Microsoft and Quick BASIC are registered trademarks of Microsoft, Inc.

(2) Controller (see below).
(3) Signal conditioner (transistor amplifier to adjust levels as needed).
(4) Transistor - 2N3053.
(5) DC motor, 1.5 V to 3.0 V, 100 ma., 1100 Rpm to 3300 Rpm, and compatible generator.
The above speed control system is low cost and suitable for learning at home where being rigorously, mathematically correct is not required.   It is important to be aware that this speed controller is only an experimental controller to get familiar with the fuzzy logic concept.   It is not what engineers call a rigorous, technically correct application of fuzzy logic.  The difference is in the fact that this approach does not add triangles to compute center of mass as specified by Dr. Bart Kosko (Fuzzy Thinking, Chapter 10).  Adding triangles can be done, but is difficult and time consuming, however that is the way a truly professional application would be designed.  There are IC’s that do it all and commercially available fuzzy logic controllers that do everything correctly.
This fuzzy logic controller project was done under pressure of very limited money available, resulting in an inexpensive approach.   What is needed is an analog to digital converter, which connects to a PC, and a digital to analog output device from the PC to the transistors and DC motor-generator being controlled.  Often this is all in one plug-in card that goes inside the PC.   Plug in the A to D and D to A converter in the PC and write a program to measure the input and control the output according to fuzzy logic principles.  This approach can be somewhat expensive and was not used in this case.
For this experiment, the controller was a 40-8 controller manufactured by Prairie Digital Company.   Click on the following Web page to see this controller.   http://www.prairiedigital.com/PDI_Website/PDI_Model40.htm   (The author has no connection at all with Prairie Digital.)   The 40-8 controller is external to the computer, connecting to the PC via a standard RS-232 serial port.   The serial port connects to the 40-8 controller via a serial cable.   A BASIC program is used to communicate with the 40-8 controller.   The Prairie Digital instruction book has sample programs showing how to do this.  Through a BASIC program, you can read the analog voltage level on one of the 40-8 analog input lines, then tell the 40-8 to output a pulse-width-modulated signal.   By controlling the pulse width of the 40-8 output, the average value of the output is the equivalent of varying the level of the output in an analog fashion.
If not constrained by cost, a 12 bit, A to D unit should be used, rather than the 8 bit unit.  This would provide improved control.   This approach, using the 40-8 controller, is low cost, in the range of $100 to buy the 40-8.   Purchasing the items Prairie Digital offers to accompany the controller, that is the connector, cables, software, etc., is recommended. It costs very little extra, but is well worth it.
With regard to the other hardware, only low cost transistors, resistors, capacitors, etc., were used for the signal conditioner providing input to the motor-generator.   The DC motor and DC generator were small, low power units purchased from a surplus catalog.   The motor output shaft was connected to the generator input shaft with a small section of shrink insulation tubing; cheap, simple and effective.   The power supply for everything, including the 40-8, was a 12 Volt DC power supply removed from an old Apple computer.
National Instruments, www.natinst.com, sells a fuzzy logic system where the fuzzy control action is accomplished by the software.   National Instruments applications engineers recommend one of their several analog/digital in, digital/analog out converters for your application and provide a mathematically correct software program to produce fuzzy control action.   Their system also provides attractive screen display color graphics.   Needless to say, cost of the National Instruments system is considerably above the $100 range.   One would use the National Instruments approach for a large, complex system where flexibility and changes down the road are involved, such as automating a processing plant.
Where using a personal computer is not practical because of space and weight limitations, fuzzy logic control is also available utilizing microchips manufactured by Motorola.   These microchips are suitable for fuzzy control applications, www.mcu.motsps.com.   One would use this approach if developing, for example, a fuzzy logic anti-lock braking system (see "Fuzzy Logic, Revolutionizing Automotive Engineering; Circuit Cellar INK magazine, November 1997; www.circuitcellar.com).
(Please note, this note added January 1, 2008: A reader sent the following information. The author has not personally pursued this, but this information could be very useful. FUDGE is a fuzzy logic development tool for the Motorola 68hc11 microcontroller that enables the user to graphically design a fuzzy system, run fuzzy logic simulations, and generate C and assembly source code. FUDGE can be downloaded from the Internet: http://users.sdsc.edu/~decastro/home/projects/fudge/ Fudge.exe is a visual program that shows the crisp inputs and outputs as well as the fuzzified inputs and the fuzzified outputs. You can change the input and observe the output . KBG11C.EXE is the .asm file for the 68hc11 fuzzy engine. If you open this with notepad you can actually see the code for the fuzzification process. In FUDGE click on >Balance.fdg then click on >Evaluate, then click on > Fuzzy Logic Evaluator. Input and output is displayed graphically and all the input and output membership functions are shown as well as the rules, all on one screen. End of note added January 1, 2008.)

The steps in building our system are:
1.   Determine the control system input.   Examples:   The temperature is the input for your home air conditioner control system.   Speed of the car is the input for your cruise control.
In our case, input is the speed in Rpm of the DC motor, for which we are going to regulate the speed.   See Figure 3 above.   Speed error between the speed measured and the target speed of 2,420 Rpm is determined in the program.   Speed error may be positive or negative.   We measure the DC output voltage from the generator.   This voltage is proportional to speed.   This speed-proportional voltage is applied to an analog input channel of our fuzzy logic controller, where it is measured by the analog to digital converter and the pesonal computer, including appropriate software.
2.   Determine the control system output.   For a home air conditioner, the output is the opening and closing of the switch that turns the fan and compressor on and off.   For a car's cruise control, the output is the adjustment of the throttle that causes the car to return to the target speed.
In our case, we have just one control output.   This is the voltage connected to the input of the transistor controlling the motor.   See Figure 3.
3.   Determine the target set point value, for example 70 degrees F for your home temperature, or 60 Miles per hour for your car.

In our case, the target set point is 2,420 Rpm.
4.   Choose word descriptions for the status of input and output.

For the steam engine project, Professor Mamdani used the following for input:
Positive Big
Positive Medium
Positive Small
Almost No Error
Negative Small
Negative Medium
Negative Big
Our system is much less complicated, so let us select only three conditions for input:
Input Status Word Descriptions

Too slow
About right
Too fast
And, for output:
Output Action Word Descriptions

Speed up
Not much change needed
Slow down
RULES
Translate the above into plain English rules (called "linguistic" rules by Dr. Zadeh).   These Rules will appear in the BASIC computer program as "If-Then" statements:

Rule 1: If the motor is running too slow, then speed it up.
Rule 2: If motor speed is about right, then not much change is needed.
Rule 3: If motor speed is to fast, then slow it down.
The next three steps use a charting technique which will lead to a computer program.   The purpose of the computer program is to determine the voltage to send to the speed controlled motor.   One function of the charting technique is to determine the "degree of membership" (see Ch. 1) of the Too slow, About right and Too fast triangles, for a given speed.   Further, the charting technique helps make the continuous control feedback loop easier to visualize, program and fine tune.
5.   Associate the above inputs and outputs as causes and effect with a Rules Chart, as in Figure 4, below.   The chart is made with triangles, the use of which will be explained.   Triangles are used, but other shapes, such as bell curves, could also be used.   Triangles work just fine and are easy to work with.   Width of the triangles can vary.   Narrow triangles provide tight control when operating conditions are in their area.   Wide triangles provide looser control.   Narrow triangles are usually used in the center, at the set point (the target speed).   For our example, there are three triangles, as can be seen in Figure 4 (three rules, hence three triangles).


6.   Figure 4 (above) is derived from the previously discussed Rules and results in the following regarding voltage to the speed controller:
a.   If speed is About right then Not much change needed in voltage to the speed controller.
b.   If speed is Too slow then increase voltage to the speed controller to Speed up.
c.   If speed is Too fast then decrease voltage to the speed controller to Slow down.
7.   Determine the output, that is the voltage that will be sent from the controller/signal conditioner/transistor to the speed controlled motor.   This calculation is time consuming when done by hand, as we will do below, but this calculation takes only thousandths of a second when done by a computer.

Assume something changes in the system causing the speed to increase from the target speed of 2,420 Rpm to 2,437.4 Rpm, 17.4 Rpm above the 'set point." Action is needed to "pull" the speed back to 2,420 Rpm.   Intuitively we know we need to reduce the voltage to the motor a little.   The "cause" chart and vertical speed line appear as follows, see Figure 5 below:


The vertical line intersects the About right triangle at .4 and the Too fast triangle at .3.   This is determined by the ratio of sides of congruent triangles from Plane Geometry:

Intersect point / 1 = 11.6/29 = .4
Intersect point / 1 = 17.4/58 = .3
8.   The next step is to draw "effect" (output determining) triangles with their height "h" determined by the values obtained in Step 7, above.   The triangles to be drawn are determined by the rules in Step 6.   Since the vertical 2,437.4 Rpm speed line does not intersect the Too slow triangle, we do not draw the Speed up triangle.   We draw the Not much change and the Slow down triangles because the vertical speed line intersects the About right and Too fast triangles.   These "effect" triangles will be used to determine controller output, that is the voltage to send to the speed control transistor.   The result is affected by the widths we have given the triangles and will be calculated.   See Figure 6, below.   The Not much change triangle has a height of .4 and the Slow down triangle has a height of .3, because these were the intersect points for their matching "cause" triangles; see Figure 4, above.


The output, as seen in Figure 6 (above), is determined by calculating the point at which a fulcrum would balance the two triangles, as follows:
The Area of the Not much change triangle is: 1/2 X Base X Height = .5 X .04 X .4 = .008.   Area of the Slow down triangle is .5 X .08 X .3 = .012.
Compute the controller output voltage by finding the point on the output voltage, Vdc, axis where the "weight" (area) of the triangles will balance.   Assume all the weight of the Not much change triangle is at 2.40 Vdc and all the weight of the Slow down triangle is at 2.36 Vdc.   We are looking for the balance point.
Find the position of the controller output voltage (the balance point) with the following calculation:

(Eq.   1)   .008 X D1 = .012 X D2
(D1 is the fulcrum distance from 2.4 V.   D2 is the fulcrum distance from 2.36 V.)

(Eq.   2)  D1 + D2 = .04 (from Figure 6)
D1 = .04 - D2
Solving the above by substituting (.04-D2) for D1 in Equation 1 gives D2 = .016 and D1 = .024, therefore the balance point is a voltage of 2.376 Vdc, and this is the voltage which we have determined should be applied to return speed to the target value.   See Figure 6, above.
Keep in mind that we are only discussing one sample at one instant in time, with a resulting controller output voltage;  the controller is sampling several times each second with a resulting "correction" output following each sample.

The above system was tested with changing loads on the rotating shaft, and returned the speed of the motor to within 2 % of the 2,420 Rpm set point in less than 1.5 seconds.   The accuracy with which the set point speed can be maintained is determined by the resolution of the analog to digital and digital to analog conversion circuits in the fuzzy logic controller.   Typical "low cost" resolution is "8 bit", 256 increments.   Higher cost "12 bit" units provide 4,096 increments.
Please note:   The above is a very effective, but much simplified, version of computer based fuzzy logic control systems actually in use commercially.   If your application is of a more demanding, complex or commercial nature, we suggest you refer to Fuzzy Thinking, a book by Bart Kosko, Ph.D., Chapter 10, Hyperion, New York, 1993.   Dr. Kosko is one of the world's leading proponents of fuzzy control and among the most knowledgeable regarding fuzzy control theory.   In the Kosko method, the intersecting triangles are added, then the total area of the added triangles determined by integration.   Fulcrum location is determined by computer integration of area "under the curve" to the point of one half the total area.   This sounds complicated, but only requires a few thousandths of a second for a computer, once the program is set up.

For more complex systems with additional inputs (for example, using rate of change as an input in addition to speed error), the approach is as above, but there are two or more "sub-outputs" to be considered in arriving at one crisp output to control the system.   This is handled by averaging these sub-outputs with a weighting determined by the system designer and inserted in the program.   This weighting may be based on theoretical prediction, previous experience with a similar manual system and/or experimentation and "tuning" of the system, once it is assembled.
Patch It
For an individual control channel, fuzzy rules cover control requirements during a certain "range" of operation.   In our example speed control system, one rule covered about right.   There was an actual numerical upper limit and lower limit for about right.   Our control rule for this range is sometimes referred to in fuzzy logic literature as a "patch." As you can see, the more patches we have over the control range, the better the control.   Fortunately, most system control problems can be solved with relatively few patches.   A patch, or rule, may be anything that solves the problem.   If the system required it, you could even mix continuous feedback loop control and off-on control over a channel's control range, if that solved the problem.
The Program
The fuzzy logic program in the computer directs sending messages to and receiving messages from the controller, thereby directing the measurement and control operation and causing target and actual speed to be displayed.   The fuzzy logic controller receives messages from the computer via BASIC language commands.   Reply messages to the computer from the fuzzy logic controller are acquired via BASIC.

In this case, the computer was an IBM PC/XT.   The programming language was Microsoft Quick BASIC.   The program was compiled with Microsoft's compiler, but compiling is not essential.   Compiling increases speed of execution and performance.   Ideal computers for fuzzy logic control systems are often ancient IBM PC-XT computers, available in garage sales for $50.   These computers are of no value for today's software, but work very adequately for fuzzy logic measurement and control applications.   IBM is a trademark of IBM Corporation.   Microsoft and Quick BASIC are trademarks of Microsoft, Inc.
The portion of the program for the above system system which examines the input and performs the "triangle" calculations to arrive at a crisp output follows:
910 IF MS = 2420 THEN MIV = 2.4 : GOTO 5000 'MS-MEASURED SPEED, MIV-MOTOR INPUT VOLTAGE
920 IF MS < 2420 THEN 2000 ELSE 1000
1000 ' LINES 1010-1110; GREATER THAN 2420 RPM, SLOW DOWN
1010 IF MS > 2449 THEN MIV = 2.36 : GOTO 5000
1020 ' COMPUTE INTERSECT POINT, IPA, FOR 'ABOUT RIGHT' TRIANGLE
1030 IPA = (2449-MS) / 29
1040 IF IPA =< 0 THEN IPA = .0001
1050 ' COMPUTE INTERSECT POINT, IPS, FOR 'SLOW DOWN' TRIANGLE
1060 IPS = (MS-2420) / 58
1070 ' COMPUTE MOTOR (TRANSISTOR) INPUT VOLTAGE (MIV)
1080 AAR = .5 * .04 * IPA 'AAR - AREA OF 'ABOUT RIGHT' TRIANGLE
1090 ASD = .5 * .08 * IPS 'ASD - AREA OF 'SLOW DOWN' TRIANGLE
1100 D1 = .04 * (ASD / (ASD+AAR))
1110 MIV = 2.4 - D1 : GOTO 5000
2000 ' LINES 2010-2110; LESS THAN 2420 RPM, SPEED UP
2010 IF MS < 2362 THEN MIV = 2.44 : GOTO 5000
2020 ' COMPUTE INTERSECT POINT, IPA, FOR 'ABOUT RIGHT 'TRIANGLE
2030 IPA = (MS-2391) / 29
2040 IF IPA =< 0 THEN IPA = .0001
2050 ' COMPUTE INTERSECT POINT, IPF, FOR 'SPEED UP' TRIANGLE
2060 IPF = (2420-MS) / 58
2070 ' COMPUTE MOTOR INPUT VOLTAGE (MIV)
2080 AAR = .5 * .04 * IPA 'AAR - AREA OF 'ABOUT RIGHT 'TRIANGLE
2090 ASU = .5 * .08 * IPF 'ASU - AREA OF 'SPEED UP' TRIANGLE
2100 D1 = .04 * (ASU / (ASU+AAR))
2110 MIV = 2.4 + D1
5000 '
The remainder of the program would be determined by the program requirements of the analog to digital/digital to analog controller in use.   Program statements would be specific to the hardware selected.   Almost any controller should be usable with the above BASIC statements, so long as the controller could be programmed in BASIC to measure inputs and send control output signals.   Program execution would cycle in the sequence:  1.   Measure input.     2.   Analyze with the fuzzy logic program statements.     3.   Send the output signal.