Skip to main content

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. 

In theory, 
practise and theory are the same, 
but in practice not.
To measure, is to know!

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.

You can also use NEC to calculate scattering from an incident plane wave to determine the Radar Cross Section of an aircraft, as described here: https://www.aeronetworks.ca/2017/09/scattering-rcs-calculation-with-nec2.html.

Here is another similar method of moments approach for the calculation of scattering (RCS) of very large objects (Ships).  However, this program is not maintained at the moment and needs to be installed on a specific version of Ubuntu Linux: http://www.aeronetworks.ca/2015/04/rcs-calculations-puma-em-on-ubuntu-linux.html

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 NEC2 or Puma EM - for Free - or buy a LLNL NEC4 license for $300 to $1500 https://ipo.llnl.gov/technologies/nec.

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: http://www.nec2.org/

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: http://www.aeronetworks.ca/2017/02/openbsd-on-netbook.html

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 https://ftp.openbsd.org/pub/OpenBSD/$(uname -r)/{ports.tar.gz,SHA256.sig}
$ signify -Cp /etc/signify/openbsd-$(uname -r | cut -c 1,3)-base.pub -x SHA256.sig ports.tar.gz

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

# su -
password
# 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 other.zip 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:

$ cat HELIX.NEC
CE  HELIX TEST
GH 1,60, .05,.5,.1,.1,.1,.1,.00001
GE
EN

RTFM:
$ 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
CE
GH 1,500,.0766,1.150,.0581,.0581,.0581,.0581,.0066
GE
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
EN


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 VERTICAL HALF WAVELENGTH ANTENNA,
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
CE
GW     1     9  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  8.30000E-02  1.00000E-03
GE
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
EN

 

Why?

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.

Heretics

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.

Note that when NEC crashes due to a divide by zero, then moving a ground plane or other element by a fraction of a millimeter can make the problem go away!

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 to 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.

A Two Port Vector Network Analyzer

The proof of the pudding is in the eating.   At the end of the day, after you stopped playing with NEC2, you need to actually build the antenna and measure it.  Test equipment can be very expensive to a hobbyist, but you can get a 2 port VNA second hand at a reasonable price, or buy a new one from China.

The aliexpress web site lists many different VNA models from $300 to $3000, which is orders of magnitude less than a couple decades ago.  I got a Measall KC901V, and I am very happy with it and can now characterize antennas up to the C-band quickly and easily.
 

La voila!

Herman



Comments

Popular posts from this blog

Parasitic Quadrifilar Helical Antenna

This article was reprinted in OSCAR News, March 2018:  http://www.amsat-uk.org If you want to receive Satellite Weather Pictures , then you need a decent antenna, otherwise you will receive more noise than picture. For polar orbit satellites, one needs an antenna with a mushroom shaped radiation pattern .  It needs to have strong gain towards the horizon where the satellites are distant, less gain upwards where they are close and as little as possible downwards, which would be wasted and a source of noise.  Most satellites are spin stabilized and therefore the antenna also needs circular polarization, otherwise the received signal will flutter as the antennas rotate through nulls. The helical antenna, first proposed by Kraus in 1948, is the natural solution to circular polarized satellite communications.  It is a simple twisted wire - there seems to be nothing to it.  Various papers have been published on helix antennas, so the operation is pretty well understood. Therefore,

To C or not to C, That is the Question

As most would know, the Kernighan and Ritchie C Programming Language is an improved version of B, which is a simplified version of BCPL, which is derived from ALGOL, which is the Ur computer language that started the whole madness, when Adam needed an operating system for his Abacus, to count Eve's apples in the garden of Eden in Iraq.  The result is that C is my favourite, most hated computer language , which I use for everything. At university, I learned FORTRAN with punch cards on a Sperry-Univac, in order to run SPICE, to simulate an operational amplifier.  Computers rapidly lost their glamour after that era! Nobody taught me C.  I bought the book and figured it out myself. Over time, I wrote a couple of assemblers, a linker-locator, various low level debuggers and schedulers and I even fixed a bug in a C compiler - not because I wanted to, but because I had to, to get the job done!   Much of my software work was down in the weeds with DSP and radio modems ( Synchronization,

Weather Satellite Turnstile Antennas for the 2 meter Band

NEC2, 2 m band, 146 MHz, Yagi Turnstile Simulation and Build This article describes a Turnstile Antenna for the 2 meter band, 146 MHz amateur satcom, 137 MHz NOAA and Russian Meteor weather satellites.  Weather satellite reception is described here .  A quadrifilar helical antenna is described here .   Engineering, is the art of making what you need,  from what you can get. Radiation Pattern of the Three Element Yagi-Uda Antenna Once one combine and cross two Yagis, the pattern becomes distinctly twisted. The right hand polarization actually becomes visible in the radiation pattern plot, which I found really cool. Radiation Pattern of Six Element Turnstile Antenna Only a true RF Geek can appreciate the twisted invisible inner beauty of a herring bone antenna... Six Element Turnstile Antenna Essentially, it is three crosses on a stick.  The driven elements are broken in the middle at the drive points.  The other elements can go straight throug