-
Notifications
You must be signed in to change notification settings - Fork 3
/
Final_Structure.m
276 lines (217 loc) · 8.56 KB
/
Final_Structure.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
%------------------ Truncated Microstrips with Cylindrical Dielectric region ---------------------
clear all;
clc;
%----- Dimensions ----------
sub_l = 45e-3;
sub_w = sub_l;
sub_h = 1.57e-3;
strip_w = 4.66e-3;
strip_l = sub_l/2;
cyl_dia = 19.43e-3;
cyl_h = 7.3e-3;
%----- Filling ----------
eps0 = 8.854e-12;
meu0 = 4*pi*1e-7;
epsr = 2.33;
epsr_cyl = 24;
meur = 1;
epss = eps0*epsr; % Substrate
epss_cyl = eps0*epsr_cyl; % Cylinder
meus = meu0*meur;
epsa = eps0; % air
meua = meu0;
%---- Signal -----------
c = 3e8;
vmin = c/sqrt(epsr*meur);
vmax = c;
%------ Cell length and time step---------
dx = 0.5e-3; dy = 0.2e-3; dz = dx;
dt = 1/(vmax*sqrt(1/dx^2+1/dy^2+1/dz^2));
%-------- computational space
Nx = ceil(sub_w/dx);
Nh = ceil(sub_h/dy); % Substrate height (no. of cells)
yoff = 10; % Air column height above DR
Ncyl = ceil(cyl_h/dy); % DR height (no. of cells)
Ny = Ncyl + yoff; % Total height
Nz = ceil(sub_l/dz);
Nw = ceil(strip_w/dx);
cyl_rad = cyl_dia/(2*dx);
%----------- Substrate start and end
sub_x1 = 1;
sub_x2 = Nx;
sub_y1 = 1;
sub_y2 = Nh;
sub_z1 = 1;
sub_z2 = Nz;
x_centre = Nx/2;
disp = 10e-03;
z_centre = Nz/2 - (disp/dz);
%----------- Strip start and end
strip_x12 = ceil(Nx/2 - cyl_rad);
strip_x11 = strip_x12 - Nw;
strip_x21 = ceil(Nx/2 + cyl_rad);
strip_x22= strip_x21 + Nw;
strip_y = sub_y2 + 1; %%%%%%%% Note this step
strip_z1 = sub_z1;
strip_z2 = strip_z1 + ceil(strip_l/dz);
%-------- Ports
feed_x1 = strip_x11 + ceil((strip_x12-strip_x11)/2);
feed_x2 = strip_x21 + ceil((strip_x22-strip_x21)/2);
feed_y1 = sub_y1;
feed_y2 = sub_y2;
feed_z1 = strip_z1+3;
feed_z2 = strip_z1;
%------- Initialise E,H,multipliers and ABC arrays ------------
ex = zeros(Nx,Ny,Nz); ex = single(ex); ey = ex; ez = ey;
hx = ex; hy = hx; hz = hy;
const_ex = ex; const_ey = const_ex; const_ez = const_ey;
const_hx = hx; const_hy = const_hx; const_hz = const_hy;
ex_abc = ex; ey_abc = ex; ez_abc = ex;
gx = ex;
v = ex; % v for abc_mult
%------- Default constants in update eqn
const_ex(:,:,:) = dt/(epsa*dx);
const_ey(:,:,:) = dt/(epsa*dy);
const_ez(:,:,:) = dt/(epsa*dz);
%--------------------------------------
const_hx(:,:,:) = dt/(meua*dx);
const_hy(:,:,:) = dt/(meua*dy);
const_hz(:,:,:) = dt/(meua*dz);
%----------- Substrate---------
const_ex(sub_x1:sub_x2,sub_y1:sub_y2,sub_z1:sub_z2) = dt/(epss*dx);
const_ey(sub_x1:sub_x2,sub_y1:sub_y2,sub_z1:sub_z2) = dt/(epss*dy);
const_ez(sub_x1:sub_x2,sub_y1:sub_y2,sub_z1:sub_z2) = dt/(epss*dz);
%------- Constants in E-update eqn
gx(:,:,:) = 1; gy = gx; gz = gy; % default is 1 for non-PEC areas
%----------- Metal boundaries ---------
%---- GND plane
gx(sub_x1:sub_x2,sub_y1,sub_z1:sub_z2) = 0;
gz(sub_x1:sub_x2,sub_y1,sub_z1:sub_z2) = 0;
%---- Striplines
gx(strip_x11:strip_x12,strip_y,strip_z1:strip_z2) = 0;
gz(strip_x11:strip_x12,strip_y,strip_z1:strip_z2) = 0;
gx(strip_x21:strip_x22,strip_y,strip_z1:strip_z2) = 0;
gz(strip_x21:strip_x22,strip_y,strip_z1:strip_z2) = 0;
%----------- Leubbers --------
gx(strip_x11+1:strip_x12-1,feed_y2-1:feed_y2,feed_z1) = 0;
gx(strip_x11+2:strip_x12-2,feed_y2-3:feed_y2-2,feed_z1) = 0;
gx(strip_x11+3:strip_x12-3,feed_y2-5:feed_y2-4,feed_z1) = 0;
gx(strip_x11+4:strip_x12-4,feed_y2-6,feed_z1) = 0;
gy(strip_x11+1:strip_x12-1,feed_y2-1:feed_y2,feed_z1) = 0;
gy(strip_x11+2:strip_x12-2,feed_y2-3:feed_y2-2,feed_z1) = 0;
gy(strip_x11+3:strip_x12-3,feed_y2-5:feed_y2-4,feed_z1) = 0;
gy(strip_x11+4:strip_x12-4,feed_y2-6,feed_z1) = 0;
%----------- Cylinder --------
% for x = strip_x12+1:strip_x21-1
% val1 = z_centre - ceil((sqrt(((cyl_rad)^2)-((x-x_centre)^2))));
% val2 = z_centre + ceil((sqrt(((cyl_rad)^2)-((x-x_centre)^2))));
% const_ex(x, sub_y1+1:Ncyl, round(val1):round(val2)) = dt/(epss_cyl*dx);
% const_ey(x, sub_y1+1:Ncyl, round(val1):round(val2)) = dt/(epss_cyl*dy);
% const_ez(x, sub_y1+1:Ncyl, round(val1):round(val2)) = dt/(epss_cyl*dz);
% gx(x, sub_y1+1:Ncyl, round(val1):round(val2)) = dt/(epss_cyl*dx);
% gz(x, sub_y1+1:Ncyl, round(val1):round(val2)) = dt/(epss_cyl*dz);
% end
%------ ABC constants
v(:,:,:) = vmax; % default value
v(sub_x1:sub_x2,sub_y1:sub_y2,sub_z1:sub_z2) = vmin;
constz_abc = (v*dt-dz)./(v*dt+dz);
consty_abc = (v*dt-dy)./(v*dt+dy);
constx_abc = (v*dt-dx)./(v*dt+dx);
%------ Plot a cross section
f1 = figure('Name','Striplines & Cylinder');
figure(f1);
arr = gx(:,strip_y,:);
surf(1:Nz,1:Nx,arr(:,:));
f2 = figure('Name','Source Tapering');
figure(f2);
arr2 = gy(:,:,feed_z1);
surf(1:Ny,1:Nx,arr2(:,:));
%%
%------ Gaussian pusle ------------
Ts = 10*dt;
t0 = 3*Ts; % nothing to do with stability, but abc do
count = 0;
volt_in = zeros(1e6,1); volt_in = single(volt_in);
curr_in = volt_in;
volt_out = volt_in;
N_steps = 5000;
for val = 1:N_steps
tstart = cputime;
time = count*dt;
count = count+1;
clc;
fprintf('\n\tTime step : %d',count);
% ----- Source------- curr, pulse, lub, vol
m = feed_x1; n = feed_y1; p = feed_z1;
curr_in(count) = -(hx(m,n,p-1)-hx(m,n,p))*dx + (hz(m,n,p)-hz(m-1,n,p))*dz;
pulse = exp(-((time-t0)/Ts)^2); %*sin(2*pi*5e9*time);
m = feed_x1-1:feed_x1+1; p = feed_z1;
ey(m,n,p) = (pulse + curr_in(count)*50)/dy; %%%%%%% Note the sign !!!
volt_in(count) = ey(feed_x1, feed_y1, feed_z1)*dy;
volt_out(count) = ey(feed_x2, feed_y1, feed_z2)*dy;
%------------------------ compute H -------------------------
j=1:Ny-1; k=1:Nz-1;
hx(:,j,k) = hx(:,j,k) + const_hz(:,j,k).*(ey(:,j,k+1)-ey(:,j,k)) - const_hy(:,j,k).*(ez(:,j+1,k)-ez(:,j,k));
i=1:Nx-1; k=1:Nz-1;
hy(i,:,k) = hy(i,:,k) + const_hx(i,:,k).*(ez(i+1,:,k)-ez(i,:,k)) - const_hz(i,:,k).*(ex(i,:,k+1)-ex(i,:,k));
i=1:Nx-1; j=1:Ny-1;
hz(i,j,:) = hz(i,j,:) + const_hy(i,j,:).*(ex(i,j+1,:)-ex(i,j,:)) - const_hx(i,j,:).*(ey(i+1,j,:)-ey(i,j,:));
%------------------------- compute E ------------------------
j=2:Ny-1; k=2:Nz-1;
ex(:,j,k) = ex(:,j,k) + gx(:,j,k).*(const_ey(:,j,k).*(hz(:,j,k)-hz(:,j-1,k)) - const_ez(:,j,k).*(hy(:,j,k)-hy(:,j,k-1)));
i=2:Nx-1; k=2:Nz-1;
ey(i,:,k) = ey(i,:,k) + gy(i,:,k).*(const_ez(i,:,k).*(hx(i,:,k)-hx(i,:,k-1)) - const_ex(i,:,k).*(hz(i,:,k)-hz(i-1,:,k)));
i=2:Nx-1; j=2:Ny-1;
ez(i,j,:) = ez(i,j,:) + gz(i,j,:).*(const_ex(i,j,:).*(hy(i,j,:)-hy(i-1,j,:)) - const_ey(i,j,:).*(hx(i,j,:)-hx(i,j-1,:)));
%---------- XY plane
ex(:,:,1) = ex_abc(:,:,2) + constz_abc(:,:,1).*(ex(:,:,2)-ex(:,:,1));
ey(:,:,1) = ey_abc(:,:,2) + constz_abc(:,:,1).*(ey(:,:,2)-ey(:,:,1));
ex(:,:,Nz) = ex_abc(:,:,Nz-1) + constz_abc(:,:,Nz).*(ex(:,:,Nz-1)-ex(:,:,Nz));
ey(:,:,Nz) = ey_abc(:,:,Nz-1) + constz_abc(:,:,Nz).*(ey(:,:,Nz-1)-ey(:,:,Nz));
%---------- XZ plane
%ex(:,1,:) = ex_abc(:,2,:) + consty_abc(:,1,:).*(ex(:,2,:)-ex(:,1,:));
%ez(:,1,:) = ez_abc(:,2,:) + consty_abc(:,1,:).*(ez(:,2,:)-ez(:,1,:));
ex(:,Ny,:) = ex_abc(:,Ny-1,:) + consty_abc(:,Ny,:).*(ex(:,Ny-1,:)-ex(:,Ny,:));
ez(:,Ny,:) = ez_abc(:,Ny-1,:) + consty_abc(:,Ny,:).*(ez(:,Ny-1,:)-ez(:,Ny,:));
%---------- YZ plane
ey(1,:,:) = ey_abc(2,:,:) + constx_abc(1,:,:).*(ey(2,:,:)-ey(1,:,:));
ez(1,:,:) = ez_abc(2,:,:) + constx_abc(1,:,:).*(ez(2,:,:)-ez(1,:,:));
ey(Nx,:,:) = ey_abc(Nx-1,:,:) + constx_abc(Nx,:,:).*(ey(Nx-1,:,:)-ey(Nx,:,:));
ez(Nx,:,:) = ez_abc(Nx-1,:,:) + constx_abc(Nx,:,:).*(ez(Nx-1,:,:)-ez(Nx,:,:));
ex_abc = ex; ey_abc = ey; ez_abc = ez;
end % for loop ends
f3 = figure('Name','V in & I in');
figure(f3);
subplot(1,2,1);
plot(1:count,volt_in(1:count));
grid on; grid minor;
title('V in');
xlim([0, count]);
xlabel('Count')
ylabel('Amplitude (V)')
subplot(1,2,2);
plot(1:count,curr_in(1:count));
grid on; grid minor;
title('I in');
xlim([0, count]);
xlabel('Count')
ylabel('Amplitude (A)')
%--------- S21
Nmax = 1e6;
S21 = fft(volt_out,Nmax)./fft(volt_in,Nmax); S21 = single(S21);
S21 = 20*log10(abs(S21));
fmax = 1/dt;
N = 100;
fmax = fmax/N;
Nmax = Nmax/N;
df = fmax/Nmax;
f = 0:df:fmax-df; f = single(f);
n = round(f/df)+1;
f4 = figure('Name','S21 = fft(Vout)/fft(Vin)');
figure(f4);
plot(f,S21(n));
grid on; grid minor;
title(['Strip Length = ' num2str((strip_z2-strip_z1)/(sub_z2-sub_z1+1)) ' of Substrate']);
xlabel('Frequency');
ylabel('S21');
xlim([min(f) max(f)]);