%==========================================================================
%
%   How far can I reach if the aliens aren't necessasrily looking for me?
%
%==========================================================================
%
%   James Nagel
%   Department of Metallurgical Engineering
%   University of Utah, Salt Lake City, Utah
%   james.nagel@utah.edu
%   Copyright November 28, 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;                 % Number of antennas
A0 = 1e4;               % Effective area of single antenna [m^2]
Ae = N*A0;              % Net effective area [m^2] 
Ar = 10*Ae;             % Receive antenna area [m^2]

%  Define parameters and variables.
SNR = 1;       % Desired SNR at reciever
T   = 5e3;   	% Noise temperature [K]
Pt  = 10e6;   	% Total transmitted power [W]
BW  = 1e2;      % Bandwidth [Hz]
f   = 1.5e9;    % Carrier frequency [Hz]
L   = c0/f;     % Wavelength [m]

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

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

% Recieved power
Pr = SNR*Pn;

%  Equivalent isotropic radiated power
Gt   = 4*pi*Ae/L^2;     %  Transmit gain
EIRP = Pt*Gt;

% Solve for maximum distance
r = sqrt(EIRP*Ar/(4*pi*Pr));

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

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(rLy) ' ly'];
disp(str1);
disp(str2);
disp(str3);
disp(str4);
disp(str5);

