{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 07:Transmission System Design"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.1:pg-305"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The lower limit on the transmitter power =  7.23   mW\n",
      "\n",
      " The lower limit on the transmitter peak power is 7.23mW. If the transmitter peak power < 7.23mW, Q < 6.\n"
     ]
    }
   ],
   "source": [
    "# Example 7.1 \n",
    "# Compuatation of the lower limit on the transmitter power\n",
    "#\n",
    "# Page no. 305\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "q=1.6*10**-19;\n",
    "R=1;\n",
    "B=7*10**9;\n",
    "c=3*10**8;           # Velocity of light\n",
    "h=6.62*10**-34;     # Planck constant\n",
    "Q=6;\n",
    "k=1.38*10**-23;    # Boltzman constant\n",
    "T=298;\n",
    "Rl=50;\n",
    "alpha=0.046;     # Fiber loss coefficient\n",
    "L=130;           # Length\n",
    "\n",
    "\n",
    "# The lower limit on the transmitter power\n",
    "a=2*q*R*B;\n",
    "b=(4*k*T*B)/Rl;\n",
    "p=(2*math.sqrt(b)/R*Q)+((a*Q**2)/R**2);\n",
    "Pi=p*math.exp(alpha*L);\n",
    "\n",
    "#Displaying the result in command window\n",
    "print \"\\n The lower limit on the transmitter power = \",round(Pi*10**3,2),\"  mW\"\n",
    "print \"\\n The lower limit on the transmitter peak power is 7.23mW. If the transmitter peak power < 7.23mW, Q < 6.\"\n",
    "\n",
    "# The answer vary due to round off error\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.2:pg-311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Exact Q-factor if the signal is OOK =  3.7\n",
      "\n",
      " Approximate Q-factor if the signal is OOK =  3.8\n",
      "\n",
      " Exact Q-factor if the signal is PSK =  5.24\n",
      "\n",
      " Approximate Q-factor if the signal is PSK =  5.39\n"
     ]
    }
   ],
   "source": [
    "# Example no. 7.2\n",
    "# To calculate exact and approximate Q-factor if the signal is (a)OOK, (b) PSK\n",
    "# Page no. 311\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "# Given data\n",
    "lambdaa=1.55*10**(-6);                                               # Wavelength of given signal\n",
    "meanPin=1;                                                         # Mean fiber launch power in dBm\n",
    "alpha=0.2;                                                         # fiber loss in dB/km\n",
    "l=240;                                                             # fiber length in km\n",
    "neta=0.7;                                                          # quantum efficiency \n",
    "T = 290;                                                           # Tempearture in  K\n",
    "RL=100;                                                            # Length resistance in Î©\n",
    "PLOdBm = 10;                                                       # Power at local oscillator in dBm\n",
    "Be = 7.5*10**9;                                                     # Efficient bandwidth of filter in Hz\n",
    "c=3*10**8;                                                          # Speed of ligth in air in m/s\n",
    "loss=alpha*l;                                                      # Total fiber loss\n",
    "q=1.602*10**(-19);                                                  # Charge of electron\n",
    "h=6.626*10**(-34);                                                  # Planck constant\n",
    "kB=1.38*10**(-23);                                                  # Bolzman constant\n",
    "\n",
    "f=c/lambdaa;                                                        # mean frequency\n",
    "R=(neta*q)/(h*f);                                                  # Responsivity\n",
    "\n",
    "#For OOK\n",
    "Pin=10*math.log10(2)+meanPin;                                           # peak power in dBm\n",
    "P1rdBm=Pin-loss;                                                   # received peak power in dBm\n",
    "P1r=(10**(P1rdBm/10))*10**(-3);                                      # received peak power in W\n",
    "PLO=(10**(PLOdBm/10))*10**(-3);                                      # Power at local oscillator in W\n",
    "I1=2*R*math.sqrt(P1r*PLO);                                              # mean of bit 1\n",
    "sigma1=2*q*Be*R*(P1r+PLO)+(4*kB*T*Be)/RL;                          # Square of variance of bit 1\n",
    "I0=0;                                                              # mean of bit 0\n",
    "sigma0=sigma1;                                                     # Square of variance of bit 0\n",
    "Q1=(I1-I0)/(2*math.sqrt(sigma1));                                       # Exact Q-factor\n",
    "Q2=math.sqrt((neta*P1r)/(2*h*f*Be));                                    # Approximate Q-factor\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Exact Q-factor if the signal is OOK = \",round(Q1,1)\n",
    "print \"\\n Approximate Q-factor if the signal is OOK = \",round(Q2,1)\n",
    "\n",
    "# For PSK\n",
    "P1rdBm=meanPin-loss;                                               # received peak power in dBm\n",
    "P1r=(10**(P1rdBm/10))*10**(-3);                                      # received peak power in W\n",
    "I1=2*R*math.sqrt(P1r*PLO);                                              # mean of bit 1\n",
    "sigma1=2*q*Be*R*(P1r+PLO)+(4*kB*T*Be)/RL;                          # Square of variance of bit 1\n",
    "I0=-I1;                                                            # mean of bit 0\n",
    "sigma0=sigma1;                                                     # Square of variance of bit 0\n",
    "Q1=I1/math.sqrt(sigma1);                                                # Exact Q-factor\n",
    "Q2=math.sqrt((2*neta*P1r)/(h*f*Be));                                    # Approximate Q-factor\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Exact Q-factor if the signal is PSK = \",round(Q1,2)\n",
    "print \"\\n Approximate Q-factor if the signal is PSK = \",round(Q2,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.3:pg-315"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Distance =  10.0  Km \n"
     ]
    }
   ],
   "source": [
    "# Example 7.3\n",
    "# Calculation of the distance.\n",
    "# Page no 315\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "\n",
    "#Given data\n",
    "B1=2.5*10**9;                      # Mean optical power\n",
    "B2=10*10**9;                      # Split loss\n",
    "L1=160*10**3;                       # Total system margin\n",
    "\n",
    "\n",
    "\n",
    "# Distance\n",
    "L2=((B1/B2)**2*L1); \n",
    "L2=L2*10**-3;\n",
    "\n",
    "\n",
    "\n",
    "#Displaying results in the command window            \n",
    "print \"\\n Distance = \",round(L2),\" Km \"\n",
    "\n",
    "\n",
    "# The answers vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.4:pg-321"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " OSNR is =  15.18  dB\n",
      "\n",
      " Q-factor is =  7.72\n"
     ]
    }
   ],
   "source": [
    "# Example 7.4 \n",
    "# Compuatation of (a) OSNR in a reference bandwidth of 0.1 nm, (b) Q-factor.\n",
    "# Page no. 321\n",
    "\n",
    "import math\n",
    "\n",
    "# Given data\n",
    "\n",
    "f=10*10**9;\n",
    "n=1.5;                                                   #Refractive index\n",
    "h=6.63*10**-34;                                           # Planck constant\n",
    "c=3*10**8;                                                # Velocity of light\n",
    "lambdaa=1.55*10**-6;                                       #\n",
    "q=1.6*10**-19;                                            # Electron charge\n",
    "d=0.1*10**-9;                                             # Reference bandwidth\n",
    "alpha=0.0461;                                            # Fiber loss coefficient\n",
    "L=80;                                                    # Spacing\n",
    "Pi=-3;                                                   # Mean fiber launch power\n",
    "N=80;                                                    # Identical amplifers\n",
    "fe=7*10**9;                                               # Electrical filter bandwidth\n",
    "\n",
    "\n",
    "# Signal calculation\n",
    "df=-((c*d)/lambdaa**2);                                    #Reference frequency\n",
    "G=math.exp(alpha*L);\n",
    "G1=10*math.log10(G);\n",
    "N1=10*math.log10(N);\n",
    "Fn=2*n;                                                  #Noise figure\n",
    "Fn=10*math.log10(Fn);\n",
    "\n",
    "O=Pi-N1-G1-Fn+58;                                       #OSNR\n",
    "Pi1=2*10**(-(3/10.0));                                     # Peak power in mW\n",
    "f=c/lambdaa;\n",
    "Q=math.sqrt((Pi1*10**-3)/(4*N*n*h*f*(G-1)*fe));               #Q-factor\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n OSNR is = \",round(O,2),\" dB\"\n",
    "print \"\\n Q-factor is = \",round(Q,2)\n",
    "\n",
    "# The answer vary due to round off error\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.5:pg-325"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The transmission distance is =  19709.0  km\n"
     ]
    }
   ],
   "source": [
    "# Example 7.5 \n",
    "# Compuatation of the transmission distance\n",
    "# Page no. 325\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "\n",
    "fl=0.2                  # Fiber loss\n",
    "L=100;                  # Amplifeir spacing\n",
    "n=1.4;\n",
    "h=6.63*10**-34;          # Planck constant\n",
    "c=3*10**8;               # Velocity of light\n",
    "lambdaa=1.55*10**-6;\n",
    "\n",
    "q=1.6*10**-19;          # Electron charge\n",
    "R=0.9;\n",
    "d=0.1*10**-9;\n",
    "alpha=0.0461;\n",
    "L=100;                # Spacing\n",
    "Pi=-3;                # Mean fiber launch power\n",
    "#N=80;               # Identical amplifers\n",
    "fe=7*10**9;            #  Electrical filter bandwidth\n",
    "q=6;\n",
    "B=5*10**9;\n",
    "\n",
    "\n",
    "# The transmission distance\n",
    "l=fl*L;\n",
    "G=10**(l/10.0);\n",
    "f=c/lambdaa;\n",
    "# r=N*n*h*f*(G-1);\n",
    "Pi=10**(-(2/10.0));\n",
    "N=Pi/(q**2*n*h*f*(G-1)*B);\n",
    "Td=N*L;\n",
    "Td=Td*10**-3;\n",
    "\n",
    "#Displaying the result in command window\n",
    "print \"\\n The transmission distance is = \",round(Td),\" km\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.6:pg-327"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Q factor=  8.017\n"
     ]
    }
   ],
   "source": [
    "# Example 7.6 \n",
    "# Compuatation of the Q-factor.\n",
    "\n",
    "# Page no. 327\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "alpha=0.18;          # Fiber loss coefficient\n",
    "L=190;              # Fiber length\n",
    "G=20;               # Gain of preamplifier\n",
    "lambdaa=1.55*10**-6; # Operating wavelength\n",
    "h=6.63*10**-34;     # Planck constant\n",
    "n=1.409;    \n",
    "G1=10**(G/10.0);  \n",
    "f0=20*10.0**9; \n",
    "R=1.1;   \n",
    "q=1.6*10.0**-19;\n",
    "fe=7.5*10.0**9;\n",
    "Pi=1;              # Input power\n",
    "c=3*10.0**8;          # Velocity of light\n",
    "k=1.38*10**-23;\n",
    "T=298;\n",
    "Rl=200;\n",
    "\n",
    "# The Q factor\n",
    "l=alpha*L;\n",
    "Po=Pi-l+G;\n",
    "Po=10**(Po/10.0)*10**-3;\n",
    "f=c/lambdaa;\n",
    "r=h*f*(G1-1)*n;\n",
    "fn=2*n;\n",
    "fn=10**(fn/10.0);\n",
    "I1=R*Po+2*r*f0;\n",
    "I0=2*R*r*f0;\n",
    "o1=(2*q*I1*fe)+((4*k*T*fe)/Rl)+(2*R**2*r*(2*Po*fe+r*(2*f0-fe)*fe));\n",
    "o2=(2*q*I0*fe)+((4*k*T*fe)/Rl)+(2*R**2*r**2*(2*f0-fe)*fe);\n",
    "Q=(I1-I0)/(math.sqrt(o1)+math.sqrt(o2));\n",
    "\n",
    "#Displaying the result in command window\n",
    "\n",
    "print \"\\n Q factor= \",round(Q,3)\n",
    "\n",
    "# The answer vary due to round off error\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.7:pg-329"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The optimum amplifier configuration by choosing Amp2 as the first amplifier =  5.531  dB\n",
      "\n",
      " The optimum amplifier configuration by choosing Amp1 as the first amplifier =  7.076  dB\n"
     ]
    }
   ],
   "source": [
    "# Example 7.7 \n",
    "# Compuatation of the optimum amplifier configuration\n",
    "\n",
    "# Page no. 329\n",
    "\n",
    "import math\n",
    "#Given data\n",
    "\n",
    "G1=8.0;           # Amplifier gain 1\n",
    "G2=16.0;          # Amplifier gain 2\n",
    "fn1=7.0;          # Noise figure of amplifier 1\n",
    "fn2=5.5;        # Noise figure of amplifier 2\n",
    "H=7.0;            # Insertion loss of the DCF\n",
    "#N=80.0;         # Identical amplifers\n",
    "fe=7*10.0**9;      #  Electrical filter bandwidth\n",
    "# q=6;\n",
    "\n",
    "\n",
    "# The optimum amplifier configuration\n",
    "\n",
    "fn1=10**(fn1/10);\n",
    "fn2=10**(fn2/10);\n",
    "G2=10**(G2/10);\n",
    "H=10**(H/10);\n",
    "Fna=fn2+(fn1/(G2*H));\n",
    "Fna=10*math.log10(Fna);\n",
    "G=G2+G1+H;\n",
    "Fnb=fn1+(fn2/(G1*H));\n",
    "\n",
    "Fnb=10*math.log10(Fnb);\n",
    "\n",
    "#Displaying the result in command window\n",
    "print \"\\n The optimum amplifier configuration by choosing Amp2 as the first amplifier = \",round(Fna,3),\" dB\"\n",
    "print \"\\n The optimum amplifier configuration by choosing Amp1 as the first amplifier = \",round(Fnb,3),\" dB\"\n",
    "\n",
    "# The answer vary due to round off error\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex7.9:pg-331"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " The length of the DCF =  13.03  km\n",
      "\n",
      " Gain G2 =  8.52  dB\n",
      "\n",
      " Q factor=  6.2\n"
     ]
    }
   ],
   "source": [
    "# Example 7.9 \n",
    "# Compuatation of the (a) the length of the DCF (b) the gain G2 and (c) the Q-factor.\n",
    "\n",
    "# Page no. 331\n",
    "\n",
    "import math\n",
    "\n",
    "#Given data\n",
    "b=-21*10.0**-27;\n",
    "L=100.0*10**3;\n",
    "Lt=100.0;\n",
    "l=0.18;               # Loss\n",
    "l1=0.5;               # Dispersion coefficients of the TF\n",
    "G1=16.0;                # Amplifier gain\n",
    "p=-2;                 # Mean transmitter output power\n",
    "fe=7*10.0**9;\n",
    "c=3*10.0**8;             # Velocity of light\n",
    "h=6.62*10**-34;       # Planck constant\n",
    "fn1=5.5;             # Noise figure of amplifier 1\n",
    "fn2=7.5;             # Noise figure of amplifier 2\n",
    "lambdaa=1.55*10**-6;\n",
    "bd=145.0*10**-27;      # Dispersion coefficients of the DCF\n",
    "\n",
    "# (a) The length of the DCF\n",
    "st=b*L;\n",
    "sd=-0.9*st;\n",
    "Ld=sd/bd;\n",
    "Ld=Ld*10**-3;\n",
    "# (b) Gain G2\n",
    "Ht=l*Lt;\n",
    "Hd=l1*Ld;\n",
    "G2=Ht+Hd-G1;\n",
    "\n",
    "# (c) Q factor\n",
    "Ge=G1+G2+-Hd;\n",
    "Ge=10**(Ge/10);\n",
    "fn1=10**(fn1/10);\n",
    "fn2=10**(fn2/10);\n",
    "G1=10**(G1/10);\n",
    "Hd=10**(-Hd/10);\n",
    "Fe=fn1+(fn2/(G1*Hd))-(1/G1);\n",
    "f=c/lambdaa;\n",
    "r=70*h*f*(((Ge*Fe)-1)/2.0);\n",
    "Pi=2*10**(p/10.0)*10**-3;\n",
    "Q=math.sqrt(Pi/(4*r*fe));\n",
    "\n",
    "\n",
    "#Displaying the result in command window\n",
    "print \"\\n The length of the DCF = \",round(Ld,2),\" km\"\n",
    "print \"\\n Gain G2 = \",round(G2,2),\" dB\"\n",
    "print \"\\n Q factor= \",round(Q,1)\n",
    "\n",
    "# The answer vary due to round off error\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
}
