{
 "metadata": {
  "name": "",
  "signature": "sha256:4a9283ba6472e11de214bfc0c69a7f007685d94fb7b513179011a2e471e81b7b"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7:Operational Amplifiers"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.1,Page number 361"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "V1=120                   #negative terminal Vn(uV)\n",
      "V2=80                    #positive terminal Vp(uV)\n",
      "Ad=10**3                 #difference mode gain\n",
      "\n",
      "\n",
      "#Calculations\n",
      "Vd=V1-V2                #difference mode signal(uV)  \n",
      "Vc=(V1+V2)/2            #common mode signal(uV)\n",
      "\n",
      "#Part a\n",
      "CMRR=100.                    #common mode rejection ratio\n",
      "Vo=Ad*Vd*(1+(Vc/(CMRR*Vd)))  #output voltage(mV)\n",
      "          \n",
      "#Part b\n",
      "CMRR=10**5.                    #common mode rejection ratio\n",
      "Vo1=Ad*Vd*(1+(1/CMRR)*(Vc/Vd)) #output voltage(mV) \n",
      "\n",
      "#Results\n",
      "print\"output voltage is\",round(Vo/1E+3),\"mV\"\n",
      "print\"output voltage is\",round(Vo1/1E+3),\"mV\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "output voltage is 41.0 mV\n",
        "output voltage is 40.0 mV\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.2,Page number 365"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "deltavi=0.5             #change in vi(V)\n",
      "deltat=10               #change in time(us)\n",
      "s=1                     #slew rate(V/us)\n",
      "\n",
      "#Calculations\n",
      "Kvf=(s*deltat)/deltavi  #closed loop gain of amplifier\n",
      "\n",
      "#Results\n",
      "print\"closed loop gain of amplifier is\",Kvf"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "closed loop gain of amplifier is 20.0\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.3,Page number 365"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "f=50*10**3.                  #OPAMP freequency(Hz)\n",
      "Vm=0.02                      #maximum value of signal voltage(V)\n",
      "S=.5*10**6                     #slew rate(V/s)\n",
      "\n",
      "#Calculations\n",
      "Kvf=S/(2*(math.pi)*f*Vm)    #closed loop gain of amplifier\n",
      "\n",
      "#Results\n",
      "print\"closed loop gain of amplifier is\",round(Kvf)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "closed loop gain of amplifier is 80.0\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.4,Page number 369"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Ic=100              #current at quinscent point(uA)\n",
      "beta=2000.          #current gain\n",
      "Ad=250              #difference mode gain\n",
      "CMRR=5000           #as 74 dB=5000,common mode rejection ratio(dB)\n",
      "\n",
      "#Calculations\n",
      "rpi=(25*beta)/Ic     #dynamic internal resistance(k ohms)  \n",
      "gm=beta/rpi          #transconductance(mS)\n",
      "Re=CMRR/gm           #emitter resistance(k ohms)\n",
      "Rc=(Ad*2)/gm         #collector resistance(k ohms) from formula Ad=gmRc/2\n",
      "Rin=2*rpi            #input resistance(k ohms)\n",
      "\n",
      "#Results\n",
      "print\"Re is\",Re,\"k ohms\"\n",
      "print\"Rc is\",Rc,\"k ohms\"\n",
      "print\"input resistance is\",Rin,\"k ohms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Re is 1250.0 k ohms\n",
        "Rc is 125.0 k ohms\n",
        "input resistance is 1000.0 k ohms\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.6,Page number 371"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Icq=.428            #current at quinscent point(uA)\n",
      "beta=200.           #current gain\n",
      "                    #as 74 dB=5000,common mode rejection ratio(dB)\n",
      "Rc=10.              #collector resistance(k ohms)    \n",
      "Re=16.              #emitter resistance(k ohms)   \n",
      "Vcc=15.             #supply voltage(V)\n",
      "\n",
      "#Calculations\n",
      "#Part b\n",
      "Ibq=Icq/beta         #Ib at Q(uA)\n",
      "rpi=(25*beta)/Icq    #dynamic resistance(k ohms)\n",
      "gm=beta/rpi          #transconductance\n",
      "\n",
      "#Part b\n",
      "vo1=Vcc-(Icq*Rc)    #terminal 1 voltage(V) \n",
      "vo2=vo1             #terminal 2 voltage(V) \n",
      "\n",
      "#Part c                  \n",
      "Ad=(gm*Rc)/2        #differential mode gain\n",
      "Ac=Rc/(2*Re)        #common mode gain\n",
      "CMRR=Ad/Ac          #common mode rejection ratio\n",
      "\n",
      "#Part d\n",
      "Rid=2*rpi                     #differential input resistance(k ohms)\n",
      "rpi=11.7                      #dynamic resistance(k ohms)\n",
      "Ric=rpi+(2*(beta+1)*Re)       #common mode input resistance(k ohms)\n",
      "\n",
      "#Results\n",
      "print\"Icq is\",Icq,\"mA,and Ibq is \",round((Ibq/1E-3),2),\"uA\"\n",
      "print\"vo1 and vo2 have same value as\",vo1,\"V\"\n",
      "print\"\",\n",
      "print\"Ad:\",round(Ad/1E-3),\",Ac:\",round(Ac,3),\"and CMRR is\",round(CMRR/1E-3)\n",
      "print\"Rid is\",round((Rid/1E+3),1),\"K ohms and Ric is\",round((Ric/1E+3),2),\" Mohms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Icq is 0.428 mA,and Ibq is  2.14 uA\n",
        "vo1 and vo2 have same value as 10.72 V\n",
        " Ad: 86.0 ,Ac: 0.313 and CMRR is 274.0\n",
        "Rid is 23.4 K ohms and Ric is 6.44  Mohms\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.7,Page number 373"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "R1=10.                   #series resistance(K ohms)\n",
      "Rf=10**3.                #feedback resistance(k ohms)   \n",
      "vo=-5.                   #output voltage(V)\n",
      "Ri=1000                  #input resistance(k ohms)\n",
      "Av=2.5*10**5             #gain\n",
      "\n",
      "#Calculations\n",
      "v1=-vo*(R1/Rf)           #input signal voltage(V)\n",
      "vi=-vo/Av                #inverting voltage(V)  \n",
      "i1=((v1*10**-3)-vi)/R1   #current through R1(uA)\n",
      "ii=vi/Ri                 #inverting current(uA)\n",
      "iF=-ii                   #forward current(uA)\n",
      "\n",
      "#Results\n",
      "print\"value of vi is\",vi,\"mV\"\n",
      "print\"value of ii:\",ii,\"uA i1:,\",i1,\"uA and iF is\",iF,\"uA\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "value of vi is 2e-05 mV\n",
        "value of ii: 2e-08 uA i1:, 3e-06 uA and iF is -2e-08 uA\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.8,Page number 374"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vs=4                    #source voltage(V)\n",
      "R1=10.                   #resistance(k ohms)\n",
      "Vb=Va=2                 #voltage at point A and point B\n",
      "Rf=30                   #forward resistance(k ohms)\n",
      "\n",
      "#Calculations\n",
      "I=(Vs-Vb)/R1           #current(mA)\n",
      "Vo=(-I*Rf)+Vb          #output voltage(V)  \n",
      "\n",
      "#Result\n",
      "print\"output voltage\",Vo,\"V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "output voltage -4.0 V\n"
       ]
      }
     ],
     "prompt_number": 45
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.9,Page number 375"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Rf=2              #as vs=2sinwt and vo=(1+Rf/Rs)*vb and vB=vA=vs\n",
      "Rs=1\n",
      "\n",
      "\n",
      "#Calculations\n",
      "vo=(1+(Rf/Rs))*2       #output voltage(V)\n",
      "\n",
      "#Result\n",
      "print\"output voltage\",vo,\"sinwt\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "output voltage 6 sinwt\n"
       ]
      }
     ],
     "prompt_number": 50
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.10,Page number 377"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Ro=100.                 #output resistance(ohms)\n",
      "vo=10.                  #output voltage(V)\n",
      "A=10**5.                #gain \n",
      "Ri=100*10**3            #input resistance(ohms) \n",
      "Rs=1*10**3.             #resistance(ohms)\n",
      "Rl=10*10**3             #load resistance(ohms)\n",
      "\n",
      "#Calculations\n",
      "#Part i\n",
      "iL=vo/Rl                  #load current(mA)\n",
      "Avi=vo+(iL*Ro)            #voltage gain without feedback\n",
      "vi=Avi/A                  #voltage(V)\n",
      "ii=vi/Ri                  #current(A)  \n",
      "vs=vo+ii*(Rs+Ri)          #source voltage(V)\n",
      "\n",
      "#Part ii\n",
      "Avf=vo/vs                #voltage gain with feedback  \n",
      "\n",
      "\n",
      "#Part iii\n",
      "Rif=vs/ii              #input resistance(ohms) \n",
      "Rof=Ro/A               #output resistance(ohms)\n",
      "\n",
      "#Results\n",
      "print\"vs is\",round(vs,4),\"V\"\n",
      "print\"vo/vs that is Avf is\",Avf\n",
      "print\"input and output resistances are\",Rif,Rof,\"ohms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "vs is 10.0001 V\n",
        "vo/vs that is Avf is 0.999989799104\n",
        "input and output resistances are 9901091099.01 0.001 ohms\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.11,Page number 382"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Vb=Va=3                     #voltage at A and B \n",
      "R1=40*10**3.                #input resistance(ohms)\n",
      "t=50*10**-3                 #time after switch is open(mS)\n",
      "V1=5                        #input voltage(V)\n",
      "\n",
      "#Calculations\n",
      "#Part a\n",
      "vo=-3                       #as Va=Vb=3\n",
      "\n",
      "#Part b\n",
      "i1=(V1-Vb)/R1               #input current(A)\n",
      "vo1=(-250*t)-Va             #vo at 50 mS\n",
      "\n",
      "#Result\n",
      "print\"output voltage\",vo1,\"V\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "output voltage -15.5 V\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.14,Page number 388"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "BW=30*10**3               #specified bandwidth(k Hz)\n",
      "fc=18*10**3               #centered frequency(Hz)\n",
      "R1=20                     #resistance(k ohms) \n",
      "R2=180                    #resistance(k ohms)  \n",
      "C=1.2*10**-9              #capacitance(F)\n",
      "G=40                      #pass band gain(dB)\n",
      "g=20                      #pass region gain(dB)\n",
      "\n",
      "#Calculationsv\n",
      "fc1=fc-(BW/2)             #high pass section frequency(Hz)\n",
      "fc2=fc+(BW/2)             #low pass section frequency(Hz)\n",
      "Rfc1=1/(2*math.pi*fc1*C)  #high pass section resistance(k ohms)\n",
      "Rfc2=1/(2*math.pi*fc2*C)  #low pass section resistance(k ohms)\n",
      "Gfc1=G-g                  #gain at frequency 0.3KHz(dB)\n",
      "Gfc2=G-2*6                #gain at frequency 132KHz(dB)\n",
      "\n",
      "#Results\n",
      "print\"R1 and R2 are\",R1,\"K ohms and\",R2,\"K ohms\"\n",
      "print\"Rfc1 is\",round(Rfc1/1E+3),\"k ohms and Rfc2 is\",round(Rfc2/1E+3),\"k ohms\"\n",
      "print\"filter gain at frequencies 0.3 KHz is\",Gfc1,\"dB and 132 k Hz are\",Gfc2,\"dB\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R1 and R2 are 20 K ohms and 180 K ohms\n",
        "Rfc1 is 44.0 k ohms and Rfc2 is 4.0 k ohms\n",
        "filter gain at frequencies 0.3 KHz is 20 dB and 132 k Hz are 28 dB\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.21,Page number 402"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "R=250            #resistance(k ohms)\n",
      "\n",
      "#Calculations\n",
      "#part a\n",
      "R1=-R/(-5)    #as vo=-5va+3vb(given),so when vb=0,vo/voa=-250/R1=-5\n",
      "\n",
      "#part b\n",
      "R2=R1/(2-1)   #as va=0\n",
      "              #vx=(R1/R1+R)*vob=(1/6)*vb\n",
      "              #vy=(R2/R1+R2)*vb\n",
      "              #vx=vy\n",
      "              #(1/6)*vob=(R2/R1+R2)*vb\n",
      "              #vob=3vb\n",
      "              #(1/6)*3=R2/(50+R2)\n",
      "                \n",
      "#Result\n",
      "print\"R1 and R2 are\",R1,\"K ohms and\",R2,\"K ohms\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R1 and R2 are 50 K ohms and 50 K ohms\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.22,Page number 403"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "R1=10*10**3                       #resistance(k ohms)\n",
      "C1=10**-6                         #capacitance(uF) \n",
      "C=0.1*10**-6                      #capacitance(uF) \n",
      "R=100*10**3                       #resistance(k ohms)   \n",
      "\n",
      "#Calculations\n",
      "#part b \n",
      "wc1=1/C1*R1                     #angular frequency(rad/s)\n",
      "wc2=1/C*R                       #angular frequency(rad/s)\n",
      "wc=wc1=wc2                      #angular frequency(rad/s)\n",
      "\n",
      "#Results\n",
      "print\"wc1 is\",wc1/1E+10,\"rad/s\"\n",
      "print\"wc2 is\",wc2/1e+10,\"rad/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "wc1 is 100.0 rad/s\n",
        "wc2 is 100.0 rad/s\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.23,Page number 404"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "vo1=5                  #say (V)\n",
      "K=25                   #proportionality constant  \n",
      "Q=250                  #volume of fluid passed across metering point(cm^3) \n",
      "R1=2.5                  #output resistance(k ohms)\n",
      "\n",
      "#Calculations\n",
      "C1=(K*Q)/(R1*vo1)     #capacitor(nF)\n",
      "\n",
      "#Results\n",
      "print\"C1 is\",round(C1/1E+1),\"uF\"\n",
      "print\"vo1 is -5V when Q=250 cm^3\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C1 is 50.0 uF\n",
        "vo1 is -5V when Q=250 cm^3\n"
       ]
      }
     ],
     "prompt_number": 6
    }
   ],
   "metadata": {}
  }
 ]
}