{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 02:Optical Fiber Transmission"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.1:pg-38"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The numerical aperture =  0.2417\n",
      "\n",
      " The acceptance angle =  0.2441  Radian\n",
      "\n",
      " The relative index difference =  0.0136\n"
     ]
    }
   ],
   "source": [
    "# Example no. 2.1\n",
    "# To find a)The numerical aperture b)The acceptanca angle c)The relative index defference\n",
    "# Page no. 38\n",
    "\n",
    "\n",
    "import math\n",
    "\n",
    "# Given data\n",
    "n1=1.47;                                  # Refractive index of core\n",
    "n2=1.45;                                  # Refractive index of cladding\n",
    "\n",
    "# a)The numerical aperture\n",
    "NA=(n1**2-n2**2)**(1/2.0);                    # Numerical aperture\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The numerical aperture = \",round(NA,4)\n",
    "\n",
    "# b)The acceptanca angle\n",
    "imax=math.asin(NA);                          # The acceptanca angle\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The acceptance angle = \",round(imax,4),\" Radian\"\n",
    "\n",
    "# c)The relative index defference\n",
    "delta=(n1-n2)/n1;                      # Relative index defference\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The relative index difference = \",round(delta,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.2:pg-41"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Refractive index of cladding =  1.4454\n",
      "\n",
      " Delay = 49 ns\n",
      "\n",
      " Approximate delay =  50 ns\n",
      "\n",
      " Maximum bit-rate distance product =  20.3  Mb/(s.km)\n"
     ]
    }
   ],
   "source": [
    "# Example no. 2.2\n",
    "# To find maximum bit-rate distance product\n",
    "# Page no. 41\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "# Given data\n",
    "n1=1.46;                                               # Refractive index of core\n",
    "delta=0.01;                                            # Relative difference of refractive index\n",
    "L=1*10**3;                                              # Fiber length\n",
    "c=3*10**(8);                                            # Speed of ligth in km/sec\n",
    "\n",
    "n2=n1*(1-delta);                                       # Refractive index of cladding\n",
    "deltaT=(n1**2*L*delta)/(c*n2);                          # Delay in sec\n",
    "BL=(((c*n2)/(n1**2*delta))/10**3)*10**-6;                 # maximum bit-rate distance product in Mb/s.km\n",
    "deltaT=((n1**2*L*delta)/(c*n2))*10**9;                   # Delay in ns\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Refractive index of cladding = \",round(n2,4)\n",
    "print \"\\n Delay =\",int(deltaT),\"ns\"\n",
    "print \"\\n Approximate delay = \",int(deltaT+1),\"ns\"\n",
    "print \"\\n Maximum bit-rate distance product = \",round(BL,1),\" Mb/(s.km)\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.3:pg-43"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pulse width for step index fiber =  67.59  ns\n",
      "Pulse width for parabolic index fiber =  0.1667  ns\n",
      "Thus, the intermodal dispersion can be significantly reduced by using parabolic-index fiber\n"
     ]
    }
   ],
   "source": [
    "# Example no.2.3\n",
    "# To compare deltaT for step index fiber with parabolic-index fiber\n",
    "# Page no. 43\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "# Given data\n",
    "n1=1.47;                                           # Refractive index of core\n",
    "n2=1.45;                                           # Refractive index of cladding\n",
    "L=1*10.0**3;                                          # Length of medium in meter\n",
    "c=3*10**8;                                          # speedof ligth in (m/s)\n",
    "delta=(n1-n2)/n1;\n",
    "\n",
    "# The deltaT for step index fiber\n",
    "deltaTSIF=((n1**2*L*delta)/(c*n2))*10**9;            #Pulse width for step index fiber\n",
    "\n",
    "# deltaT for parabolic-index fiber\n",
    "deltaTPIF=((n1**2*delta**2*L)/(8*c))*10**9;          # Pulse width for parabolic-index fiber\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"Pulse width for step index fiber = \",round(deltaTSIF,2),\" ns\"\n",
    "print \"Pulse width for parabolic index fiber = \",round(deltaTPIF,4),\" ns\"\n",
    "\n",
    "# The answer of pulse width for parabolic index fiber is wrong in book\n",
    "\n",
    "print \"Thus, the intermodal dispersion can be significantly reduced by using parabolic-index fiber\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.4:pg-61"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Transmitted power =  10.79  dBm\n",
      "\n",
      " Received power =  0.3162  mW\n"
     ]
    }
   ],
   "source": [
    "# Example 2.4\n",
    "# a)To convert transmitted power into dBm b)To convert received power into mW\n",
    "# Page no. 61\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "# Given data\n",
    "Ptr=0.012;                               # Transmitted power in watt \n",
    "PrdBm=-5;                                # Received power in dBm\n",
    "\n",
    "# a)To convert transmitted power into dBm\n",
    "PtrdBm=10*math.log10(Ptr/(10.0**-3));            # Transmitted power in dBm\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Transmitted power = \",round(PtrdBm,2),\" dBm\"\n",
    "\n",
    "# b)To convert received power into mW\n",
    "PrmW=10**(-5/10.0);                        # Received power in mW\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Received power = \",round(PrmW,4),\" mW\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.7:pg-69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The core radius of step-index fiber =  2.907  micrometer\n",
      "\n",
      " Operating wavelength =  1.55  micrometer\n",
      "\n",
      " Cutoff wavelength =  1.1  micrometer\n",
      "Since operating wavelength is greater than cutoff wavelength, it is single moded at this wavelength.\n"
     ]
    }
   ],
   "source": [
    "# Example no.2.7\n",
    "# To find the core radius of step-index fiber\n",
    "# Page no.69\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "# Given data\n",
    "n1=1.45;                                                         # Refractive index of core\n",
    "delta=0.005;\n",
    "n2=n1*(1-delta);                                                 # Refractive index of cladding\n",
    "lambdac=1.1;                                                     # Cutoff wavelength in meter\n",
    "lambdaa=1.55;                                                     # Operating wavelength in micrometer\n",
    "a=((2.4048*lambdac*10**-6)/(2*math.pi*(n1**2-n2**2)**(1/2.0)))/10**-6;      # Core radius\n",
    "\n",
    "#Displaying the result in command window\n",
    "print \"\\n The core radius of step-index fiber = \",round(a,3),\" micrometer\"\n",
    "print \"\\n Operating wavelength = \",round(lambdaa,2),\" micrometer\"\n",
    "print \"\\n Cutoff wavelength = \",round(lambdac,1),\" micrometer\"\n",
    "\n",
    "print \"Since operating wavelength is greater than cutoff wavelength, it is single moded at this wavelength.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.8:pg-72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Total loss in fiber =  16  dB\n",
      "\n",
      " Output power of fiber = -13 dBm\n",
      "\n",
      " Output power of fiber =  0.05  mW\n"
     ]
    }
   ],
   "source": [
    "# Example no 2.8\n",
    "# To find the total loss and output power in mW and dBm in fiber\n",
    "# Page no. 72\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "# Given data\n",
    "losscoe=0.046;                                 # Loss coefficient in km**-1\n",
    "L=80;                                          # Length of fiber in km\n",
    "PindBm=3;                                      # Input power in dBm\n",
    "\n",
    "# To find total loss of fiber\n",
    "loss=round(4.343*losscoe*L);                   # Total loss in fiber\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Total loss in fiber = \",int(loss),\" dB\"\n",
    "\n",
    "# To find output power \n",
    "PoutdBm=PindBm-loss;                           # Output power in dBm\n",
    "\n",
    "PoutmW=10**(PoutdBm/10);                        # Output power in mW\n",
    "\n",
    "#Displaying the result in command window\n",
    "print \"\\n Output power of fiber =\",int(PoutdBm),\"dBm\"\n",
    "print \"\\n Output power of fiber = \",round(PoutmW,2),\" mW\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.10:pg-77"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We choose center of band (lambda_0) for large maximum allowable dispersion slope.\n",
      "\n",
      " Dispersion slope =  0.917  ps/nm**2/km\n"
     ]
    }
   ],
   "source": [
    "# Example no. 2.10\n",
    "# To design single mode fiber such that absolute accumulated dispersion should not exceed 1100ps/nm\n",
    "# Page no. 77\n",
    "\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "# Given data\n",
    "lambda1=1530;                              # Left edge of wavelength range in nm\n",
    "lambda2=1560;                              # Rigth edge of wavelength range in nm\n",
    "lambda0=1545;                              # Center of the band in nm\n",
    "L=80;                                     # Fiber length in km\n",
    "\n",
    "print \"We choose center of band (lambda_0) for large maximum allowable dispersion slope.\"\n",
    "\n",
    "Dlambda2=1100.0/L;                         # Dispersion at rigth edge of band in ps/nm/km\n",
    "S=Dlambda2/(lambda2-lambda0);            # Dispersion slope in ps/nm**2/km\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Dispersion slope = \",round(S,3),\" ps/nm**2/km\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.11:pg-80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Length of DCF =  12.9  km\n",
      "\n",
      " Output power of DCF =  -19.95  dBm\n",
      "\n",
      " Gain of amplifier =  22.96  dBm\n"
     ]
    }
   ],
   "source": [
    "# Example no.2.11\n",
    "# To find a)length of DCF b)power at the output of DCF c)gain of amplifier\n",
    "# Page no.80\n",
    "\n",
    "\n",
    "\n",
    "import math\n",
    "# Given data\n",
    "LTF=80;                                                    # Length of transmission fiber\n",
    "beta2TF=-21.0;                                               # Dispersion of transmission fiber in ps**2/km\n",
    "beta2DCF=130.0;                                              # Dispersion of DCF in ps**2/km\n",
    "Pin=2*10**(-3);                                             # Input power of transmission fiber in W\n",
    "DCFloss=0.5;                                               # Losses of DCF in dB/km\n",
    "TFloss=0.2;                                                # Losses of TF in dB/km\n",
    "spliceloss=0.5;                                            # Splice loss in dB\n",
    "\n",
    "# a)To find length of DCF\n",
    "LDCF=(-beta2TF*LTF)/beta2DCF;                             # Length of DCF in km\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Length of DCF = \",round(LDCF,1),\" km\"\n",
    "\n",
    "# b)To find power at the output of DCF\n",
    "PindBm=10*math.log10(Pin/10**(-3));                            # Input power of transmission fiber in dBm\n",
    "Totalloss=TFloss*LTF+DCFloss*LDCF+spliceloss;            # Total loss in fiber in dB\n",
    "PoutdBm=PindBm-Totalloss;                                # Output power of DCF in dBm\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Output power of DCF = \",round(PoutdBm,2),\" dBm\"\n",
    "\n",
    "# c)To find gain of amplifier\n",
    "gain=Totalloss;                                        # gain of amplifier\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Gain of amplifier = \",round(gain,2),\" dBm\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.12:pg-81"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The delay between the shortest and longest path =  91.95  ns\n"
     ]
    }
   ],
   "source": [
    "# Example no. 2.12\n",
    "# To find the delay between the shortest and longest path.\n",
    "# Page no. 81\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "# Given data\n",
    "NA=0.2;                                         # Numerical aperture\n",
    "L=2*10**3;                                       # Fiber length in meters\n",
    "n1=1.45;                                        # Core refractive index\n",
    "delta=(NA)**2/(2*n1**2);                          # Relative index difference\n",
    "n2=n1;                                          # since difference between core index and cladding index is smaller\n",
    "c=3*10**8;                                       # Speed of ligth in m/s\n",
    "\n",
    "# The delay between the shortest and longest path.\n",
    "deltaT=((n1**2*L*delta)/(c*n2));                # the delay between the shortest and longest path.\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The delay between the shortest and longest path = \",round(deltaT*10**9,2),\" ns\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.13:pg-82"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The propagation constant at 1551nm wavelength =  5.9961  X 10**6 rad/s\n"
     ]
    }
   ],
   "source": [
    "# Example no. 2.13\n",
    "# To calculate the propagation constant\n",
    "# Page no. 82\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "# Given data\n",
    "lambda0=1550*10**-9;                                          # wavelength in meter\n",
    "beta0=6*10**6;                                                # propagation constant in rad/m\n",
    "lambda1=1551*10**-9;                                          # wavelength in meter\n",
    "beta1=0.5*10**-8;                                             # inverse group velocity in sec/meter\n",
    "beta2=-10*10**-24;                                            # second-order dispersion coefficient in sec**2/km\n",
    "c=3*10**8;                                                    # Speed of ligth in m/s\n",
    "omega0=(2*math.pi*c)/lambda0;                                    # Radial frequency at lambda0\n",
    "omega1=(2*math.pi*c)/lambda1;                                    # Radial frequency at lambda1\n",
    "omega=omega1-omega0;\n",
    "\n",
    "# The propagation constant at 1551nm wavelength\n",
    "betaomega1=(beta0+beta1*omega+beta2*omega**2/2.0);        # Propagation constant at 1551nm wavelength\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The propagation constant at 1551nm wavelength = \",round(betaomega1*10**-6,4),\" X 10**6 rad/s\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.14:pg-83"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The lower limit on the transmitter power in dBm =  -1.5\n",
      "\n",
      " The lower limit on the transmitter power in mW =  0.7079\n"
     ]
    }
   ],
   "source": [
    "# Example No. 2.14\n",
    "# To calculate the lower limit on the transmitter power in dBm and mW units.\n",
    "# Page No. 83\n",
    "\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "# Given data\n",
    "l=80;                                             # Length of fiber in km\n",
    "F1=-0.2*l;                                        # Fiber loss in dB\n",
    "F2=-0.5;                                          # Filter loss in dB\n",
    "G=15;                                             # Amplifier gain in dB\n",
    "Pout=-3;                                          # Minimum power required at the receiver in dBm\n",
    "\n",
    "# Lower limit on the transmitter power\n",
    "Pin=Pout-F1-F2-G;                                 # Lower limit on the transmitter power in dBm\n",
    "PinmW=10**(0.1*Pin);                               # Lower limit on the transmitter power in mW\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The lower limit on the transmitter power in dBm = \",round(Pin,1)\n",
    "print \"\\n The lower limit on the transmitter power in mW = \",round(PinmW,4)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.16:pg-84"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The length of DCF so that the pulse width (FWHM) at the output of the DCF is twice the pulse width at the input of the TF \n",
      " =  13.67 km\n",
      " or =  12.17  km\n"
     ]
    }
   ],
   "source": [
    "# Example No. 2.16\n",
    "# To find the length of DCF so that the pulse width (FWHM) at the output of the DCF is twice the pulse width at the input of the TF\n",
    "# Page No. 84\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "# Given data\n",
    "beta2TF=-21*(10**(-12))**2;                                    # Dispersion coefficient of transmission fiber in s**2/km\n",
    "beta2DCF=130*(10**(-12))**2;                                   # Dispersion coefficient of dispersion compensating fiber in s**2/km\n",
    "LTF=80;                                                  # Length of transmission fiber in km\n",
    "TFWHM=12.5*10**(-12);                                     # Full-width at half-maximum\n",
    "T0=TFWHM/1.665;                                          # Half-width\n",
    "\n",
    "# The length of required DCF\n",
    "LDCF1=(math.sqrt(3)*T0**2-beta2TF*LTF)/beta2DCF;                # Length of dispersion compensating fiber in km\n",
    "LDCF2=(-math.sqrt(3)*T0**2-beta2TF*LTF)/beta2DCF;               # Length of dispersion compensating fiber in km\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The length of DCF so that the pulse width (FWHM) at the output of the DCF is twice the pulse width at the input of the TF \\n = \",round(LDCF1,2),\"km\"\n",
    "\n",
    "print \" or = \",round(LDCF2,2),\" km\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex2.17:pg-85"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The accumulated dispersion of the DCF should be less than  -3380  ps/nm\n"
     ]
    }
   ],
   "source": [
    "# Example No. 2.17\n",
    "# To find the accumulated dispersion of the DCF so that the net accumulated dispersion does not exceed 1100 ps/nm\n",
    "# Page no. 85\n",
    "\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "# Given data\n",
    "lambda0=1490;                                                    # Zero dispersion wavelength in nm\n",
    "lambdaa=1560;                                                     # Upper limit of wavelength range in nm\n",
    "Sc=0.08;                                                         # Dispersion slope of transmission fiber ps/nm2/km\n",
    "LTF=800;                                                         # Length of transmission fiber in km\n",
    "DTF=Sc*(lambdaa-lambda0);                                         # Dispersion at 1560 nm in ps/nm/km\n",
    "\n",
    "# The accumulated dispersion of the DCF\n",
    "DLDCF=1100-DTF*LTF;                                              # The accumulated dispersion of the DCF in ps/nm\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n The accumulated dispersion of the DCF should be less than \",int(DLDCF),\" ps/nm\"\n"
   ]
  }
 ],
 "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
