{
 "metadata": {
  "name": "",
  "signature": "sha256:c80be9ee73d5adb979ad6bf2343ea3cff1243505e35fc82560bd445f960931b7"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter4 - Signal Degradation in fibers"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.3.1, page 4-4"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from numpy import sqrt, pi, log10\n",
      "L=10        #fiber length in km\n",
      "Pin=150*10**-6      #input power\n",
      "Pout=5*10**-6       #output power\n",
      "ln=20        #length of optical link\n",
      "interval=1      #splices after interval of 1 km\n",
      "l=1.2       #loss due to 1 splice\n",
      "attenuation=10*log10(Pin/Pout) \n",
      "alpha=attenuation/L \n",
      "attenuation_loss=alpha*20 \n",
      "splices_loss=(ln-interval)*l \n",
      "total_loss=attenuation_loss+splices_loss \n",
      "power_ratio=10**(total_loss/10) \n",
      "print \"Signal attenuation is %.2f dBs.\\nSignal attenuation is %.3f dB/Km.\\nTotal loss in 20 Km fiber is %.2f dbs.\\nTotal attenuation is %.2f dBs.\\ninput/output ratio is %0.e.\" %(attenuation,alpha,attenuation_loss,total_loss,power_ratio) \n",
      "# Answer wrong for last part."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Signal attenuation is 14.77 dBs.\n",
        "Signal attenuation is 1.477 dB/Km.\n",
        "Total loss in 20 Km fiber is 29.54 dbs.\n",
        "Total attenuation is 52.34 dBs.\n",
        "input/output ratio is 2e+05.\n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.6.1, page 4-12"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import exp\n",
      "beta_c=8*10**-11      #isothermal compressibility\n",
      "n=1.46      #refractive index\n",
      "P=0.286     #photoelastic constat\n",
      "k=1.38*10**-23  #Boltzmnn constant\n",
      "T=1500      #temperature\n",
      "L=1000      #length\n",
      "lamda=1000*10**-9   #wavelength\n",
      "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4))       #computing coefficient\n",
      "attenuation=exp(-gamma_r*L)         #computing attenuation\n",
      "print \"Attenuation due to Rayleigh scattering is %.3f.\" %(attenuation) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Attenuation due to Rayleigh scattering is 0.794.\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.6.2, page 4-12"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "beta_c=7*10**-11         #isothermal compressibility\n",
      "n=1.46      #refractive index\n",
      "P=0.29     #photoelastic constat\n",
      "k=1.38*10**-23  #Boltzmnn constant\n",
      "T=1400      #temperature\n",
      "L=1000      #length\n",
      "lamda=0.7*10**-6   #wavelength\n",
      "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4))       #computing coefficient\n",
      "attenuation=exp(-gamma_r*L)         #computing attenuation\n",
      "gamma_r=gamma_r\n",
      "print \"Raleigh Scattering corfficient is %.3e per meter\" %(gamma_r) \n",
      "#Attenuation is not calcualted in textbook\"\n",
      "print \"Attenuation due to Rayleigh scattering is %.3f\" %(attenuation) \n",
      "#answer for Raleigh Scattering corfficient in the book is given as 0.804d-3, deviation of 0.003d-3"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Raleigh Scattering corfficient is 8.074e-04 per meter\n",
        "Attenuation due to Rayleigh scattering is 0.446\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.7.1, page 4-17"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "d=5      #core diameter\n",
      "alpha=0.4   #attenuation\n",
      "B=0.5     #Bandwidth\n",
      "lamda=1.4    #wavelength\n",
      "PB=4.4*10**-3*d**2*lamda**2*alpha*B       #computing threshold power for SBS\n",
      "PR=5.9*10**-2*d**2*lamda*alpha       #computing threshold power for SRS\n",
      "PB=PB*10**3 \n",
      "PR=PR*10**3 \n",
      "print \"Threshold power for SBS is %.1f mW.\\nThreshold power for SRS is %.3f mW.\" %(PB,PR) \n",
      "#NOTE - Calculation error in the book while calculating threshold for SBS.\n",
      "#Also, while calculating SRS, formula is taken incorrectly, \n",
      "#Bandwidth is multiplied in second step, which is not in the formula.\") "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Threshold power for SBS is 43.1 mW.\n",
        "Threshold power for SRS is 826.000 mW.\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.8.1, page 4-18"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "n1=1.5      #refractive index of core\n",
      "delta=0.03/100      #relative refractive index\n",
      "lamda=0.82*10**-6       #wavelength\n",
      "n2=sqrt(n1**2-2*delta*n1**2)       #computing cladding refractive index\n",
      "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**1.5)      #computing critical radius\n",
      "Rc=Rc*10**3 \n",
      "print \"Critical radius is %.f micrometer.\" %(Rc)  "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Critical radius is 9 micrometer.\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.8.2, page 4-20"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "n1=1.45      #refractive index of core\n",
      "delta=3.0/100      #relative refractive index\n",
      "lamda=1.5*10**-6       #wavelength\n",
      "a=5*10**-6      #core radius\n",
      "n2=sqrt(n1**2-2*delta*n1**2)       #computing cladding refractive index\n",
      "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**0.5)      #computing critical radius for single mode\n",
      "Rc=Rc*10**6 \n",
      "print \"Critical radius is %.2f micrometer\" %(Rc) \n",
      "lamda_cut_off= 2*3.14*a*n1*sqrt(2*delta)/2.405 \n",
      "RcSM= (20*lamda/(n1-n2)**1.5)*(2.748-0.996*lamda/lamda_cut_off)**-3       #computing critical radius for single mode\n",
      "RcSM=RcSM*10**6 \n",
      "print \"Critical radius for single mode fiber is %.2f micrometer.\" %(RcSM) \n",
      "#Calculation error in the book.(2.748-0.996*lamda/lamda_cut_off)**-3  in this term raised to -3 is not taken in the book."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Critical radius is 2.12 micrometer\n",
        "Critical radius for single mode fiber is 226.37 micrometer.\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.13.1, page 4-28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "lamda=1550*10**-9 \n",
      "lamda0=1.3*10**-6 \n",
      "s0=0.095 \n",
      "Dt=lamda*s0/4*(1-(lamda0/lamda)**4)      #computing material dispersion\n",
      "Dt=Dt*10**9 \n",
      "print \"Material dispersion at 1550 nm is %.1f ps/nm/km\" %Dt\n",
      "#answer in the book is wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Material dispersion at 1550 nm is 18.6 ps/nm/km\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.14.1, page 4-33"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "tau=0.1*10**-6      #pulse broadning\n",
      "dist=20*10**3       #distance\n",
      "Bopt=1/(2*tau)      #computing optical bandwidth\n",
      "Bopt=Bopt*10**-6 \n",
      "dispertion=tau/dist         #computing dispersion\n",
      "dispertion=dispertion*10**12 \n",
      "BLP=Bopt*dist       #computing Bandwidth length product\n",
      "BLP=BLP*10**-3 \n",
      "print \"optical bandwidth is %d MHz.\\nDispersion per unit length is %d ns/km.\\nBandwidth length product is %d MHz.km.\" %(Bopt,dispertion,BLP) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "optical bandwidth is 5 MHz.\n",
        "Dispersion per unit length is 5 ns/km.\n",
        "Bandwidth length product is 100 MHz.km.\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.15.1, page 4-34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "RSW=0.0012      #relative spectral width\n",
      "lamda=0.90*10**-6   #wavelength\n",
      "L=1         #distance in km (assumed)\n",
      "P=0.025     #material dispersion parameter\n",
      "c=3*10**5       #speed of light in km/s\n",
      "M=10**3*P/(c*lamda)      #computing material dispersion\n",
      "sigma_lamda=RSW*lamda \n",
      "sigmaM=sigma_lamda*L*M*10**7         #computing RMS pulse broadning\n",
      "sigmaB=25*L*M*10**-3 \n",
      "print \"Material dispersion parameter is %.2f ps/nm/km.\\nRMS pulsr broadning when sigma_lamda is 25 is %.1f ns/km.\\nRMS pulse broadning is %.2f ns/km.\" %(M,sigmaB,sigmaM) \n",
      "#answer in the book for RMS pulse broadning is wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Material dispersion parameter is 92.59 ps/nm/km.\n",
        "RMS pulsr broadning when sigma_lamda is 25 is 2.3 ns/km.\n",
        "RMS pulse broadning is 1.00 ns/km.\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.17.1, page 4-37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L=10         #length of optical link\n",
      "n1=1.49      #refractive index\n",
      "c=3*10**8       #speed of light\n",
      "delta=1.0/100         #relative refractive index\n",
      "delTS=L*n1*delta/c      #computing delay difference\n",
      "delTS=delTS*10**12 \n",
      "sigmaS=L*n1*delta/(2*sqrt(3)*c)     #computing rms pulse broadning\n",
      "sigmaS=sigmaS*10**12 \n",
      "B=1/(2*delTS)         #computing maximum bit rate\n",
      "B=B*10**3 \n",
      "B_acc=0.2/(sigmaS)      #computing accurate bit rate\n",
      "B_acc=B_acc*10**3 \n",
      "BLP=B_acc*L       #computing Bandwidth length product\n",
      "print \"Delay difference is %d ns.\\nRMS pulse broadning is %.1f ns.\\nBit rate is %.1f Mbit/s.\\nAccurate bit rate is %.3f Mbits/s.\\nBandwidth length product is %.1f MHz.km\" %(delTS,sigmaS,B,B_acc,BLP) \n",
      "#answer for maximum bit rate is given as 1.008 Mb/s, deviation of 0.008 Mb/s."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Delay difference is 496 ns.\n",
        "RMS pulse broadning is 143.4 ns.\n",
        "Bit rate is 1.0 Mbit/s.\n",
        "Accurate bit rate is 1.395 Mbits/s.\n",
        "Bandwidth length product is 13.9 MHz.km\n"
       ]
      }
     ],
     "prompt_number": 31
    }
   ],
   "metadata": {}
  }
 ]
}