{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 15 : Operational Amplifier"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15.1a, Page No 572"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "v11=50.0      #in microV\n",
      "v21=-50.0     #in microV\n",
      "#Second Set of Input Signal\n",
      "v12=1050.0    #in microV\n",
      "v22=950.0     #in microV\n",
      "p=100.0      #Common Mode Rejection Ratio\n",
      "\n",
      "#Required Formulae\n",
      "#vo = Ad*vd*(1+vc/p*vd) .... p = commom mode rejection ratio\n",
      "#Ad  will be same for both case, So let us write Vo = vo/Ad = Ad*(1+vc/p*vd)\n",
      "\n",
      "#Calculations\n",
      "#First Set of Values\n",
      "vd1=v11-v21#in microV\n",
      "vc1=(v11+v21)/2#in microV\n",
      "Vo1 = vd1*(1+vc1/(p*vd1))\n",
      "\n",
      "#Second Set of Values\n",
      "vd2=v12-v22#in microV\n",
      "vc2=(v12+v22)/2#in microV\n",
      "Vo2 = vd2*(1+vc2/(p*vd2))\n",
      "\n",
      "#Results\n",
      "print(\"Percentage difference in output signal = %.2f v \" %(100*(Vo2-Vo1)/Vo1))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Percentage difference in output signal = 10.00 v \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15.1b, Page No 572"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#initialisation of variables\n",
      "v11=50.0    #in microV\n",
      "v21=-50.0   #in microV\n",
      "#Second Set of Input Signal\n",
      "v12=1050.0  #in microV\n",
      "v22=950.0  #in microV\n",
      "p=100.0    #Common Mode Rejection Ratio\n",
      "\n",
      "#Required Formulae\n",
      "#vo = Ad*vd*(1+vc/p*vd) .... p = commom mode rejection ratio\n",
      "#Ad  will be same for both case, So let us write Vo = vo/Ad = Ad*(1+vc/p*vd)\n",
      "\n",
      "#Calculations\n",
      "#First Set of Values\n",
      "vd1=v11-v21#in microV\n",
      "vc1=(v11+v21)/2#in microV\n",
      "Vo1 = vd1*(1+vc1/(p*vd1))\n",
      "\n",
      "#Second Set of Values\n",
      "vd2=v12-v22#in microV\n",
      "vc2=(v12+v22)/2#in microV\n",
      "Vo2 = vd2*(1+vc2/(p*vd2))\n",
      "\n",
      "\n",
      "#Now we have to calculate the same thing with common mode rejection ratio = 10000\n",
      "\n",
      "p=10000#Common Mode Rejection Ratio\n",
      "\n",
      "#First Set of Values\n",
      "vd1=v11-v21#in microV\n",
      "vc1=(v11+v21)/2#in microV\n",
      "Vo1 = vd1*(1+vc1/(p*vd1))\n",
      "\n",
      "#Second Set of Values\n",
      "vd2=v12-v22#in microV\n",
      "vc2=(v12+v22)/2#in microV\n",
      "Vo2 = vd2*(1+vc2/(p*vd2))\n",
      "\n",
      "#Results\n",
      "print(\"Percentage difference in output signal = %.2f v \" %(100*(Vo2-Vo1)/Vo1))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Percentage difference in output signal = 0.10 v \n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15.2 Page No 576"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#initialisation of variables\n",
      "Vbe1=0.7\n",
      "Vce3=0.2\n",
      "I3=5.0\n",
      "R3=0.4\n",
      "Vee=5\n",
      "Vcc=5\n",
      "Ic1=2.5\n",
      "Rc=1.0\n",
      "\n",
      "#Calculations\n",
      "Vcmmin=Vbe1+Vce3+(I3*R3)-Vee\n",
      "Vcmmax=Vcc-(Ic1*Rc)+0.6\n",
      "\n",
      "#Results\n",
      "print(\"The Vcm can vary from = %.2f v to \" %Vcmmin)\n",
      "print(\"%.2f v \" %Vcmmax)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Vcm can vary from = -2.10 v to \n",
        "3.10 v \n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15.3 Page No 583"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#initialisation of variables\n",
      "Vbe2=0.7\n",
      "Vce1=0.2\n",
      "I1=0.99\n",
      "R1=2.2\n",
      "Vee=6\n",
      "Vcc=6\n",
      "Ic2=0.495\n",
      "R2=7.75\n",
      "Vbc2=0.6\n",
      "\n",
      "#Calculations\n",
      "Vcmmin=Vbe2+Vce1+(I1*R1)-Vee\n",
      "Vcmmax=Vcc-(Ic2*R2)+0.6\n",
      "\n",
      "#Results\n",
      "print(\"The Vcm can vary from = %.2f v to \" %Vcmmin)\n",
      "print(\"%.2f v \" %Vcmmax)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Vcm can vary from = -2.92 v to \n",
        "2.76 v \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15.4 Page No 596"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#initialisation of variables\n",
      "\n",
      "f=32.0    #feedback in dB\n",
      "#from the Bodes plot we get that Avo = 2510\n",
      "Avo = 2510.0   #gain\n",
      "print('The parameters are R , r (for Rdash), C (for Cdash)')\n",
      "#Desensivity D = B*Rmo = Avo*(R/(R+r))\n",
      "#20log10(D ) = f\n",
      "\n",
      "#Calculations\n",
      "k = f - (20*math.log(Avo,10))\n",
      "#Let (R+r)/R = l\n",
      "l = 1.0/(10**(k/20))\n",
      "#R/(R+r) = fp/fz\n",
      "#For 45degree phase margin and 32dB of low frequency feedback we find by trial and error method from the graph\n",
      "fz = 10#in MHz\n",
      "fp = fz*l\n",
      "#to determine c we can arbitrarily choose R\n",
      "R = 1000.0   #in ohm\n",
      "\n",
      "#Results\n",
      "print(\"R = %.2f ohm \" %R)\n",
      "r = (l-1)*R\n",
      "print(\"r = %.2f ohm \" %r)\n",
      "C = 1/(2*math.pi*fz*r*10**-6)\n",
      "print(\"C = %.2f pF \" %C)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The parameters are R , r (for Rdash), C (for Cdash)\n",
        "R = 1000.00 ohm \n",
        "r = 62048.35 ohm \n",
        "C = 0.26 pF \n"
       ]
      }
     ],
     "prompt_number": 5
    }
   ],
   "metadata": {}
  }
 ]
}