{
 "metadata": {
  "name": "",
  "signature": "sha256:08f6666963b63d68f1720253f0e8a698e5752723f4515bbc0a7b3ce6b79e7e0a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter2 - Differential amplifiers"
     ]
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Ex 2.1 - page 31"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "v1=7 #mV\n",
      "v2=9 #mV\n",
      "Ad=80 #dB\n",
      "CMRR=90 #dB\n",
      "vid=v2-v1 #mV\n",
      "vcm=(v1+v2)/2 #mV\n",
      "Ad=10**(Ad/20) #unitless\n",
      "CMRR=10**(CMRR/20) #unitless\n",
      "vout=Ad*(vid+vcm/CMRR)/1000 #V\n",
      "print \"Output Voltage is %0.2f V\" %vout"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Output Voltage is 20.00 V\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.2 - page 31"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "v1=50.0 #micro V\n",
      "v2=55.0 #micro V\n",
      "Ad=2*10**5 #unitless\n",
      "CMRR=80 #dB\n",
      "vid=v2-v1 #micro V\n",
      "vcm=(v1+v2)/2 #mV\n",
      "CMRR=10**(CMRR/20) #unitless\n",
      "vout=Ad*(vid+vcm/CMRR)/10**6 #V\n",
      "print \"Output Voltage is %0.3f V\" %vout  \n",
      "Verror=vout-Ad*vid/10**6 #V\n",
      "print \"Error Voltage is %0.3f V\" %Verror\n",
      "error_p=(Verror/vout)*100 #% error\n",
      "print \"Percentage error is %0.3f %%\" %error_p \n",
      "#Percentage error answer is not correct in the book."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Output Voltage is 1.001 V\n",
        "Error Voltage is 0.001 V\n",
        "Percentage error is 0.105 %\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.3 - page 38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "IT=1.0 #mA\n",
      "VCC=15 #V\n",
      "RE=50 #kohm\n",
      "RC=15 #kohm\n",
      "Beta=120 #unitless\n",
      "alfa=Beta/(Beta+1) #unitless\n",
      "Vid=6 #mV\n",
      "VT=26 #mV\n",
      "#Part (a)\n",
      "iC1=alfa*IT/(1+math.exp(-Vid/VT)) #mA\n",
      "iC2=IT-iC1 #mA\n",
      "print \"dc Collector current through transistors is %0.3f mA\" %iC2 \n",
      "#Part (b)\n",
      "iC=IT/2 #mA(let iC1=iC2=iC)\n",
      "re=VT/iC #ohm(let re1=re2=re)\n",
      "Ad=-RC*1000/re #unitless\n",
      "Acm=-RC*1000/(re+2*RE*1000) #unitless\n",
      "Acm=abs(Acm) ##unitless\n",
      "CMRR=abs(Ad/Acm) ##unitless\n",
      "print \"Ad is %0.2f\" %Ad \n",
      "print \"Acm is %0.2f \" %Acm \n",
      "CMRR=20*math.log10(CMRR) #dB\n",
      "print \"CMRR is %0.1f dB\" %CMRR"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "dc Collector current through transistors is 0.447 mA\n",
        "Ad is -288.46\n",
        "Acm is 0.15 \n",
        "CMRR is 65.7 dB\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.4 - page 44"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "RC=2 #kohm\n",
      "RE=4.3 #kohm\n",
      "VEE=5 #V\n",
      "VBE=0.7 #V\n",
      "IT=(VEE-VBE)/RE #mA\n",
      "VT=26 #mV\n",
      "re=2*VT/IT #ohm\n",
      "Ad=-RC*1000/2/re #unitless\n",
      "print \"Ad = \",round(Ad,2)  \n",
      "Acm=-RC*1000/(re+2*RE*1000) #unitless\n",
      "print \"Acm = \",round(Acm,2)\n",
      "CMRR=abs(Ad/Acm) ##unitless\n",
      "print \"CMRR = \",round(CMRR,1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Ad =  -19.23\n",
        "Acm =  -0.23\n",
        "CMRR =  83.2\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.5 - page 45"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Beta=100 #unitless\n",
      "VBE=0.715 \n",
      "VD1=0.715 #V\n",
      "VZ=6.2 #V\n",
      "VT=26 #mV\n",
      "IZt=41 #mA\n",
      "VCC=10 #V\n",
      "VEE=10 #V\n",
      "RE=2.7 #kohm\n",
      "RC=4.7 #kohm\n",
      "VB=-VEE+VZ+VD1 #V\n",
      "VE=VB-VBE #V\n",
      "IE3=(VE-(-VEE))/(RE) #mA\n",
      "IT=IE3 #mA\n",
      "ICQ=IT/2 #mA(let ICQ1=ICQ2=ICQ)\n",
      "VCEQ=VCC+VBE-ICQ*RC #V\n",
      "#Q=[ICQ,VCEQ] #[mA V](Q point)\n",
      "print \"Q point (ICQ(mA), VCEQ(V)), ICQ is \",round(ICQ,2),\"mA & VCEQ is \",round(VCEQ,2),\"V\"\n",
      "re=2*VT/IT #ohm\n",
      "Ad=-RC*1000/re #unitless\n",
      "Rid=2*Beta*re/1000 #kohm\n",
      "print \"Ad = \",round(Ad)\n",
      "print \"Rid is %0.2f kohm\" %Rid"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q point (ICQ(mA), VCEQ(V)), ICQ is  1.15 mA & VCEQ is  5.32 V\n",
        "Ad =  -208.0\n",
        "Rid is 4.53 kohm\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.6 - page 47"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Beta=100 #unitless\n",
      "VBE=0.7 #V\n",
      "VCC=10 #V\n",
      "VEE=10 #V\n",
      "VT=26 #mV\n",
      "RC=2.7 #kohm\n",
      "R=2.2 #kohm\n",
      "IExt=(VEE-VBE)/R #mA\n",
      "IC3=IExt \n",
      "IT=IExt  #mA\n",
      "ICQ=IT/2 #mA\n",
      "re=2*VT/IT #ohm(let re1=re2=re)\n",
      "Ad=-RC*1000/re #unitless\n",
      "Rid=2*Beta*re/1000 #kohm(let Rid1=Rid2=Rid)\n",
      "print \"Differntial mode gain, Ad = \", round(Ad,1) \n",
      "print \"Differntial input resistance, Rid is %0.2f kohm\" %Rid"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Differntial mode gain, Ad =  -219.5\n",
        "Differntial input resistance, Rid is 2.46 kohm\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.7 - page 49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Beta=100 #unitless\n",
      "VBE=0.7 #V\n",
      "VD1=0.7 #V\n",
      "VD2=0.7#V\n",
      "VCC=15 #V\n",
      "VEE=15 #V\n",
      "VT=26 #mV\n",
      "RE=560 #ohm\n",
      "RC=6.8 #kohm\n",
      "R=220 #ohm\n",
      "VB=-VEE+VD1+VD2 #V\n",
      "VE=VB-VBE #V\n",
      "IE3=(VE-(-VEE))/RE*1000 #mA\n",
      "IT=IE3 #mA\n",
      "ICQ=IT/2 #mA\n",
      "VCEQ=VCC+VBE-ICQ*RC #V\n",
      "#Q=[ICQ VCEQ] #[mA V](Q point)\n",
      "print \"Q point (ICQ(mA), VCEQ(V)), ICQ is \",round(ICQ,3),\"mA & VCEQ is \",round(VCEQ,2),\"V\"\n",
      "re=2*VT/IT #ohm\n",
      "Ad=-RC*1000/re #unitless\n",
      "print \"Differntial mode gain, Ad = \",round(Ad,2) \n",
      "#Answer in the book is wrong for Q point."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q point (ICQ(mA), VCEQ(V)), ICQ is  0.625 mA & VCEQ is  11.45 V\n",
        "Differntial mode gain, Ad =  -163.46\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.8 - page 50"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "ICQ=200.0 #micro A\n",
      "Beta=1000.0 #unitless\n",
      "Ad=180.0 #unitless\n",
      "CMRR=80.0 #dB\n",
      "VT=26.0 #mV\n",
      "re=VT/(ICQ/1000) #ohm(Let re=re1=re2)\n",
      "RC=Ad*re/1000 #kohm\n",
      "CMRR=10**(CMRR/20) #untless\n",
      "RE=(CMRR-1)*re/2/1000 #kohm\n",
      "print \"Value of RC is %0.2f kohm & RE is %0.f kohm\" %(RC,RE) \n",
      "Rid=2*Beta*re/1000 #kohm(Let Rid=Rid1=Rid2)\n",
      "print \"Differntial input resistance, Rid is %0.f kohm \" %Rid \n",
      "Ric=(Beta+1)*(re+2*RE*1000)/10**6 #Mohm\n",
      "print \"Common mode input resistance, Ric is %0.f Mohm \" %Ric\n",
      "#Answer for last part is wrong in the textbook."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Value of RC is 23.40 kohm & RE is 650 kohm\n",
        "Differntial input resistance, Rid is 260 kohm \n",
        "Common mode input resistance, Ric is 1301 Mohm \n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.9 - page 51"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Beta=110 #unitless\n",
      "VBE=0.7 #V\n",
      "VT=26 #mV\n",
      "VCC=10 #V\n",
      "VEE=10 #V\n",
      "RC=1.8 #kohm\n",
      "R=3.9 #kohm\n",
      "IExt=(VCC-VBE-(-VEE))/R #mA\n",
      "IT=IExt  #mA\n",
      "ICQ=IT/2 #mA\n",
      "V1=0 \n",
      "V2=0 #V\n",
      "VE=-2*VBE #V\n",
      "VC=VCC-ICQ*RC #V\n",
      "VCEQ=VC-VE #V\n",
      "# Q=[ICQ VCEQ] #[mA V](Q point)\n",
      "print \"Q point (ICQ(mA), VCEQ(V)), ICQ is \",round(ICQ,2),\"mA & VCEQ is \",round(VCEQ,2),\"V\"\n",
      "re=2*VT/IT #ohm(let re1=re2=re)\n",
      "reD=2*re #ohm\n",
      "Ad=-RC*1000/reD #unitless\n",
      "print \"Differntial mode gain, Ad = \",round(Ad,1) \n",
      "BetaD=Beta**2 #unitless\n",
      "Rid=2*BetaD*reD/1000 #kohm(let Rid1=Rid2=Rid)\n",
      "print \"Differntial input resistance, Rid is %0.1f kohm\" %Rid\n",
      "#Answer for Ad is wrong(+ve) in the book while it is negative."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Q point (ICQ(mA), VCEQ(V)), ICQ is  2.47 mA & VCEQ is  6.95 V\n",
        "Differntial mode gain, Ad =  -85.7\n",
        "Differntial input resistance, Rid is 508.6 kohm\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.10 - page 54"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Beta=100 #unitless\n",
      "VBE=0.7 #V\n",
      "R=18.6 #kohm\n",
      "VT=26 #mV\n",
      "VCC=5 #V\n",
      "VEE=5 #V\n",
      "IExt=(VCC-VBE-(-VEE))/R #mA\n",
      "IT=IExt  #mA\n",
      "re=2*VT/IT #ohm(let re1=re2=re)\n",
      "Rid=2*Beta*re/1000 #kohm(let Rid1=Rid2=Rid)\n",
      "print \"Differntial input resistances, Rid1=Rid2 is %0.1f kohm\" %Rid"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Differntial input resistances, Rid1=Rid2 is 20.8 kohm\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 2.11 - page 55"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Beta=100 #unitless\n",
      "VBE=0.7 #V\n",
      "RC=2.7 #kohm\n",
      "R=2.2 #kohm\n",
      "VT=26 #mV\n",
      "VCC=10 #V\n",
      "VEE=10 #V\n",
      "IExt=(VEE-VBE)/R #mA\n",
      "IT=IExt  #mA\n",
      "IE=IT/2 #mA(Let IE1=IE2=IE)\n",
      "re=2*VT/IT \n",
      "re1=re #ohm \n",
      "re2=re #ohm \n",
      "re3=re #ohm\n",
      "re4=re #ohm\n",
      "reD=re1+re2 #ohm\n",
      "BetaD=Beta**2 #unitless\n",
      "Ad=-RC*1000/reD #unitless\n",
      "print \"Differential voltage gain, Ad = \",round(Ad,2)\n",
      "Rid=2*BetaD*reD/1000 #kohm(let Rid1=Rid2=Rid)\n",
      "print \"Differntial input resistances, Rid1=Rid2 is %0.2f kohm \" %Rid \n",
      "#Answer in the book is not accurate."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Differential voltage gain, Ad =  -109.75\n",
        "Differntial input resistances, Rid1=Rid2 is 492.04 kohm \n"
       ]
      }
     ],
     "prompt_number": 28
    }
   ],
   "metadata": {}
  }
 ]
}