Code covered by the BSD License  

Highlights from
input impedance converter : S11, Z, Y (1 complex value)

image thumbnail

input impedance converter : S11, Z, Y (1 complex value)

by

 

03 Jun 2005 (Updated )

reflection coef. converter: S11 -impedance -admittance -Return Loss -VSWR; graphical & text input

SZYconv.m
% Complex Impedance Convertor with graphic interface
%
% see Contents.m for full help
clear; clc;
close('all');

WPosition = [ 10 10 820 600];
figNr = figure('NumberTitle', 'off', ...
    'Position', WPosition, ...
    'Resize' , 'off', ...
    'Name', 'Impedance Converter');
figBckgndCol = get(figNr,'color'); % and duplicate it for the labels...

sq = min(WPosition(4), WPosition(3));
yxratio = WPosition(4)/WPosition(3);
BtnAreaW = WPosition(3)*(1-yxratio);
BtnAreaH = WPosition(4);

AxesPosition = [ 0 0 yxratio 1];
set(figNr,'defaultaxesposition', AxesPosition );
set(figNr, 'WindowButtonDownFcn', '[Re, Im] = ginput(1);[out] = convF(''ri'', Re, Im); UpdateLs;' );

polar(.01, .99, 'k');
hold on;

TextFontWeight = 'bold';

%----------------------------------------
% start initializing buttons
%----------------------------------------
leftEdge = 5;
rightEdge = 1;
upEdge = 1;
downEdge = 1;
NoButtons = [2 10]; % -- first y, second x...
btnW = (BtnAreaW - leftEdge - rightEdge)/NoButtons(1);
btnH = (BtnAreaH - upEdge - downEdge)/NoButtons(2);
margin = 20;
ValOff = [WPosition(4) 0 0 10];
LabelOff = [WPosition(4) 0 0 0];

EditBkgColour = [1 1 1]; % future colour of edit fields bkgd


%---------------------------------------------------
% Create the GammaRE, GammaIM buttons (1,9), (2,9)
%---------------------------------------------------

LabelStr = '0.33';
Re = .33;
BtnRank = [1 9]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hRe=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Enable','off', ...
    'Callback', 'Re = str2num(get(hRe, ''String''));[out] = convF(''ri'', Re, Im);UpdateLs;' );

LabelStr = '0.45';
Im = .45;
BtnRank = [2 9]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hIm=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Enable','off', ...
    'Callback', 'Im = str2num(get(hIm, ''String''));[out] = convF(''ri'', Re, Im);UpdateLs;' );

LabelStr = 'gamma R';
BtnRank = [1 10]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

LabelStr = 'gamma I';
BtnRank = [2 10]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

%---------------------------------------------------
% Create the GammaRad, GammaAng buttons (1,7), (2,7)
%---------------------------------------------------

LabelStr = '0.56';
Rad = .56;
BtnRank = [1 7]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hRad=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Enable','off', ...
    'Callback', 'Rad = str2num(get(hRad, ''String''));[out] = convF(''ma'', Rad, Ang);UpdateLs;' );


LabelStr = '36.25';
Ang = 36.25;
BtnRank = [2 7]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hAng=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Enable','off', ...
    'Callback', 'AngStr = get(hAng, ''String''); Ang = str2num(AngStr(1:size(AngStr,2)) );[out] = convF(''ma'', Rad, Ang);UpdateLs;' );


LabelStr = 'radius';
BtnRank = [1 8]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

LabelStr = 'angle <deg>';
BtnRank = [2 8]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

%---------------------------------------------------
% Create the ZRE, ZIM buttons (1,5), (2,5)
%---------------------------------------------------

LabelStr = '59.85';
ReZ = 59.85;
BtnRank = [1 5]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hReZ=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Callback', 'ReStr = get(hReZ, ''String''); ReZ = str2num(ReStr(1:size(ReStr,2)) );[out] = convF(''z'', ReZ, ImZ);UpdateLs;');

LabelStr = '69.08 ohms';
ImZ = 69.08;
BtnRank = [2 5]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hImZ=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Enable','off', ...
    'Callback', 'ImStr = get(hImZ, ''String''); ImZ = str2num(ImStr(1:size(ImStr,2)) );[out] = convF(''z'', ReZ, ImZ);UpdateLs;');

LabelStr = 'Re[Z] <ohm>';
BtnRank = [1 6]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

LabelStr = 'Im[Z] <ohm>';
BtnRank = [2 6]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

%---------------------------------------------------
% Create the YRE, YIM buttons (1,3), (2,3)
%---------------------------------------------------

mS_factor = 1000;
Callback_Y = 'ReY = str2num(get(hReY, ''String'')); ImY = str2num(get(hImY, ''String'')); [out] = convF(''y'', ReY/mS_factor, ImY/mS_factor);  UpdateLs;';
LabelStr = '7'; ReY = 7e-3;
BtnRank = [1 3]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hReY=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Enable','off', ...
    'Callback', Callback_Y);

LabelStr = '-9.1';
ImY = -9.1e-3;
BtnRank = [2 3]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hImY=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black' , ...
    'Enable','off', ...
    'Callback', Callback_Y);

LabelStr = 'Re[Y] <mS>';
BtnRank = [1 4]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

LabelStr = 'Im[Y] <mS>';
BtnRank = [2 4]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

%---------------------------------------------------
% Create the RL, VSWR buttons (2,2), (2,1)
%---------------------------------------------------

LabelStr = '-5.06';
BtnRank = [2 2]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hRL=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black',...
    'Callback', 'RL = str2num(get(hRL, ''String'')); out = convF(''rl'', RL, Ang); UpdateLs');

LabelStr = '3.52';
BtnRank = [2 1]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + ValOff;
hVSWR=uicontrol( ...
    'Style','edit', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', 'white', ...
    'ForegroundColor', 'black',...
    'Callback', 'VSWR = str2num(get(hVSWR, ''String'')), out = convF(''wswr'', VSWR, Ang); UpdateLs');


LabelStr = 'RL <dB>';
BtnRank = [1 2]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

LabelStr = 'VSWR';
BtnRank = [1 1]; % [xy] position in the button array
BtnPos = [leftEdge+(BtnRank(1)-1)*btnW downEdge+(BtnRank(2)-1)*btnH btnW-margin btnH-margin];
BtnPos = BtnPos + LabelOff;
hL=uicontrol( ...
    'Style','text', ...
    'Units','pixels', ...
    'Position', BtnPos, ...
    'String', LabelStr, ...
    'BackgroundColor', figBckgndCol, ...
    'ForegroundColor', 'white' , ...
    'Callback', ' ' );

set([hRe hIm hRad hAng hReZ hImZ hReY hImY hRL hVSWR], 'Enable', 'on' );

Contact us