How to design the membership functions for error and change in error in a fuzzy logic controller

4 views (last 30 days)
fuzzy logic

Answers (1)

Sam Chak
Sam Chak on 25 Apr 2025
Since your description of the problem is a simple one-liner and lacks additional details, I will show the design of the simplest possible two-input fuzzy controller, using one's preferred design of 'All-Encompassing' membership functions (as long as the membership value is above the absolute 0) and a single rule. This approach is inspired by Professor László T. Kóczy, a prominent figure in the field of fuzzy systems.
%% Simplest two-input fuzzy controller
fis = sugfis;
% Fuzzy Input E
fis = addInput(fis, [-1 +1], 'Name', 'E');
fis = addMF(fis, 'E', 'gaussmf', [0.5 0], 'Name', 'All-Encompassing');
% Fuzzy Input CE
fis = addInput(fis, [-1 +1], 'Name', 'CE');
fis = addMF(fis, 'CE', 'gauss2mf', [0.25 -0.5 0.25 0.5], 'Name', 'All-Encompassing');
% Fuzzy Output
fis = addOutput(fis, [-2 +2], 'Name', 'U');
Kp = 1; % proportional gain
Kd = 1; % derivative gain
fis = addMF(fis, 'U', 'linear', [Kp, Kd, 0], 'Name', 'Linear_Plane');
% Fuzzy Rule
fis = addRule(fis, "If E is All-Encompassing and CE is All-Encompassing then U is Linear_Plane");
%% dynamical system
function dx = ode(t, x, fis)
dx = zeros(2, 1);
error = 1 - x(1);
ce = 0 - x(2);
Fctrl = evalfis(fis, [error, ce]);
dx(1) = x(2);
dx(2) = Fctrl;
end
%% plot results
[t, x] = ode45(@(t, x) ode(t, x, fis), [0 20], [0; 0]);
figure
plot(t, x), grid on
xlabel('t'), ylabel('\bf{x}(t)'), title('Step Response')
legend('x_1', 'x_2', 'location', 'east')
figure
subplot(211)
plotmf(fis, 'input', 1), grid on, ylim([-0.2, 1.2]), xlabel('Error'), title('Only one membership function of E')
subplot(212)
plotmf(fis, 'input', 2), grid on, ylim([-0.2, 1.2]), xlabel('Change in Error'), title('Only one membership function of CE')
figure
opt = gensurfOptions('NumGridPoints', 51);
gensurf(fis, opt);
xlabel('Error'), ylabel('Change in Error'), zlabel('U')
title ('Fuzzy Control Surface')
figure
plotrule(fis, Inputs=[0.25, 0.75])

Categories

Find more on Fuzzy Logic in Simulink in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!