{
 "metadata": {
  "name": "",
  "signature": "sha256:6bef06309f2dc6c34cb3f6505e0a7b5381887b6e742832b02487100464da77a5"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter5, Inverters"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.3.1: page 5-8"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import pi, sqrt\n",
      "#Maximum frequency\n",
      "#given data :\n",
      "T_off=100 # in micro-sec\n",
      "L=40 # in micro-H\n",
      "C=5 # in micro-farad\n",
      "R=4 #in ohm\n",
      "Tr=((2*pi)/sqrt((1/(C*10**-6*L*10**-6))-(R**2/(4*(L*10**-6)**2))))*10**6 \n",
      "f=(1/(Tr+T_off))*10**3 \n",
      "print \"maximum frequency, f = %0.3f kHz \" %f"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "maximum frequency, f = 4.431 kHz \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.12.1: page 5-37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from numpy import arange, pi, sqrt, nditer, array\n",
      "#rms output voltage,output power, average and peak currents,peak reverse blocking voltage,\n",
      "#THD,DF,harmonic factor and distortion factor of the lowest order harmonic\n",
      "print \"part (a)\"\n",
      "v=24 #in volts\n",
      "V=v #\n",
      "r=3 #in ohms\n",
      "v1rms=(2*v)/(sqrt(2)*pi) #in volts\n",
      "print \"rms output voltage at fundamental frequency = %0.2f V\" %v1rms\n",
      "print \"part (b)\"\n",
      "po=((v/2)**2)/r #in watts\n",
      "print \"output power = %0.2f Watt\" %po\n",
      "print \"part (c)\"\n",
      "itav=(v/(4*r)) #in amperes\n",
      "itp=((v/2)/r) #in amperes\n",
      "print \"average transistor current = %0.2f A\" %itav\n",
      "print \"transistor peak current = %0.2f A\" %itp\n",
      "print \"part (d)\"\n",
      "vbr=2*(v/2) #in volts\n",
      "print \"peak reverse blocking voltage = %0.2f V\" %vbr\n",
      "print \"part (e)\"\n",
      "vo=v/2 #\n",
      "THD1=((vo)**2-(v1rms)**2)**(1/2) #in volts\n",
      "THD=THD1/v1rms #\n",
      "print \"Total Hramonic distortion = %0.2f %%\" %(THD*100)\n",
      "print \"part (f)\"\n",
      "n=array([0,0,(1/3),0,(1/5),0,(1/7),0,(1/9),0,(1/11),0,(1/13)]) #\n",
      "i = arange(3,15,2)\n",
      "def fun1(n):\n",
      "    it = nditer([n, None])\n",
      "    for x,y in it:\n",
      "        y[...] = 2*V*x/pi/sqrt(2)\n",
      "    return it.operands[1]\n",
      "v = fun1(n)\n",
      "x=sqrt((((v[2])/(3**2))**2)+(((v[4])/(5**2))**2)+(((v[6])/(7**2))**2)+(((v[8])/(9**2))**2)+(((v[10])/(11**2))**2)+(((v[12])/(13**2))**2)) #\n",
      "DF=x/v1rms #\n",
      "print \"distortion factor = %0.2f %%\" %(DF*100)\n",
      "#distortion factor is calculated wrong in the textbook\n",
      "print \"part (g)\"\n",
      "HF3=v[2]/v1rms #\n",
      "DF3=((v[2]/(3**2)))/v1rms\n",
      "print \"HF for the third harmonic = %0.2f %%\" %(HF3*100)\n",
      "print \"DF the third harmonic = %0.2f %%\" %(DF3*100)\n",
      "# answer for part f is wrong in the textbook."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "part (a)\n",
        "rms output voltage at fundamental frequency = 10.80 V\n",
        "part (b)\n",
        "output power = 48.00 Watt\n",
        "part (c)\n",
        "average transistor current = 2.00 A\n",
        "transistor peak current = 4.00 A\n",
        "part (d)\n",
        "peak reverse blocking voltage = 24.00 V\n",
        "part (e)\n",
        "Total Hramonic distortion = 48.34 %\n",
        "part (f)\n",
        "distortion factor = 3.80 %\n",
        "part (g)\n",
        "HF for the third harmonic = 33.33 %\n",
        "DF the third harmonic = 3.70 %\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.12.2: page 5-39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#rms output voltage,output power,average and peak currents,peak reverse blocking voltage,\n",
      "#THD,DF,harmonic factor and distortion factor of the lowest order harmonic\n",
      "v=48 #in volts\n",
      "V=v #\n",
      "r=2.4 #in ohms\n",
      "v1rms=(4*v)/(sqrt(2)*pi) #in volts\n",
      "print \"part (a)\"\n",
      "print \"rms output voltage at fundamental frequency = %0.2f V\" %v1rms\n",
      "print \"part (b)\"\n",
      "po=((v)**2)/r #in watts\n",
      "print \"output power = %0.2f Watt\" %po\n",
      "print \"part (c)\"\n",
      "itav=(v/(r)) #in amperes\n",
      "itp=((v/2)/r) #in amperes\n",
      "print \"average transistor current = %0.2f A\" %itp\n",
      "print \"transistor peak current = %0.2f A\" %itav\n",
      "print \"part (d)\"\n",
      "vbr=2*(v/2) #in volts\n",
      "print \"peak reverse bloacking voltage = %0.2f V\" %vbr\n",
      "print \"part (e)\"\n",
      "vo=v #\n",
      "THD1=((vo)**2-(v1rms)**2)**(1/2) #in volts\n",
      "THD=THD1/v1rms #\n",
      "print \"Total Hramonic distortion = %0.2f %%\" %(THD*100)\n",
      "print \"part (f)\"\n",
      "n=array([0, 0, (1/3), 0, (1/5), 0, (1/7), 0, (1/9), 0, (1/11), 0, (1/13)]) #\n",
      "i = arange(3,15,2)\n",
      "def fun1(n):\n",
      "    it = nditer([n, None])\n",
      "    for x,y in it:\n",
      "        y[...] = 2*V*x/pi/sqrt(2)\n",
      "    return it.operands[1]\n",
      "v = fun1(n)\n",
      "x=sqrt((((v[2])/(3**2))**2)+(((v[4]/(5**2))**2)+(((v[6]/(7**2))**2)+(((v[8]/(9**2))**2)+\n",
      "(((v[10]/(11**2))**2)+(((v[12])/(13**2))**2)))))) #\n",
      "vorms=0.9\n",
      "DF=x/vorms #\n",
      "print \"distor factor = %0.2f %%\" %(DF*100)\n",
      "#distortion factor is calculated  wrong in the textbook\n",
      "print \"part (g)\"\n",
      "HF3=2*v[2]/v1rms #\n",
      "DF3=2*((v[2]/(3**2)))/v1rms\n",
      "print \"HF for the third harmonic = %0.2f %%\" %(HF3*100)\n",
      "print \"DF the third harmonic = %0.2f %%\" %(DF3*100)\n",
      "# Answer not accurate for some part."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "part (a)\n",
        "rms output voltage at fundamental frequency = 43.22 V\n",
        "part (b)\n",
        "output power = 960.00 Watt\n",
        "part (c)\n",
        "average transistor current = 10.00 A\n",
        "transistor peak current = 20.00 A\n",
        "part (d)\n",
        "peak reverse bloacking voltage = 48.00 V\n",
        "part (e)\n",
        "Total Hramonic distortion = 48.34 %\n",
        "part (f)\n",
        "distor factor = 91.32 %\n",
        "part (g)\n",
        "HF for the third harmonic = 33.33 %\n",
        "DF the third harmonic = 3.70 %\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.12.3: page 5-40"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#amplitude of the first three lower order harmonis\n",
      "#given data :\n",
      "v=200 #in volts\n",
      "n=array([(1/3), (1/5), (1/7)]) #\n",
      "def fun1(n):\n",
      "    it = nditer([n, None])\n",
      "    for x,y in it:\n",
      "        y[...] = 4*v*x/pi/sqrt(2)\n",
      "    return it.operands[1]\n",
      "vn = fun1(n)\n",
      "print \"Rms value of third harmonic component of output voltage = %0.2f V\" %round(vn[0])\n",
      "print \"Rms value of fifth harmonic component of output voltage = %0.2f V\" %round(vn[1])\n",
      "print \"Rms value of seventh harmonic component of output voltage = %0.2f V\" %(vn[2])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Rms value of third harmonic component of output voltage = 60.00 V\n",
        "Rms value of fifth harmonic component of output voltage = 36.00 V\n",
        "Rms value of seventh harmonic component of output voltage = 25.72 V\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.12.4: page 5-42"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#amplitude of the first three lower order harmonis\n",
      "#given data :\n",
      "v=200 #in volts\n",
      "n=array([(1/3), (1/5), (1/7)]) #\n",
      "vo1rms=(2*v)/(sqrt(2)*pi) #in volts\n",
      "def fun1(n):\n",
      "    it = nditer([n, None])\n",
      "    for x,y in it:\n",
      "        y[...] = 2*v*x/pi/sqrt(2)\n",
      "    return it.operands[1]\n",
      "vn = fun1(n)\n",
      "print \"Vo1rms for half bridge circuit = %0.2f V\" %round(vo1rms)\n",
      "print \"Rms value of third harmonic component for half bridge circuit = %0.2f V\" %round(vn[0])\n",
      "print \"Rms value of fifth harmonic component for half bridge circuit = %0.2f V\" %round(vn[1])\n",
      "print \"Rms value of seventh harmonic component for half bridge circuit = %0.2f V\" %vn[2]\n",
      "print \"for bridge inverter\"\n",
      "vo1rms1=(4*v)/(sqrt(2)*pi) #in volts\n",
      "def fun2(n):\n",
      "    \n",
      "    it = nditer([n, None])\n",
      "    for x,y in it:\n",
      "        y[...] = 4*v*x/pi/sqrt(2)\n",
      "    return it.operands[1]\n",
      "vn1 = fun2(n)\n",
      "print \"Vo1rms for half bridge circuit = %0.2f V\" %round(vo1rms1)\n",
      "print \"Rms value of third harmonic component for bridge inverter circuit = %0.2f V\" %round(vn1[0])\n",
      "print \"Rms value of fifth harmonic component for half bridge inverter circuit = %0.2f V\" %round(vn1[1])\n",
      "print \"Rms value of seventh harmonic component for half bridge inverter circuit = %0.2f V\" %vn1[2]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Vo1rms for half bridge circuit = 90.00 V\n",
        "Rms value of third harmonic component for half bridge circuit = 30.00 V\n",
        "Rms value of fifth harmonic component for half bridge circuit = 18.00 V\n",
        "Rms value of seventh harmonic component for half bridge circuit = 12.86 V\n",
        "for bridge inverter\n",
        "Vo1rms for half bridge circuit = 180.00 V\n",
        "Rms value of third harmonic component for bridge inverter circuit = 60.00 V\n",
        "Rms value of fifth harmonic component for half bridge inverter circuit = 36.00 V\n",
        "Rms value of seventh harmonic component for half bridge inverter circuit = 25.72 V\n"
       ]
      }
     ],
     "prompt_number": 5
    }
   ],
   "metadata": {}
  }
 ]
}