{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 33 : Operational Amplifiers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_1 Page No.  1072"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Differential Voltage Gain =143.00\n",
      "The Ac Output Voltage = 1.43 Volts(p-p)\n"
     ]
    }
   ],
   "source": [
    "# Calculate the differential voltage gain, Ad, and the ac output voltage, Vout.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Vin = 10*10**-3#    # Input voltage=10 mVolts(p-p)\n",
    "Rc = 10*10**3#      # Collector resistance=10 kOhms\n",
    "Ie = 715.*10**-6#    # Emitter current=715 uAmps\n",
    "\n",
    "re = (25*10**-3)/Ie#\n",
    "\n",
    "Ad = Rc/(2*re)#\n",
    "print 'The Differential Voltage Gain =%0.2f'%Ad\n",
    "\n",
    "Av = Ad\n",
    "\n",
    "Vo = Av*Vin#\n",
    "print 'The Ac Output Voltage = %0.2f Volts(p-p)'%Vo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_2 Page No.  1073"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Common-Mode Voltage Gain Acm = 0.50\n",
      "The Commom-Mode Rejection Ratio = 49.12 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "# calculate the common-mode voltage gain, ACM, and the CMRR (dB).\n",
    "\n",
    "# Given data\n",
    "\n",
    "Rc = 10*10**3#     # Collector resistance=10 kOhms\n",
    "Re = 10.*10**3#     # Emitter resistance=10 kOhms\n",
    "Ad = 142.86#      # Differential gain=142.86\n",
    "\n",
    "Acm = Rc/(2*Re)#\n",
    "print 'The Common-Mode Voltage Gain Acm = %0.2f'%Acm\n",
    "\n",
    "CMRR = 20*log10(Ad/Acm)#\n",
    "print 'The Commom-Mode Rejection Ratio = %0.2f dB'%CMRR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_3 Page No.  1074"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output Frequency = 7.96e+04 Hertz\n",
      "i.e 79.6 kHz\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "# Calculate fmax for an op amp that has an Sr of 5 V/u\u0002s and a peak output voltage of 10 V.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Vpk = 10.#       # Peak output voltage=10 Volts\n",
    "Sr = 5./10**-6#   # Slew rate=5 V/us\n",
    "\n",
    "\n",
    "fo = Sr/(2*pi*Vpk)#\n",
    "print 'The Output Frequency = %0.2e Hertz'%fo\n",
    "print 'i.e 79.6 kHz'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_4 Page No.  1075"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Closed-Loop Voltage Gain Acl =-10.00\n",
      "The Output Voltage = 10.00 Volts(p-p)\n",
      "The -ve sign indicates that input and output voltages are 180° out-of-phase\n"
     ]
    }
   ],
   "source": [
    "# calculate the closed-loop voltage gain, Acl, and the output voltage, Vout.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Vin = 1.#        # Input voltage=1 Volts(p-p)\n",
    "Rf = 10.*10**3#   # Feedback resistance=10 kOhms\n",
    "Ri = 1.*10**3#    # Input resistance=1 kOhms\n",
    "\n",
    "Acl = -(Rf/Ri)#\n",
    "print 'The Closed-Loop Voltage Gain Acl =%0.2f'%Acl\n",
    "\n",
    "Vo = -Vin*Acl#\n",
    "print 'The Output Voltage = %0.2f Volts(p-p)'%Vo\n",
    "print 'The -ve sign indicates that input and output voltages are 180° out-of-phase'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_5 Page No.  1076"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Differential Input Voltage = 1.00e-04 Volts(p-p)\n",
      "i.e 100 uVolts(p-p)\n"
     ]
    }
   ],
   "source": [
    "#If Avol equals 100,000, calculate the value of Vid.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Avol = 100000.#  # Open loop voltage gain=100,000\n",
    "Vo = 10.#        # Output voltage=10 Volts(p-p)\n",
    "\n",
    "Vid = Vo/Avol#\n",
    "print 'The Differential Input Voltage = %0.2e Volts(p-p)'%Vid\n",
    "print 'i.e 100 uVolts(p-p)'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_6 Page No. 1078"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Input Impedence = 1.00e+03 Ohms\n",
      "i.e 1 kOhms\n",
      "The Closed Loop Output Impedence = 0.01 Ohms\n"
     ]
    }
   ],
   "source": [
    "# calculate Zin and Zout(CL). Assume AVOL is\u0004 100,000 and Zout(OL) is\u0004 75 Ohms.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Avol = 100000.#  # Open loop voltage gain=100,000\n",
    "Rf = 10.*10**3#   # Feedback resistance=10 kOhms\n",
    "Ri = 1.*10**3#    # Input resistance=1 kOhms\n",
    "Zool = 75.#      # Output impedence (open-loop)=75 Ohms\n",
    "\n",
    "Zi = Ri#\n",
    "print 'The Input Impedence = %0.2e Ohms'%Zi\n",
    "print 'i.e 1 kOhms'\n",
    "\n",
    "Beta = Ri/(Ri+Rf)#\n",
    "\n",
    "A = Avol*Beta#\n",
    "\n",
    "Zocl = Zool/(1+A)#\n",
    "print 'The Closed Loop Output Impedence = %0.2f Ohms'%Zocl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_7 Page No.  1083"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output Frequency = 1.59e+04 Hertz\n",
      "i.e 15.915 kHz\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "# Calculate the 5-V power bandwidth.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Vo = 10.#            # Output voltage=10 Volts(p-p)\n",
    "Sr = 0.5/10**-6#     # Slew rate=0.5 V/us\n",
    "\n",
    "Vpk = Vo/2#\n",
    "\n",
    "fo = Sr/(2*pi*Vpk)#\n",
    "print 'The Output Frequency = %0.2e Hertz'%fo\n",
    "print 'i.e 15.915 kHz'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_8 Page No.  1085"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Closed-Loop Voltage Gain Acl =11.00\n",
      "The Output Voltage = 11.00 Volts(p-p)\n"
     ]
    }
   ],
   "source": [
    "# Calculate the closed-loop voltage gain, Acl, and the output voltage, Vout.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Vin = 1#        # Input voltage=1 Volts(p-p)\n",
    "Rf = 10.*10**3#   # Feedback resistance=10 kOhms\n",
    "Ri = 1.*10**3#    # Input resistance=1 kOhms\n",
    "\n",
    "Acl = 1+(Rf/Ri)#\n",
    "print 'The Closed-Loop Voltage Gain Acl =%0.2f'%Acl\n",
    "\n",
    "Vo = Vin*Acl#\n",
    "print 'The Output Voltage = %0.2f Volts(p-p)'%Vo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_9 Page No.  1089"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Input Impedence Closed-Loop = 1.82e+10 Ohms\n",
      "i.e 18 GOhms\n",
      "The Closed-Loop Output Impedence = 0.01 Ohms\n"
     ]
    }
   ],
   "source": [
    "# Calculate Zin(CL) and Zout(CL). Assume Rin is\u0004 2 MOhms\u0006, Avol is 100,000, and Zout(OL) is 75 Ohms.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Avol = 100000.#  # Open loop voltage gain=100,000\n",
    "Ri = 2.*10**6#    # Input resistance=2 MOhms\n",
    "B = 0.0909#     # Beta=0.0909\n",
    "Zool = 75.#      # Output impedence (open-loop)=75 Ohms\n",
    "\n",
    "Zicl = Ri*(1+Avol*B)#\n",
    "print 'The Input Impedence Closed-Loop = %0.2e Ohms'%Zicl\n",
    "print 'i.e 18 GOhms'\n",
    "\n",
    "A = Avol*B#\n",
    "\n",
    "Zocl = Zool/(1+A)#\n",
    "print 'The Closed-Loop Output Impedence = %0.2f Ohms'%Zocl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_10 Page No.  1090"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Input impedence closed-loop = 2.00e+11 Ohms\n",
      "i.e 200 GOhms\n",
      "The Closed loop Output Impedence = 0.001 Ohms\n"
     ]
    }
   ],
   "source": [
    "# Assume Rin is 2 MOhms, Avol is 100,000, and Zout(OL) is 75 Ohms. Calculate Zin(CL) and Zout(CL)\n",
    "\n",
    "# Given data\n",
    "\n",
    "Avol = 100000.#  # Open loop voltage gain=100,000\n",
    "Ri = 2.0*10**6#    # Input resistance=2 MOhms\n",
    "B = 1.0#          # Beta=1\n",
    "Zool = 75.#      # Output impedence (open-loop)=75 Ohms\n",
    "\n",
    "Zicl = Ri*(1+Avol*B)#\n",
    "print 'The Input impedence closed-loop = %0.2e Ohms'% Zicl\n",
    "print 'i.e 200 GOhms'\n",
    "\n",
    "A = Avol*B#\n",
    "\n",
    "Zocl = Zool/(1+A)#\n",
    "print 'The Closed loop Output Impedence = %0.3f Ohms'%Zocl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_11 Page No.  1091"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Closed-Loop Voltage Gain Acl =-10.00\n",
      "The Output Voltage = 7.50 Volts\n"
     ]
    }
   ],
   "source": [
    "# Calculate the closed-loop voltage gain, Acl, and the dc voltage at the op-amp output terminal.\n",
    "\n",
    "# Given data\n",
    "\n",
    "V = 15.#         # Voltage at +ve terminal of op-amp=15 Volts\n",
    "Rf = 10.*10**3#   # Feedback resistance=10 kOhms\n",
    "Ri = 1.*10**3#    # Input resistance=1 kOhms\n",
    "R1 = 10.*10**3#   # Resistance1=10 kOhms\n",
    "R2 = 10.*10**3#   # Rsistance2=10 kOhms\n",
    "\n",
    "Acl = -(Rf/Ri)#\n",
    "print 'The Closed-Loop Voltage Gain Acl =%0.2f'%Acl\n",
    "\n",
    "Vo = V*(R2/(R1+R2))#\n",
    "print 'The Output Voltage = %0.2f Volts'%Vo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_12 Page No.  1095"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output Voltage 1 Volts\n"
     ]
    }
   ],
   "source": [
    "# Calculate the output voltage, Vout.\n",
    "\n",
    "# Given data\n",
    "\n",
    "V1 = 1#     # Input voltage1=1 Volts\n",
    "V2 = -5#    # Input voltage2=-5 Volts\n",
    "V3 = 3#     # Input voltage3=3 Volts\n",
    "\n",
    "Vo = -(V1+V2+V3)#\n",
    "print 'The Output Voltage %0.f Volts'%Vo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_13 Page No.  1097"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output Voltage = 3.00 Volts\n"
     ]
    }
   ],
   "source": [
    "# Calculate the output voltage, Vout.\n",
    "\n",
    "# Given data\n",
    "\n",
    "V1 = 0.5#       # Input voltage1=0.5 Volts\n",
    "V2 = -2.0#        # Input voltage2=-2 Volts\n",
    "Rf = 10.*10**3#   # Feedback resistance=10 kOhms\n",
    "R1 = 1.*10**3#    # Resistance1=1 kOhms\n",
    "R2 = 2.5*10**3#  # Rsistance2=2.5 kOhms\n",
    "\n",
    "A = Rf/R1#\n",
    "B = Rf/R2#\n",
    "\n",
    "Vo = -(A*V1+B*V2)#\n",
    "print 'The Output Voltage = %0.2f Volts'%Vo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_14 Page No.  1101"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output Voltage of Case A = -12.50 Volts\n",
      "The Output Voltage of Case B = 10.00 Volts\n",
      "The Output Voltage of Case C = -0.00 Volts\n"
     ]
    }
   ],
   "source": [
    "# Calculate the output voltage, Vout, if (a) Vx is 1 Vdc and Vy is -0.25 Vdc, (b) -Vx is 0.5 Vdc and Vy is 0.5 Vdc, (c) Vx is 0.3 V and Vy is 0.3 V.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Rf = 10.*10**3#   # Feedback resistance=10 kOhms\n",
    "R1 = 1.*10**3#    # Resistance1=1 kOhms\n",
    "Vx1 = 1.#        # Input voltage Vx1 at -ve terminal of op-amp=1 Volts\n",
    "Vy1 = -0.25#    # Input voltage Vy1 at +ve terminal of op-amp=-0.25 Volts\n",
    "Vx2 = -0.5#     # Input voltage Vx2 at -ve terminal of op-amp=-0.5 Volts\n",
    "Vy2 = 0.5#    # Input voltage Vy2 at +ve terminal of op-amp=0.5 Volts\n",
    "Vx3 = 0.3#        # Input voltage Vx3 at -ve terminal of op-amp=0.3 Volts\n",
    "Vy3 = 0.3#    # Input voltage Vy3 at +ve terminal of op-amp=0.3 Volts\n",
    "\n",
    "A = -Rf/R1#\n",
    "\n",
    "#  Case A\n",
    "\n",
    "Voa = A*(Vx1-Vy1)#\n",
    "print 'The Output Voltage of Case A = %0.2f Volts'%Voa\n",
    "\n",
    "#  Case B\n",
    "\n",
    "Voa = A*(Vx2-Vy2)#\n",
    "print 'The Output Voltage of Case B = %0.2f Volts'%Voa\n",
    "\n",
    "#  Case C\n",
    "\n",
    "Voa = A*(Vx3-Vy3)#\n",
    "print 'The Output Voltage of Case C = %0.2f Volts'%Voa"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_15 Page No.  1102"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output of Differential Amplifier = 5.00 Volts\n"
     ]
    }
   ],
   "source": [
    "# Assume that Rd increases to 7.5 k\u0006 due to an increase in the ambient temperature. Calculate the output of the differential amplifier. Note: Rb is 5 kOhms\u0006.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Vi = 5.#         # Voltage input=5 Volts(dc)\n",
    "Rf = 10.*10**3#   # Feedback resistance=10 kOhms\n",
    "R1 = 1.*10**3#    # Resistance1=1 kOhms\n",
    "Ra = 5.*10**3#    # Resistance A at wein bridge=5 kOhms\n",
    "Rb = 10.*10**3#   # Resistance B at wein bridge=10 kOhms\n",
    "Rc = 5.*10**3#    # Resistance C at wein bridge=5 kOhms\n",
    "Rd = 7.5*10**3#  # Resistance D at wein bridge=7.5 kOhms\n",
    "\n",
    "Vx = Vi*(Ra/Rb)#\n",
    "Vy = Vi*(Rd/(Rd+Rc))#\n",
    "A = -Rf/R1\n",
    "\n",
    "Vo = A*(Vx-Vy)#\n",
    "print 'The Output of Differential Amplifier = %0.2f Volts'%Vo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_16 Page No.  1103"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Cutoff Frequency = 1.59e+03 Hertz\n",
      "i.e 1.591 kHz\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "# Calculate the cutoff frequency, fc.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Rf = 10.*10**3#       # Feedback resistance=10 kOhms\n",
    "Cf = 0.01*10**-6#    # Feedback capacitance=0.01 uFarad\n",
    "\n",
    "fc = 1./(2.*pi*Rf*Cf)#\n",
    "print 'The Cutoff Frequency = %0.2e Hertz'%fc\n",
    "print 'i.e 1.591 kHz'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_17 Page No. 1104"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Closed-Loop Voltage Gain at 0 Hz =-10.00\n",
      "The Closed-Loop Voltage Gain at 1 MHz =-0.02\n"
     ]
    }
   ],
   "source": [
    "from math import pi,sqrt\n",
    "# Calculate the Voltage gain, Acl at (a)0 Hz and (b) 1 MHz\n",
    "\n",
    "# Given data\n",
    "\n",
    "f1 = 1.*10**6#        # Frequency=1 MHertz\n",
    "Rf = 10.*10**3#       # Feedback resistance=10 kOhms\n",
    "R1 = 1.*10**3#        # Resistance1=1 kOhms\n",
    "Cf = 0.01*10**-6#    # Feedback capacitance=0.01 uFarad\n",
    "\n",
    "# At 0 Hz, Xcf = infinity ohms, So, Zf=Rf \n",
    "\n",
    "Acl = -Rf/R1#\n",
    "print 'The Closed-Loop Voltage Gain at 0 Hz =%0.2f'%Acl\n",
    "\n",
    "# At 1 MHz\n",
    "\n",
    "Xcf = 1/(2*pi*f1*Cf)#\n",
    "\n",
    "A = (Rf*Rf)#\n",
    "B = (Xcf*Xcf)#\n",
    "\n",
    "Zf = ((Xcf*Rf)/sqrt(A+B))#\n",
    "\n",
    "Acl1 = -Zf/R1#\n",
    "print 'The Closed-Loop Voltage Gain at 1 MHz =%0.2f'%Acl1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_18 Page No. 1105"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Voltage Gain at 0 Hz = 20.00 dB\n",
      "The Voltage Gain at 1.591 kHz = 16.99 dB\n",
      "approx 17dB\n"
     ]
    }
   ],
   "source": [
    "from math import log10,pi,sqrt\n",
    "# Calculate the dB voltage gain, at (a)0 Hz and (b) 1.591 kHz\n",
    "\n",
    "# Given data\n",
    "\n",
    "f1 = 1.591*10**3#    # Frequency=1.591 kHertz\n",
    "Rf = 10.*10**3#       # Feedback resistance=10 kOhms\n",
    "Ri = 1.*10**3#        # Input resistance=1 kOhms\n",
    "Cf = 0.01*10**-6#    # Feedback capacitance=0.01 uFarad\n",
    "\n",
    "# At 0 Hz, Xcf = infinity ohms, So, Zf=Rf \n",
    "\n",
    "A = Rf/Ri\n",
    "\n",
    "Acl = 20*log10(A)#\n",
    "print 'The Voltage Gain at 0 Hz = %0.2f dB'%Acl\n",
    "\n",
    "# At 1.591 kHz\n",
    "\n",
    "Xcf = 1/(2*pi*f1*Cf)#\n",
    "B = (Rf*Rf)#\n",
    "C = (Xcf*Xcf)#\n",
    "Zf = (Xcf*Rf/sqrt(B+C))#\n",
    "D = Zf/Ri#\n",
    "\n",
    "Acl1 = 20*log10(D)#\n",
    "print 'The Voltage Gain at 1.591 kHz = %0.2f dB'%Acl1\n",
    "print 'approx 17dB'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_19 Page No.  1106"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Cutoff Frequency = 1591.55 Hertz\n",
      "i.e 1.591 kHz\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "# Calculate the cutoff frequency, fc.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Ri = 1.*10**3#       # Input resistance=10 kOhms\n",
    "Ci = 0.1*10**-6#    # Input capacitance=0.01 uFarad\n",
    "\n",
    "fc = 1/(2*pi*Ri*Ci)#\n",
    "print 'The Cutoff Frequency = %0.2f Hertz'%fc\n",
    "print 'i.e 1.591 kHz'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_20 Page No.  1118"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output Current = 5.00e-03 Amps\n",
      "i.e 5 mAmps\n"
     ]
    }
   ],
   "source": [
    "# Vin is  5 V, R is  1 kOhms , and Rl is  100 Ohms . Calculate the output current, Iout.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Vin = 5.#        # Input votage=5 Volts\n",
    "Ri = 1.*10**3#    # Input resistance=1 kOhms\n",
    "Rl = 100.#       # Load resistance=100 Ohms\n",
    "\n",
    "Io = Vin/Ri#\n",
    "print 'The Output Current = %0.2e Amps'%Io\n",
    "print 'i.e 5 mAmps'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_21 Page No.  1120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Output Voltage = 1.50 Volts\n"
     ]
    }
   ],
   "source": [
    "# Iin is 1.5 mA, R is 1 kOhms, and Rl is 10 kOhms. Calculate Vout.\n",
    "\n",
    "# Given data\n",
    "\n",
    "Iin = 1.5*10**-3#    # Input votage=5 Volts\n",
    "Ri = 1.*10**3#        # Input resistance=1 kOhms\n",
    "Rl = 100.#           # Load resistance=100 Ohms\n",
    "\n",
    "Vo = Iin*Ri#\n",
    "print 'The Output Voltage = %0.2f Volts'%Vo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_22 Page No. 1121"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Upper Trigger Point = 0.129 Volts\n",
      "i.e 128.7 mVolts\n",
      "The Lower Trigger Point = -0.129 Volts\n",
      "i.e -128.7 mVolts\n",
      "The Hysterisis Voltage = 0.257 Volts\n",
      "i.e 257.4 mVolts\n"
     ]
    }
   ],
   "source": [
    "# R1 is 1 kOhms and R2 is 100 kOhms . Calculate UTP, LTP, and VH.\n",
    "\n",
    "# Given data\n",
    "\n",
    "R1 = 1.*10**3#        # Resistance1=1 kOhms\n",
    "R2 = 100.*10**3#      # Resistance2=100 kOhms\n",
    "Vcc = 15.#           # Applied votage=15 Volts\n",
    "Vsat = 13.#          # Assume Saturation voltage=13 Volts\n",
    "\n",
    "Beta = R1/(R1+R2)#\n",
    "\n",
    "Utp = Beta*Vsat#\n",
    "print 'The Upper Trigger Point = %0.3f Volts'%Utp\n",
    "print 'i.e 128.7 mVolts'\n",
    "\n",
    "Ltp = -Beta*Vsat#\n",
    "print 'The Lower Trigger Point = %0.3f Volts'%Ltp\n",
    "print 'i.e -128.7 mVolts'\n",
    "\n",
    "Vh = Utp-Ltp#\n",
    "print 'The Hysterisis Voltage = %0.3f Volts'%Vh\n",
    "print 'i.e 257.4 mVolts'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example No. 33_23 Page No.  1124"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Minimum value of required Capacitor = 1.00e-04 Farads\n",
      "i.e 100 uFarad\n"
     ]
    }
   ],
   "source": [
    "# Rl is 1 kOhms  and the frequency of the input voltage equals 100 Hz. Calculate the minimum value of C required.\n",
    "\n",
    "# Given data\n",
    "\n",
    "f = 100.#        # Applied frequency=100 Hertz\n",
    "Rl = 1.*10**3#    # Load resistance=1 kOhms\n",
    "\n",
    "T = 1./f#\n",
    "\n",
    "C = (10*T)/Rl#\n",
    "print 'The Minimum value of required Capacitor = %0.2e Farads'%C\n",
    "print 'i.e 100 uFarad'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}