{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8: Oscillators"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.1, Page No.272"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#feed bck factor\n",
      "import math\n",
      "\n",
      "#variable declaration\n",
      "A=50.0                 #unitless\n",
      "\n",
      "#Calculations\n",
      "Beta=1/A               #unitless\n",
      "\n",
      "#Result\n",
      "print(\"Barkhausen criterion for oscillator : Beta*A=1\")\n",
      "print(\"Feedback Factor to make oscillator : %.2f\"%Beta)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Barkhausen criterion for oscillator : Beta*A=1\n",
        "Feedback Factor to make oscillator : 0.02\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.2, Page No.277"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Range of variable capacitor\n",
      "import math\n",
      "#variable declaration\n",
      "L=100                  #in uH\n",
      "L=L*10**-6             #in H\n",
      "f1=500.0               #in kHz\n",
      "f1=f1*10**3            #in Hz\n",
      "f2=1500.0              #in kHz\n",
      "f2=f2*10**3            #in Hz\n",
      "\n",
      "#Calculations\n",
      "#Formula : f=1/(2*%pi*sqrt(L*C))\n",
      "C1=1/(4*math.pi**2*f1**2*L)\n",
      "C2=1/(4*math.pi**2*f2**2*L)\n",
      "\n",
      "#Result\n",
      "print(\"Range of capacitor : %.0f pF to %.0f pF\"%(C2*10**12,math.ceil(C1*10**12)))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Range of capacitor : 113 pF to 1014 pF\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.3, page No.283"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#C2 of colpitt oscilator\n",
      "import math\n",
      "#variable declaration\n",
      "L=100.0             #in mH\n",
      "L=L*10**-3          #in H\n",
      "C1=0.1              #in uF\n",
      "C1=C1*10**-6        #in F\n",
      "f=100.0*10**3       #in Hz\n",
      "f=f*10**3           #in Hz\n",
      "\n",
      "#Calculations\n",
      "#Formula : f=1/(2*pi*sqrt(L*C))\n",
      "C=1.0/(4*math.pi**2*f**2*L)\n",
      "#Formula : C=C1*C2/(C1+C2)\n",
      "C2=C*C1/(C1-C)\n",
      "\n",
      "#Result\n",
      "print(\"C2 in farad : %.3f * 10^15\"%(C2*10**15))\n",
      "#Note : Answer in the book is wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C2 in farad : 0.025 * 10^15\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.4, page No. 288"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Frequency of oscillation\n",
      "import math\n",
      "\n",
      "#variable declaration\n",
      "R=100              #in kOhm\n",
      "R=R*10**3          #in Ohm\n",
      "C=0.01             #in uF\n",
      "C=C*10**-6         #in F\n",
      "\n",
      "#calculations\n",
      "fo=math.sqrt(6)/(2*math.pi*R*C)\n",
      "\n",
      "#result\n",
      "print(\"Frequency of oscillation in Hz : %.3f\"%fo)\n",
      "#Note : Answer in the book is not accurate."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency of oscillation in Hz : 389.848\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.5, Page No.288"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Amplifier voltage gain\n",
      "import math\n",
      "\n",
      "print(\"Put alfa=sqrt(6) to find the gain\");\n",
      "alfa=math.sqrt(6)           #unitless\n",
      "\n",
      "#calculation\n",
      "Beta=1/(1-5*alfa**2);\n",
      "#Barkhausen critera : A*|Beta|>=1\n",
      "Beta=-Beta\n",
      "A=1/Beta\n",
      "\n",
      "#Result\n",
      "print(\"Minimum Gain of Amplifier must be  :%.0f \"%A)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Put alfa=sqrt(6) to find the gain\n",
        "Minimum Gain of Amplifier must be  :29 \n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.6, Page No.292"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Frequency of oscillation and min current gain\n",
      "import math\n",
      "#variable declaration\n",
      "R1=50.0                      #in kohm\n",
      "R1=R1*10**3                  #in ohm\n",
      "C1=0.001                     #in uF\n",
      "C1=C1*10**-6                 #in F\n",
      "R2=1.0                       #in kohm\n",
      "R2=R2*10**3                  #in ohm\n",
      "C2=0.01                      #in uF\n",
      "C2=C2*10**-6                 #in F\n",
      "\n",
      "#calculation\n",
      "\n",
      "#Part (i)\n",
      "#Formula : f=1/(2*%pi*sqrt(C1*C2*R1*R2))\n",
      "f=1/(2*math.pi*math.sqrt(C1*C2*R1*R2))\n",
      "\n",
      "#Part (ii)\n",
      "CurrentGain=1+C2/C1+R1/R2\n",
      "\n",
      "#Result\n",
      "print(\"Frequency of oscillations in kHz :%.3f \"%(f/1000.0))\n",
      "print(\"Current Gain :%.0f \"%CurrentGain)\n",
      "#Note:Answer for Frequency of oscillations is incorrect in the book"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency of oscillations in kHz :7.118 \n",
        "Current Gain :61 \n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.7, Page No.292"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Resistnce to cover frequency range\n",
      "import math\n",
      "#variable declaration\n",
      "fmin=20.0               #in Hz\n",
      "fmax=20.0               #in kHz\n",
      "Cmin=30.0               #in pF\n",
      "Cmax=300.0              #in pF\n",
      "\n",
      "#Calculations\n",
      "#Formula : fo=1/(2*%pi*R*C))\n",
      "R=1/(2*math.pi*fmin*Cmax*10**-12)\n",
      "\n",
      "#To cover frequency range from 200Hz to 2kHz R should be decrease by factor of 10\n",
      "R_dash = R/10.0         \n",
      "#TO cover the frequency range from 2kHz to 20kHz, R should be decrease by factor of 100\n",
      "R_dash_2= R/100.0\n",
      "#Result\n",
      "print(\"Minimum Fequeny correspond to maximum capacitance.\")\n",
      "print(\"Required resistance in Mohm : %.1f\"%(R/10**6))\n",
      "print(\"\\nR_dash in MOhm = %.2f (for frequency range 200Hz to 2kHz)\"%(R_dash/10**6))\n",
      "print(\"\\nR_dash_2 in kOhm = %.0f(for frequency range 2kHz to 20kHz)\"%(R_dash_2*1000//10**6))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Minimum Fequeny correspond to maximum capacitance.\n",
        "Required resistance in Mohm : 26.5\n",
        "\n",
        "R_dash in MOhm = 2.65 (for frequency range 200Hz to 2kHz)\n",
        "\n",
        "R_dash_2 in kOhm = 265(for frequency range 2kHz to 20kHz)\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.8, Page No.296"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Resonant Frequency\n",
      "import math\n",
      "#variable declaration\n",
      "f=500.0                  #in kHz\n",
      "T1=50.0                  #in degree C\n",
      "T2=60.0                  #in degree C\n",
      "TC=-20.0                 #in ppm/degree C\n",
      "\n",
      "#Calculations\n",
      "ChangeInFreq=TC*(f*10**-3)*(T1-T2) #in Hz\n",
      "ResonantFreq=f*1000-ChangeInFreq   #in Hz\n",
      "\n",
      "#Result\n",
      "print(\"Resonant frequency in kHz : %.1f\"%(ResonantFreq/1000))\n",
      "#Note : answer in the book is wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Resonant frequency in kHz : 499.9\n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.9, Page No.296"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Resonant Frequency\n",
      "import math\n",
      "#Variable declarations\n",
      "f=450.0               #in kHz\n",
      "T1=30.0               #in degree C\n",
      "T2=50.0               #in degree C\n",
      "TC=-10.0              #in ppm/degree C\n",
      "\n",
      "#Calculations\n",
      "PercentChange=-TC*100/10**6                               #in %\n",
      "TotalChangeInFreq=(PercentChange/100)*(f*10**3)*(T2-T1)   #in Hz\n",
      "ResonantFreq=f*1000-TotalChangeInFreq                     #in Hz\n",
      "\n",
      "#Result\n",
      "print(\"Resonant frequency in kHz :%.3f \"%(ResonantFreq/1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Resonant frequency in kHz :449.910 \n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "example 8.10, Page No.297"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Parallel and series resonant frequencies\n",
      "import math\n",
      "#Variable declaration\n",
      "L=0.5                  #in H\n",
      "C=0.05                 #in pF\n",
      "R=1                    #in kohm\n",
      "Cm=1                   #in pF\n",
      "\n",
      "#Calculations\n",
      "fs=1/(2*math.pi*math.sqrt(L*C*10**-12))\n",
      "fp=1/(2*math.pi*math.sqrt((L*C*10**-12*Cm*10**-12)/(C*10**-12+Cm*10**-12)))\n",
      "\n",
      "#Result\n",
      "print(\"Series resonant frequency in MHz :%.3f\"%(fs/10**6))\n",
      "print(\"Parallel resonant frequency in MHz :%.3f\"%(fp/10**6))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Series resonant frequency in MHz :1.007\n",
        "Parallel resonant frequency in MHz :1.031\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Miscellaneous example 8.1, Page No.302"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Value of L\n",
      "import math\n",
      "#Variable declaration\n",
      "L2=0.4              #in mH\n",
      "C=0.004             #in \u00b5F\n",
      "f=120               #in KHz\n",
      "L1=1/(4*math.pi**2*(f*10**3)**2*C*10**-6)-L2*10**-3\n",
      "\n",
      "#Result\n",
      "print(\"Value of L1(in mH) :%.2f\"%(L1*10**3))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Value of L1(in mH) :0.04\n"
       ]
      }
     ],
     "prompt_number": 40
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Miscellaneous example 8.2, page No.303"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Value of C and hfe\n",
      "import math\n",
      "#variable declaration\n",
      "fo=10.0                 #in KHz\n",
      "R1=25.0                 #in kohm\n",
      "R2=60.0                 #in kohm\n",
      "Rc=40.0                 #in kohm\n",
      "R=7.1                   #in kohm\n",
      "hie=1.8                 #in kohm\n",
      "\n",
      "#Calculations\n",
      "C=1/(2*math.pi*fo*10**3*R*10**3*math.sqrt(6+4*Rc/R))\n",
      "hfe=23+29*R/Rc+4*Rc/R\n",
      "\n",
      "#Result\n",
      "print(\"Value of Capacitor(in nF) %.3f\"%(C*10**9))\n",
      "print(\"Value of hfe is \u2265 %.3f\"%hfe)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Value of Capacitor(in nF) 0.420\n",
        "Value of hfe is \u2265 50.683\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Miscellaneous example 8.3, Page No.303"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Value of Capacitor\n",
      "import math\n",
      "#variable declaration\n",
      "R=100.0               #in kohm\n",
      "fo=10.0               #in KHz\n",
      "\n",
      "#Calculations\n",
      "C=1/(2*math.pi*fo*10**3*R*10**3)\n",
      "\n",
      "#Result\n",
      "print(\"Value of Capacitor(in pF) :%.0f\"%(C*10**12))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Value of Capacitor(in pF) :159\n"
       ]
      }
     ],
     "prompt_number": 47
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Miscellaneous example 8.4, page No.304"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Various parameter of colpitt oscillator\n",
      "import math\n",
      "\n",
      "#variable declaration\n",
      "L=40.0                #in mH\n",
      "C1=100.0              #in pF\n",
      "C2=500.0              #in pF\n",
      "Vout=10.0             #in volt\n",
      "\n",
      "#Calculations\n",
      "fo=1/(2*math.pi*math.sqrt(L*10**-3*C1*10**-12*C2*10**-12/(C1*10**-12+C2*10**-12)))\n",
      "print(\"Frequency of oscillation (in KHz) :%.1f\"%(fo*10**-3))\n",
      "Vf=Vout*C1/C2\n",
      "Gain=C2/C1\n",
      "Gain=10                #given\n",
      "C1=C2/Gain             #in pF\n",
      "fo=1/(2*math.pi*math.sqrt(L*10**-3*C1*10**-12*C2*10**-12/(C1*10**-12+C2*10**-12)))\n",
      "\n",
      "#Result\n",
      "\n",
      "print(\"Feedback voltage in volt :%.0f\"%Vf)\n",
      "print(\"Minimum Gain is %.0f\"%Gain)\n",
      "print(\"For a gain of 10 C1 in pF is :%.0f\"%C1)\n",
      "print(\"New frequency of oscillation (in KHz) :%.3f\"%(fo*10**-3))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Frequency of oscillation (in KHz) :87.2\n",
        "Feedback voltage in volt :2\n",
        "Minimum Gain is 10\n",
        "For a gain of 10 C1 in pF is :50\n",
        "New frequency of oscillation (in KHz) :118.032\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Miscellaneous example 8.5, Page No.305"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Resonant frequencies and Q factor\n",
      "import math\n",
      "#Variable declaration\n",
      "L=0.5                   #in H\n",
      "Cs=0.06                 #in pF\n",
      "Cp=1.0                  #in pF\n",
      "R=5.0                   #in Kohm\n",
      "\n",
      "#calculations\n",
      "fs=1/(2*math.pi*math.sqrt(L*Cs*10**-12))\n",
      "Q=2*math.pi*fs*L/(R*10**3)\n",
      "print(\"Seies resonance frequency(in KHz): %.1f\"%(fs/10**3))\n",
      "print(\"Q-factor f the crystal at fs is %.0f\"%Q)\n",
      "fp=(1/(2*math.pi))*math.sqrt((Cs*10**-12+Cp*10**-12)/(L*Cs*10**-12*Cp*10**-12))\n",
      "Q=2*math.pi*fp*L/(R*10**3)\n",
      "print(\"\\nSeies resonance frequency(in KHz) : %.0f\"%(fp/10**3))\n",
      "print(\"Q-factor f the crystal at fs is %.0f\"%Q)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Seies resonance frequency(in KHz): 918.9\n",
        "Q-factor f the crystal at fs is 577\n",
        "\n",
        "Seies resonance frequency(in KHz) : 946\n",
        "Q-factor f the crystal at fs is 594\n"
       ]
      }
     ],
     "prompt_number": 61
    }
   ],
   "metadata": {}
  }
 ]
}