{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 6 MICROWAVE RESONATORS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example:6.1 page.no:309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Qair = 2379.5\n",
      "Qteflon = 1217.7\n",
      "conclusion: Qair is almost twice that of Qteflon\n"
     ]
    }
   ],
   "source": [
    "#program to compare the Q of an air filled and teflon filled coaxial line resonator .\n",
    "from math import pi,sqrt,log\n",
    "\n",
    "sigma=5.813*10**7;muo=4*pi*10**-7;f=5*10**9;eta=377;a =1*10**-3;b=4*10**-3;\n",
    "omega=2*pi*f;ko=104.7;B=104.7;alpha=0.022;\n",
    "Rs=sqrt((omega*muo)/(2*sigma));\n",
    "alphaca=(Rs/(2*eta*log(b/a)))*((1/a)+(1/b)); # attenuation due to conductor loss for air filled line .\n",
    "eipsilar=2.08;tandelta=0.0004; # for teflon filled line .\n",
    "alphact=((Rs*sqrt(2.08)*0.01)/(2*eta*log(b/a)))*((1/ a)+(1/b)); # attenuation due to conductor loss for teflon filled line .\n",
    "alphada=0; # for air filled line .\n",
    "alphadt=ko*(sqrt(eipsilar)/2)*tandelta;\n",
    "Qair=B/(2*alpha);\n",
    "B=B*sqrt(eipsilar);\n",
    "alpha =0.062;\n",
    "Qteflon=B/(2*alpha);\n",
    "print \"Qair = %.1f\"%Qair\n",
    "print \"Qteflon = %.1f\"%Qteflon\n",
    "print \"conclusion: Qair is almost twice that of Qteflon\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example:6.2 page.no:312"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "length of the line in meter = 0.0219\n",
      "Q of the resonator = 525.9\n"
     ]
    }
   ],
   "source": [
    "# program to compute the length of the line for resonance at 5 GHZ and the Q of the resonator .\n",
    "from math import sqrt,pi\n",
    "\n",
    "W=0.0049;c=3*10**8;f=5*10**9;Zo=50;eipsilar=2.2;ko =104.7;tandelta =0.001;\n",
    "Rs=0.0184; # taken from example 7.1.\n",
    "eipsilae=1.87; # effective permittivity .\n",
    "l=c/(2*f*sqrt(eipsilae)); # resonator length .\n",
    "B=(2*pi*f*sqrt(eipsilae))/c;\n",
    "alphac=Rs/(Zo*W);\n",
    "alphad=(ko*eipsilar*(eipsilae -1)*tandelta)/(2*sqrt(eipsilae)*(eipsilar -1));\n",
    "alpha=alphac+alphad;\n",
    "Q=B/(2*alpha);\n",
    "print \"length of the line in meter = %.4f\"%l\n",
    "print \"Q of the resonator = %.1f\"%Q"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example:6.3 page.no:317"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d in meter = 0.0465\n",
      "Q1 = 1437\n",
      "Q2 = 1518\n"
     ]
    }
   ],
   "source": [
    "# program to find required length ,d and Q for l=1 and l=2 resonator mode.\n",
    "from math import sqrt,pi\n",
    "\n",
    "a=0.04755;b=0.02215;eipsilar=2.25;tandelta=0.0004;f =5*10**9;c=3*10**8;\n",
    "k=(2*pi*f*sqrt(eipsilar))/c # wave number .\n",
    "for l in range(1,2):\n",
    "    d=(l*pi)/sqrt((k**2)-((pi/b)**2)); # m=1 & n=0 mode .\n",
    "    print \"d in meter = %.4f\"%d\n",
    "eta=377/sqrt(eipsilar);\n",
    "Qc1=3380.;# l=1.\n",
    "Qc2=3864.;# l=2.\n",
    "Qd=2500.; # Q due to dielectric loss only .\n",
    "Q1=((1./Qc1)+(1./Qd))**-1; # for l =1.\n",
    "Q2=((1./Qc2)+(1./Qd))**-1; # for l =2.\n",
    "print \"Q1 = %.0f\"%Q1\n",
    "print \"Q2 = %.0f\"%Q2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example:6.4 page.no:323"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a in meter = 0.0395\n",
      "Qc = 42364.227\n"
     ]
    }
   ],
   "source": [
    "# program to find dimension and Q;\n",
    "from math import pi,sqrt\n",
    "\n",
    "f=5.*10**9;c=3.*10**8;p01=3.832;sigma=5.813*10**7;muo=4.*pi*10** -7;\n",
    "eipsilar =2.25;\n",
    "# mode TE011 . and d=2a .\n",
    "omega=2*pi*f;\n",
    "eta =377.;\n",
    "lamda=c/f;\n",
    "k=(2.*pi)/lamda;\n",
    "# f=(c/(2⇤pi))⇤sqrt((p01/a)ˆ2+(%pi/(2⇤a))ˆ2); as d=2a given\n",
    "a=sqrt((p01)**2+(pi/2)**2)/k;\n",
    "Rs=sqrt((omega*muo)/(2.*sigma))\n",
    "Qc=(k*a*eta)/(2.*Rs); # for m=l =1,n=0 and d=2a .\n",
    "print \"a in meter = %.4f\"%a\n",
    "print \"Qc = %.3f\"%Qc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example:6.5 page.no:309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f1 in GHZ= 2.853\n",
      "f2 in GHZ= 27.804\n",
      "approx. value of Q due to dielectric loss = 1000\n"
     ]
    }
   ],
   "source": [
    "# program to find the resonant frequency and Q for TE01delta mode .\n",
    "from math import sqrt,pi,tan\n",
    "\n",
    "delta=0.001;eipsilar=95.;a=0.413;L=0.008255;c=3.*10**8;\n",
    "#tan((B⇤L)/2)=alpha/beta.\n",
    "ko=2.405\n",
    "alpha=(sqrt((2.405/a)**2-(ko)**2));\n",
    "B=sqrt((eipsilar*(ko)**2) -(2.405/a)**2); # beta\n",
    "f1=((c*2.405)/(2*pi*sqrt(eipsilar)*a))*10**-7;\n",
    "f2=((c*2.405)/(2*pi*a))*10**-7;\n",
    "print \"f1 in GHZ= %.3f\"%f1\n",
    "print \"f2 in GHZ= %.3f\"%f2\n",
    "Q=1/tan(delta);\n",
    "print \"approx. value of Q due to dielectric loss = %.0f\"%Q"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example:6.6 page.no:336"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "coupling capacitor in pF =  433773.991\n",
      "frequency in GHZ=  3.66602230334e-07\n"
     ]
    }
   ],
   "source": [
    "# program to find the value of the coupling capacitor required for critical coupling .\n",
    "from math import pi,sqrt,atan\n",
    "\n",
    "l=0.02175;Zo=50;eipsilae=1.9;c=3*10^8;\n",
    "fo=c/(2*l*sqrt(eipsilae)); # first resonant frequency will occur when the resonator ia about l=lamdag/2 in length .\n",
    "lamdag=c/fo;\n",
    "alpha=1/8.7; # in Np/m.\n",
    "Q=pi/(2*l*alpha);\n",
    "bc=sqrt(pi/(2*Q));\n",
    "C=bc/(2*pi*fo*Zo)*10**12;\n",
    "print \"coupling capacitor in pF = \",C\n",
    "C=bc/(2*pi*fo*Zo);\n",
    "w1=atan(2*pi*fo*C*Zo)*c/(l*sqrt(eipsilae)); # from equation tan (B⇤l) =bc ;\n",
    "w1=w1*10**-8;\n",
    "print \"frequency in GHZ= \",w1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example:6.7 page.no:342"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on taking sin (2⇤pi )=0 ,w becomes=  A**2*a*c*d*t/4\n",
      "fractional change in resonant frequency=  2*(-A**2*a*b*d*eo/2 + A**2*a*c*d*t/4)/(A**2*a*b*d*eo)\n"
     ]
    }
   ],
   "source": [
    "# program to derive an expression for the change in resonant frequency .\n",
    "from sympy import symbols,sin,cos,integrate,limit\n",
    "from math import pi\n",
    "\n",
    "Ey,Hx,Hz,A,Zte,n,a,p,i,x,z,d,j,k,t,y,er,eo,c,wo,w,b=symbols('Ey,Hx,Hz,A,Zte,n,a,p,i,x,z,d,j,k,t,y,er,eo,c,wo,w,b')\n",
    "Ey=A*sin((pi*x)/a)*sin((pi*z)/d);\n",
    "Hx=((-j*A)/Zte)*sin((pi*x)/a)*cos((pi*z)/d);\n",
    "Hz=((j*pi*A)/(k*n*a))*cos((pi*x)/a)*sin((pi*z)/d); \n",
    "Ey=Ey**2; #c=(er1)⇤eo;\n",
    "w=c*integrate(integrate(integrate(Ey,(z,0,d)),(y,0,t)),(x,0,a));\n",
    "# as sin (2⇤ pi )=0; then last term of above result will be:\n",
    "w=(c*A**2*a*t*d)/4;\n",
    "print \"on taking sin (2⇤pi )=0 ,w becomes= \",w\n",
    "wo=((a*b*d*eo)/2)*A**2;\n",
    "deltaw=(w-wo)/wo;\n",
    "print \"fractional change in resonant frequency= \",deltaw"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}