ADDING FUZZY LOGIC FILE .FLS IN MATLAB- SIMULINK

Photo of author

By Jackson Taylor

Home » Programming » ADDING FUZZY LOGIC FILE .FLS IN MATLAB- SIMULINK

Fuzzy logic controllers are common in power electronics, motor drives and other control projects. Designing the controller is only half the job. You also have to get the saved fuzzy system into your Simulink model so the simulation can use it. This guide shows how to add a fuzzy logic .FLS file to MATLAB Simulink, and what to do when MATLAB does not accept the file straight away. The video above shows the same process on screen.

What a .FLS file is and how MATLAB reads fuzzy systems

A fuzzy logic file stores the parts of a fuzzy inference system (FIS): the input and output variables, the membership functions, the rules, and settings such as the AND/OR methods and the defuzzification method.

MATLAB’s Fuzzy Logic Toolbox normally saves and loads these systems as plain-text .fis files. If you have a file with a .fls extension, check what it contains before you do anything else. If it is a text file in the FIS layout, MATLAB can usually read it once the extension is .fis. If it came from a different fuzzy tool and uses another format, you will need to rebuild the system in MATLAB or export it again in a compatible format.

Before you start

  • MATLAB with Simulink installed.
  • The Fuzzy Logic Toolbox. Without it, the fuzzy blocks and functions are not available.
  • Your fuzzy file saved in a folder you can easily find.
  • A Simulink model with a place for the controller, such as an error signal going in and a control signal coming out.

Step 1: Check the file in a text editor

Open the .FLS file in Notepad or any plain text editor. A file in FIS format typically starts with a [System] section that lists the name, type (for example Mamdani or Sugeno), number of inputs and outputs, and number of rules. It is followed by [Input1], [Output1] and [Rules] sections.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video
See also
PIC16F877A-HITECH C- EEPROM

If you see that structure, the file is in the format MATLAB expects. If the content is unreadable or looks very different, it is probably not a FIS file and the steps below will not work as they are.

Step 2: Put the file in MATLAB’s working folder

Copy the file into the folder you are using as MATLAB’s current folder, or add its folder to the MATLAB path. Keeping the Simulink model and the fuzzy file in the same folder avoids most “file not found” errors.

If MATLAB does not recognise the extension, make a copy of the file and rename the copy to use .fis, for example controller.fis. Keep the original untouched so you can go back to it.

Step 3: Load the fuzzy system into the workspace

In the MATLAB command window, read the file into a variable:

  1. Type fis = readfis(‘controller.fis’); and press Enter.
  2. Check that fis appears in the Workspace panel.
  3. Optionally, open it in the Fuzzy Logic Designer to confirm the membership functions and rules look the way you expect.

You can also test it quickly with evalfis, giving it a sample input value. If the output is sensible, the file loaded correctly.

Step 4: Add the Fuzzy Logic Controller block in Simulink

  1. Open your Simulink model and open the Library Browser.
  2. Find the Fuzzy Logic Controller block under the Fuzzy Logic Toolbox library and drag it into the model.
  3. Double-click the block to open its parameters.
  4. In the FIS name field, enter the name of the workspace variable, for example fis. Depending on your MATLAB version, the field may also accept a file name.
  5. Click OK or Apply.

Next, connect the signals. The number of block inputs must match the number of inputs in your fuzzy system. A typical controller takes the error and the change in error, so you would use a Sum block to compute the error and a Derivative or a Delay-based block to get the change.

See also
CHIP ENABLE ERROR IN AT89S52 FOR USBASP

Step 5: Make the variable load automatically

The workspace variable disappears when you close MATLAB, and the simulation will then fail with an undefined variable error. To avoid this, load the file when the model opens:

  1. In Simulink, go to Modeling and open Model Properties.
  2. Open the Callbacks tab.
  3. Add fis = readfis(‘controller.fis’); to InitFcn (or PreLoadFcn).
  4. Save the model.

Now the fuzzy system is loaded every time you open or run the model.

Step 6: Run and check the simulation

Set the stop time, add a Scope on the output and run the model. Compare the response with what you expect: the output should settle near the reference without large overshoot or constant oscillation. If it does not, adjust the input scaling gains before changing the rules, since badly scaled inputs are a common cause of poor fuzzy control.

Where this is used

Fuzzy controllers are often used to regulate converter output voltage. Examples on this site include a 12V to 24V boost converter simulation with fuzzy control, and a quadruple boost converter with a closed loop. If you want to compare fuzzy control with a conventional controller, the closed loop boost converter example is a useful reference for how the feedback path is built in Simulink.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

Common problems and fixes

“Undefined function or variable ‘fis'”

The variable is not in the workspace. Run readfis again, or add it to the model’s InitFcn callback as described above.

MATLAB cannot open the file

Check the file path, the spelling and the extension. Make sure the file is in the current folder or on the MATLAB path. If the content is not in FIS format, it will not load.

Input and output counts do not match

The block must have the same number of inputs as the FIS. Check the Mux or the signal lines connected to the Fuzzy Logic Controller block.

See also
SOLAR FULL BRIDGE BASED MICRO INVERTER -SIMULATION MATLAB -SIMULINK

Output is stuck or always the same value

The input values may be outside the range of the membership functions. Check the input ranges in the Fuzzy Logic Designer and add gains so the signals fit within them.

Simulation runs very slowly

Large rule bases and a very small fixed step size slow things down. Reduce the number of rules if you can, or use a larger step size if the rest of the model allows it.

FAQ

Can MATLAB open a .FLS file directly?

MATLAB’s Fuzzy Logic Toolbox is built around .fis files. A .FLS file works only if its content is in the FIS text format, and you may need to rename a copy to .fis first.

Do I need the Fuzzy Logic Toolbox?

Yes, for the Fuzzy Logic Controller block and functions such as readfis and evalfis. Without the toolbox you would have to build the fuzzy logic yourself with basic Simulink blocks or MATLAB code.

Can I edit the fuzzy system after loading it?

Yes. Open the variable in the Fuzzy Logic Designer, change the membership functions or rules, and save it again. Then reload it in your model.

Why does my model work on my computer but not on another one?

The other computer may be missing the fuzzy file, the toolbox, or the callback that loads the file. Keep the model and the fuzzy file together and confirm the toolbox is installed.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works