%
%  readme.m  for the fuzzy logic matlab package by Tom Ahola
%
%    The fuzzy matlab functions are copyright (C) Tom Ahola 1995
%    You may use them freely for educational and personal purposes
%
%    The idea behind the fuzzy controlled temperature sensor
%    is from an article by Lei Wang and Hans Volker
%
%    Type help followed by the function name on the
%    matlab command line to get instructions on how to
%    use the functions.
%
%              Tom Ahola
%                  Helsinki University of Technology
%                  Metrology Research Institute
%                  E-mail:  tom.ahola@hut.fi
%                  WWW:     http://www.hut.fi/~tahola/
%
type readme;
return;

%============ the fuzzy matlab functions ================

% the fuzzy matlab functions

mf=mmembr(centr,width);         %   Create a triangular fuzzy set
mf=mmembr2(a,b,trans);          %   Create a trapezoidal fuzzy set
mf=mmembr3(a,b,transa,transb);  %   Create a trapezoidal fuzzy set
memplot(mf);                    %   plots membership function graph

c=ismembr(mf,x);                %   The degree of membership of x in mf
mf=hatfunc(mf1,hat);            %   Limit membership function by hat value

mf=fuzzyadd(mf1,mf2);           %   Add two fuzzy sets together
mf=fuzzyand(mf1,mf2);           %   Fuzzy AND operation (minimum)
mf=fuzzyor(mf1,mf2);            %   Fuzzy OR operation (maximum)

c=centroid(mf);                 %   Returns center of gravity of fuzzy set


%============ an example fuzzy controller ================

% create fuzzy sets

tlow=mmembr2(-100,20,10);  % temperature low
thigh=mmembr2(20,200,10);  % temperature high
dtneg=mmembr2(-100,0,1);   % temperature change negative
dtlow=mmembr2(0.5,2,1);    % temperature change low
dthigh=mmembr2(2,100,1);   % temperature change high
izero=mmembr(0,5);         % heater current zero
ilow=mmembr2(5,10,5);      % heater current low
ihigh=mmembr2(10,40,5);    % heater current high

% fuzzy control algorith

% TS=current temperature, temps=previous temperature
rule1=hatfunc(ihigh,min([ismembr(tlow,TS),ismembr(dthigh,TS-temps)]));
rule2=hatfunc(ilow,min([ismembr(tlow,TS),ismembr(dtlow,TS-temps)]));
rule3=hatfunc(ilow,min([ismembr(thigh,TS),ismembr(dthigh,TS-temps)]));
rule4=hatfunc(ilow,min([ismembr(thigh,TS),ismembr(dtlow,TS-temps)]));
rule5=hatfunc(izero,ismembr(dtneg,TS-temps));
result=fuzzyadd(rule1,rule2);
result=fuzzyadd(result,rule3);
result=fuzzyadd(result,rule4);
result=fuzzyadd(result,rule5);
heat=centroid(result);
if (heat<0) heat=0; end;


% the rules in the controller are:

  1 - IF temperature is low AND temperature change is high
      THEN current is high

  2 - IF temperature is low AND temperature change is low
      THEN current is low

  3 - IF temperature is high AND temperature change is high
      THEN current is low

  4 - IF temperature is high AND temperature change is low
      THEN current is low

  5 - IF temperature change is negative
      THEN current is zero


% end of readme.m
