{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ch-7 : .Optical Fiber Connection : Connectors, Joints and Couplers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.1 Pg: 311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The fiber loss =0.13 db\n",
      "\n",
      " there is a similar loss at the other interface\n",
      "\n",
      " The total fiber loss =0.26 db\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "n1=1.46## core refractive index\n",
    "n=1## refractive index due to air\n",
    "r=((n1-n)/(n1+n))**2#\n",
    "r1=0.03## r take upto two decimal place\n",
    "l_s=-10*log(1-r1)/log(10)## fiber loss in db\n",
    "l_t=2*l_s## total loss in db\n",
    "print \"The fiber loss =%0.2f db\"%( l_s)#\n",
    "print \"\\n there is a similar loss at the other interface\"#\n",
    "print \"\\n The total fiber loss =%0.2f db\"%( l_t)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.2 Pg: 311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The coupling efficiency for multimode step index fiber =0.86\n",
      "\n",
      " The insertion loss for lateral misalignment =0.65 dB\n",
      "\n",
      " The coupling efficiency when there is no air gap =0.92\n",
      "\n",
      " The insertion loss for lateral misalignment when there is no air gap =0.34 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log,pi,acos\n",
    "from __future__ import division\n",
    "n1=1.46## core refractive index\n",
    "n=1## refractive index due to air\n",
    "a=25*10**-6## core radius in m\n",
    "y=3*10**-6## in m\n",
    "A=(y/a)*(1-(y/(2*a))**2)**0.5#\n",
    "B=acos(y/(2*a))#\n",
    "C=n1/n#\n",
    "M=(16*C**2)/(pi*(1+C)**4)#\n",
    "n_lat=M*(2*B-A)## coupling efficiency for multimode step index fiber\n",
    "L_lat=-10*log(n_lat)/log(10)## insertion loss for lateral misalignment\n",
    "n_lat1=(1/pi)*(2*B-A)## coupling efficiency when there is no air gap\n",
    "L_lat1=-10*log(n_lat1)/log(10)## insertion loss for lateral misalignment when there is no air gap\n",
    "print \"The coupling efficiency for multimode step index fiber =%0.2f\"%( n_lat)#\n",
    "print \"\\n The insertion loss for lateral misalignment =%0.2f dB\"%( L_lat)#\n",
    "print \"\\n The coupling efficiency when there is no air gap =%0.2f\"%( n_lat1)#\n",
    "print \"\\n The insertion loss for lateral misalignment when there is no air gap =%0.2f dB\"%( L_lat1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.3 Pg: 311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The total insertion loss =1.15 dB\n",
      "\n",
      " the answer is wrong in the textbook\n"
     ]
    }
   ],
   "source": [
    "from math import log,acos,pi,sqrt\n",
    "from __future__ import division\n",
    "n1=1.50## core refractive index\n",
    "n=1## refractive index due to air\n",
    "a=25*10**-6## core radius in m\n",
    "y=4*10**-6## in m\n",
    "A=(y/a)*(1-(y/(2*a))**2)**0.5#\n",
    "B=acos(y/(2*a))#\n",
    "C=n1/n#\n",
    "M=(16*C**2)/(pi*(1+C)**4)#\n",
    "n_lat=M*(2*B-A)## coupling efficiency for multimode step index fiber\n",
    "L_lat=-10*log(n_lat)/log(10)## insertion loss for lateral misalignment\n",
    "dx=4*(3.14/180)## angular misalignment in radian\n",
    "dl=0.02## relative index difference\n",
    "NA=n1*sqrt(2*dl)## numerical aperture\n",
    "n_ang=1-(0.069/(3.14*NA))## coupling efficiency due to angular misalignment\n",
    "L_ang=-10*log(n_ang)/log(10)## loss due to angular misalignment\n",
    "Lt=L_lat+L_ang## total insertion loss in dB\n",
    "print \"The total insertion loss =%0.2f dB\"%( Lt)#\n",
    "print \"\\n the answer is wrong in the textbook\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.4 Pg: 312"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The insertion loss when there is a smsll air gap =0.65 dB\n",
      "\n",
      " The insertion loss when the joint is indexed matched =0.34 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log,acos,pi,sqrt\n",
    "from __future__ import division\n",
    "n1=1.46## core refractive index\n",
    "n=1## refractive index due to air\n",
    "a=1## core radius in m\n",
    "y=0.12## lateral offset\n",
    "A=(y/a)*(1-(y/(2*a))**2)**0.5#\n",
    "B=acos(y/(2*a))#\n",
    "C=n1/n#\n",
    "M=(16*C**2)/(pi*(1+C)**4)#\n",
    "n_lat=M*(2*B-A)## coupling efficiency when there is a smsll air gap\n",
    "L_lat=-10*log(n_lat)/log(10)## insertion loss when there is a smsll air gap\n",
    "n_lat1=(1/pi)*(2*B-A)## coupling efficiency when the joint is indexed matched\n",
    "L_lat1=-10*log(n_lat1)/log(10)## insertion loss when the joint is indexed matched\n",
    "print \"The insertion loss when there is a smsll air gap =%0.2f dB\"%( L_lat)#\n",
    "print \"\\n The insertion loss when the joint is indexed matched =%0.2f dB\"%( L_lat1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.5 Pg: 313"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The total coupling efficiency in the frw direction =0.52\n",
      "\n",
      " The total loss at the joint in the frw direction =2.81 dB\n",
      "\n",
      " In the backward direction n_cd & n_a are all unity therefore there will be no loss in the backward direction of transmission of the signal \n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "d1=60*10**-6## core diameter of fiber 1 in m\n",
    "d2=50*10**-6## core diameter of fiber 1 in m\n",
    "NA1=0.25## numerical aerture of fiber 1\n",
    "NA2=0.22## numerical aerture of fiber 2\n",
    "a1=2.0## for fiber 1\n",
    "a2=1.9## for fiber 2\n",
    "n_cd=(d2/d1)**2#\n",
    "n_NA=(NA2/NA1)**2#\n",
    "n_a=(1+(2/a1))/(1+(2/a2))#\n",
    "n_t=n_cd*n_NA*n_a## total coupling efficiency\n",
    "Lt=-10*log(n_t)/log(10)## total loss at the joint in dB\n",
    "print \"The total coupling efficiency in the frw direction =%0.2f\"%( n_t)#\n",
    "print \"\\n The total loss at the joint in the frw direction =%0.2f dB\"%( Lt)#\n",
    "print \"\\n In the backward direction n_cd & n_a are all unity therefore there will be no loss in the backward direction of transmission of the signal \""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.6 Pg: 313"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The total loss at the joint in the frw direction =4.22 dB\n",
      "\n",
      " The total loss at the joint in the backward direction =0.22 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "d1=80*10**-6## core diameter of fiber 1 in m\n",
    "d2=60*10**-6## core diameter of fiber 1 in m\n",
    "NA1=0.25## numerical aerture of fiber 1\n",
    "NA2=0.20## numerical aerture of fiber 2\n",
    "a1=1.9## for fiber 1\n",
    "a2=2.1## for fiber 2\n",
    "n_cd=(d2/d1)**2#\n",
    "n_NA=(NA2/NA1)**2#\n",
    "n_a=(1+(2/a1))/(1+(2/a2))#\n",
    "n_t=n_cd*n_NA*n_a## total coupling efficiency in the frw direction\n",
    "Lt=-10*log(n_t)/log(10)## total loss at the joint in the frw direction in dB\n",
    "n_cd1=1#\n",
    "n_NA1=1#\n",
    "n_a1=(1+(2/a2))/(1+(2/a1))#\n",
    "n_t1=n_cd1*n_NA1*n_a1## total coupling efficiency in the backward direction\n",
    "Lt1=-10*log(n_t1)/log(10)## total loss at the joint in the backward direction in dB\n",
    "print \"The total loss at the joint in the frw direction =%0.2f dB\"%( Lt)#\n",
    "print \"\\n The total loss at the joint in the backward direction =%0.2f dB\"%( Lt1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.7 Pg: 314"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The insertion loss of the splice =0.35 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log,acos,pi\n",
    "from __future__ import division\n",
    "n1=1.5## core refractive index\n",
    "n=1.47## refractive index due to air\n",
    "a=1## core radius in m\n",
    "y=0.12## lateral offset\n",
    "A=(y/a)*(1-(y/(2*a))**2)**0.5#\n",
    "B=acos(y/(2*a))#\n",
    "C=n1/n#\n",
    "M=(16*C**2)/(pi*(1+C)**4)#\n",
    "n_lat=M*(2*B-A)## coupling efficiency of the splice\n",
    "L_lat=-10*log(n_lat)/log(10)## insertion loss of the splice\n",
    "print \"The insertion loss of the splice =%0.2f dB\"%( L_lat)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.8 Pg: 315"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The refractive index of the fiber core =1.51\n"
     ]
    }
   ],
   "source": [
    "from math import pi,sqrt\n",
    "from __future__ import division\n",
    "L_f=0.036#\n",
    "n_f=10**(-0.036)#\n",
    "# here we get a quadratic equation in n1 and on solving we get\n",
    "n1=(2.17+sqrt((-2.17)**2-4*1*1))/2## refractive index of the fiber core\n",
    "print \"The refractive index of the fiber core =%0.2f\"%( n1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.9 Pg: 315"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The numerical aperture =0.34\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "from __future__ import division\n",
    "n1=1.46## core refractive index\n",
    "n=4## refractive index due to air\n",
    "x=pi/180#\n",
    "A=(16*n1**2)/((1+n1)**4)#\n",
    "B=n*x#\n",
    "n_ang=10**(-0.06)## angular coupling efficiency\n",
    "NA=B/((pi)*(1-(n_ang/A)))## numerical aperture\n",
    "print \"The numerical aperture =%0.2f\"%( NA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.10 Pg: 316"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The insertion loss =0.81 dB\n",
      "\n",
      " The insertion loss,if we have both guided and leaky modes =0.71 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log,pi\n",
    "from __future__ import division\n",
    "y=5*10**-6## lateral misalignment in m\n",
    "a=25*10**-6## core diameter in m\n",
    "Lt=0.85*(y/a)## misalignment loss\n",
    "n_c=1-Lt## coupling efficiency\n",
    "L_i=-10*log(n_c)/log(10)## insertion loss in dB\n",
    "Lt1=0.75*(y/a)## misalignment loss if we have both guided and leaky modes\n",
    "n_c1=1-Lt1## coupling efficiency\n",
    "L_i1=-10*log(n_c1)/log(10)## insertion loss in dB if we have both guided and leaky modes\n",
    "print \"The insertion loss =%0.2f dB\"%( L_i)#\n",
    "print \"\\n The insertion loss,if we have both guided and leaky modes =%0.2f dB\"%( L_i1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.11 Pg: 316"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The inserion loss when NA=0.22 =0.94 dB\n",
      "\n",
      " The inserion loss when NA=0.32 =0.75 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log,pi\n",
    "from __future__ import division\n",
    "n1=1.5## core refractive index\n",
    "n=1## refractive index due to air\n",
    "x=5*pi/180#\n",
    "C=n1/n#\n",
    "A=(16*C**2)/((1+C)**4)#\n",
    "B=n*x#\n",
    "NA=0.22## numerical aperture\n",
    "n_ang=A*(1-(B/(pi*NA)))## angular coupling efficiency\n",
    "L_ang=-10*log(n_ang)/log(10)## inserion loss when NA=0.22\n",
    "NA1=0.32## numerical aperture\n",
    "n_ang1=A*(1-(B/(pi*NA1)))## angular coupling efficiency\n",
    "L_ang1=-10*log(n_ang1)/log(10)## inserion loss when NA=0.32\n",
    "print \"The inserion loss when NA=0.22 =%0.2f dB\"%( L_ang)#\n",
    "print \"\\n The inserion loss when NA=0.32 =%0.2f dB\"%( L_ang1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.12 Pg: 317"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The total insertion loss  =1.81 dB\n",
      "\n",
      " The answer is wrong in the textbook\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "from __future__ import division\n",
    "V=2.50## normalised frequency\n",
    "n1=1.5## core refractive index\n",
    "a=4.5*10**-6## core radius in m\n",
    "NA=0.2## numerical aperture\n",
    "y=3*10**-6## lateral misalignment in m\n",
    "w=a*((0.65+1.62*(V)**-1.5+2.88*(V)**-6)/2**0.5)## normalised spot size in m\n",
    "T1=2.17*(y/w)**2## Loss due to lateral offset in dB\n",
    "x=(pi/180)*w#\n",
    "Ta=2.17*((x*n1*V)/(a*NA))**2## loss due to angular misalignment in dB\n",
    "T=T1+Ta## total insertion loss in dB\n",
    "print \"The total insertion loss  =%0.2f dB\"%( T)#\n",
    "print \"\\n The answer is wrong in the textbook\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.13 Pg: 317"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Excess loss =1.10 dB\n",
      "\n",
      " The insertion loss port 1 to 3  =4.33 dB\n",
      "\n",
      " The insertion loss port 1 to 4  =3.90 dB\n",
      "\n",
      " The cross talk =-41.14 dB\n",
      "\n",
      " The split ratio =47.52 %\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "P1=65## optical power in uW\n",
    "P2=0.005## output power at port 2 in uW\n",
    "P3=24## output power at port 3 in uW\n",
    "P4=26.5## output power at port 4 in uW\n",
    "Le=10*log(P1/(P3+P4))/log(10)## Excess loss in dB\n",
    "Le1=10*log(P1/P3)/log(10)## insertion loss port 1 to 3 in dB\n",
    "Le2=10*log(P1/P4)/log(10)## insertion loss port 1 to 4 in dB\n",
    "ct=10*log(P2/P1)/log(10)## cross talk in dB\n",
    "sr=(P3/(P3+P4))*100## split ratio\n",
    "print \"The Excess loss =%0.2f dB\"%( Le)#\n",
    "print \"\\n The insertion loss port 1 to 3  =%0.2f dB\"%( Le1)#\n",
    "print \"\\n The insertion loss port 1 to 4  =%0.2f dB\"%( Le2)#\n",
    "print \"\\n The cross talk =%0.2f dB\"%( ct)#\n",
    "print \"\\n The split ratio =%0.2f %%\"%( sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.14 Pg: 318"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The total fresnel loss =0.33 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "n=1#\n",
    "n1=1.48#\n",
    "r=((n1-n)/(n1+n))**2## fresnel's reflection\n",
    "Ls=-10*log(1-r)/log(10)## optical loss in dB\n",
    "Lt=2*Ls## total fresnel loss\n",
    "print \"The total fresnel loss =%0.2f dB\"%( Lt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.15 Pg: 318"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The NA mismatch coupling loss =3.25 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "NA1=0.32## numerical aperture for fiber1\n",
    "NA2=0.22## numerical aperture for fiber2\n",
    "Lc=20*log(NA1/NA2)/log(10)## NA mismatch coupling loss\n",
    "print \"The NA mismatch coupling loss =%0.2f dB\"%( Lc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.16 Pg: 319"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The coupling ratio =46.67 %\n",
      "\n",
      " The Excess loss =2.22 dB\n",
      "\n",
      " The insertion loss port 0 to 1  =4.95 dB\n",
      "\n",
      " The insertion loss port 0 to 2 =5.53 dB\n",
      "\n",
      " The cross talk =-46.99 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "P0=250## optical power in uW\n",
    "P1=80## output power at port 1 in uW\n",
    "P2=70## output power at port 2 in uW\n",
    "P3=5*10**-3## output power at port 3 in uW\n",
    "cr=(P2/(P1+P2))*100## coupling ratio\n",
    "Le=10*log(P0/(P1+P2))/log(10)## Excess loss in dB\n",
    "Le1=10*log(P0/P1)/log(10)## insertion loss port 0 to 1 in dB\n",
    "Le2=10*log(P0/P2)/log(10)## insertion loss port 0 to 2 in dB\n",
    "ct=10*log(P3/P0)/log(10)## cross talk in dB\n",
    "print \"The coupling ratio =%0.2f %%\"%( cr)#\n",
    "print \"\\n The Excess loss =%0.2f dB\"%( Le)#\n",
    "print \"\\n The insertion loss port 0 to 1  =%0.2f dB\"%( Le1)#\n",
    "print \"\\n The insertion loss port 0 to 2 =%0.2f dB\"%( Le2)#\n",
    "print \"\\n The cross talk =%0.2f dB\"%( ct)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.17 Pg: 319"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The throughput loss =0.97 dB\n",
      "\n",
      " The tap loss =6.99 dB\n",
      "\n",
      " Directionality=-10*log(0/Pi=infinity)\n",
      "\n",
      " The excess loss =0 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "P_21=4/5## ratio of the input available at port2 \n",
    "P_31=1/5## ratio of the input available at port3 \n",
    "Lt=-10*log(P_21)/log(10)## throughput loss\n",
    "Lp=-10*log(P_31)/log(10)## tap loss\n",
    "Le=-10*log(P_21+P_31)/log(10)## excess loss\n",
    "print \"The throughput loss =%0.2f dB\"%( Lt)#\n",
    "print \"\\n The tap loss =%0.2f dB\"%( Lp)#\n",
    "print \"\\n Directionality=-10*log(0/Pi=infinity)\"#\n",
    "print \"\\n The excess loss =%d dB\"%( Le)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.18 Pg: 320"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The fraction of the input power goes to each of the ports =0.54 dB\n",
      "\n",
      " The throughput loss =2.71 dB\n",
      "\n",
      " The tap loss =8.73 dB\n",
      "\n",
      " The loss due to radiation scattering =1.74 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "Le=4## excess loss in dB\n",
    "D=60## Directionality in dB\n",
    "P_41=10**-6## the ratio of P4 to P1\n",
    "P_31=0.670/5## the ratio of P3 to P1\n",
    "P_21=P_31*4## the ratio of P2 to P1\n",
    "Lt=-10*log(P_21)/log(10)## throughput loss\n",
    "Lp=-10*log(P_31)/log(10)## tap loss\n",
    "Ls=-10*log(0.670)/log(10)## loss due to radiation scattering in dB\n",
    "print \"The fraction of the input power goes to each of the ports =%0.2f dB\"%( P_21)#\n",
    "print \"\\n The throughput loss =%0.2f dB\"%( Lt)#\n",
    "print \"\\n The tap loss =%0.2f dB\"%( Lp)#\n",
    "print \"\\n The loss due to radiation scattering =%0.2f dB\"%( Ls)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.19 Pg: 320"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The attenuation per km =5.92 dB/km\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "from __future__ import division\n",
    "L1=1.5## length in km\n",
    "L2=2/1000## length in km\n",
    "Pi=50.1*10**-6## optical power in W\n",
    "Po=385.4*10**-6## output power in W\n",
    "a=(10/(L1-L2))*log(Po/Pi)/log(10)## attenuation per km\n",
    "print \"The attenuation per km =%0.2f dB/km\"%( a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex:7.20 Pg: 321"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The scattering loss in the fiber =3.91 dB/km\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Psc=5.31*10**-9##\n",
    "Popt=98.45*10**-6## \n",
    "L=5.99## length in km\n",
    "asc=(4.343*10**5/L)*(Psc/Popt)## scattering loss in the fiber in dB\n",
    "print \"The scattering loss in the fiber =%0.2f dB/km\"%( asc)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}