Fuzzy Logic display results

25 visualizzazioni (ultimi 30 giorni)
strat
strat il 31 Dic 2018
Risposto: Sam Chak il 21 Set 2022
Dear all.
I am trying to make a basic fuzzy logic system for an aircondition operation. This is my first attemp to fuzzy logic, so my knowledge is very limited.
So far, Membership function & Rules all work fine . (it 's a very simple model)
I have two input variables ( Temperature (T) an Humidity (H) ) and two output variables ( FAN SPEED (FS) and DEHUMIDIFIER(DH) ).
I am trying to design a new script from the EDITOR, where you can give the input variables ( T & H) and get the results ( FS & DH).
Here comes my answer.
I want to get in the results the linguistic variable of the outputs, not the "fuzzy number". So, instead of displaying i.e. FS=3 & DH=2 ,
I would like to get FS=HIGH & FS= HIGH (or variables like these)
I have wrttten the following code
r=readfis('FuzzyLogicAIRCONDITION.fis');
T=input('Temperature (scale: 0-40)=');
H=input('Humidity (scale: 0-100)=');
result=evalfis([T H], r);
disp(['Fan Speed & Dehumidifier= ', num2str(result)]);
Running the code I have the following:
i.e. T=10 & H= 65% --> OUTPUT: // FS=3.5 & DH=1.5 (the variable FS=3.5 correspond to FS="HIGH" and DH=2.5 to DH="LOW").
How can I get the FS="HIGH" and DH="LOW" to my results?

Risposte (1)

Sam Chak
Sam Chak il 21 Set 2022
For this requirement, we can try the dictionary Object (newly introduced in R2022b) to map the FIS output (Fan Speed number) to the linguistic output.
If the FIS output is between 0 to 1, the Fan Speed is Low.
If the FIS output is between 1 to 2, the Fan Speed is Medium.
If the FIS output is between 2 to 3, the Fan Speed is High.
fis = mamfis('Name', "Fuzzy_FanSpeed");
% Fuzzy Input #1
fis = addInput(fis, [20 30], 'Name', 'Temperature');
fis = addMF(fis, 'Temperature', 'zmf', [22.5 26.25], 'Name', 'Lo');
fis = addMF(fis, 'Temperature', 'gaussmf', [1.15 25.00], 'Name', 'Me');
fis = addMF(fis, 'Temperature', 'smf', [23.75 27.5], 'Name', 'Hi');
% Fuzzy Input #2
fis = addInput(fis, [0 100], 'Name', 'Humidity');
fis = addMF(fis, 'Humidity', 'zmf', [25 62.5], 'Name', 'Lo');
fis = addMF(fis, 'Humidity', 'gaussmf', [11.5 50], 'Name', 'Me');
fis = addMF(fis, 'Humidity', 'smf', [37.5 75], 'Name', 'Hi');
% Plot membership functions
figure(1)
subplot(2,1,1)
plotmf(fis, 'input', 1), grid on, title('Input: Temperature \circ{C}')
subplot(2,1,2)
plotmf(fis, 'input', 2), grid on, title('Input: Humidity %')
% Fuzzy Output
fis = addOutput(fis, [-0.91 3.91], 'Name', 'Fan_Speed');
fis = addMF(fis, 'Fan_Speed', 'zmf', [0.305 1.50], 'Name', 'Lo');
fis = addMF(fis, 'Fan_Speed', 'gaussmf', [0.5496 1.5], 'Name', 'Me');
fis = addMF(fis, 'Fan_Speed', 'smf', [1.50 2.695], 'Name', 'Hi');
% Plot membership functions
figure(2)
plotmf(fis, 'output', 1), grid on, title('Output: Fan Speed')
% Fuzzy Rules
rules = [...
"Temperature==Lo & Humidity==Lo => Fan_Speed=Lo"; ...
"Temperature==Lo & Humidity==Me => Fan_Speed=Lo"; ...
"Temperature==Lo & Humidity==Hi => Fan_Speed=Me"; ...
"Temperature==Me & Humidity==Lo => Fan_Speed=Lo"; ...
"Temperature==Me & Humidity==Me => Fan_Speed=Me"; ...
"Temperature==Me & Humidity==Hi => Fan_Speed=Hi"; ...
"Temperature==Hi & Humidity==Lo => Fan_Speed=Me"; ...
"Temperature==Hi & Humidity==Me => Fan_Speed=Hi"; ...
"Temperature==Hi & Humidity==Hi => Fan_Speed=Hi"; ...
];
fis = addRule(fis, rules);
% Generate output surface of Mamdani FIS
figure(3)
opt = gensurfOptions('NumGridPoints', 51);
gensurf(fis, opt)
% Test if works:
Current_Temp = 26;
Current_Humd = 70;
Speed_number = round(evalfis(fis, [Current_Temp Current_Humd]))
Speed_number = 3
selector = [1 2 3];
speed = ["Low" "Medium" "High"];
FuzzyFan = dictionary(selector, speed)
FuzzyFan =
dictionary (doublestring) with 3 entries: 1 ⟼ "Low" 2 ⟼ "Medium" 3 ⟼ "High"
FS = FuzzyFan(Speed_number)
FS = "High"

Categorie

Scopri di più su Fuzzy Inference System Modeling in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by