%==========================================================================
%
%   Calculate the maximum distance for detecting a signal from ambassador
%   Hitler
%
%==========================================================================
%
%   James Nagel
%   Department of Metallurgical Engineering
%   University of Utah, Salt Lake City, Utah
%   james.nagel@utah.edu
%   Copyright November 12, 2016

clear all;

%  Constants 
mPerLY = 9.461e15;      %  Meters per light-year
kB     = 1.3806e-23;    %  Boltzmann's constant [m^2*kg/s^2/K]
c0     = 3e8;           %  Speed of light [m/s]

%  Antenna parameters
N  = 1;
A0 = (1e3)^3;           % Square-kilometer receiver [m^2]
Ae = A0;

% Define parameters and variables.
Pt  = 1e5;   	% Total transmitted power [W]
T   = 5e3;   	% Noise temperature [K]
BW  = 5e6;      % Bandwidth [Hz]
f   = 40e6;     % Carrier frequency [Hz]
L   = c0/f;     % Wavelength [m]
Gt  = 10;       % Transmit gain
SNR = 0.1;      % Signal to noise ratio

% Equivalent isotropic radiated power
EIRP = Pt*Gt;

% Calcualte noise power
Pn = BW*kB*T;

% Calculate received power
Pr = SNR*Pn;

% Calculate max distance to get attention
r = sqrt(EIRP*Ae/(4*pi*Pr));

% Convert distance to light-years
rLy = r/mPerLY;

% Convert distance to AUs
rAU = r/1.5e11;

% Channel capacity
C = BW*log2(1 + SNR);

str1 = ['Total received power: ' num2str(Pr) ' W'];
str2 = ['Total noise power: ' num2str(Pn) ' W'];
str3 = ['SNR: ' num2str(SNR)];
str4 = ['Channel Capacity : ' num2str(C) ' bps'];
str5 = ['Total distance : ' num2str(rAU) ' A.U.'];
disp(str1);
disp(str2);
disp(str3);
disp(str4);
disp(str5);




