Code covered by the BSD License  

Highlights from
GUI for Rational Fitting

image thumbnail

GUI for Rational Fitting

by

 

Use this GUI for fitting 2-port S-parameters using the functions from RF Toolbox

simple_weight(varargin)
%%Copyright 2013 The MathWorks, Inc
function varargout = simple_weight(varargin)
% SIMPLE_WEIGHT MATLAB code for simple_weight.fig
%      SIMPLE_WEIGHT, by itself, creates a new SIMPLE_WEIGHT or raises the existing
%      singleton*.
%
%      H = SIMPLE_WEIGHT returns the handle to a new SIMPLE_WEIGHT or the handle to
%      the existing singleton*.
%
%      SIMPLE_WEIGHT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SIMPLE_WEIGHT.M with the given input arguments.
%
%      SIMPLE_WEIGHT('Property','Value',...) creates a new SIMPLE_WEIGHT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before simple_weight_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to simple_weight_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help simple_weight

% Last Modified by GUIDE v2.5 05-Mar-2013 12:59:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @simple_weight_OpeningFcn, ...
                   'gui_OutputFcn',  @simple_weight_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% Open the Weight GUI, initialize the weights to ones
function simple_weight_OpeningFcn(hObject, eventdata, handles, varargin)
%handles.output = hObject;
handles.Freq = varargin{2};
handles.S = varargin{3};
% Update handles structure
handles.weight = ones(1,length(handles.Freq));
handles.line1 = line('Xdata',handles.Freq*1e-6,'Ydata',handles.weight);
set(handles.line1,'LineWidth', 2);
set(handles.line1,'Color', [0 0 1])
xlabel('MHz');
ylabel('Weighting Vector');
guidata(hObject, handles);

% Return the Weights GUI identifier
function varargout = simple_weight_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.weight;

% Callback for the user to edit the custom weigths
function weight_edit_Callback(hObject, eventdata, handles)
Freq = handles.Freq;
X = abs(handles.S);
weight_in = (get(handles.weight_edit,'String'));
weight_in = strrep(weight_in,'x','X'); % allow upper and lower x input
if strcmp(upper(weight_in),'UNIFORM') % Uniform weigths
   handles.weight = ones(1,length(handles.Freq));
else % Custom weights
    try
       weight = abs(eval(weight_in));
       % Check if the weights are non-finite
       if( sum(isinf(weight)) || sum(isnan(weight)))
           errordlg('The weigths should be finite');
       end
       if length(weight) == 1 % check if the weights is a scalar instead of a vector
           handles.weight = weight*ones(1,length(X));
       else
           handles.weight = weight;
       end
    catch err % reset to "auto" 
       disp(err)
       handles.weight = ones(1,length(handles.Freq));
       set(handles.weight_edit,'String','uniform')
    end
end
% Plot the weigths
set(handles.line1,'Xdata',handles.Freq);
set(handles.line1,'Ydata',handles.weight);
% Export the weights
guidata(hObject, handles);

% Callback executed when the Weight GUI is closed
function WeightGUI_CloseRequestFcn(hObject, eventdata, handles)
delete(hObject);

% Function to update frequency and S data
function set_FandSxy(varargin)
% Fing the Weight GUI
h_fig = findobj('Tag','WeightGUI');
handles = guidata(h_fig);
% Update the data in the GUI structure
handles.Freq = varargin{2};
handles.S = varargin{3};
guidata(h_fig,handles);
% Recompute the weights
weight_edit_Callback(handles.weight_edit,[],handles);

function varargout = get_weight()
h_fig = findobj('Tag','WeightGUI');
handles = guidata(h_fig);
varargout{1} = handles.weight; % I have no idea why this needs to be set
simple_weight_OutputFcn(h_fig, [], handles);

% GUI create functions - nothing to say -
function weight_edit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

Contact us