In the previous part it has been told as to promodelirovat distribution of EMV by means of simulator

openEMS. Now we will consider as to calculate something useful. Promodeliruyem the dipolar half-wave antenna on the frequency of 500 MHz. Modeling in frequency domain and modeling of the direction characteristic (DC) of the antenna will be considered. The scheme of this antenna is shown in drawing.

The dipolar antenna consists of two beams, each of which has length of equal 1/4 waves for resonance frequency. The antenna from the center is powered. The antenna has resistance on chatota of resonance, equal about 75 Ohms and digaramma of orientation in the form of the torus. In more detail about the theory of operation of the dipolar antenna it is possible to read, for example, in Ayzenberg or Belotserkovsky's textbook. We also have to receive these results after modeling.

Under cat the script with model of the dipolar antenna with line-by-line analysis is given. It is supposed that the reader is familiar with bases of Matlab/Octave, electrical equipment and the theory of antennas (knows that such complex resistance, S-parameters and KSV).

For those who is not aware that occurs here, links to my previous articles:

The script for modeling needs to be saved at first in the text file with the *.m expansion, using your favourite test editor (for example KWrite). Then Octave need to start from command line, having transferred it as parameter script name. Let's say if our script is called as dipole.m, simulation is started so:

```
octave dipole.m
```

If we want to use viewing of diagrams from Octave in interactive mode, it is necessary to start at first Octave from command line, and then to use the source team. It will load dipole.m script from the current directory.

```
source dipole.m
```

As a result of modeling we want to receive:

- Dependence of input resistance of the antenna in powering points from frequency.
- Dependence of KSV of the antenna in powering point from frequency for 50 Ohms of source
- DN in polar coordinates
- 3D DN in spherical coordinates

Let's start line-by-line analysis of script. Documentation of openEMS suffers from spaces therefore it was necessary to finish thinking about something most.

So at the beginning of script we clear all variables:

```
close all;
clear;
clc;
```

Now it is necessary to objvit name of the XML file which contains task for modeling and the temporary directory in which results of modeling will be stored. Files with results of calculations reach 100 Mb therefore it is necessary to take care of place on disk.

```
physical_constants
SimPath = 'tmp';
SimCSX = 'tmp.xml';
```

Now we begin the description of parametrical model of the antenna. It means that at change of parameters (for example estimated resonance frequency) Matlab/Octave will automatically recalculate all sizes of the antenna. The slot pitch is selected equal 1/50 wavelengths.

```
f_max = 0.5e9; # расчётная частота резонанса
lambda = c0/f_max; # длина волны
step=lambda/50; # шаг сетки
```

As you remember from physics, the wavelength and frequency are connected through light speed

c0

We declare space of modeling (SimBox)? cube with edge equal

to the doubled wavelength (2*lambda). We fill space with grid

mesh.

```
CSX = InitCSX();
mesh.x = -lambda:step:lambda;
mesh.y = -lambda:step:lambda;
mesh.z = -lambda:step:lambda;
SimBox = [2*lambda 2*lambda 2*lambda];
CSX = DefineRectGrid(CSX,1,mesh);
```

Now we set excitation source. In last part we used sinusoidal source of fixed frequency. openEMS at first carries out calculation in time domain, and then recalculates result in frequency domain. Therefore to simulate frequency properties of system, the source with extended range is necessary. As such source in openEMS the Gaussian impulse is available.

So at first we declare variables in which we will store parameters of the Gaussian impulse. It is necessary to set the center frequency of range of the Gaussian impulse and half of width of range. We will model our antenna in frequency band from 200 MHz to 600 MHz. Therefore center frequency will be 400 MHz, and range width +-200 MHz from center frequency.

```
f0 = 400e6;
fc = 0.5*f0;
FDTD = InitFDTD('NrTS',30000);
FDTD = SetGaussExcite(FDTD,f0,fc);
```

The space of FDTD is initialized by means of the InitFDTD function () It the second parameter needs to transfer number of selections in time domain. It needs to be picked up so that it exceeded pulse width in sampling steps. Usually is 30000 enough. Otherwise we will receive error message which says that the interval of calculation is less than duration of the Gaussian impulse.

Now it is necessary to set edge conditions. We model the antenna in free space therefore it will be surrounded with absolutely absorbing MUR dielectric from all directions:

```
BC = {'MUR','MUR','MUR','MUR','MUR','MUR'};
FDTD = SetBoundaryCond(FDTD,BC);
```

Now we declare geometry. Process of the description of geometry for those who is familiar for example with HFSS looks unusually and unusually.

The dipole will consist of two carrying-out parallelepipeds between which the excitation source is connected. Thickness of beams of dipole can be less slot pitch. As the theory, the more thickness of the dipolar antenna, the wider it bandpass range speaks. All geometry at us is parametrized and will be automatically recalculated at change of parameters. Advantage of the simulator which is built in Matlab/Octave consists in it.

```
t = step/4; # толщина луча диполя (1/200 длины волны)
CSX = AddMetal(CSX,'right_beam'); # правая половинка диполя
start = [t -t -t]; # начальная точка
stop = [lambda/4 t t]; # конечная точка
CSX = AddBox(CSX,'right_beam',1,start,stop); # строим параллелепипед из металла
```

Coordinates of points in space are set in openEMS as matrix line from three components which [x y z] follow as it should be.

The AddMetal function () adds some object from metal. The created object needs to be associated with some geometrical object. The AddBox function () adds parallelepiped. Penultimate and last parameters? these are coordinates of its extreme tops. Third parameter? it is priority. Its assignment remains for me not clear. It is possible to set it always equal 1. Second parameter? parallelepiped material object name. We have to use object of 'right_beam' which we have created earlier.

Similar actions for the left beam:

```
CSX = AddMetal(CSX,'left_beam');
start = [0 -t -t];
stop = [-lambda/4 t t];
CSX = AddBox(CSX,'left_beam',1,start,stop);
```

Now it is necessary to power the antenna. For powering of the antenna the special object, the called port (Lumped Port) serves.

There is still distributed port which represents area of space from which EMV extends. The distributed port was used in the second part.

We need to use normal port. It sootvetvut to case of powering of the antenna from voltage source. The declared earlier Gaussian impulse acts as voltage source. The port represents two points in space between which clips of virtual voltage source are connected. At first we declare two of these points. They have to lie on surface of beams of dipole:

```
start = [0 0 0 ]; # сюда подключаем порт
stop = [step 0 0];
```

Now we will declare the output resistance of source:

```
R = 50;
```

Also it is possible to add actually port:

```
[CSX port] = AddLumpedPort(CSX,1,1,R,start,stop,[1 0 0],true);
```

The AddLumpedPort function () has 8 parameters. Let's consider them in more detail:

- Second parameter? priority. It is possible to put in 1
- Third parameter? sequence number of port. Can be a little

ports. - Fourth parameter? output resistance of source
- Fifth and sixth parameters? connection points of port
- Seventh parameter? direction of signal. Vector from three components,

which shows the direction of signal in format [x y z]. At us

the signal is directed along x axis.

Now it is necessary to set area in which the field radiated by the antenna will be calculated. openEMS calculates field in near field region, and then by means of the NF2FF post-processor recalculates it in the field in far field region. DN of the antenna is calculated across the field in far field region. Area in which, the field is calculated, the equal area of modeling needs to accept, surely having receded in some slot pitches from border.

```
SimBox = SimBox-step*4.0; # отступаем от границы
[CSX nf2ff] = CreateNF2FFBox(CSX,'nf2ff',-SimBox/2,SimBox/2);
```

In total! The geometry is set. It is possible to write the file of task for openEMS and to look at result in interactive prosmotrovshchik of AppCSXCAD.

```
mkdir('tmp');
SimPath = 'tmp/tmp.xml'
WriteOpenEMS(SimPath,FDTD,CSX);
CSXGeomPlot(SimPath);
```

If everything was made correctly, we will see the following picture (in gap of dipole the port is visible):

Tepr we start openEMS.

```
RunOpenEMS('tmp','tmp.xml');
```

Calculation goes long enough. After calculation are created for structure:

- port? contains information on characteristics of the antenna in

frequency domain - nf2ff? contains information on antenna DN

We need to retrieve information on the input resistance of the antenna and reflection coefficient of S11 from structure of port. For this purpose the following fields of structure will be necessary

port:

- port.uf.tot? Full tension on clips of port
- port.if.tot? The total current proceeding through port
- port.uf.inc? Voltage amplitude of incident wave
- port.uf.ref? Voltage amplitude of reflected mode

Tepr by means of the formulas known from radio engineering course, we calculate input resistance of Zin and reflection coefficient on S11 input (it can be counted in

standing wave ratio? KSV). Now KCB and S11 is possible postrot diagrams of Zvkh (active and reactive part), using standard means of Matlab/Octave This piece of code does not demand explanations.

```
freq = linspace(f0-fc,f0+fc,501); # ось частот
port = calcPort(port,'tmp',freq); # извлекаем параметры
Zin = port.uf.tot ./ port.if.tot;
S11 = port.uf.ref ./ port.uf.inc;
subplot(3,1,1);
plot(freq/1e6,real(Zin),freq/1e6,imag(Zin)); # строим графики Rвх и Xвх
legend('Re(Zin)','Im(Zin)');
subplot(3,1,2);
plot(freq/1e6,S11); # строим график S11
swr = (1+abs(S11))./(1-abs(S11)); # найдём точку минимального КСВ
[swr_min idx] = min(swr);
[Xmin idx1] = min(abs(imag(Zin))); # и точку резонанса
fr = freq(idx);
fr1 = freq(idx1);
Zr = Zin(idx);
Zr1 = Zin(idx1);
disp("Minimum SWR frequency:"); # выведем параметры антенны
disp(fr);
disp("Resonant frequency (jX=0)");
disp(fr1);
disp("Impedance at minimum SWR");
disp(Zr);
disp("Impedance at resonant frequency");
disp(Zr1);
disp("Minimum SWR:");
disp(swr_min);
subplot(3,1,3);
semilogy(freq/1e6,swr);
```

We receive the following parameters of the antenna. It is visible that the frequency of resonance has left from the estimated down. Antenna resistance in resonance of 71,2 Ohms? almost like in textbooks, the deviation is caused by dipole thickness.

```
Minimum SWR frequency:
427200000
Resonant frequency (jX=0)
431200000
Impedance at minimum SWR
68.7692 - 6.5511i
Impedance at resonant frequency
71.18555 - 0.45064i
Minimum SWR:
1.4013
```

Now we will calculate DN in polar coordinates. Last two function parameters CalcNF2FF ()? it is the range of corners within which DN is considered. The third parameter it needs to give the frequency at which DN is calculated.

We receive the following diagrams:

```
nf2ff = CalcNF2FF(nf2ff,'tmp',fr,[-180:2:180]*pi/180,[0 90]*pi/180);
figure
polarFF(nf2ff,'xaxis','theta','param',[1 2],'normalize',1);
```

DN in Cartesian coordinates:

```
figure
plotFFdB(nf2ff,'xaxis','theta','param',[1 2]);
```

```
thetaRange = (0:2:180);
phiRange=(0:2:360)-180;
nf2ff =
CalcNF2FF(nf2ff,'tmp',fr,thetaRange*pi/180,phiRange*pi/180,'Verbose',1,'Outfile'
,'3D_Pattern.h5');
figure
plotFF3D(nf2ff,'logscale',-20);
```

Space DN has torus form as in textbooks on antennas. Coefficient

gains of the antenna of 2,1 dB.

Still it is possible to create the *.vtk file that then to view it by means of Paraview:

```
E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax;
DumpFF2VTK(['tmp/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',
1e-3);
```

Here so DN looks in Paraview (it is necessary to open the file 3D_Pattern.vtk):

We promodelirovat the dipolar antenna in the range of frequencies from 200 to 600 MHz. Apparently, modeling yields results close to the theory and allows to consider influence of deviation of parameters of dipole from the ideal. At whom is near at hand HFSS can check result.

We will provide our script in the conclusion entirely:

**Hidden text**

```
close all;
clear;
clc;
physical_constants
#unit = 1e-3; # Units in mm
SimPath = 'tmp';
SimCSX = 'tmp.xml';
f_max = 0.5e9;
lambda = c0/f_max;
dipole_L = lambda/2;
step=lambda/50;
CSX = InitCSX();
mesh.x = -lambda:step:lambda;
mesh.y = -lambda:step:lambda;
mesh.z = -lambda:step:lambda;
SimBox = [2*lambda 2*lambda 2*lambda];
CSX = DefineRectGrid(CSX,1,mesh);
#f0 = f_max;
f0 = 400e6;
fc = 0.5*f0;
FDTD = InitFDTD('NrTS',30000);
FDTD = SetGaussExcite(FDTD,f0,fc);
BC = {'MUR','MUR','MUR','MUR','MUR','MUR'};
FDTD = SetBoundaryCond(FDTD,BC);
t = step/4;
CSX = AddMetal(CSX,'right_beam');
start = [t -t -t];
stop = [lambda/4 t t];
CSX = AddBox(CSX,'right_beam',1,start,stop);
CSX = AddMetal(CSX,'left_beam');
start = [0 -t -t];
stop = [-lambda/4 t t];
CSX = AddBox(CSX,'left_beam',1,start,stop);
start = [0 0 0 ];
stop = [step 0 0];
R = 50;
[CSX port] = AddLumpedPort(CSX,1,1,R,start,stop,[1 0 0],true);
SimBox = SimBox-step*4.0;
[CSX nf2ff] = CreateNF2FFBox(CSX,'nf2ff',-SimBox/2,SimBox/2);
mkdir('tmp');
SimPath = 'tmp/tmp.xml'
WriteOpenEMS(SimPath,FDTD,CSX);
CSXGeomPlot(SimPath);
RunOpenEMS('tmp','tmp.xml');
freq = linspace(f0-fc,f0+fc,501);
port = calcPort(port,'tmp',freq);
Zin = port.uf.tot ./ port.if.tot;
S11 = port.uf.ref ./ port.uf.inc;
subplot(3,1,1);
plot(freq/1e6,real(Zin),freq/1e6,imag(Zin));
legend('Re(Zin)','Im(Zin)');
subplot(3,1,2);
plot(freq/1e6,S11);
legend('S11');
swr = (1+abs(S11))./(1-abs(S11));
[swr_min idx] = min(swr);
[Xmin idx1] = min(abs(imag(Zin)));
fr = freq(idx);
fr1 = freq(idx1);
Zr = Zin(idx);
Zr1 = Zin(idx1);
disp("Minimum SWR frequency:");
disp(fr);
disp("Resonant frequency (jX=0)");
disp(fr1);
disp("Impedance at minimum SWR");
disp(Zr);
disp("Impedance at resonant frequency");
disp(Zr1);
disp("Minimum SWR:");
disp(swr_min);
subplot(3,1,3);
semilogy(freq/1e6,swr);
legend('SWR');
nf2ff = CalcNF2FF(nf2ff,'tmp',fr,[-180:2:180]*pi/180,[0 90]*pi/180);
figure
polarFF(nf2ff,'xaxis','theta','param',[1 2],'normalize',1);
figure
plotFFdB(nf2ff,'xaxis','theta','param',[1 2]);
thetaRange = (0:2:180);
phiRange=(0:2:360)-180;
nf2ff =
CalcNF2FF(nf2ff,'tmp',fr,thetaRange*pi/180,phiRange*pi/180,'Verbose',1,'Outfile'
,'3D_Pattern.h5');
figure
plotFF3D(nf2ff,'logscale',-20);
E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax;
DumpFF2VTK(['tmp/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',
1e-3);
pause;
```

Perhaps, continuation follows?

This article is a translation of the original post at habrahabr.ru/post/259383/

If you have any questions regarding the material covered in the article above, please, contact the original author of the post.

If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.

Shared knowledge makes the world better.

Best wishes.