{
 "metadata": {
  "name": "",
  "signature": "sha256:2baa3eb0c199078d6675540c13fc8ca69d0c0eaa0d2eef907c98727dce3b6cde"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Ch-1 : Microwaves"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 12 Example 1.2"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import cmath \n",
      "from math import pi\n",
      "#Given\n",
      "z0=50 #ohm\n",
      "zg=50 #ohm\n",
      "l=0.25 #m\n",
      "f=4e9 #hz\n",
      "zl=100 #ohm\n",
      "vg=10 #V\n",
      "w=2*pi*f #rad/sec\n",
      "c=3e8  #m/s\n",
      "\n",
      "#(i) Voltage and current at any point\n",
      "tg=(zg-z0)/(zg+z0) \n",
      "tl=(zl-z0)/(zl+z0) \n",
      "vi=z0*vg/(z0+zg) #V\n",
      "print 'Voltage at any point = %0.2f V' %(vi)\n",
      "ii=vg/(2*z0) #A\n",
      "print 'Current at any point = %0.2f A'%(ii) \n",
      "\n",
      "#(ii) Voltage at generator end\n",
      "#Taking z=1\n",
      "z=1 \n",
      "bet=w/c \n",
      "vz=(vg/2)*cmath.exp(-1J*bet*(z+l))*(1+(tl*cmath.exp(2*1J*bet*z))) #V\n",
      "print 'Voltage at generator end ={:.3f}'.format(vz),'V'\n",
      "iz=ii*cmath.exp(-1J*bet*(z+l))*(1-(tl*cmath.exp(2*1J*bet*z))) #A\n",
      "vz1=(vg/2)*cmath.exp(-1J*bet*(z+l))*(1+(tl*cmath.exp(2*1J*bet*z))) #V\n",
      "\n",
      "#Voltage at load end, z=0\n",
      "z11=0 \n",
      "vl=(vg/2)*cmath.exp(-1J*bet*l)*(1+(tl*cmath.exp(2*1J*bet*z11))) #V\n",
      "print 'Voltage at load end ={:.3f}'.format(vl),'V'\n",
      "\n",
      "#(iii) Reflection coefficient\n",
      "zx=0.25 \n",
      "tz=tl*cmath.exp(1J*2*bet*zx) \n",
      "print 'Reflection coefficient:{:.3f}'.format(tz) \n",
      "\n",
      "#(iv) VSWR\n",
      "p=(1+tl)/(1-tl) \n",
      "print 'VSWR:' ,p\n",
      "\n",
      "#(v) Average power delivered to the load\n",
      "vl=20/3 \n",
      "pl0=vl**2/(2*zl) #W\n",
      "print 'Average power delivered to the load = %0.2f W' %pl0"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Voltage at any point = 5.00 V\n",
        "Current at any point = 0.10 A\n",
        "Voltage at generator end =-0.833+4.330j V\n",
        "Voltage at load end =-3.333-5.774j V\n",
        "Reflection coefficient:-0.167-0.289j\n",
        "VSWR: 2.0\n",
        "Average power delivered to the load = 0.22 W\n"
       ]
      }
     ],
     "prompt_number": 41
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 14 Example 1.3"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log \n",
      "#Given\n",
      "pm=3 \n",
      "pl=4 \n",
      "l=24 #cm\n",
      "l1=l/100 #m\n",
      "\n",
      "#Attenuation\n",
      "tin=(pm-1)/(pm+1) \n",
      "tl=(pl-1)/(pl+1) \n",
      "alp=(1/(2*l1))*log(tl/tin) #Np/m\n",
      "print 'Attenuation in the line = %0.2f'%alp,'Mp/m' "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Attenuation in the line = 0.38 Mp/m\n"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 14 Example 1.4"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt \n",
      "#Given\n",
      "c=3e8  #m/s\n",
      "z0=200 #ohm\n",
      "zl=800 #ohm\n",
      "f=30e6 #hz\n",
      "\n",
      "#Characterstic impedance\n",
      "z00=sqrt(z0*zl) #ohm\n",
      "print 'Characterstic impedance = %0.2f ohm' %z00\n",
      "\n",
      "#Length of line\n",
      "lam=c/f #m\n",
      "l=lam/4 #m\n",
      "print 'Length of line = %0.2f m' %l"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Characterstic impedance = 400.00 ohm\n",
        "Length of line = 2.50 m\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 15 Example 1.5"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "l=1.2 #mH\n",
      "r=8 #ohm\n",
      "c=200e-12 #F\n",
      "\n",
      "#(i) Resonant frequency\n",
      "f0=(1/(2*pi))*sqrt(1/(l*c)) #hz\n",
      "print 'Resonant frequency:%0.2f'%f0,'Hz' \n",
      "\n",
      "#(ii) Impedance of circuit\n",
      "print 'Impedance of circuit:',r,'ohm' \n",
      "\n",
      "#(iii)Q factor of the circuit\n",
      "q=1/(2*pi*f0*c*r) \n",
      "print 'Q factor of the circuit:%0.2f'%q\n",
      "\n",
      "#(iv) Bandwidth\n",
      "df=f0/q #hz\n",
      "\n",
      "print  'Bandwidth:%0.2f' %df,'Hz'\n",
      "\n",
      "#The value of resonant frequency is calculated wrong in book\n",
      "#Hence Q factor and bandwidth, all these answers dont match"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Resonant frequency:10273.41 Hz\n",
        "Impedance of circuit: 8 ohm\n",
        "Q factor of the circuit:9682.46\n",
        "Bandwidth:1.06 Hz\n"
       ]
      }
     ],
     "prompt_number": 44
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: Example 1.6"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import cos, sin\n",
      "#Given\n",
      "c=3e8  #m/s\n",
      "le=25 #m\n",
      "zl=40+(1J*30) #ohm\n",
      "f=10e6 #hz\n",
      "cap=40e-12 #F\n",
      "l=300e-9 #H/m\n",
      "\n",
      "#Input impedance\n",
      "z0=sqrt(l/cap) #ohm\n",
      "zl1=zl/z0 \n",
      "lam=c/f #m\n",
      "bet=(2*pi*le)/lam #rad\n",
      "zin=((zl1*cos(bet))+(1J*sin(bet)))/(cos(bet)+(1J*zl1*sin(bet))) #ohm\n",
      "print 'Input impedance: {:.3f}'.format(zin), 'ohm'\n",
      "\n",
      "#Reflection coefficient\n",
      "t=(zl1-1)/(zl1+1) \n",
      "print 'Reflection coefficient:{:.3f}'.format(t)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Input impedance: 0.577-0.577j ohm\n",
        "Reflection coefficient:-0.295+0.307j\n"
       ]
      }
     ],
     "prompt_number": 46
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 16 Example 1.7"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import cmath \n",
      "#Given\n",
      "c=3e8  #m/s\n",
      "R=2.25 #ohm\n",
      "L=1e-9 #H/m\n",
      "C=1e-12 #F/m\n",
      "f=0.5e9 #hz\n",
      "G=0 \n",
      "w=2*pi*f #rad/sec\n",
      "\n",
      "#Characterstic impedance\n",
      "z0=cmath.sqrt((R+(1J*w*L))/(G+(1J*w*C)))  #ohm\n",
      "print 'Characterstic impedance:{:.3f}'.format(z0),'ohm'\n",
      "\n",
      "#Propagation constant\n",
      "gam=cmath.sqrt((R+(1J*w*L))*(G+(1J*w*C))) \n",
      "print 'Propagation constant:{:.3f}'.format(gam)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Characterstic impedance:33.392-10.724j ohm\n",
        "Propagation constant:0.034+0.105j\n"
       ]
      }
     ],
     "prompt_number": 48
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 20 Example 1.8"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "c=3e8  #m/s\n",
      "f=3e9  #Hz\n",
      "ZL=50-(1J*100)  #ohms\n",
      "Z0=50  #ohm\n",
      "#Wavelength\n",
      "lam=c/f \n",
      "print 'Wavelength:',lam*100, 'cm'\n",
      "\n",
      "#Normalized load impedance\n",
      "z=ZL/Z0 \n",
      "print 'Normalized load impedance:' ,z\n",
      "\n",
      "#From chart\n",
      "zin=0.45+(1J*1.2) \n",
      "yin=0.27-(1J*0.73) \n",
      "ZINN=Z0*zin \n",
      "print 'Line impedance:' ,ZINN,'ohm'\n",
      "YINN=yin/Z0 \n",
      "print 'Line admittance:',YINN, 'mho'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Wavelength: 10.0 cm\n",
        "Normalized load impedance: (1-2j)\n",
        "Line impedance: (22.5+60j) ohm\n",
        "Line admittance: (0.0054-0.0146j) mho\n"
       ]
      }
     ],
     "prompt_number": 49
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 22 Example 1.9"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "ZL=75+(1J*100)  #ohms\n",
      "Z0=50  #ohm\n",
      "\n",
      "#Normalized load impedance\n",
      "z=ZL/Z0 \n",
      "print 'Normalized load impedance:' ,z\n",
      "\n",
      "#(i) 0.051*lam\n",
      "#From chart\n",
      "r=4.6 \n",
      "Zi1=r*Z0 \n",
      "print 'Input impedance at 0.051 lam:' ,Zi1,'ohm'\n",
      "\n",
      "#(ii) 0.102*lam\n",
      "r1=1.5-(1J*2) \n",
      "Zi2=r1*Z0 \n",
      "print 'Input impedance at 0.102 lam:' ,Zi2,'ohm'\n",
      " \n",
      "#(iii) 0.301*lam\n",
      "r2=0.22 \n",
      "Zi3=r2*Z0 \n",
      "print 'Input impedance at 0.301 lam:' ,Zi3, 'ohm'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Normalized load impedance: (1.5+2j)\n",
        "Input impedance at 0.051 lam: 230.0 ohm\n",
        "Input impedance at 0.102 lam: (75-100j) ohm\n",
        "Input impedance at 0.301 lam: 11.0 ohm\n"
       ]
      }
     ],
     "prompt_number": 50
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 23 Example 1.10"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "ZL=15+(1J*20)  #ohms\n",
      "Z0=50  #ohm\n",
      "\n",
      "#Normalized load impedance\n",
      "z=ZL/Z0 \n",
      "print 'Normalized load impedance:' ,z\n",
      "\n",
      "#From chart\n",
      "T=0.6 \n",
      "print 'Reflection coefficient:' ,T\n",
      "\n",
      "#VSWR\n",
      "p=4 \n",
      "print 'VSWR:' ,p"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Normalized load impedance: (0.3+0.4j)\n",
        "Reflection coefficient: 0.6\n",
        "VSWR: 4\n"
       ]
      }
     ],
     "prompt_number": 51
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 25 Example 1.11"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "Z0=50  #ohm\n",
      "p=2.4 \n",
      "\n",
      "#From chart\n",
      "zl=1.4+1J \n",
      "L=Z0*zl \n",
      "print 'Load:',L, 'ohm'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Load: (70+50j) ohm\n"
       ]
      }
     ],
     "prompt_number": 52
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 26 Example 1.12"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "Z0=50  #ohm\n",
      "T=2.23 \n",
      "\n",
      "#From chart\n",
      "zl=2+1J \n",
      "ZLd=Z0*zl \n",
      "print 'Normalized impedance:',ZLd, 'ohm'\n",
      "\n",
      "#Impedance of device is by negating the real part\n",
      "imp=-(ZLd.real)+((ZLd.imag)*1J) \n",
      "print 'Impedance of device:' ,imp,'ohm'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Normalized impedance: (100+50j) ohm\n",
        "Impedance of device: (-100+50j) ohm\n"
       ]
      }
     ],
     "prompt_number": 53
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 27 Example 1.13"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "p=3 \n",
      "m1=54  #cm\n",
      "m2=204  #cm\n",
      "\n",
      "#Point A\n",
      "print 'Point A' \n",
      "lam=4*(m2-m1) \n",
      "dA=0.083*lam \n",
      "L=m1-dA \n",
      "print 'Location of stub:',L, 'cm'\n",
      "IA=0.114*lam \n",
      "print 'Length:' ,IA, 'cm'\n",
      "\n",
      "#Point B\n",
      "print 'Point B' \n",
      "dB=0.083*lam \n",
      "IB=0.386*lam \n",
      "Lb=dB+m1 \n",
      "print 'Location of stub:',Lb, 'cm'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Point A\n",
        "Location of stub: 4.2 cm\n",
        "Length: 68.4 cm\n",
        "Point B\n",
        "Location of stub: 103.8 cm\n"
       ]
      }
     ],
     "prompt_number": 54
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 30 Example 1.15"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Given\n",
      "Z0=50  #ohm\n",
      "ZL=100  #ohms\n",
      "f=10e9  #Hz\n",
      "c=0.159e-12  #F\n",
      "\n",
      "#Normalized load impedance\n",
      "z=ZL/Z0 \n",
      "print 'Normalized load impedance:' ,z\n",
      "\n",
      "#From chart\n",
      "zin=0.4+(1J*0.55) \n",
      "ZINN=Z0*zin \n",
      "print 'Normalized impedance:',ZINN, 'ohm'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Normalized load impedance: 2.0\n",
        "Normalized impedance: (20+27.5j) ohm\n"
       ]
      }
     ],
     "prompt_number": 55
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 42 Example 1.16"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#From given wave equation we can see\n",
      "w=1e9 #rad/sec\n",
      "bet=30 #rad/m\n",
      "c=3e8  #m/s\n",
      "u0=1  #let\n",
      "e0=1/(9e16) \n",
      "\n",
      "vp=w/bet #m/sec\n",
      "print 'Phase velocity:%0.2f' %vp,'m/s'\n",
      "\n",
      "e=1/(vp**2*u0) \n",
      "er=e/(e0*u0) \n",
      "print 'Dielectric constant:' ,er"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Phase velocity:33333333.33 m/s\n",
        "Dielectric constant: 81.0\n"
       ]
      }
     ],
     "prompt_number": 56
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 42 Example 1.17"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given\n",
      "c=3e8  #m/s\n",
      "f=10e9 #hz\n",
      "er=6 \n",
      "tandel=2e-4 \n",
      "\n",
      "vp=c/er #m/sec\n",
      "print 'Phase velocity: %0.f'%vp,'m/sec'\n",
      "al=(pi*f*tandel)/vp #Np/m\n",
      "print 'Attenuation constant: %0.3f'%al,'Np/m'\n",
      "\n",
      "#Answer for velocity is calculated wrong in book, hence answers dont match for both"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Phase velocity: 50000000 m/sec\n",
        "Attenuation constant: 0.126 Np/m\n"
       ]
      }
     ],
     "prompt_number": 59
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 43 Example 1.18"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " #Given\n",
      "er=2.2 \n",
      "n0=377 #ohm\n",
      "n2=n0/sqrt(er) #ohm\n",
      "n1=377 #ohm\n",
      "\n",
      "#Reflection coefficient\n",
      "t=(n2-n1)/(n2+n1) \n",
      "print 'Reflection coefficient: %0.2f'%t\n",
      "\n",
      "#Vswr\n",
      "#Taking mod of reflection coefficient\n",
      "t1=-t \n",
      "p=(1+t1)/(1-t1) \n",
      "print 'VSWR: %0.3f'%p"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Reflection coefficient: -0.19\n",
        "VSWR: 1.483\n"
       ]
      }
     ],
     "prompt_number": 62
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Page Number: 43 Example 1.19"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " #Given\n",
      "sig=5 #mohm/m\n",
      "er=80*8.85e-12 \n",
      "eaz=0.1 \n",
      "u=1.26e-6 \n",
      "\n",
      "az=-log(0.1) \n",
      "#(i) Range at 25Khz\n",
      "f=25e3 #Khz\n",
      "w=2*pi*f #rad/sec\n",
      "a=w*(sqrt((u*er/2)*(sqrt(sig**2/(w**2*er**2)+1)-1))) \n",
      "z=az/a #m\n",
      "print 'Range at 25khz: %0.3f'%z, 'm'\n",
      "\n",
      "#(ii) Range at 25Mhz\n",
      "f1=25e6 #Mhz\n",
      "w1=2*pi*f1 #rad/sec\n",
      "a1=w1*(sqrt((u*er/2)*(sqrt(sig**2/(w1**2*er**2)+1)-1))) \n",
      "z1=az/a1 #m\n",
      "print 'Range at 25Mhz: %0.3f'%z1, 'm'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Range at 25khz: 3.273 m\n",
        "Range at 25Mhz: 0.105 m\n"
       ]
      }
     ],
     "prompt_number": 63
    }
   ],
   "metadata": {}
  }
 ]
}