diff --git a/matlab/AddMSLPort.m b/matlab/AddMSLPort.m index 10ebdf5..3b6314d 100644 --- a/matlab/AddMSLPort.m +++ b/matlab/AddMSLPort.m @@ -122,6 +122,13 @@ else direction = -1; end +% direction of propagation +if stop(idx_height)-start(idx_height) > 0 + upsidedown = +1; +else + upsidedown = -1; +end + % create the metal/material for the MSL MSL_start = start; MSL_stop = stop; @@ -177,7 +184,7 @@ i2_stop(idx_prop) = i2_start(idx_prop); % create the probes name = ['port_ut' num2str(portnr) 'A']; % weight = sign(stop(idx_height)-start(idx_height)) -weight = -1; +weight = upsidedown; CSX = AddProbe( CSX, name, 0, weight ); CSX = AddBox( CSX, name, prio, v1_start, v1_stop ); name = ['port_ut' num2str(portnr) 'B']; @@ -196,13 +203,18 @@ CSX = AddProbe( CSX, name, 1, weight ); CSX = AddBox( CSX, name, prio, i2_start, i2_stop ); % create port structure +port.LengthScale = 1; +if ((CSX.ATTRIBUTE.CoordSystem==1) && (idx_prop==2)) + port.LengthScale = MSL_stop(idx_height); +end port.nr = portnr; port.drawingunit = CSX.RectilinearGrid.ATTRIBUTE.DeltaUnit; -port.v_delta = diff(meshlines); -port.i_delta = diff( meshlines(1:end-1) + diff(meshlines)/2 ); +port.v_delta = diff(meshlines)*port.LengthScale; +port.i_delta = diff( meshlines(1:end-1) + diff(meshlines)/2 )*port.LengthScale; port.direction = direction; port.excite = 0; -port.measplanepos = abs(v2_start(idx_prop) - start(idx_prop)); +port.measplanepos = abs(v2_start(idx_prop) - start(idx_prop))*port.LengthScale; +% port % create excitation % excitation of this port is enabled diff --git a/matlab/calcPort.m b/matlab/calcPort.m index f6a5b9b..1e1dbb8 100644 --- a/matlab/calcPort.m +++ b/matlab/calcPort.m @@ -1,5 +1,5 @@ function [port] = calcPort( port, SimDir, f, varargin) -% [port] = calcPort( port, SimDir, f, [ref_ZL], [ref_shift]) +% [port] = calcPort( port, SimDir, f, varargin) % % Calculate voltages and currents, the propagation constant beta % and the characteristic impedance ZL of the given port. @@ -11,12 +11,13 @@ function [port] = calcPort( port, SimDir, f, varargin) % f: frequency vector for DFT % % variable input: -% 'RefImpedance': use a given reference impedance to calculate inc and -% ref voltages and currents -% default is given port or calculated line impedance -% 'RefPlaneShift': use a given reference plane shift from port beginning -% for a desired phase correction -% default is the measurement plane +% 'RefImpedance': - use a given reference impedance to calculate inc and +% ref voltages and currents +% - default is given port or calculated line impedance +% 'RefPlaneShift': - use a given reference plane shift from port beginning +% for a desired phase correction +% - default is the measurement plane +% - the plane shift has to be given in drawing units! % % output: % port.f the given frequency fector @@ -90,9 +91,10 @@ ZL = sqrt(Et .* dEt ./ (Ht .* dHt)); % reference plane shift (lossless) if ~isnan(ref_shift) - % renormalize the shift to the measurement plane - ref_shift = ref_shift - port.measplanepos * port.drawingunit; -% ref_shift = ref_shift * port.drawingunit; + ref_shift = ref_shift * port.LengthScale; + % shift to the beginning of MSL + ref_shift = ref_shift - port.measplanepos; + ref_shift = ref_shift * port.drawingunit; % store the shifted frequency domain waveforms phase = real(beta)*ref_shift;