B1=[.8,.2];%The probablity of LOS in the first and second ball of the first layer respectively
B2=[1,0];%The probablity of LOS in the first and second ball of the second layer respectively
B3=[1,0];%The probablity of LOS in the first and second ball of the third layer respectively
%%%%%%%%%%the value of path loss in macro BSs
for i=1:n1;
AA1=[MACRO.DISTANCEMACRO];
if AA1(i)<=R11;
a1=rand;
if a1<B1(1,1);
MACRO(i).PATHLOSSMACRO=K.*AA1(1,i).*ALFAL;
MACRO(i).LOSMACRO=1; %%%%To show BSs are LOS OR NLOS .if BS was LOS in macro's cell in sub cell LOS write 1
MACRO(i).NLOSMACRO=0;
CL=CL+1; %to count the number od LOS BSs
MACRO(i).NUMFADINGMACRO=CL;
else
MACRO(i).PATHLOSSMACRO=K.*AA1(1,i).*ALFAN;
MACRO(i).NLOSMACRO=1; %%%%%%if BS was NLOS in macro's cell in sub cell NLOS write 1
MACRO(i).LOSMACRO=0;
CN=CN+1;%to count the number od nLOS BSs ;
MACRO(i).NUMFADINGMACRO=CN;
end
elseif R11<=AA1(i)<=R12;
a1=rand;
if a1<B1(1,2);
MACRO(i).PATHLOSSMACRO=K.*AA1(1,i).*ALFAL;
MACRO(i).LOSMACRO=1;
MACRO(i).NLOSMACRO=0;
CL=CL+1;
MACRO(i).NUMFADINGMACRO=CL;
else
MACRO(i).PATHLOSSMACRO=K.*AA1(1,i).*ALFAN;
MACRO(i).NLOSMACRO=1;
MACRO(i).LOSMACRO=0;
CN=CN+1;
MACRO(i).NUMFADINGMACRO=CN;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%the value of path loss in pico BSs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:n2;
AA2=[PICO.DISTANCEPICO];
if AA2(i)<=R21;
PICO(i).PATHLOSSPICO=K.*AA2(1,i).*ALFAL;
PICO(i).LOSPICO=1;
PICO(i).NLOSPICO=0;
CL=CL+1;
PICO(i).NUMFADINGPICO=CL;
elseif R21<=AA2(i)<=R22;
PICO(i).PATHLOSSPICO=K.*AA2(1,i).*ALFAN;
PICO(i).NLOSPICO=1;
PICO(i).LOSPICO=0;
CN=CN+1;
PICO(i).NUMFADINGPICO=CN;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%the value of path loss in femto BSs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:n3;
AA3=[FEMTO.DISTANCEFEMTO];
if AA3(i)<=R31;
FEMTO(i).PATHLOSSFEMTO=K.*AA3(1,i).*ALFAL;
FEMTO(i).LOSFEMTO=1;
FEMTO(i).NLOSFEMTO=0;
CL=CL+1;
FEMTO(i).NUMFADINGFEMTO=CL;
elseif R31<=AA3(i)<=R32;
FEMTO(i).PATHLOSSFEMTO=K.*AA3(1,i).*ALFAN;
FEMTO(i).NLOSFEMTO=1;
FEMTO(i).LOSFEMTO=0;
CN=CN+1;
FEMTO(i).NUMFADINGFEMTO=CN;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% The min of path loss in every layer
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A1=[MACRO.PATHLOSSMACRO];
MINPATHLOSSMACRO=min(A1);
A3=[MINPATHLOSSMACRO];
A2=[PICO.PATHLOSSPICO];
MINPATHLOSSPICO=min(A2);
A3=[FEMTO.PATHLOSSFEMTO];
MINPATHLOSSFEMTO=min(A3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% Cell Association
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:n1;
MACRO(i).CELLASSOCIATIONMACRO=G.*MACRO(i).POWERMACRO.*MACRO(i).BIASEMACRO/MACRO(i).PATHLOSSMACRO;
MACRO(i).MINCELLASSOCIATIONMACRO=G.*MACRO(i).POWERMACRO.*MACRO(i).BIASEMACRO/MINPATHLOSSMACRO;
end
for i=1:n2;
PICO(i).CELLASSOCIATIONPICO=G.*PICO(i).POWERPICO.*PICO(i).BIASEPICO/PICO(i).PATHLOSSPICO;
PICO(i).MINCELLASSOCIATIONPICO=G.*PICO(i).POWERPICO.*PICO(i).BIASEPICO/MINPATHLOSSPICO;
end
for i=1:n3;
FEMTO(i).CELLASSOCIATIONFEMTO=G.*FEMTO(i).POWERFEMTO.*FEMTO(i).BIASEFEMTO/FEMTO(i).PATHLOSSFEMTO;
FEMTO(i).MINCELLASSOCIATIONFEMTO=G.*FEMTO(i).POWERFEMTO.*FEMTO(i).BIASEFEMTO/MINPATHLOSSFEMTO;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%find the number of BS that typical user has associatede
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A1=[MACRO.CELLASSOCIATIONMACRO];
MAXCELLASSOCIATIONMACRO=max(A1);%%%%%find max value of cell association through the macro BSs
A1(A1<MAXCELLASSOCIATIONMACRO)=0;
INDICEMACRO=find(A1);%%%%%disclose the number of BS that has had max cell association through the macro BSs
A2=[PICO.CELLASSOCIATIONPICO];
MAXCELLASSOCIATIONPICO=max(A2);
A2(A2<MAXCELLASSOCIATIONPICO)=0;
INDICEPICO=find(A2);
A3=[FEMTO.CELLASSOCIATIONFEMTO];
MAXCELLASSOCIATIONFEMTO=max(A3);
A3(A3<MAXCELLASSOCIATIONFEMTO)=0;
INDICEFEMTO=find(A3);
%%%%%find max value of cell association through the macro BSs
MAXALL=[MAXCELLASSOCIATIONMACRO,MAXCELLASSOCIATIONPICO,MAXCELLASSOCIATIONFEMTO];
MAXASSOCIATION=max(MAXALL);
%%%%%%%%%%%%%%%%%%%%PRODUCE FGADING
FL=random('Gamma',NLOS,1/NLOS,1,CL);%%%%%produce fading GAMMA for LOS links
FN=random('Gamma',NNLOS,1/NNLOS,1,CN);%%%%%produce fading GAMMA for NLOS links
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%disclose the number of BS that has had max cell association through all BSs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if MAXASSOCIATION==MAXCELLASSOCIATIONMACRO;
CELLASSOCIATION=[1,INDICEMACRO] %%%%%the first column show the TYPE of BS(1=macro,2=pico,3=femto), and the second column show the number of BS
if MACRO(INDICEMACRO).LOSMACRO==1;
A=MACRO(INDICEMACRO).POWERMACRO.*G.*(1/MACRO(INDICEMACRO).PATHLOSSMACRO).*(MACRO(INDICEMACRO).LOSMACRO.*FL(MACRO(INDICEMACRO).NUMFADINGMACRO));
elseif MACRO(INDICEMACRO).NLOSMACRO==1;
A=MACRO(INDICEMACRO).POWERMACRO.*G.*(1/MACRO(INDICEMACRO).PATHLOSSMACRO).*(MACRO(INDICEMACRO).NLOSMACRO.*FN(MACRO(INDICEMACRO).NUMFADINGMACRO));
end
elseif MAXASSOCIATION==MAXCELLASSOCIATIONPICO;
CELLASSOCIATION=[2,INDICEPICO]
if PICO(INDICEPICO).LOSPICO==1;
A=PICO(INDICEMACRO).POWERPICO.*G.*(1/PICO(INDICEPICO).PATHLOSSPICO).*FL(PICO(INDICEPICO).NUMFADINGPICO);
elseif PICO(INDICEPICO).NLOSPICO==1;
A=PICO(INDICEMACRO).POWERPICO.*G.*(1/PICO(INDICEPICO).PATHLOSSPICO).*FN(PICO(INDICEPICO).NUMFADINGPICO);
end
elseif MAXASSOCIATION==MAXCELLASSOCIATIONFEMTO;
CELLASSOCIATION=[3,INDICEFEMTOO]
if FEMTO(INDICEFEMTO).LOSFEMTO==1;
FEMTO(i).FAIDINGFEMTO=FL;%%%%%TO INDICATE THE VALU OF Faiding IN EACH MACRO
A=FEMTOO(INDICEFEMTO).POWERFEMTO.*G.*(1/FEMTO(INDICEFEMTO).PATHLOSSFEMTO).*FL(FEMTO(INDICEFEMTO).NUMFADINGFEMTO);
elseif FEMTO(INDICEFEMTO).NLOSFEMTO==1;
FEMTO(i).FAIDINGFEMTO=FN;%%%%%TO INDICATE THE VALU OF Faiding IN EACH MACRO
A=FEMTOO(INDICEFEMTO).POWERFEMTO.*G.*(1/FEMTO(INDICEFEMTO).PATHLOSSFEMTO).*FN(FEMTO(INDICEFEMTO).NUMFADINGFEMTO);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%TO caculate the gain in each BSs%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PG=[(delta/(2*pi))^2,2*delta*(2*pi-delta)/(2*pi)^2,((2*pi-delta)/(2*pi))^2];%%%%matris the probablity of gain
PG1=PG(1,1);%%%%%to define bound
PG2=PG(1,1)+PG(1,2); %%%%%to define bound
for i=1:n1;%%%%%%%%TO caculate the gain for macro BSs
b=rand;
if b<PG1;
MACRO(i).GAINMACRO=M*M;
elseif PG1<=b<PG2;
MACRO(i).GAINMACRO=M*m;
elseif PG2<=b<=1;
MACRO(i).GAINMACRO=m*m;
end
end
for i=1:n2;%%%%%%%%TO caculate the gain of pico BSs
b=rand;
if b<PG1;
PICO(i).GAINPICO=M*M;
elseif PG1<=b<PG2;
PICO(i).GAINPICO=M*m;
elseif PG2<=b<=1;
PICO(i).GAINPICO=m*m;
end
end
for i=1:n3;%%%%%%%%TO caculate the gain for femto BSs
b=rand;
if b<PG1;
FEMTO(i).GAINFEMTO=M*M;
elseif PG1<=b<PG2;
FEMTO(i)