%------------------------------------------------
% Path loss (attenuation) comparison tool
% ECE2305 
% D.R. Brown III
%------------------------------------------------
% USER PARAMETERS BELOW
%------------------------------------------------
dmin = 0.1e3;           % minimum distance (meters)
dmax = 100e3;           % maximum distance (meters)
fc = 2.4e9;             % center frequency (Hz)
ht = 2;                 % height of transmitter from ground (meters)
hr = 20;                % height of receiver from ground (meters)
Gt = 0;                 % transmitter antenna gain (dBi)
Gr = 0;                 % receiver antenna gain (dBi)
c = 3e8;                % propagation velocity (meters/second)
cable = 2;              % attenuation of a cable (dB per 100m)
%------------------------------------------------
% END OF USER PARAMETERS
%------------------------------------------------

lam = c/fc;
d = logspace(log10(dmin),log10(dmax),100);

L_freespace = 10*log10((4*pi*d/lam).^2)-Gt-Gr;
L_flatreflecting = 10*log10((4*pi*d).^2./(2*lam*sin(2*pi*ht*hr./(lam*d))).^2)-Gt-Gr;
L_flatreflectingapprox = 10*log10(d.^4/(ht*hr)^2)-Gt-Gr;
L_cable = cable*(d/100);
semilogx(d/1e3,L_freespace,d/1e3,L_flatreflecting,d/1e3,L_flatreflectingapprox,d/1e3,L_cable,'Linewidth',2);
xlabel('distance (km)')
ylabel('attenuation (dB)')
legend('free space','flat reflecting surface','flat reflecting surface approx',['cable (' num2str(cable) 'dB/100m)'],'Location','SouthEast');
grid on
axis([(dmin/1e3) (dmax/1e3) L_cable(1) L_flatreflectingapprox(end)]);

