{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 10:Nonlinear Effects in Fibers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.1:pg-429"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Nonlinear coefficient =  1.267  W**-1m**-1 \n"
     ]
    }
   ],
   "source": [
    "# Example 10.1\n",
    "# Calculation of the non linear coeffifient.\n",
    "# Page no 429\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "n2=2.5*10**-20;                      # Kerr coefficient\n",
    "lambdaa=1550*10**-9;                 # Wavelength\n",
    "A=80*10**-12;                       # Effective area\n",
    "\n",
    "\n",
    "\n",
    "# Non linear coeffifient\n",
    "g=(n2*2*math.pi)/(lambdaa*A); \n",
    "g=g*10**3;\n",
    "\n",
    "\n",
    "#Displaying results in the command window            \n",
    "print \"\\n Nonlinear coefficient = \",round(g,3),\" W**-1m**-1 \"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.2:pg-431"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The lower limit on the effective area of the fiber  =  43.62  micrometer**2\n",
      "\n",
      " The effective area should be greater than 43.62 Î¼m2 to have the peak nonlinear phase shift less than or equal to 0.5 rad.\n"
     ]
    }
   ],
   "source": [
    "# Example 10.2\n",
    "# Calculation of the lower limit on the effective area of the fiber.\n",
    "# Page no 431\n",
    "\n",
    "\n",
    "\n",
    "import math\n",
    "#Given data\n",
    "\n",
    "c=3*10**8;                # Velocity of light\n",
    "tl=1000*10**3;            # Total length\n",
    "asp=100*10**3;             # Amplifier spacing\n",
    "alpha=0.046*10**-3;       # Loss coefficient\n",
    "L=100*10**3;\n",
    "n2=2.5*10**-20;          # Kerr coefficient\n",
    "p=0;                    # Peak power at the fiber input\n",
    "lambdaa=1550*10**-9;      # Operating frequency\n",
    "\n",
    "# The peak power required to form a soliton\n",
    "Le=(1-math.exp(-alpha*L))/alpha;\n",
    "n=tl/asp;\n",
    "p=10**(p/10);\n",
    "r=0.5/(Le*p);\n",
    "A=(2*math.pi*n2)/(lambdaa*r);\n",
    "A=A*10**12;\n",
    "\n",
    "# Displaying results in the command window            \n",
    "print \"\\n The lower limit on the effective area of the fiber  = \",round(A*10**-2,2),\" micrometer**2\"\n",
    "print \"\\n The effective area should be greater than 43.62 Î¼m2 to have the peak nonlinear phase shift less than or equal to 0.5 rad.\"\n",
    "\n",
    "\n",
    "# The answers vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.3:pg-435"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The peak power required to form a soliton =  2.4  mW\n"
     ]
    }
   ],
   "source": [
    "# Example 10.3\n",
    "# Calculation of the peak power required to form a soliton\n",
    "# Page no 435\n",
    "\n",
    "import math\n",
    "from sympy.mpmath import asech\n",
    "\n",
    "#Given data\n",
    "\n",
    "b=-21*10**-27;       # FWHM of a fundamental soliton\n",
    "Tf=50*10**-12;       # Fiber dispersion coefficient\n",
    "r=1.1*10**-3;        # Nonlinear coefficient\n",
    "\n",
    "# The peak power required to form a soliton\n",
    "Th=asech(math.sqrt(0.5));\n",
    "f=2*Th;\n",
    "T0=Tf/f;\n",
    "n=(math.sqrt(-b))/T0;\n",
    "P=(n**2)/r;\n",
    "#P=P*10**2;\n",
    "\n",
    "\n",
    "# Displaying results in the command window            \n",
    "print \"\\n The peak power required to form a soliton = \",round(P*10**2,1),\" mW\"\n",
    "\n",
    "# Answer is wrong in book\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.4:pg-444"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " XPM efficiency =  3.567  *10**-3\n"
     ]
    }
   ],
   "source": [
    "# Example 10.4\n",
    "# Calculation of the peak power required to form a soliton\n",
    "# Page no 444\n",
    "\n",
    "\n",
    "import math\n",
    "# Given data\n",
    "\n",
    "c=3*10**8;                # Velocity of light\n",
    "S=0.06*10**3;            # Dispersion slope\n",
    "D=17*10**-6;             # Dispersion coefficient\n",
    "lambdaa=1550*10**-9;     # Signal Wavelength\n",
    "lc=1550*10**-9;         # Signal Wavelength\n",
    "lp=1549.6*10**-9;       # Pump wavelength\n",
    "l=50*10**3;             # Length\n",
    "r=2*math.pi*10**10;\n",
    "alpha=0.046*10**-3;      # Loss coefficient\n",
    "\n",
    "# The peak power required to form a soliton\n",
    "b3=S*(lambdaa**2/(2*math.pi*c))+D*(lambdaa**3/(2*math.pi**2*c**2));\n",
    "b2=-(D*lambdaa**2)/(2*math.pi*c);\n",
    "o=2*math.pi*(c/lp-c/lc);\n",
    "d=(b2*o)+(b3*o**2)/2;\n",
    "n=alpha**2/alpha**2*r*4*d**2*(1+(4*(math.sin(r*d*l))**2*math.e**(-alpha*l))/(1-math.e**(-alpha*l)**2));\n",
    "n=n*10**-18;\n",
    "# Displaying results in the command window            \n",
    "print \"\\n XPM efficiency = \",round(n,3),\" *10**-3\"\n",
    "\n",
    "\n",
    "# The answers vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.5:pg-453"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The efficiency of the non-degenerate FWM tone at âˆ’2Î”f (beta2 = âˆ’4ps**2/km) =  3.4  X 10**(-3) \n",
      "\n",
      "\n",
      " The efficiency of the non-degenerate FWM tone at âˆ’2Î”f (beta2 = 0ps**2/km) =  1.0\n"
     ]
    }
   ],
   "source": [
    "# Example 10.5\n",
    "# Calculate the efficiency of the non-degenerate FWM tone at âˆ’2Î”f if (a) beta2 = âˆ’4ps**2/km, (b) beta2 = 0ps**2/km.\n",
    "# Page no 453\n",
    "\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "#Given data\n",
    "f=50*10**9;                                     # The bandwidth\n",
    "alpha= 0.046*10**-3;                            # The fiber loss coefficient\n",
    "L=40*10**3;                                     # The fiber length\n",
    "\n",
    "Leff=(1-math.exp(-(alpha*L)))/alpha;               # Effective fiber length\n",
    "\n",
    "# (a) Calculate the efficiency of the non-degenerate FWM tone at âˆ’2Î”f beta2 = âˆ’4ps**2/km\n",
    "bet21=-4*10**(-12);\n",
    "j=-1;\n",
    "k=0;\n",
    "l=1;\n",
    "n=j+k-l;\n",
    "\n",
    "bet1=bet21*10**(-12)/10**(3)*(2*math.pi*f)**2*n;\n",
    "\n",
    "#The efficiency of the non-degenerate FWM tone\n",
    "neta1=(alpha**2+4*math.exp(-alpha*L*10**3)*(math.sin(radians(bet1*(L*10**3)/2))/Leff**2))/(alpha**2+bet1**2)\n",
    "\n",
    "#Displaying results in the command window            \n",
    "print \"\\n The efficiency of the non-degenerate FWM tone at âˆ’2Î”f (beta2 = âˆ’4ps**2/km) = \",round(neta1*10**3,1),\" X 10**(-3) \"\n",
    "\n",
    "# (b) Calculate the efficiency of the non-degenerate FWM tone at âˆ’2Î”f beta2 = 0ps**2/km\n",
    "bet22=0*10**(-12);\n",
    "j=-1;\n",
    "k=0;\n",
    "l=1;\n",
    "n=j+k-l;\n",
    "\n",
    "bet2=bet22*10**(-12)/10**(3)*(2*math.pi*f)**2*n;\n",
    "\n",
    "#The efficiency of the non-degenerate FWM tone\n",
    "neta2=(alpha**2+4*math.exp(-alpha*L*10**3)*(sin(radians(bet2*(L*10**3)/2))/Leff**2))/(alpha**2+bet2**2);\n",
    "\n",
    "#Displaying results in the command window            \n",
    "print \"\\n\\n The efficiency of the non-degenerate FWM tone at âˆ’2Î”f (beta2 = 0ps**2/km) = \",round(neta2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.6:pg-469"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The nonlinear phase shift at the center of the pulse =  0.1206  rad \n",
      "\n",
      "\n",
      " Amplitude shift using first order =  1.007\n",
      "\n",
      " Non-linear shift using first order =  0.12002  rad\n",
      "\n",
      "\n",
      " Amplitude shift using second order =  1.00003\n",
      "\n",
      " Non-linear shift using second order =  0.1209  rad\n"
     ]
    }
   ],
   "source": [
    "# Example 10.6\n",
    "# to find the nonlinear phase shift at the center of the pulse. Compare the exact results with those obtained using first and second-order perturbation theory\n",
    "# Page no 469\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "P=6*10**(-3);                                    # The peak power of rectangular pulse\n",
    "L=40*10**3;                                      # Fiber of length\n",
    "Floss=0.2;                                      # The fiber loss (dB/Km)\n",
    "gamm=1.1*10**(-3);\n",
    "\n",
    "alpha=Floss/4.343;                              # Attenuation coefficient\n",
    "Zeff=(1-math.exp(-alpha*10**(-3)*L))/alpha*10**3;\n",
    "\n",
    "# The nonlinear phase shift at the center of the pulse\n",
    "phi=gamm*P*Zeff;                                # Nonlinear phase shift\n",
    "\n",
    "#Displaying results in the command window\n",
    "print \"\\n The nonlinear phase shift at the center of the pulse = \",round(phi,4),\" rad \"\n",
    "\n",
    "\n",
    "# Results using first order\n",
    "B01=math.sqrt(1+gamm**2*P**2*(Zeff)**2);                # Amplitude shift \n",
    "thet1=math.atan(gamm*P*Zeff);                        # Non-linear phase shift \n",
    "\n",
    "#Displaying results in the command window\n",
    "print \"\\n\\n Amplitude shift using first order = \",round(B01,3)\n",
    "print \"\\n Non-linear shift using first order = \",round(thet1,5),\" rad\"\n",
    "\n",
    "# Results using second order\n",
    "x=1-((gamm)**2/2*P**2*Zeff**2);\n",
    "y=gamm*P*Zeff;\n",
    "thet2=math.atan(y/x);                                # Nonlinear phase shift\n",
    "B02=x/math.cos(thet2);                               # Amplitude shift\n",
    "\n",
    "#Displaying results in the command window\n",
    "print \"\\n\\n Amplitude shift using second order = \",round(B02,5)             # Answer is varying due to round-off error\n",
    "print \"\\n Non-linear shift using second order = \",round(thet2,5),\" rad\"         # Answer is varying due to round-off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.7:pg-477"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The linear phase noise at the receiver =  1.5  rad**2 \n",
      "\n",
      " The nonlinear phase noise at the receiver =  1.6  rad**2 \n",
      "\n",
      " The total variance =  3.1  X 10**-3 rad**2 \n"
     ]
    }
   ],
   "source": [
    "# Example 10.7\n",
    "# Calculation of the variance of (a) linear phase noise, (b) nonlinear phase noise at the receiver\n",
    "# Page no 477\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "\n",
    "alpha=0.0461;                # Loss coeffient\n",
    "na=20;                      # No of amplifiers\n",
    "L=80;                       # Amplifier spacing\n",
    "tb=25*10**-12;               # Pulse width\n",
    "P=2*10**-3;                  # Peak power\n",
    "c=3*10**8;                   # Velocity of light\n",
    "lambdaa=1550*10**-9;\n",
    "n=1.5;                      # Spontaneous emission factor\n",
    "h=6.626*10**-34;             # Planck constant\n",
    "r0=1.1*10**-3;               # Nonlinear coefficient\n",
    "\n",
    "# a) linear phase noise at the receiver\n",
    "G=math.exp(alpha*L);\n",
    "f=c/lambdaa;\n",
    "R=h*f*(G-1)*n;\n",
    "E=P*tb;\n",
    "rl=(na*R)/(2*E);\n",
    "rl=rl*10**3;\n",
    "\n",
    "# (b) nonlinear phase noise at the receiver\n",
    "Le=(1-math.exp(-alpha*L))/alpha;\n",
    "rnl=((na-1)*na*(2*na-1)*R*E*r0**2*Le**2)/(3*tb**2);\n",
    "rnl=rnl*10**9;\n",
    "\n",
    "t=rl+rnl;\n",
    "\n",
    "#Displaying results in the command window            \n",
    "print \"\\n The linear phase noise at the receiver = \",round(rl,2),\" rad**2 \"\n",
    "print \"\\n The nonlinear phase noise at the receiver = \",round(rnl,2),\" rad**2 \"\n",
    "print \"\\n The total variance = \",round(t,2),\" X 10**-3 rad**2 \"\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex10.8:pg-480"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The Stokes signal power at the fiber output  =  0.1447807958  mW \n"
     ]
    }
   ],
   "source": [
    "# Example 10.8\n",
    "# Calculation of the Stokes signal power at the fiber output\n",
    "# Page no 480\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "p1=20;                       # Input power pump\n",
    "ps=-10;                      # Input Stokesâ€™s signal power\n",
    "alpha=0.08;\n",
    "L=2;                        # Length of fiber\n",
    "alpha1=0.046;\n",
    "A=40*10**-12;               # Effective area of fiber\n",
    "g=1*10**-13;                # Raman coefficient of the fiber\n",
    "\n",
    "# The Stokes signal power at the fiber output\n",
    "p1=10**(p1/10);\n",
    "ps=10**(ps/10);\n",
    "Le=(1-math.exp(-alpha*L))/alpha;\n",
    "s=(g*p1*Le)/A;\n",
    "d=alpha1*L;\n",
    "pd=ps*math.e**(-d+s);\n",
    "\n",
    "\n",
    "\n",
    "# Displaying results in the command window            \n",
    "print \"\\n The Stokes signal power at the fiber output  = \",round(pd,15),\" mW \"\n",
    "\n",
    "\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
}
