{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2 : Operational Amplifier"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.1 Page No.44"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given Data\n",
      "\n",
      "R1 = 5*10**3\n",
      "Rf = 20*10**3\n",
      "vi = 1 \n",
      "RL = 5*10**3\n",
      "\n",
      "# calculating the values \n",
      "vo = float((1+(Rf/R1))*vi) \n",
      "ACL = int(vo/vi)\n",
      "iL = int((vo/RL)*10**3)\n",
      "i1 = float(((vo - vi)/Rf))*(10**3)\n",
      "io = iL+i1\n",
      " \n",
      " \n",
      "# printing the values\n",
      "print \"Output voltage vo = \",vo,\"V\"\n",
      "print \"Gain ACL          = \",ACL\n",
      "print \"Load current iL   = \",iL,\"mA\"\n",
      "print \"The value of i1   = \",i1,\"mA\"\n",
      "print \"Output current io = \", io,\"mA\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Output voltage vo =  5.0 V\n",
        "Gain ACL          =  5\n",
        "Load current iL   =  1 mA\n",
        "The value of i1   =  0.2 mA\n",
        "Output current io =  1.2 mA\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.2 Page No.44"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "\n",
      "R1 = 10*10**3      #R1 input resistance \n",
      "Rf = 100*10**3     # Rf feedback resistance\n",
      "vi = float(1)          #input voltage  \n",
      "RL = 25*10**3\n",
      "#calculating the values \n",
      "\n",
      "i1 = float((vi/R1)*10**3)                 # input resistace id the ratio of input voltage to the input resitance \n",
      "vo = float(-(Rf/R1)*vi)            # finding the output voltage \n",
      "iL = float((abs(vo)/RL)*10**3)                  #  calculating the load current \n",
      "io = float((i1+iL))                 # calculating the output current which is equal to the sum of input current and load current\n",
      "\n",
      "#printing the values \n",
      "\n",
      "print \"The input current i1  =\",i1,\"mA\"\n",
      "print \"The output voltage vo =\",vo,\"V\"\n",
      "print \"The load current iL   =\",iL,\"mA\"\n",
      "print \"The output current io =\",io,\"mA\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The input current i1  = 0.1 mA\n",
        "The output voltage vo = -10.0 V\n",
        "The load current iL   = 0.4 mA\n",
        "The output current io = 0.5 mA\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.3 Page No.49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "\n",
      "ACL = 5     # Gain of the amplifier\n",
      "R1 = 10*10**3 # input resisitance in ohms \n",
      "\n",
      "# calculations\n",
      "\n",
      "Rf = (5-1) * R1 # calculating the resistance of feedback resistor \n",
      "\n",
      "# printing the values \n",
      "\n",
      "print \"The value of feedback resistor = \", (Rf/10**3),\"KiloOhms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of feedback resistor =  40 KiloOhms\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.4 Page No.49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Given Data\n",
      "\n",
      "R1 = 5*10**3\n",
      "Rf = 20*10**3\n",
      "vi = 1 \n",
      "RL = 5*10**3\n",
      "\n",
      "# calculating the values \n",
      "vo = float((1+(Rf/R1))*vi) \n",
      "ACL = int(vo/vi)\n",
      "iL = int((vo/RL)*10**3)\n",
      "i1 = float(((vo - vi)/Rf))*(10**3)\n",
      "io = iL+i1\n",
      " \n",
      " \n",
      "# printing the values\n",
      "print \"Output voltage vo = \",vo,\"V\"\n",
      "print \"Gain ACL          = \",ACL\n",
      "print \"Load current iL   = \",iL,\"mA\"\n",
      "print \"The value of i1   = \",i1,\"mA\"\n",
      "print \"Output current io = \", io,\"mA\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Output voltage vo =  5.0 V\n",
        "Gain ACL          =  5\n",
        "Load current iL   =  1 mA\n",
        "The value of i1   =  0.2 mA\n",
        "Output current io =  1.2 mA\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.6 Page No.61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Given Data\n",
      "from decimal import Decimal, ROUND_HALF_UP\n",
      "import math\n",
      "Beta = 200\n",
      "ICQ = 100*10**-6\n",
      "ADM = 100\n",
      "CMRR = 80\n",
      "\n",
      "# finding the solution \n",
      "# for VT =25 milli volt \n",
      "VT = 25*10**-3\n",
      "gm = float(ICQ/VT)\n",
      "Rc = (ADM/gm) \n",
      "CMRR = 10**(80/20) # log inverse is equal to powers of 10\n",
      "RE = float((CMRR-1)/gm)\n",
      "x = Decimal((RE/10**6))\n",
      "\n",
      "# printing the values \n",
      "\n",
      "print \" The value of gm =\",int(math.ceil((gm*10**3))),\"mMho\"            #converting the answer into milli Mho\n",
      "print \" The value of Rc =\",int((Rc/10**3)),\"kiloOhm\"         #converting the answer into Kilo Ohm\n",
      "print \" The value of RE =\", x.quantize(Decimal('2.5')),\"MegaOhm\"         #converting the answer into MegaOhm"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of gm = 4 mMho\n",
        " The value of Rc = 25 kiloOhm\n",
        " The value of RE = 2.5 MegaOhm\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.7 Page No.61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "# Given Data\n",
      "RC = 2*10**3\n",
      "RE = 4.3*10**3\n",
      "VCC = VEE = 5\n",
      "beta0 = 200\n",
      "VBE = 0.7\n",
      "VT = 25*10**-3                                  # VT = 25 mV \n",
      "\n",
      "#calculations \n",
      "\n",
      "Ibq  = (((VEE - VBE)/(2*(1+beta0)*RE)))*10**6   # converting the into mA\n",
      "IBQ = int(Ibq*10)/10.0                          # rounding the answer 2.48 to 2.4\n",
      "ICQ = beta0 * IBQ*10**-3                        # finding ICQ and convert it into milli Ambere\n",
      "V01 = V02 = VCC - (RC * ICQ*10**-3)\n",
      "VCEQ = V01 + VBE\n",
      "gm = ICQ / VT                                   # Finding the gm value in milli Mho\n",
      "rpi = float(beta0/gm)                           # finding rpi interms of KiloOhms \n",
      "ADM = -(gm*RC)/10**3                            # Calculating the gain \n",
      "ACM = float((-beta0*RC)/(rpi*10**3 + (2*beta0) * RE)) # Calulating the value of ACM and coverting it into a float \n",
      "CMRR = float(round(ADM,2)/round(ACM,2))               # rounding ACM and ADM to 2 digits after decimals and taking the\n",
      "                                                      #ratio\n",
      "CMRRdb = float(20*math.log10(round(CMRR,1)))          # Find the CMRR in dB using equation 20*log(CMRR)\n",
      "\n",
      "# Printing all values \n",
      "\n",
      "print \"The IBQ        =\",IBQ,\"uA\"\n",
      "print \"The ICQ        =\",ICQ,\"mA\"\n",
      "print \"The V01        =\",V01,\"mV\"\n",
      "print \"The VCEQ       =\",VCEQ,\"V\"\n",
      "print \"The gm         =\",gm,\"m Mho\"\n",
      "print \"The rpi        =\",round(rpi,1),\"kilo Ohm\"\n",
      "print \"The ADM        =\",round(ADM,2)\n",
      "print \"The ACM        =\",round(ACM,2)\n",
      "print \"The CMRR       =\",round(CMRR,1)\n",
      "print \"The CMRR in dB =\",int(CMRRdb*10)/10.0,\"dB\"\n",
      "                                      "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The IBQ        = 2.4 uA\n",
        "The ICQ        = 0.48 mA\n",
        "The V01        = 4.04 mV\n",
        "The VCEQ       = 4.74 V\n",
        "The gm         = 19.2 m Mho\n",
        "The rpi        = 10.4 kilo Ohm\n",
        "The ADM        = -38.4\n",
        "The ACM        = -0.23\n",
        "The CMRR       = 167.0\n",
        "The CMRR in dB = 44.4 dB\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.8 Page No.62"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# v1 = 15*sin*2*pi(60)t + 5*sin*2*pi(1000)t mV\n",
      "# v1 = 15*sin*2*pi(60)t - 5*sin*2*pi(1000)t mV\n",
      "\n",
      "# Given data \n",
      "\n",
      "gm = 4*10**-3\n",
      "RC = 125*10*3\n",
      "RE = 1.25*10**3\n",
      "beta0 = 200\n",
      "\n",
      "# calculating the values\n",
      "\n",
      "rpi = beta0/gm              # value is in ohms \n",
      "ADM =-500                   # Given Value\n",
      "ACM = -((200*RC)/(402*RE)+rpi)*10**-6\n",
      "print \"ACM is =\",round(ACM,2)\n",
      "\n",
      "# derivation part is as follows  \n",
      "# VDM = (v1 - v2)/2 = 5*sin*2*pi(1000)*t\n",
      "# VCM = (v1 - v2)/2 = 15*sin*2*pi(60)*t\n",
      "# VO1 = ADM*VDM + ACM*VCM\n",
      "# VO2 = ADM*VDM - ACM*VCM\n",
      "# V01 = -2500*sin*2*pi(1000)t - 0.75*sin*2*pi(60)t mV\n",
      "# V01 =  2500*sin*2*pi(1000)t - 0.75*sin*2*pi(60)t mV"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "ACM is = -0.05\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.9 Page No.63"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from fractions import Fraction \n",
      "# Given data\n",
      "\n",
      "beta0 = 100\n",
      "IQ = 5*10**-4\n",
      "RC = 10*10**3\n",
      "RE = 150\n",
      "VT = 25*10**-3 \n",
      "\n",
      "# calculations \n",
      "\n",
      "ICQ = float(IQ/2)\n",
      "gm  = float(ICQ / VT)\n",
      "rpi = beta0/gm\n",
      "# calculaing the gain in Differential mode\n",
      "ADM = ((0.5)*(beta0*RC))/(rpi+((1+beta0)*RE))\n",
      "# To get the differentila mode gain multiply the value by 2\n",
      "ADM2 = (ADM*2)\n",
      "\n",
      "# print the values \n",
      "\n",
      "print \"ICQ value is =\",ICQ*10**3,\"mA\"\n",
      "print \"gm value is  =\",Fraction(gm).limit_denominator(100),\"Mho\"  \n",
      "print \"rpi value is =\",int(rpi/10**3),\"kilo Ohm\"\n",
      "print \"THe gain is  =\",int(math.ceil(ADM2)),\"V/V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "ICQ value is = 0.25 mA\n",
        "gm value is  = 1/100 Mho\n",
        "rpi value is = 10 kilo Ohm\n",
        "THe gain is  = 40 V/V\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.10 Page No.67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given Data \n",
      "VCC = 10.0                  # initializing as floats \n",
      "beta = 125.0\n",
      "VBE = 0.7\n",
      "\n",
      "# calculations \n",
      "# Define a function for calculating the value of R1 according to the equation given in 2.67\n",
      "def R1(I):\n",
      "    R1 = (beta/(2+beta))*((VCC-VBE)/I)       \n",
      "    return (R1/1000)\n",
      "# Cosisdering Ic = 1mA\n",
      "print \"The value of R1 when I is 1 mA  = \",round(R1(10**-3),2),\"Kilo Ohm\"           # calling the function R1 with arguiment as current value 1 mA\n",
      "print \"The value of R1 when I is 10 uA = \",int(round(R1(10*10**-6),0)),\"Kilo Ohm\"  # calling the function R1 with arguiment as current value 10 uA"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R1 when I is 1 mA  =  9.15 Kilo Ohm\n",
        "The value of R1 when I is 10 uA =  915 Kilo Ohm\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.11 Page No.69"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "import math\n",
      "I0 = 10*10**-6\n",
      "VCC =10\n",
      "VBE = 0.7\n",
      "beta = 125\n",
      "VT = 25*10**-3\n",
      "\n",
      "# Solution of the problem is \n",
      "Iref = 10**-3 # Assumption\n",
      "\n",
      "R1 = (VCC - VBE)/Iref\n",
      "# Finding the value RE from the equation 2.74\n",
      "RE = (VT/(1+(1/beta)*I0))*math.log(Iref/I0)\n",
      "\n",
      "# printing the values \n",
      "\n",
      "print \"The value of R1 =\",R1/10**3,\"Kilo Ohms\"\n",
      "print \"The value of RE =\",round(RE*100,1),\"Kilo Ohms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of R1 = 9.3 Kilo Ohms\n",
        "The value of RE = 11.5 Kilo Ohms\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.13 Page No.74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data \n",
      "\n",
      "VCC = 10.0\n",
      "beta = 100\n",
      "VBE = 0.7\n",
      "RE = 10*10**3\n",
      "\n",
      "# solution\n",
      "# fom the KVL loop1\n",
      "Iref = ((VCC - VBE)/RE)   # Finding the Iref \n",
      "# Assuming the transistor are identical \n",
      "# Iref = 2IE\n",
      "# IE = IC + IB\n",
      "IC = (beta*Iref/(2*(1+beta)))\n",
      "I0 = IC\n",
      "#Displaying the values \n",
      "\n",
      "print \"The value of Iref =\",Iref*10**3,\"mA\"             # Converting the value into mA\n",
      "print \"The value of IC   =\",round(IC*10**3,2),\"mA\"      # Converting the value into mA and rounding the answer\n",
      "print \"The value of I0   =\",round(I0*10**3,2),\"mA\"      # Converting the value into mA and rounding the answer"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Iref = 0.93 mA\n",
        "The value of IC   = 0.46 mA\n",
        "The value of I0   = 0.46 mA\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.14 Page No.75"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data  \n",
      "\n",
      "VCC = 12.0\n",
      "Rref = 15*10**3 \n",
      "R1 = 2.8*10**3\n",
      "beta = 200\n",
      "VBE = 0.7\n",
      "V0 = 6.0\n",
      "\n",
      "#Calculations \n",
      "#Calculations for finding the IC1 and IC2\n",
      "Iref = (VCC - VBE)/Rref\n",
      "I1 = VBE / R1\n",
      "IC1 = (Iref - I1)/(1+(2/beta))\n",
      "IC2 = IC1 # Due to mirror effect \n",
      "RC = (VCC - V0)/IC1\n",
      "\n",
      "# Displaying the values \n",
      "\n",
      "print \"The value of Iref  =\",round(Iref*10**3,2),\"mA\"             # convert into milli amps and rounding the output\n",
      "print \"The value of I1    =\",round(I1*10**3,2),\"mA\"               # convert into milli amps and rounding the output\n",
      "print \"The value of IC1   =\",round(IC1*10**3,1),\"mA\"              # convert into milli amps and rounding the output\n",
      "print \"The value of Rc    =\",int(round(RC*10**-3,0)),\"Kilo Ohm\"   # convert into kilo Ohms and rounding the output"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Iref  = 0.75 mA\n",
        "The value of I1    = 0.25 mA\n",
        "The value of IC1   = 0.5 mA\n",
        "The value of Rc    = 12 Kilo Ohm\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.15 Page No.75"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data  \n",
      "\n",
      "VCC = 10.0\n",
      "VBE = 0.75\n",
      "R1 = 4.7*10**3\n",
      "\n",
      "# solution \n",
      "# I is approximately equals to Ic(2 + (1/beta)), since 1/beta is a small value its considerd as 2Ics \n",
      "I = (VCC - VBE)/R1\n",
      "# IE3 is approxiamtly equal to IC3 = I/2\n",
      "#finding the value of IC \n",
      "IC = I /2\n",
      "print \" The value of I  =\",round(I*10**3,2),\"mA\"\n",
      "print \" The value of IC =\",round(IC*10**3,2),\"mA\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of I  = 1.97 mA\n",
        " The value of IC = 0.98 mA\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.16 Page No.80"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "VCC = 15.0\n",
      "VBE = 0.7\n",
      "R = 10*10**3\n",
      "RC2 = 5*10**3\n",
      "# consider beta is a large value \n",
      "I = (VCC - VBE)/R\n",
      "IC1 = IC2 = I\n",
      "#V12 = V1 - V2\n",
      "V12 = VBE + IC2 * RC2 \n",
      "\n",
      "# displaying the values\n",
      "print \"The value of I        =\",round(I*10**3,2),\"mA\"\n",
      "print \"The value of V1 - V2  =\",V12,\"V\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of I        = 1.43 mA\n",
        "The value of V1 - V2  = 7.85 V\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.17 Page No.83"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Given data\n",
      "\n",
      "VEE = 6.0\n",
      "VCC = 6.0\n",
      "VD = VD1 = VD2 = VD3 = VD4 = 0.7\n",
      "R5 = 3.2*10**3\n",
      "R4 = 1.5*10**3\n",
      "VBE1 = VBE2 =VBE3 = VBE4 = VBE5 = VBE6 = VBE7 = VBE8 = 0.7\n",
      "R1 = 2.2*10**3\n",
      "R2 = 7.75*10**3\n",
      "R3 = 5.2*10**3\n",
      "R6 = 1.5*10**3\n",
      "R7 = 3*10**3\n",
      "R8 = 3.4*10**3\n",
      "R9 = 6*10**3\n",
      "R10 =30*10**3\n",
      "hfe = 100\n",
      "VT = 26*10**-3\n",
      "\n",
      "# Solution for part A\n",
      "\n",
      "VBN1 = round((-VEE+VD+VD)*R5/(R4+R5),2)\n",
      "I1 = (VEE+VBN1-VBE1)/R1\n",
      "IQ = I1  # If the base current of Q1 is neglected\n",
      "IC2 = IC3 = IQ2 = round(IQ/2,6)\n",
      "VC2 = VC3 = round((VCC - R2*IC2),2)\n",
      "VE4 = VC2 - VBE4 \n",
      "I6 = round(VE4/R6,6)\n",
      "IC4 = IC5 = round((I6/2),6)\n",
      "VC5 = round(VCC - IC5*R7,2)\n",
      "VE6 = round(VC5 - VBE6,2)\n",
      "IC7 = I8 = round((VEE - VD3)/R8,5)\n",
      "VB8 = VBE8 + VD4 - VEE\n",
      "I9 = round((VE6 - VB8)/R9,5)\n",
      "I10 = IC7 - I9\n",
      "Vo = (I10 * R10) + VB8\n",
      "V0 = int(Vo)         # Vo value is assumed to be very small\n",
      "\n",
      "# Displaying the values \n",
      "print \"PART A\"\n",
      "print \"==================\"\n",
      "print \"the value of VBN1 =\",VBN1,\"V\"\n",
      "print \"The value of I1   =\",I1*10**3,\"mA\"\n",
      "print \"The value of IQ   =\",IQ*10**3,\"mA\"\n",
      "print \"The value of IC2  =\",IC2*10**3,\"mA\"\n",
      "print \"The value of VC3  =\",VC3,\"V\"\n",
      "print \"The value of VE4  =\",VE4,\"V\"\n",
      "print \"The value of IC4  =\",IC4*10**3,\"mA\"\n",
      "print \"The value of VC5  =\",VC5,\"V\"\n",
      "print \"The value of VE6  =\",VE6,\"V\"\n",
      "print \"The value of IC7  =\",IC7*10**3,\"mA\"\n",
      "print \"The value of VB8  =\",VB8,\"V\"\n",
      "print \"The value of I9   =\",I9*10**3,\"mA\"\n",
      "print \"The value of I10  =\",I10*10**3,\"mA\"\n",
      "print \"The value of V0   =\",V0,\"V\"\n",
      "\n",
      "# Solution for part B\n",
      "VT = 26*10**-3                #the volt equivalent of temperature \n",
      "IC2 = IC3 = IC4 = IC5 = IC = 0.5*10**-3\n",
      "hie = (hfe*VT)/IC\n",
      "RL2 = RL3 = (R2*R3)/(R2+R3)\n",
      "AV1 = round((hfe*RL2)/hie,0)\n",
      "AV2 = round(-(hfe*R7)/(2*hie),2)\n",
      "AV3 = 1                                        # the thrid stage emitter follower differential gain \n",
      "AV4 = int(-R10/R9)\n",
      "AV = AV1*round(AV2,1)*AV4                      # again rounding AV2 to get the desired value\n",
      "\n",
      "# Displaying the values\n",
      "print \"PART B\"\n",
      "print \"==================\"\n",
      "print \"The value of hie =\",int(hie)\n",
      "print \"The value of RL2 =\",RL2*10**-3,\"Kilo Ohms\"\n",
      "print \"The value of AV1 =\",int(AV1)\n",
      "print \"The value of AV2 =\",round(AV2,1)\n",
      "print \"The value of AV3 =\",AV3\n",
      "print \"The value of AV4 =\",AV4\n",
      "print \"The value of AV  =\",int(AV)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "PART A\n",
        "==================\n",
        "the value of VBN1 = -3.13 V\n",
        "The value of I1   = 0.986363636364 mA\n",
        "The value of IQ   = 0.986363636364 mA\n",
        "The value of IC2  = 0.493 mA\n",
        "The value of VC3  = 2.18 V\n",
        "The value of VE4  = 1.48 V\n",
        "The value of IC4  = 0.494 mA\n",
        "The value of VC5  = 4.52 V\n",
        "The value of VE6  = 3.82 V\n",
        "The value of IC7  = 1.56 mA\n",
        "The value of VB8  = -4.6 V\n",
        "The value of I9   = 1.4 mA\n",
        "The value of I10  = 0.16 mA\n",
        "The value of V0   = 0 V\n",
        "PART B\n",
        "==================\n",
        "The value of hie = 5200\n",
        "The value of RL2 = 3.11196911197 Kilo Ohms\n",
        "The value of AV1 = 60\n",
        "The value of AV2 = -28.9\n",
        "The value of AV3 = 1\n",
        "The value of AV4 = -5\n",
        "The value of AV  = 8670\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.18 Page No.87"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data \n",
      "VEE = 15.0\n",
      "VCC = 15.0\n",
      "VBE1 = VBE2 = VBE3 = VBE4 = VBE5 = VBE= 0.7\n",
      "R = 28.6*10**3\n",
      "RC1 = 20*10**3\n",
      "RC6 = 3*10**3\n",
      "RC8 = 2.3*10**3\n",
      "RA = 15.7*10**3\n",
      "hfe = 100\n",
      "VT = 25*10**-3\n",
      "\n",
      "# Solution for part 1 DC - ANALYSIS\n",
      "\n",
      "I = (VEE - VBE3)/R\n",
      "ICQ4 = I\n",
      "ICQ1 = ICQ2 = ICQ4/2\n",
      "# Q1 and Q2 are biased at 0.25mA so their Collector voltages are\n",
      "IC1 = IC = ICQ1\n",
      "VCQ1 = VCQ2 = VCC - (IC1*RC1)\n",
      "VEQ5 = VEQ6 = VCQ1 - VBE\n",
      "IQ7 = 4*I\n",
      "# The collector current of Q5 and Q6 are \n",
      "ICQ5 = ICQ6 = IQ7/2\n",
      "VCQ6 = VCC - (ICQ6 * RC6)\n",
      "VEQ8 = VCQ6 + VBE\n",
      "IEQ8 = (VCC - VEQ8)/RC8\n",
      "# The voltage VA at the collector of Q8 is \n",
      "VA = -VCC + (IEQ8 * RA)\n",
      "IEQ9 = (0-(-VCC))/RC6\n",
      "\n",
      "# Displaying all values of Part 1\n",
      "\n",
      "print \"The value of I      =\",int(I*10**3),\"mA\"\n",
      "print \"The value of ICQ1   =\",int(ICQ1*10**3),\"mA\"\n",
      "print \"The value of VCQ1   =\",int(VCQ1),\"V\"\n",
      "print \"The value of VEQ5   =\",int(VEQ5),\"V\"\n",
      "print \"The value of IQ7    =\",int(IQ7*10**3),\"mA\"\n",
      "print \"The value of ICQ5   =\",int(ICQ5*10**3),\"mA\"\n",
      "print \"The value of VCQ6   =\",int(VCQ6),\"V\"\n",
      "print \"The value of VEQ8   =\",int(VEQ8),\"V\"\n",
      "print \"The value of IEQ8   =\",int(IEQ8*10**3),\"mA\"\n",
      "print \"The value of VA     =\",VA,\"V\"\n",
      "print \"The value of IEQ9   =\",int(IEQ9*10**3),\"mA\"\n",
      "\n",
      "# Part 2 AC -ANALYSIS\n",
      "\n",
      "hieQ12 = (hfe * VT)/IC\n",
      "# The ac emitter resistance of transister Q5 - Q6\n",
      "hieQ56 = (hfe * VT)/ICQ5\n",
      "RL1 = RL2 = (RC1*hieQ56)/(RC1 + hieQ56)          # parallel combination of resistor RC1 and hieQ56\n",
      "ADM1 = (hfe * RL2)/hieQ12\n",
      "ADM2 = -(hfe * RC6)/(2*hieQ56)\n",
      "\n",
      "\n",
      "# Displaying the values \n",
      "\n",
      "print \"The value of ac emiiter resistace of the transistor Q1-Q2  = \",int(round(hieQ12*10**-3,0)),\"Kilo Ohm\"\n",
      "print \"The value of ac emiiter resistace of the transistor Q5-Q6  = \",round(hieQ56*10**-3,1),\"Kilo Ohm\"\n",
      "print \"The value of effective load of Q1-Q2                       = \",round(RL1*10**-3,1),\"Kilo Ohm\"\n",
      "print \"The value of voltage gain of first differential pair       = \",int(round(ADM1,0)),\"Kilo Ohm\"\n",
      "print \"The value of voltage gain of second differential pair      = \",int(ADM2),\"Kilo Ohm\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of I      = 0 mA\n",
        "The value of ICQ1   = 0 mA\n",
        "The value of VCQ1   = 10 V\n",
        "The value of VEQ5   = 9 V\n",
        "The value of IQ7    = 2 mA\n",
        "The value of ICQ5   = 1 mA\n",
        "The value of VCQ6   = 12 V\n",
        "The value of VEQ8   = 12 V\n",
        "The value of IEQ8   = 1 mA\n",
        "The value of VA     = 0.7 V\n",
        "The value of IEQ9   = 5 mA\n",
        "The value of ac emiiter resistace of the transistor Q1-Q2  =  10 Kilo Ohm\n",
        "The value of ac emiiter resistace of the transistor Q5-Q6  =  2.5 Kilo Ohm\n",
        "The value of effective load of Q1-Q2                       =  2.2 Kilo Ohm\n",
        "The value of voltage gain of first differential pair       =  22 Kilo Ohm\n",
        "The value of voltage gain of second differential pair      =  -60 Kilo Ohm\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}