{
 "metadata": {
  "name": "ch_10"
 }, 
 "nbformat": 2, 
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown", 
     "source": [
      "<h1>Chapter 10: Phase locked loop<h1>"
     ]
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example 10.1, Page No: 429<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "fs=20000.0                 #Signal frequency in hertz", 
      "fr=21000.0                 #Free running frquency in hertz", 
      "VCOf=4000.0                #V/F transfer coefficient of VCO in Khz/V", 
      "", 
      "#Calculation:", 
      "Vcd=(fr-fs)/VCOf           #Calculating change in DC control voltage", 
      "", 
      "#Result:", 
      "print('Vcd= %.2f V'%Vcd)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "Vcd= 0.25 V"
       ]
      }
     ], 
     "prompt_number": 1
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 10.2, Page No: 430<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "", 
      "#Part A", 
      "#Variable Ceclaration:", 
      "R1=15.0*10**3                #Resistance in ohm", 
      "R3=15.0*10**3                #Resistance in ohm", 
      "R2=2.2*10**3                 #Resistance in ohm", 
      "C1=0.001*10**-6              #Capacitance in farad", 
      "Vcc=12.0                     #Voltage in volt", 
      "", 
      "#Calculations:", 
      "Vc=Vcc*(R3/(R2+R3))          #Calculating volatage in Vc", 
      "fo1=2*(Vcc-Vc)/(C1*R1*Vcc)   #Calculating frequency", 
      "fo1n=fo1/1000.0              #Calculating frequency", 
      "", 
      "#Results:", 
      "print('\\nVc= %.3f V'%Vc)", 
      "print('\\nFo= %.2f kHz'%fo1n)", 
      "", 
      "#Part B", 
      "#Variable Declaration:", 
      "Vc1=7.0", 
      "Vc2=8.0", 
      "", 
      "#Calculation:", 
      "fo2=2*(Vcc-Vc1)/(C1*R1*Vcc)  #Calculating frequency", 
      "fo2n=fo2/1000.0              #Calculating frequency", 
      "", 
      "fo3=2*(Vcc-Vc2)/(C1*R1*Vcc)  #Calculating frequency", 
      "fo3n=fo3/1000.0              #Calculating frequency", 
      "", 
      "fch=fo2n-fo3n                #Calculating chane in output frequency", 
      " ", 
      "#Results:", 
      "print('\\nFo= %.3f kHz'%fo2n)", 
      "print('\\nFo= %.3f kHz'%fo3n)", 
      "print('\\nChange in output frequency= %.3f kHz'%fch)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Vc= 10.465 V", 
        "", 
        "Fo= 17.05 kHz", 
        "", 
        "Fo= 55.556 kHz", 
        "", 
        "Fo= 44.444 kHz", 
        "", 
        "Change in output frequency= 11.111 kHz"
       ]
      }
     ], 
     "prompt_number": 2
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 10.3, Page No: 438<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "import math", 
      "fo=100.0*10**3                            #Frequency in hertz", 
      "C=2.0*10**-6                              #Capacitance in farad", 
      "Vcc=6.0                                   #Voltage in volt", 
      "", 
      "#Calculations:", 
      "fld=7.8*fo/(2*Vcc)                        #Calculating lock frequency", 
      "fldn=fld/1000.0                           #Calculating lock frequency", 
      "LR=2.0*fldn                               #Calculating lock range", 
      "", 
      "fcd=math.sqrt(fld/(C*2*math.pi*3.6*10**3))#Calculating capture frequency ", 
      "fcdn=fcd/1000.0                           #Calculating capture frequency", 
      "CR=2*fcdn                                 #Calculating capature range ", 
      "", 
      "R1=12.0*10**3", 
      "C1=1.2/(4*R1*fo)                          #Calculating value of capacitance  ", 
      "C1n=C1*10**12                             #Calculating value of capacitance", 
      "", 
      "#Results:", 
      "print('\\nDelta FL= +/- %d kHz'%fldn)", 
      "print('\\nLock Range= %d kHz'%LR)", 
      "print('\\nDelta FC= +/- %.3f kHz'%fcdn)", 
      "print('\\nCapture Range= %.3f kHz'%CR)", 
      "print('\\nC1= %d pF'%C1n)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Delta FL= +/- 65 kHz", 
        "", 
        "Lock Range= 130 kHz", 
        "", 
        "Delta FC= +/- 1.199 kHz", 
        "", 
        "Capture Range= 2.397 kHz", 
        "", 
        "C1= 250 pF"
       ]
      }
     ], 
     "prompt_number": 3
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 10.4, Page No: 438<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "import math", 
      "R1=15000.0                      #Resistance in ohm", 
      "C1=0.01*10**-6                  #Capacitance in farad", 
      "C=1*10**-6                      #Capacitance in farad", 
      "V=12.0                          #Voltage in volt", 
      "", 
      "#Calculations:", 
      "fo=1.2/(4*R1*C1)                #Calculating output frequency ", 
      "fon=fo*10**-3                   #Calculating output frequency", 
      "LR=7.8*fo/V                     #Calculating lock range", 
      "LR1=LR/1000.0                   #Calculating lock range", 
      "fcd=math.sqrt(LR/(C*2*math.pi*3.6*1000)) #Calculating delta for capture frequency", 
      "", 
      "#Results:", 
      "print('\\nCentre frequency of VCO is= %.2f kHz'%fon)", 
      "print('\\nLock Range = +/- %.1f kHz'%LR1)", 
      "print('\\nDelta FC= %.2f Hz'%fcd)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Centre frequency of VCO is= 2.00 kHz", 
        "", 
        "Lock Range = +/- 1.3 kHz", 
        "", 
        "Delta FC= 239.73 Hz"
       ]
      }
     ], 
     "prompt_number": 3
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 10.5, Page No: 439<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "import math", 
      "C1=470.0*10**-12                 #Capacitance value in farad", 
      "C=20.0*10**-6                    #Capacitance value in farad", 
      "V=12.0                           #Voltage in volt", 
      "R1=15000.0                       #Resistance in ohm", 
      "", 
      "#Calculations:", 
      "fo=1.2/(4*R1*C1)                 #Calculating centre frequency of the VCO", 
      "fon=fo/1000.0                    #Calculating centre frequency of the VCO", 
      "", 
      "LR=7.8*fo/V                      #Calculating lock range ", 
      "LR1=LR/1000.0                    #Calculating lock range", 
      "fcd=math.sqrt(LR/(C*2*math.pi*3.6*1000)) #Calculating capture range ", 
      "", 
      "#Results:", 
      "print('\\nCentre frequency of VCO is= %.3f kHz'%fon)", 
      "print('\\nLock Range = +/- %.2f kHz'%LR1)", 
      "print('\\nDelta FC= +/- %.2f Hz'%fcd)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Centre frequency of VCO is= 42.553 kHz", 
        "", 
        "Lock Range = +/- 27.66 kHz", 
        "", 
        "Delta FC= +/- 247.27 Hz"
       ]
      }
     ], 
     "prompt_number": 5
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example No. 10.6, Page No: 439<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "fr=300.0                  #Free running frequency in hertz", 
      "bw=50.0                   #Bandwidth in hertz", 
      "ip=320.0                  #input signal frequency in hertz", 
      "", 
      "#Calculations:", 
      "pdop=fr+ip                #Calculating phase detector output", 
      "difr=ip-fr                #Calculating difference frequency", 
      "", 
      "#Results:", 
      "print('\\nPhase detector output= %d kHz'%pdop)", 
      "print('\\nDifference Frequency= %d kHz'%difr)", 
      "print('\\nAs Bandwidth is greater than difference frequency,')", 
      "print('\\nPLL can acquire lock')"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Phase detector output= 620 kHz", 
        "", 
        "Difference Frequency= 20 kHz", 
        "", 
        "As Bandwidth is greater than difference frequency,", 
        "", 
        "PLL can acquire lock"
       ]
      }
     ], 
     "prompt_number": 4
    }, 
    {
     "cell_type": "markdown", 
     "source": [
      "<h3>Example no. 10.7, Page No: 440<h3>"
     ]
    }, 
    {
     "cell_type": "code", 
     "collapsed": false, 
     "input": [
      "", 
      "#Variable Declaration:", 
      "import math", 
      "C1=0.01*10**-6                       #Capacitance value in farad", 
      "C=0.04*10**-6                        #Capacitance value in farad", 
      "V=12.0                               #Voltage in volt", 
      "R1=10000.0                           #Resistance in ohm", 
      "", 
      "#Calculations:", 
      "fo=120/(4*R1*C1)                     #Calculating centre frequency of the VCO", 
      "fon=fo/1000.0                        #Calculating centre frequency of the VCO", 
      "", 
      "fld=7.8*fo/(V)                       #Calculating Lock range", 
      "fldn=fld/1000.0                      #Calculating Lock range", 
      "       ", 
      "fcd=math.sqrt(fld/(C*2*math.pi*3.6*10**3)) #Calculating capture range", 
      "fcdn=fcd/1000.0                            #Calculating Capture range", 
      "", 
      "#Results:", 
      "print('\\nCentre frequency of VCO is= %.1f kHz'%fon)", 
      "print('\\nLock Range= %d kHz'%fldn)", 
      "print('\\nCapture Range= %.2f kHz'%fcdn)"
     ], 
     "language": "python", 
     "outputs": [
      {
       "output_type": "stream", 
       "stream": "stdout", 
       "text": [
        "", 
        "Centre frequency of VCO is= 300.0 kHz", 
        "", 
        "Lock Range= 195 kHz", 
        "", 
        "Capture Range= 14.68 kHz"
       ]
      }
     ], 
     "prompt_number": 5
    }
   ]
  }
 ]
}