{
 "metadata": {
  "name": "",
  "signature": "sha256:e5e51717065f48c86dca50bb80c877a8dccdac1a1049a8aa680cfb5df955894e"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter6, Antenna Arrays"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.2.1, page 6-13"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "n=2 #(No. of point source)\n",
      "#E=E0*{exp(%i*pi/2)-exp(-%i*si/2)} where exp(-%i*si)=-1\n",
      "#si=Beta*d*cosd(fi)=2*pi*cosd(fi)\n",
      "#E=2*%i*E0*sind(pi*cosd(fi))  But 2*%i*E0=1\n",
      "from numpy import arange, sin, pi, cos, nditer\n",
      "fi=arange(0,331,30) #degree(angle)\n",
      "En=sin(pi*cos(fi*pi/180)) #Normalized field\n",
      "print \" fi  :\\t\",\n",
      "for x in fi:\n",
      "    print x,\"\\t\",\n",
      "print \"\"\n",
      "print \"|En| :\\t\",\n",
      "for x in abs(En):\n",
      "    print \"%0.2f\"%x,\"\\t\","
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " fi  :\t0 \t30 \t60 \t90 \t120 \t150 \t180 \t210 \t240 \t270 \t300 \t330 \t\n",
        "|En| :\t0.00 \t0.41 \t1.00 \t0.00 \t1.00 \t0.41 \t0.00 \t0.41 \t1.00 \t0.00 \t1.00 \t0.41 \t"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.2.2, page 6-16"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "n=2 #(No. of point source)\n",
      "#E=E0*{exp(%i*(pi/4+si/2))-exp(-%i*(pi/4+si/2))} as exp(%i*theta)+exp(-%i*theta)=2*cos(theta)\n",
      "#E=2*E0*cos(pi/4+si/2) \n",
      "#si=Beta*d*cosd(fi)=2*pi*cosd(fi)\n",
      "#En=cos(pi/4+Beta*d*cosd(pi/4))  But 2*E0=1\n",
      "from numpy import arange, sin, pi, cos, nditer\n",
      "fi=arange(0,331,30) #degree(angle)\n",
      "En=cos(pi/4+pi/4*cos(fi*pi/180)) #Normalized field\n",
      "print \" fi  :\\t\",\n",
      "for x in fi:\n",
      "    print x,\"\\t\",\n",
      "print \"\"\n",
      "print \"|En| :\\t\",\n",
      "for x in abs(En):\n",
      "    print \"%0.3f\"%x,\"\\t\","
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " fi  :\t0 \t30 \t60 \t90 \t120 \t150 \t180 \t210 \t240 \t270 \t300 \t330 \t\n",
        "|En| :\t0.000 \t0.105 \t0.383 \t0.707 \t0.924 \t0.994 \t1.000 \t0.994 \t0.924 \t0.707 \t0.383 \t0.105 \t"
       ]
      }
     ],
     "prompt_number": 36
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.2.3, page 6-18"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#E=cos(fi)+sin(fi)<si \n",
      "#En=cos(pi/4+pi*cosd(fi)) as 2*E0=1\n",
      "from numpy import arange, sin, pi, cos, nditer\n",
      "fi=arange(0,331,30) #degree(angle)\n",
      "si=pi/2*(cos(fi*pi/180)+1) #(Phase)\n",
      "En=cos(pi/4+pi*cos(fi*pi/180)) #Normalized field\n",
      "print \" fi  :\\t\",\n",
      "for x in fi:\n",
      "    print x,\"\\t\",\n",
      "print \"\"\n",
      "print \"|En| :\\t\",\n",
      "for x in abs(En):\n",
      "    print \"%0.3f\"%x,\"\\t\",\n",
      "#Answer in the book is wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " fi  :\t0 \t30 \t60 \t90 \t120 \t150 \t180 \t210 \t240 \t270 \t300 \t330 \t\n",
        "|En| :\t0.707 \t0.934 \t0.707 \t0.707 \t0.707 \t0.356 \t0.707 \t0.356 \t0.707 \t0.707 \t0.707 \t0.934 \t"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.6.1, page 6-34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import degrees, acos\n",
      "n=80.0 #(no. of elements)\n",
      "N=1.0 #for first null\n",
      "#d=lamda/2 (spacing)\n",
      "dBYlamda=1.0/2 #(spacing/wavelength)\n",
      "fi01=degrees(acos(N/n/dBYlamda)) #degree(Angle)\n",
      "Null_1st=(pi/2*180/pi)-fi01 #degree(First Null)\n",
      "print \"Location of 1st null from maxima = %0.2f degree \"%Null_1st "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Location of 1st null from maxima = 1.43 degree \n"
       ]
      }
     ],
     "prompt_number": 47
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6.6.2, page 6-34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import degrees, acos\n",
      "import numpy as np\n",
      "n=4.0 #(No. of elements)\n",
      "#d=lamda/2 (Spacing)\n",
      "dBYlamda=1.0/2 #(Spacing/wavelength)\n",
      "alfa=0 #degree(angle)\n",
      "N=1.0 #(For first null)\n",
      "print \"Part (i) :\" \n",
      "theta01=np.array([degrees(acos(+N/2)),degrees(acos(-N/2))]) #degree(Angle)\n",
      "N=2 #(For second null)\n",
      "theta02=np.array([degrees(acos(+N/2)), degrees(acos(-N/2))]) #degree(angle)\n",
      "#N=3 #not possible as N/2 is greater than 1\n",
      "print \"\\tNull directions for N=1 : theta01 =\" ,theta01 ,\"degree\"\n",
      "print \"\\tNull directions for N=2 : theta02 =\" ,theta02 ,\"degree\"\n",
      "print \"Part (ii):\" \n",
      "m=0 #for maxima\n",
      "theta_m=degrees(acos(m/dBYlamda)) #degree(angle)\n",
      "print \"\\tDirection of maxima : theta_m = %0.2f degree \" %theta_m\n",
      "print \"Part (iii):\" \n",
      "S=1 #for side lobe maxima\n",
      "#S=2 & onwards not possible\n",
      "theta_S=np.array([degrees(acos((2*S+1)/2/n/dBYlamda)), degrees(acos(-(2*S+1)/2/n/dBYlamda))]) #degree(angle for side lobe)\n",
      "print \"\\tSide lobe maxima : theta_S =\",theta_S ,\"degree \"\n",
      "print \"Part (iv):\" \n",
      "HPBW=2*(90-degrees(acos(1.391/np.pi/n/dBYlamda))) #degree(HPBW)\n",
      "print \"\\tHPBW = %0.2f degree \" %HPBW \n",
      "print \"Part (v):\" \n",
      "FNBW=2*(90-degrees(acos(1/n/dBYlamda))) #degree(FNBW)\n",
      "print \"\\tFNBW = %0.2f degree \"%FNBW \n",
      "print \"Part (vi):\" \n",
      "SLL=-13.46 #dB##for isotropic sources array(Side lobe level)\n",
      "print \"\\tSide lobe level = %0.2f dB \"%SLL \n",
      "# Answer wrong in the textbook."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (i) :\n",
        "\tNull directions for N=1 : theta01 = [  60.  120.] degree\n",
        "\tNull directions for N=2 : theta02 = [   0.  180.] degree\n",
        "Part (ii):\n",
        "\tDirection of maxima : theta_m = 90.00 degree \n",
        "Part (iii):\n",
        "\tSide lobe maxima : theta_S = [  60.  180.] degree \n",
        "Part (iv):\n",
        "\tHPBW = 25.58 degree \n",
        "Part (v):\n",
        "\tFNBW = 60.00 degree \n",
        "Part (vi):\n",
        "\tSide lobe level = -13.46 dB \n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.8.1, page 6-41"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "from __future__ import division\n",
      "n=4 #(No. of elements)\n",
      "#d=lamda/2 (spacing)\n",
      "dBYlamda=1/2 #(spacing/wavelength)\n",
      "theta=0 #degree(angle)\n",
      "#Beta=2*pi/lamda\n",
      "print \"Part (i):\" \n",
      "Beta_into_lamda=2*np.pi #(Coefficient)\n",
      "#alfa=-Beta*d\n",
      "alfa=-Beta_into_lamda*dBYlamda #radian(Progressive phase shift)\n",
      "alfa=alfa*180/np.pi #degree(Progressive phase shift)\n",
      "print \"\\tProgressive phase shift = %0.2f degree \"%alfa \n",
      "print \"Part (ii):\" \n",
      "N=range(1,4) #as N=4 is not allowed\n",
      "theta01=degrees(acos(1-N[0]/n/dBYlamda)) #degree(angle)\n",
      "theta02=degrees(acos(1-N[1]/n/dBYlamda)) #degree(angle)\n",
      "theta03=degrees(acos(1-N[2]/n/dBYlamda)) #degree(angle)\n",
      "print \"\\tNull directions, theta01, theta02 & theta03 are %0.2f, %0.2f & %0.2f degree \"%(theta01,theta02,theta03) \n",
      "print \"Part (iii):\" \n",
      "m=range(0,2) #as m=2 & onwards is not allowed\n",
      "theta0=degrees(acos(1-m[0]/dBYlamda)) #degree(angle)\n",
      "theta1=degrees(acos(1-m[1]/dBYlamda)) #degree(angle)\n",
      "print \"\\tMaxima directions, theta0, theta1 are %0.2f & %0.2f degree \"%(theta0,theta1) \n",
      "print \"Part (iv):\" \n",
      "FNBW=2*degrees(acos(1-1/n/dBYlamda)) #degree(FNBW)\n",
      "print \"\\tFNBW = %0.2f degree \"%(FNBW) \n",
      "print \"Part (v):\" \n",
      "HPBW=2*degrees(acos(1-1.391/n/np.pi/dBYlamda)) #degree(HPBW)\n",
      "print \"\\tHPBW = %0.2f degree :  \"%HPBW "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part (i):\n",
        "\tProgressive phase shift = -180.00 degree \n",
        "Part (ii):\n",
        "\tNull directions, theta01, theta02 & theta03 are 60.00, 90.00 & 120.00 degree \n",
        "Part (iii):\n",
        "\tMaxima directions, theta0, theta1 are 0.00 & 180.00 degree \n",
        "Part (iv):\n",
        "\tFNBW = 120.00 degree \n",
        "Part (v):\n",
        "\tHPBW = 77.73 degree :  \n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.8.2, page 6-43"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "n=16 #no. of point source\n",
      "#d=lamda/4 (spacing)\n",
      "dBYlamda=1/4 #(Spacing/wavelength)\n",
      "HPBW=2*degrees(acos(1-1.391/n/np.pi/dBYlamda)) #degree(HPBW)\n",
      "print \"HPBW = %0.2f degree\" %HPBW"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "HPBW = 54.43 degree\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.10.1, page 6-50"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "n=10 #no. of elements\n",
      "#d=lamda/4 (spacing)\n",
      "dBYlamda=1/4 #/(Spacing/wavelength)\n",
      "#Broadside array\n",
      "D=2*n*dBYlamda #unitless(Directivity)\n",
      "D=10*np.log10(D) #dB(Directivity)\n",
      "print \"Directivity for broadside array = %0.2f dB \" %D\n",
      "#Endfire array\n",
      "D=4*n*dBYlamda #unitless(Directivity)\n",
      "D=10*np.log10(D) #dB(Directivity)\n",
      "print \"Directivity for Ordinary endfire array = %0.2f dB \"%D "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Directivity for broadside array = 6.99 dB \n",
        "Directivity for Ordinary endfire array = 10.00 dB \n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.10.2, page 6-50"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "D=20 #dB(Directivity)\n",
      "#d=lamda/4 (spacing)\n",
      "dBYlamda=1/4 #(spacing/wavelength)\n",
      "D=10**(D/10) #unitless(Directivity)\n",
      "n=D/4/dBYlamda #no. of elements\n",
      "print \"(i) No. of elements : \",n \n",
      "LBYlamda=(n-1)*dBYlamda #(length/wavelength)\n",
      "print \"(ii) Length of the array is \",(LBYlamda),\"*lamda\" \n",
      "HPBW=2*degrees(acos(1-1.391/np.pi/n/dBYlamda)) #degree(HPBW)\n",
      "print \"(iii) HPBW = %0.2f degree \" %HPBW \n",
      "SLL=-13.46 #dB(Side lobe level)\n",
      "print \"(iv) SLL = %0.2f dB \" %SLL \n",
      "Beta_into_lamda=2*np.pi #(temorary calculatuion)\n",
      "#alfa=-Beta*d #for theta=0\n",
      "#alfa=Beta*d #for theta=180\n",
      "alfa1=-Beta_into_lamda*dBYlamda #radian##for theta=0\n",
      "alfa1=alfa1*180/np.pi #degree(angle)\n",
      "alfa2=Beta_into_lamda*dBYlamda #radian##for theta=180\n",
      "alfa2=alfa2*180/np.pi #degree(angle)\n",
      "print \"(v) Progressive phase shift, \u03b1 for theta equals to 0\u00b0 & 180\u00b0 are : \",(alfa1,alfa2) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i) No. of elements :  100.0\n",
        "(ii) Length of the array is  24.75 *lamda\n",
        "(iii) HPBW = 21.60 degree \n",
        "(iv) SLL = -13.46 dB \n",
        "(v) Progressive phase shift, \u03b1 for theta equals to 0\u00b0 & 180\u00b0 are :  (-90.0, 90.0)\n"
       ]
      }
     ],
     "prompt_number": 40
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example No. 6.14.1, page 6-74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import symbols, solve\n",
      "SLL=19.1 #dB(Side Lobe Level)\n",
      "#d=lamda/2 (spacing)\n",
      "dBYlamda=1/2 #(Spacing/wavelength)\n",
      "n=4 #(no. of elements)\n",
      "r=round(10**(SLL/20)) #(ratio of main lobe to side lobe)\n",
      "m=n-1 #(degree )\n",
      "x0 = symbols('x0')\n",
      "#T3(x0)=r=4*x0**3-3*x0 \n",
      "T3=4*x0**3-3*x0 -9\n",
      "#x0=roots([4 0 -3 -r]) #(Coefficient)\n",
      "x0=solve(T3)\n",
      "x0=x0[0] #taking real value(Coefficient)\n",
      "#E4(z)=T3(x)=4*x**3-3*x=4*a1*z**3-3*a1*z+a0*z\n",
      "#4*a1*z**3=4*x**3 where z**3=(x/x0)**3\n",
      "a1=4*x0**3/4 #(Coefficient)\n",
      "#a0*z-3*z*a1=-3*x\n",
      "a0=(3/x0*a1-3)*x0 #(Coefficient)\n",
      "print \"Coefficients of array polynomial a1 & a0 are : \",float(a0),\"&\", float(a1)\n",
      "print \"Relative current amplitudes are :\",round(float(a0/a1),2),\"&\",float(a1/a1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Coefficients of array polynomial a1 & a0 are :  5.625 & 3.375\n",
        "Relative current amplitudes are : 1.67 & 1.0\n"
       ]
      }
     ],
     "prompt_number": 52
    }
   ],
   "metadata": {}
  }
 ]
}