{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7: Phase Frequency and Time"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_1,pg 496"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find pulse width\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "delt=1*10**-3                  #pulse width\n",
      "#w=2wo\n",
      "#delt at w=2wo\n",
      "\n",
      "#Calculations\n",
      "delT=(delt/2.0)                #changed in pulse width\n",
      "\n",
      "#Result\n",
      "print(\"pulse width:\")\n",
      "print(\"delT = %.1f ms\"%(delT*10**3))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "pulse width:\n",
        "delT = 0.5 ms\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_2,pg 496"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# detector senstivity\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "\n",
      "#senstivity of phase detection\n",
      "#Sphi=(Vo/sin(B))=(Vo/B)=(+/-)0.5Vmax, B is phase displacement\n",
      "Vmax=1.0                           #amplitude of cosine waves\n",
      "\n",
      "#Calculations\n",
      "Sphi=(1.0/2)*Vmax\n",
      "\n",
      "#Result\n",
      "print(\"senstivity of phase detection:\")\n",
      "print(\"Sphi = %.1f V/rad\"%Sphi)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "senstivity of phase detection:\n",
        "Sphi = 0.5 V/rad\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_3,pg 496"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# phase measured\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Vp=1.3                    #pulse height\n",
      "delt=0.31*10**-3          #pulse width\n",
      "T=1*10**-3                #pulse repetion rate\n",
      "\n",
      "#Calculations\n",
      "Vphi=Vp*(delt/T)          #phase deviation\n",
      "phi=2*math.pi*(Vphi/Vp)   #phase\n",
      "\n",
      "#Result\n",
      "print(\"phase measured:\")\n",
      "print(\"phi = %.4f rad\"%phi)\n",
      "#Answer is wrong in the book"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "phase measured:\n",
        "phi = 1.9478 rad\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_4,pg 497"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# measured phase difference\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "delt=0.13*10**-3                   #time delay\n",
      "T=1.3*10**-3                       #time period\n",
      "\n",
      "#Calculations\n",
      "n=(1.0/3.0)*(1+(delt/T))           #order of phase meter\n",
      "delphi=(n-(1.0/3))*1080            #measured phase difference\n",
      "\n",
      "#Result\n",
      "print(\"measured phase difference:\")\n",
      "print(\"delphi = %.f\u00b0\"%delphi)\n",
      "#Answer slightly different than the book"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "measured phase difference:\n",
        "delphi = 36\u00b0\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_5,pg 497"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find phase difference\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "n=8.0                   #8-bit counter\n",
      "N2=64.0                 #output digital count\n",
      "\n",
      "#Calculations\n",
      "theta=math.pi*(N2/(2**n-1))\n",
      "\n",
      "#Result\n",
      "print(\"measured phase difference:\")\n",
      "print(\"theta = %.3f radian\"%theta)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "measured phase difference:\n",
        "theta = 0.788 radian\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_6,pg 497"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# states for stages required\n",
      "import math\n",
      "#Variable declaration\n",
      "#since the no. is more than 9, the two-stage counting is required. the states of the stages are\n",
      "print(\"D  C   B   A   decimal equivalent\")\n",
      "a1=\"0  0   0   1    1\"\n",
      "a5=\"0  1   0   1    5\"\n",
      "\n",
      "#Result\n",
      "print a1 \n",
      "print a5"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "D  C   B   A   decimal equivalent\n",
        "0  0   0   1    1\n",
        "0  1   0   1    5\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_7,pg 498"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find time base division\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "fd=10.0*10**6                     #frequency meter input\n",
      "fc=10.0*10**3                     #counter clock\n",
      "fi=100.0*10**6                    #actual input frequency\n",
      "\n",
      "#Calculations\n",
      "k=fc*(fd/fi)                    #division time base\n",
      "\n",
      "#Result\n",
      "print(\"division time base:\")\n",
      "print(\"k = %.f\"%k)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "division time base:\n",
        "k = 1000\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_8,pg 498"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# frequency of sinusoid\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "V2=0.130                        #output-1\n",
      "V1=0.103                        #output-2\n",
      "Vx=0.4                          #peak amplitude\n",
      "delt=0.1*10**-3                 #time delay\n",
      "\n",
      "#Calculations\n",
      "f1=(1.0/(2*math.pi*delt))*(math.asin(V2/Vx)-math.asin(V1/Vx))\n",
      "\n",
      "#Result\n",
      "print(\"frequency of sinusoid:\")\n",
      "print(\"f1 = %.0f Hz\"%(math.ceil(f1)))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "frequency of sinusoid:\n",
        "f1 = 113 Hz\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_9,pg 498"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# count of counter(refer fig. 7.30(a),(b),(c))\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "#N=(2*fc/fs^2)*fi\n",
      "fs=10*10**2                        #sampler frequency\n",
      "fc=10*10**3                        #counter clock\n",
      "\n",
      "#Calculations\n",
      "M=(fs**2)/(2*fc)                   #multiplication factor\n",
      "fi=113.0                           #input frequency\n",
      "N=(1.0/M)*fi                       #count of counter\n",
      "\n",
      "print(\"count of counter:\")\n",
      "print(\"N = %.2f \"%N)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "count of counter:\n",
        "N = 2.26 \n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7_10,pg 498"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find time between events \n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "n=10.0*10**2                      #scale factor=(1/n)\n",
      "fc=10.0*10**5                     #clock frequency\n",
      "N=10.0                          #count\n",
      "\n",
      "#Calculations\n",
      "Tp=(n/fc)*N                     #time between events\n",
      "\n",
      "#Result\n",
      "print(\"time between events:\")\n",
      "print(\"Tp = %.f ms\"%(Tp*1000))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "time between events:\n",
        "Tp = 10 ms\n"
       ]
      }
     ],
     "prompt_number": 13
    }
   ],
   "metadata": {}
  }
 ]
}