% Skywave.m
% Cambridge to Lerwick is approximately 890km (greate circle distance).
% Bottom of E-layer 90-150km  

clear all;
close all;

graphics_toolkit("gnuplot");
%graphics_toolkit("qt");   % This doesn't seem to render properly every time.
%graphics_toolkit("fltk");

R = 6371;   % Earth's radius [km]
h = 483;    % Virtual height of ionosphere [km]

d = 20:1:10000;  % Distance over the earth's surface.

% The angle of radiation necessary to achieve the skip distance d when the
% virtual height of the ionosphere is h.
theta = d/R;
radiationAngle = atan( (h + R*(1 - cos(theta/2))) ./ (R*sin(theta/2)) ) - theta/2;
% Or if you want to get fancier: 
%radiationAngle = atan( (1 + h/R)*csc(theta/2) - cot(theta/2)) - theta/2;


% Remove angles less than 0 rads.
radiationAngle(radiationAngle < 0) = [];

% Zero angle distance check.
maxDistance = 2*R*acos(R/(R + h));

figure;
semilogx(d(1:length(radiationAngle)), radiationAngle*180/pi);
grid;
legend(sprintf('h = %d km', h));
xlabel('skip distance [km]');
ylabel('angle of radiation [deg]');
title('Single hop skywave propagation');

figure;
semilogx(d(1:length(radiationAngle))/1.609, radiationAngle*180/pi);
grid;
legend(sprintf('h = %0.1f miles', h/1.609));
xlabel('skip distance [miles]');
ylabel('angle of radiation [deg]');
title('Single hop skywave propagation');


