Imported Patch antenna simulation

How to use openEMS. Discussion on examples, tutorials etc

Moderator: thorsten

Post Reply
Upballoon
Posts: 1
Joined: Wed 21 Apr 2021, 04:57

Imported Patch antenna simulation

Post by Upballoon » Wed 21 Apr 2021, 05:01

Hey guys,
I made a patch in freecad and imported it into CSXCAD. And I'm trying to get it to simulate properly but don't have any luck.
I'm a complete beginner and just installed openEMS the other day. Any help would be appreciated. I've attached my code here:

Code: Select all

physical_constants;
unit = 1e-3; % all length in mm
 
% patch width in x-direction
patch.width  = 40.7423; % resonant length
% patch length in y-direction
patch.length = 32.2599;
patch.thickness = 1;
 
%substrate setup
substrate.epsR   = 3.7;
substrate.kappa  = 1e-3 * 2*pi*2.45e9 * EPS0*substrate.epsR;
substrate.width  = 60;
substrate.length = 75;
substrate.thickness = 1;
substrate.cells = 4;
 
%setup feeding
feed.pos = 0; %feeding position in x-direction
feed.width = 2;  %feeding port width
feed.R = 50;     %feed resistance
 
% size of the simulation box
SimBox = [200 200 100];

f0 = 2.45e9; % center frequency
fc = 1e9; % 20 dB corner frequency
FDTD = InitFDTD('NrTS', 30000 );
FDTD = SetGaussExcite( FDTD, f0, fc );
BC = {'MUR' 'MUR' 'MUR' 'MUR' 'MUR' 'MUR'}; % boundary conditions
FDTD = SetBoundaryCond( FDTD, BC );


max_res = c0 / (f0+fc) / unit / 20; % cell size: lambda/20
CSX = InitCSX();
 
%create fixed lines for the simulation box, substrate and port
mesh.x = [-SimBox(1)/2 SimBox(1)/2 -substrate.width/2 substrate.width/2 -patch.width/2 patch.width/2 feed.pos];
mesh.x = SmoothMeshLines( mesh.x, max_res, 1.4); % create a smooth mesh between specified fixed mesh lines
 
mesh.y = [-SimBox(2)/2 SimBox(2)/2 -substrate.length/2 substrate.length/2 -feed.width/2 feed.width/2 -patch.length/2 patch.length/2];
mesh.y = SmoothMeshLines( mesh.y, max_res, 1.4 );
 
%create fixed lines for the simulation box and given number of lines inside the substrate
mesh.z = [-SimBox(3)/2 linspace(-patch.thickness/2-substrate.thickness,substrate.thickness/10,substrate.cells) SimBox(3)/2 ];
%mesh.z = SmoothMeshLines( mesh.z, max_res, 1.4 );

 
CSX = DefineRectGrid( CSX, unit, mesh );

%% create patch
patch_path = '/home/upballoon/Documents/School/Spring2021/Thesis/Patch.stl';
CSX = AddMetal( CSX, 'cad_model' );
CSX = ImportSTL(CSX, 'cad_model',10, patch_path,'Transform',{'Scale',1});

%{
CSX = AddMetal( CSX, 'patch' ); % create a perfect electric conductor (PEC)
start = [-patch.width/2 -patch.length/2 substrate.thickness];
stop  = [ patch.width/2  patch.length/2 substrate.thickness+0.1];
CSX = AddBox(CSX,'patch',10,start,stop); % add a box-primitive to the metal property 'patch'
%}
 
%% create substrate
CSX = AddMaterial( CSX, 'substrate' );
CSX = SetMaterialProperty( CSX, 'substrate', 'Epsilon', substrate.epsR, 'Kappa', substrate.kappa );
start = [-substrate.width/2 -substrate.length/2 -patch.thickness/2-substrate.thickness];
stop  = [ substrate.width/2  substrate.length/2 -patch.thickness/2];
CSX = AddBox( CSX, 'substrate', 0, start, stop );
 
%% create ground (same size as substrate)
CSX = AddMetal( CSX, 'gnd' ); % create a perfect electric conductor (PEC)
start(3)= -patch.thickness/2-substrate.thickness;
stop(3) = start(3);
CSX = AddBox(CSX,'gnd',10,start,stop);



start = [0 0 -patch.thickness/2-substrate.thickness];
stop  = [0 feed.width/2 -patch.thickness/2];
[CSX port] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 0 1], true);


SimBox = SimBox - max_res * 4; %reduced SimBox size for nf2ff box
[CSX nf2ff] = CreateNF2FFBox(CSX, 'nf2ff', -SimBox/2, SimBox/2);

%% prepare simulation folder
Sim_Path = 'tmp';
Sim_CSX = 'patch_ant.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] );


%% run openEMS
RunOpenEMS( Sim_Path, Sim_CSX );

%% postprocessing & do the plots
freq = linspace( max([1e9,f0-fc]), f0+fc, 501 );
port = calcPort(port, Sim_Path, freq);

Zin = port.uf.tot ./ port.if.tot;
s11 = port.uf.ref ./ port.uf.inc;
P_in = 0.5 * port.uf.inc .* conj( port.if.inc ); % antenna feed power

% plot feed point impedance
figure
plot( freq/1e6, real(Zin), 'k-', 'Linewidth', 2 );
hold on
grid on
plot( freq/1e6, imag(Zin), 'r--', 'Linewidth', 2 );
title( 'feed point impedance' );
xlabel( 'frequency f / MHz' );
ylabel( 'impedance Z_{in} / Ohm' );
legend( 'real', 'imag' );

% plot reflection coefficient S11
figure
plot( freq/1e6, 20*log10(abs(s11)), 'k-', 'Linewidth', 2 );
grid on
title( 'reflection coefficient S_{11}' );
xlabel( 'frequency f / MHz' );
ylabel( 'reflection coefficient |S_{11}|' );
 

Post Reply