function [modelB, RR, testB] = regionsB( param )


% estimate indoor areas
load('Cell_Info');

testB = Cell_Info_B;
modelB = Cell_Info_G;
% calculate power received regions (8 total)
for i = 1:203
    for j = 1:203
        if Cell_Info_B.ReceivedPowerMap(i,j) == 0
            testB.ReceivedPowerMap(i,j) = 0;
        elseif Cell_Info_B.ReceivedPowerMap(i,j) < -90
            testB.ReceivedPowerMap(i,j) = 1;
        elseif Cell_Info_B.ReceivedPowerMap(i,j) < -88
            testB.ReceivedPowerMap(i,j) = 2;
        elseif Cell_Info_B.ReceivedPowerMap(i,j) < -85
            testB.ReceivedPowerMap(i,j) = 3;
        elseif Cell_Info_B.ReceivedPowerMap(i,j) < -80
            testB.ReceivedPowerMap(i,j) = 4;
        elseif Cell_Info_B.ReceivedPowerMap(i,j) < -75
            testB.ReceivedPowerMap(i,j) = 5;
        elseif Cell_Info_B.ReceivedPowerMap(i,j) < -60
            testB.ReceivedPowerMap(i,j) = 6;
        elseif Cell_Info_B.ReceivedPowerMap(i,j) < -55
            testB.ReceivedPowerMap(i,j) = 7;
        else
            testB.ReceivedPowerMap(i,j) = 8;
        end
    end
end

RR = zeros(203, 203); na = zeros(1,3); nb = zeros(1,3); n = zeros(1,3);

% calculate directionality regions (4 total)
for i = 1:203
    for j = 1:203
        R = sqrt((101-i)^2 + (101-j)^2)*10;
        if R == 0
            R = 5;
        end
        PL = modelB.erp - Cell_Info_B.ReceivedPowerMap(i,j) + 20*log10((3*10^8/(850*10^6))/(4*pi));
        ang = atan2(i-101,j-101)*180/pi;
        if ang < 0
            ang = ang + 360;
        end

        % region 1: +/- 58 degrees from azimuth
        if 150 <= ang && ang <= 266     %G
        %if (270 <= ang && ang <= 360) || (ang <= 26 && ang >= 0)    %F
        %if 34 <= ang && ang <= 146     %B
            if Cell_Info_B.ReceivedPowerMap(i,j) ~= 0
                na(1) = na(1) + PL*10*log10(R);
                nb(1) = nb(1) + (10*log10(R))^2;
            end
            RR(i,j) = 1;

        % region 2: +30 degrees from region 1
        elseif  120 < ang && ang < 150    %G
        %elseif  26 < ang && ang < 56    %F
        %elseif   4 < ang && ang <  34   %B
            if Cell_Info_B.ReceivedPowerMap(i,j) ~= 0
                na(2) = na(2) + PL*10*log10(R);
                nb(2) = nb(2) + (10*log10(R))^2;
            end
            RR(i,j) = 2;

        % region 2: -30 degrees from region 1
        elseif  266 < ang && ang < 296     %G
        %elseif  240 < ang && ang < 270     %F
        %elseif  146 < ang && ang < 176     %B
            if Cell_Info_B.ReceivedPowerMap(i,j) ~= 0
                na(2) = na(2) + PL*10*log10(R);
                nb(2) = nb(2) + (10*log10(R))^2;
            end
            RR(i,j) = 2;

        % region 3: other portion of map
        else
            if Cell_Info_B.ReceivedPowerMap(i,j) ~= 0
                na(3) = na(3) + PL*10*log10(R);
                nb(3) = nb(3) + (10*log10(R))^2;
            end
            RR(i,j) = 3;
        end
    end
end

for i = 1:203
    for j = 1:203
        R = sqrt((101-i)^2 + (101-j)^2)*10;
        if RR(i,j) == 1
            if testB.ReceivedPowerMap(i,j) > 6
                testB.ReceivedPowerMap(i,j) = testB.ReceivedPowerMap(i,j) + 2;
            elseif testB.ReceivedPowerMap(i,j) > 0
                testB.ReceivedPowerMap(i,j) = testB.ReceivedPowerMap(i,j) + 1;
            end
        elseif RR(i,j) == 2
            if testB.ReceivedPowerMap(i,j) > 6
                testB.ReceivedPowerMap(i,j) = testB.ReceivedPowerMap(i,j) + 1;
            end
        else
            if testB.ReceivedPowerMap(i,j) > 4
                testB.ReceivedPowerMap(i,j) = testB.ReceivedPowerMap(i,j) - 1;
            end
        end
    end
end


n = na ./ nb;
% calculate path loss and apply it to map
for i = 1:203
    for j = 1:203
        R = sqrt((101-i)^2 + (101-j)^2)*10;
        region = testB.ReceivedPowerMap(i,j);
        if R ~= 0
            if RR(i,j) == 1
                if region == 1
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) + 15;
                elseif region == 2
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R)  + 3;
                elseif region == 3
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R)  + 3;
                elseif region == 4
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 3;
                elseif region == 5
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 8;
                elseif region == 6
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 14;
                elseif region == 7
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 26;
                else
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 35;
                end

                if testB.ReceivedPowerMap(i,j) ~= 0
                    modelB.ReceivedPowerMap(i,j) = modelB.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - PL+ 206.5; %243
                else
                    modelB.ReceivedPowerMap(i,j) = modelB.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - 10*n(1)*log10(R);
                end
              
            elseif RR(i,j) == 2
                if region == 1
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) + 12;
                elseif region == 2
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) + 2;
                elseif region == 3
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 0;
                elseif region == 4
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 2;
                elseif region == 5
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 4;
                elseif region == 6
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 12;
                elseif region == 7
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 18;
                else
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 20;
                end

                if testB.ReceivedPowerMap(i,j) ~= 0
                    modelB.ReceivedPowerMap(i,j) = modelB.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - PL+ 210.5; %245
                else
                    modelB.ReceivedPowerMap(i,j) = modelB.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - 10*n(2)*log10(R);
                end

            elseif RR(i,j) == 3
                if region == 1
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) + 11;
                elseif region == 2
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) + 4;
                elseif region == 3
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) + 1;
                elseif region == 4
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 0;
                elseif region == 5
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 3;
                elseif region == 6
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 5;
                elseif region == 7
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 16;
                else
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(220)+(44.9-6.55*log(220))*log10(R) - 19;
                end

                if R < 50
                    PL = PL + 10;
                end

                if testB.ReceivedPowerMap(i,j) ~= 0
                    modelB.ReceivedPowerMap(i,j) = modelB.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - PL+ 210.5; %245
                else
                    modelB.ReceivedPowerMap(i,j) = modelB.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - 10*n(3)*log10(R);
                end

            end
        end
    end
end

save PREDF.mat modelB
save actualB.mat Cell_Info_B;
Cell_Info_B = modelB;
save modelB.mat Cell_Info_B;

CompareMaps('actualB', 'modelB')