{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 16 : Integrated Circuits as Analog System Building blocks"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.1, Page No 621"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "\n",
      "#Caption:Fourth Order Butterworth Filter\n",
      "#Given Data\n",
      "fo=1.0\t\t#Cutoff Frequency in Hz\n",
      "#For n = 4\n",
      "k1=0.765\n",
      "k2=1.848\n",
      "Av1 = 3-k1\n",
      "Av2 = 3-k2\n",
      "\n",
      "#Calculations\n",
      "print('For a fourth order Buttworth filter we cacade 2 second order Buttworth filter with parameters R1 R2 R1d R2d R C')\n",
      "#we arbitrarily choose\n",
      "R1=10.0  \t#in K\n",
      "print(\"The value of R1= %.2f K \" %R1)\n",
      "#Av1=(R1+R1d)/R1\n",
      "R1d=(Av1*R1)-R1\n",
      "print(\"The value of R1d= %.2f K \" %R1d)\n",
      "\n",
      "R2 = 10.0      #in K\n",
      "print(\"The value of R2= %.2f K \" %R2)\n",
      "R2d=(Av2*R2)-R2\n",
      "print(\"The value of R2d= %.2f K \" %R2d)\n",
      "\n",
      "\n",
      "#Results\n",
      "#To satisfy fo = 1/(2*math.pi*r*c) = 1kHz\n",
      "R=1#in K\n",
      "C = 1/(2*math.pi*R*fo)\n",
      "print(\"The value of R = %.2f K \" %R)\n",
      "print(\"The value of C = %.2f microF \" %C)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "For a fourth order Buttworth filter we cacade 2 second order Buttworth filter with parameters R1 R2 R1d R2d R C\n",
        "The value of R1= 10.00 K \n",
        "The value of R1d= 12.35 K \n",
        "The value of R2= 10.00 K \n",
        "The value of R2d= 1.52 K \n",
        "The value of R = 1.00 K \n",
        "The value of C = 0.16 microF \n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.2, Page No 626"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#initialisation of variables\n",
      "Ao=50.0    #Gain\n",
      "fo=160.0   #center frequency\n",
      "B=16.0     #Bandwidth in Hz\n",
      "C1=0.1     #in microF\n",
      "C2=0.1     #in microF\n",
      "\n",
      "#Required Formulae\n",
      "\n",
      "#Calculations\n",
      "Q=fo/B\n",
      "R1=(1000*Q)/(Ao*2*math.pi*fo*C1)\n",
      "R3=(1000*Q)/((2*math.pi*fo)*(C1*C2/(C1+C2)))\n",
      "#As C is in microFarad to compensate for it 1000 is multiplied\n",
      "#Let r = R'\n",
      "r=(10**6)/((2*math.pi*fo)**2*R3*C1*C2)\n",
      "R2=(R1*r)/(R1-r)\n",
      "\n",
      "#Results\n",
      "print(\"The value of R1= %.2f K \" %R1)\n",
      "print(\"The value of R3= %.2f K \" %R3)\n",
      "print(\"The value of r= %.2f ohm \" %(r*10**3))\n",
      "print(\"The value of R2= %.2f ohm \" %(R2*10**3))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R1= 1.99 K \n",
        "The value of R3= 198.94 K \n",
        "The value of r= 497.36 ohm \n",
        "The value of R2= 663.15 ohm \n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.3 Page No 638"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#initialisation of variables\n",
      "\n",
      "Avo=-25.0\n",
      "Vagc=20.0   #in V\n",
      "Vcc=6.0   #in V\n",
      "hfe=50.0 \n",
      "rbb=50.0  #in ohm\n",
      "Cs=5.0     #in pF\n",
      "Cl=5.0    #in pF\n",
      "Ie1=1.0  #in mA\n",
      "ft=900.0 #in MHz\n",
      "Vt=26.0 #in V\n",
      "n=2.0  #eeta\n",
      "#re2 = infinity\n",
      "\n",
      "#Calculations\n",
      "#Since Vagc=0 , transistor Q2 is in cut off region and collector current of Q1 flows through Q3....So\n",
      "Ie2=0\n",
      "Ie3=1.0    #in mA\n",
      "re3 = (n*Vt)/Ie3   #in ohm\n",
      "print(\"The value of re3 = %.2f ohm \" %re3)\n",
      "gm = (Ie1)/Vt     #in ohm^-1\n",
      "print(\"The value of gm = %.2f ohm^-1 \" %gm)\n",
      "rbe=hfe/gm\n",
      "print(\"The value of rbe = %.2f ohm \" %rbe)\n",
      "Ce=gm/(2*math.pi*ft*10**-6)\n",
      "print(\"The value of Ce = %.2f pF \" %Ce)\n",
      "a3=1.0  #we make an assumption that alpha is one\n",
      "s=0\n",
      "#Av0 = -((a3*gm)/(re3*rbb))*(1/(((1/rbb)+(1/rbe)+(s*Ce))*((1/re3)+(s*Cs))*((1/Rl)+(s*(Cs+Cl)))))\n",
      "#From here we can find Rl\n",
      "k = -((a3*gm)/(re3*rbb))*(1/(((1/rbb)+(1/rbe)+(s*Ce))*((1/re3)+(s*Cs))))\n",
      "Rl=Avo/k\n",
      "print(\"The value of Rl = %.2f ohm \" %Rl)\n",
      "#C is in picoFarad so to compensate the whole equation some constants are multiplied\n",
      "f1 = 1.0/(2*math.pi*Rl*(Cs+Cl)*10**-6)\n",
      "\n",
      "#Results\n",
      "print(\"The value of f1 = %.2f MHz \" %f1)\n",
      "f2 = 1.0/(2*math.pi*Ce*10**-6*((rbe*rbb)/(rbe+rbb)))\n",
      "print(\"The value of f2 = %.2f MHz \" %f2)\n",
      "f3 = 1.0/(2*math.pi*Cs*re3*10**-6)\n",
      "print(\"The value of f3 = %.2f MHz \" %f3)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of re3 = 52.00 ohm \n",
        "The value of gm = 0.04 ohm^-1 \n",
        "The value of rbe = 1300.00 ohm \n",
        "The value of Ce = 6.80 pF \n",
        "The value of Rl = 675.00 ohm \n",
        "The value of f1 = 23.58 MHz \n",
        "The value of f2 = 486.00 MHz \n",
        "The value of f3 = 612.13 MHz \n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.4a, Page No 656"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "\n",
      "Vbb = 1.15    #in V\n",
      "Vee=5.20       #in V\n",
      "Vbe5=0.7      #in V\n",
      "R=1.18        #in K\n",
      "r=300.0       #in ohm\n",
      "Vbecutin=0.5    #in V\n",
      "\n",
      "#Calculations\n",
      "#If all inputs are low then we assume that Q1,Q2 and Q3 are cutoff and Q4 is conducting\n",
      "Ve=-Vbb-Vbe5#Voltage at Common Emitter in V\n",
      "#Current I in 1.18K Resistor\n",
      "I = (Ve+Vee)/R#in mA\n",
      "I1=I\n",
      "print(\"Current in 300 ohm resistance I= %.2f mA \" %I)\n",
      "#Output Voltage at Y\n",
      "vy = -(r*I/1000)-Vbe5       #I is in mA so 1000 is multiplied\n",
      "Vbe = vy-Ve\n",
      "print(\"The value of Vbe is %.2f v \" %Vbe)\n",
      "if Vbe<Vbecutin :\n",
      "    print('Input transistors are non conducting as was assumed')\n",
      "    print('If atleast one input is high then it is assumed that curent in 1.18K resistance is switched to R and Q4 is cutoff')\n",
      "    print('Drop in 300 ohm resistance is zero.Since the base aand collector are tied together Q5 now behaves as a diode')\n",
      "    print('Across Q5')\n",
      "    v=0.7#voltage across Q5 in V\n",
      "    rQ5 = 1.5#in K\n",
      "    i = (Vee-v)/rQ5\n",
      "    v = 0.75#from the graph in V\n",
      "    print(\"The value of i is %.2f mA \" %i)\n",
      "    print(\"The value of V is %.2f v \" %v)\n",
      "    Ve = -v-Vbe5\n",
      "    Vbe4=-Vbb-Ve\n",
      "    print(\"The value of Vbe4 is %.2f v \" %Vbe4)\n",
      "\n",
      "#Results    \n",
      "print('The total output swing between two logic gates')\n",
      "vo = -vy-v\n",
      "print(\"The value of vo is %.2f v \" %vo)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Current in 300 ohm resistance I= 2.84 mA \n",
        "The value of Vbe is 0.30 v \n",
        "Input transistors are non conducting as was assumed\n",
        "If atleast one input is high then it is assumed that curent in 1.18K resistance is switched to R and Q4 is cutoff\n",
        "Drop in 300 ohm resistance is zero.Since the base aand collector are tied together Q5 now behaves as a diode\n",
        "Across Q5\n",
        "The value of i is 3.00 mA \n",
        "The value of V is 0.75 v \n",
        "The value of Vbe4 is 0.30 v \n",
        "The total output swing between two logic gates\n",
        "The value of vo is 0.80 v \n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.4b Page No 656"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "Vbb = 1.15    #in V\n",
      "Vee=5.20      #in V\n",
      "Vbe5=0.7     #in V\n",
      "R=1.18       #in K\n",
      "r=300        #in ohm\n",
      "Vbecutin=0.5    #in V\n",
      "\n",
      "#Calculations\n",
      "#If all inputs are low then we assume that Q1,Q2 and Q3 are cutoff and Q4 is conducting\n",
      "Ve=-Vbb-Vbe5          #Voltage at Common Emitter in V\n",
      "#Current I in 1.18K Resistor\n",
      "I = (Ve+Vee)/R#in mA\n",
      "I1=I\n",
      "#Output Voltage at Y\n",
      "vy = -(r*I/1000)-Vbe5     #I is in mA so 1000 is multiplied\n",
      "Vbe = vy-Ve\n",
      "if Vbe<Vbecutin :\n",
      "    v=0.7                #voltage across Q5 in V\n",
      "    rQ5 = 1.5#in K\n",
      "    i = (Vee-v)/rQ5\n",
      "    v = 0.75           #from the graph in V\n",
      "    Ve = -v-Vbe5\n",
      "    Vbe4=-Vbb-Ve\n",
      "\n",
      "vo = -vy-v\n",
      "\n",
      "#Results\n",
      "#Calculation of noise margin\n",
      "vn = Vbecutin-Vbe4\n",
      "print('Positive noise spike which will cause the gate to malfunction')\n",
      "print(\"The value of vn is %.2f v \" %vn)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Positive noise spike which will cause the gate to malfunction\n",
        "The value of vn is 0.20 v \n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.4c Page No 656"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#initialisation of variables\n",
      "\n",
      "#Verify that conducting transistor is in active region\n",
      "#Given Data\n",
      "Vbb = 1.15   #in V\n",
      "Vee=5.20       #in V\n",
      "Vbe5=0.7      #in V\n",
      "R=1.18       #in K\n",
      "r=300.0     #in ohm\n",
      "Vbecutin=0.5  #in V\n",
      "\n",
      "#Calculations\n",
      "#If all inputs are low then we assume that Q1,Q2 and Q3 are cutoff and Q4 is conducting\n",
      "Ve=-Vbb-Vbe5#Voltage at Common Emitter in V\n",
      "#Current I in 1.18K Resistor\n",
      "I = (Ve+Vee)/R     #in mA\n",
      "I1=I\n",
      "#Output Voltage at Y\n",
      "vy = -(r*I/1000)-Vbe5       #I is in mA so 1000 is multiplied\n",
      "Vbe = vy-Ve\n",
      "if Vbe<Vbecutin :\n",
      "    v=0.7    #voltage across Q5 in V\n",
      "    rQ5 = 1.5   #in K\n",
      "    i = (Vee-v)/rQ5\n",
      "    v = 0.75    #from the graph in V\n",
      "    Ve = -v-Vbe5\n",
      "    Vbe4=-Vbb-Ve\n",
      "    \n",
      "vo = -vy-v\n",
      "\n",
      "Vb4 = Vbb\n",
      "Vc4 = -(I*r)/1000     #in V\n",
      "Vcb4 = Vc4+Vb4\n",
      "print(\"The value of Vcb4 is %.2f v \" %Vcb4)\n",
      "if Vcb4>0 :\n",
      "    print('For on npn transistor this represents a reverse bias and Q4 must be in active region')\n",
      "\n",
      "Vb1 = v\n",
      "Vc1 = vy+Vbe5\n",
      "Vcb1 = Vc1 + Vb1\n",
      "\n",
      "#Results\n",
      "print(\"The value of Vc1 is %.2f v \" %Vc1)\n",
      "print(\"The value of Vcb1 is %.2f v \" %Vcb1)\n",
      "if Vcb1<0 :\n",
      "    print('For an npn transistor this represents a forward bias.... therefore Q1 is in saturation region')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Vcb4 is 0.30 v \n",
        "For on npn transistor this represents a reverse bias and Q4 must be in active region\n",
        "The value of Vc1 is -0.85 v \n",
        "The value of Vcb1 is -0.10 v \n",
        "For an npn transistor this represents a forward bias.... therefore Q1 is in saturation region\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.4d, Page No 656"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "Vbb = 1.15       #in V\n",
      "Vee=5.20         #in V\n",
      "Vbe5=0.7         #in V\n",
      "R=1.18           #in K\n",
      "r=300.0          #in ohm\n",
      "Vbecutin=0.5    #in V\n",
      "\n",
      "#Calculations\n",
      "\n",
      "#If all inputs are low then we assume that Q1,Q2 and Q3 are cutoff and Q4 is conducting\n",
      "Ve=-Vbb-Vbe5#Voltage at Common Emitter in V\n",
      "#Current I in 1.18K Resistor\n",
      "I = (Ve+Vee)/R#in mA\n",
      "I1=I\n",
      "#Output Voltage at Y\n",
      "vy = -(r*I/1000.0)-Vbe5#I is in mA so 1000 is multiplied\n",
      "Vbe = vy-Ve\n",
      "if Vbe<Vbecutin :\n",
      "    v=0.7#voltage across Q5 in V\n",
      "    rQ5 = 1.5#in K\n",
      "    i = (Vee-v)/rQ5\n",
      "    v = 0.75#from the graph in V\n",
      "    Ve = -v-Vbe5\n",
      "    Vbe4=-Vbb-Ve\n",
      "\n",
      "vo = -vy-v\n",
      "\n",
      "#Verify that conducting transistor is in active region\n",
      "Vb4 = Vbb\n",
      "Vc4 = -(I*r)/1000#in V\n",
      "Vcb4 = Vc4+Vb4\n",
      "Vb1 = v\n",
      "Vc1 = vy+Vbe5\n",
      "Vcb1 = Vc1 + Vb1\n",
      "\n",
      "Vbe1 = Vbe5\n",
      "Ve = -(Vb1+Vbe1)\n",
      "\n",
      "#Results\n",
      "\n",
      "print(\"The value of Ve is %.2f v \" %Ve)\n",
      "I = (Ve + Vee)/R\n",
      "I2=I\n",
      "R = -Vc1/I\n",
      "print(\"The value of R is %.2f ohm \" %R)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Ve is -1.45 v \n",
        "The value of R is 0.27 ohm \n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.4e Page No 656"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#initialisation of variables\n",
      "\n",
      "Vbb = 1.15#in V\n",
      "Vee=5.20#in V\n",
      "Vbe5=0.7#in V\n",
      "R=1.18#in K\n",
      "r=300.0 #in ohm\n",
      "Vbecutin=0.5#in V\n",
      "\n",
      "#Calculations\n",
      "#If all inputs are low then we assume that Q1,Q2 and Q3 are cutoff and Q4 is conducting\n",
      "Ve=-Vbb-Vbe5#Voltage at Common Emitter in V\n",
      "#Current I in 1.18K Resistor\n",
      "I = (Ve+Vee)/R#in mA\n",
      "I1=I\n",
      "#Output Voltage at Y\n",
      "vy = -(r*I/1000.0)-Vbe5#I is in mA so 1000 is multiplied\n",
      "Vbe = vy-Ve\n",
      "if Vbe<Vbecutin :\n",
      "    v=0.7#voltage across Q5 in V\n",
      "    rQ5 = 1.5#in K\n",
      "    i = (Vee-v)/rQ5\n",
      "    v = 0.75#from the graph in V\n",
      "    Ve = -v-Vbe5\n",
      "    Vbe4=-Vbb-Ve\n",
      "\n",
      "vo = -vy-v\n",
      "\n",
      "Vb4 = Vbb\n",
      "Vc4 = -(I*r)/1000.0#in V\n",
      "Vcb4 = Vc4+Vb4\n",
      "Vb1 = v\n",
      "Vc1 = vy+Vbe5\n",
      "Vcb1 = Vc1 + Vb1\n",
      "\n",
      "Vbe1 = Vbe5\n",
      "Ve = -(Vb1+Vbe1)\n",
      "I = (Ve + Vee)/R\n",
      "I2=I\n",
      "\n",
      "I =(I1+I2)/2.0\n",
      "\n",
      "#Results\n",
      "print(\"The value of I is %.2f mA \" %I)\n",
      "I2 = (Vee-v)/rQ5\n",
      "I3 = (Vee+vy)/rQ5\n",
      "I = I + I2 + I3\n",
      "P = Vee*I\n",
      "print(\"Power dissipated  is %.2f mW \" %P)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of I is 3.01 mA \n",
        "Power dissipated  is 43.72 mW \n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.5 Page No 668"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "#initialisation of variables\n",
      "C=50.0    #nF\n",
      "Ra=10.0    #kOhm\n",
      "Vcc=5.0     #V\n",
      "beta=20.0    \n",
      "\n",
      "#Calculations\n",
      "T=1.1*Ra*C\n",
      "Ib=(Vcc-0.7)/100\n",
      "Ic=beta*Ib\n",
      "dt=C*(Vcc/Ic)\n",
      "\n",
      "#Results\n",
      "print(\"Another pulse can be generated at hte output after time period of = %.2f ns \" %dt)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Another pulse can be generated at hte output after time period of = 290.70 ns \n"
       ]
      }
     ],
     "prompt_number": 30
    }
   ],
   "metadata": {}
  }
 ]
}