Code covered by the BSD License  

Highlights from
Analog Filter Design Toolbox

image thumbnail
from Analog Filter Design Toolbox by James Squire
GUI to design and simulate active (opamp) LP and HP Bessel, Butter, Cheby, and Elliptic filters.

GuiSpecifyFilter(varargin)
function varargout = GuiSpecifyFilter(varargin)
% GUISPECIFYFILTER M-file for GuiSpecifyFilter.fig
%      GUISPECIFYFILTER, by itself, creates a new GUISPECIFYFILTER or raises the existing
%      singleton*.
%
%      H = GUISPECIFYFILTER returns the handle to a new GUISPECIFYFILTER or the handle to
%      the existing singleton*.
%
%      GUISPECIFYFILTER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUISPECIFYFILTER.M with the given input arguments.
%
%      GUISPECIFYFILTER('Property','Value',...) creates a new GUISPECIFYFILTER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GuiSpecifyFilter_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GuiSpecifyFilter_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 GuiSpecifyFilter

% Last Modified by GUIDE v2.5 04-Jan-2004 12:08:26

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GuiSpecifyFilter_OpeningFcn, ...
                   'gui_OutputFcn',  @GuiSpecifyFilter_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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


% --- Executes just before GuiSpecifyFilter is made visible.
function GuiSpecifyFilter_OpeningFcn(hObject, eventdata, handles, varargin)
global strFilterObject
handles.output = hObject;
if isempty(strFilterObject)
   Utility_GetDefaultFilterObject;  % create global variable strFilterObject
end
SpecifyFilter_LoadStrFilterObject(handles) % makes the GUI reflect strFilterObject data
SpecifyFilter_LoadPicture(handles)
guidata(hObject, handles);

% --- Outputs from this function are returned to the command line.
function varargout = GuiSpecifyFilter_OutputFcn(hObject, eventdata, handles)

% Get default command line output from handles structure
varargout{1} = handles;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                      Menu Callbacks                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --------------------------------------------------------------------
function uimenuFileNew_Callback(hObject, eventdata, handles)
MenuFileNew(handles)

% --------------------------------------------------------------------
function uimenuFileOpen_Callback(hObject, eventdata, handles)
MenuFileOpen;
SpecifyFilter_LoadStrFilterObject(handles)

% --------------------------------------------------------------------
function uimenuFileSave_Callback(hObject, eventdata, handles)
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles)
MenuFileSave(handles)

% --------------------------------------------------------------------
function uimenuFileSaveas_Callback(hObject, eventdata, handles)
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);  
% save it, as well as save the new file name
MenuFileSaveAs(handles)

% --------------------------------------------------------------------
function uimenuFilePrint_Callback(hObject, eventdata, handles)
printdlg(handles.figSpecifyFilter)

% --------------------------------------------------------------------
function uimenuFileExit_Callback(hObject, eventdata, handles)
delete(handles.figSpecifyFilter)

% --------------------------------------------------------------------
function uimenuSpecifyOrderrequired_Callback(hObject, eventdata, handles)
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiFilterOrder

% --------------------------------------------------------------------
function uimenuAnalyzeListtransferfunction_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiListTransferFunction')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiListTransferFunction

% --------------------------------------------------------------------
function uimenuAnalyzePolezeroplot_Callback(hObject, eventdata, handles)
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
MenuAnalyzePoleZeroPlot

% --------------------------------------------------------------------
function uimenuAnalyzeImpulseresponse_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiTimeResponse')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiTimeResponse('Impulse')

% --------------------------------------------------------------------
function uimenuAnalyzeStepresponse_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiTimeResponse')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiTimeResponse('Step')

% --------------------------------------------------------------------
function uimenuAnalyzeRampresponse_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiTimeResponse')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiTimeResponse('Ramp')

% --------------------------------------------------------------------
function uimenuAnalyzeParabolaresponse_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiTimeResponse')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiTimeResponse('Parabola')

% --------------------------------------------------------------------
function uimenuAnalyzeListfrequencyresponse_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiListFrequencyResponse')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiListFrequencyResponse

% --------------------------------------------------------------------
function uimenuAnalyzePlotfrequencyresponse_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiPlotFrequencyResponse')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiPlotFrequencyResponse

% --------------------------------------------------------------------
function uimenuAnalyzeUserinputresponse_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiFilterUserData')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiPlotUserData

% --------------------------------------------------------------------
function uimenuBuild_Callback(hObject, eventdata, handles)
DeleteMeIfIExistAlready('uiBuildActiveCircuit')
DeleteMeIfIExistAlready('uiBuildStageInformation')
% move the GUI data into the global variable strFilterObject
SpecifyFilter_SaveStrFilterObject(handles);
GuiBuildActiveCircuit

% --------------------------------------------------------------------
function uimenuHelpUsermanual_Callback(hObject, eventdata, handles)
open('Analog Filter Designer.pdf')

% --------------------------------------------------------------------
function uimenuHelpContext_Callback(hObject, eventdata, handles)
SpecifyFilter_HelpContext

% --------------------------------------------------------------------
function uimenuHelpAbout_Callback(hObject, eventdata, handles)
MenuHelpAbout

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                  GUI Control Callbacks                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in uipmPurpose.
function uipmPurpose_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];
SpecifyFilter_LoadPicture(handles)

% --- Executes on selection change in uipmType.
function uipmType_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];
SpecifyFilter_TypeChange(handles) % dims/undims Gp and Gs as needed
SpecifyFilter_LoadPicture(handles)

% --- Executes on selection change in uipmOrder.
function uipmOrder_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];
SpecifyFilter_LoadPicture(handles)

% --- Executes on selection change in uitxFc.
function uitxFc_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];
if str2double(get(hObject,'String')) <= 0
    errordlg('The cutoff frequency fc must be greater than zero','Error')
    set(hObject,'String','100')
end

% --- Executes on selection change in uipmFcUnits.
function uipmFcUnits_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];

% --- Executes on selection change in uitxGp.
function uitxGp_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];
if str2double(get(hObject,'String')) <= 0
    errordlg('The parameter Gp must be greater than zero','Error')
    set(hObject,'String','100')
end

% --- Executes on selection change in uitxGs.
function uitxGs_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];
if str2double(get(hObject,'String')) <= 0
    errordlg('The parameter Gs must be greater than zero','Error')
    set(hObject,'String','100')
end

% --- Executes on selection change in uitxGain.
function uitxGain_Callback(hObject, eventdata, handles)
global strFilterObject
global strCircuit
strCircuit=[]; strFilterObject.vPoles1=[]; strFilterObject.vZeros1=[];strFilterObject.fK1=[];
num=str2double(get(hObject,'String'));
if isnan(num)
    errordlg('Enter a nun-zero number (usually 1) for the filter''s passband gain.','Error')
    num=1;
elseif num == 0
    errordlg('The passband gain must be non-zero','Error')
    num=1;
elseif num < 0
    warndlg('You may specify a passband phase inversion when constructing a circuit implementation (see the ''Build'' menu)','Warning')
    num=abs(num);
end
set(hObject,'String',sprintf('%0.4g',num))
set(handles.uitxGainDb,'String',sprintf('= %0.4gdB = "PB" in graph above',20*log10(num)))

% --- Executes when user attempts to close figSpecifyFilter.
function figSpecifyFilter_CloseRequestFcn(hObject, eventdata, handles)
t=questdlg('This is the primary window of Analog Filter Designer.  Closing this window will close the entire program.  Are you sure you want to quit ?','Confirm Exit ','Yes','No','Yes');
t=lower(t(1));
if isequal(t,'y')
    delete(hObject);
end
clear global strFilterObject
clear global strCircuit
%delete(hObject);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                    Helper Functions                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function DeleteMeIfIExistAlready(sTagName)
% deletes one of Analog Filter's helper GUI's if it already exists
% This prevents new data being written on top of already-existing UI
% It will search for GUIs with the figure sTagName and delete if they exist.
set(0,'ShowHiddenHandles','On')
vHandlesList=get(0,'children');
cHandlesList=get(vHandlesList,'Tag');
if length(vHandlesList)==1 % a single handle tag is returned as a string, not a cell array
    cHandlesList={cHandlesList}; 
end 
for i=1:length(cHandlesList)
    if strcmp(cHandlesList{i}, sTagName)
        delete(vHandlesList(i))
        break
    end
end
set(0,'ShowHiddenHandles','Off')

Contact us at files@mathworks.com