% Simulate HAta-Okumura Models %
clc
clear
%% Given Values %%
Hbts = 50;    
Tbts = 350;            %
Htav = 300;
Pt = 19.5;      %Transmitter power in watts
fc = 870;
Gt = 10;
hm = 3;      
d = 3:0.5:15;

%% Calculated Values %%
Ptdbm = 10*log10(Pt*1000);                              % Power delivered to BTS antenna converted to dBm
hb = Hbts + Tbts - Htav;                                % Effective antenna height
ahreA = hm*(1.1*log10(fc)-0.7) - (1.56*log10(470)-0.8); % a(hre) for suburban, small/medium & rural cities
ahreB = 3.2*(log10(11.57*hm))^2 - 4.97;                 % a(hre) for large cities
A = 69.55+26.16*log10(fc)-13.82*log10(hb);              % Variable A for path loss expression PL(db)
B = 44.9-6.55*log10(hb);                                % Variable B for path loss expression PL(db)
Cs =-2*(log10(fc/28))^2-5.4;                            % Variable C for path loss expression PL(db), suburban model
Cr = -4.78*(log10(fc))^2+18.33*log10(fc)-40.98;         % Variable C for path loss expression PL(db), rural model
PLdb = B*log10(d);                                      % Path loss expression
                                      
%% Hata Okumura Models %%
models = {'Small city';'Large city';'Suburban city'; 'Rural area'};
disp('Hata-Okumura models');
display(['1  :  ',models{1,1}])
display(['2  :  ',models{2,1}])
display(['3  :  ',models{3,1}])
display(['4  :  ',models{4,1}])

answer = input('Choose your Okumura Model :','s');
while str2double(answer) < 1 || str2double(answer) > 4
    display('Invalid Input')
    answer = input('Choose your Okumura Model :','s');
end
%  switch answer
%     case '1'
          PrdBmA = Ptdbm + Gt - (A + PLdb );                          %Received power for small city
          PathLoss1 = (A + PLdb );             
%          plot(d, PrdBmA, '-o')
%          hold on;
%          plot (d,PathLoss1, '-o')
%          hold off;
%          grid;legend ('Path loss', 'Received Power')
%          title('Small City')
%          xlabel({'Distance (Km)'})
%     case '2'
          PrdBmB = Ptdbm + Gt -((A - ahreB) + PLdb);                  %Received power for large city
          PathLoss2 = ((A - ahreB) + PLdb);
%          plot(d, PrdBmB, '-o')
%          hold on;
%          plot (d,PathLoss2, '-o')
%          hold off;
%          grid;legend ('Path loss', 'Received Power')
%          title('Large City')
%     case '3'
          PrdBmC = Ptdbm + Gt - ((A - ahreA) + (PLdb + Cs));          %Received power for suburban city
          PathLoss3 = ((A - ahreA) + (PLdb + Cs));
%          plot(d, PrdBmC, '-o')
%          hold on;
%          plot (d,PathLoss3, '-o')
%          hold off;
%          grid;legend ('Path loss', 'Received Power')
%          title('Suburban City')
%     case '4'
          PrdBmD = Ptdbm + Gt - ((A - ahreB) + (PLdb + Cr));          %Received power for rural area
          PathLoss4 = ((A - ahreB) + (PLdb + Cr));
%          plot(d, PrdBmD, '-o')
%          hold on;
%          plot (d,PathLoss4, '-o')
%          hold off;
%          grid;legend ('Path loss', 'Received Power')
%          title('Rural Area')
%  end 
%% Graph for Path Loss Models %%
plot (d,PathLoss1, '-o')
hold on;
plot (d,PathLoss2, '-o')
hold on;
plot (d,PathLoss3, '-o')
hold on;
plot (d,PathLoss4, '-o')
hold off;
title('Path Loss for Hata Okumura Models')
grid;legend ('Rural Area','Suburban City','Large City','Small City')
xlabel({'Distance (Km)'});
ylabel({'Path Loss'});

% %% Graph for Received Power Models %%
% plot (d,PrdBmA, '-o')
% hold on;
% plot (d,PrdBmB, '-o')
% hold on;
% plot (d,PrdBmC, '-o')
% hold on;
% plot (d,PrdBmD, '-o')
% hold off;
% title('Received Power for Hata Okumura Models')
% grid;legend ('Rural Area','Suburban City','Large City','Small City')
% xlabel({'Distance (Km)'});
% ylabel({'Received Power dBm'});





