-
Notifications
You must be signed in to change notification settings - Fork 5
/
RIS_pairs_simulation.m
416 lines (342 loc) · 17.5 KB
/
RIS_pairs_simulation.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
close all
clear
clc
%% switches & options...
postprocessing_only = 0;
use_pml = 0; % use pml boundaries instead of mur
cal=0; % if cal=0 only the structure is depicted. If cal=1 the calculation is done.
%% setup the simulation
physical_constants;
unit = 1e-3; % all length in mm
%% VARIABLES FROM unit_cell_definition.m
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
%% END OF VARIABLES FROM unit_cell_definition
%% USER-DEFINED VARIABLES
dim_meta=13; %%% dimension of metasurface-elements per column and row. ONLY ODD NUMBERS!!!
%% parameters for load patches
width_patch=1.2;
patch_thickness=srr_thickness;
dx=10;% x-axis distance between elements
dz=10; % z-axis distance between elements
%% RISs positions and distance between them %%
RIS1_x=0; %%RIS1 position%%
RIS1_y=5;
RIS1_z=0;
RIS2_x=0; %%RIS2 position%%
RIS2_y=-5;
RIS2_z=0;
substrate_srr.thickness = 2.1; %% The only variable that is useful to change from unit_cell_definition in order to improve the coupling
%% END OF USER-DEFINED VARIABLES
% substrate setup
distance_x=L2+dx;
distance_z=L1+dz;
substrate_srr.width = dim_meta*distance_x;
substrate_srr.length =dim_meta*distance_z;
%% setup FDTD parameter & excitation function
max_timesteps = 500000;
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
% currently, openEMS cannot automatically generate a 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;
% set the resolution for the coarser structures, e.g. the surrounding air
coarseResolution = c0/(f0 + fc) / unit / 20;
substrate_srr.cells = 4;
CSX = InitCSX();
%% prepare simulation folder
Sim_Path = 'tmp';
Sim_CSX = 'patch_ant.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
%% create materials
CSX = AddMaterial(CSX,'substrate_srr'); %create substrate
CSX = SetMaterialProperty(CSX,'substrate_srr','Epsilon',substrate.epsR,'Kappa',substrate_srr.kappa);
CSX = AddMetal(CSX,'groundplane'); %create groundplane
CSX = AddMetal( CSX, 'patch');%create patches
CSX = AddMetal( CSX, 'SRR'); %create S-SRRs
%% DESIGN OF STRUCTURE %%
%% RIS1 %%
%% create substrate
start = [-substrate_srr.length/2+RIS1_x, RIS1_y,-substrate_srr.width/2+RIS1_z];
stop = [ substrate_srr.length/2+RIS1_x, substrate_srr.thickness+RIS1_y,substrate_srr.width/2+RIS1_z];
CSX = AddBox(CSX,'substrate_srr',1,start,stop);
%% create groundplane
start = [ -substrate_srr.length/2+RIS1_x, RIS1_y+substrate_srr.thickness,-substrate_srr.width/2+RIS1_z];
stop = [substrate_srr.length/2+RIS1_x, RIS1_y+substrate_srr.thickness, substrate_srr.width/2+RIS1_z];
CSX = AddBox(CSX,'groundplane',2,start,stop);
%create unit cells-S-SRRs
number_of_elements=0;
for i=-((dim_meta-1)/2):((dim_meta-1)/2)
x=i*distance_x;
for j=-((dim_meta-1)/2):((dim_meta-1)/2)
number_of_elements=number_of_elements+1;
z=j*distance_z;
start = [L2/2+RIS1_x+x, RIS1_y+srr_thickness/2,-L1/2+RIS1_z+width_outer+z];
stop = [L2/2-width_outer+RIS1_x+x, RIS1_y-srr_thickness/2,L1/2+RIS1_z-width_outer+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2+G1/2-width_outer/2+RIS1_x+x, RIS1_y+srr_thickness/2, -L1/2+RIS1_z+z];
stop = [G1/2+RIS1_x+x, RIS1_y-srr_thickness/2,-L1/2+width_outer+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2-G1/2+width_outer/2+RIS1_x+x, RIS1_y+srr_thickness/2, -L1/2+RIS1_z+z];
stop = [-G1/2+RIS1_x+x, RIS1_y-srr_thickness/2,-L1/2+width_outer+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+RIS1_x+x, RIS1_y+srr_thickness/2, L1/2+RIS1_z+z];
stop = [ L2/2+RIS1_x+x, RIS1_y-srr_thickness/2,L1/2-width_outer+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+RIS1_x+x, RIS1_y+srr_thickness/2,-L1/2+RIS1_z+width_outer+z];
stop = [-L2/2+width_outer+RIS1_x+x, RIS1_y-srr_thickness/2,L1/2+RIS1_z-width_outer+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
%% iner ring
start = [ L2/2-width_iner-G3-width_iner+RIS1_x+x, RIS1_y+srr_thickness/2, -L1/2+width_iner+G3+RIS1_z+z];
stop = [-L2/2+width_iner+G3+width_iner+RIS1_x+x, RIS1_y-srr_thickness/2,-L1/2+width_iner+G3+width_iner+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-G2/2+RIS1_x+x, RIS1_y+srr_thickness/2,L1/2-width_iner-G3+RIS1_z+z];
stop = [ -L2/2+width_iner+width_iner+G3+RIS1_x+x, RIS1_y-srr_thickness/2,L1/2-width_iner-G3-width_iner+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [G2/2+RIS1_x+x, RIS1_y+srr_thickness/2,L1/2-width_iner-G3+RIS1_z+z];
stop = [ L2/2-width_iner-G3-width_iner+RIS1_x+x, RIS1_y-srr_thickness/2,L1/2-width_iner-G3-width_iner+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+width_iner+G3+RIS1_x+x, RIS1_y+srr_thickness/2,-L1/2+width_iner+G3+RIS1_z+z];
stop = [-L2/2+width_iner+G3+width_iner+RIS1_x+x, RIS1_y-srr_thickness/2,L1/2-width_iner-G3+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2-width_iner-G3+RIS1_x+x, RIS1_y+srr_thickness/2,-L1/2+width_iner+G3+RIS1_z+z];
stop = [L2/2-width_iner-G3-width_iner+RIS1_x+x, RIS1_y-srr_thickness/2,L1/2-width_iner-G3+RIS1_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
%% load patches
if i~=(dim_meta-1)/2
start = [L2/2+RIS1_x+i*(dx+L2), RIS1_y+patch_thickness/2, L1/4+RIS1_z+z];
stop = [ L2/2+RIS1_x+dx+i*(dx+L2), RIS1_y-srr_thickness/2,L1/4-width_patch+RIS1_z+z];
CSX = AddBox(CSX,'patch',4,start,stop);
start = [L2/2+RIS1_x+i*(dx+L2), RIS1_y+patch_thickness/2, -L1/4+RIS1_z+z];
stop = [ L2/2+RIS1_x+dx+i*(dx+L2), RIS1_y-patch_thickness/2,-L1/4+width_patch+RIS1_z+z];
CSX = AddBox(CSX,'patch',4,start,stop);
end
if j~=(dim_meta-1)/2
start = [L2/4+RIS1_x+x, RIS1_y+patch_thickness/2,L1/2+RIS1_z+j*(L1+dz)];
stop = [L2/4+width_patch+RIS1_x+x, RIS1_y-patch_thickness/2,L1/2+RIS1_z+dz+j*(L1+dz)];
CSX = AddBox(CSX,'patch',4,start,stop);
start = [-L2/4+RIS1_x+x, RIS1_y+patch_thickness/2,L1/2+RIS1_z+j*(L1+dz)];
stop = [-L2/4-width_patch+RIS1_x+x, RIS1_y-patch_thickness/2,L1/2+RIS1_z+dz+j*(L1+dz)];
CSX = AddBox(CSX,'patch',4,start,stop);
end
%% lumped ports. All the ports of RIS #1 are active
for k=number_of_elements
start = [-G1/2+RIS1_x+x, RIS1_y, -L1/2+RIS1_z+z];
stop = [G1/2+RIS1_x+x, substrate_srr.thickness+RIS1_y, -L1/2+width_outer+RIS1_z+z];
[CSX, port{k}] = AddLumpedPort(CSX, 1 ,k ,feed.R, start, stop, [0 1 0], true);
end
end
end
%% RIS2 %%
%% create substrate
start = [-substrate_srr.length/2+RIS2_x, RIS2_y,-substrate_srr.width/2+RIS2_z];
stop = [ substrate_srr.length/2+RIS2_x, substrate_srr.thickness+RIS2_y,substrate_srr.width/2+RIS2_z];
CSX = AddBox(CSX,'substrate_srr',1,start,stop);
%% create groundplane
start = [ -substrate_srr.length/2+RIS2_x, RIS2_y,-substrate_srr.width/2+RIS2_z];
stop = [substrate_srr.length/2+RIS2_x, RIS2_y, substrate_srr.width/2+RIS2_z];
CSX = AddBox(CSX,'groundplane',2,start,stop);
number_of_elements_2=0;
x=0;
z=0;
for i=-((dim_meta-1)/2):((dim_meta-1)/2)
x=i*distance_x;
for j=-((dim_meta-1)/2):((dim_meta-1)/2)
number_of_elements_2=number_of_elements_2+1;
z=j*distance_z;
%% outer ring
CSX = AddMetal( CSX, 'SRR');
start = [L2/2+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+RIS2_z+z+width_outer];
stop = [L2/2-width_outer+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/2+RIS2_z+z-width_outer];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2+G1/2-width_outer/2+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness, -L1/2+RIS2_z+z];
stop = [G1/2+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,-L1/2+width_outer+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2-G1/2+width_outer/2+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness, -L1/2+RIS2_z+z];
stop = [-G1/2+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,-L1/2+width_outer+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness, L1/2+RIS2_z+z];
stop = [ L2/2+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_outer+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+RIS2_z+z+width_outer];
stop = [-L2/2+width_outer+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/2+RIS2_z+z-width_outer];
CSX = AddBox(CSX,'SRR',10,start,stop);
%% iner ring
start = [ L2/2-width_iner-G3-width_iner+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness, -L1/2+width_iner+G3+RIS2_z+z];
stop = [-L2/2+width_iner+G3+width_iner+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,-L1/2+width_iner+G3+width_iner+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-G2/2+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+RIS2_z+z];
stop = [ -L2/2+width_iner+width_iner+G3+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3-width_iner+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [G2/2+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+RIS2_z+z];
stop = [ L2/2-width_iner-G3-width_iner+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3-width_iner+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [-L2/2+width_iner+G3+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+width_iner+G3+RIS2_z+z];
stop = [-L2/2+width_iner+G3+width_iner+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
start = [L2/2-width_iner-G3+RIS2_x+x, RIS2_y+srr_thickness/2+substrate_srr.thickness,-L1/2+width_iner+G3+RIS2_z+z];
stop = [L2/2-width_iner-G3-width_iner+RIS2_x+x, RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/2-width_iner-G3+RIS2_z+z];
CSX = AddBox(CSX,'SRR',10,start,stop);
%% load patches
if i~=(dim_meta-1)/2
start = [L2/2+RIS2_x+i*(dx+L2), RIS2_y+patch_thickness/2+substrate_srr.thickness, L1/4+RIS2_z+z];
stop = [ L2/2+RIS2_x+dx+i*(dx+L2), RIS2_y-srr_thickness/2+substrate_srr.thickness,L1/4-width_patch+RIS2_z+z];
CSX = AddBox(CSX,'patch',4,start,stop);
start = [L2/2+RIS2_x+i*(dx+L2), RIS2_y+patch_thickness/2+substrate_srr.thickness, -L1/4+RIS2_z+z];
stop = [ L2/2+RIS2_x+dx+i*(dx+L2), RIS2_y-srr_thickness/2+substrate_srr.thickness,-L1/4+width_patch+RIS2_z+z];
CSX = AddBox(CSX,'patch',4,start,stop);
end
if j~=(dim_meta-1)/2
start = [L2/4+RIS2_x+x, RIS2_y+patch_thickness/2+substrate_srr.thickness,L1/2+RIS2_z+j*(L1+dz)];
stop = [L2/4+width_patch+RIS2_x+x, RIS2_y-patch_thickness/2+substrate_srr.thickness,L1/2+RIS2_z+dz+j*(L1+dz)];
CSX = AddBox(CSX,'patch',4,start,stop);
start = [-L2/4+RIS2_x+x, RIS2_y+patch_thickness/2+substrate_srr.thickness,L1/2+RIS2_z+j*(L1+dz)];
stop = [-L2/4-width_patch+RIS2_x+x, RIS2_y-patch_thickness/2+substrate_srr.thickness,L1/2+RIS2_z+dz+j*(L1+dz)];
CSX = AddBox(CSX,'patch',4,start,stop);
end
%% lumped ports. All the ports of RIS #2 are passive.
for k=number_of_elements_2
start = [-G1/2+RIS2_x+x, RIS2_y, -L1/2+RIS2_z+z];
stop = [G1/2+RIS2_x+x, RIS2_y+substrate_srr.thickness, -L1/2+width_outer+RIS2_z+z];
[CSX, port{k+number_of_elements}] = AddLumpedPort(CSX, 5 ,k+number_of_elements ,feed.R, start, stop, [0 1 0], false);
end
end
end
% setup a mesh
mesh.x = [];
mesh.y = [];
% two mesh lines for the metal coatings of teh substrate
mesh.z = linspace(-substrate_srr.thickness+RIS1_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', 'patch'}, '2D_Metal_Edge_Res', max_res/2);
%replace gap mesh lines which are too close by a single mesh line in each
%axis
tooclose = find (diff(mesh.y) < max_res/2);
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/2);
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/2);
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,-dim_meta*20, +dim_meta*20];
mesh.y = [mesh.y, -dim_meta*10, dim_meta*10];
mesh.z = [mesh.z, -dim_meta*20, +dim_meta*20];
% add coarse mesh lines for the free space
%mesh = SmoothMesh(mesh, coarseResolution,'algorithm',[1 3]);
mesh = SmoothMesh(mesh, coarseResolution);
% define the grid
CSX = DefineRectGrid( CSX, unit, mesh);
start = [mesh.x(2) mesh.y(2) mesh.z(2)];
stop = [mesh.x(end-1) mesh.y(end-1) mesh.z(end-1)];
CSX = AddDump(CSX,'Ef', 'DumpType', 10, 'Frequency',(f0));
CSX = AddBox(CSX,'Ef',10,start, stop); %assign box
%% 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);
%% prepare and run simulation folder
Sim_Path = 'tmp_ris_pairs';
Sim_CSX = 'ris_pairs.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);
for i=1:2*dim_meta^2
port{i} = calcPort(port{i},Sim_Path,freq);
Zin{i} = port{i}.uf.tot ./ port{i}.if.tot;
P_in{i} = real(0.5 * port{i}.uf.tot .* conj( port{i}.if.tot ));
Pincoming{i}=port{i}.P_inc;
Preflected{i}=port{i}.P_ref;
Paccepted{i}=port{i}.P_acc; %incoming minus reflected, may be negative for passive port
end
for i=1:2*dim_meta^2
for j=1:2*dim_meta^2
s{j,i} = port{j}.uf.ref ./ port{i}.uf.inc;
end
end
for i=1:2*dim_meta^2
for j=1:2*dim_meta^2
if j==i && i<=dim_meta^2
f_res{i}=find(s{j,i}==min(s{j,i}));
elseif i>dim_meta^2
f_coupling{j,i}=find(s{j,i}==max(s{j,i}));
end
end
end
for i=1:dim_meta^2
figure
for j=1:2*dim_meta^2
if i==j
plot(freq/1e6, 20*log10(abs(s{j,i})), 'b-', 'Linewidth', 4 );
hold on
elseif j>dim_meta^2 && i~=j
plot( freq/1e6, 20*log10(abs(s{j,i})), 'k-', 'Linewidth', 0.25 );
hold on
elseif j<dim_meta^2 && i~=j
plot( freq/1e6, 20*log10(abs(s{j,i})), 'r-', 'Linewidth', 0.25 );
hold on
end
grid on
title( 'Simulated S-parameters' );
xlabel( 'frequency f / MHz' );
ylabel( 'S-parameters(dB)' );
end
drawnow
end
end