-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetasurfacepixelMATLAB
More file actions
254 lines (217 loc) · 7.06 KB
/
metasurfacepixelMATLAB
File metadata and controls
254 lines (217 loc) · 7.06 KB
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
addpath(genpath('C:\Users\GOPAL\OneDrive\Documents\MATLAB\CSTMATLABAPImaster'))
% the above path is used in the below as well
addpath('...\Home');
addpath('...\Materials');
addpath('...\Modeling');
addpath('...\PostProcessing');
addpath('...\Simulation');
addpath('...\cst api');
addpath('..\cstapitest');
cst = actxserver('CSTStudio.application');
mws = cst.invoke('NewMWS');
CstDefaultUnits(mws)
ComponentList = 'component1';
CstFR4lossy(mws)
st = 0.8; % thickness of substrate
ls = 5; %substrate length
p = 0; %pixel thickness
Name = 'Substrate';
component = 'component1';
material = 'FR-4 (lossy)';
Xrange = [-ls/2 ls/2];
Yrange = [-ls/2 ls/2];
Zrange = [0 st];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'ground';
component = 'component1';
material = 'PEC';
Xrange = [-ls/2 ls/2];
Yrange = [-ls/2 ls/2];
Zrange = [0 -p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel1';
component = 'component1';
material = 'PEC';
Xrange = [1.5 2.5];
Yrange = [1.5 2.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel2';
component = 'component1';
material = 'PEC';
Xrange = [0.5 1.5];
Yrange = [1.5 2.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel3';
component = 'component1';
material = 'PEC';
Xrange = [-0.5 0.5];
Yrange = [1.5 2.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel4';
component = 'component1';
material = 'PEC';
Xrange = [-0.5 0.5];
Yrange = [0.5 1.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel5';
component = 'component1';
material = 'PEC';
Xrange = [-0.5 0.5];
Yrange = [-0.5 0.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel6';
component = 'component1';
material = 'PEC';
Xrange = [1.5 2.5];
Yrange = [-0.5 0.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel7';
component = 'component1';
material = 'PEC';
Xrange = [0.5 1.5];
Yrange = [-0.5 -1.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel8';
component = 'component1';
material = 'PEC';
Xrange = [-0.5 -1.5];
Yrange = [-1.5 -2.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
Name = 'pixel9';
component = 'component1';
material = 'PEC';
Xrange = [-1.5 -2.5];
Yrange = [0.5 1.5];
Zrange = [st st+p];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
SetNormal = [0 0 1];
SetOrigin = [0 0 0];
SetUVector = [1 0 0];
CstActivateLocalWCS(mws, SetNormal, SetOrigin, SetUVector, 0)
CstDefineFrequencyRange(mws,13,17)
CstMeshInitiator(mws)
minfrequency = 13;
% Defines the background material
XminSpace = 0;
XmaxSpace = 0;
YminSpace = 0;
YmaxSpace = 0;
ZminSpace = 0;
ZmaxSpace = 0;
CstDefineBackroundMaterial(mws,XminSpace,XmaxSpace, YminSpace, YmaxSpace, ZminSpace, ZmaxSpace)
% Creates the Zmin and Zmax under the ports in navigation tree
Xmin = 'unit cell';
Xmax = 'unit cell';
Ymin = 'unit cell';
Ymax = 'unit cell';
Zmin = 'expanded open';
Zmax = 'expanded open';
CstDefineOpenBoundary(mws,minfrequency,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax)
% Call the defineFloquetModes function directly with the CST project object (mws)
defineFloquetModes(mws, 2);
CstSaveProject(mws)
% CstDefineTimedomainSolver(mws,-40)
CstDefineFrequencydomainSolver(mws, 13, 17, 2);
% % Define export path and file name
% exportpath = 'C:\Users\GOPAL\OneDrive\Documents\MATLAB\pixel2.txt';
%
% % Export S11 as a .txt file
% CstExportSparametersTXT(mws, exportpath);
%
% % Load and plot the exported S-parameters
% if isfile(exportpath)
% [Frequency, Sparametter] = CstLoadSparametterTXT(exportpath);
%
% % Plot the results
% figure;
% plot(Frequency, Sparametter, '-', 'LineWidth', 2);
% grid on;
% legend('S11 (dB)', 'Location', 'Best');
% title('Patch Antenna at 2.45 GHz');
% xlabel('Frequency (GHz)');
% ylabel('S-Parameter (dB)');
% else
% error('The file %s does not exist. Ensure export was successful.', exportpath);
% end
% Define export path and file name
% exportpath = 'C:\Users\GOPAL\OneDrive\Documents\MATLAB\pixel2.txt';
%
% % Export both sets of S-parameters as .txt files
% CstExportSparametersTXT(mws, exportpath);
%
% % Load and plot the exported S-parameters from both files
% if isfile(exportpath)
% [Frequency1, Sparameter1] = CstLoadSparametterTXT(exportpath);
%
% % Load second set of S-parameters
% exportpath2 = strrep(exportpath, '.txt', '_set2.txt');
% if isfile(exportpath2)
% [Frequency2, Sparameter2] = CstLoadSparametterTXT(exportpath2);
%
% % Plot the results
% figure;
% plot(Frequency1, Sparameter1, '-', 'LineWidth', 2);
% hold on;
% plot(Frequency2, Sparameter2, '--', 'LineWidth', 2);
% grid on;
% legend('SZmax(1),Zmax(1) (dB)', 'SZmax(2),Zmax(1) (dB)', 'Location', 'Best');
% title('S parameters');
% xlabel('Frequency (GHz)');
% ylabel('(dB)');
% else
% error('The file %s does not exist. Ensure second export was successful.', exportpath2);
% end
% else
% error('The file %s does not exist. Ensure first export was successful.', exportpath);
% end
exportpathA = 'C:\Users\GOPAL\OneDrive\Documents\MATLAB\pixel2.txt';
exportpathB = strrep(exportpathA,'.txt','_set2.txt');
% Export both sets of S-parameters as .txt files
CstExportSparametersTXT(mws, exportpathA);
if isfile(exportpathA)
[FrequencyA,SparameterA] = CstLoadSparametterTXT(exportpathA);
% Load second set of S-parameters (if applicable)
if isfile(exportpathB)
[FrequencyB,SparameterB] = CstLoadSparametterTXT(exportpathB);
% Plot results from both files
figure;
plot(FrequencyA,SparameterA,'-', 'LineWidth', 2);
hold on;
plot(FrequencyB,SparameterB,'--', 'LineWidth', 2);
grid on;
legend('SZmax(1),Zmax(1) (dB)', 'SZmax(2),Zmax(1) (dB)', 'Location', 'Best');
title('S parameters');
xlabel('Frequency (GHz)');
ylabel('(dB)');
% Calculate and plot MAG(A) and MAG(B)
MAG_A = 10 .^ (SparameterA / 20); % Convert dB to magnitude for A
MAG_B = 10 .^ (SparameterB / 20); % Convert dB to magnitude for B
resultCalculation(FrequencyA,MAG_A,MAG_B);
else
error('The file %s does not exist.', exportpathB);
end
else
error('The file %s does not exist.', exportpathA);
end
function resultCalculation(Frequency, MAG_A, MAG_B)
% Calculate expression and invert it
result = (MAG_A .* MAG_A) ./ ((MAG_A .* MAG_A) + (MAG_B .* MAG_B));
inverted_result = 1 - result; % Invert the result
% Plot the inverted result
figure;
plot(Frequency, inverted_result, 'LineWidth', 2);
grid on;
title('Inverted Calculated Result Against Frequency');
xlabel('Frequency (GHz)');
ylabel('Inverted Result');
% Set y-axis limits to be linear from 0 to 1
ylim([0 1]);
end