import math
#Variable declaration
n1=1.5 #core refractive index
n=1.0 #refractive index of medium
#Calculation
r=((n1-n)/(n1+n))**2 #magnitude of the Fresnel reflection at the fiber–air interface
Loss=-10*math.log10(1-r) #loss in decibels at the single interface
Loss1=2*Loss #total loss
#Result
print'Total loss due to Fresnel reflection = %.2f dB'%Loss1 #loss due to fresnel resolution = 0.18X2 dB
import math
#Variable declaration
n1=1.5 #refractive index
y=5 #lateral offset of the fiber core axes in um
a=25 #radius in um
#Calculation
b=(16*n1**2)/(math.pi*(1+n1)**4)
c=math.acos(y*(2*a)**-1)
e=(y*a**-1)
f=math.sqrt(1-(y*(2*a)**-1)**2)
n=b*((2*c)-(e*f)) #coupling efficiency
Loss=-10*math.log10(n) #insertion loss
na=(math.pi**-1)*((2*c)-(e*f))
Loss1=-10*math.log10(na)
#Result
print'(a) Insertion loss = %.3f dB'%Loss
print'(b) Insertion loss = %.2f dB'%Loss1
import math
#Variable declaration
y=3 #lateral misalignment in um
a=25 #core radius in um
#Calculation
Lt=0.85*(y*a**-1) #misalignment loss for guided modes
n=1-Lt #coupling efficiency
Loss=-10*math.log10(n) #insertion loss
Lt1=0.75*(y*a**-1) #both guided and leaky modes
n1=1-Lt1 #coupling efficiency
Loss1=-10*math.log10(n1) #insertion loss
#Result
print'(a) Uniform illumination of all guided modes only = %.2f dB'%Loss
print'(b) Uniform illumination of all guided and leaky modes = %.2f dB'%Loss1
import math
#Variable declaration
NA=0.2 #numerical aperture
n1=1.48 #core refractive index
ang=(5*math.pi)/180 #angular misalignment (radians)
NA1=0.4 #numerical aperture
#Calculation
na=((16*(n1)**2)/((1+n1)**4))*(1-(ang/(math.pi*NA))) #angular coupling efficiency
Loss=-10*math.log10(na) #insertion loss
na1=((16*(n1)**2)/((1+n1)**4))*(1-(ang/(math.pi*NA1))) #angular coupling efficiency
Loss1=-10*math.log10(na1) #insertion loss
#Result
print'Insertion loss at a joint (NA = 0.2) = %.2f dB'%Loss
print'Insertion loss at a joint (NA = 0.4) = %.2f dB'%Loss1 #in textbook, value is not calculated
import math
#Variable declaration
V=2.4 #normalized frequency
a=4 #core radius in um
NA=0.1 #numerical aperture
n1=1.46 #core refractive index
y=1 #lateral misalignment in um
teta=math.pi/180 #angular misalignment in rad
#Calculation
w=a*(0.65+(1.62/V**1.5)+(2.88/V**6))/(2**0.5) #normalized spot size
Tl=2.17*(y/w)**2 #loss due to the lateral offset
Ta=2.17*((teta*w*n1*V)/(a*NA))**2 #loss due to angular misalignment
Tt=Tl+Ta #total insertion loss
#Result
print'Total insertion loss = %.2f dB'%Tt
import math
#Variable declaration
w01=5.6 #mode-field radius in um
w02=4.2 #mode-field radius in um
#Calculation
Loss=-10*math.log10(4*((w02/w01)+(w01/w02))**(-2)) #intrinsic loss
#Result
print'Intrinsic loss = %.2f dB'%Loss
import math
#Variable declaration
p1=60 #input port power
p2=0.004 #output port power
p3=26 #output port power
p4=27.5 #output port power
#Calculation
xloss=10*math.log10(p1/(p3+p4)) #Excess Loss
iloss1=10*math.log10(p1*p3**-1) #Insertion Loss at input
iloss2=10*math.log10(p1/p4) #Insertion Loss at output
cross=10*math.log10(p2/p1) #Crosstalk ratio
srat=((p3/(p3+p4))*100) #Split ratio
#Result
print'Excess Loss = %.1f dB'%xloss
print'Insertion Loss at input = %.2f dB'%iloss1
print'Insertion Loss at output = %.2f dB'%iloss2
print'Crosstalk ratio = %.1f dB'%cross
print'Split ratio = %.1f percent'%srat
import math
#Variable declaration
N=32 #total no of ports
pi=10**3 #optical power at input in micro-watt
pj=14 #optical power at input in micro-watt
#Calculation
sloss=10*math.log10(N) #splitting loss
xloss=10*math.log10(pi*(pj*N)**-1) #excess loss
tloss=sloss+xloss #total loss
iloss=10*math.log10(pi*pj**-1) #insertion loss
#Result
print'Total loss = %.2f dB'%tloss
print'Insertion loss = %.2f dB'%iloss
import math
#Variable declaration
p=16 #output ports
l=0.2 #excess loss with split ratio of 50%
l1=0.1 #splice loss
#Calculation
m=math.log(p)/math.log(2) #no of stages
xloss=(4*l)+(3*l1) #excess loss
sloss=10*math.log10(p) #split loss
iloss=sloss+xloss #insertion loss
#Result
print'Insertion loss = %.2f dB'%iloss
#Variable declaration
h=1.55*10**-6 #optical signal wavelength
N=1.46 #refractive index
#Calculation
v=h/(2*N) #grating period of the FBG
#Result
print'Grating period of FBG = %.2f um'%(v*10**6)