You are on page 1of 6

# Tutorial: Rectangular Waveguide

Download the latest matlab file using gitweb: Rect_Waveguide.m Simulation Time: ~ 5 min for a 5m long waveguide

## We will cover in this tutorial:

setup a mode profile excitation create voltage and current probes using the mode profile calculate the waveguide impedance and S-Parameter
Contents
[hide]

o

First Steps

## Matlab Simulation Script

Start the script within an empty environment: close all clear clc

Setup the simulation parameter physical_constants; unit = 1e-3; %drawing unit in mm numTS = 50000; %max. number of timesteps % waveguide dimensions length = 5000;

a = 1000; b = 1000;

## %waveguide width %waveguide heigth

% frequency range of interest f_start = 300e6; f_stop = 500e6; %waveguide TE-mode definition m = 1; n = 1; mesh_res = [10 10 10]; %targeted mesh resolution

Define the mode functions % by David M. Pozar, Microwave Engineering, third edition, page 113 freq = linspace(f_start,f_stop,201); k = 2*pi*freq/c0; kc = sqrt((m*pi/a/unit)^2 + (n*pi/b/unit)^2); fc = c0*kc/2/pi; %cut-off frequency beta = sqrt(k.^2 - kc^2); %waveguide phase-constant ZL_a = k * Z0 ./ beta; %analytic waveguide impedance % mode profile E- and H-field func_Ex = [num2str( n/b/unit) '*cos(' num2str(m*pi/a) '*x)*sin(' num2str(n*pi/b) '*y)']; func_Ey = [num2str(-m/a/unit) '*sin(' num2str(m*pi/a) '*x)*cos(' num2str(n*pi/b) '*y)']; func_Hx = [num2str(m/a/unit) '*sin(' num2str(m*pi/a) '*x)*cos(' num2str(n*pi/b) '*y)']; func_Hy = [num2str(n/b/unit) '*cos(' num2str(m*pi/a) '*x)*sin(' num2str(n*pi/b) '*y)']; disp([' Cutoff frequencies for this mode and wavguide is: ' num2str(fc/1e6) ' MHz']); if (f_start<fc) warning('openEMS:example','f_start is smaller than the cutofffrequency, this may result in a long simulation... '); end

## Set FDTD parameter and excitation time-signal FDTD = InitFDTD(numTS,1e-5);

FDTD = SetGaussExcite(FDTD,0.5*(f_start+f_stop),0.5*(f_stopf_start)); % boundary conditions BC = [0 0 0 0 3 3]; %pml in pos. and neg. z-direction FDTD = SetBoundaryCond(FDTD,BC);

Define the homogeneous mesh CSX = InitCSX(); mesh.x = SmoothMeshLines([0 a], mesh_res(1)); mesh.y = SmoothMeshLines([0 b], mesh_res(2)); mesh.z = SmoothMeshLines([0 length], mesh_res(3)); CSX = DefineRectGrid(CSX, unit,mesh);

Apply the mode profile excitation % xy-mode profile excitation located directly on top of pml (first 8 z-lines) CSX = AddExcitation(CSX,'excite',0,[1 1 0]); weight{1} = func_Ex; weight{2} = func_Ey; weight{3} = 0; CSX = SetExcitationWeight(CSX,'excite',weight); start=[mesh.x(1) mesh.y(1) mesh.z(8) ]; stop =[mesh.x(end) mesh.y(end) mesh.z(8) ]; CSX = AddBox(CSX,'excite',0 ,start,stop);

Define the mode profile voltage and currents probes %port 1 start = [mesh.x(1) mesh.y(1) mesh.z(15)]; stop = [mesh.x(end) mesh.y(end) mesh.z(15)]; CSX = AddProbe(CSX, 'ut1', 10, 1, [], 'ModeFunction',{func_Ex,func_Ey,0}); CSX = AddBox(CSX, 'ut1', 0 ,start,stop); CSX = AddProbe(CSX,'it1', 11, 1, [], 'ModeFunction',{func_Hx,func_Hy,0}); CSX = AddBox(CSX,'it1', 0 ,start,stop); %port 2 start = [mesh.x(1) mesh.y(1) mesh.z(end-14)]; stop = [mesh.x(end) mesh.y(end) mesh.z(end-14)]; CSX = AddProbe(CSX, 'ut2', 10, 1, [], 'ModeFunction',{func_Ex,func_Ey,0}); CSX = AddBox(CSX, 'ut2', 0 ,start,stop);

CSX = AddProbe(CSX,'it2', 11, 1, [], 'ModeFunction',{func_Hx,func_Hy,0}); CSX = AddBox(CSX,'it2', 0 ,start,stop); port_dist = mesh.z(end-14) - mesh.z(15);

Define a dump box using the HDF5 file format CSX = AddDump(CSX,'Et','FileType',1,'SubSampling','4,4,4'); start = [mesh.x(1) mesh.y(1) mesh.z(1)]; stop = [mesh.x(end) mesh.y(end) mesh.z(end)]; CSX = AddBox(CSX,'Et',0 , start,stop);

Save & Run the simulation Sim_Path = 'tmp'; Sim_CSX = 'rect_wg.xml'; [status, message, messageid] = rmdir(Sim_Path,'s'); [status, message, messageid] = mkdir(Sim_Path); WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX); RunOpenEMS(Sim_Path, Sim_CSX)

Post-Processing

Read all voltages and currents and calculate the incoming and reflected wave

using the known analytic waveguide impedance U = ReadUI({'ut1','ut2'},[Sim_Path '/'],freq); I = ReadUI({'it1','it2'},[Sim_Path '/'],freq); Exc = ReadUI('et',Sim_Path,freq); uf1 uf2 if1 if2 = = = = U.FD{1}.val./Exc.FD{1}.val; U.FD{2}.val./Exc.FD{1}.val; I.FD{1}.val./Exc.FD{1}.val; I.FD{2}.val./Exc.FD{1}.val; = = = = 0.5 0.5 0.5 0.5 * * * * ( ( ( ( uf1 if1 uf2 if2 + + + + if1 uf1 if2 uf2 .* ./ .* ./ ZL_a ZL_a ZL_a ZL_a ); ); ); );

## uf2_ref = uf2 - uf2_inc; if2_ref = if2_inc - if2;

Calculate & Plot the S-Parameter figure s11 = uf1_ref./uf1_inc; s21 = uf2_inc./uf1_inc; plot(freq*1e-6,20*log10(abs(s11)),'k-','Linewidth',2); xlim([freq(1) freq(end)]*1e-6); grid on; hold on; plot(freq*1e-6,20*log10(abs(s21)),'r--','Linewidth',2); l = legend('S_{11}','S_{21}','Location','Best'); set(l,'FontSize',12); ylabel('S-Parameter (dB)','FontSize',12); xlabel('frequency (MHz) \rightarrow','FontSize',12);

Calculate & Plot the FDTD extracted waveguide impedance figure ZL = uf1./if1; plot(freq*1e-6,real(ZL),'Linewidth',2); hold on; grid on; plot(freq*1e-6,imag(ZL),'r--','Linewidth',2); plot(freq*1e-6,ZL_a,'g-.','Linewidth',2); ylabel('ZL (\Omega)','FontSize',12); xlabel('frequency (MHz) \rightarrow','FontSize',12); xlim([freq(1) freq(end)]*1e-6); l = legend('\Re(Z_L)','\Im(Z_L)','Z_L analytic','Location','Best'); set(l,'FontSize',12);

Visualize the electric field in the time domain using matlab figure dump_file = [Sim_Path '/Et.h5']; PlotArgs.slice = {a/2*unit b/2*unit 0}; PlotArgs.pauseTime=0.01; PlotArgs.component=0; PlotArgs.Limit = 'auto'; PlotHDF5FieldData(dump_file, PlotArgs)

Results

## Waveguide scattering parameter

Modifications

Try different/multiple modes for excitation/detection Add an unsymmetrical dielectric material load to see a mode-conversion (multiple mode detection necessary) Try adding a periodic dielectric material to see a frequency selective reflection (Bragg reflections)