Main Content

Simulate Fuzzy Inference Systems in万博1manbetx

You can simulate a fuzzy inference system (FIS) in Simulink®using either theFuzzy Logic ControllerorFuzzy Logic Controller with Ruleviewerblocks. Alternatively, you can evaluate fuzzy systems at the command line usingevalfis.

Using theFuzzy Logic Controller, you can simulate traditional type-1 fuzzy inference systems (mamfisandsugfis) and type-2 fuzzy inference systems (mamfistype2andsugfistype2). TheFuzzy Logic Controller with Ruleviewerblock supports only type-1 systems.

For more information on creating fuzzy inference systems, seeBuild Fuzzy Systems Using Fuzzy Logic DesignerandBuild Fuzzy Systems at the Command Line.

Simulate Fuzzy Inference System

Once you have implemented a fuzzy inference system usingFuzzy Logic Designer, usingNeuro-Fuzzy Designer或在命令行上,您可以模拟the system in Simulink.

For this example, you control the level of water in a tank using a fuzzy inference system implemented using a Fuzzy Logic Controller block. Open thesltankmodel.

open_system('sltank')

For this system, you control the water that flows into the tank using a valve. The outflow rate depends on the diameter of the output pipe, which is constant, and the pressure in the tank, which varies with water level. Therefore, the system has nonlinear characteristics.

The two inputs to the fuzzy system are the water level error,level, and the rate of change of the water level,rate. The output of the fuzzy system is the rate at which the control valve is opening or closing,valve.

To implement a fuzzy inference system, specify theFIS nameparameter of the Fuzzy Logic Controller block as the name of a FIS object in the MATLAB® workspace. In this example, the block uses themamfisobjecttank.

For more information on this system, seeWater Level Control in a Tank.

As a first attempt to control the water level, set the following rules in the FIS. These rules adjust the valve based on only the water level error.

  • If the water level is okay, then do not adjust the valve.

  • If the water level is low, then open the valve quickly.

  • If the water level is high, then close the valve quickly.

Specify the rules by creating a vector offisruleobjects and assigning it to theRulesproperty of thetankFIS object.

rule1 ="If level is okay then valve is no_change"; rule2 ="If level is low then valve is open_fast"; rule3 ="If level is high then valve is close_fast"; rules = [rule1 rule2 rule3]; tank.Rules = fisrule(rules);

Simulate the model, and view the water level.

open_system('sltank/Comparison') sim('sltank',100)

These rules are insufficient for controlling the system, since the water level oscillates around the setpoint.

To reduce the oscillations, add two more rules to the system. These rules adjust the valve based on the rate of change of the water level when the water level is near the setpoint.

  • If the water level is okay and increasing, then close the valve slowly.

  • If the water level is okay and decreasing, then open the valve slowly.

To add these rules, use theaddRulefunction.

rule4 ="If level is okay and rate is positive then valve is close_slow"; rule5 ="If level is okay and rate is negative then valve is open_slow"; newRules = [rule4 rule5]; tank = addRule(tank,newRules);

Simulate the model.

sim('sltank',100)

The water level now tracks the setpoint without oscillating.

You can also simulate fuzzy systems using the Fuzzy Logic Controller with Ruleviewer block. Thesltankrulemodel is the same as thesltankmodel, except that it uses the Fuzzy Logic Controller with Ruleviewer block.

open_system('sltankrule')

During simulation, this block displays the Rule Viewer from theFuzzy Logic Designer应用程序。

sim('sltankrule',100)

If you pause the simulation, you can examine the FIS behavior by manually adjusting the input variable values in the Rule Viewer, and observing the inference process and output.

You can also access theFuzzy Logic Designereditors from the Rule Viewer. From the Rule Viewer, you can then adjust the parameters of your fuzzy system using these editors, and export the updated system to the MATLAB workspace. To simulate the updated FIS, restart the simulation. For more information on using these editors, seeBuild Fuzzy Systems Using Fuzzy Logic Designer.

Access Intermediate Fuzzy Inference Results

You can access intermediate fuzzy inference results using theFuzzy Logic Controllerblock. You can use this data to visualize the fuzzy inference process or troubleshoot the performance of your FIS. To access this data, enable the corresponding parameters in the block, and connect signals to the corresponding output ports.

Block Parameter Description Output Port
Fuzzified Inputs Fuzzified input values, obtained by evaluating the input membership functions of each rule at the current input values. fi
Rule firing strengths Rule firing strengths, obtained by evaluating the antecedent of each rule. rfs
Rule outputs Rule outputs, obtained by evaluating the consequent of each rule. ro
Aggregated outputs Aggregate output for each output variable, obtained by combining the corresponding outputs from all the rules. ao

For more information, seeFuzzy Logic Controller.

Simulation Modes

TheFuzzy Logic Controllerblock has the following two simulation modes:

  • Interpreted execution— Simulate fuzzy systems using precompiled MEX files. 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. Doing so simulates your system using the same code path used for generated code.

To select a simulation mode, set theSimulate usingparameter of the block. By default, the block usesInterpreted executionmode for simulation.

Map Command-Line Functionality toFuzzy Logic ControllerBlock

The parameters and ports of theFuzzy Logic Controllerblock map to the input and output arguments ofevalfisor the properties ofevalfisOptions. The following table shows the block parameters and ports that map toevalfisarguments.

evalfisArgument Description Block Parameter or Port
fis Fuzzy inference system FIS name
input, when a single row Input variable values in
output, when a single row Output variable values out
fuzzifiedIn Fuzzified inputs fi
ruleOut Rule outputs ro
aggregateOut Aggregated outputs ao
ruleFiring Rule firing strengths rfs

The following table shows the block parameters that map toevalfisOptionsproperties.

evalfisOptionsProperty Description Block Parameter or Port
NumSamplePoints Number of points in output fuzzy sets Number of samples for output discretization
OutOfRangeInputValueMessage Diagnostic message behavior when an input is out of range Out of range input value
NoRuleFiredMessage Diagnostic message behavior when no rules fire No rule fired
EmptyOutputFuzzySetMessage Diagnostic message behavior when an output fuzzy set is empty Empty output fuzzy set

The remaining parameters of theFuzzy Logic Controllerblock do not map to arguments ofevalfis. Also, unlike theFuzzy Logic Controllerblock,evalfisdoes not support fixed-point data for simulation or code generation.

See Also

Blocks

Related Topics