% Max and min wavelengths (m)
lmin=300/(1413+200);
lmax=300/(1413-200);

% Plot distance from roof to ground
figure(1)
set(gca,'Fontsize',14);
H=7;
tt=(0:76)*pi/180;
plot(tt*180/pi,H./cos(tt))
hold on
grid on
plot(tt*180/pi,10./cos(tt),'--')
xlabel('Obervation angle (deg)')
ylabel('Distance to ground (m)')
     legend('H=7 m','H=10 m')
     axis([0 75 0 35])

% Far field for various size antennas
far1p2=2*(1.2)^2/lmin;
far1p5=2*(1.5)^2/lmin;
 
line([0 75],[far1p2 far1p2])
line([0 75],[far1p5 far1p5])
text(10, 17, 'Far field: 1.2 m Antenna','Fontsize',14)
text(10, 25.5, 'Far field: 1.5 m Antenna','Fontsize',14)

% Horizontal distance
figure(4)
set(gca,'Fontsize',14);
H=7;
tt=(0:76)*pi/180;
plot(tt*180/pi,H.*tan(tt))
hold on
grid on
plot(tt*180/pi,10.*tan(tt),'--')
xlabel('Obervation angle (deg)')
ylabel('X = Spot center distance along ground (m)')
     legend('H=7 m','H=10 m')
     axis([0 75 0 35])



% set D to 1.2 m based on far field test
D=1.2;

% Beam efficiency 80%
Q=0.8

% max 2 sided beamwidth
tpsi=lmax/D/Q;
psi=tpsi/2;

% Plot spot size versus observation angle at height 10 m
H=10;
figure(2)
set(gca,'Fontsize',14)
plot(tt*180/pi,H.*(tan(tt+psi)-tan(tt-psi)))
hold on
grid on
plot(tt*180/pi,2*H*tan(tt)*sin(psi),'--')
     xlabel('Observation angle (deg)')
     ylabel('Spot diameter (m)')
     legend('Along range','Cross range')
     axis([30 60 0 10])


% try D 1.5 m 
D=1.5;

% Beam efficiency 80%
Q=0.8

% max 2 sided beamwidth
tpsi=lmax/D/Q;
psi=tpsi/2;

% Plot spot size versus observation angle at height 10 m
H=10;
figure(3)
set(gca,'Fontsize',14)
plot(tt*180/pi,H.*(tan(tt+psi)-tan(tt-psi)))
hold on
grid on
plot(tt*180/pi,2*H*tan(tt)*sin(psi),'--')
     xlabel('Observation angle (deg)')
     ylabel('Spot diameter (m)')
     legend('Along range','Cross range')
     axis([30 60 0 10])

