{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3 : Op-amp with Negative Feedback"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.1, Page No. 90"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# parameters of practical invertig amplifier\n",
      "\n",
      "import math\n",
      "#VAriable declaration\n",
      "R1 = 470                 # Resistor R1\n",
      "Rf = 4.7*10**3           # feedback resistor\n",
      "A  = 2*10**5             # Open loop gain\n",
      "Rin= 2*10**6             # input resistance\n",
      "Ro = 75                  # output resistance\n",
      "f  = 5                   # single break frequency\n",
      "V  = 15                  # dual supply voltage\n",
      "\n",
      "#Calculations\n",
      "K = Rf/(R1+Rf)\n",
      "B = R1/(R1+Rf)\n",
      "B = math.floor(B*10000)/10000 \n",
      "Af = (-A*Rf)/(R1+Rf+R1*A)\n",
      "Rinf = R1+(Rf*Rin/(Rf+Rin+A*Rin))\n",
      "Rof = Ro/(1+A*B)\n",
      "ff = f*(1+A*B)\n",
      "\n",
      "#Result\n",
      "print(\"Closed loop voltage gain with feedback = %.0f\\nInput resistane with feedback = %.4f ohm\"%(math.floor(Af),Rinf))\n",
      "print(\"Output resistance with feedback = %.2f m-ohm\\nBandwidth with feedback = %.3f KHz\"%(Rof*1000,ff/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Closed loop voltage gain with feedback = -10\n",
        "Input resistane with feedback = 470.0235 ohm\n",
        "Output resistance with feedback = 4.13 m-ohm\n",
        "Bandwidth with feedback = 90.905 KHz\n"
       ]
      }
     ],
     "prompt_number": 47
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.2, Page No. 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# inverting Op-amp design\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Af = -30.0               # voltage gain\n",
      "Rf = 1*10**6             # feedback resistance\n",
      "\n",
      "#Calcaculation\n",
      "R1 = -Rf/Af\n",
      "\n",
      "#Result\n",
      "print(\"R1 = %.2f k-ohm\\nlet us choose, R1 = 30 k-ohm + 3.3 k-ohm......standard values(refer fig. 3.7)\"%(R1/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R1 = 33.33 k-ohm\n",
        "let us choose, R1 = 30 k-ohm + 3.3 k-ohm......standard values(refer fig. 3.7)\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.3, Page No. 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(\"Theoretical example\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical example\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.4, Page No. 95"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Value of feedback resistance\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Af = 61               # gain with feedback\n",
      "R1 = 1000             # resistor R1\n",
      "\n",
      "\n",
      "#Calculations\n",
      "Rf = (Af-1)*R1\n",
      "\n",
      "#Result\n",
      "print(\"Rf = %d k-ohm\"%(Rf/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Rf = 60 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.5, Page No.95"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# parameters of non-invertig amplifier\n",
      "\n",
      "import math\n",
      "#VAriable declaration\n",
      "R1 = 1000.0              # Resistor R1\n",
      "Rf = 10*10**3            # feedback resistor\n",
      "A  = 2*10**5             # Open loop gain\n",
      "Rin= 2*10**6             # input resistance\n",
      "Ro = 75                  # output resistance\n",
      "f  = 5                   # single break frequency\n",
      "V  = 12                  # dual supply voltage\n",
      "\n",
      "#Calculations\n",
      "B = R1/(R1+Rf)\n",
      "#B = math.floor(B*10000)/10000 \n",
      "Af = A/(1+A*B)\n",
      "Rinf = Rin*(1+A*B)\n",
      "Rof = Ro/(1+A*B)\n",
      "ff = f*(1+A*B)\n",
      "\n",
      "#Result\n",
      "print(\"Closed loop voltage gain with feedback = %.3f\\nInput resistane with feedback = %.2f G-ohm\"%(Af,math.floor((Rinf/10**9)*100)/100))\n",
      "print(\"Output resistance with feedback = %.2f m-ohm\\nBandwidth with feedback = %.2f KHz\"%(Rof*1000,ff/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Closed loop voltage gain with feedback = 10.999\n",
        "Input resistane with feedback = 36.36 G-ohm\n",
        "Output resistance with feedback = 4.12 m-ohm\n",
        "Bandwidth with feedback = 90.91 KHz\n"
       ]
      }
     ],
     "prompt_number": 48
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.6, Page No. 96"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# inverter parameters\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "A  = 2*10**5             # Open loop gain\n",
      "Rin= 2*10**6             # input resistance\n",
      "Ro = 75                  # output resistance\n",
      "f  = 5                   # single break frequency\n",
      "\n",
      "\n",
      "#Calculations\n",
      "Af  = -1                 # inverter gain\n",
      "Rf = 330.0               # Rf = R1, Value assumed\n",
      "R1 = Rf\n",
      "B = R1/(R1+Rf)\n",
      "Rof = Ro/(A*B)\n",
      "BW = f*(A*B)\n",
      "\n",
      "#Result\n",
      "print(\"Af = %.0f\\nRif = %.0f ohm\\nRof = %.5f ohm\\nfF = %.1f MHz\"%(Af,Rf,Rof,BW/10**6))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Af = -1\n",
        "Rif = 330 ohm\n",
        "Rof = 0.00075 ohm\n",
        "fF = 0.5 MHz\n"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.7, Page No. 96"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# parameters of invertig and non-inverting amplifier\n",
      "\n",
      "import math\n",
      "#VAriable declaration\n",
      "R1_n = 1000.0            # Resistor R1 in case of non-inverting ampliflier\n",
      "Rf_n = 10*10**3          # feedback resistor in case of non-inverting ampliflier\n",
      "R1_i = 470.0             # Resistor R1 in case of inverting ampliflier\n",
      "Rf_i = 4.7*10**3         # feedback resistor in case of inverting ampliflier\n",
      "A  = 2*10**5             # Open loop gain\n",
      "Ri = 2*10**6             # input resistance\n",
      "Ro = 75                  # output resistance\n",
      "f  = 5                   # single break frequency\n",
      "V  = 15                  # dual supply voltage\n",
      "Vos = 13                 # output voltage swing\n",
      "\n",
      "#Calculations\n",
      "#(i) Non-inverting amplifier\n",
      "B = R1_n/(R1_n+Rf)\n",
      "Af = 1+(Rf_n/R1_n)\n",
      "Rinf = Ri*(1+A*B)\n",
      "Rof = Ro/(1+A*B)\n",
      "ff = f*(1+A*B)\n",
      "ff =ff/1000        # KHz\n",
      "VooT = Vos/(1+A*B)\n",
      "#(ii) Inverting amplifier\n",
      "B_i = R1_i/(R1_i+Rf)\n",
      "Af_i = -(Rf_i/R1_i)\n",
      "Rinf_i = R1_i\n",
      "Rof_i = Ro/(1+A*B_i)\n",
      "ff_i = f*(1+A*B_i)\n",
      "ff_i =ff_i/1000        # KHz\n",
      "VooT_i = Vos/(1+A*B_i)\n",
      "\n",
      "#Result\n",
      "print(\"(i) Non-inverting amplifier:\")\n",
      "print(\" Closed loop voltage gain with feedback = %.0f\\n Input resistane with feedback = %.4f ohm\"%(math.floor(Af),Rinf/10**9))\n",
      "print(\" Output resistance with feedback = %.5f ohm\\n Bandwidth with feedback = %.2f KHz\"%(Rof,math.ceil(ff*100)/100))\n",
      "print(\" Total output offset voltage with feedback = +/- %.3f mV\"%(VooT*1000))\n",
      "\n",
      "print(\"\\n(ii) Inverting amplifier:\")\n",
      "print(\" Closed loop voltage gain with feedback = %.0f\\n Input resistane with feedback = %.0f ohm\"%(math.floor(Af_i),Rinf_i))\n",
      "print(\" Output resistance with feedback = %.5f ohm\\n Bandwidth with feedback = %.2f KHz\"%(Rof,math.ceil(ff*100)/100))\n",
      "print(\" Total output offset voltage with feedback = +/- %.3f mV\"%(VooT*1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i) Non-inverting amplifier:\n",
        " Closed loop voltage gain with feedback = 11\n",
        " Input resistane with feedback = 36.3656 ohm\n",
        " Output resistance with feedback = 0.00412 ohm\n",
        " Bandwidth with feedback = 90.92 KHz\n",
        " Total output offset voltage with feedback = +/- 0.715 mV\n",
        "\n",
        "(ii) Inverting amplifier:\n",
        " Closed loop voltage gain with feedback = -10\n",
        " Input resistane with feedback = 470 ohm\n",
        " Output resistance with feedback = 0.00412 ohm\n",
        " Bandwidth with feedback = 90.92 KHz\n",
        " Total output offset voltage with feedback = +/- 0.715 mV\n"
       ]
      }
     ],
     "prompt_number": 68
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.8, Page No. 97"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# inverting amplifier parameters\n",
      "\n",
      "import math\n",
      "#variable declaration\n",
      "Rf = 500*10**3            # feedback resistance\n",
      "R1 = 5*10**3              # R1 resistance\n",
      "Vi = 0.1                  # input voltage\n",
      "\n",
      "\n",
      "#Calculation\n",
      "Af = -Rf/R1\n",
      "Ri = R1\n",
      "Ro = 0\n",
      "Vout = Af*Vi\n",
      "Iin = Vi/R1\n",
      "\n",
      "#Result\n",
      "print(\"Af = %d\\nRi = %d k-ohm\\nRo = %d ohm\\nVout = %d V\\nIin = %.2f mA\"%(Af,Ri/1000,Ro,Vout,Iin*1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Af = -100\n",
        "Ri = 5 k-ohm\n",
        "Ro = 0 ohm\n",
        "Vout = -10 V\n",
        "Iin = 0.02 mA\n"
       ]
      }
     ],
     "prompt_number": 76
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.9, Page No.97"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# input ippedance, Voltage gain and power gain(refer fig. 3.15)\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Rf = 1*10**6           # feedback resistance\n",
      "Rin = 1*10**6          # input resistance\n",
      "\n",
      "#Calculations\n",
      "Av = -Rf/Rin\n",
      "Ai = 1                #unity gain inverter\n",
      "Ap = abs(Av*Ai)\n",
      "\n",
      "#Result\n",
      "print(\"(i) Given amplifier is an inverting amplifier,therefore, Av = %.0f\"%Av)\n",
      "print(\"(ii) Because it is a unity gain inverter, so Ai = %.0f\"%Ai)\n",
      "print(\"(iii) Power gain of op-amp circuit, Ap = %.0f\"%Ap)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i) Given amplifier is an inverting amplifier,therefore, Av = -1\n",
        "(ii) Because it is a unity gain inverter, so Ai = 1\n",
        "(iii) Power gain of op-amp circuit, Ap = 1\n"
       ]
      }
     ],
     "prompt_number": 79
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.10, Page No. 98"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# inverting op-amp circuit design\n",
      "\n",
      "import math\n",
      "# Variable declaartion\n",
      "Av = -8                # voltage gain\n",
      "Vin = -1               # input voltage\n",
      "I1 = 15*10**-6         # maximum current through R1 and Rf\n",
      "\n",
      "#Calculations\n",
      "R1 = abs(Vin)/I1\n",
      "R1std = 68*10**3       # standard value\n",
      "Rf = -Av*R1\n",
      "\n",
      "#Result\n",
      "print(\"R1 = %.2f K-ohm\\t\\t(we use %.0f  K-ohm as standard value)\"%(R1/1000,R1std/1000))\n",
      "print(\"Rf = %f K-ohm\"%(Rf/1000))\n",
      "#Answer for Rf is wrong in the book"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R1 = 66.67 K-ohm\t\t(we use 68  K-ohm as standard value)\n",
        "Rf = 533.333333 K-ohm\n"
       ]
      }
     ],
     "prompt_number": 85
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 3.11, Page No. 98"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(\"Theoretical example\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical example\n"
       ]
      }
     ],
     "prompt_number": 86
    }
   ],
   "metadata": {}
  }
 ]
}