-
Notifications
You must be signed in to change notification settings - Fork 5
/
unit_cell_definition.m
451 lines (367 loc) · 17.4 KB
/
unit_cell_definition.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
close all
clear
clc
%% switches & options...
postprocessing_only = 0;
use_pml = 0; % use pml boundaries instead of mur
cal=1; % if cal=0 only the structure is depicted. If cal=1 the calculation is done.
active=1; % if active=1 the port of the first S-SRR is active and the other passive. If active=2 the port of the second is active and the one of the first passive
%% setup the simulation
physical_constants;
unit = 1e-3; % all length in mm
%% USER-DEFINED VARIABLES %%
f0 = 8e9; % center frequency of Gaussian excitation
fc = 2e9; % 20 dB corner frequency. Bandwidth of Gaussian excitation
%% dimensions of S-SRRs %%
L1=10.9; % length of the outer ring
L2=10.36; % width of the outer ring
G1=1.05; % width of the outer gap
width_outer=1.05; % width outer patch
width_iner=width_outer;
G3=1.05; %distance between iner and outer
G2=G1; % width of inner gap
srr_thickness=0.15;
%% properties of substrate %%
substrate.epsR = 2.2; % electric permittivity
tand = 0.024; % tangent loss
substrate_srr.kappa = tand*2*pi*f0*EPS0*substrate.epsR;
feed.R = 50; % feed resistance
%% dimensions of substrate %%
dx=1.85;
dz=1.85+L2-L1;
substrate_srr.width = L2+dx;
substrate_srr.length =L1+dz;
substrate_srr.thickness = 4.8;
%% S-SRRs positions and distance between them %%
ssrr_x=0;
ssrr_y=5;
ssrr_z=0;
ssrr2_x=0;
ssrr2_y=-5;
ssrr2_z=0;
%% END OF USER-DEFINED VARIABLES %%
%% setup FDTD parameter & excitation function
max_timesteps = 150000;
min_decrement = 1e-5; % equivalent to -50 dB
FDTD = InitFDTD( 'NrTS', max_timesteps, 'EndCriteria', min_decrement );
FDTD = SetGaussExcite( FDTD, f0, fc );
BC = {'MUR' 'MUR' 'MUR' 'MUR' 'MUR' 'MUR'}; % boundary conditions
if (use_pml>0)
BC = {'PML_8' 'PML_8' 'PML_8' 'PML_8' 'PML_8' 'PML_8'}; % use pml instead of mur
end
FDTD = SetBoundaryCond( FDTD, BC );
%% setup CSXCAD geometry & mesh
% set the resolution for the finer structures, e.g. the S-SRR's gap
max_res = c0 / (f0 + fc) / sqrt(substrate.epsR) / unit /40; % cell size: lambda/40
% set the resolution for the coarser structures, e.g. the surrounding air
coarseResolution = c0/(f0 + fc) / unit / 20; % cell size: lambda/20
substrate_srr.cells = 4;
CSX = InitCSX();
%% prepare simulation folder
Sim_Path = 'tmp';
Sim_CSX = 'unit_cell_definition.xml';
if (postprocessing_only==0)
[status, message, messageid] = rmdir( Sim_Path, 's' ); % clear previous directory
[status, message, messageid] = mkdir( Sim_Path ); % create empty simulation folder
end
%% DESIGN OF STRUCTURE %%
%% S-SRR1 %%
%% create substrate
CSX = AddMaterial(CSX,'substrate_srr');
CSX = SetMaterialProperty(CSX,'substrate_srr','Epsilon',substrate.epsR,'Kappa',substrate_srr.kappa);
start = [-substrate_srr.length/2+ssrr_x, ssrr_y,-substrate_srr.width/2+ssrr_z];
stop = [ substrate_srr.length/2+ssrr_x, substrate_srr.thickness+ssrr_y,substrate_srr.width/2+ssrr_z];
CSX = AddBox(CSX,'substrate_srr',1,start,stop);
%% create groundplane
CSX = AddMetal(CSX,'groundplane'); %create a PEC
start = [ -substrate_srr.length/2+ssrr_x,ssrr_y+substrate_srr.thickness,-substrate_srr.width/2+ssrr_z];
stop = [substrate_srr.length/2+ssrr_x, ssrr_y+substrate_srr.thickness, substrate_srr.width/2+ssrr_z];
CSX = AddBox(CSX,'groundplane',10,start,stop);
%% outer ring
CSX = AddMetal( CSX, 'SRR');
start = [L2/2+ssrr_x, ssrr_y+srr_thickness/2,-L1/2+ssrr_z+width_outer];
stop = [L2/2-width_outer+ssrr_x, ssrr_y-srr_thickness/2,L1/2+ssrr_z-width_outer];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2+G1/2-width_outer/2+ssrr_x, ssrr_y+srr_thickness/2, -L1/2+ssrr_z];
stop = [G1/2+ssrr_x, ssrr_y-srr_thickness/2,-L1/2+width_outer+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2-G1/2+width_outer/2+ssrr_x, ssrr_y+srr_thickness/2, -L1/2+ssrr_z];
stop = [-G1/2+ssrr_x, ssrr_y-srr_thickness/2,-L1/2+width_outer+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+ssrr_x, ssrr_y+srr_thickness/2, L1/2+ssrr_z];
stop = [ L2/2+ssrr_x, ssrr_y-srr_thickness/2,L1/2-width_outer+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+ssrr_x, ssrr_y+srr_thickness/2,-L1/2+ssrr_z+width_outer];
stop = [-L2/2+width_outer+ssrr_x, ssrr_y-srr_thickness/2,L1/2+ssrr_z-width_outer];
CSX = AddBox(CSX,'SRR',10,start,stop);
%%iner ring
start = [ L2/2-width_iner-G3-width_iner+ssrr_x, ssrr_y+srr_thickness/2, -L1/2+width_iner+G3+ssrr_z];
stop = [-L2/2+width_iner+G3+width_iner+ssrr_x, ssrr_y-srr_thickness/2,-L1/2+width_iner+G3+width_iner+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-G2/2+ssrr_x, ssrr_y+srr_thickness/2,L1/2-width_iner-G3+ssrr_z];
stop = [ -L2/2+width_iner+width_iner+G3+ssrr_x, ssrr_y-srr_thickness/2,L1/2-width_iner-G3-width_iner+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [G2/2+ssrr_x, ssrr_y+srr_thickness/2,L1/2-width_iner-G3+ssrr_z];
stop = [ L2/2-width_iner-G3-width_iner+ssrr_x, ssrr_y-srr_thickness/2,L1/2-width_iner-G3-width_iner+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+width_iner+G3+ssrr_x, ssrr_y+srr_thickness/2,-L1/2+width_iner+G3+ssrr_z];
stop = [-L2/2+width_iner+G3+width_iner+ssrr_x, ssrr_y-srr_thickness/2,L1/2-width_iner-G3+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2-width_iner-G3+ssrr_x, ssrr_y+srr_thickness/2,-L1/2+width_iner+G3+ssrr_z];
stop = [L2/2-width_iner-G3-width_iner+ssrr_x, ssrr_y-srr_thickness/2,L1/2-width_iner-G3+ssrr_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
%% S-SRR2 %%
%% create substrate
CSX = SetMaterialProperty(CSX,'substrate_srr','Epsilon',substrate.epsR,'Kappa',substrate_srr.kappa);
start = [-substrate_srr.length/2+ssrr2_x, ssrr2_y,-substrate_srr.width/2+ssrr2_z];
stop = [ substrate_srr.length/2+ssrr2_x, substrate_srr.thickness+ssrr2_y,substrate_srr.width/2+ssrr2_z];
CSX = AddBox(CSX,'substrate_srr',1,start,stop);
%% create groundplane
CSX = AddMetal(CSX,'groundplane'); %create a PEC
start = [ -substrate_srr.length/2+ssrr2_x,ssrr2_y,-substrate_srr.width/2+ssrr2_z];
stop = [substrate_srr.length/2+ssrr2_x, ssrr2_y, substrate_srr.width/2+ssrr2_z];
CSX = AddBox(CSX,'groundplane',10,start,stop);
%% outer ring
CSX = AddMetal( CSX, 'SRR');
start = [L2/2+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+ssrr2_z+width_outer];
stop = [L2/2-width_outer+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,L1/2+ssrr2_z-width_outer];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2+G1/2-width_outer/2+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness, -L1/2+ssrr2_z];
stop = [G1/2+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,-L1/2+width_outer+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2-G1/2+width_outer/2+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness, -L1/2+ssrr2_z];
stop = [-G1/2+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,-L1/2+width_outer+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness, L1/2+ssrr2_z];
stop = [ L2/2+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_outer+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+ssrr2_z+width_outer];
stop = [-L2/2+width_outer+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,L1/2+ssrr2_z-width_outer];
CSX = AddBox(CSX,'SRR',10,start,stop);
%%iner ring
start = [ L2/2-width_iner-G3-width_iner+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness, -L1/2+width_iner+G3+ssrr2_z];
stop = [-L2/2+width_iner+G3+width_iner+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,-L1/2+width_iner+G3+width_iner+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-G2/2+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+ssrr2_z];
stop = [ -L2/2+width_iner+width_iner+G3+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3-width_iner+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [G2/2+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+ssrr2_z];
stop = [ L2/2-width_iner-G3-width_iner+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3-width_iner+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+width_iner+G3+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+width_iner+G3+ssrr2_z];
stop = [-L2/2+width_iner+G3+width_iner+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2-width_iner-G3+ssrr2_x, ssrr2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+width_iner+G3+ssrr2_z];
stop = [L2/2-width_iner-G3-width_iner+ssrr2_x, ssrr2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+ssrr2_z];
CSX = AddBox(CSX,'SRR',10,start,stop);
%% ports of S-SRRs %%
if (active==1)
start = [-G1/2+ssrr_x, ssrr_y, -L1/2+ssrr_z];
stop = [G1/2+ssrr_x, substrate_srr.thickness+ssrr_y, -L1/2+width_outer+ssrr_z];
[CSX,port{1}] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 1 0], true);
start = [-G1/2+ssrr2_x, ssrr2_y, -L1/2+ssrr2_z];
stop = [G1/2+ssrr2_x, substrate_srr.thickness+ssrr2_y, -L1/2+width_outer+ssrr2_z];
[CSX,port{2}] = AddLumpedPort(CSX, 5 ,2 ,feed.R, start, stop, [0 1 0], false);
elseif (active==2)
start = [-G1/2+ssrr_x, ssrr_y, -L1/2+ssrr_z];
stop = [G1/2+ssrr_x, substrate_srr.thickness+ssrr_y, -L1/2+width_outer+ssrr_z];
[CSX, port{1}] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 1 0], false);
start = [-G1/2+ssrr2_x, ssrr2_y, -L1/2+ssrr2_z];
stop = [G1/2+ssrr2_x, substrate_srr.thickness+ssrr2_y, -L1/2+width_outer+ssrr2_z];
[CSX,port{2}] = AddLumpedPort(CSX, 5 ,2 ,feed.R, start, stop, [0 1 0], true);
end
% setup a mesh
mesh.x = [];
mesh.y = [];
% two mesh lines for the metal coatings of teh substrate
mesh.z = linspace(-substrate_srr.thickness+ssrr_y, 0, substrate_srr.cells +1);
% find optimal mesh lines for the patch and ground, not yes the microstrip line
mesh = DetectEdges(CSX, mesh, 'SetProperty','groundplane', '2D_Metal_Edge_Res', max_res/2);
%replace gap mesh lines which are too close by a single mesh line
tooclose = find (diff(mesh.y) < max_res/4);
if ~isempty(tooclose)
mesh.y(tooclose) = (mesh.y(tooclose) + mesh.y(tooclose+1))/2;
mesh.y(tooclose + 1) = [];
end
tooclose = find (diff(mesh.x) < max_res/4);
if ~isempty(tooclose)
mesh.x(tooclose) = (mesh.x(tooclose) + mesh.x(tooclose+1))/2;
mesh.x(tooclose + 1) = [];
end
tooclose = find (diff(mesh.z) < max_res/4);
if ~isempty(tooclose)
mesh.z(tooclose) = (mesh.z(tooclose) + mesh.z(tooclose+1))/2;
mesh.z(tooclose + 1) = [];
end
% store the microstrip edges in a temporary variable
meshline = DetectEdges(CSX, [], 'SetProperty', 'SRR', '2D_Metal_Edge_Res', max_res/2);
% as well as the edges of the substrate (without 1/3 - 2/3 rule)
meshsubstrate = DetectEdges(CSX, [], 'SetProperty', 'substrate_srr');
% add only the x mesh lines of the microstrip
mesh.x = [mesh.x meshline.x];
% and only the top of the substrate, the other edges are covered by the ground plane
mesh.y = [mesh.y, meshsubstrate.y]; % top of substrate
% for now we have only the edges, now calculate mesh lines inbetween
mesh = SmoothMesh(mesh, max_res);
% add the outer boundary
mesh.x = [mesh.x -60, 60];
mesh.y = [mesh.y, -60, 65];
mesh.z = [mesh.z, -45, 45];
% add coarse mesh lines for the free space
mesh = SmoothMesh(mesh, coarseResolution);
% define the grid
CSX = DefineRectGrid( CSX, unit, mesh);
%% add a nf2ff calc box,size is 3 cells away from bound cond
if (use_pml == 0)
start = [mesh.x(4) mesh.y(4) mesh.z(4)];
stop = [mesh.x(end-3) mesh.y(end-3) mesh.z(end-3)];
else
start = [mesh.x(12) mesh.y(12) mesh.z(12)];
stop = [mesh.x(end-11) mesh.y(end-11) mesh.z(end-11)];
end
[CSX, nf2ff] = CreateNF2FFBox(CSX,'nf2ff',start,stop);
%% Paraview
CSX = AddDump(CSX,'Ef','DumpType',10,'Frequency',(5e9));
CSX = AddBox(CSX,'Ef',10,[-substrate_srr.width -substrate_srr.length -10*substrate_srr.thickness],[substrate_srr.width substrate_srr.length 10*substrate_srr.thickness]); %assign box
%% prepare and run simulation folder
Sim_Path = 'tmp_unit_cell_definition';
Sim_CSX = 'unit_cell_definition.xml';
[status, message, messageid] = rmdir( Sim_Path, 's' ); % clear previous directory
[status, message, messageid] = mkdir( Sim_Path ); % create empty simulation folder
%% write openEMS compatible xml-file
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
%% show the structure
CSXGeomPlot([Sim_Path '/' Sim_CSX]);
if (cal==1)
%% run openEMS
RunOpenEMS(Sim_Path,Sim_CSX);
%% POST PROCESSING AND DO THE PLOTS
%Postprocessing &Plots
freq = linspace(f0-fc,f0+fc,1001);
port{1} = calcPort(port{1},Sim_Path,freq);
port{2} = calcPort(port{2},Sim_Path,freq);
Pincoming_1=port{1}.P_inc;
Preflected_1=port{1}.P_ref;
Paccepted_1=port{1}.P_acc; %incoming minus reflected, may be negative for passive ports
Pincoming_2=port{2}.P_inc;
Preflected_2=port{2}.P_ref;
Paccepted_2=port{2}.P_acc; %incoming minus reflected, may be negative for passive ports
Zin1 = port{1}.uf.tot ./ port{1}.if.tot;
Zin2 = port{2}.uf.tot ./ port{2}.if.tot;
if (active == 1)
s11 = port{1}.uf.ref ./ port{1}.uf.inc;
s21 = port{2}.uf.ref ./ port{1}.uf.inc;
elseif (active == 2)
s22 = port{2}.uf.ref ./ port{2}.uf.inc;
s12 = port{1}.uf.ref ./ port{2}.uf.inc;
end
if (active == 1)
% plot feed point impedance
figure
plot( freq/1e9, real(Zin1), 'k-', 'Linewidth', 2 );
hold on
grid on
plot( freq/1e9, imag(Zin1), 'r--', 'Linewidth', 2 );
title( 'Feed Point Impedance' );
xlabel( 'frequency f / GHz' );
ylabel( 'impedance Z_{in} / Ohm' );
legend( 'real', 'imag' );
% plot refl coefficient S11,S-parameters S21
figure
plot( freq/1e9, 20*log10(abs(s11)), 'k-', 'Linewidth', 2 );
hold on
grid on
plot( freq/1e9, 20*log10(abs(s21)), 'b-', 'Linewidth', 2 );
title( 'Simulated S-parameters' );
xlabel( 'frequency f / GHz' );
ylabel( 'S-parameters(dB)' );
legend('S11','S21');
drawnow
end
if (active == 2)
% plot feed point impedance
figure
plot( freq/1e9, real(Zin2), 'k-', 'Linewidth', 2 );
hold on
grid on
plot( freq/1e9, imag(Zin2), 'r--', 'Linewidth', 2 );
title( 'Feed Point Impedance' );
xlabel( 'frequency f / MHz' );
ylabel( 'impedance Z_{in} / Ohm' );
legend( 'real', 'imag' );
% plot reflection coefficient S11,S-parameters S21,S31,S41
figure
plot( freq/1e9, 20*log10(abs(s22)), 'k-', 'Linewidth', 2 );
hold on
grid on
plot( freq/1e9, 20*log10(abs(s12)), 'b-', 'Linewidth', 2 );
title( 'Simulated S-parameters' );
xlabel( 'frequency f / GHz' );
ylabel( 'S-parameters(dB)' );
legend('S22','S12');
drawnow
end
% plot reflection coefficient S11,S-parameters S21,S31,S41
figure
plot( freq/1e9,Pincoming_1, 'k-', 'Linewidth', 2 );
hold on
plot( freq/1e9,Preflected_1, 'r-', 'Linewidth', 2 );
hold on
plot( freq/1e9,Paccepted_1, 'b-', 'Linewidth', 2 );
grid on
title( 'Power' );
xlabel( 'frequency f / GHz' );
ylabel( 'Power' );
legend('Power Incoming 1','Power reflected 1', 'Power accepted 1');
drawnow
figure
plot( freq/1e9,Pincoming_2, 'k-', 'Linewidth', 2 );
hold on
plot( freq/1e9,Preflected_2, 'r-', 'Linewidth', 2 );
hold on
plot( freq/1e9,Paccepted_2, 'b-', 'Linewidth', 2 );
grid on
title( 'Power' );
xlabel( 'frequency f / GHz' );
ylabel( 'Power' );
legend('Power Incoming 2','Power reflected 2', 'Power accepted 2');
drawnow
%% NFFF contour plots
%find resonance frequncy from s11
if (active == 1)
f_res_ind = find(s11==min(s11));
f_res = freq(f_res_ind);
elseif (active == 2)
f_res_ind = find(s22==min(s22));
f_res = freq(f_res_ind);
end
% calculate the far field at phi=0 degrees and at phi=90 degrees
disp( 'calculating far field at phi=[0 90] deg...' );
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, (-180:2:180)*pi/180, [0 90]*pi/180, 'Mode', 1);
% display power and directivity
disp( ['radiated power: Prad = ' num2str(nf2ff.Prad) ' Watt']);
disp( ['directivity: Dmax = ' num2str(nf2ff.Dmax) ' (' num2str(10*log10(nf2ff.Dmax)) ' dBi)'] );
if (active == 1)
disp( ['efficiency(ant1) @30GHz = ' num2str(100*nf2ff.Prad./port{1}.P_inc(f_res_ind)) ' %']);
elseif (active == 2)
disp( ['efficiency(ant2) @30GHz = ' num2str(100*nf2ff.Prad./port{2}.P_inc(f_res_ind)) ' %']);
end
% normalized directivity as polar plot
figure
polarFF(nf2ff,'xaxis','theta','param',[1 2],'normalize',1)
% log-scale directivity plot
figure
plotFFdB(nf2ff,'xaxis','theta','param',[1 2])
% conventional plot approach
% plot( nf2ff.theta*180/pi, 20*log10(nf2ff.E_norm{1}/max(nf2ff.E_norm{1}(:)))+10*log10(nf2ff.Dmax));
drawnow
% Show 3D pattern
disp( 'calculating 3D far field pattern and dumping to vtk (use Paraview to visualize)...' );
thetaRange = (0:2:180);
phiRange = (0:2:360) - 180;
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, 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([Sim_Path '/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);
end