{
 "metadata": {
  "name": "",
  "signature": "sha256:915bbc296599c9cae8476366ab28673955be075640a27c082930b79dfed61501"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7: Optical Detectors"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1: PgNo-284"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Initialisation of variables\n",
      "n1=1.46    # core refractive index\n",
      "n=1        # refractive index due to air\n",
      "r=math.pow(((n1-n)/(n1+n)),2)\n",
      "r1=0.03    # r take upto two decimal place\n",
      "l_s=-10*math.log(1-r1)/math.log(10) # fiber loss in db\n",
      "l_t=2*l_s  # total loss in db\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The fiber loss = \",l_s,\"db\"))\n",
      "print (\"\\n there is a similar loss at the other interface \")\n",
      "print ('%s %.2f %s' %(\"\\n The total fiber loss = \",l_t,\"db\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "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"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2: PgNo-285"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "n1=1.46 # core refractive index\n",
      "n=1  # refractive index due to air\n",
      "a=25*math.pow(10,-6) # core radius in m\n",
      "y=3*math.pow(10,-6) # in m\n",
      "\n",
      "# calculations\n",
      "A=(y/a)*math.pow((1-math.pow((y/(2*a)),2)),0.5)\n",
      "B=math.acos(y/(2*a))\n",
      "C=n1/n\n",
      "M=(16*math.pow(C,2))/(math.pi*math.pow((1+C),4))\n",
      "n_lat=M*(2*B-A) # coupling efficiency for multimode step index fiber\n",
      "L_lat=-10*math.log(n_lat)/math.log(10) # insertion loss for lateral misalignment\n",
      "n_lat1=(1/math.pi)*(2*B-A) # coupling efficiency when there is no air gap\n",
      "L_lat1=-10*math.log(n_lat1)/math.log(10) # insertion loss for lateral misalignment when there is no air gap\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f ' %(\" The coupling efficiency for multimode step index fiber = \", n_lat))\n",
      "print ('%s %.2f %s' %(\"\\n The insertion loss for lateral misalignment = \",L_lat,\"dB\"))\n",
      "print ('%s %.2f ' %(\"\\n The coupling efficiency when there is no air gap = \", n_lat1))\n",
      "print ('%s %.2f %s' %(\"\\n The insertion loss for lateral misalignment when there is no air gap = \",L_lat1,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "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"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3: PgNo-287"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "n1=1.50     # core refractive index\n",
      "n=1         # refractive index due to air\n",
      "a=25*math.pow(10,-6) # core radius in m\n",
      "y=4*math.pow(10,-6) # in m\n",
      "\n",
      "# calculations\n",
      "A=(y/a)*math.pow((1-math.pow((y/(2*a)),2)),0.5)\n",
      "B=math.acos(y/(2*a))\n",
      "C=n1/n\n",
      "M=(16*math.pow(C,2))/(math.pi*math.pow((1+C),4))\n",
      "n_lat=M*(2*B-A)                # coupling efficiency for multimode step index fiber\n",
      "L_lat=-10*math.log(n_lat)/math.log(10)   # insertion loss for lateral misalignment\n",
      "dx=4*(math.pi/180)          # angular misalignment in radian\n",
      "dl=0.02                #relative index difference\n",
      "NA=n1*math.sqrt(2*dl)       # numerical aperture\n",
      "n_ang=1-(0.069/(math.pi*NA)) # coupling efficiency due to angular misalignment\n",
      "L_ang=-10*math.log(n_ang)/math.log(10) # loss due to angular misalignment\n",
      "Lt=L_lat+L_ang         # total insertion loss in dB\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %( \" The total insertion loss = \",Lt,\"dB\"))\n",
      "print (\"\\n the answer is wrong in the textbook \")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The total insertion loss =  1.15 dB\n",
        "\n",
        " the answer is wrong in the textbook \n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4: PgNo-292"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable initialisation\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",
      "\n",
      "# Calculations\n",
      "A=(y/a)*math.pow((1-math.pow((y/(2*a)),2)),0.5)\n",
      "B=math.acos(y/(2*a))\n",
      "C=n1/n\n",
      "M=(16*math.pow(C,2))/(math.pi*math.pow((1+C),4))\n",
      "n_lat=M*(2*B-A) #coupling efficiency when there is a smsll air gap\n",
      "L_lat=-10*math.log(n_lat)/math.log(10) # insertion loss when there is a smsll air gap\n",
      "n_lat1=(1/math.pi)*(2*B-A) # coupling efficiency when the joint is indexed matched\n",
      "L_lat1=-10*math.log(n_lat1)/math.log(10) # insertion loss when the joint is indexed matched\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The insertion loss when there is a smsll air gap = \",L_lat,\"dB\"))\n",
      "print ('%s %.2f %s' %( \"\\n The insertion loss when the joint is indexed matched = \",L_lat1,\"dB\"))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "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"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5: PgNo-296"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable initialisation\n",
      "d1=60*math.pow(10,-6)# core diameter of fiber 1 in m\n",
      "d2=50*math.pow(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",
      "# calculations\n",
      "n_cd=math.pow((d2/d1),2)\n",
      "n_NA=math.pow((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*math.log(n_t)/math.log(10) #total loss at the joint in dB\n",
      "\n",
      "# Results\n",
      "print ('%s %.3f ' %(\" The total coupling efficiency in the frw direction = \", n_t))\n",
      "print ('%s %.2f %s' %(\"\\n The total loss at the joint in the frw direction = \",Lt,\"dB\"))\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 \")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The total coupling efficiency in the frw direction =  0.524 \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"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6: PgNo-298"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable initialisation\n",
      "d1=80*math.pow(10,-6) #core diameter of fiber 1 in m\n",
      "d2=60*math.pow(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",
      "# Calculations\n",
      "n_cd=math.pow((d2/d1),2)\n",
      "n_NA=math.pow((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*math.log(n_t)/math.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*math.log(n_t1)/math.log(10)# total loss at the joint in the backward direction in dB\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The total loss at the joint in the frw direction = \",Lt,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The total loss at the joint in the backward direction = \",Lt1,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "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"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7: PgNo-303"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable initialisation\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",
      "\n",
      "# calculations\n",
      "A=(y/a)*math.pow((1-math.pow((y/(2*a)),2)),0.5)\n",
      "B=math.acos(y/(2*a))\n",
      "C=n1/n\n",
      "M=(16*math.pow(C,2))/(math.pi*math.pow((1+C),4))\n",
      "n_lat=M*(2*B-A) #coupling efficiency of the splice\n",
      "L_lat=-10*math.log(n_lat)/math.log(10) #insertion loss of the splice\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %( \" The insertion loss of the splice = \",L_lat,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The insertion loss of the splice =  0.35 dB\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8: PgNo-305"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable initialisation\n",
      "L_f=0.036\n",
      "n_f=math.pow(10,(-0.036))\n",
      "# here we get a quadratic equation in n1 and on solving we get\n",
      "n1=(2.17+math.sqrt(math.pow((-2.17),2)-4*1*1))/2 # refractive index of the fiber core\n",
      "# Results\n",
      "print ('%s %.3f' %(\" The refractive index of the fiber core = \", n1))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The refractive index of the fiber core =  1.506\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9: PgNo-309"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable declaration\n",
      "n1=1.46 #core refractive index\n",
      "n=4   # refractive index due to air\n",
      "x=math.pi/180\n",
      "A=(16*math.pow(n1,2))/(math.pow((1+n1),4))\n",
      "B=n*x\n",
      "n_ang=math.pow(10,(-0.06)) # angular coupling efficiency\n",
      "NA=B/((math.pi)*(1-(n_ang/A))) # numerical aperture\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f' %(\" The numerical aperture = \", NA))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The numerical aperture =  0.34\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10: PgNo-311"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "y=5*math.pow(10,-6)   # lateral misalignment in m\n",
      "a=25*math.pow(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*math.log(n_c)/math.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*math.log(n_c1)/math.log(10) # insertion loss in dB if we have both guided and leaky modes\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The insertion loss = \",L_i,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The insertion loss,if we have both guided and leaky modes = \",L_i1,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The insertion loss =  0.81 dB\n",
        "\n",
        " The insertion loss,if we have both guided and leaky modes =  0.71 dB\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11: PgNo-314"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "n1=1.5 # core refractive index\n",
      "n=1  # refractive index due to air\n",
      "x=5*math.pi/180\n",
      "\n",
      "# Calculations\n",
      "C=n1/n\n",
      "A=(16*math.pow(C,2))/(math.pow((1+C),4))\n",
      "B=n*x\n",
      "NA=0.22 # numerical aperture\n",
      "n_ang=A*(1-(B/(math.pi*NA))) # angular coupling efficiency\n",
      "L_ang=-10*math.log(n_ang)/math.log(10) # inserion loss when NA=0.22\n",
      "NA1=0.32 # numerical aperture\n",
      "n_ang1=A*(1-(B/(math.pi*NA1))) # angular coupling efficiency\n",
      "L_ang1=-10*math.log(n_ang1)/math.log(10) # inserion loss when NA=0.32\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The inserion loss when NA=0.22 = \",L_ang,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The inserion loss when NA=0.32 = \",L_ang1,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The inserion loss when NA=0.22 =  0.94 dB\n",
        "\n",
        " The inserion loss when NA=0.32 =  0.75 dB\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12: PgNo-315"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "V=2.50 # normalised frequency\n",
      "n1=1.5 # core refractive index\n",
      "a=4.5*math.pow(10,-6) # core radius in m\n",
      "NA=0.2 # numerical aperture\n",
      "y=3*math.pow(10,-6) # lateral misalignment in m\n",
      "w=a*((0.65+1.62*math.pow((V),-1.5)+2.88*math.pow((V),-6))/math.pow(2,0.5)) # normalised spot size in m\n",
      "T1=2.17*math.pow((y/w),2) # Loss due to lateral offset in dB\n",
      "x=(math.pi/180)*w\n",
      "Ta=2.17*math.pow(((x*n1*V)/(a*NA)),2) # loss due to angular misalignment in dB\n",
      "T=T1+Ta # total insertion loss in dB\n",
      "\n",
      "# Results\n",
      "print ('%s %.3f %s' %(\" The total insertion loss  = \",T,\"dB\"))\n",
      "print (\"\\n The answer is wrong in the textbook \")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The total insertion loss  =  1.813 dB\n",
        "\n",
        " The answer is wrong in the textbook \n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13: PgNo-317"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable declaration\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",
      "\n",
      "# Calculations\n",
      "Le=10*math.log(P1/(P3+P4))/math.log(10) # Excess loss in dB\n",
      "Le1=10*math.log(P1/P3)/math.log(10) # insertion loss port 1 to 3 in dB\n",
      "Le2=10*math.log(P1/P4)/math.log(10) # insertion loss port 1 to 4 in dB\n",
      "ct=10*math.log(P2/P1)/math.log(10) # cross talk in dB\n",
      "sr=(P3/(P3+P4))*100 # split ratio\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The Excess loss = \",Le,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The insertion loss port 1 to 3  = \",Le1,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The insertion loss port 1 to 4  = \",Le2,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The cross talk = \",ct,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The split ratio = \",sr,\"%\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The Excess loss =  1.10 dB\n",
        "\n",
        " The insertion loss port 1 to 3  =  3.01 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"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14: PgNo-318"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable initialisation\n",
      "n=1.0\n",
      "n1=1.48\n",
      "r=math.pow(((n1-n)/(n1+n)),2) # fresnel's reflection\n",
      "Ls=-10*math.log(1-r)/math.log(10) #optical loss in dB\n",
      "Lt=2*Ls # total fresnel loss\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The total fresnel loss = \",Lt,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The total fresnel loss =  0.33 dB\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15: PgNo-322"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "NA1=0.32 # numerical aperture for fiber1\n",
      "NA2=0.22 # numerical aperture for fiber2\n",
      "Lc=20*math.log(NA1/NA2)/math.log(10) #NA mismatch coupling loss\n",
      "\n",
      "#Results\n",
      "print ('%s %.2f %s' %(\" The NA mismatch coupling loss = \",Lc,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The NA mismatch coupling loss =  3.25 dB\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16: PgNo-325"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# variable initialisation\n",
      "P0=250.0 # optical power in uW\n",
      "P1=80.0 # output power at port 1 in uW\n",
      "P2=70.0 # output power at port 2 in uW\n",
      "P3=5*math.pow(10,-3) # output power at port 3 in uW\n",
      "\n",
      "# calculations\n",
      "cr=(P2/(P1+P2))*100 # coupling ratio\n",
      "Le=10*math.log(P0/(P1+P2))/math.log(10) # Excess loss in dB\n",
      "Le1=10*math.log(P0/P1)/math.log(10) # insertion loss port 0 to 1 in dB\n",
      "Le2=10*math.log(P0/P2)/math.log(10) # insertion loss port 0 to 2 in dB\n",
      "ct=10*math.log(P3/P0)/math.log(10)  #cross talk in dB\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The coupling ratio = \",cr,\"%\"))\n",
      "print ('%s %.2f %s' %(\"\\n The Excess loss = \",Le,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The insertion loss port 0 to 1  = \",Le1,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The insertion loss port 0 to 2 = \",Le2,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The cross talk = \",ct,\"dB\"))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "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"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17: PgNo-327"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "P_21=4.0/5.0 # ratio of the input available at port2\n",
      "P_31=1.0/5.0 # ratio of the input available at port3 \n",
      "Lt=-10*math.log(P_21)/math.log(10) # throughput loss\n",
      "Lp=-10*math.log(P_31)/math.log(10) # tap loss\n",
      "Le=-10*math.log(P_21+P_31)/math.log(10) # excess loss\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The throughput loss = \",Lt,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The tap loss = \",Lp,\"dB\"))\n",
      "print (\"\\n Directionality=-10*log(0/Pi=infinity)\")\n",
      "print ('%s %.1f %s' %(\"\\n The excess loss = \",Le,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "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.0 dB\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 18: PgNo-329"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "Le=4 # excess loss in dB\n",
      "D=60 # Directionality in dB\n",
      "P_41=math.pow(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*math.log(P_21)/math.log(10) # throughput loss\n",
      "Lp=-10*math.log(P_31)/math.log(10) # tap loss\n",
      "Ls=-10*math.log(0.670)/math.log(10) # loss due to radiation scattering in dB\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The fraction of the input power goes to each of the ports = \",P_21,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The throughput loss = \",Lt,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The tap loss = \",Lp,\"dB\"))\n",
      "print ('%s %.2f %s' %(\"\\n The loss due to radiation scattering = \",Ls,\"dB\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "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"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19: PgNo-330"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable declaration\n",
      "L1=1.5 # length in km\n",
      "L2=2/1000 # length in km\n",
      "Pi=50.1*math.pow(10,-6) # optical power in W\n",
      "Po=385.4*math.pow(10,-6) # output power in W\n",
      "a=(10/(L1-L2))*math.log(Po/Pi)/math.log(10) # attenuation per km\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The attenuation per km = \",a,\"dB/km\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The attenuation per km =  5.91 dB/km\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 20: PgNo-334"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variable initialisation\n",
      "Psc=5.31*math.pow(10,-9)\n",
      "Popt=98.45*math.pow(10,-6) \n",
      "L=5.99 # length in km\n",
      "asc=(4.343*math.pow(10,5)/L)*(Psc/Popt) # scattering loss in the fiber in dB\n",
      "\n",
      "# Results\n",
      "print ('%s %.2f %s' %(\" The scattering loss in the fiber = \",asc,\"dB/km\"))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The scattering loss in the fiber =  3.91 dB/km\n"
       ]
      }
     ],
     "prompt_number": 26
    }
   ],
   "metadata": {}
  }
 ]
}