⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guibuildactivecircuit.m

📁 Talking about adaptive filter digital
💻 M
📖 第 1 页 / 共 2 页
字号:
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)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -