{
 "metadata": {
  "name": "",
  "signature": "sha256:044922821cb1a1b0c88578b071d30db5925d3f145784f5c6308641fcf8036e67"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter4 - Op-amps with negative feedback"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.1 - page 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "AOL=2*10**5 #unitless\n",
      "fo=5 #Hz\n",
      "ACL=100 #unitless\n",
      "SF=AOL/ACL #unitless\n",
      "fodash=SF*fo #Hz\n",
      "fodash/=1000 #kHz\n",
      "print \"Bandwidth with feedback is %0.2f kHz\" %fodash\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Bandwidth with feedback is 10.00 kHz\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.2 - page : 99"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "AOL=2*10**5 #unitless\n",
      "Ri=1.5 #kohm\n",
      "Rf=12 #kohm\n",
      "Rio=1 #Mohm\n",
      "Ro=100 #ohm\n",
      "fo=5 #Hz\n",
      "Beta=Ri/(Ri+Rf) #unitless\n",
      "SF=(1+AOL)*Beta #unitless\n",
      "ACL=AOL/SF #unitless\n",
      "print \"Value of ACL is %0.2f\" % ACL\n",
      "#In case of ideal opamp\n",
      "ACL=1+Rf/Ri #unitless\n",
      "print \"In case of ideal opamp, Value of ACL is %0.2f \" %ACL \n",
      "Rif=Rio*SF #kohm\n",
      "print \"Value of Rif is %0.2f Mohm\" %Rif\n",
      "print \"This is a large value can be assumed as infity resistance.\"\n",
      "Rof=Ro/SF #ohm\n",
      "Rof*=1000  #mohm\n",
      "print \"Value of Rof is %0.2f mohm\" %Rof\n",
      "fodash=SF*fo #Hz\n",
      "fodash/=1000 #kHz\n",
      "print \"Bandwidth with feedback, fo_dash is %0.f kHz\" %fodash\n",
      "#Answer for Rif in the book has mistake of unit."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Value of ACL is 9.00\n",
        "In case of ideal opamp, Value of ACL is 9.00 \n",
        "Value of Rif is 22222.33 Mohm\n",
        "This is a large value can be assumed as infity resistance.\n",
        "Value of Rof is 4.50 mohm\n",
        "Bandwidth with feedback, fo_dash is 111 kHz\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.3 - page : 99"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "AOL=float(\"inf\") #unitless\n",
      "Rio=float(\"inf\") #ohm\n",
      "Ri=1.0 #kohm\n",
      "Rf=15.0 #kohm\n",
      "SF=float(\"inf\") #unitless #as SF=1+AOL*Beta\n",
      "Beta=Ri/(Ri+Rf) #unitless\n",
      "ACL=1/Beta #unitless\n",
      "print \"Input impedence(ohm) for ideal opamp is %0.2f \" %Rio \n",
      "print \"Gain of the circuit, ACL is %0.f \" %ACL "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Input impedence(ohm) for ideal opamp is inf \n",
        "Gain of the circuit, ACL is 16 \n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.4 - page : 100"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "AOL=400 #unitless\n",
      "Rio=500 #kohm\n",
      "Ro=75 #ohm\n",
      "ACL=100 #unitlessc\n",
      "SF=AOL/ACL #unitless\n",
      "Rif=Rio*SF #kohm\n",
      "Rif/=1000 #Mohm\n",
      "print \"Input impedence, Rif is %0.2f Mohm \" %Rif \n",
      "Rof=Ro/SF #ohm\n",
      "print \"Output impedence, Rof is %0.2f ohm \" %Rof\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Input impedence, Rif is 2.00 Mohm \n",
        "Output impedence, Rof is 18.75 ohm \n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.5 - page : 100"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "ACL=200.0 #unitless\n",
      "AOL=2*10.0**5 #unitless\n",
      "Rio=2.0 #Mohm\n",
      "Ro=75 #ohm\n",
      "Ri=1 #kohm(Assumed)\n",
      "SF=AOL/ACL #unitless\n",
      "Beta=(SF-1)/AOL #unitless\n",
      "Rf=Ri*(1-Beta)/Beta #kohm\n",
      "print \"Input impedence, Rif is %0.f kohm\" %Ri \n",
      "print \"Feedback impedence, Rf is %0.f kohm \" %Rf \n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Input impedence, Rif is 1 kohm\n",
        "Feedback impedence, Rf is 199 kohm \n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.6 - page : 101"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "AOL=50 #unitless\n",
      "Beta=0.8 #unitless\n",
      "deltaAOL=-20 #%(Change in open loop gain)\n",
      "deltaBeta=15 #%(Change in feedback factor)\n",
      "AOLnew=AOL+AOL*deltaAOL/100 #unitless(AOL after change)\n",
      "Betanew=Beta+Beta*deltaBeta/100 #unitless(Beta after change)\n",
      "ACL=AOLnew/(1+AOLnew*Betanew) #unitless\n",
      "print \"Close loop gain, ACL is %0.2f \" %ACL "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Close loop gain, ACL is 1.06 \n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.7 - page : 102"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "AOL=500 #unitless\n",
      "Rio=300 #kohm\n",
      "Ro=100 #ohm\n",
      "ACL=AOL/(1+AOL) #unitless\n",
      "Rif=Rio*(1+AOL)/1000 #Mohm\n",
      "Rof=Ro/(1+AOL) #ohm\n",
      "print \"Close loop gain, ACL is %0.2f \" %ACL  \n",
      "print \"Value of Rif is %0.f Mohm \" %Rif\n",
      "print \"Value of Rof is %0.1f ohm \" %Rof "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Close loop gain, ACL is 1.00 \n",
        "Value of Rif is 150 Mohm \n",
        "Value of Rof is 0.2 ohm \n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.8 - page : 111"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Iin=1 #mA\n",
      "Rf=1 #kohm\n",
      "IB=0 #for ideal opamp\n",
      "If=Iin-IB #mA\n",
      "Vout=-If*Rf #V\n",
      "print \"Output Voltage is %0.2f V \" %Vout "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Output Voltage is -1.00 V \n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.9 - page : 111"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "I2=1 #mA\n",
      "Rf=4.7 #kohm\n",
      "#Case 1st\n",
      "I1=500 #micro A\n",
      "Vout1=-I1*10**-6*Rf*10**3 #V\n",
      "print \"For 500 uA current, Output Voltage is %0.2f V \" %Vout1 \n",
      "#Case 2nd\n",
      "I2=1 #mA\n",
      "Vout2=-I2*10**-3*Rf*10**3 #V\n",
      "print \"For 1 mA current, Output Voltage is %0.2f V \" %Vout2 \n",
      "deltaVout=Vout2-Vout1 #V\n",
      "print \"Variation in Output Voltage is %0.2f V \" %deltaVout "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "For 500 uA current, Output Voltage is -2.35 V \n",
        "For 1 mA current, Output Voltage is -4.70 V \n",
        "Variation in Output Voltage is -2.35 V \n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.10 - page : 112"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "AOL=2*10**5 #unitless\n",
      "Rio=2 #Mohm\n",
      "Ro=75 #ohm\n",
      "Ri=1 #kohm\n",
      "Rf=10 #kohm\n",
      "ACL=-AOL*Rf/(Rf+Ri+AOL*Ri) #unitless(Exact)\n",
      "print \"Exact close loop voltage gain is %0.2f \" %ACL \n",
      "ACL=-Rf/Ri #unitless(Approximate)\n",
      "print \"Approximate close loop voltage gain is %0.2f \" %ACL\n",
      "Beta=Ri/(Ri+Rf) #unitless\n",
      "SF=1+AOL*Beta #unitless\n",
      "Rif=Rio*10**6/SF #ohm\n",
      "print \"Input impedence after feedback is %0.f ohm\" %Rif\n",
      "# Answer for last part wrong in the textbook."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Exact close loop voltage gain is -10.00 \n",
        "Approximate close loop voltage gain is -10.00 \n",
        "Input impedence after feedback is 110 ohm\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.11 - page : 113"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Ri=2 #kohm\n",
      "Rf=200 #kohm\n",
      "#For 741C\n",
      "fo=5 #Hz\n",
      "AOL=2*10**5 #unitless\n",
      "UGB=1 #MHz\n",
      "ACL=-AOL*Rf/(Rf+Ri+AOL*Ri) #unitless(Exact)\n",
      "print \"Close loop voltage gain is %0.2f \" %ACL \n",
      "fodash=fo*AOL/-ACL #Hz\n",
      "fodash/=1000   #kHz\n",
      "print \"Bandwidth, fo_dash is %0.f kHz \" %fodash "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Close loop voltage gain is -99.95 \n",
        "Bandwidth, fo_dash is 10 kHz \n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.12 - page : 113"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from math import sqrt\n",
      "Beta=0.06 #feedback factor\n",
      "fo=100 #Hz\n",
      "AOL=40000 #unitless(at dc)\n",
      "SFdc=1+AOL*Beta #sacrifice factor at dc\n",
      "f=1 #kHz\n",
      "f=f*10**3 #Hz\n",
      "SF1=1+AOL*Beta/sqrt(1+f**2/fo**2) #sacrifice factor at 1 kHz\n",
      "#(a)\n",
      "ACL=AOL/SFdc #(unitless)exact close loop gain at dc\n",
      "print \"Exact close loop gain at dc is %0.2f \" %ACL \n",
      "#(b)\n",
      "ACL=1/Beta #(unitless)approximate close loop gain at dc\n",
      "print \"Approximate close loop gain at dc is %0.2f \" %ACL \n",
      "#(c)\n",
      "AOL=3980 #unitless(at dc)\n",
      "ACL=AOL/SF1 #(unitless)exact close loop gain at 1kHz\n",
      "print \"Exact close loop gain at 1kHz is %0.2f \" %ACL\n",
      "# Answer not accurate in the textbook."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Exact close loop gain at dc is 16.66 \n",
        "Approximate close loop gain at dc is 16.67 \n",
        "Exact close loop gain at 1kHz is 16.60 \n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex 4.13 - page : 115"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "Beta=0.04 #feedback factor\n",
      "AOL=5000 #unitless(at dc)\n",
      "Rio=40 #kohm\n",
      "Ro=1 #kohm\n",
      "SF=1+AOL*Beta #sacrifice factor at dc\n",
      "Rif=Rio/SF*1000 #ohm\n",
      "print \"Input impedence is %0.f ohm \" %Rif \n",
      "Rof=Ro*1000/SF #ohm\n",
      "print \"Output impedence is %0.2f ohm \" %Rof "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Input impedence is 199 ohm \n",
        "Output impedence is 4.98 ohm \n"
       ]
      }
     ],
     "prompt_number": 41
    }
   ],
   "metadata": {}
  }
 ]
}