{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 Switched communication systems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.2, page no 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "maximum auxillary current is:10.00 mA\n",
      "\n",
      "MMF in the auxillary winding is:2.00AT \n",
      "\n",
      "MMF in main winding is:40.00 AT \n",
      "\n",
      "net MMF required in main winding is:44.00 AT \n",
      "\n",
      "operating current needed is:4.40 mA \n",
      "\n",
      "working voltage is:2.84 volts \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "#given\n",
    "Io=4*10**-3 #rqueired operating current\n",
    "N1=10000 #no of turns in the main winding\n",
    "R1=645 #resistence of the main winding in ohms\n",
    "N2=200 #no of turns in auxillary winding\n",
    "B=2 #spacing bias\n",
    "Iaux=B/N2 #maximum auxillary current\n",
    "print \"maximum auxillary current is:%0.2f mA\\n\"%(Iaux*1e3)\n",
    "MMFaux=N2*Iaux #MMF in the auxillary winding\n",
    "print \"MMF in the auxillary winding is:%0.2fAT \\n\"%(MMFaux)\n",
    "MMFop=Io*N1 #operating MFF in main winding\n",
    "print \"MMF in main winding is:%0.2f AT \\n\"%(MMFop)\n",
    "MMFnet=MMFop+(0.1*MMFop) #net MMF required in main winding\n",
    "print \"net MMF required in main winding is:%0.2f AT \\n\"%(MMFnet)\n",
    "Iop=MMFnet/N1 #operating current needed\n",
    "print \"operating current needed is:%0.2f mA \\n\"%(Iop*1e3)\n",
    "V=Iop*R1 #working voltage in volts\n",
    "print \"working voltage is:%0.2f volts \\n\"%(V)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.3,page no 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Busy hour calling rate is:1.20 \n",
      "\n",
      "Rate of traffic flow is 250.00 traffic unit \n"
     ]
    }
   ],
   "source": [
    "#given\n",
    "C=6000#Tatol no of call in busy hour\n",
    "SC=5000#no of subscribers\n",
    "CR=C/SC#busy hour calling rate\n",
    "print \"Busy hour calling rate is:%0.2f \\n\"%(CR)\n",
    "T=2.5/60#avarage duration of calls in hours\n",
    "\n",
    "A=C*T#rate of traffic flow\n",
    "print \"Rate of traffic flow is %0.2f traffic unit \"%(A)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.4,page no 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "maxixmum current is 33.33 mamps \n",
      "\n",
      "operate lag is 1.83 msec \n",
      "\n",
      "release lag is 2.85 msec \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import log\n",
    "#given\n",
    "L=3#relay inductance in henry\n",
    "R=1500#relay resistance in ohm\n",
    "Io=20e-3#oparating current in amps\n",
    "Ir=8e-3#release current in amps\n",
    "\n",
    "V=50#supply volatage in volts\n",
    "Im=V/R#maxixmum current in amps\n",
    "print \"maxixmum current is %0.2f mamps \\n\"%(Im*1e3)\n",
    "to=(L/R)*log(1/(1-(Io/Im)))#operate lag in sec\n",
    "print \"operate lag is %0.2f msec \\n\"%(to*1000)\n",
    "tr=(L/R)*log(Im/Ir)#release lag in sec\n",
    "print \"release lag is %0.2f msec \\n\"%(tr*1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.4.1,page no 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)\n",
      "periods per character is:150.00 msec\n",
      "\n",
      "period per element is:20.00 msec\n",
      "\n",
      "speed is:50.00 bauds\n",
      "\n",
      "\n",
      "(b)\n",
      "periods per character is:100.00 msec\n",
      "\n",
      "period per element is:13.33 msec\n",
      "\n",
      "speed is 75.00 bauds\n",
      "\n",
      "\n",
      "(c)\n",
      "periods per character is:100.00 msec\n",
      "\n",
      "period per element is:10.00 msec\n",
      "\n",
      "speed is 100.00 bauds\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#given\n",
    "#a\n",
    "C_S1=20/3#speed in characters per second\n",
    "P_C1=1/C_S1#periods per character\n",
    "print \"(a)\\nperiods per character is:%0.2f msec\\n\"%(P_C1*1e3)\n",
    "E_C1=7.5#elements per character\n",
    "P_E1=P_C1/E_C1#period per element\n",
    "print \"period per element is:%0.2f msec\\n\"%(P_E1*1e3)\n",
    "Sb1=1/P_E1#speed in bauds\n",
    "print \"speed is:%0.2f bauds\\n\\n\"%(Sb1)\n",
    "#b\n",
    "C_S2=10#speed in characters per second\n",
    "P_C2=1/C_S2#periods per character\n",
    "print \"(b)\\nperiods per character is:%0.2f msec\\n\"%(P_C2*1e3)\n",
    "E_C2=7.5#elements per character\n",
    "P_E2=P_C2/E_C2#period per element\n",
    "print \"period per element is:%0.2f msec\\n\"%(P_E2*1e3)\n",
    "Sb2=1/P_E2#speed in bauds\n",
    "print \"speed is %0.2f bauds\\n\\n\"%( Sb2)\n",
    "#c\n",
    "C_S3=10#speed in characters per second\n",
    "P_C3=1/C_S3#periods per character\n",
    "print \"(c)\\nperiods per character is:%0.2f msec\\n\"%(P_C3*1e3)\n",
    "E_C3=10#elements per character\n",
    "P_E3=P_C3/E_C3#period per element\n",
    "print \"period per element is:%0.2f msec\\n\"%(P_E3*1e3)\n",
    "Sb3=1/P_E3#speed in bauds\n",
    "print \"speed is %0.2f bauds\\n\"%(Sb3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.5,page no 127"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total inductance is 0.05 H \n",
      "\n",
      "maximum current is 10.00 mA \n",
      "\n",
      "operating current is 5.00 mA \n",
      "\n",
      "operate lag is 0.35 msec \n",
      "\n"
     ]
    }
   ],
   "source": [
    "#given\n",
    "N=1000#no of turns\n",
    "L1=5e-8#inductance per turn\n",
    "L=N**2*L1#total inductance\n",
    "print \"total inductance is %0.2f H \\n\"%(L)\n",
    "R=100#resistance of winding in ohm\n",
    "MMF=5#operating MMF in amp. turn\n",
    "V=1#voltage of received signal in volts\n",
    "Im=V/R#maximum current\n",
    "print \"maximum current is %0.2f mA \\n\"%(Im*1e3)\n",
    "Io=MMF/N#operating current\n",
    "print \"operating current is %0.2f mA \\n\"%(Io*1e3)\n",
    "to=(L/R)*log(1/(1-(Io/Im)))#operate lag\n",
    "print \"operate lag is %0.2f msec \\n\"%(to*1e3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.6,page no 128"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Busy hour calling rate is:1.60 \n",
      "\n",
      "Rate of traffic flow is 693.33 traffic unit \n"
     ]
    }
   ],
   "source": [
    "#given\n",
    "S=10000#no of subscribers\n",
    "C=16000#Tatol no of call in busy hour\n",
    "CR=C/S#busy hour calling rate\n",
    "print \"Busy hour calling rate is:%0.2f \\n\"%(CR)\n",
    "T=2.6#avarage duration of calls in min\n",
    "\n",
    "A=C*(T/60)#rate of traffic flow\n",
    "print \"Rate of traffic flow is %0.2f traffic unit \"%(A)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.7,page no 135"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "duration of each element is:10.00 msec\n",
      "\n",
      "speed is 100.00 bauds\n",
      "\n",
      "total possible combinations are:128.00\n"
     ]
    }
   ],
   "source": [
    "#given\n",
    "N=7#no of character elements\n",
    "E_C=10#elements per character (1+7+1+1)\n",
    "To=100e-3#duration of one character\n",
    "Te=To/E_C#duration of each element\n",
    "print \"duration of each element is:%0.2f msec\\n\"%(Te*1e3)\n",
    "Sb=1/Te#speed in bauds\n",
    "print \"speed is %0.2f bauds\\n\"%(Sb)\n",
    "C=2**N#total possible combinations\n",
    "print \"total possible combinations are:%0.2f\"%(C)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8,page no 129"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total no of call in busy hour is:1500.00 calls per Hour\n",
      "\n",
      "Busy hour calling rate is:1.50 \n",
      "\n",
      "grade of service is: 0.02\n"
     ]
    }
   ],
   "source": [
    "#given\n",
    "S=1000#no of subscribers\n",
    "T=2.4/60#avarage duration of calls in hours\n",
    "A=60#rate of traffic flow\n",
    "C=A/T#Tatol no of call in busy hour\n",
    "print \"Total no of call in busy hour is:%0.2f calls per Hour\\n\"%(C)\n",
    "CR=C/S#busy hour calling rate\n",
    "print \"Busy hour calling rate is:%0.2f \\n\"%(CR)\n",
    "SCL=30#no of call lost per hour\n",
    "\n",
    "B=SCL/(C+SCL)#grade of service\n",
    "print \"grade of service is: %0.2f\"%(B)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.9,page no 129"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "grade of service is: 2.00e-03\n",
      "\n",
      "traffic lost is: 1.80e-03\n"
     ]
    }
   ],
   "source": [
    "from math import factorial\n",
    "#given\n",
    "N=5#no of switches\n",
    "A=0.9#traffic offered \n",
    "#grade of service B=(A**N/N!)/(1+A+A**2/2!+A**3/3!+...+A**N/N!)\n",
    "#here\n",
    "B=(A**N/factorial(N))/(1+A+(A**2/factorial(2))+(A**3/factorial(3))+(A**4/factorial(4))+(A**5/factorial(5)))\n",
    "print \"grade of service is: %0.2e\\n\"%(B)\n",
    "Tl=A*B#traffic lost\n",
    "print \"traffic lost is: %0.2e\"%(Tl)"
   ]
  }
 ],
 "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}