Friday, July 28, 2017

Olde Skool Antenna Design with NEC2 on OpenBSD

The Numerical Electromagnetics Code (NEC) is a powerful and efficient program for the analysis of the electromagnetic properties of antennas and other objects. It is a Method of Moments type of successive approximation program and dates back to the time of the dinosaurs.  NEC was developed on a CDC 7700 in the mid 1970s to early 80s at Lawrence Livermore by Burke and Poggio for the US Navy and it was paid for by the friendly US tax payers - free for use by anyone now.

Dipole Antenna Example

CDC - Control Data Corporation, became Computing Devices Canada, which became General Dynamics Canada - I worked there through all the name changes - but you don't need to go hunt in a museum for a CDC 7700 to run NEC - an Intel PC will do.   The NEC documentation amusingly still refers to stacks of punch cards, but these have been replaced with simple text files.  I learned programming with punch cards on a Sperry-Univac, so the batch processing way that NEC works is not strange to me, but it does bring back some scary memories of the good old, bad old days of iron age, hollow state computing...

NEC was considered a large program, requiring a powerful mainframe to execute.  However, what used to require a big room full of computing equipment, can now be done on a laptop computer.  Just to prove the point, I installed NEC on my Lenovo S10e netbook running OpenBSD.

The original FORTRAN code is still available, but it has been rewritten a few times into C and C++, to improve the efficiency and ability to handle very large numbers of wire elements. The new versions can handle tens of thousands of elements and can be used to model a whole aircraft for example, but then you would need something with a wee bit more RAM than my netbook.

Here is another similar method of moments approach:

As usual with high tech things, there is absolutely no correlation between price and quality.  You can spend $100,000 on an antenna design program from ANSYS or others, or you can use NEC or Puma EM - for Free.

The difference is that the $100,000 package comes with training and support, whereas with NEC, you have to figure it out yourself - but figuring it out yourself over a few days, is rather less than $100,000 me thinks and even with the commercial support and training session, you still need to sit for a few days to figure it out anyway.  If you have big money burning your pocket, then spending it on RF test equipment may be a better idea.

Getting Started With NEC2 Antenna Modelling

The place to start is here:

Download the manuals, and read them:

The first manual describes how NEC works and the third manual describes how to use NEC to model an antenna.  There are many examples, from dipoles to Yagis and helixes - it is all there.  To get started, you could find a suitable example and tweak it to suit your purpose.

Download the NEC example files from the American Radio Relay League:

Download an antenna handbook or two and clue up on antennas, so that you can tell when your simulations are going wrong:

If you are broke, get this one - the author passed away before he could complete it and his legacy is a free antenna book: 

NEC on OpenBSD

If you are a very recent convert and don't have an OpenBSD laptop computer yet:

Assuming that you have a machine which is minimally working, first set up the OpenBSD ports system.  Look for a file named ports.tar.gz on the mirrors.

$ cd /tmp
$ ftp$(uname -r)/{ports.tar.gz,SHA256.sig}
$ signify -Cp /etc/signify/openbsd-$(uname -r | cut -c 1,3) -x SHA256.sig ports.tar.gz

Untar this file in the /usr directory, to create /usr/ports and all the directories under it.

# su -
# cd /usr
# tar xzf /tmp/ports.tar.gz

Look for nec2 based antenna design software:
# cd /usr/ports
# make search key="nec2"
  Port:   xnecview-1.36p0
  Port:   necpp-1.2.3p3

Build necpp:
# cd cad/necpp
# make install
... looong wait ...
# make clean

Build xnecview:
# cd cad/xnecview/
# make install
... looong wait ...
# make clean

OK, so which programs do we have now?
$ ls /usr/local/bin/*nec*
  nec2++              nec2diff            xnecview

Apparently we have nec2++ for antenna design and xnecview to plot the results.  A text editor and some RTFMing is all that is needed to create the input files.  Mousepad or even vi will do.

Helical Antenna Model

Let's look at a helical antenna model.  There is one in the file from ARRL.  The NEC manual has two parts, part 1 describes the program and part 3 describes how to use it, with exhaustive examples.  A volunteer is needed to write part 2!   A helical antenna card stack is described on page 20 of part 3 of the manual.

Helix - CocoaNEC
A helical antenna definition is extremely simple, since it is only one wire.  Nevertheless, you need to refer to page 20 of the third manual to know what exactly the Geometry Helix (GH) line means:

GH 1,60, .05,.5,.1,.1,.1,.1,.00001

$ man nec2++
$ man xnecview

Let's put the card stack in the hopper and run it to see what happens.  Watch out for the continuous paper spewing out of the high speed line printer...

$ nec2++ -iHELIX.NEC -ohelix.out

Let's view it:
$ xnecview HELIX.NEC helix.out

To make the original example useful, one has to add definitions for the EX signal source and RP antenna pattern cards.

With EX 0 1 1 0 1 and RP 0 1 360 360 1000 0 0 1 1,  I eventually got something to plot, but it didn't look pretty and an attempt to calculate an admittance matrix caused the netbook to run out of RAM and the program was terminated.

Eventually, I got the NEC syntax sorted and the plots made sense once I used a very large number of elements (500 or more).  As the elements are straight sections, if you specify too few, then the simulation of the spiral becomes complete nonsense.

CM Helix, 900 MHz, 15 loops, 1.15 meter
CM Herman Oosthuysen, July 2017
CM Wave length = 2.998x10^8 / 900MHz = 0.333 m
CM Use Kraus formula:
CM Radius = 116.2 / 2 = 58.1 mm
CM Loops = 15
CM Spacing = .23 = 76.6 mm
CM Length = 1150 mm
CM GH 1,200,.0766,1.150,.0581,.0581,.0581,.0581,.0066
CM EX element 1 has voltage source of 1V
CM EX 0,1,1,0,1,0,0,0,0,0,0
CM FR Freq response 800 to 1000 MHz, 5 points
CM FR 0,5,0,0,800,50
CM RP 72 points x 5 = 360 degrees
CM RP XNDA = 0 (max pwr gain) works best
CM RP 0,1,72,72,0,0,0,5,5,0,0
CM The simulation needs a very large number of elements, 500 or more
GH 1,500,.0766,1.150,.0581,.0581,.0581,.0581,.0066
EX 0,1,1,0,1,0,0,0,0,0,0
FR 0,5,0,0,800,50,,,,,
RP 0,1,72,72,0,0,0,5,5,0,0

Helix 900 MHz

The little netbook can calculate up to about 5 frequencies in a sweep.  For more accurate rendering, a better computer is required!

Equations from Kraus:
G= 10.8 + 10*log10(  (C/lambda)2*N*(S/lambda) )    (Note1)
Z= 150/sqrt(C/lambda) Ohm
D= lambda /PI
S= C/4
HPBW= 52/( (C/lambda)*sqrt(N*(S/lambda)) ),  Half power beamwidth.
BWFN= 115/( (C/lambda)*sqrt(N*(S/lambda)) ),  Beamwidth first nulls.
Ae= D*lambda2/(4*PI)

Where C is circumference, which is about one wavelength for axial mode.

What exactly the gain of this antenna will be, is not clear - somewhere between 7 and 15 dBi - but the simulation at least shows that it radiates in axial mode.

Log Periodic Antenna Model

Just for fun, I tried a few more example files and a log periodic design plotted beautifully.

Logperiodic Example Plots

Therefore the design software is shown to be working fine and now the real work can start, to make a new antenna from scratch.  This becomes complicated when you add all the parasitic things: Stubs, ground plane, loading...

Vertical Dipole Model

Here is something simple that I created with xnec2c on Fedora Linux.  The picture is at the top of the page.

CM 900 MHz, WL = 0.333 m, 1/4 WL = 0.083 m
CM Limitations of xnec2c visualization program RP card:
CM Cannot plot a 360 degree sweep with ground plane (need to remove GN cards)
CM The XNDA field must be 0
GW     1     9  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  8.30000E-02  1.00000E-03
FR     0     0     11     0  8.00000E+02  2.00000E+01  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00
EX     0     0     5      0  1.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00
RP     0    72    72      0  0.00000E+00  0.00000E+00  5.00000E+00  5.00000E+00  0.00000E+00  0.00000E+00



A helical antenna is the general case of a wire antenna.  If you squash it up, it becomes a loop and if your stretch it out, it becomes a long wire.

Helical antennas can radiate in two modes (and everything in between...) Normal, or Axial.  Normal mode occurs when the helix circumference is smaller than 1/2 wavelength (0.2 nominal) and Axial mode occurs when it is larger than 0.8 wavelength (1 nominal). (See John D. Kraus, The Helical Antenna, Proceedings of the IRE, 1949).

As you can see in this graph from Kraus, there is almost no right or wrong way to make a helical antenna, provided that you stay close to the two D lambda curves.  To increase the gain, use more wire and reduce the spacing.  To make it more wide band, make the loops bigger.  To match the impedance to your radio, you can either add a tuner, or bend the first loop a little bit!

Axial mode is good for a ground antenna pointing at a small aircraft just like a Yagi-Uda, but the circular polarization will ensure minimal changes in signal strength when the aircraft banks in turns.

Normal mode is good when a retired radio amateur tries to fit a 160 meter HF dipole antenna into the attic of a small cottage.  If one uses two curly cords then a dipole becomes much smaller - any size you want it to be really, so it is a guaranteed fit, whether in your roof or outside in the yard.  Wrap the dipole wire around a plastic drain pipe, stretch it out as much as you can and stick a tuner on it to match it to your radio for whatever frequency you want to work at - as easy as borscht.

Axial mode concerns me at the moment and the normal mode will eventually!

While playing with example designs from the web in order to get going with the modelling programs, I noticed that many published designs and 'antenna calculators' are quite dreadful.  I even found some Yagis that radiate more backwards than forwards, so you really should model an antenna before you build it.


Heretic geeks can buy EZNec for Windows and Linux cowboys can do dnf install nec2c xnec2c, or apt install nec2c xnec2c.  For Mac users, there is CocoaNEC.  All these programs work the same, since the underlying engine is the same, but they do have different bugs.

For example, xnec2c has trouble with the radiation pattern plot when there is a ground plane (remove the GN card) and the RP XNDA field must be 0.  Despite this, xnec2c seems to make better plots than xnecview as it handles edge cases better (where things go to zero).  CocoaNEC creates the best graphics by far, but it also struggles with a helical antenna (it won't display the helix structure, but it can display the radiation pattern) and CocoaNEC always inserts its own RP card - which ensures that it always works.

Different RP Card Handling:
  • xnec2++:     RP 0,1,72,72,1000,0,0,5,5,0,0
  • xnec2c:        RP 0,72,72,0,0,0,5,5,0,0,0
  • CocoaNEC: RP 0,91,120,1000,0,0,2,3,5000
So, you just have pick one and play with it a bit till you figured it out - they all work - eventually.

However, the fancy GUIs only implement a small subset of what NEC can do.  Therefore, to do anything special, you need to stick your nose into the manual and edit the source card stack file with a text editor, the old fashioned way.  This is not easy and fancy GUIs cannot make it so.

La voila!


No comments:

Post a Comment

On topic comments are welcome. Junk will be deleted.