Vous êtes sur la page 1sur 4

THIS M-FILE IS CREATED BY A.

RAMEZANIFAR,student of TEHRAN POLITECHNINC UNIVERSITY % ELECTRICLA ENGINEERING DEPARTMENT, % % % This program is useful for fast implementation of a fuzzy logic controller. Suppose a fuzzy controller % with two inputs and 1 output. From various choices to implement it, if we choose product inference % engine, singleton fuzzifier and center average defuzzifier (which is very commonplace choice) % the output will be as : % % % % % % % % % % % where __ \ /__ l __ \ /__ l _l y denotes center of l-th rule and M_A and M_B are input _l _l _l _l _l y ( m_A . m_B )

% y= ------------------( m_A . m_B )

membership functions of first input (A) % and second input (B) respectively. To calculate y, the software needs to use two intricate loops and this % waste enormous amount of time which decreases simulation speed. % In the following we calculate y with using matrix algebra which prompts simulation time. this formula is % beneficent for use both in m-file and SIMULINK. In the following there is a function which receives % two values as inputs and returns the output based on fuzzy rules. If one wants to use it in a SIMULINK, % it can be written in embeddable function y = fcn(u) x1=u(1); x2=u(2); %the first input value %the second input value MATLAB function block .

% For each of two inputs n & m fuzzy membership functions are constructed respectively. n*m fuzzy rules % are constructed to obtain the fuzzy output. % Going on three steps we produce three matrices and refer to them before long. % The A input % --------------------------% A=[M_A_1 M_A_2 ... M_A_n]; % evaluate member ship functions of the first input : ( in the following example there are three % membership functions for each inputs ) SIGMA=2.14; C=-8; N_A=exp(-(x1 - C).^2/(2*SIGMA^2)); SIGMA=2.5; C=-5.5; ZR_A_left=1./(1 + exp(-A*(x1-C))); SIGMA=2.5; C=5.5; ZR_A_right=1./(1 + exp(-A*(x1-C))); ZR_A=ZR_P_right-ZR_P_left; SIGMA=2.14; C=8; P_A=exp(-(x1 - C).^2/(2*SIGMA^2)); A=[N_A ZR_A P_A]; % Similarly the B matrix is composed with evaluating m membership functions of second input. % B=[M_B_1 M_B_2 ... M_B_m]; %--------------------------%evaluate membership functions of the second input SIGMA=0.009; C=-0.025; N_B=exp(-(x2 - C).^2/(2*SIGMA^2)); SIGMA=500; matrix is composed of n evaluated membership functions of the first

C=-0.014; ZR_B_left=1./(1 + exp(-A*(x2-C))); SIGMA=500; C=0.014; ZR_B_right=1./(1 + exp(-A*(x2-C))); ZR_B=ZR_Pd_right-ZR_Pd_left; SIGMA=0.009; C=0.025; P_B=exp(-(x2 - C).^2/(2*SIGMA^2)); B=[N_B ZR_B P_B]; %------------------------------------------------------% The fuzzy rules are given in table below: % % % % % % % % % % % % % % % % % the fist row describes the first input and the first column describes the second input. The fuzzy value for % the output is obtained by reading the cell representing the intersection of the applicable column and row. % % With regard to the this table the matrix R is made in such a way that each elements of it % conforms to the center of membership function in the same element in the table above. second input . . . |M_A_1 M_B_1|M_y_1 | M_B_2|M_y_(n+1) | | ... | M_y_(n*m) output ... M_A_2 ... M_A_n M_y_2 ... M_Y_m -----------------------------first input

M_B_m|...

-----|---------------------------

% the center of membership functions of the output (in this example output has three membership function) : N_y=-5; ZR_y=0; P_y=5; %there are 3*3=9 rules R=[P_y P_y ZR_y P_y ZR_y N_y P_y; N_y ; N_y];

% in this condition, with using some operations and arrangments, the output y reforms in the form of : % y= ( A'*R*B )/( sum(A).sum(B) ) % sum denotes summation on the vector's a=A'*Press_sp*B; b=sum(A)*sum(B); y=a/b; % therefore we can calculate the output using matrix algebra which is more faster than using % fuzzy logic controller block in the SIMULINK. In comparison with Fuzzy toolbox, in complicated systems, % the speed of simulation is improved. elements

...

Vous aimerez peut-être aussi