%==========================================================================
%
%   Calculate the channel capacity of an interstellar digital radio
%   communications link.
%
%==========================================================================
%
%   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 = 1e4; %(25/2)^2*pi;
Ae = N*A0;              % Net effective area [m^2]

%  Define parameters and variables.
Pt  = 1e6;   	% Total transmitted power [W]
rLY = 4.25;  	% Total distance [light-years]
T   = 3e0;   	% Noise temperature [K]
BW  = 10e3;      % Bandwidth [Hz]
f   = 10e9;     % Carrier frequency [Hz]
L   = c0/f;     % Wavelength [m]

%  Convert distance to meters
r = rLY*mPerLY;

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

%  Calculate received power
Pr = EIRP*Ae/(4*pi*r^2);

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

%  Signal to noise ratio
SNR = Pr/Pn;

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




