(* To load this package, type "<< /usr/mcm/src/lri/budget.m" at the
   Mathematica command line. To find the value of a variable, for a given
   assignment of values to variables, type "N[<var>/.<subs>]", e.g. to
   find the link margin for the substitutions in subs11M, type
   "N[M/.subs11M]".
*)


(* Transmitter Losses (Lt):
          Pointing loss: 1 dB
      Bandlimiting loss: 1 dB
   Antenna circuit loss: 1 dB
   
   Path Losses (Lp):
           Ionospheric loss: 0.1 dB
    Atmospheric Attenuation: 0.3 dB
           Rain Attenuation: 1.0 dB (Based on 99.5% availability at worst
	                            DSN site, Canberra, Australia, for
				    8.45 GHz. 0.601 dB, rounded up)
   Waveform distortion loss: 0.2 dB

   Receiver Losses (Lr):
    Demod/Detector loss: 0.2 dB
      Polarization loss: 0.2 dB
          Pointing loss: 0.2 dB
   Antenna circuit loss: 0.5 dB
           Phase jitter: 0.2 dB
     Receiver feed loss: 0.1 dB
*)

(* Pt = Transmitter output power (W)
   freq = carrier frequency (Hz)
   lambda = carrier wavelength (m)
   theta0Max = Maximum electronically pointed angle (degrees)
   Dt = Diameter of (circular) phased array transmitter (m)
   At = Area of transmitter (m^2)
   etat = efficiency of transmitting antenna (dimensionless)
   Lt = Transmitter Losses
   Gt = Gain of transmitter
   HPBW = Half Power Beam Width (degrees)
   factor = holds an intermediate result
   dx = Horizontal spacing of elements in phased array (m)
   dy = Vertical spacing of elements in phased array (m)
   NumElements = Approx. number of elements in phased array
   EIRP = Effective Isotropic Radiated Power (W)
   Ls = So called space Loss
   Lp = Path Losses
   Lr = Receiver Losses
   etar = efficiency of receiving antenna (dimensionless)
   Dr = Diameter of (parabolic) receiving antenna (m)
   Gr = Gain of receiving antenna (dimensionless)
   Flux = Flux density on Earth (W/m^2)
   Pr = Received power (W)
   Te = Equivalent noise temperature (K)
   R = Modulated data rate (bits/sec)
   EbN0 = Signal per bit / single sided noise density  (Eb/N0) (dB)
   EbN0Req = Required Eb/N0 (dB)
   M = Link Margin (dB)
*)   

subs11M = {Pt -> 12, freq -> 8.475 10^9, theta0Max -> 30., Dt -> 0.50,
        etat -> 0.7, LtdB -> 3, LpdB-> 1.6, LrdB -> 1.4,
	etar -> 0.55, Dr -> 11, Te -> 400, R -> 6 * 10^6, EbN0Req -> 6.5} ;

subs22M = {Pt -> 9, freq -> 8.475 10^9, theta0Max -> 30., Dt -> 0.5,
           etat -> 0.7, LtdB -> 3, LpdB-> 1.6, LrdB -> 1.4,
  	   etar -> 0.55, Dr -> 22, Te -> 400, R -> 6 * 10^6, EbN0Req -> 6.5} ;


TodB[x_] := 10. * Log[x] / Log[10.] ;
FromdB[xdB_] := 10^(xdB / 10) ;

PtdB = TodB[Pt] ;
lambda = 3 10^8 / freq ;
At = Pi * Dt * Dt / 4. ;
Gt = 4 * Pi * At / (lambda^2) * etat * Cos[theta0Max*Pi/180.] ;
GtdB = TodB[Gt] ;

HPBW = 58.5 * lambda / Dt ;
factor = 1/(1 + Sin[ (theta0Max + 1.5*HPBW) * Pi/180. ]) ;
dx = factor * lambda ;
dy = factor/Sqrt[3.] * lambda ;
NumElements = At / (2 * dx * dy) ;

EIRPdB = PtdB + GtdB - LtdB ;
EIRP = FromdB[EIRPdB] ;
Ls = (4 * Pi * 384000000. / lambda) ^ 2 ;
LsdB = TodB[Ls] ;
Ar = Pi * Dr^2 / 4 ;
Gr = 4 * Pi * Ar / lambda^2 * etar ;
GrdB = TodB[Gr] ;
PrdB = EIRPdB - LsdB - LtdB + GrdB ;
Pr = FromdB[PrdB] ;
FluxdB = PrdB - TodB[Ar] ;
Flux = FromdB[FluxdB] ;
TedB = TodB[Te] ;
RdB = TodB[R] ;
EbN0 = PrdB + 228.6 - TedB - RdB ;
M = EbN0 - EbN0Req ;
