Attachment 'line07.c'

Download

   1 //  line07.c   random spacings
   2 //  version 0.7 - constants fed in defines
   3 //
   4 //  compile with gcc -o line07 line07.c -lm
   5 //
   6 //  This computes the off-axis lobes for a 1 dimensional phased array
   7 //  normalized random spacing
   8 //
   9 //  The array is NX points wide centered around x=0.  
  10 //  The distance from the center of the array to a ground station is gy
  11 
  12 //  look at signal intensity along a line from X0 to X1
  13 
  14 //  Start with the simple minded assumption that all stations are
  15 //  phased from the ground receiver, with an (r,-i) component
  16 //  Then look at the change of intensity with distance.
  17 
  18 #define DISTANCE 1
  19 #undef  DISTANCE
  20 
  21 // -------------------- array definition --------------------------
  22 // NX  == number of cells in array
  23 //  #define  NX  32
  24 #define  NX  128
  25 
  26 // SX1 == base spacing
  27 #define  SX1 10.0
  28 
  29 // SXF == random spread (uniform) in meters
  30 // #define  SXF 0.5
  31 #define  SXF 3.0
  32 
  33 // number of random spreads from 0 to SXF
  34 #define  NSP   4
  35 
  36 // SAM == amplitude increase, parabolic
  37 // #define  SAM  -1.0
  38 #define  SAM  0.0
  39 
  40 // wavelength
  41 #define  WL  0.008         
  42 
  43 // -------------------- ground spot --------------------------------
  44 
  45 #define  GY  6411000.0     // 6411km from m288 to equator
  46 #define  GX  0.0
  47 
  48 // --------------------  ground sweep -------------------------------
  49 #define THRESH 0.02
  50 
  51 //  -1000/5000
  52 #define  X0 -1000000.0
  53 #define  X1  5000000.0
  54 #define  NBINS  1201
  55 #define  NPTS_PER_BIN 4999     // odd to get center lobe
  56 
  57 //  -100/500
  58 //#define  X0 -100000.0
  59 //#define  X1  500000.0
  60 //#define  NBINS  1201
  61 //#define  NPTS_PER_BIN 499      // odd to get center lobe
  62 
  63 //  -10/50
  64 //#define  X0 -10000.0
  65 //#define  X1  50000.0
  66 //#define  NBINS  1201
  67 //#define  NPTS_PER_BIN 49          // odd to get center lobe
  68 
  69 //  -5/20
  70 // #define  X0 -5000.0
  71 // #define  X1  20000.0
  72 // #define  NBINS  1001
  73 // #define  NPTS_PER_BIN 49          // odd to get center lobe
  74 
  75 //  -1/1
  76 //#define  X0 -1000.0
  77 //#define  X1  1000.0
  78 //#define  NBINS  1001
  79 //#define  NPTS_PER_BIN 9              // odd to get center lobe
  80 
  81 //  14/16
  82 //#define  X0 14000.0
  83 //#define  X1 16000.0
  84 //#define  NBINS  1001
  85 //#define  NPTS_PER_BIN 9              // odd to get center lobe
  86 
  87 
  88 #include <stdio.h>
  89 #include <stdlib.h>
  90 #include <math.h>
  91 
  92 // emitter array phase
  93 double r[NX][NSP];
  94 double i[NX][NSP];
  95 
  96 main()
  97 {
  98    int     ix        ; // array index
  99    int     ir        ; // random part index
 100    double  gx        ; // swept ground position
 101    double  px        ; //
 102    double  x1[NX][NSP]    ; // distance component for x
 103    double  x0        ; // working distance from center
 104    double  xx        ; // distance component for x
 105    double  x2        ; // squared distance component for x
 106    double  y1        ; // distance component for y
 107    double  y2        ; // squared distance component for y
 108    double  ran       ; // accumulating random part
 109    double  xdd       ;
 110  
 111    double  sumr      ; // working sum per point
 112    double  sumi      ; // working sum per point
 113    double  mag       ; // power magnitude
 114    double  binmax    ; // maximum sum per bin
 115    double  binmin    ; // minimum sum per bin
 116    double  lbinmax   ; // log maximum sum per bin 
 117    double  lbinmin   ; // log minimum sum per bin
 118    double  frac      ; // fraction of sweep
 119    double  rp, ip    ; // downlink path phase
 120    int     nbin, npt ; // ground index
 121    
 122    double  length    ; // length of beam in wavelengths
 123    double  wavenum = 2.0 * 3.1415926535897932 / WL ; // wavenumber
 124    double  tmp       ;
 125 
 126    double  s2 = 1.0 / ( (double) (  NBINS-1                   ) ) ;
 127    double  s1 = 1.0 / ( (double) ( (NBINS-1)*( NPTS_PER_BIN ) ) ) ;
 128    double  s0 = 0.5 * ( s1 - s2 ) ;
 129    double  nx2 = 2.0 / ( NX - 1 ) ;
 130    double  sam = SAM * nx2 * nx2  ;
 131    double  am        ;
 132    double  amsum     ;
 133 
 134 // first, compute emitter array from intended ground spot
 135 
 136    ran = 0.0 ;
 137    x0  = 0.5*SX1*(1-NX%2) ;   // 0.5 if even, 0.0 if odd
 138    
 139 
 140    // find the distances
 141    for( ix=0 ; ix < NX/2 ; ix++ ) {
 142       // array position with spreading
 143       for( ir= 0 ; ir < NSP ; ir++ ) {
 144          xdd = x0 + ran * ( (double) ir ) / ( (double) (NSP-1) ) ;
 145          x1[NX/2+ix][ir]     = GX + xdd ;   
 146          x1[NX/2-(ix+1)][ir] = GX - xdd ; 
 147       }
 148       ran +=  SXF*(drand48()-0.5) ;
 149       x0  += SX1 ;
 150    }
 151 
 152    // next, find the conjugate real and imaginary parts for each array
 153 
 154    y1 = GY    ;
 155    y2 = y1*y1 ;
 156    for ( ir=0 ; ir < NSP ; ir++ ) {
 157       amsum=0.0 ;
 158       for( ix=0 ; ix < NX ; ix++ ) {
 159          x2 = x1[ix][ir]*x1[ix][ir]  ;                 // distance squared
 160          length = wavenum * sqrt( x2 + y2 );
 161          px     = ix + 0.5 * ( 1.0 - NX ) ;
 162          am     = 1.0 + sam * px * px ;
 163          amsum += am ;
 164          r[ix][ir]  =  am * cos( length ) ;  
 165          i[ix][ir]  = -am * sin( length ) ;
 166       }
 167    
 168       // normalize 
 169       for( ix=0 ; ix < NX ; ix++ ) {
 170          r[ix][ir] /= amsum ;
 171          i[ix][ir] /= amsum ;
 172       }
 173    }
 174 
 175 #ifdef DISTANCE
 176    for( ix=0 ; ix < NX/2 ; ix++ ) {
 177       printf("%12d",NX/2+ix );
 178       for( ir= 0 ; ir < NSP ; ir++ ) {
 179          printf("%8.2f", x1[NX/2+ix][ir] );
 180       }
 181       printf("\n" );
 182    }
 183 
 184    printf("\n");
 185    printf("random scale");
 186    for( ir= 0 ; ir < NSP ; ir++ ) {
 187       xdd = SXF * ( (double) ir ) / ( (double) (NSP-1) ) ;
 188       printf( "%8.3f", xdd );
 189    }
 190    printf("\n");
 191    printf("        gx     max(db)\n");
 192 #endif //DISTANCE
 193 
 194 
 195    // now, compute the traverse
 196   
 197    for( nbin = 0 ; nbin < NBINS ; nbin++ ) {
 198       frac = ((double)nbin )/(double)(NBINS-1) ;
 199       gx = GX + X0 + frac*(X1-X0);
 200       printf( "%12.2f", gx );
 201 
 202       for ( ir=0 ; ir < NSP ; ir++ ) {
 203          binmax = -1e30 ;
 204          binmin = 1e30  ;
 205          for( npt = 0 ; npt < NPTS_PER_BIN ; npt++ ) {
 206             frac = s0 + s1*npt + s2*nbin  ;
 207             gx   = GX + X0 + frac*(X1-X0) ;
 208 
 209             sumr = 0.0 ;
 210             sumi = 0.0 ;
 211 
 212             // compute the signal sum at the ground from all the antennas
 213 
 214             for( ix=0 ; ix < NX ; ix++ ) {
 215                xx = gx + x1[ix][ir] ;
 216                x2 = xx * xx ;
 217                length = wavenum * sqrt( x2 + y2 );
 218                rp = cos( length ) ;
 219                ip = sin( length ) ;
 220                sumr += rp*r[ix][ir] - ip*i[ix][ir] ;
 221                sumi += ip*r[ix][ir] + rp*i[ix][ir] ;
 222             }
 223 
 224             mag    = sumr*sumr + sumi*sumi ;
 225             if ( binmax < mag ) binmax = mag ;
 226             if ( binmin > mag ) binmin = mag ;
 227          }
 228 
 229          lbinmax = 10.0*(log(binmax)/log(10.0));
 230 
 231          printf("%8.3f", lbinmax );
 232       }
 233       printf("\n");
 234       fflush(stdout);
 235    }
 236 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-06-09 20:06:22, 6.4 KB) [[attachment:line07.c]]
  • [get | view] (2009-06-09 20:06:52, 16.5 KB) [[attachment:line07_0001.png]]
  • [get | view] (2009-06-09 20:07:07, 22.8 KB) [[attachment:line07_0016.png]]
  • [get | view] (2009-06-09 20:07:38, 17.5 KB) [[attachment:line07_0020.png]]
  • [get | view] (2009-06-09 20:07:52, 10.8 KB) [[attachment:line07_0020a.png]]
  • [get | view] (2009-06-09 20:08:13, 6.6 KB) [[attachment:line07_0020b.png]]
  • [get | view] (2009-06-09 20:08:49, 14.3 KB) [[attachment:line07_0500.png]]
  • [get | view] (2009-06-09 20:10:25, 2.0 KB) [[attachment:line07_5000.cmd]]
  • [get | view] (2009-06-09 20:09:01, 14.6 KB) [[attachment:line07_5000.png]]
  • [get | view] (2009-06-09 20:08:26, 17.4 KB) [[attachment:line08_0050.png]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.