{
 "metadata": {
  "name": "",
  "signature": "sha256:c41fce225679ac457a37b8135a3b4343e35e5bc26e64b35427fb89f090d39c55"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chepter 8: Digital links"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.1, Page Number: 287"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "system_margin = 6                           # (dB)\n",
      "alpha = 3.5                                 #attenuation (dB/Km)\n",
      "L =6                                        #Length of transmission path (Km)\n",
      "lc = 1                                      #connector loss (dB)\n",
      "\n",
      "#calculation\n",
      "PT = 2*lc+alpha*L+system_margin             #total optical power loss(dB)\n",
      "\n",
      "#result\n",
      "print \"Total optical power loss = \" , round(PT) ,\"dB\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Total optical power loss =  29.0 dB\n"
       ]
      }
     ],
     "prompt_number": 34
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.2, Page Number: 288"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "Ps = 3                                       #laser output (dBm)\n",
      "APD_sen = -32                                #APD sensitivity (dBm)\n",
      "lsc = 1                                      #source connectorloss (dB)\n",
      "ljc = 2*4                                    #two (jumper+connector loss) (dB)\n",
      "alpha = 0.3                                  #attenuation (dB/Km)\n",
      "L = 60                                       #cable length (Km)\n",
      "cable_att = alpha*60                         #cable attenuation (dB)\n",
      "lrc = 1                                      #receiver connector loss (dB)\n",
      "\n",
      "#calculation\n",
      "Allowed_Loss = Ps-APD_sen                                  # (dB)\n",
      "system_margin = Allowed_Loss-lsc-ljc-cable_att-lrc         #system margin(dB)\n",
      "\n",
      "#result\n",
      "print \"Allowed loss between light source and photodetector = \",Allowed_Loss,\"dB\"\n",
      "print \"The Final power margin = \" , round(system_margin) , \"dB\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Allowed loss between light source and photodetector =  35 dB\n",
        "The Final power margin =  7.0 dB\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.3, Page Number: 291"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "t_tx = 15*10**-9                            #transmitter rise time(ns)\n",
      "t_mat = 21*10**-9                           #material dispersion related rise time(ns)\n",
      "t_mod = 3.9*10**-9                          #rise time resulting from modal dispersion(ns)\n",
      "t_rx = 14*10**-9                            #receiver rise time(ns)\n",
      "\n",
      "#calculation\n",
      "tsys = math.sqrt(t_tx**2+t_mat**2+t_mod**2+t_rx**2)     #link rise time(ns)\n",
      "\n",
      "#result\n",
      "print \"Link rise time = \" , round(tsys*10**9),\"ns\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Link rise time =  30.0 ns\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.4, Page Number: 292"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "t_tx = 25*10**-12                             #transmission rise time (sec)\n",
      "t_GVD = 12*10**-12                            #GVD rise time (sec)\n",
      "t_rx = 0.14*10**-9                            #receiver rise time (sec)\n",
      "\n",
      "#calculation\n",
      "tsys = math.sqrt(t_tx**2+t_GVD**2+t_rx**2)    #Link rise time(ns)\n",
      "\n",
      "#result\n",
      "print \"System rise time = \" , round(tsys*10**9,2) , \"ns\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "System rise time =  0.14 ns\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.5, Page Number: 306"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "bit_error_dur = 1*10**-3                       #bit-corrupting burst noise duration (ms)\n",
      "B = 10*10**3                                   #data rate (kb/sec)\n",
      "\n",
      "#calculation\n",
      "N = B*bit_error_dur                            #number of bits affected by by burst error (MB/s)\n",
      "\n",
      "#result\n",
      "print \"Number of bits affected by a burst error = \" , round(N) , \"Mb/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of bits affected by a burst error =  10.0 Mb/s\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.6, Page Number: 308"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "x=1\n",
      "\n",
      "#calculation\n",
      "polynomial = str(x**7)+\"0\"+str(x**5)+\"0\"+\"0\"+str(x**2)+str(x)+\"1\"     #generator polynommial\n",
      "\n",
      "#result\n",
      "print \"The generator polynomial to 8-bit binary represantation = \",polynomial"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The generator polynomial to 8-bit binary represantation =  10100111\n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.8, Page Number: 309"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "N = 32.0                                    #number of CRC\n",
      "\n",
      "#calculation\n",
      "Ped = 1.0-(1.0/(2.0**N))                    #burst error\n",
      "\n",
      "#result\n",
      "print \"Burst error detected by CRC = \" , round(Ped*100,8), \"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Burst error detected by CRC =  99.99999998 %\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.9, Page Number: 309"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#variable declaration\n",
      "S = 8                                       #Reed-Solomon code with 1 byte\n",
      "n = (2**S-1)                                #length of coded sequence\n",
      "k = 239.0                                   #length of message sequence\n",
      "\n",
      "#calculation\n",
      "r = n-k                                     #number of redundent bytes\n",
      "over_head = (r/k)                           #overhead %\n",
      "\n",
      "#result\n",
      "print \"Number of redundent bytes r = \" ,round(r),\"bytes\"\n",
      "print \"Percent overhead = \" , round(over_head*100) , \"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of redundent bytes r =  16.0 bytes\n",
        "Percent overhead =  7.0 %\n"
       ]
      }
     ],
     "prompt_number": 7
    }
   ],
   "metadata": {}
  }
 ]
}