-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmicrostripMATLAB
More file actions
188 lines (159 loc) · 6.83 KB
/
microstripMATLAB
File metadata and controls
188 lines (159 loc) · 6.83 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
addpath(genpath('C:\Users\GOPAL\OneDrive\Documents\MATLAB\CSTMATLABAPImaster'))
%This command is used to initiate the CST application, as you can see here, it is assigned to
%the cst variable.
cst = actxserver('CSTStudio.application');
%This command is used to open a new CST project. From now on this mws
%variable will be used to operate any matlab function that is used for the
%control of CST
mws = cst.invoke('NewMWS');
%Sets default units for your project. mm, GHz e.t.c you can open
%CSTDefaultUnits to see the exact selections or if you want I have
%CSTDefineUnits function in the api Home folder that you can use to assign you own units
CstDefaultUnits(mws)
%The frequency sweep of your simulation. Here in GHz, remember that the
%CSTDefaulttUnits from before uses GHz
CstDefineFrequencyRange(mws,1.5,3.5)
%Initiates the auto-meshing
CstMeshInitiator(mws)
%This one defines your boundaries, here we are using expanded open since
%our structure is not some kind of waveguide or unit cell
%Remember that you must define your boundary according to your
%lowest frequency of simulation (minfrequency), here it's 1.5GHz
Xmin='expanded open';
Xmax='expanded open';
Ymin='expanded open';
Ymax='expanded open';
Zmin='expanded open';
Zmax='expanded open';
minfrequency = 1.5;
CstDefineOpenBoundary(mws,minfrequency,Xmin,Xmax,Ymin,Ymax,Zmin,Zmax)
%This function defines the Backround material, here we are using the
%default assignment of CST which is vacuum (permittivity=permeability=1)
%Once again, XminSpace, Xmaxspace e.t.c are the default assignments of CST
%for antennas
XminSpace = 0;
XmaxSpace = 0;
YminSpace = 0;
YmaxSpace = 0;
ZminSpace = 0;
ZmaxSpace = 0;
CstDefineBackroundMaterial(mws,XminSpace,XmaxSpace, YminSpace, YmaxSpace, ZminSpace, ZmaxSpace)
%These two functions are material properties functions. Here there is a
%little trick: You can't call and assign a material from the CST library using matlab or any kind of code (besides PEC).
%It is a bit more complicated, you need to see the properties of the
%desired material in CST library and make a matlab function with all these properties, name the material and call it in your code by that name.
%This is a painfull process but I've managed to replicate some of the most
%important. You can find them in the materials folder of the API, once you
%get a grip of how my code works feel free to add more materials to that
%folder
%Here I am calling Copper annealed lossy and FR4 lossy, after these two
%function I can just write their names as a string and assign them to any
%desired shape
CstCopperAnnealedLossy(mws)
CstFR4lossy(mws)
W = 28.45; %Width of the patch
L = 28.45; %Lenght of the patch
Fi = 9; %Depth of the cut inside the microstrip
Wf = 1.137;%Width of the feedline
Gpf=1; %Width of the empty space slot
Lg = 2*L;%Length of the ground
Wg = 2*W;%Width of the ground
Ht = 0.035;%Height of the copper
Hs = 1.6;% Height of the substrate
%Cstbrick creates a brick for the groundplane. Notice how I just need to do this:
%material ='Copper (annealed)'; and the material of the brick will be
%copper, that's because I already called CstCopperAnnealedLossy(mws) before
Name = 'Groundplane';
component = 'component1';
material = 'Copper (annealed)';
Xrange = [-0.5*Wg 0.5*Wg];
Yrange = [-0.5*Lg 0.5*Lg];
Zrange = [0 Ht];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
%This creates the substrate
Name = 'Substrate';
component = 'component1';
material = 'FR-4 (lossy)';
Xrange = [-0.5*Wg 0.5*Wg];
Yrange = [-0.5*Lg 0.5*Lg];
Zrange = [Ht Ht+Hs];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
%This one creates the patch
Name = 'Patch';
component = 'component1';
material = 'Copper (annealed)';
Xrange = [-W/2 W/2];
Yrange = [-L/2 L/2];
Zrange = [Ht+Hs Ht+Hs+Ht];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
%Here I am cutting the patch to fit the feedline
Name = 'Empty space';
component = 'component1';
material = 'Copper (annealed)';
Xrange = [-((Wf/2)+Gpf) ((Wf/2)+Gpf)];
Yrange = [-L/2+Fi -L/2];
Zrange = [Ht+Hs Ht+Hs+Ht];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
%This subtracts two components
component1 = 'component1:Patch';
component2 = 'component1:Empty space';
CstSubtract(mws,component1,component2)
%This creates the feedline
Name = 'FeedLine';
component = 'component1';
material = 'Copper (annealed)';
Xrange = [-Wf/2 Wf/2];
Yrange = [-L/2+Fi -Lg/2];
Zrange = [Ht+Hs Ht+Hs+Ht];
Cstbrick(mws, Name, component, material, Xrange, Yrange, Zrange)
%This adds the feedline to the patch
component1 = 'component1:Patch';
component2 = 'component1:FeedLine';
CstAdd(mws,component1,component2)
%Here I pick the substrate to assign the port, there is more than one way
%to assign a port in your geometry i.e you can use coordinates and not
%picks, I think coordinates are easier cause pics are generated according
%to your design. i.e id = 3; is how CST names the area I am selecting
%because there are at least 3 faces in my design but that is not standard,
%it depends on your design. Better use coordinates to be sure.
Name = 'Substrate';
id = 3;
CstPickFace(mws,Name,id)
%Here I am assigning a waveguide port (I think I have most of the possible CST ports as functions in my api)
PortNumber = 1;
Xrange = [-36 36];
Yrange = [-36 -36];
Zrange = [0.035 1.635];
XrangeAdd =[3*Wf 3*Wf];
YrangeAdd =[0 0];
ZrangeAdd =[Ht+Hs 4*Hs];
Coordinates = 'Picks';
Orientation = 'positive';
CstWaveguidePort(mws,PortNumber, Xrange, Yrange, Zrange, XrangeAdd, YrangeAdd, ZrangeAdd,Coordinates,Orientation)
%Here I am assigning monitors for the e-field, h-field and farfield at 2.45GHz
CstDefineEfieldMonitor(mws,strcat('e-field', '2.45'),2.45);
CstDefineHfieldMonitor(mws,strcat('h-field', '2.45'), 2.45);
CstDefineFarfieldMonitor(mws,strcat('Farfield','2.45'), 2.45);
%Saves the project
CstSaveProject(mws)
%Defines the solver and starts simulation (I also have frequency domain solver and Integral solver)
%-40 corresponds to accuracy
CstDefineTimedomainSolver(mws,-40)
%Here you need to define the path that you want your s parametters to be
%exported and the name of your file. Mine for instance are:
% exportpath = 'C:\Users\simos\Dropbox\cst api\microstrip';
% filenameTXT = 'microstrip';
exportpath ='C:\Users\GOPAL\OneDrive\Documents\MATLAB\microstrip' ;
filenameTXT = 'microstrip';
%Here the S11 is exported as a .txt file and plotted
CstExportSparametersTXT(mws, exportpath)
[Frequency, Sparametter] = CstLoadSparametterTXT(filenameTXT);
plot(Frequency,Sparametter,'-'); grid on;
legend('S11 (dB)')
title('patch antenna at 2.45GHz')
xlabel('Frequency (GHz)')
%In the API's folders you'll find many more functions that do all kinds of stuff in CST.
%As you've seen in this tutorial the name of each function prety much describes what it does
%Always remember first to call the function of your desired material before you assing it into a
%geometry
%Feel free to experiment with them! Have fun!