# How to create relation from each rule

2 views (last 30 days)
KoolMU on 9 May 2015
Commented: KoolMU on 14 May 2015
How to create fuzzy relation from multi input variable? My fuzzy system has four input from QRS duration, QTP interval, Raton RR and Area A ST. After I obtain membership function, I need to crate fuzzy operation in each rule for obtain relation between input and output.
Assume my rule is " IF QRS-duration is PM and QTR-interval is PS and Ratio RR is PB and Area R ST is PM THEN Heart beat case is NORM"
I need to use min operation for combine each variable, and finally I will obtain relation between input and output.
%%%%%%%%%%%%%%%%%%%%%%______________________________%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%The membership function of the input variable%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%The Fuzzy Set of QRS Duration%%%%%%%%%%%%%%%%
x1=0:250;
%%%%%%Positive Small Set%%%%%%
for i=1:length(x1)
if (x1(i)>34) && (x1(i)<=54.3)
PS(i)=((x1(i)-34.0)/(54.3-34.0));
elseif (x1(i)>54.3) && (x1(i)<=61.0)
PS(i)=((61.0-x1(i))/(61.0-54.3));
else
PS(i)=0;
end
end
plot(x1,PS);
%%%%%%Positive Median Set%%%%%%
for i=1:length(x1)
if (x1(i)>33)&&(x1(i)<=55)
PM(i)=(x1(i)-33)/(55-33);
elseif (x1(i)>55)&&(x1(i)<=79)
PM(i)=(79-x1(i))/(79-55);
else
PM(i)=0;
end
end
hold on;
plot(x1,PM,'r');
%%%%%%Positive Big Set%%%%%%
for i=1:length(x1)
if x1(i)>46 && x1(i)<=74.6
PB(i)=(x1(i)-46)/(74.6-46.0);
elseif x1(i)>74.6 && x1(i)<=130
PB(i)=(130-x1(i))/(130-74.6);
else
PB(i)=0;
end
end
hold on;
plot(x1,PB,'g');
%%%%%%Positive Very-Big Set%%%%%%
for i=1:length(x1)
if x1(i)>52&& x1(i)<=120.4
PV(i)=(x1(i)-52)/(120.4-52);
elseif x1(i)>120.4 && x1(i)<=210
PV(i)=(210-x1(i))/(210-120.4);
else
PV(i)=0;
end
end
hold on;
plot(x1,PV,'m');
%%%%%%Positive Enormous Set%%%%%%
for i=1:length(x1)
if x1(i)>86&& x1(i)<=109.2
PE(i)=(x1(i)-86)/(109.2-86);
elseif x1(i)>109.2 && x1(i)<=153
PE(i)=(153-x1(i))/(153-109.2);
else
PE(i)=0;
end
end
hold on;
plot(x1,PE,'c');
xlabel('Feature Value (mV)');
ylabel('Degree of Membership');
title('QRS Duration');
legend('PS','PM','PB','PV','PE');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%The Fuzzy Set of QTP Interval%%%%%%%%%%%%%%%%
x2=0:500;
%%%%%%Positive Small Set%%%%%%
for i=1:length(x2)
if (x2(i)>43) && (x2(i)<=73)
PS2(i)=((x2(i)-43)/(73-43.0));
elseif (x2(i)>73) && (x2(i)<=90.0)
PS2(i)=((90-x2(i))/(90-73));
else
PS2(i)=0;
end
end
figure;
plot(x2,PS2);
%%%%%%Positive Median Set%%%%%%
for i=1:length(x2)
if (x2(i)>52.5) && (x2(i)<=90)
PM2(i)=((x2(i)-52.5)/(90-52.5));
elseif (x2(i)>90) && (x2(i)<=112.5)
PM2(i)=((112.5-x2(i))/(112.5-90));
else
PM2(i)=0;
end
end
hold on;
plot(x2,PM2,'r');
%%%%%%Positive Big Set%%%%%%
for i=1:length(x2)
if (x2(i)>97.5) && (x2(i)<=143)
PB2(i)=((x2(i)-97.5)/(143-97.5));
elseif (x2(i)>143) && (x2(i)<=212)
PB2(i)=((212-x2(i))/(212-143));
else
PB2(i)=0;
end
end
hold on;
plot(x2,PB2,'g');
%%%%%%Positive Very-Big Set%%%%%%
for i=1:length(x2)
if (x2(i)>120) && (x2(i)<=294)
PV2(i)=((x2(i)-120)/(294-120));
elseif (x2(i)>294) && (x2(i)<=482)
PV2(i)=((482-x2(i))/(482-294));
else
PV2(i)=0;
end
end
hold on;
plot(x2,PV2,'m');
%%%%%%Positive Enormous Set%%%%%%
for i=1:length(x2)
if (x2(i)>135) && (x2(i)<=172.5)
PE2(i)=((x2(i)-135)/(172.5-135));
elseif (x2(i)>172.5) && (x2(i)<=233)
PE2(i)=((233-x2(i))/(233-172.5));
else
PE2(i)=0;
end
end
hold on;
plot(x2,PE2,'c');
xlabel('Feature Value (ms)');
ylabel('Degree of Membership');
title('QTR Interval');
legend('PS','PM','PB','PV','PE');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% Ratio R-R%%%%%%%%%%%%%%%%
x3=0:160;
%%%%%%Positive Small Set%%%%%%
for i=1:length(x3)
xa=x3/100;
if (xa(i)>0.440) && (xa(i)<=0.640)
PS3(i)=((xa(i)-0.440)/(0.640-0.440));
elseif (xa(i)>0.640) && (xa(i)<=0.760)
PS3(i)=((0.760-xa(i))/((0.760-0.640)));
else
PS3(i)=0;
end
end
figure;
plot(x3/100,PS3);
%%%%%%Positive Median Set%%%%%%
for i=1:length(x3)
xa=x3/100;
if (xa(i)>0.400) && (xa(i)<=0.690)
PM3(i)=((xa(i)-0.400)/(0.690-0.400));
elseif (xa(i)>0.690) && (xa(i)<=0.760)
PM3(i)=((0.760-xa(i))/((0.760-0.690)));
else
PM3(i)=0;
end
end
hold on;
plot(x3/100,PM3,'r');
%%%%%%Positive Big Set%%%%%%
for i=1:length(x3)
xa=x3/100;
if (xa(i)>0.800) && (xa(i)<=0.990)
PB3(i)=((xa(i)-0.800)/(0.990-0.800));
elseif (xa(i)>0.990) && (xa(i)<=1.200)
PB3(i)=((1.200-xa(i))/((1.200-0.990)));
else
PB3(i)=0;
end
end
hold on;
plot(x3/100,PB3,'g');
%%%%%%Positive Very-Big Set%%%%%%
for i=1:length(x3)
xa=x3/100;
if (xa(i)>0.77) && (xa(i)<=1.02)
PV3(i)=((xa(i)-0.77)/(1.02-0.77));
elseif (xa(i)>1.02) && (xa(i)<=1.500)
PV3(i)=((1.500-xa(i))/((1.500-1.02)));
else
PV3(i)=0;
end
end
hold on;
plot(x3/100,PV3,'m');
%%%%%%Positive Enormous Set%%%%%%
for i=1:length(x3)
xa=x3/100;
if (xa(i)>0.840) && (xa(i)<=1.010)
PE3(i)=((xa(i)-0.840)/(1.010-0.840));
elseif (xa(i)>1.010) && (xa(i)<=1.300)
PE3(i)=((1.300-xa(i))/((1.300-1.010)));
else
PE3(i)=0;
end
end
hold on;
plot(x3/100,PE3,'c');
xlabel('Feature Value ');
ylabel('Degree of Membership');
title('Ration R-R');
legend('PS','PM','PB','PV','PE');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% Area -R'ST'%%%%%%%%%%%%%%%%
x4=0:300;
%%%%%%Positive Small Set%%%%%%
for i=1:length(x4)
if (x4(i)>0) && (x4(i)<=8)
PS4(i)=((x4(i)-0)/(8-0));
elseif (x4(i)>8) && (x4(i)<=155)
PS4(i)=((155-x1(i))/(155-8));
else
PS4(i)=0;
end
end
figure;
plot(x4,PS4);
%%%%%%Positive Median Set%%%%%%
for i=1:length(x4)
if (x4(i)>0) && (x4(i)<=10)
PM4(i)=((x4(i)-0)/(10));
elseif (x4(i)>10) && (x4(i)<=24.50)
PM4(i)=((24.50-x4(i))/(24.50-10));
else
PM4(i)=0;
end
end
hold on;
plot(x4,PM4,'r');
%%%%%%Positive Big Set%%%%%%
for i=1:length(x4)
if (x4(i)>18) && (x4(i)<=25)
PB4(i)=((x4(i)-18)/(25-18));
elseif (x4(i)>25) && (x4(i)<=34)
PB4(i)=((34-x4(i))/(34-25));
else
PB4(i)=0;
end
end
hold on;
plot(x4,PB4,'g');
%%%%%%Positive Very-Big Set%%%%%%
for i=1:length(x4)
if (x4(i)>0) && (x4(i)<=150)
PV4(i)=((x4(i)-0)/(150-0));
elseif (x4(i)>150) && (x4(i)<=265)
PV4(i)=((265-x4(i))/(265-150));
else
PV4(i)=0;
end
end
hold on;
plot(x4,PV4,'m');
%%%%%%Positive Enormous Set%%%%%%
for i=1:length(x4)
if (x4(i)>32) && (x4(i)<=55)
PE4(i)=((x4(i)-32)/(55-32));
elseif (x4(i)>55) && (x4(i)<=88)
PE4(i)=((88-x4(i))/(88-55));
else
PE4(i)=0;
end
end
hold on;
plot(x4,PE4,'c');
xlabel('Feature Value mVxms');
ylabel('Degree of Membership');
title('Area-R ST');
legend('PS','PM','PB','PV','PE');
%%%%%%%%%%%%%%%%%%%%%%______________________________%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%The membership function of the output variable%%%%%%%%%%%%%%%%
x5=0:12;
for i=1:length(x5)
if x5(i)==2
NORM(i)=1;
elseif x5(i)~= 2
NORM(i)=0;
else
NORM(i)=0;
end
end
figure;
plot(x5,NORM);
for i=1:length(x5)
if x5(i)==4
LBBB(i)=1;
elseif x5(i)~= 4
LBBB(i)=0;
else
LBBB(i)=0;
end
end
hold on;
plot(x5,LBBB,'r');
for i=1:length(x5)
if x5(i)==6
RBBB(i)=1;
elseif x5(i)~=6
RBBB(i)=0;
else
RBBB(i)=0;
end
end
hold on;
plot(x5,RBBB,'r');
for i=1:length(x5)
if x5(i)==8
VPC(i)=1;
elseif x5(i)~=8
VPC(i)=0;
else
VPC(i)=0;
end
end
hold on;
plot(x5,VPC,'g');
for i=1:length(x5)
if x5(i)==10
APC(i)=1;
elseif x5(i)~=10
APC(i)=0;
else
APC(i)=0;
end
end
hold on;
plot(x5,APC,'m');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Salaheddin Hosseinzadeh on 9 May 2015
Edited: Salaheddin Hosseinzadeh on 9 May 2015
Great now I can read something. I see you're writing a code from ground zero and defined a lot of membership functions, which seem that they all have the same length. good job.
Is your problem on how to apply fuzzy max min (intersection and union) to the membership functions and you're looking for a easy way?
if so, then
make the membership functions as columns, so the size will be n x 1 then you can easily use max and min command.
max(mf1,mf2); % this gives u the union if i'm right ;)
To form the consequent you can make can to the same thing, and max or min it with the consequent mf.
Please let me know if this helps.
Good luck!
##### 2 CommentsShow 1 older commentHide 1 older comment
KoolMU on 14 May 2015
Thanks for your advice, it can use to find relation between two membership functions.