import math
#Varaible Declaration
EIRP=55 #EIRP for satellite(dBW)
fD=12.5 #Downlink frequency(GHz)
Pss=-101 #Receiving at ground station direction(degrees west)
Rb=40*10**6 #Transmission Rate(Hz)
D=18 #Diameter of antenna(inches)
n=0.55 #Efficiency of antenna
Tant=70 #Antenna noise(Kelvin)
Teq=100 #Equivalent noise temperature at LNA(Kelvin)
R=6371 #Radius of earth(Km)
L=2 #Transmission losses(dB)
aGSO=42164 #Circumference of earth(km)
k=-228.6 #Boltzmann's constant (dB)
PE=-90 #Longitude of Earth station(degrees west)
LE=45 #Latitude of Earth station(degrees north)
f=14 #Frequency(GHz)
#Calculation
B=PE-Pss
b=math.acos(math.cos(B*3.142/180)*math.cos(LE*3.142/180))
b=b*180/3.142
A=math.asin(math.sin(abs(B)*3.142/180)/math.sin(b*3.142/180))
A=A*180/3.142
Az=180+A #Azimuth angle of antenna(degrees)
d=(R**2+aGSO**2-2*R*aGSO*math.cos(b*3.142/180))**0.5 #Range of antenna(km)
El=math.acos(aGSO*math.sin(b*3.142/180)/d) #Elevation angle of antenna(radians)
El=El*180/3.142 #Elevation angle of antenna(degrees)
Az=round(Az,1)
El=round(El)
d=round(d)
FSL=32.4+20*math.log10(d)+20*math.log10(f*10**3) #Free space loss(dB)
LOSSES=FSL+L #Total Transmission Losses
Ts=Teq+Tant #Total system noise temperature(Kelvin)
T=10*math.log10(Ts) #Total system noise temperature(dBK)
G=n*(3.192*f*(D/float(12)))**2
G=10*math.log10(G) #Antenna Gain(dB)
GTR=G-T #G/T ratio(dB)
CNR=EIRP+GTR-LOSSES-k #Carrier to noise ratio(dB)
Rb=10*math.log10(Rb) #Transmission Rate(dBHz)
EbN0R=CNR-Rb #Eb/N0 ratio at IRD(dB)
EbN0R=round(EbN0R,1)
#Results
print "The Azimuth angle of antenna is",Az,"degrees"
print "The Elevaation Angle of Antenna is",El,"degrees"
print "The Range of Antenna is",d,"km"
print "The Eb/N0 ratio at IRD is",EbN0R,"dB"
import math
#Varaible Declaration
R01=42 #Rainfall at earth station(mm/hr)
p=0.01 #Percentage of time for which rain exceeds
LE=45 #Latitue of earth station(degrees)
hR=3.5 #Rain Height(km)
h0=0 #Mean Sea level(km)
Ta=272 #
El=37 #Elevation angle of the antenna(degrees)
Ts=170 #Total system noise temperature(Kelvin)
NCR=2.3*10**-9 #Carrier to noise ratio
fD=12.5 #Frequency of operation(GHz)
f12=12 #Frequency 12GHz(GHz)
f15=15 #Frequency 15GHz(GHz)
#Coefficients for horizontal and vertical polarizations at 12GHz and 15GHz as given in Table 4.2
ah12=0.0188
av12=0.0168
bh12=1.217
bv12=1.2
ah15=0.0367
av15=0.0335
bh15=1.154
bv15=1.128
#Calculation
#Using Interpolation to find coefficients at 12.5 GHz
ah=round(ah12+(ah15-ah12)*(fD-f12)/(f15-f12),3)
bh=round(bh12+(bh15-bh12)*(fD-f12)/(f15-f12),3)
av=round(av12+(av15-av12)*(fD-f12)/(f15-f12),3)
bv=round(bv12+(bv15-bv12)*(fD-f12)/(f15-f12),3)
#Coefficients for circular polarization
ac=(ah+av)/2
ac=round(ac,3)
bc=(ah*bh+av*bv)/(2*ac)
bc=round(bc,3)
Ls1=(hR-h0)/math.sin(El*3.142/180) #Slant Path Length(km)
Ls=round(Ls1,1) #Slant Path Length(km)
LG=round(Ls*math.cos(El*3.142/180),1) #Horizontal projection of slant path length(km)
r011=90/(90+4*LG) #Reduction Factor
r01=round(r011,1) #Reduction Factor
L=round(Ls1*r01,1) #Effective path length(km)
alpha=round(ac*R01**bc,3) #Specific attenuation(dB/km)
A=round(10**(alpha*L/float(10)),1) #Total Attenuation(dB)
Trn=Ta*(1-1/A) #noise temperature with effect of rain
Tscs=Ts
NCrain=NCR*(A+(A-1)*Ta/Tscs) #Noise to carrier ratio due to rain
CNrain=-10*math.log10(NCrain)#Noise to carrier ratio due to rain(dB)
Rb=10*math.log10(40*10**6) #Transmission rate(dB)
EbN0rain=round(CNrain-Rb,1) #Upper limit of Eb/N0 ratio in prescence of rain(dB)
#Result
print "Hence the upper limit for Eb/N0 for given conditions is",EbN0rain,"dB"