{
 "metadata": {
  "name": "Chapter_12"
 }, 
 "nbformat": 2, 
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown", 
     "source": [
      "<h1>Chapter 12: The Operational Amplifier<h1>"
     ]
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.1, Page Number: 392<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "import math", 
      "A_ol=100000.0;    #open loop voltage gain", 
      "A_cm=0.2;    #common mode gain", 
      "CMRR=A_ol/A_cm;", 
      "CMRR_dB=20*math.log10(CMRR);", 
      "print('CMRR = %d'%CMRR)", 
      "print('CMRR in decibels = %f'%CMRR_dB)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "CMRR = 500000", 
        "CMRR in decibels = 113.979400"
       ]
      }
     ], 
     "prompt_number": 1
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.2, Page Number: 395<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "del_t=1.0;    # in microseconds", 
      "#lower limit is -9V and upper limit is 9V from the graph", 
      "del_V_out=9.0-(-9.0);", 
      "slew_rate=del_V_out/del_t;", 
      "print('slew rate =%d V/microseconds'%slew_rate)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "slew rate =18 V/microseconds"
       ]
      }
     ], 
     "prompt_number": 2
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.3, Page Number: 400<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "R_f=100*10**3;", 
      "R_i=4.7*10**3;", 
      "A_cl_NI=1+(R_f/R_i);", 
      "print('closed loop voltage gain = %f'%A_cl_NI)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "closed loop voltage gain = 22.276596"
       ]
      }
     ], 
     "prompt_number": 3
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.4,Page Number: 402<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "R_i=2.2*10**3;", 
      "A_cl=-100.0;    #closed loop voltage gain", 
      "R_f=abs(A_cl)*R_i;", 
      "print('value of R_f = %d ohms'%R_f)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "value of R_f = 220000 ohms"
       ]
      }
     ], 
     "prompt_number": 4
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.5, Page Number: 404<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "Z_in=2*10**6;", 
      "Z_out=75.0;", 
      "A_ol=200000.0;", 
      "R_f=220.0*10**3;", 
      "R_i=10.0*10**3;", 
      "B=R_i/(R_i+R_f);    #B is attenuation", 
      "Z_in_NI=(1+A_ol*B)*Z_in;", 
      "Z_out_NI=Z_out/(1+A_ol*B);", 
      "A_cl_NI=1+(R_f/R_i);", 
      "Z_in_NI=Z_in_NI/10**10", 
      "print('input impedance = %f * 10^10 ohms'%Z_in_NI)", 
      "print('output impedance = %f ohms'%Z_out_NI)", 
      "print('closed loop voltage gain = %d'%A_cl_NI)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "input impedance = 1.739330 * 10^10 ohms", 
        "output impedance = 0.008624 ohms", 
        "closed loop voltage gain = 23"
       ]
      }
     ], 
     "prompt_number": 5
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.6, Page Number: 405<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "B=1.0;    #voltage follower configuration", 
      "A_ol=200000.0;", 
      "Z_in=2*10**6;", 
      "Z_out=75.0;", 
      "Z_in_VF=(1+A_ol)*Z_in;", 
      "Z_out_VF=Z_out/(1+A_ol);", 
      "Z_in_VF=Z_in_VF*10**-11", 
      "print('input impedance = %d * 10^11 Ohms'%Z_in_VF)", 
      "print('output impedance = %f Ohms'%Z_out_VF)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "input impedance = 4 * 10^11 Ohms", 
        "output impedance = 0.000375 Ohms"
       ]
      }
     ], 
     "prompt_number": 6
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.7, Page Number: 406<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "R_i=1.0*10**3;", 
      "R_f=100.0*10**3;", 
      "Z_in=4.0*10**6;", 
      "Z_out=50.0;", 
      "A_ol=50000.0;", 
      "B=R_i/(R_i+R_f);    #attenuation", 
      "Z_in_I=R_i;    #almost equal to R_i", 
      "Z_out_I=Z_out/(1+(A_ol*B));", 
      "A_cl_I=-R_f/R_i;", 
      "print('input impedance = %d Ohms'%Z_in_I)", 
      "print('output impedance = %f Ohms'%Z_out_I)", 
      "print('closed loop voltage gain =%d'%A_cl_I)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "input impedance = 1000 Ohms", 
        "output impedance = 0.100796 Ohms", 
        "closed loop voltage gain =-100"
       ]
      }
     ], 
     "prompt_number": 7
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.8, Page Number: 412<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "import math", 
      "f_c_ol=100.0;", 
      "A_ol_mid=100000.0;", 
      "f=0.0;", 
      "A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))", 
      "print('open loop gain when f=0Hz is %f'%A_ol);", 
      "f=10.0;", 
      "A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))", 
      "print('open loop gain when f=10Hz is %f'%A_ol)", 
      "f=100.0;", 
      "A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))", 
      "print('open loop gain when f=100Hz is %f'%A_ol)", 
      "f=1000.0;", 
      "A_ol=A_ol_mid/(math.sqrt(1+(f/f_c_ol)**2))", 
      "print('open loop gain when f=1000Hz is %f'%A_ol)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "open loop gain when f=0Hz is 100000.000000", 
        "open loop gain when f=10Hz is 99503.719021", 
        "open loop gain when f=100Hz is 70710.678119", 
        "open loop gain when f=1000Hz is 9950.371902"
       ]
      }
     ], 
     "prompt_number": 8
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.9,Page Number: 413<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "import math", 
      "f_c=100.0;", 
      "f=1.0;", 
      "theta_rad=-math.atan((f/f_c))", 
      "theta=theta_rad*180/math.pi;", 
      "print('phase lag when f=1Hz     = %f degrees'%theta)", 
      "", 
      "f=10.0;", 
      "theta_rad=-math.atan((f/f_c))", 
      "theta=theta_rad*180/math.pi;", 
      "print('phase lag when f=10Hz    = %f degrees'%theta)", 
      "f=100.0;", 
      "theta_rad=-math.atan((f/f_c))", 
      "theta=theta_rad*180/math.pi; ", 
      "print('phase lag when f=100Hz   = %f degrees'%theta)", 
      "f=1000.0;", 
      "theta_rad=-math.atan((f/f_c))", 
      "theta=theta_rad*180/math.pi;", 
      "print('phase lag when f=1000Hz  = %f degrees'%theta)", 
      "f=10000.0;", 
      "theta_rad=-math.atan((f/f_c))", 
      "theta=theta_rad*180/math.pi;", 
      "print('phase lag when f=10000Hz = %f degrees'%theta)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "phase lag when f=1Hz     = -0.572939 degrees", 
        "phase lag when f=10Hz    = -5.710593 degrees", 
        "phase lag when f=100Hz   = -45.000000 degrees", 
        "phase lag when f=1000Hz  = -84.289407 degrees", 
        "phase lag when f=10000Hz = -89.427061 degrees"
       ]
      }
     ], 
     "prompt_number": 9
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.10, Page Number: 415<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "import math", 
      "A_v1=40.0;    #all gains are in decibels", 
      "A_v2=32.0;", 
      "A_v3=20.0;", 
      "f_c1=2*10**3;", 
      "f_c2=40*10**3;", 
      "f_c3=150*10**3;", 
      "f=f_c1;", 
      "A_ol_mid=A_v1+A_v2+A_v3;", 
      "#theta 1", 
      "theta_rad1=-math.atan((f/f_c1))", 
      "theta1=theta_rad1*180/math.pi;", 
      "", 
      "#theta 2", 
      "theta_rad2=-math.atan((f/f_c2))", 
      "theta2=theta_rad2*180/math.pi;", 
      "", 
      "#theta 3", 
      "theta_rad3=-math.atan((f/f_c3))", 
      "theta3=theta_rad3*180/math.pi;", 
      "", 
      "theta_tot=theta1+theta2+theta3;", 
      "print('open loop midrange gain in decibels is %d'%A_ol_mid)", 
      "print('total phase lag in degrees is %d'%theta_tot)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "open loop midrange gain in decibels is 92", 
        "total phase lag in degrees is -45"
       ]
      }
     ], 
     "prompt_number": 10
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.11, Page Number: 416<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "A_ol_mid=150000.0;    #open loop midrange gain", 
      "B=0.002;    #feedback attenuation", 
      "BW_ol=200;    #open loop bandwidth", 
      "BW_cl=BW_ol*(1+B*A_ol_mid);", 
      "print('closed loop bandwidth = %d Hz'%BW_cl)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "closed loop bandwidth = 60200 Hz"
       ]
      }
     ], 
     "prompt_number": 11
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 12.12, Page Number: 417<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "BW=3*10**6;    #unity gain bandwidth", 
      "A_ol=100.0;    #open loop gain", 
      "print(\"non-inverting amplifier\")", 
      "R_f=220.0*10**3;", 
      "R_i=3.3*10**3;", 
      "A_cl=1+(R_f/R_i);    #closed loop gain", 
      "BW_cl=BW/A_cl;", 
      "print('closed loop bandwidth = %f Hz'%BW_cl)", 
      "print(\"inverting amplifier\")", 
      "R_f=47.0*10**3;", 
      "R_i=1.0*10**3;", 
      "A_cl=-R_f/R_i;", 
      "BW_cl=BW/(abs(A_cl));", 
      "print('closed loop bandwidth = %f Hz'%BW_cl)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "non-inverting amplifier", 
        "closed loop bandwidth = 44334.975369 Hz", 
        "inverting amplifier", 
        "closed loop bandwidth = 63829.787234 Hz"
       ]
      }
     ], 
     "prompt_number": 12
    }
   ]
  }
 ]
}