{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter- 2 : Introduction To Operational Amplifiers"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.2 - Page No 70"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "Vin1= 5 # in \u00b5V\n",
      "Vin1= Vin1*10**-6 # in V\n",
      "Vin2= -7 #in \u00b5V\n",
      "Vin2= Vin2*10**-6 # in V\n",
      "Av= 2*10**5 # unit less\n",
      "Rin= 2 # in M\u03a9\n",
      "Vout= (Vin1-Vin2)*Av # in V\n",
      "print \"The output voltage = %0.1f volts\" %Vout"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The output voltage = 2.4 volts\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.4 - Page No 71"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "# Given data\n",
      "Rs= 2 # in k\u03a9\n",
      "RL= 5 # in k\u03a9\n",
      "A= 10**5 # unit less\n",
      "Rin= 100 #in k\u03a9\n",
      "Rout= 50 # in \u03a9\n",
      "Vout= 10 # in V\n",
      "# For Vout = 10 V, V1= V2 = Vout\n",
      "V1= Vout # in V\n",
      "V2= V1 # in V\n",
      "# From equation V1= Vs*Rin/(Rin+Rs)\n",
      "Vs= V1*(Rin+Rs)/Rin # in V\n",
      "Vout_by_Vs= Vout/Vs # value of Vout/Vs\n",
      "print \"The value of Vs =%0.1f volts\" %Vs\n",
      "print \"The value of Vout/Vs = %0.2f\" %Vout_by_Vs\n",
      "print \"The input resistance of the circuit = %0.f k\u03a9\" %Rin"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Vs =10.2 volts\n",
        "The value of Vout/Vs = 0.98\n",
        "The input resistance of the circuit = 100 k\u03a9\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.6 - Page No 74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Given data\n",
      "Ad= 100 # differential mode gain\n",
      "Acm= 0.01 # common mode gain\n",
      "CMRR= Ad/Acm \n",
      "CMRR_desh= 20*math.log(CMRR,10) # CMRR in dB\n",
      "print \"CMRR = %0.f dB\" %CMRR_desh"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "CMRR = 80 dB\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.7 - Page No 74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "Ad= 10**5 # differential mode gain\n",
      "CMRR= 10**5 \n",
      "# Common-mode gain,\n",
      "Acm= Ad/CMRR \n",
      "print \"The common-mode gain = %0.f\" %Acm"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The common-mode gain = 1\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.8 - Page No 74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "V1= 10 # in mV\n",
      "V2= 9 # in mV\n",
      "Ad= 60 # differential voltage gain in dB\n",
      "Ad= 10**(Ad/20) \n",
      "CMRR= 80 # in dB\n",
      "CMRR= 10**(CMRR/20) \n",
      "Vd= V1-V2 # difference signal in mV\n",
      "Vcm= (V1+V2)/2 # common-mode signal in mV\n",
      "# Output voltage,\n",
      "Vout= Ad*Vd*(1+1/CMRR*Vcm/Vd) # in mV\n",
      "AdVd= Ad*Vd # in mV\n",
      "# Error voltage\n",
      "Verror= Vout-AdVd # in mV\n",
      "Per_error= Verror/Vout*100 # percentage error\n",
      "print \"The error voltage = %0.2f mV\" %Verror\n",
      "print \"The percentage error in the output voltage = %0.3f \" %Per_error"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The error voltage = 0.95 mV\n",
        "The percentage error in the output voltage = 0.095 \n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.9 - Page No 74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "V1= 745 # in \u00b5V\n",
      "V2= 740 # in \u00b5V\n",
      "Ad= 5*10**5 # differential voltage gain\n",
      "CMRR= 80 # in dB\n",
      "CMRR= 10**(CMRR/20) \n",
      "Vd= V1-V2 # difference signal in \u00b5V\n",
      "Vcm= (V1+V2)/2 # common-mode signal in \u00b5V\n",
      "# Output voltage,\n",
      "Vout= Ad*Vd*(1+1/CMRR*Vcm/Vd) # in \u00b5V\n",
      "AdVd= Ad*Vd # in \u00b5V\n",
      "# Error voltage\n",
      "Verror= Vout-AdVd # in \u00b5V\n",
      "Vout= Vout*10**-6 # in V\n",
      "Verror= Verror*10**-6 # in V\n",
      "Per_error= Verror/Vout*100 # percentage error\n",
      "print \"The output voltage = %0.6f V\" %Vout\n",
      "print \"The percentage error in the output voltage= %0.4f\" %Per_error"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The output voltage = 2.537125 V\n",
        "The percentage error in the output voltage= 1.4633\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.10 - Page No 76"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "Vd= 25 #differential input voltage in \u00b5V\n",
      "Vd= Vd*10**-6 # in V\n",
      "A= 200000 # open loop gain\n",
      "# Output voltage,\n",
      "Vout= A*Vd # in V\n",
      "print \"The output voltage = \u00b1 %0.f \" %Vout"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The output voltage = \u00b1 5 \n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.11 - Page 83"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "dVout= 20 # change in output voltage in V\n",
      "dt= 4 # change in time in \u00b5s\n",
      "SR= dVout/dt # slew rate in V/\u00b5s\n",
      "print \"The slew rate = %0.f V/\u00b5s\" %SR"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The slew rate = 5 V/\u00b5s\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.12 - Page No 83"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "IB1= 10 # in \u00b5A\n",
      "IB2= 7.5 # in \u00b5A\n",
      "# Input bias current,\n",
      "I_in_bias= (IB1+IB2)/2 # in \u00b5A\n",
      "# Input offset current,\n",
      "I_in_offset= IB1-IB2 # in \u00b5A\n",
      "print \"The input bias current = %0.2f \u00b5A\" %I_in_bias\n",
      "print \"The input offset current = %0.1f \u00b5A\" %I_in_offset"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The input bias current = 8.75 \u00b5A\n",
        "The input offset current = 2.5 \u00b5A\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.13 - Page No 83"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import pi\n",
      "# Given data\n",
      "SR= 6 # slew rate in V/\u00b5s\n",
      "SR= 6*10**6 # in V/s\n",
      "\n",
      "# Part (i) For Vmax= 1V\n",
      "Vmax= 1 # in V\n",
      "fmax= SR/(2*pi*Vmax) # limiting frequency in Hz\n",
      "fmax= fmax*10**-6 # in MHz\n",
      "print \"Part (i) : The limiting frequency for maximum voltage of 1V = %0.3f MHz\" %fmax\n",
      "\n",
      "# Part (ii) For Vmax= 10V\n",
      "Vmax= 10 # in V\n",
      "fmax= SR/(2*pi*Vmax) # limiting frequency in Hz\n",
      "fmax= fmax*10**-3 # in kHz\n",
      "print \"Part (ii) : The limiting frequency for maximum voltage of 10V = %0.1f kHz\"%fmax"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (i) : The limiting frequency for maximum voltage of 1V = 0.955 MHz\n",
        "Part (ii) : The limiting frequency for maximum voltage of 10V = 95.5 kHz\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example : 2.14 - Page No 84"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Given data\n",
      "Vpp= 3 # output voltage in V\n",
      "del_t= 4 # in \u00b5s\n",
      "del_V= 90*Vpp/100-10*Vpp/100 # in V\n",
      "# Required slew rate,\n",
      "SR= del_V/del_t # in V/\u00b5s\n",
      "print \"The required slew rate = %0.1f V/\u00b5s\" %SR"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The required slew rate = 0.6 V/\u00b5s\n"
       ]
      }
     ],
     "prompt_number": 22
    }
   ],
   "metadata": {}
  }
 ]
}