Post-Processing
calcPort
- calcPort(port, SimDir, f, varargin)
Full definition:
[port] = calcPort( port, SimDir, f, varargin)
Calculate:
voltages and currents
the propagation constant and the characteristic impedance (if applicable)
The port has to be created by e.g. AddMSLPort(), AddLumpedPort() or AddCurvePort
input:
port: return value of AddMSLPort()
SimDir: directory, where the simulation files are
f: frequency vector for DFT
variable input:
‘RefImpedance’: use a given reference impedance to calculate inc and ref voltages and currents default is given port or calculated line impedance
‘RefPlaneShift’: for transmission lines only, See also calcTLPort for more details
‘SwitchDirection’: 0/1, switch assumed direction of propagation
‘SignalType’: ‘pulse’ (default) or ‘periodic’
output:
output signals/values in time domain (TD):
port.ut.tot: total voltage (time-domain)
port.ut.time: voltage time vector
port.it.tot: total current (time-domain)
port.it.time: current time vector
output signals/values in frequency domain (FD):
port.f: the given frequency fector
port.uf.tot/inc/ref: total, incoming and reflected voltage
port.if.tot/inc/ref: total, incoming and reflected current
port.ZL_ref: used reference impedance
port.P_inc: incoming power
port.P_ref: reflected power
port.P_acc: accepted power (incoming minus reflected, may be negative for passive ports)
if port is a transmission line port:
port.beta: propagation constant
port.ZL: characteristic line impedance
example:
port = calcPort(port, Sim_Path, f, 'RefImpedance', 50);
(C) 2012 Thorsten Liebig thorsten.liebig@gmx.de
See also AddMSLPort, AddLumpedPort, AddCurvePort, calcTLPort, calcLumpedPort
calcLumpedPort
- calcLumpedPort(port, SimDir, f, varargin)
Full definition:
[port] = calcLumpedPort( port, SimDir, f, varargin)
Calculate voltages and currents of given lumped port.
The port has to be created by e.g. AddLumpedPort().
input:
port: return value of e.g. AddMSLPort()
SimDir: directory, where the simulation files are
f: frequency vector for DFT
variable input:
‘RefImpedance’: use a given reference impedance to calculate inc and ref voltages and currents default is given port or calculated line impedance
‘SwitchDirection’: 0/1, switch assumed direction of propagation
output:
output signals/values in time domain (TD):
port.ut.tot: total voltage (time-domain)
port.ut.time: voltage time vector
port.it.tot: total current (time-domain)
port.it.time: current time vector
output signals/values in frequency domain (FD):
port.f: the given frequency factor
port.uf.tot/inc/ref: total, incoming and reflected voltage
port.if.tot/inc/ref: total, incoming and reflected current
example:
port{1} = calcLumpedPort( port{1}, Sim_Path, f, 'RefImpedance', 50);
(C) 2012 Thorsten Liebig thorsten.liebig@gmx.de
See also AddLumpedPort, calcPort
calcTLPort
- calcTLPort(port, SimDir, f, varargin)
Full definition:
[port] = calcTLPort( port, SimDir, f, varargin)
Calculate voltages and currents, the propagation constant beta and the characteristic impedance ZL of the given transmission line port.
The port has to be created by e.g. AddMSLPort().
input:
port: return value of e.g. AddMSLPort()
SimDir: directory, where the simulation files are
f: frequency vector for DFT
variable input:
‘RefImpedance’: - use a given reference impedance to calculate inc and ref voltages and currents - default is given port or calculated line impedance
‘RefPlaneShift’: - use a given reference plane shift from port beginning for a desired phase correction - default is the measurement plane - the plane shift has to be given in drawing units!
‘SwitchDirection’: 0/1, switch assumed direction of propagation
output:
output signals/values in time domain (TD):
port.ut.tot total voltage (time-domain)
port.ut.time voltage time vector
port.it.tot total current (time-domain)
port.it.time current time vector
output signals/values in frequency domain (FD):
port.f the given frequency fector
port.uf.tot/inc/ref total, incoming and reflected voltage
port.if.tot/inc/ref total, incoming and reflected current
port.beta: propagation constant
port.ZL: characteristic line impedance
port.ZL_ref used reference impedance
example:
port{1} = calcTLPort( port{1}, Sim_Path, f, 'RefImpedance', 50);
reference:
= W. K. Gwarek, “A Differential Method of Reflection Coefficient Extraction From FDTD Simulations”, IEEE Microwave and Guided Wave Letters, Vol. 6, No. 5, May 1996
(C) 2010 Sebastian Held sebastian.held@uni-due.de
See also AddMSLPort, calcPort
calcWGPort
- calcWGPort(port, SimDir, f, varargin)
Full definition:
[port] = calcWGPort( port, SimDir, f, varargin)
Calculate voltages and currents, the propagation constant beta and the characteristic impedance ZL of the given waveguide port.
The port has to be created by e.g. AddWaveGuidePort().
input:
port: return value of e.g. AddWaveGuidePort()
SimDir: directory, where the simulation files are
f: frequency vector for DFT
variable input:
‘RefImpedance’: use a given reference impedance to calculate inc and ref voltages and currents default is given port or calculated line impedance
‘RefPlaneShift’: use a given reference plane shift from port beginning for a desired phase correction default is the measurement plane at the end of the port the plane shift has to be given in drawing units!
‘RefractiveIndex’: set a material refractive index
‘SwitchDirection’: 0/1, switch assumed direction of propagation
output:
output signals/values in time domain (TD):
port.ut.tot: total voltage (time-domain)
port.ut.time: voltage time vector
port.it.tot: total current (time-domain)
port.it.time: current time vector
output signals/values in frequency domain (FD):
port.f: the given frequency fector
port.uf.tot/inc/ref: total, incoming and reflected voltage
port.if.tot/inc/ref: total, incoming and reflected current
port.beta: propagation constant
port.ZL: characteristic line impedance
port.ZL_ref: used reference impedance
example:
port{1} = calcWGPort( port{1}, Sim_Path, f, 'RefImpedance', 50);
(C) 2013 Thorsten Liebig (thorsten.liebig@gmx.de)
See also AddWaveGuidePort, calcPort
calc_ypar
- calc_ypar(f, ports, Sim_Path_Prefix)
Full definition:
Y = calc_ypar( f, ports, Sim_Path_Prefix )
f: frequency vector (Hz)
ports: cell array of ports (see AddMSLPort() and AddLumpedPort())
Sim_Path_Prefix: prefix of the simulation dirs (will be postfixed by excitation port number)
This function calculates the Y-matrix representation of the ports
It is assumed that each port (inside ports) is excited and the corresponding simulation was carried out at Sim_Path + portnr (e.g. for port 2: ‘/tmp/sim2’)
Sebastian Held sebastian.held@uni-due.de Jun 9 2010
See also AddMSLPort AddLumpedPort
ReadUI
- ReadUI(files, path, freq, varargin)
Full definition:
function UI = ReadUI(files, path, freq, varargin)
read current and voltages from multiple files found in path
returns voltages/currents in time and frequency-domain
remarks on the frequency-domain:
all signals are assumed to start at t=0
currents that e.g. start at t = +delta_t/2 will be phase shifted by exp(-jwt(1))
optional parameter:
freq: frequency-domain values will be calculated according to ‘freq’ if ‘freq’ is not given, a (zero padded) FFT will be used
optional key,value pairs:
‘AR’ : auto-regressive model to improve FD accuracy values: order to use within an AR model or ‘auto’
examples:
U = ReadUI({'ut1_1','ut1_2'},'tmp' );
I = ReadUI('it1' ,'tmp',[0.5e9 1e9 1.5e9]);
% using the auto-regressive model
U = ReadUI('port_ut1' , 'tmp', 'AR', 'auto');
author: Thorsten Liebig
See also DFT_time2freq, AR_estimate
DFT_time2freq
- DFT_time2freq(t, val, freq, signal_type)
Full definition:
f_val = DFT_time2freq( t, val, freq, signal_type )
computes the DFT at the given frequencies
parameter:
t : time vector
val: data vector
freq: DFT frequency vector
signal_type: ‘pulse’ (default), ‘periodic’
return values:
f_val: single-sided spectrum
example:
t=linspace(0,1,100);
t_val=0.9*sin(2*pi*3*t); % sine wave; amplitude 0.9; frequency 3 Hz
f=linspace(1,5,101);
f_val=DFT_time2freq( t, t_val, f, 'periodic' );
interp1(f,abs(f_val),3)
% ans = 0.8910
plot( t, t_val )
plot( f, abs(f_val) )
FFT_time2freq
- FFT_time2freq(t, val)
Full definition:
[f,val] = FFT_time2freq( t, val )
Note: This function can only be used for pulse signals
See also DFT_time2freq
AR_estimate
- AR_estimate(t, val, freq, < nu, mu, expand_factor >)
Full definition:
[val_ar t_ar f_val_ar EC] = AR_estimate( t, val, freq, < nu, mu, expand_factor >)
apply autoregressive signal model to improve dft results
t : time vector
val : time domain values
freq : frequency vector for dft
optional
nu : AR order (default 40)
mu : number of timesteps to train the model (default 3*nu)
expand_factor : increase signal length by this factor (default 5)
return values:
val_ar: AR estimated time signal
t_ar: time vector
f_val_ar: FD transformed AR estimated signal
EC: error code 0 –> no error 1 –> input error: t and val mismatch 2 –> input error: mu has to be larger than 2*nu 3 –> input error: expand_factor has to be larger than 1 10 –> AR error: signal is to short for AR estimate –> decrease AR order 11 –> AR error: estimated signal appears to be unstable –> use a different mu
Author: Thorsten Liebig, 2011
See also ReadUI, DFT_time2freq
harminv
- harminv(timeseries, timestep, start_freq, stop_freq)
Full definition:
[f,decay,Q,amp,phase,err]=harminv( timeseries, timestep, start_freq, stop_freq )
reconstruct time signal with:
real(amp(n) * exp(-1i*(2*pi*freq(n)*t-phase(n))-decay(n)*t)));
example:
t = linspace(0,(1/0.3e9)*5,1000);
u = 0.8 * sin(2*pi*0.7e9 * t + 0/180*pi);
u = u + 0.3 * sin(2*pi*0.3e9 * t + 0/180*pi);
[freq,decay,Q,amp,phase,err]=harminv( u, t(2)-t(1), 0, 1e9 );
Sebastian Held sebastian.held@gmx.de
DelayFidelity
- DelayFidelity(nf2ff, port, path, weight_theta, weight_phi, theta, phi, f_lo, f_hi, varargin)
Full definition:
[delay, fidelity] = DelayFidelity(nf2ff, port, path, weight_theta, weight_phi, theta, phi, f_lo, f_hi, varargin)
This function calculates the time delay from the source port to the phase center of the antenna and the fidelity. The fidelity is the similarity between the excitation pulse and the radiated pulse (normalized scalar product). The resolution of the delay will be equal to or better than ((f_0 + f_c)*Oversampling)^-1 when using Gaussian excitation. Oversampling is an input parameter to InitFDTD. The rows of delay and fidelity correspond to theta and the columns to phi.
input:
nf2ff: return value of CreateNF2FFBox.
port: return value of AddLumpedPort
path: path of the simulation results.
weight_theta: weight of the E_theta component
weight_phi: weight of the E_phi component -> with both (possibly complex) parameters any polarization can be examined
theta: theta values to be simulated
phi: phi values to be simulated
f_0: center frequency of SetGaussExcite
f_c: cutoff frequency of SetGaussExcite
variable input:
‘Center’: phase center of the antenna for CalcNF2FF
‘Radius’: radius for CalcNF2FF
‘Mode’: mode CalcNF2FF
example:
theta = [-180:10:180] * pi / 180;
phi = [0, 90] * pi / 180;
% use circular right handed polarization
[delay, fidelity] = DelayFidelity2(nf2ff, port, Sim_Path, -1i, 1, theta, phi, f_0, f_c, 'Mode', 1);
figure
polar(theta.', delay(:,1) * 3e11); % delay in mm
figure
polar(theta', (fidelity(:,1)-0.95)/0.05); % last 5 percent of fidelity
Author: Georg Michel
CalcSAR
- CalcSAR(sar_fn, sar_out, varargin)
Full definition:
function CalcSAR(sar_fn, sar_out, varargin)
Calculate the SAR (specific absorption rate)
Note: No averaging method like IEEE_62704 are (yet) validated according to the IEC/IEEE-62704-1!
parameter:
sar_fn: hdf5 file with SAR raw data as created by a dump box
sar_out: hdf5 output file with SAR results
optional parameter:
‘mass’: averaging mass in g (default is no averaging)
‘method’: IEEE_C95_3, IEEE_62704 or SIMPLE (default) All three are real cubical mass averaging methods and differ only in how strictly an averaging cube has to be valid; SIMPLE accepts any cube reaching the target mass, the IEEE methods reject cubes at a boundary and fill those cells in from a neighbour. Has no effect if ‘mass’ is 0, i.e. local SAR without any averaging.
‘autoRange’: limit the calculation to the cells within N dB of the peak local SAR, plus a padding of about one averaging cube. The result is returned on this reduced mesh. This is a speedup and not a guarantee to find the global peak, do not use it for standard compliance work.
‘numThreads’: number of worker threads (default: all available)
‘progress’: show progress output
‘verbose’: verbose output
See also: AddDump
author: Thorsten Liebig, 2025
plotRefl
- plotRefl(port, varargin)
Full definition:
h = plotRefl(port,varargin)
plot the reflection coefficient of a port into a Smith chart. left and right facing triangles mark the lower and upper cutoff frequency of the pass bands. An asterisk marks the frequnecy with the lowest reflection.
input:
port: port data structure. Call calcPort with an appropriate frequency vector before calling this routine
output: graphics handle for further modification of the plot.
variable input:
‘precision’: number of decimal places (floating point precision) for the frequency (always in MHz), default is 0
‘threshold’: Threshold value (in dB) for the upper and lower cutoff frequency, default is -3
‘fmarkers’: set lower and upper frequency marker in Hz manually, like so: [4e9, 6.5e9]
example:
myport = calcPort(myport, Sim_Path, linspace(f_0-f_c, f_0+f_c, 200));
plotRefl(myport, 'fmarkers', [4e9, 6.5e9]);
See also calcPort
author: Georg Michel
plotFF3D
- plotFF3D(nf2ff, varargin)
Full definition:
h = plotFF3D(nf2ff,varargin)
plot normalized 3D far field pattern
input:
nf2ff: output of CalcNF2FF
variable input:
‘freq_index’: use the given frequency index, see nf2ff.freq default is 1
‘logscale’: if set, show far field with logarithmic scale set the dB value for point of origin values below will be clamped
‘normalize’: true/false, normalize linear plot default is false, log-plot is always normalized!
example:
plotFF3D(nf2ff, 'freq_index', 2, 'logscale', -20)
see examples/antennas/infDipol.m
See also CalcNF2FF, plotFFdB, polarFF
author: Thorsten Liebig, Stefan Mahr
plotFFdB
- plotFFdB(nf2ff, varargin)
Full definition:
h = plotFFdB(nf2ff,varargin)
plot far field pattern in dBi
input:
nf2ff: output of CalcNF2FF
variable input:
‘freq_index’: use the given frequency index, see nf2ff.freq default is 1
‘xaxis’: ‘phi’ (default) or ‘theta’
‘param’: array positions of parametric plot if xaxis=’phi’, theta is parameter, and vice versa default is 1
example:
plotFFdB(nf2ff, 'freq_index', 2, ...
'xaxis', 'phi', 'param', [1 46 91])
see examples/NF2FF/infDipol.m
See also CalcNF2FF, plotFF3D, polarFF
author: Thorsten Liebig, Stefan Mahr
polarFF
- polarFF(nf2ff, varargin)
Full definition:
h = polarFF(nf2ff,varargin)
plot polar far field pattern
input:
nf2ff: output of CalcNF2FF
variable input:
‘freq_index’: use the given frequency index, see nf2ff.freq default is 1
‘xaxis’: ‘phi’ (default) or ‘theta’
‘param’: array positions of parametric plot if xaxis=’phi’, theta is parameter, and vice versa default is 1
‘normalize’: true/false, normalize linear plot default is false, log-plot is always normalized!
‘logscale’: if set, plot logarithmic polar set the dB value for point of origin if scalar set point of origin and maximum if 2-element array values below minimum will be clamped default is -20
‘xtics’: set the number of tics for polar grid default is 5
example:
polarFF(nf2ff, 'freq_index', 2, ...
'xaxis', 'phi', 'param', [1 46 91] );
polarFF(..., 'normalize', true );
polarFF(..., 'logscale', -30 );
polarFF(..., 'logscale', [-30 10]);
polarFF(..., 'xtics', 10);
see examples/antenna/infDipol.m
See also CalcNF2FF, plotFFdB, plotFF3D
author: Thorsten Liebig, Stefan Mahr
ReadHDF5Attribute
- ReadHDF5Attribute(file, groupname, attr_name)
Full definition:
attr = ReadHDF5Attribute(file, groupname, attr_name)
internal function for openEMS to read hdf5 attributes
See also: ReadHDF5ComplexData
author: Thorsten Liebig, 2012
ReadHDF5Dump
- ReadHDF5Dump(file, varargin)
Full definition:
[field mesh] = ReadHDF5Dump(file, varargin)
Read a hdf5 field dump, including an interpolation and frequency domain transformation.
For more information about the output, refer to the help of ReadHDF5Mesh and ReadHDF5FieldData
possible arguments:
‘Range’ see GetField_Range
‘Interpolation’ see GetField_Interpolation
‘SubSampling’ see GetField_SubSampling
‘Frequency’ see GetField_TD2FD
‘CloseAlpha’: 0 (default) / 1
example:
[field mesh] = ReadHDF5Dump('Et.h5');
%or
[field mesh] = ReadHDF5Dump('Et.h5','Range',{[0 100],[-20 20],[50 90]});
%or
[field mesh] = ReadHDF5Dump('Et.h5','Interpolation',[21 1 101],'Frequency',300e6);
author: Thorsten Liebig
See also ReadHDF5Mesh ReadHDF5FieldData GetField_Interpolation GetField_SubSampling GetField_TD2FD GetField_Range
ReadHDF5FieldData
- ReadHDF5FieldData(file)
Full definition:
function hdf_fielddata = ReadHDF5FieldData(file)
returns:
time domain data (if exist)
hdf_fielddata.TD.time
hdf_fielddata.TD.names
hdf_fielddata.TD.values
hdf_fielddata.TD.DataType (0 –> real value data)
frequency domain data (if exist)
hdf_fielddata.FD.frequency
hdf_fielddata.FD.values
hdf_fielddata.FD.DataType (0 / 1 –> real / complex value data)
example: values of timestep 12:
hdf_fielddata.TD.values{12}: array (x,y,z,polarization)
plot z-field component along y-direction for timestep 12:
plot( hdf_fielddata.TD.values{12}(1,:,1,3) )
author: Thorsten Liebig
See also ReadHDF5Mesh ReadHDF5Dump
ReadHDF5Mesh
- ReadHDF5Mesh(file)
Full definition:
function hdf_mesh = ReadHDF5Mesh(file)
Get the raw mesh data stored in the hdf5 dump file created by openEMS
returns:
hdf_mesh.type (0-> Cartesian, 1-> cylindrical mesh type)
hdf_mesh.names (e.g. ‘Mesh/y’)
hdf_mesh.lines (e.g. [0,1,2,3,4])
author: Thorsten Liebig
See also ReadHDF5FieldData
WriteHDF5
- WriteHDF5(filename, hdf_fielddata, hdf_mesh)
Full definition:
function WriteHDF5(filename,hdf_fielddata,hdf_mesh)
input:
hdf_fielddata.time
hdf_fielddata.names
hdf_fielddata.values
hdf_mesh.type
hdf_mesh.names
hdf_mesh.lines
(C) 2010 Sebastian Held sebastian.held@uni-due.de See also ReadHDF5FieldData ReadHDF5Mesh
PlotHDF5FieldData
- PlotHDF5FieldData(file, PlotArgs)
Full definition:
function PlotHDF5FieldData(file, PlotArgs)
e.g.
PlotArgs.slice = {0 [10 20] 0};
PlotArgs.pauseTime=0.01;
PlotArgs.component=2;
PlotArgs.Limit = 'auto';
PlotHDF5FieldData('tmp/Et.h5',PlotArgs)
author: Thorsten Liebig
GetField_Interpolation
- GetField_Interpolation(field, mesh, lines, varargin)
Full definition:
[field_i mesh_i] = GetField_Interpolation(field, mesh, lines, varargin)
Get an interpolated field, e.g. read by ReadHDF5Dump
homogeneous interpolation given by a 3x1 vector: e.g. [21,1,101]
arbitrary interpolation on a given mesh, e.g.: mesh_interp{1} = linspace(0, 1,101) * 1e-3; mesh_interp{2} = linspace(0,0.5, 51) * 1e-3; mesh_interp{3} = linspace(0,0.2, 21) * 1e-3;
example:
[field mesh] = ReadHDF5Dump('Et.h5');
%interpolate on a mesh with 21x21x101 lines
[field_i mesh_i] = GetField_Interpolation(field, mesh, [21 21 101]);
or
[field_i mesh_i] = GetField_Interpolation(field, mesh, mesh_interp);
%or both steps in one with the same result:
[field_i mesh_i] = ReadHDF5Dump('Et.h5','Interpolation', [21 21 101]);
author: Thorsten Liebig
See also ReadHDF5Dump ReadHDF5FieldData ReadHDF5Mesh
GetField_Range
- GetField_Range(field, mesh, range)
Full definition:
[field_i mesh_i] = GetField_Range(field, mesh, range)
Get a field dump subset within a given mesh range
example:
% specify a mesh range
range{1} = [0 150] * 1e-3; % x in range 0..150mm
range{2} = [0]; % only one line close to y==0
range{3} = []; % no range restriction
% read hdf data
[field mesh] = ReadHDF5Dump('Et.h5');
% extract a ranged subset
[field_i mesh_i] = GetField_Range(field, mesh, range);
%or both steps in one with the same result:
[field_i mesh_i] = ReadHDF5Dump('Et.h5','Range', range);
author: Thorsten Liebig
See also ReadHDF5Dump ReadHDF5FieldData ReadHDF5Mesh
GetField_SubSampling
- GetField_SubSampling(field, mesh, subsampling, varargin)
Full definition:
[field_i mesh_i] = GetField_SubSampling(field, mesh, subsampling, varargin)
Get a sub-sampled field, e.g. read by ReadHDF5Dump
sub-sampling e.g. skipping every second line in x/r direction: [2 1 1]
author: Thorsten Liebig
See also ReadHDF5Dump ReadHDF5FieldData ReadHDF5Mesh
GetField_TD2FD
- GetField_TD2FD(field, freq)
Full definition:
function field = GetField_TD2FD(field, freq)
Transforms time-domain field data into the frequency domain Auto-corrects the half-timestep offset of the H-field
example:
freq = linspace(0,1e9,100); %target frequency vector (Hz)
field = ReadHDF5FieldData('tmp/Ht.h5');
field_FD = GetField_TD2FD(field, freq);
author: Thorsten Liebig
See also ReadHDF5FieldData
ConvertHDF5_VTK
- ConvertHDF5_VTK(hdf_file, vtk_prefix, varargin)
Full definition:
ConvertHDF5_VTK(hdf_file, vtk_prefix, varargin)
Convert openEMS field data stored in the given hdf5 file to a vtk file.
arguments:
hdf_file: source hdf5 file
vtk_prefix: output vtk files prefix
optional arguments:
‘TD_Dump’: activate dump for time-domain data (default is off)
‘FD_Dump’: activate dump for frequency-domain data (default is on)
‘NumPhase’: number of phase to dump frequency domain data animation (default is 36 –> 10°)
‘FieldName’: field name written to vtk, e.g. ‘E-Field’
‘weight’: field weighting
for more optional augments have a look at ReadHDF5Dump
example:
% read time-domian data from hdf5, perform dft and dump as vtk
ConvertHDF5_VTK('Et.h5','Ef','NumPhase',18,'Frequency',1e9)
author: Thorsten Liebig
See also ReadHDF5Dump Dump2VTK