- What is the desired Kp value when when both E and EC are negatively large?
- What is the desired Kp value when when E is negatively large and EC is positively large?
- What is the desired Kp value when when E is positively large and EC is negatively large?
- What is the desired Kp value when when both E and EC are positively large?
- What is the desired Kp value when when both E and EC are near zero?
How can I exactly identify the range of outputs of FuzzyPID-controller?
5 views (last 30 days)
Show older comments
I always can't exactly find out the range of the outputs(kp,ki,kd).Does there is any way can I identify the range when I layout FuzzyPID-controller?

2 Comments
Sam Chak
on 27 Mar 2025
Hi @乐乐
In the image, you designed the Mamdani fuzzy system to map the input spaces of E and EC to an output space of Kp, where the output range [0, 3] defines all possible output values of Kp that the fuzzy controller can produce from 0 to 3. In reality, the Mamdani fuzzy system can only generate output values in the open interval (0, 3), excluding exact 0 or exact 3 (see Kp Gain Surface).
To determine the fuzzy output range, you need to address several questions:
These desired Kp values are not simply derived from arbitrary assumptions. You need to verify experimentally or through simulations that these Kp values are feasible. The true output range is determined by the minimum and maximum elements in the set of the five Kp values.
Kp1 = 0.5; Kp2 = 1.0; Kp3 = 1.5; Kp4 = 2.0; Kp5 = 2.5;
Kp = [Kp1 Kp2 Kp3 Kp4 Kp5];
Kmin= min(Kp)
Kmax= max(Kp)
sd = std(Kp);
output_range = [Kmin-sd Kmax+sd] % for MamFIS only
Additionally, you must apply common sense such that if a negative value of Kp can destabilize the system, then readjust the lower bound accordingly.
By the way, I am not certain how your actual Kp gain surface appears. However, if you allow the Fuzzy Designer App to automatically add the AND-based rules to your Mamdani FIS for all possible input combinations, you will obtain a nearly flat inclined plane for Kp gain only, not
. This design is typically not suitable for reference tracking. Why? Because it produces a very large control action when both E & EC are positively large, and a very small control action when both E & EC are negatively large.
Do you have the plant model to which you would like to apply the Fuzzy PID Controller?
%% Fuzzy Controller
fis = mamfis;
% settings
ud = 1;
dis = 2/3;
c1 =-ud;
c2 = c1 + dis;
c3 = c2 + dis;
c4 = c3 + dis;
sig = (1/3)/sqrt(log(4));
% Fuzzy Input 1
fis = addInput(fis, [-ud +ud], 'Name', 'Err');
fis = addMF(fis, 'Err', 'gaussmf', [sig c1], 'Name', 'N2');
fis = addMF(fis, 'Err', 'gaussmf', [sig c2], 'Name', 'N1');
fis = addMF(fis, 'Err', 'gaussmf', [sig c3], 'Name', 'P1');
fis = addMF(fis, 'Err', 'gaussmf', [sig c4], 'Name', 'P2');
% Fuzzy Input 2
fis = addInput(fis, [-ud +ud], 'Name', 'dEr');
fis = addMF(fis, 'dEr', 'gaussmf', [sig c1], 'Name', 'N2');
fis = addMF(fis, 'dEr', 'gaussmf', [sig c2], 'Name', 'N1');
fis = addMF(fis, 'dEr', 'gaussmf', [sig c3], 'Name', 'P1');
fis = addMF(fis, 'dEr', 'gaussmf', [sig c4], 'Name', 'P2');
% Fuzzy Output
fis = addOutput(fis, [0 3], 'Name', 'Kp');
fis = addMF(fis, 'Kp', 'linzmf', [0.0 0.5], 'Name', 'K1');
fis = addMF(fis, 'Kp', 'trimf', [0.0 0.5 1.0], 'Name', 'K2');
fis = addMF(fis, 'Kp', 'trimf', [0.5 1.0 1.5], 'Name', 'K3');
fis = addMF(fis, 'Kp', 'trimf', [1.0 1.5 2.0], 'Name', 'K4');
fis = addMF(fis, 'Kp', 'trimf', [1.5 2.0 2.5], 'Name', 'K5');
fis = addMF(fis, 'Kp', 'trimf', [2.0 2.5 3.0], 'Name', 'K6');
fis = addMF(fis, 'Kp', 'linsmf', [2.5 3.0], 'Name', 'K7');
% Fuzzy Rules
rules = [
"Err==N2 & dEr==N2 => Kp=K1"
"Err==N2 & dEr==N1 => Kp=K2"
"Err==N2 & dEr==P1 => Kp=K3"
"Err==N2 & dEr==P2 => Kp=K4"
"Err==N1 & dEr==N2 => Kp=K2"
"Err==N1 & dEr==N1 => Kp=K3"
"Err==N1 & dEr==P1 => Kp=K4"
"Err==N1 & dEr==P2 => Kp=K5"
"Err==P1 & dEr==N2 => Kp=K3"
"Err==P1 & dEr==N1 => Kp=K4"
"Err==P1 & dEr==P1 => Kp=K5"
"Err==P1 & dEr==P2 => Kp=K6"
"Err==P2 & dEr==N2 => Kp=K4"
"Err==P2 & dEr==N1 => Kp=K5"
"Err==P2 & dEr==P1 => Kp=K6"
"Err==P2 & dEr==P2 => Kp=K7"
];
fis = addRule(fis, rules);
%% plot results
figure
subplot(311)
plotmf(fis, 'input', 1), grid on,
xlabel('Error'), ylabel('\mu')
title('Input Fuzzy sets of Err')
subplot(312)
plotmf(fis, 'input', 2), grid on,
xlabel('Change in Error'), ylabel('\mu')
title('Input Fuzzy sets of dEr')
subplot(313)
plotmf(fis, 'output', 1), grid on,
xlabel('Kp value'), ylabel('\mu')
title('Output Fuzzy sets of Kp')
figure
opt = gensurfOptions('NumGridPoints', 51);
gensurf(fis, opt);
xlabel('Error'), ylabel('Change in Error'), zlabel('Kp')
title ('Kp Gain Surface')
Accepted Answer
Sam Chak
on 30 Mar 2025
Hi @乐乐
Hope that you're still around.
First, you must understand that a PID controller alone cannot freely manipulate the step response of a stable 3rd-order linear plant because the controller cannot influence the accelerative component or the second derivative of the plant. Nevertheless, it is still possible to slightly improve the step response through the nonlinear effects of the fuzzy PID controller. However, the performance will be limited by the coefficient of the accelerative component.
Instead of designing a fuzzy system that varies the entire space of the control gains, a more appropriate approach would be to design dimensionless control gain multipliers specifically for
and
using fuzzy logic. The PID gains can be obtained from the autotuner. The designer can determine the desired control gain multipliers at specific operating points and then employ ANFIS to train the data and create the Sugeno fuzzy models.
The fuzzy PD+I control law is represented by this equation:
where
and
are the fuzzy models, and
is the static multiplier for the
gain. A saturation function is necessary to limit the amplitude of the rate of change of the error signal, as this signal will spike initially for a step input.
are the fuzzy models, and
is the static multiplier for the Code for ANFIS to create the Sugeno fuzzy models:
%% Fuzzy Kp multiplier
% Designer's Choice: desired Kp multiplier at specific operating points, where x1 is the error
x1 = linspace(-1.5, 1.5, 15)';
yKp = [0.6665; 0.7771; 0.9303; 1.1531; 1.4912; 2.0020; 2.6453; 3.0000; 2.6453; 2.0020; 1.4912; 1.1531; 0.9303; 0.7771; 0.6665];
% ANFIS settings for Fuzzy Kp multiplier
genOpt1 = genfisOptions('GridPartition');
genOpt1.NumMembershipFunctions = 7;
genOpt1.InputMembershipFunctionType = "gaussmf";
genOpt1.OutputMembershipFunctionType = "constant";
inFIS1 = genfis(x1, yKp, genOpt1);
opt1 = anfisOptions('InitialFIS', inFIS1);
opt1.DisplayANFISInformation = 0;
opt1.DisplayErrorValues = 0;
opt1.DisplayStepSize = 0;
opt1.DisplayFinalResults = 0;
KpFIS = anfis([x1 yKp], opt1);
KpFIS.Outputs.MembershipFunctions
figure
tL1 = tiledlayout(2, 1, 'TileSpacing', 'Compact');
nexttile
plotmf(KpFIS, 'input', 1), grid on
nexttile
plot(x1, yKp, 'o'), hold on
X1 = linspace(-1.5, 1.5, 301)';
plot(X1, evalfis(KpFIS, X1)), grid on,
xlabel('Error'), ylabel('Kp multiplier')
legend('Desired Kp multiplier', 'Kp ANFIS Output', 'location', 'south')
title(tL1, 'Fuzzy Kp multiplier')
%% Fuzzy Kd multiplier
% Designer's Choice: desired Kd multiplier at specific operating points, where x2 is the de/dt
x2 = linspace(-0.75, 0.75, 15)';
yKd = [1.3333; 1.5552; 1.8646; 2.3218; 3.0427; 4.2240; 5.9281; 7.0000; 5.9281; 4.2240; 3.0427; 2.3218; 1.8646; 1.5552; 1.3333];
% ANFIS settings for Fuzzy Kd multiplier
genOpt2 = genfisOptions('GridPartition');
genOpt2.NumMembershipFunctions = 7;
genOpt2.InputMembershipFunctionType = "gaussmf";
genOpt2.OutputMembershipFunctionType = "constant";
inFIS2 = genfis(x2, yKd, genOpt2);
opt2 = anfisOptions('InitialFIS', inFIS2);
opt2.DisplayANFISInformation = 0;
opt2.DisplayErrorValues = 0;
opt2.DisplayStepSize = 0;
opt2.DisplayFinalResults = 0;
KdFIS = anfis([x2 yKd], opt2);
KdFIS.Outputs.MembershipFunctions
figure
tL2 = tiledlayout(2, 1, 'TileSpacing', 'Compact');
nexttile
plotmf(KdFIS, 'input', 1), grid on
nexttile
plot(x2, yKd, 'o'), hold on
X2 = linspace(-0.75, 0.75, 151)';
plot(X2, evalfis(KdFIS, X2)), grid on,
xlabel('Rate of Change of Error'), ylabel('Kd multiplier')
legend('Desired Kd multiplier', 'Kd ANFIS Output')
title(tL2, 'Fuzzy Kd multiplier')
%% Nominal PID control gains
Gp = tf(1, [1 3 3 1]);
Gc = pidtune(Gp, 'PIDF');
Kp = Gc.Kp;
Ki = Gc.Ki;
Kd = Gc.Kd;
Tf = Gc.Tf;
Control Block Diagram:

Step responses:

7 Comments
Sam Chak
on 6 Apr 2025
Hi @乐乐
Thank you for your update. Could you please post this additional problem as a new question? I now have a better understanding of the control problem for the 2nd-order system and have formulated an idea for designing the Mamdani fuzzy controller. However, this method differs from the ANFIS-based control design mentioned in my Answer above.
More Answers (0)
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!
















