{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8 : Q factor Power and Power Factor"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_1,pg 234"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Q factor of coil\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "fr= 400.0*10**3                   #resonance frequency\n",
      "C = 400.0*10**-12                 #tuned capacitance\n",
      "R = 10.0                          #resistance of coil\n",
      "n = 40.0                          #Cp=nC\n",
      "\n",
      "#Calculations\n",
      "Cp=n*(100.0/400.0)*10**-12      \n",
      "L=(1.0/(4*(math.pi**2)*(fr**2)*(C+Cp)))\n",
      "Q=2*math.pi*fr*(L/R)\n",
      "\n",
      "#Result\n",
      "print(\"Inductance:\\nL = %f mH\"%(L*1000))\n",
      "print(\"Observed Q-factor:\")\n",
      "print(\"Q = %.2f \"%Q)\n",
      "# Aanswer do not match with the book"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Inductance:\n",
        "L = 0.386133 mH\n",
        "Observed Q-factor:\n",
        "Q = 97.05 \n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_2,pg 240"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# truncation error\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "fs=50*10**3                      #sampling rate\n",
      "delt=2.0                         #summation interval\n",
      "f=50.0                           #signal frequency\n",
      "\n",
      "#Calculations\n",
      "n=(fs/delt)                      #value of samples for 2s\n",
      "maxer1=100.0/(2*n)               #max error for synchronous case\n",
      "maxer2=(100.0/(2*fs*delt*math.sin((2*math.pi*f)/fs)))\n",
      "\n",
      "#Result\n",
      "print(\"max error for synchronous case:\")\n",
      "print(\"maxer1 = %.3f%% \\n\"%maxer1)\n",
      "print(\"max error for asynchronous case:\")\n",
      "print(\"maxer2 = %.2f%% \"%maxer2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "max error for synchronous case:\n",
        "maxer1 = 0.002% \n",
        "\n",
        "max error for asynchronous case:\n",
        "maxer2 = 0.08% \n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_3,pg 258"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find ratio errror and phase angle\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "#assume no iron loss and magnetizing current=1% of 10A, i.e 0.01A\n",
      "Xs=1.884                   #reactance of secondary\n",
      "Rs=0.5                     #resistance of secondary\n",
      "Xm=2.0                     #reactance of meter\n",
      "Rm=0.4                     #reactance of meter\n",
      "Im=0.01                    #magnetizing current\n",
      "n2=10\n",
      "n1=1\n",
      "\n",
      "#Calculations\n",
      "B=math.atan((Xs+Xm)/(Rs+Rm))\n",
      "#nominal ratio (n2/n1)=10/1\n",
      "R=n2+((Im*math.sin(B))/n1) #actual impedance\n",
      "R1=0.0097                  #practical impedance\n",
      "perer=(R1/R)*100           #percentage error\n",
      "theta=((Im*math.cos(B))/n2)\n",
      "\n",
      "#Result\n",
      "print(\"percentage error = %.3f%% \\n\"%perer)\n",
      "print(\"phase angle:\")\n",
      "print(\"theta = %.5f rad\"%(math.floor(theta*10**5)/10**5))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "percentage error = 0.097% \n",
        "\n",
        "phase angle:\n",
        "theta = 0.00022 rad\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_4,pg 499"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# inductor Q factor and resistance\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Vc=100.0                   #voltage across capacitor\n",
      "Vi=12.0                    #input voltage\n",
      "f=100.0                    #frequency of operation\n",
      "Vl=100.0                   #Vc=Vl at resonance\n",
      "Ir=5.0                     #current at resonance\n",
      "\n",
      "#Calculations\n",
      "Q=(Vc/Vi)                  #Q-factor\n",
      "Xl=(Vl/Ir)                 #inductive reactance\n",
      "L=(Xl/(2*math.pi*f))       #inductance\n",
      "Rl=(Xl/Q)                  #resistance\n",
      "\n",
      "#Result\n",
      "print(\"Inductance of coil:\")\n",
      "print(\"L = %.1f mH\\n\"%(L*1000))\n",
      "print(\"Q-factor:\")\n",
      "print(\"Q = %.2f\\n\"%Q)\n",
      "print(\"Resistance of coil:\")\n",
      "print(\"Rl = %.1f ohm\"%Rl)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Inductance of coil:\n",
        "L = 31.8 mH\n",
        "\n",
        "Q-factor:\n",
        "Q = 8.33\n",
        "\n",
        "Resistance of coil:\n",
        "Rl = 2.4 ohm\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_5,pg 499"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# actual Q factor and resistance\n",
      "\n",
      "import math\n",
      "# Variable declaration\n",
      "#when switch is open\n",
      "C1=0.011*10**-6                           #capacitance-1\n",
      "Q1=10.0                                   #Q-factor-1\n",
      "#when switch is closed\n",
      "C2=0.022*10**-6                           #capacitance-2\n",
      "Q2=100.0                                  #Q-factor-2\n",
      "\n",
      "#Calculations\n",
      "Qac=((Q1*Q2)/(Q1-Q2))*((C1-C2)/C1)        #actual Q-factor\n",
      "Rp=((Q1*Q2)/(Q2-Q1))*(1/(2*math.pi*C2))       #parallel resistance\n",
      "\n",
      "#Result\n",
      "print(\"actual Q-factor:\")\n",
      "print(\"Qac = %.2f \\n\"%Qac)\n",
      "print(\"parallel resistance:\")\n",
      "print(\"Rp = %.f M-ohm\"%(Rp/10**6))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "actual Q-factor:\n",
        "Qac = 11.11 \n",
        "\n",
        "parallel resistance:\n",
        "Rp = 80 M-ohm\n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_6,pg 499"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find Q factor\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Cr=0.01*10**-6               #capacitance at resonance\n",
      "Cu=0.014*10**-6              #capacitance at upper half\n",
      "Cl=0.008*10**-6              #capacitance at lower half\n",
      "\n",
      "#Calculations\n",
      "Qac=((2*Cr)/(Cu-Cl))         #actual Q-factor\n",
      "\n",
      "#Result\n",
      "print(\"actual Q-factor:\")\n",
      "print(\"Qac = %.2f \"%Qac)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "actual Q-factor:\n",
        "Qac = 3.33 \n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_7,pg 499"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find lag\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "V=10.0                    #v=10sin6280t\n",
      "I=1.0                     #current peak\n",
      "P=3.1                     #active power\n",
      "\n",
      "#Calculations\n",
      "phi=math.acos((P*2)/V)    #phase in radian\n",
      "w=6280.0                  #v=10sin6280t\n",
      "lag=(phi/w)               #lag\n",
      "\n",
      "#Result\n",
      "print(\"lag = %.2f ms\"%(lag*10**3))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "lag = 0.14 ms\n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_8,pg 500"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find truncation error\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "V=4.0                   #peak voltage\n",
      "I=0.4                   #peak current\n",
      "f=1*10**3               #operating frequency\n",
      "fs=40*10**3             #sampling rate\n",
      "delt=2.2                #time interval\n",
      "\n",
      "#Calculations\n",
      "phi=((2*math.pi*f)/fs)  #phase \n",
      "Et=(V*I*phi)/(4*math.pi*f*delt*math.sin(phi))\n",
      "\n",
      "#Result\n",
      "print(\"truncation error:\")\n",
      "print(\"Et = %.1f * 10^-6 \"%(Et*10**6))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "truncation error:\n",
        "Et = 58.1 * 10^-6 \n"
       ]
      }
     ],
     "prompt_number": 36
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_9,pg 500"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find frequency of PF meter\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "ar=1.0                     #gain of rectifier\n",
      "nc=40.0                    #turns ratio (1:40)\n",
      "Vm=4.0                     #peak load voltage\n",
      "PF=0.85                    #power factor\n",
      "\n",
      "#Calculations\n",
      "f=(1/math.pi)*ar*Vm*nc*PF #frequency\n",
      "\n",
      "#Result\n",
      "print(\"frequency of digital power meter:\")\n",
      "print(\"f = %.1f Hz\"%f)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "frequency of digital power meter:\n",
        "f = 43.3 Hz\n"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_10,pg 500"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# calculate ratio error and phase angle\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "Rp=94.0                     #primary resistance\n",
      "Xp=64.3                     #primary reactance\n",
      "Rs=0.85*10**2               #secondary resistance\n",
      "Im=31*10**-3                #magnetizing current\n",
      "PF=0.4                      #power factor\n",
      "n=10.0                      #PT ratio\n",
      "Is=1.0                      #load current\n",
      "Vs=110.0                    #n=(Vp/Vs)\n",
      "\n",
      "#Calculations\n",
      "B=math.acos(PF)\n",
      "beta = math.floor(math.sin(B)*10)/10\n",
      "R=Rp+Rs                     #total resistance\n",
      "nerr=n+((((Is/n)*((R*PF)+(Xp*beta)))+Im*Xp)/Vs)\n",
      "theta=((PF*(Xp/n))-(beta*(R/n))-(Im*Rp))/(Vs*n)\n",
      "\n",
      "#Result\n",
      "print(\"ratio error:\")\n",
      "print(\"nerr = %.3f\\n\"%nerr)\n",
      "print(\"phase angle:\")\n",
      "print(\"theta = %.3f\"%theta)\n",
      "#Answer for theta do not match with the book"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "ratio error:\n",
        "nerr = 10.136\n",
        "\n",
        "phase angle:\n",
        "theta = -0.015\n"
       ]
      }
     ],
     "prompt_number": 52
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example8_11,pg 500"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# calculate ratio error and phase angle\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "n=20.0                          #(Vs/Is)\n",
      "Is=5.0                          #n=(Vs/Is)\n",
      "Vs=100.0                        #n=(Vs/Is)\n",
      "N=0.25                          #resistance to reactance ratio\n",
      "Bur=15.0                        #burden of CT=15VA (rating)\n",
      "IL=0.13                         #iron loss\n",
      "Im=1.3                          #magnetizing current\n",
      "\n",
      "#Calculations\n",
      "V=(Bur/Is)                      #voltage rating\n",
      "B=math.atan(N)                  #cos(B)-> power factor\n",
      "#B=B*(180/math.pi)               #conversion into degree\n",
      "I=(Bur/Vs)                      #current rating\n",
      "I1=(IL/I)\n",
      "Rac=0.23                        #actual value\n",
      "R=n+((I1*math.cos(B)+Im*math.sin(B))/Is)\n",
      "theta=((Im*math.cos(B)-I1*math.sin(B))/Vs)\n",
      "nerr=-(Rac/R)*100               #ratio error\n",
      "\n",
      "# Result\n",
      "print(\"ratio error:\")\n",
      "print(\"nerr = %.3f%%\\n \"%nerr)\n",
      "print(\"phase angle \\n\")\n",
      "print(\"theta = %.4f\u00b0 \"%theta)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "ratio error:\n",
        "nerr = -1.137%\n",
        " \n",
        "phase angle \n",
        "\n",
        "theta = 0.0105\u00b0 \n"
       ]
      }
     ],
     "prompt_number": 56
    }
   ],
   "metadata": {}
  }
 ]
}