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.

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

% Last Modified by GUIDE v2.5 27-Dec-2003 17:44:28

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GuiBuildActiveCircuit_OpeningFcn, ...
                   'gui_OutputFcn',  @GuiBuildActiveCircuit_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 GuiBuildActiveCircuit is made visible.
function GuiBuildActiveCircuit_OpeningFcn(hObject, eventdata, handles, varargin)

global strFilterObject
global strCircuit

% Load data
if isempty(strFilterObject)
    temp=load('matlab');
    disp([mfilename ' called in debug mode using matlab.mat datafile'])
    strFilterObject = temp.strFilterObject;
else
    strFilterObject=Utility_zpk(strFilterObject); % find poles, zeros
    % reset the fK1, vPoles1, vZeros1
    % strFilterObject.fK1=[];
    % strFilterObject.vPoles1=[];
    % strFilterObject.vZeros1=[];
end

% fill out the initial circuit structure and build graphics
if isempty(strCircuit)  % todo: must reset strCircuit if strFilterObject changed
    strCircuit = BuildCircuit_Zpk2Circuit(strFilterObject);
end
handles.strCircuit = strCircuit;
UpdateTopThirdGUI(handles)
UpdateMiddleThirdGUI(handles)
UpdateBottomThirdGUI(handles)
sStatus = { ...
        'Select each stage, and if desired, change circuit schematic, component tolerances, and component values.', ...
        'You must choose a non-exact component tolerance and then close this window to enable "use toleranced components" in other windows.'};
set(handles.uitxStatus,'String',sStatus)

% Choose default command line output for GuiBuildActiveCircuit
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);


% --- Outputs from this function are returned to the command line.
function varargout = GuiBuildActiveCircuit_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               Callbacks in the Upper Third of Display                     %
%             uipmStage, uipmPolarity, uipmRTol, uipmCTol                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function uipmStage_Callback(hObject, eventdata, handles)
UpdateTopThirdGUI(handles)
UpdateMiddleThirdGUI(handles)
UpdateBottomThirdGUI(handles)

function uipmPolarity_Callback(hObject, eventdata, handles)
global strCircuit
switch get(hObject,'Value')
    case 1, strCircuit.sPolarity = 'd'; % don't care
    case 2, strCircuit.sPolarity = 'n'; % non-inverting
    case 3, strCircuit.sPolarity = 'i'; % inverting
end
strCircuit = BuildCircuit_LastStage(strCircuit);
% the change in polarity may have removed a previous inverting gain stage, so remove its z1,p1,k1
nStages=strCircuit.nStages;
if nStages<5
    strCircuit.vStage(nStages+1).z1=[];
    strCircuit.vStage(nStages+1).p1=[];
    strCircuit.vStage(nStages+1).k1=[];
end
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(strCircuit)
handles.strCircuit = strCircuit;
guidata(gcbo,handles)
UpdateTopThirdGUI(handles)   % maybe viewing last stage, or a stage was deleted/added
UpdateMiddleThirdGUI(handles)
UpdateBottomThirdGUI(handles)

function uipmRTol_Callback(hObject, eventdata, handles)
global strCircuit
switch get(hObject,'Value')
    case 1, nRTol = 0;
    case 2, nRTol = 1;
    case 3, nRTol = 5;
end
strCircuit.nRTol = nRTol;
nCTol = strCircuit.nCTol;
for i=1:strCircuit.nBiquads
    strCircuit.vStage(i) = BuildCircuit_UpdateComponents(strCircuit.vStage(i),nRTol,nCTol);
end
% to get a close-as-possible overall gain, refigure last stage.  LastStage calls UpdateComponent
strCircuit = BuildCircuit_LastStage(strCircuit);
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(strCircuit)
handles.strCircuit=strCircuit;
guidata(gcbo,handles)
UpdateTopThirdGUI(handles)   % maybe viewing last stage, or a stage was deleted/added
UpdateMiddleThirdGUI(handles)
UpdateBottomThirdGUI(handles)

function uipmCTol_Callback(hObject, eventdata, handles)
global strCircuit
switch get(hObject,'Value')
    case 1, nCTol = 0;
    case 2, nCTol = 1;
    case 3, nCTol = 5;
    case 4, nCTol = 10;
end
strCircuit.nCTol = nCTol;
nRTol = strCircuit.nRTol;
for i=1:strCircuit.nBiquads
    strCircuit.vStage(i) = BuildCircuit_UpdateComponents(strCircuit.vStage(i),nRTol,nCTol);
end
% to get a close-as-possible overall gain, refigure last stage.  LastStage calls UpdateComponent
strCircuit = BuildCircuit_LastStage(strCircuit);
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(strCircuit)
handles.strCircuit=strCircuit;
guidata(gcbo,handles)
UpdateTopThirdGUI(handles)   % maybe viewing last stage, or a stage was deleted/added
UpdateMiddleThirdGUI(handles)
UpdateBottomThirdGUI(handles)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                 Callbacks in the Middle Third of Display                  %
%                             uiaxCircuit, uitxStage                        %
%                   uipmSelectedCircuit, uitxRecommendedCircuit             %
%                           uipbDetails, uipbPrint                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function uipmSelectedCircuit_Callback(hObject, eventdata, handles)
global strCircuit
% get the new title from the pm
contents = get(hObject,'String');
nSelections = length(contents);
if nSelections == 1
    return
end
schTitle = contents{get(hObject,'Value')};
% determine the new schName from the schTitle (which is generic) and the sPurpose
curStage = get(handles.uipmStage,'Value');
% calculation function below
strCircuit = BuildCircuit_SelectCircuit(strCircuit, curStage, schTitle);
% update the gui and save the new data
handles.strCircuit = strCircuit;
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(strCircuit) % may have changed the polarity of k1
UpdateTopThirdGUI(handles) % may have changed the number of stages required
UpdateMiddleThirdGUI(handles)
UpdateBottomThirdGUI(handles)
guidata(gcbo,handles)

function uipbDetails_Callback(hObject, eventdata, handles)
curStage = get(handles.uipmStage,'Value');
GuiBuildStageInformation(handles.strCircuit.vStage(curStage),curStage)

function uipbPrint_Callback(hObject, eventdata, handles)
printdlg(handles.uiBuildActiveCircuit)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                  Components                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function uitxCa_Callback(hObject, eventdata, handles)
% get the new Ca and setup variables
nCurStage = get(handles.uipmStage,'Value');
strStage = handles.strCircuit.vStage(nCurStage);
nRTol = handles.strCircuit.nRTol;
nCTol = handles.strCircuit.nCTol;
componentName = 'Ca';
componentValue = str2num(get(handles.uitxCa,'String'))*10^(get(handles.uipmCa,'Value')*3-15);
% calculation function below
handles.strCircuit.vStage(nCurStage) = BuildCircuit_UpdateComponents(handles.strCircuit.vStage(nCurStage),nRTol,nCTol,componentName,componentValue);
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(handles.strCircuit)
% update the gui and save the new data
UpdateBottomThirdGUI(handles)
guidata(gcbo,handles)

function uipmCa_Callback(hObject, eventdata, handles)
uitxCa_Callback(hObject, eventdata, handles)

function uitxCb_Callback(hObject, eventdata, handles)
% get the new Cb and setup variables
nCurStage = get(handles.uipmStage,'Value');
strStage = handles.strCircuit.vStage(nCurStage);
nRTol = handles.strCircuit.nRTol;
nCTol = handles.strCircuit.nCTol;
componentName = 'Cb';
componentValue = str2num(get(handles.uitxCb,'String'))*10^(get(handles.uipmCb,'Value')*3-15);
% calculation function below
handles.strCircuit.vStage(nCurStage) = BuildCircuit_UpdateComponents(handles.strCircuit.vStage(nCurStage),nRTol,nCTol,componentName,componentValue);
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(handles.strCircuit)
% update the gui and save the new data
UpdateBottomThirdGUI(handles)
guidata(gcbo,handles)

function uipmCb_Callback(hObject, eventdata, handles)
uitxCb_Callback(hObject, eventdata, handles)

function uitxRa_Callback(hObject, eventdata, handles)
% get the new Ra and setup variables
nCurStage = get(handles.uipmStage,'Value');
strStage = handles.strCircuit.vStage(nCurStage);
nRTol = handles.strCircuit.nRTol;
nCTol = handles.strCircuit.nCTol;
componentName = 'Ra';
componentValue = str2num(get(handles.uitxRa,'String'))*10^(get(handles.uipmRa,'Value')*3-3);
% calculation function below
handles.strCircuit.vStage(nCurStage) = BuildCircuit_UpdateComponents(handles.strCircuit.vStage(nCurStage),nRTol,nCTol,componentName,componentValue);
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(handles.strCircuit)
% update the gui and save the new data
UpdateBottomThirdGUI(handles)
guidata(gcbo,handles)

function uipmRa_Callback(hObject, eventdata, handles)
uitxRa_Callback(hObject, eventdata, handles)

function uitxRb_Callback(hObject, eventdata, handles)
% get the new Ra and setup variables
nCurStage = get(handles.uipmStage,'Value');
strStage = handles.strCircuit.vStage(nCurStage);
nRTol = handles.strCircuit.nRTol;
nCTol = handles.strCircuit.nCTol;
componentName = 'Rb';
componentValue = str2num(get(handles.uitxRb,'String'))*10^(get(handles.uipmRb,'Value')*3-3);
% calculation function below
handles.strCircuit.vStage(nCurStage) = BuildCircuit_UpdateComponents(handles.strCircuit.vStage(nCurStage),nRTol,nCTol,componentName,componentValue);
% determine the overall filter Z1,P1, and k1 directly into the global variable strFilterObject 
UpdateFilter_Z1P1k1(handles.strCircuit)
% update the gui and save the new data
UpdateBottomThirdGUI(handles)
guidata(gcbo,handles)

function uipmRb_Callback(hObject, eventdata, handles)
uitxRCb_Callback(hObject, eventdata, handles)



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                 DrawStages                                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function DrawStages(nStages,nSelected,hax)
ARROW = 35;
ARROWSHORT = 20;
BOX = 70;
XT = 25;
axes(hax)
hold off
cla
set(hax,'Units','pixels')
axPosition=get(hax,'Position');
xStart = axPosition(3)/2 - nStages*(BOX+ARROW)/2 - ARROWSHORT -XT/2;
DrawText(xStart,'x(t)')
hold on
DrawArrow(xStart+XT,ARROWSHORT)
for i=1:nStages
    DrawBox(xStart+XT+ARROWSHORT+(i-1)*(ARROW+BOX),BOX,sprintf('Stage %g',i),nSelected==i)
end
for i=1:nStages-1
    DrawArrow(xStart+XT+ARROWSHORT+i*BOX+(i-1)*ARROW,ARROW)
end
DrawArrow(xStart+XT+ARROWSHORT+nStages*BOX+(nStages-1)*ARROW,ARROWSHORT)
DrawText(xStart+XT+2*ARROWSHORT+nStages*BOX+(nStages-1)*ARROW+5,'y(t)')
set(gca,'XLim',[0 axPosition(3)])
set(gca,'YLim',[0 axPosition(4)])
set(gca,'TickLength',[0 0])
set(gca,'XTick',[])
set(gca,'YTick',[])
hold off

function DrawBox(x,width,label,highlight)
HEIGHT = 30;
YSTART = 10;
if nargin==2 || ~highlight % thin blue box
    color = [0 0 1];
    thickness = 1;
else                      % thick red box
    color = [1 0 0];
    thickness = 1.5;
end
vx=[x x+width x+width x x];
vy=[YSTART YSTART YSTART+HEIGHT YSTART+HEIGHT YSTART];
plot(vx,vy,'Color',color,'LineWidth',thickness)
hold on
text(x+width/2-20,YSTART+HEIGHT/2,label);

function DrawArrow(x,len)
ARROWLEN = 5;
YSTART = 25;
vx = x+[0 len len-ARROWLEN len len-ARROWLEN];
vy = YSTART+[0 0 ARROWLEN 0 -ARROWLEN];
plot(vx,vy,'k','LineWidth',1)

function DrawText(x,label)
text(x,25,label)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                             UpdateTopThirdGUI                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function UpdateTopThirdGUI(handles)
global strFilterObject
global strCircuit
% create the figure title bar
set(handles.uiBuildActiveCircuit,'Name',strFilterObject.sTitle)
% draw the boxes
curStage = get(handles.uipmStage,'Value');
DrawStages(strCircuit.nStages,curStage,handles.uiaxStage)
% error check to make sure a stage was not deleted making current stage to edit non-existant
maxStage = strCircuit.nStages;
if curStage > maxStage
    if curStage==1
        error('Zero or negative maxStage')
    else
        curStage = maxStage;
        set(handles.uipmStage,'Value',curStage);
    end
end
% fill the popup "stage to edit" with the correct number of choices
tString={};
for i=1:maxStage
    tString{i}=num2str(i);
end
tString=tString';
set(handles.uipmStage,'String',tString)
% set the passband polarity popup box correctly
sPolarity = strCircuit.sPolarity;
switch sPolarity
    case 'd', set(handles.uipmPolarity,'Value',1)
    case 'n', set(handles.uipmPolarity,'Value',2)
    case 'i', set(handles.uipmPolarity,'Value',3)
end
% set the resistor tolerance popup box correctly
nRTol=strCircuit.nRTol;
switch nRTol
    case 0, set(handles.uipmRTol,'Value',1)
    case 1, set(handles.uipmRTol,'Value',2)
    case 5, set(handles.uipmRTol,'Value',3)
end
% set the capacitor tolerance popup box correctly
nCTol=strCircuit.nCTol;
switch nCTol
    case 0,  set(handles.uipmCTol,'Value',1)
    case 1,  set(handles.uipmCTol,'Value',2)
    case 5,  set(handles.uipmCTol,'Value',3)
    case 10, set(handles.uipmCTol,'Value',4)
end
% Set the title of the middle third of figure
set(handles.uitxStage,'String',sprintf('Stage %g',curStage))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           UpdateMiddleThirdGUI                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draws the schematic and grays out unused boxes in bottom third
function UpdateMiddleThirdGUI(handles)
% load pictures of schematics
persistent strGraphic
if isempty(strGraphic)
    t=load('BuildCircuit.mat');
    strGraphic = t.strGraphic;
end
% display curStage schematic
curStage = get(handles.uipmStage,'Value');
axes(handles.uiaxCircuit)
schName = lower(handles.strCircuit.vStage(curStage).schName);
hImage = image(strGraphic.(schName), 'Parent', handles.uiaxCircuit);
% fix the display details
set(handles.uiaxCircuit, ...
    'Visible', 'off', ...
    'YDir'   , 'reverse'       , ...
    'XLim'   , get(hImage,'XData'), ...
    'YLim'   , get(hImage,'YData')  ...
    );
set(handles.uiBuildActiveCircuit,'Colormap',gray(16))
% fill in "selected circuit" box with options
schName = handles.strCircuit.vStage(curStage).schName;
sPurpose = handles.strCircuit.sPurpose;
curChoice = handles.strCircuit.vStage(curStage).schTitle;
curRec = handles.strCircuit.vStage(curStage).recTitle;
switch schName(1:2)
    case {'ZO','SO'}
        vcStrings = {curChoice};
    otherwise
        switch sPurpose
            case 'LP'
                vcStrings = {'Sallen-Key','Multiple Feedback','Ackerberg-Mossberg (+)','Ackerberg-Mossberg (-)'};
            case 'HP'
                vcStrings = {'Sallen-Key','Ackerberg-Mossberg'};
            case 'Notch'
                vcStrings = {'Multiple Feedback','Ackerberg-Mossberg'};
            otherwise
                error('Unidentified schematic name and purpose')
        end
end
set(handles.uipmSelectedCircuit,'String',vcStrings);
% fill in "selected circuit" box with current choice, allowing for possible spelling error
for i=1:length(vcStrings)
    index(i)=isequal(curChoice,vcStrings{i});
end
[dummy,i] = max(index);
set(handles.uipmSelectedCircuit,'Value',i)
% fill in "recommended circuit" box
set(handles.uitxRecommendedCircuit,'String',curRec)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           UpdateBottomThirdGUI                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function UpdateBottomThirdGUI(handles)
curStage = get(handles.uipmStage,'Value');
nCSelect = length(handles.strCircuit.vStage(curStage).vfCSelect);
nRSelect = length(handles.strCircuit.vStage(curStage).vfRSelect);
nCCalc = length(handles.strCircuit.vStage(curStage).vfCCalc);
nRCalc = length(handles.strCircuit.vStage(curStage).vfRCalc);
% gray out unused boxes
switch nCSelect
    case 0
        set(handles.uitxCa,'Enable','off'); set(handles.uitxCa,'String','0');
        set(handles.uipmCa,'Enable','off'); set(handles.uipmCa,'Value',1);
        set(handles.uitxCb,'Enable','off'); set(handles.uitxCb,'String','0');
        set(handles.uipmCb,'Enable','off'); set(handles.uipmCb,'Value',1);
    case 1
        set(handles.uitxCa,'Enable','on');  set(handles.uitxCa,'String',handles.strCircuit.vStage(curStage).csCSelectMan{1})
        set(handles.uipmCa,'Enable','on');  set(handles.uipmCa,'Value',handles.strCircuit.vStage(curStage).vnCSelectExp(1)/3+5)
        set(handles.uitxCb,'Enable','off'); set(handles.uitxCb,'String','0');
        set(handles.uipmCb,'Enable','off'); set(handles.uipmCb,'Value',1);
    case 2
        set(handles.uitxCa,'Enable','on');  set(handles.uitxCa,'String',handles.strCircuit.vStage(curStage).csCSelectMan{1})
        set(handles.uipmCa,'Enable','on');  set(handles.uipmCa,'Value',handles.strCircuit.vStage(curStage).vnCSelectExp(1)/3+5)
        set(handles.uitxCb,'Enable','on');  set(handles.uitxCb,'String',handles.strCircuit.vStage(curStage).csCSelectMan{2})
        set(handles.uipmCb,'Enable','on');  set(handles.uipmCb,'Value',handles.strCircuit.vStage(curStage).vnCSelectExp(2)/3+5)
    otherwise, error('bad nCSelect')
end
switch nRSelect
    case 0
        set(handles.uitxRa,'Enable','off'); set(handles.uitxRa,'String','0');
        set(handles.uipmRa,'Enable','off'); set(handles.uipmRa,'Value',1);
        set(handles.uitxRb,'Enable','off'); set(handles.uitxRb,'String','0');
        set(handles.uipmRb,'Enable','off'); set(handles.uipmRb,'Value',1);
    case 1
        set(handles.uitxRa,'Enable','on');  set(handles.uitxRa,'String',handles.strCircuit.vStage(curStage).csRSelectMan{1})
        set(handles.uipmRa,'Enable','on');  set(handles.uipmRa,'Value',handles.strCircuit.vStage(curStage).vnRSelectExp(1)/3+1)
        set(handles.uitxRb,'Enable','off'); set(handles.uitxRb,'String','0');
        set(handles.uipmRb,'Enable','off'); set(handles.uipmRb,'Value',1);
    case 2
        set(handles.uitxRa,'Enable','on');  set(handles.uitxRa,'String',handles.strCircuit.vStage(curStage).csRSelectMan{1})
        set(handles.uipmRa,'Enable','on');  set(handles.uipmRa,'Value',handles.strCircuit.vStage(curStage).vnRSelectExp(1)/3+1)
        set(handles.uitxRb,'Enable','on');  set(handles.uitxRb,'String',handles.strCircuit.vStage(curStage).csRSelectMan{2})
        set(handles.uipmRb,'Enable','on');  set(handles.uipmRb,'Value',handles.strCircuit.vStage(curStage).vnRSelectExp(2)/3+1)
    otherwise, error('bad nRSelect')
end
switch nCCalc
    case 0
        set(handles.uitxC1,'Visible','off')
        set(handles.uitxC2,'Visible','off')
        set(handles.uitxC3,'Visible','off')
        set(handles.uitxC4,'Visible','off')
        set(handles.uitxStaticC1,'Enable','off')
        set(handles.uitxStaticC2,'Enable','off')
        set(handles.uitxStaticC3,'Enable','off')
        set(handles.uitxStaticC4,'Enable','off')
        set(handles.uitxStaticC1sub,'Enable','off')
        set(handles.uitxStaticC2sub,'Enable','off')
        set(handles.uitxStaticC3sub,'Enable','off')
        set(handles.uitxStaticC4sub,'Enable','off')
    case 1
        set(handles.uitxC1,'Visible','on'); set(handles.uitxC1,'String',handles.strCircuit.vStage(curStage).csCCalc{1})
        set(handles.uitxC2,'Visible','off')
        set(handles.uitxC3,'Visible','off')
        set(handles.uitxC4,'Visible','off')
        set(handles.uitxStaticC1,'Enable','on')
        set(handles.uitxStaticC2,'Enable','off')
        set(handles.uitxStaticC3,'Enable','off')
        set(handles.uitxStaticC4,'Enable','off')
        set(handles.uitxStaticC1sub,'Enable','on')
        set(handles.uitxStaticC2sub,'Enable','off')
        set(handles.uitxStaticC3sub,'Enable','off')
        set(handles.uitxStaticC4sub,'Enable','off')
    case 2
        set(handles.uitxC1,'Visible','on'); set(handles.uitxC1,'String',handles.strCircuit.vStage(curStage).csCCalc{1})
        set(handles.uitxC2,'Visible','on'); set(handles.uitxC2,'String',handles.strCircuit.vStage(curStage).csCCalc{2})
        set(handles.uitxC3,'Visible','off')
        set(handles.uitxC4,'Visible','off')
        set(handles.uitxStaticC1,'Enable','on')
        set(handles.uitxStaticC2,'Enable','on')
        set(handles.uitxStaticC3,'Enable','off')
        set(handles.uitxStaticC4,'Enable','off')
        set(handles.uitxStaticC1sub,'Enable','on')
        set(handles.uitxStaticC2sub,'Enable','on')
        set(handles.uitxStaticC3sub,'Enable','off')
        set(handles.uitxStaticC4sub,'Enable','off')
    case 3
        set(handles.uitxC1,'Visible','on'); set(handles.uitxC1,'String',handles.strCircuit.vStage(curStage).csCCalc{1})
        set(handles.uitxC2,'Visible','on'); set(handles.uitxC2,'String',handles.strCircuit.vStage(curStage).csCCalc{2})
        set(handles.uitxC3,'Visible','on'); set(handles.uitxC3,'String',handles.strCircuit.vStage(curStage).csCCalc{3})
        set(handles.uitxC4,'Visible','off')
        set(handles.uitxStaticC1,'Enable','on')
        set(handles.uitxStaticC2,'Enable','on')
        set(handles.uitxStaticC3,'Enable','on')
        set(handles.uitxStaticC4,'Enable','off')
        set(handles.uitxStaticC1sub,'Enable','on')
        set(handles.uitxStaticC2sub,'Enable','on')
        set(handles.uitxStaticC3sub,'Enable','on')
        set(handles.uitxStaticC4sub,'Enable','off')
    case 4
        set(handles.uitxC1,'Visible','on'); set(handles.uitxC1,'String',handles.strCircuit.vStage(curStage).csCCalc{1})
        set(handles.uitxC2,'Visible','on'); set(handles.uitxC2,'String',handles.strCircuit.vStage(curStage).csCCalc{2})
        set(handles.uitxC3,'Visible','on'); set(handles.uitxC3,'String',handles.strCircuit.vStage(curStage).csCCalc{3})
        set(handles.uitxC4,'Visible','on'); set(handles.uitxC4,'String',handles.strCircuit.vStage(curStage).csCCalc{4})
        set(handles.uitxStaticC1,'Enable','on')
        set(handles.uitxStaticC2,'Enable','on')
        set(handles.uitxStaticC3,'Enable','on')
        set(handles.uitxStaticC4,'Enable','on')
        set(handles.uitxStaticC1sub,'Enable','on')
        set(handles.uitxStaticC2sub,'Enable','on')
        set(handles.uitxStaticC3sub,'Enable','on')
        set(handles.uitxStaticC4sub,'Enable','on')
    otherwise, error('bad nCCalc')
end
switch nRCalc
    case 0
        set(handles.uitxR1,'Visible','off')
        set(handles.uitxR2,'Visible','off')
        set(handles.uitxR3,'Visible','off')
        set(handles.uitxR4,'Visible','off')
        set(handles.uitxStaticR1,'Enable','off')
        set(handles.uitxStaticR2,'Enable','off')
        set(handles.uitxStaticR3,'Enable','off')
        set(handles.uitxStaticR4,'Enable','off')
        set(handles.uitxStaticR1sub,'Enable','off')
        set(handles.uitxStaticR2sub,'Enable','off')
        set(handles.uitxStaticR3sub,'Enable','off')
        set(handles.uitxStaticR4sub,'Enable','off')
    case 1
        set(handles.uitxR1,'Visible','on'); set(handles.uitxR1,'String',handles.strCircuit.vStage(curStage).csRCalc{1})
        set(handles.uitxR2,'Visible','off')
        set(handles.uitxR3,'Visible','off')
        set(handles.uitxR4,'Visible','off')
        set(handles.uitxStaticR1,'Enable','on')
        set(handles.uitxStaticR2,'Enable','off')
        set(handles.uitxStaticR3,'Enable','off')
        set(handles.uitxStaticR4,'Enable','off')
        set(handles.uitxStaticR1sub,'Enable','on')
        set(handles.uitxStaticR2sub,'Enable','off')
        set(handles.uitxStaticR3sub,'Enable','off')
        set(handles.uitxStaticR4sub,'Enable','off')
    case 2
        set(handles.uitxR1,'Visible','on'); set(handles.uitxR1,'String',handles.strCircuit.vStage(curStage).csRCalc{1})
        set(handles.uitxR2,'Visible','on'); set(handles.uitxR2,'String',handles.strCircuit.vStage(curStage).csRCalc{2})
        set(handles.uitxR3,'Visible','off')
        set(handles.uitxR4,'Visible','off')
        set(handles.uitxStaticR1,'Enable','on')
        set(handles.uitxStaticR2,'Enable','on')
        set(handles.uitxStaticR3,'Enable','off')
        set(handles.uitxStaticR4,'Enable','off')
        set(handles.uitxStaticR1sub,'Enable','on')
        set(handles.uitxStaticR2sub,'Enable','on')
        set(handles.uitxStaticR3sub,'Enable','off')
        set(handles.uitxStaticR4sub,'Enable','off')
    case 3
        set(handles.uitxR1,'Visible','on'); set(handles.uitxR1,'String',handles.strCircuit.vStage(curStage).csRCalc{1})
        set(handles.uitxR2,'Visible','on'); set(handles.uitxR2,'String',handles.strCircuit.vStage(curStage).csRCalc{2})
        set(handles.uitxR3,'Visible','on'); set(handles.uitxR3,'String',handles.strCircuit.vStage(curStage).csRCalc{3})
        set(handles.uitxR4,'Visible','off')
        set(handles.uitxStaticR1,'Enable','on')
        set(handles.uitxStaticR2,'Enable','on')
        set(handles.uitxStaticR3,'Enable','on')
        set(handles.uitxStaticR4,'Enable','off')
        set(handles.uitxStaticR1sub,'Enable','on')
        set(handles.uitxStaticR2sub,'Enable','on')
        set(handles.uitxStaticR3sub,'Enable','on')
        set(handles.uitxStaticR4sub,'Enable','off')
    case 4
        set(handles.uitxR1,'Visible','on'); set(handles.uitxR1,'String',handles.strCircuit.vStage(curStage).csRCalc{1})
        set(handles.uitxR2,'Visible','on'); set(handles.uitxR2,'String',handles.strCircuit.vStage(curStage).csRCalc{2})
        set(handles.uitxR3,'Visible','on'); set(handles.uitxR3,'String',handles.strCircuit.vStage(curStage).csRCalc{3})
        set(handles.uitxR4,'Visible','on'); set(handles.uitxR4,'String',handles.strCircuit.vStage(curStage).csRCalc{4})
        set(handles.uitxStaticR1,'Enable','on')
        set(handles.uitxStaticR2,'Enable','on')
        set(handles.uitxStaticR3,'Enable','on')
        set(handles.uitxStaticR4,'Enable','on')
        set(handles.uitxStaticR1sub,'Enable','on')
        set(handles.uitxStaticR2sub,'Enable','on')
        set(handles.uitxStaticR3sub,'Enable','on')
        set(handles.uitxStaticR4sub,'Enable','on')
    otherwise, error('bad nRCalc')
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                            UpdateFilter_Z1P1k1                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function UpdateFilter_Z1P1k1(strCircuit)
% makes the overall strFilterObject Z1,P1,k reflect the individual stage's z1,p1,k
global strFilterObject

% setup
nBiquads=strCircuit.nBiquads;
bFirstOrderStage=strCircuit.bFirstOrderStage;
bGainStage=strCircuit.bGainStage;
nStages=strCircuit.nStages;
% find zeros
vZeros1=[];
vPoles1=[];
fK1=1;
for i=1:nBiquads
    vZeros1 = [vZeros1; strCircuit.vStage(i).z1(:)];
    vPoles1 = [vPoles1; strCircuit.vStage(i).p1(:)];
    fK1=fK1*strCircuit.vStage(i).k1;
end
if bFirstOrderStage | bGainStage
    vZeros1 = [vZeros1; strCircuit.vStage(nStages).z1];
    vPoles1 = [vPoles1; strCircuit.vStage(nStages).p1];
    fK1=fK1*strCircuit.vStage(nStages).k1;
end
strFilterObject.vZeros1=vZeros1;
strFilterObject.vPoles1=vPoles1;
strFilterObject.fK1=fK1;

Contact us at files@mathworks.com