{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 6 IMPEDENCE MATCHING AND TUNNING"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 6.1 page no:284"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "inductor of first circuit in nH =  38.9848400617\n",
      "capacitor of the first circuit in pF =  0.9227738301\n",
      "inductor of second circuit in nH =  46.138691505\n",
      "capacitor of the second circuit in pF =  2.59898933745\n",
      "\"NOTE:−for above specific problem Rl>Zo, positive X implies inductor , negative X implies capacitor , positive B implies capacitor and negative B implies inductor .\"\n"
     ]
    }
   ],
   "source": [
    "#Exa 6.1 program to design an L section matching network\n",
    "# example:−6.1,page no.−284.\n",
    "from math import pi,sqrt\n",
    "from sympy import I\n",
    "# program to design an L section matching network to match a series RC load.\n",
    "Zl=200-I*100; # load impedence .\n",
    "Rl=200;Xl=-100;f=500*10**6;Zo=100;\n",
    "B1=(Xl+sqrt(Rl/Zo)*sqrt(Rl**2+Xl**2-(Rl*Zo)))/(Rl**2+Xl**2);\n",
    "B2=(Xl-sqrt(Rl/Zo)*sqrt(Rl**2+Xl**2-(Rl*Zo)))/(Rl**2+Xl**2);\n",
    "C1=(B1/(2*pi*f))*10**12;\n",
    "L2=(-1/(B2*2*pi*f))*10**9;\n",
    "X1=(1/B1)+((Xl*Zo)/Rl)-(Zo/(B1*Rl));\n",
    "X2=(1/B2)+((Xl*Zo)/Rl)-(Zo/(B2*Rl));\n",
    "L1=(X1/(2*pi*f))*10**9;\n",
    "C2=(-1/(X2*2*pi*f))*10**12;\n",
    "print\"inductor of first circuit in nH = \",L1\n",
    "print\"capacitor of the first circuit in pF = \",C1\n",
    "print\"inductor of second circuit in nH = \",L2\n",
    "print\"capacitor of the second circuit in pF = \",C2 \n",
    "print\"\\\"NOTE:−for above specific problem Rl>Zo, positive X implies inductor , negative X implies capacitor , positive B implies capacitor and negative B implies inductor .\\\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 6.2 page no:304"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "charecteristic impedence of matching section = 22.360679775\n",
      " fractional bandwidth =  0.293159219438\n"
     ]
    }
   ],
   "source": [
    "#Exa 6.5 design quarter wave matching transformer\n",
    "#example:−6.5,page no.−304.\n",
    "from math import sqrt,pi,acos\n",
    "#program to design a single section quarter wave matching transformer .\n",
    "Zl=10; # load impedence .\n",
    "Zo=50; # characteristic impedence .\n",
    "fo=3*10**9;swr=1.5; # maximum limit of swr.\n",
    "Z1=sqrt(Zo*Zl); # characteristic impedence of the matching section .\n",
    "taom=(swr-1)/(swr+1);\n",
    "frac_bw=2-(4/pi)*acos((taom/sqrt(1-taom**2))*(2*sqrt(Zo*Zl)/abs(Zl-Zo))); # fractional bandwidth .\n",
    "print \"charecteristic impedence of matching section =\",Z1\n",
    "print \" fractional bandwidth = \",frac_bw"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 6.6 page no:307"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "approximate value of reflection coefficient is =  0.4\n",
      "the error in percent is about =  4.0\n"
     ]
    }
   ],
   "source": [
    "#Exa 6.6 program to evaluate the worst case percent error\n",
    "# example:−6.6,page no.−307.\n",
    "#from math import abs\n",
    "# program to evaluate the worst case percent error in computing magnitude of reflection coefficient .\n",
    "Z1 =100.; \n",
    "Z2 =150.; \n",
    "Zl =225.;\n",
    "tao_1=(Z2-Z1)/(Z2+Z1);\n",
    "tao_2=(Zl-Z2)/(Zl+Z2);\n",
    "tao_exact=(tao_1+tao_2)/(1+tao_1*tao_2); # this results as angle is taken zero .\n",
    "tao_approx=tao_1+tao_2; # this results as angle is taken zero .\n",
    "eror=abs(((tao_exact -tao_approx)/tao_exact)*100);\n",
    "print \"approximate value of reflection coefficient is = \",tao_approx\n",
    "print \"the error in percent is about = \",eror"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 6.7 page no:312"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Z1 =  91.7004043205\n",
      "Z2 =  84.0896415254\n",
      "Z3 =  77.1105412704\n"
     ]
    }
   ],
   "source": [
    "#Exa 6.7 design three section binomial transformer\n",
    "# example:−6.7,page no.−312.\n",
    "from math import pi,acos\n",
    "# program to design three section binomial transformer .\n",
    "Zl=50.;Zo=100.;N=3;taom=0.05;\n",
    "A=(2**-N)*abs((Zl-Zo)/(Zl+Zo));\n",
    "frac_bw=2-(4/pi)*acos(0.5*(taom/A)**2);\n",
    "c=1\n",
    "Z1=Zo*((Zl/Zo)**((2**-N)*(c**N)));\n",
    "print \"Z1 = \",Z1\n",
    "c=3**(1/3)\n",
    "Z2=Z1*((Zl/Zo)**((2**-N)*(c**N)));\n",
    "print \"Z2 = \",Z2\n",
    "c=3**(1/3)\n",
    "Z3=Z2*((Zl/Zo)**((2**-N)*(c**N)));\n",
    "print \"Z3 = \",Z3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 6.8 page no:316"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the characteristic impedences are =  52.5641025641 , 52.5641025641 , 95.1219512195\n"
     ]
    }
   ],
   "source": [
    "#Exa 6.8 design three section chebysev transfomer\n",
    "# example:−6.8,page no.−316.\n",
    "from math import pi,cosh\n",
    "from sympy import asec,acosh\n",
    "# program to design a three section chebysev transformer .\n",
    "Zl=100.;Zo=50.;taom=0.05;N=3;A=0.05;\n",
    "thetam=asec(cosh((1/N)*acosh((1/taom)*abs((Zl-Zo)/(Zl+Zo)))))*(180/pi);\n",
    "x=(cosh((1/N)*acosh((1/taom)*abs((Zl-Zo)/(Zl+Zo)))))\n",
    "tao_o=A*(x**3)/2;\n",
    "tao_1=(3*A*(x**3-x))/2; # from symmetry tao 3=tao \n",
    "Z1=Zo*((1+tao_o)/(1-tao_o));\n",
    "Z2=Z1*((1+tao_1)/(1-tao_1));\n",
    "Z3=Zl*((1-tao_o)/(1+tao_o));\n",
    "print \"the characteristic impedences are = \",Z1,\",\",Z2,\",\",Z3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 6.9 page no:323"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tao o =  -0.346573590279973\n",
      "A=  -3.54467649562\n"
     ]
    }
   ],
   "source": [
    "#Exa 6.9 design triangular taper and a klopfenstein taper\n",
    "#example:−6.9,page no.−323.\n",
    "from sympy import acosh,log\n",
    "#program to designa triangular taper and a klopfenstein taper .\n",
    "taom =0.02; Zl =50.; Zo =100.;\n",
    "tao_o=0.5*log(Zl/Zo);\n",
    "A=complex(acosh(tao_o/taom));\n",
    "A=A.real;\n",
    "print \"tao o = \",tao_o\n",
    "print\"A= \",A"
   ]
  }
 ],
 "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
}