from math import sqrt
#Given P-I-N Diode
q=0.6 #Quantam Efficiency
l=1.3*(10**-6) #Wavelength in Meters
i=3*(10**-9) #Reverse Bias Leakage Current in Ampere
r=50 #Resistance in Ohm
b=500*(10**6) #Bandwidth in Hertz
P=10*(10**-6) #Optical Power in Watt
e=1.6*(10**-19) #Charge of a Electron
h=6.6*(10**-34) #Plancks Constant
c=3*(10**8) #Speed Of Light
k=1.38*(10**-23) #Boltzmann Constant
c1=1*(10**-12) #Assumed Capacitance in Farad
ip=(q*P*e*l)/(h*c) #Where i is the Photogenerated current
print "The Photogenereated Current is %.2e A"%(ip)
itotal=sqrt(2*(i+ip)*e*b) #Where itotal is the Total Shot Noise Current using equation 9.11
print "The total shot noise Current is %.2e A"%(itotal)
ij=sqrt(4*k*r*b*300)/r #Where ij is the Total Johnson Noise Current using Equation 9.13
print "The Total Johnson Noise Current is "+str(ij)+" A"
sn=(ip**2)/((itotal**2)+(ij**2)) #Where sn is the Signal to Noise Ratio in Decibel
sn=round(sn,1)
print "The Required Signal to noise ratio is "+str(sn)
rl=1/(2*3.14*c1*b) #Where rl is the optimum Load Resistance
rl=round(rl,1)
print "The optimum Load Resistance "+str(rl)+" ohm"
ij2=sqrt(4*k*rl*b*300)/rl
print "The Optimum Johnson Noise Current is %.2e A"%(ij2)
sn1=(ip**2)/((itotal**2)+(ij2**2))
sn1=round(sn1,1)
print "The New Signal to noise Ratio is "+str(sn1)
print "The Transmitter Output is 0 Dbm"
print "The Receiver Sensitivity is -50 Dbm"
print "The Required Margin is 50 Dbm"
print "System Loss-"
print "Fiber Loss 2 Db/Km,15 Km 30 Db"
print "Detector Coupling Loss 1 Db"
print "Total Splicing Loss (0.5 DB x 10) 5 Db"
print "Headroom for Temperature range,ageing effects & Future Splices 5 Db"
print "Total Attenuation 41 Db"
f=30
d=1
t=5
h=5
t=f+d+t+h #The total power attenuation
p=50-t
print "The Excess Power Margin required is "+str(p)+" Db"
from math import sqrt
n1=2.286 #The Ordinary Refractive Index
d=6*(10**-3) #Refractive Index Change
n2=n1-d #The Difference of the Two
NA=sqrt((n1**2)-(n2**2))
first=1/(4*NA)
first=round(first,2)
second=3/(4*NA)
second=round(second,2)
print "The Requirement for Single Mode Behaviour becomes"
print str(first)+" <= d/lambda <= "+str(second) #Where d=5*Lambda for suitable thickness design
#The Higher Region is Miscalculated in the Book