How to use output of one fuzzy logic system as input for another?
5 views (last 30 days)
Show older comments
Hi all,
I'm quite new at Matlab and created a fuzzy control system using the Fuzzy Logic Toolbox in Matlab. I would now like to use the value of the output variable of this system as one of the input parameters for another fuzzy control system. Could you show me how I'm able to do this using Matlab?
Best, Sebastian
1 Comment
Answers (1)
Sam Chak
on 20 Sep 2022
Here is a simple example, where the output from the first FIS is fed into the second FIS.
If the dual system is designed correctly, then the output of FIS 2 should give a linear Z-shaped graph.
If u is the output of FIS 2, then the first-order system should be stable.
% *****************
% CREATION OF FIS 1
% *****************
fis1 = sugfis('Name', "Linear_FIS");
% Fuzzy Input
fis1 = addInput(fis1, [-10 +10], 'Name', 'in1');
fis1 = addMF(fis1, 'in1', 'linzmf', [-10 +10], 'Name', 'N');
fis1 = addMF(fis1, 'in1', 'linsmf', [-10 +10], 'Name', 'P');
% Plot input membership functions
figure(1)
plotmf(fis1, 'input', 1), grid on, title('Input MFs of FIS 1')
% Fuzzy Output
fis1 = addOutput(fis1, [-10 +10], 'Name', 'out1');
fis1 = addMF(fis1, 'out1', 'constant', +10, 'Name', 'N');
fis1 = addMF(fis1, 'out1', 'constant', -10, 'Name', 'P');
% Fuzzy Rules for FIS 1
rules = [...
"in1==N => out1=N"; ...
"in1==P => out1=P"; ...
];
fis1 = addRule(fis1, rules);
% Generate input-output relationship of FIS 1
figure(2)
opt = gensurfOptions('NumGridPoints', 41);
gensurf(fis1, opt), grid on
% *****************
% CREATION OF FIS 2
% *****************
fis2 = sugfis('Name', "Saturated_FIS");
% Fuzzy Input
fis2 = addInput(fis2, [-10 +10], 'Name', 'in2');
fis2 = addMF(fis2, 'in2', 'linzmf', [-5 +5], 'Name', 'N');
fis2 = addMF(fis2, 'in2', 'linsmf', [-5 +5], 'Name', 'P');
% Plot input membership functions
figure(3)
plotmf(fis2, 'input', 1), grid on, title('Input MFs of FIS 2')
% Fuzzy Output
fis2 = addOutput(fis2, [-10 10], 'Name', 'out2');
fis2 = addMF(fis2, 'out2', 'constant', -7, 'Name', 'N');
fis2 = addMF(fis2, 'out2', 'constant', +7, 'Name', 'P');
% Fuzzy Rules
% Rules for 1-Input, 1-Output
rules = [...
"in2==N => out2=N"; ...
"in2==P => out2=P"; ...
];
fis2 = addRule(fis2, rules);
% Generate input-output relationship of FIS 2
figure(3)
opt = gensurfOptions('NumGridPoints', 41);
gensurf(fis2, opt), grid on, ylim([-10 10])
% *********************************
% Generate outputs of FIS1 and FIS2
% *********************************
figure(4)
x = linspace(-10, 10, 1001)';
y = evalfis(fis1, x);
z = evalfis(fis2, y); % output of FIS1 as input to FIS2
subplot(2,1,1)
plot(x, y, 'linewidth', 1.5, 'Color', [0 0.4470 0.7410]), grid on
xlabel('$x$', 'Interpreter', 'LaTeX', 'FontSize', 12),
ylabel('$y = \mathcal{F}_{1}(x)$', 'Interpreter', 'LaTeX', 'FontSize', 12)
subplot(2,1,2)
plot(x, z, 'linewidth', 1.5, 'Color', [0.8500 0.3250 0.0980]), grid on,
xlabel('$x$', 'Interpreter', 'LaTeX', 'FontSize', 12)
ylabel('$z = \mathcal{F}_{2}(x)$', 'Interpreter', 'LaTeX', 'FontSize', 12)
2 Comments
Gregory
on 2 Oct 2023
What language is this written in? Is this just all Matlab commands and not a language?
See Also
Categories
Find more on Fuzzy Logic Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!