{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8 : Non-linear Applications of Op-amp"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.1, Page No. 332"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Threshold voltages(refer fig. 8.20)\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Vcc = 15             # positive saturation voltage\n",
      "Vee = -15            # Negative saturation voltage\n",
      "R1 = 120.0           # resistance R1\n",
      "R2 = 51*10**3        # resistance R2\n",
      "vin = 1              # input voltage\n",
      "\n",
      "#Calculations\n",
      "Vut = Vcc*R1/(R1+R2)\n",
      "Vult = Vee*R1/(R1+R2)\n",
      "\n",
      "#Result\n",
      "print(\"Vut  = %.1f mV\\nVult = %.1f mV\"%(Vut*1000,Vult*1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Vut  = 35.2 mV\n",
        "Vult = -35.2 mV\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.2, Page No.333"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Values of R1 and R2\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "Vcc = 12.0                      # positive saturation voltage\n",
      "Vee = -12.0                     # negative saturation voltage\n",
      "Vh = 6.0                        # hysteresis width\n",
      "\n",
      "\n",
      "#Calculations\n",
      "R1 = 10*10**3\n",
      "R2 = (1-(Vh/(Vcc-Vee)))*R1/(Vh/(Vcc-Vee))\n",
      "\n",
      "#Result\n",
      "print(\"R1 = %.0f k-ohm\\nR2 = %.0f k-ohm\"%(R1/1000,R2/1000))\n",
      "    "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R1 = 10 k-ohm\n",
        "R2 = 30 k-ohm\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.3, Page No. 333"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Schmitt trigger\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Vh = 2.0              # hysteresis width\n",
      "Vlt = -1.5            # lower threshold\n",
      "Vpp = 5.0             # sine wave amplitude\n",
      "f = 1000.0            # frequency\n",
      "\n",
      "# Calculations\n",
      "Vut = Vh - abs(Vlt)\n",
      "Vm = Vpp/2\n",
      "theta = math.asin(-Vlt/Vm)\n",
      "theta = theta*180/math.pi\n",
      "T = 1/f\n",
      "T1 = T*(180.0+theta)/360.0\n",
      "T2 = T-T1\n",
      "\n",
      "#Result\n",
      "print(\"Time duration for negative portion , T1 = %.3f ms\\nTime duration for positive portion , T2 = %.3f ms\"%(T1*1000,T2*1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Time duration for negative portion , T1 = 0.602 ms\n",
        "Time duration for positive portion , T2 = 0.398 ms\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.4, Page No. 334"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Schmitt Trigger\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Vh = 10.0                # ligher threshold\n",
      "Vl = -10.0               # lower threshold\n",
      "Imax = 100*10**-6        # maximum current through R1 and R2\n",
      "Vhv = 0.1                # hysteresis width\n",
      "\n",
      "\n",
      "#Calculations\n",
      "R2 = 1000.0              # assumed\n",
      "R1= R2*(1-(Vhv/(2*Vh)))/(Vhv/(2*Vh))\n",
      "R = R1*R2/(R1+R2)\n",
      "\n",
      "#Result\n",
      "print(\"R1 = %.0f k-ohm\\nR2 = %.0f k-ohm\\nR1||R2 = %.0f ohm\"%(R1/1000,R2/1000,R))\n",
      "# R1||R2 value is in ohm and not in k-ohm"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "R1 = 199 k-ohm\n",
        "R2 = 1 k-ohm\n",
        "R1||R2 = 995 ohm\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.5, Page No. 334"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " print(\"Theoretical example\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical example\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.6, Page No.336"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Threshold voltages and hysteresis voltage (refer fig. 8.26)\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "VsatP = 12.0              # Positive saturation voltage\n",
      "VsatN = -12.0             # Negative saturation voltage\n",
      "R1 = 1000.0               # Resistor R1 \n",
      "R2 = 3*10**3              # Resistor R2\n",
      "\n",
      "#Result\n",
      "Vlt = -VsatP*R1/R2\n",
      "Vut = -VsatN*R1/R2\n",
      "Vh = (R1/R2)*abs(VsatP-VsatN)\n",
      "\n",
      "#Result\n",
      "print(\"Vlt = %.0f V\\nVut =  %.0f V\\nVh  =  %.0f V\"%(Vlt,Vut,Vh))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Vlt = -4 V\n",
        "Vut =  4 V\n",
        "Vh  =  8 V\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.7, Page No.336"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Schmitt's trigger (refer fig. 8.27)\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Vcc = 12.5             # positive supply voltage\n",
      "Vee = -12.5            # negative supply voltage\n",
      "R1 = 80.0*10**3        # Resistor R1\n",
      "R2 = 20.0*10**3        # Resistor R2\n",
      "\n",
      "#Calcualtions\n",
      "Vut = R2*Vcc/(R1+R2)\n",
      "Vlt = R2*Vee/(R1+R2) \n",
      "Vhv =  R2*2*Vcc/(R1+R2)\n",
      "\n",
      "#Result\n",
      "print(\"Vlt = %.1f V\\nVut =  %.1f V\\nVh  =  %.1f V\"%(Vlt,Vut,Vhv))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Vlt = -2.5 V\n",
        "Vut =  2.5 V\n",
        "Vh  =  5.0 V\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.8, Page No.350"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(\"Theoretical example\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical example\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.9, Page No.360"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Sample and hold circuit\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "del_Vin = 5.0                 # changes in input volage\n",
      "FRR = 80.0                    # feedthrough rejection ratio\n",
      "\n",
      "#Calculations\n",
      "math.sqrt(5)\n",
      "del_Vout = del_Vin/math.pow(10,FRR/20)\n",
      "\n",
      "#Result\n",
      "print(\"Change in output = %.4f V = %.1f mV\"%(del_Vout,del_Vout*1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in output = 0.0005 V = 0.5 mV\n"
       ]
      }
     ],
     "prompt_number": 41
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.10, Page No. 365"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Threshold voltages and frequency of oscillation ( refer fig.8.72)\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "R1 = 86*10**3                 # Resistor R1\n",
      "R2 = 100*10**3                # Resistor R2\n",
      "Vcc = 15.0                    # positive saturation voltage\n",
      "Vee = -15.0                   # negative saturation voltage\n",
      "Rf = 100*10**3                # feedback resistance\n",
      "C = 0.1*10**-6                # capacitance\n",
      "\n",
      "#Calculations\n",
      "Vut = R1*Vcc/(R1+R2)\n",
      "Vlt = R1*Vee/(R1+R2) \n",
      "fo = 1/(2*Rf*C*math.log((Vcc-Vlt)/(Vcc-Vut)))\n",
      "\n",
      "#Result\n",
      "print(\"(i)  Vut =  %.2f V\\n(ii) Vlt = %.2f \\n(iii)fo  =  %.0f Hz\"%(Vut,Vlt,fo))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i)  Vut =  6.94 V\n",
        "(ii) Vlt = -6.94 \n",
        "(iii)fo  =  50 Hz\n"
       ]
      }
     ],
     "prompt_number": 36
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.11, Page No. 365"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(\"Theoretical example\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical example\n"
       ]
      }
     ],
     "prompt_number": 37
    }
   ],
   "metadata": {}
  }
 ]
}