Fuzzy Logic Controller
Evaluate fuzzy inference system
Libraries:
Fuzzy Logic Toolbox
Description
The Fuzzy Logic Controller block implements a fuzzy inference system (FIS) in Simulink®. You specify the FIS to evaluate using the FIS name parameter.
For more information on fuzzy inference, see Fuzzy Inference Process.
To display the fuzzy inference process during simulation, use the Fuzzy Logic Controller with Ruleviewer block.
Examples
Simulate FIS
The simulateTipper
model computes tip values for specified food and service ratings using the Fuzzy Logic Controller block, which is configured to use the FIS stored in the tipper.fis
file. For more information on how to create this FIS, see Build Fuzzy Systems Using Fuzzy Logic Designer.
model = "simulateTipper";
open_system(model)
In this model:
You specify the food and service ratings using the
Food Rating
andService Rating
blocks, respectivelyThe input signals are constrained to the expected input range of the FIS, which is [0,10] for both signals.
The constrained input signals are combined using a Mux block.
The Fuzzy Logic Controller block computes the tip output value based on the input signals.
Extended Examples
Simulate Fuzzy Inference System
Once you have implemented a fuzzy inference system using Fuzzy Logic Designer, using Neuro-Fuzzy Designer, or at the command line, you can simulate the system in Simulink.
Water Level Control in a Tank
Implement a water level controller using the Fuzzy Logic Controller block in Simulink.
Temperature Control in a Shower
Implement a water temperature controller using the Fuzzy Logic Controller block in Simulink.
Fuzzy PID Control with Type-2 FIS
Create a type-2 fuzzy logic PID controller and compare its performance with a type-1 fuzzy PID controller and a conventional PID controller.
Ports
Input
in — Input signal
scalar | vector
For a single-input fuzzy inference system, the input is a scalar signal. For a multi-input fuzzy system, combine the inputs into a vector signal using blocks such as:
Mux (Simulink)
Vector Concatenate (Simulink)
Bus Creator (Simulink)
Output
out — Defuzzified output signal
scalar | vector
For a single-output FIS, the output is a scalar signal. For a multi-output FIS, the output is a vector signal. To split system outputs into scalar signals, use the Demux (Simulink) block.
fi — Fuzzified input values
matrix
Fuzzified input values, obtained by evaluating the input membership functions of each rule at the current input values.
For a type-1 FIS, fi is an NR-by-NU matrix signal, where NR is the number of FIS rules. Element (i,j) of fi is the value of the input membership function for the jth input in the ith rule.
For a type-2 FIS, fi is an NR-by-(2*NU) matrix signal. The first NU columns contain the fuzzified values of the upper membership function for each rule, and the last NU columns contain the fuzzified values from the lower membership functions.
For more information on fuzzifying input values, see Fuzzify Inputs.
Dependencies
To enable this port, select the Fuzzified inputs (fi) parameter.
rfs — Rule firing strengths
column vector
Rule firing strengths, obtained by evaluating the antecedent of each rule; that is, applying the fuzzy operator to the values of the fuzzified inputs.
For a type-1 FIS, rfs is a column vector signal of length NR, where NR is the number of rules, and element i is the firing strength of the ith rule.
For a type-2 FIS, rfs is an NR-by-2 matrix signal. The first column contains the rule firing strengths generated using upper membership functions, and the second column contains the rule firing strengths generated using lower membership functions.
For more information on applying fuzzy operators, see Apply Fuzzy Operator.
Dependencies
To enable this port, select the Rule firing strengths (rfs) parameter.
ro — Rule outputs
matrix
Rule outputs, obtained by applying the rule firing strengths to the output membership functions using the implication method specified in the FIS.
For a type-1 Mamdani FIS, ro is an NS-by-(NRNY) matrix signal, where NR is the number of rules, NY is the number of outputs, and NS is the number of sample points used for evaluating output variable ranges. Each column of ro contains the output fuzzy set for one rule. The first NR columns contain the rule outputs for the first output variable, the next NR columns correspond to the second output variable, and so on.
For a type-2 Mamdani FIS, ro is an NS-by-(2*NR*NY) matrix signal. The first NR*NY columns contain the rule outputs generated using upper membership functions, and the last NR*NY columns contain the rule outputs generated using lower membership functions.
For a type-1 Sugeno system, each rule output is a scalar value. In this case, ro is an NR-by-NY matrix signal. Element (j,k) of ro is the value of the kth output variable for the jth rule.
For a type-2 Sugeno system, ro is an NR-by-(3*NY) array. The first NY columns contain the rule output levels. The next NY columns contain the corresponding rule firing strengths generated using upper membership functions. The last NY columns contain the rule firing strengths generated using lower membership functions. For example, in a three-output system, columns 4 and 7 contain the firing strengths for the output levels in column 1.
For more information on fuzzy implication, see Apply Implication Method.
Dependencies
To enable this port, select the Rule outputs (ro) parameter.
To specify NS, use the Number of samples for output discretization parameter.
ao — Aggregated output
matrix | row vector
Aggregate output for each output variable, obtained by combining the corresponding outputs from all the rules using the aggregation method specified in the FIS.
For a type-1 Mamdani fuzzy inference system, the aggregate result for each output variable is a fuzzy set. In this case, ao is as an NS-by-NY matrix signal, where NY is the number of outputs and NS is the number of sample points used for evaluating output variable ranges. Each column of ao contains the aggregate fuzzy set for one output variable.
For a type-2 Mamdani FIS, the aggregate result for each output variable is a fuzzy set. In this case, ao is as an NS-by-(2*NY) matrix signal. The first NY columns contain the aggregated outputs generated using upper membership functions, and the last NY columns contain the aggregated outputs generated using lower membership functions.
For a type-1 Sugeno system, the aggregate result for each output variable is a scalar value. In this case, ao is a row vector of length NY, where element k is the sum of the rule outputs for the kth output variable.
For a type-2 Sugeno system, ao is an NR-by-(3*NY) array. ro contains the same data as ao with the columns sorted based on the output levels. For example, in a three-output system, when the output levels in column 1 are sorted, the corresponding firing strengths in columns 4 and 7 are adjusted accordingly.
For more information on fuzzy aggregation, see Aggregate All Outputs.
Dependencies
To enable this port, select the Aggregated outputs (ao) parameter.
To specify NS, use the Number of samples for output discretization parameter.
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
General
FIS name — Fuzzy inference system to evaluate
mamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object | FIS file name in quotes | MAT file name in quotes
Fuzzy inference system to evaluate, specified as one of the following:
mamfis
orsugfis
object — Specify the name of a type-1 FIS object in the MATLAB® workspace.mamfistype2
orsugfistype2
object — Specify the name of a type-2 FIS object in the MATLAB workspace.Name of a FIS file (
*.fis
) in the current working folder or on the MATLAB path. Including the file extension in the file name is optional. Specify the filename in quotes.Name of a MAT file (
*.mat
) in the current working folder or on the MATLAB path. The MAT file must contain only one FIS object. Including the file extension in the file name is optional. Specify the filename in quotes. (since R2024a)
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | FIS |
Values: | '"tipper.fis"' (default) | variable name in quotes | file name in quotes |
Number of samples for output discretization — Number of points in output fuzzy sets
101 (default) | integer greater than 1
Number of samples for discretizing the range of FIS output variables, specified as an integer greater than 1
. This value corresponds to the number of points in the output fuzzy set for each rule.
To reduce memory usage while evaluating Mamdani FISs, specify a lower number of samples. Doing so sacrifices the accuracy of the defuzzified output value. Specifying a low number of samples can make the output area for defuzzification zero. In this case, the defuzzified output value is the midpoint of the output variable range.
Note
The block ignores this parameter when evaluating Sugeno FISs.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | OutputSampleNumber |
Values: | "101" (default) | integer greater than 1 in quotes |
Data type — Signal data type
double
(default) | single
| fixed-point
| expression
Signal data type, specified as one of the following:
double
— Double-precision signalssingle
— Single-precision signalsfixdt(1,16,0)
— Fixed-point signals with binary point scalingfixdt(1,16,2^0,0)
— Fixed-point signals with slope and bias scalingExpression — Expression that evaluates to one of these data types
For fixed-point data types, you can configure the signedness, word length, and scaling parameters using the Data Type Assistant. For more information, see Specifying a Fixed-Point Data Type (Simulink).
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | DataType |
Values: | "double" (default) | "single" | "fixdt(1,16,0)" | "fixdt(1,16,2^0,0)" |
Fuzzified inputs (fi) — Enable fi
output port
off
(default) | on
Enable fi output port for accessing intermediate fuzzified input data.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | FuzzifiedInputs |
Values: | "off" (default) | "on" |
Rule firing strengths (rfs) — Enable rfs
output port
off
(default) | on
Enable rfs output port for accessing intermediate rule firing strength data.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | RuleFiringStrengths |
Values: | "off" (default) | "on" |
Rule outputs (ro) — Enable ro
output port
off
(default) | on
Enable ro output port for accessing intermediate rule output data.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | RuleOutputs |
Values: | "off" (default) | "on" |
Aggregated outputs (ao) — Enable ao
output port
off
(default) | on
Enable ao output port for accessing intermediate aggregate output data.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | AggregatedOutputs |
Values: | "off" (default) | "on" |
Simulate using — Simulation mode
Interpreted execution
(default) | Code generation
Simulation mode, specified as one of the following:
Interpreted execution
— Simulate fuzzy systems using precompiled MEX files forsingle
anddouble
data types. Using this option reduces the initial compilation time of the model.Code generation
— Simulate fuzzy system without precompiled MEX files. Use this option when simulating fuzzy systems for code generation applications.
For fixed-point data types, the Fuzzy Logic Controller block always simulates using Code generation
mode.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | SimulateUsing |
Values: | "Interpreted execution" (default) | "Code generation" |
Diagnostics
Out of range input value — Diagnostic message behavior when an input is out of range
warning
(default) | error
| none
Diagnostic message behavior when an input is out of range, specified as one of the following:
warning
— Report the diagnostic message as a warning.error
— Report the diagnostic message as an error.none
— Do not report the diagnostic message.
When an input value is out of range, corresponding rules in the fuzzy system can have unexpected firing strengths.
Dependencies
Diagnostic messages are provided only when the Simulate using parameter is
Interpreted execution
.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | OutOfRangeInputValueMessage |
Values: | "warning" (default) | "error" | "none" |
No rule fired — Diagnostic message behavior when no rules fire
warning
(default) | error
| none
Diagnostic message behavior when no rules fire for a given output variable, specified as one of the following:
warning
— Report the diagnostic message as a warning.error
— Report the diagnostic message as an error.none
— Do not report the diagnostic message.
When No rule fired is warning
or none
and no rules fire for a given output, the defuzzified output value is set to its mean range value.
Dependencies
Diagnostic messages are provided only when the Simulate using parameter is
Interpreted execution
.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | NoRuleFiredMessage |
Values: | "warning" (default) | "error" | "none" |
Empty output fuzzy set — Diagnostic message behavior when an output fuzzy set is empty
warning
(default) | error
| none
Diagnostic message behavior when an output fuzzy set is empty, specified as one of the following:
warning
— Report the diagnostic message as a warning.error
— Report the diagnostic message as an error.none
— Do not report the diagnostic message.
When Empty output fuzzy set is warning
or none
and an output fuzzy set is empty, the defuzzified value for the corresponding output is set to its mean range value.
Dependencies
This diagnostic message applies to Mamdani systems only.
Diagnostic messages are provided only when the Simulate using parameter is
Interpreted execution
.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | EmptyOutputFuzzySetMessage |
Values: | "warning" (default) | "error" | "none" |
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced before R2006aR2024b: Fuzzy inference system structures not supported
This block no longer supports fuzzy inference system structures. Use mamfis
and sugfis
objects
instead. To convert existing fuzzy inference system structures to objects, use the convertfis
function.
R2024a: Specify FIS using MAT file
You can specify the FIS to evaluate using a MAT file in the current working folder or on the MATLAB path. The MAT file must contain only one FIS object.
R2019b: Fuzzy inference system structures will not be supported
Support for fuzzy inference systems structures will be removed in a future release. This change was announced in R2018b. Using fuzzy inference system structures with this block issues a warning starting in R2019b.
R2017b: Access intermediate fuzzy inference results
Using the Fuzzy Logic Controller block, you can access intermediate fuzzy inference results by enabling the following output ports.
fi
— Fuzzified input valuesrfs
— Rule firing strengthsro
— Rule outputsao
— Aggregated membership function for each output variable
R2017b: Expanded data type support
The Fuzzy Logic Controller block supports double-precision, single-precision, and fixed-point data types.
R2017b: Improved code generation support
When generating code using Simulink Coder™, the Fuzzy Logic Controller block supports code generation for fuzzy systems that use:
Single-precision data.
Fixed-point data. To generate code for fixed-point data, you need Fixed-Point Designer™ software.
Custom membership functions and custom inference functions. For more information on specifying custom functions for a fuzzy system, see Build Fuzzy Systems Using Custom Functions.
R2017b: PLC code generation support
The Fuzzy Logic Controller block supports generation of IEC 61131-3 Structured Text for PLC deployment using Simulink PLC Coder™ software.
See Also
Blocks
Apps
Functions
mamfis
|sugfis
|mamfistype2
|sugfistype2
|readfis
|evalfis
|genfis
|writeFIS
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)