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

📄 guibuildstageinformation.m

📁 Talking about adaptive filter digital
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = GuiBuildStageInformation(varargin)
% GUIBUILDSTAGEINFORMATION M-file for guiBuildStageInformation.fig
%      GUIBUILDSTAGEINFORMATION, by itself, creates a new GUIBUILDSTAGEINFORMATION or raises the existing
%      singleton*.
%
%      H = GUIBUILDSTAGEINFORMATION returns the handle to a new GUIBUILDSTAGEINFORMATION or the handle to
%      the existing singleton*.
%
%      GUIBUILDSTAGEINFORMATION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUIBUILDSTAGEINFORMATION.M with the given input arguments.
%
%      GUIBUILDSTAGEINFORMATION('Property','Value',...) creates a new GUIBUILDSTAGEINFORMATION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before guiBuildStageInformation_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to guiBuildStageInformation_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 guiBuildStageInformation

% Last Modified by GUIDE v2.5 27-Dec-2003 17:45:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GuiBuildStageInformation_OpeningFcn, ...
                   'gui_OutputFcn',  @GuiBuildStageInformation_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 guiBuildStageInformation is made visible.
function GuiBuildStageInformation_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for guiBuildStageInformation
handles.output = hObject;

% Load data
if length(varargin) == 2
    strStage = varargin{1};
    curStage = varargin{2};
else
   temp=load('curStage.mat');
   disp([mfilename ' called in debug mode using StageInformation.mat datafile'])
   strStage = temp.curStage;
   curStage = 1;
end
handles.curStage = curStage;
handles.strStage = strStage;

% create the figure title and status bar
set(handles.uiBuildStageInformation,'Name',sprintf('Stage %g',curStage))
set(handles.uitxTitle,'String',['Detailed Information: Stage ' num2str(curStage)])
set(handles.uitxStatus,'String','Select the information to view')

% Figure out if there is a toleranced R or C and if so display it by default
global strCircuit
if strCircuit.nRTol + strCircuit.nCTol == 0
    set(handles.uirbComponentsExact,'Value',1)
    set(handles.uirbComponentsToleranced,'Value',0)
else
    set(handles.uirbComponentsExact,'Value',0)
    set(handles.uirbComponentsToleranced,'Value',1)
end
% create upper plot and table, and lower plot and table
RecalculateRightSide(handles)

% fill the component selection popup
nCSelect = length(strStage.vfCSelect);
nRSelect = length(strStage.vfRSelect);
nCCalc = length(strStage.vfCCalc);
nRCalc = length(strStage.vfRCalc);
cComponents = {};
for i=1:nCSelect
    cComponents{end+1} = ['C' char(96+i)];
end
for i=1:nRSelect
    cComponents{end+1} = ['R' char(96+i)];
end
for i=1:nCCalc
    cComponents{end+1} = ['C' num2str(i)];
end
for i=1:nRCalc
    cComponents{end+1} = ['R' num2str(i)];
end
set(handles.uipmSensitivityIn,'String',cComponents)
CalculateSensitivity(handles)

% Update handles structure
guidata(hObject, handles);

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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                       Components, Frequency, Gain                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function uirbComponentsExact_Callback(hObject, eventdata, handles)
set(hObject,'Value',1);
set(handles.uirbComponentsToleranced,'Value',0)
RecalculateRightSide(handles)

function uirbComponentsToleranced_Callback(hObject, eventdata, handles)
set(hObject,'Value',1);
set(handles.uirbComponentsExact,'Value',0)
RecalculateRightSide(handles)

function uirbFrequencyRads_Callback(hObject, eventdata, handles)
set(hObject,'Value',1);
set(handles.uirbFrequencyHz,'Value',0)
RecalculateRightSide(handles)

function uirbFrequencyHz_Callback(hObject, eventdata, handles)
set(hObject,'Value',1);
set(handles.uirbFrequencyRads,'Value',0)
RecalculateRightSide(handles)

function uirbGainLinear_Callback(hObject, eventdata, handles)
set(hObject,'Value',1);
set(handles.uirbGainDb,'Value',0)
RecalculateRightSide(handles)

function uirbGainDb_Callback(hObject, eventdata, handles)
set(hObject,'Value',1);
set(handles.uirbGainLinear,'Value',0)
RecalculateRightSide(handles)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                              CustomFrequency                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function uitxCustomFreq_Callback(hObject, eventdata, handles)
RecalculateRightSide(handles)

function uipmCustomFreq_Callback(hObject, eventdata, handles)
RecalculateRightSide(handles)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                               Sensitivity                                 %
%          uipmSensitivityIn, uipmSensitivityOut, uitxSensitivity           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function uipmSensitivityIn_Callback(hObject, eventdata, handles)
CalculateSensitivity(handles)

function uipmSensitivityOut_Callback(hObject, eventdata, handles)
CalculateSensitivity(handles)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                           RecalculateRightSide                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function RecalculateRightSide(handles)
% setup
strStage = handles.strStage;
nStage = handles.curStage;
if get(handles.uirbComponentsExact,'Value') % exact components
    % Temporarily, refigure entire circuit out as if RTol=CTol=0 and use the 
    % calculated z1,p1,k1 from this for the exact stage.
    % The issue is that the ideal stage z,p,k is not a function of the circuit type,
    % so, e.g., a MFB biquad section that cannot select a gain may have a RTol=CTol=0
    % yielding a max gain of 0.1, whereas an "ideal" biquad that lets one set the
    % gain may have a gain of 1.  We don't want the user getting confused by seeing
    % a 0 toleranced implementation with a gain of 0.1 and an ideal stage having a
    % gain of 1, so, we do this.
    global strCircuit
    oldstrCircuit=strCircuit;
    strCircuit.RTol=0;
    strCircuit.CTol=0;
    for i=1:strCircuit.nBiquads
        strCircuit.vStage(i) = BuildCircuit_UpdateComponents(strCircuit.vStage(i),0,0);
    end
    strCircuit = BuildCircuit_LastStage(strCircuit);
    z = strCircuit.vStage(nStage).z1; % what they would be with 0 toleranced components
    p = strCircuit.vStage(nStage).p1;
    k = strCircuit.vStage(nStage).k1;
    % now account for rounding by making small values = 0
    z = RemoveSmallValues(z);
    p = RemoveSmallValues(p);
    strCircuit = oldstrCircuit;
else
    z = strStage.z1; zIdeal=strStage.z;
    p = strStage.p1; pIdeal=strStage.p;
    k = strStage.k1; kIdeal=strStage.k;
end
isHz = get(handles.uirbFrequencyHz,'Value');
isDb = get(handles.uirbGainDb,'Value');

% begin by loading the schematic
persistent strGraphic
if isempty(strGraphic)
    t=load('StageInformation.mat');
    strGraphic = t.strGraphic;
end
nPoles=length(strStage.p);
nZeros=length(strStage.z);
switch nPoles
    case 0
        schName = 'ZO';
    case 1
        if nZeros == 1
            schName = 'FO_HP';
        else
            schName = 'FO_LP';
        end
    case 2
        if nZeros == 0
            schName = 'SO_LP';
        elseif strStage.z(1) == 0
            schName = 'SO_HP';
        else
            schName = 'SO_Notch';
        end
    otherwise
        error('Unknown strStage type')
end
axes(handles.uiaxEqn)
hImage = image(strGraphic.(schName), 'Parent', handles.uiaxEqn);
set(handles.uiaxEqn, ...
    'Visible', 'off', ...
    'YDir'   , 'reverse'       , ...
    'XLim'   , get(hImage,'XData'), ...
    'YLim'   , get(hImage,'YData')  ...
    );
set(handles.uiBuildStageInformation,'Colormap',gray(255))

% Next, load the table values under the schematic
sK = sprintf('%g',k);
switch schName
    case 'ZO'
        sZ = 'No zeros';
        sP = 'No poles';
        sQ = 'Not second order';
        sWp = 'No poles';
        sWz = 'No zeros';
        LFGain = abs(k);
        HFGain = abs(k);
        minGainFreq = 'All';
        minGain = abs(k);
        maxGainFreq = 'All';
        maxGain = abs(k);
        halfPowerFreq = 'None';
        halfPowerGain = 1/sqrt(2);
    case 'FO_LP'
        sZ = 'No zeros';
        sP = sprintf('%0.5g',p);
        sQ = 'Not second order';
        sWp = abs(p);
        sWz = 'No zeros';
        LFGain = abs(k/p);
        HFGain = 0;
        minGainFreq = 'Infinity';
        minGain = 0;
        maxGainFreq = 0;
        maxGain = abs(k/p);
        halfPowerFreq = -p;
        halfPowerGain = abs(k/(p*sqrt(2)));
    case 'FO_HP'
        sZ = '0';
        sP = sprintf('%0.5g',p);
        sQ = 'Not second order';
        sWp = abs(p);
        sWz = '0';
        LFGain = 0;
        HFGain = abs(k);
        minGainFreq = 0;
        minGain = 0;
        maxGainFreq = 'Infinity';
        maxGain = abs(k);
        halfPowerFreq = -p;
        halfPowerGain = 1/sqrt(2);
    case 'SO_LP'
        sZ = 'No zeros';
        sP = sprintf('%0.5g + j%0.5g',real(p(1)),abs(imag(p(1))));
        sQ = sprintf('%0.5g',-abs(p(1))/(2*real(p(1))));
        sWp = sprintf('%0.5g',abs(p(1)));
        sWz = 'No zeros';
        LFGain = abs(k)/abs(p(1))^2;
        HFGain = 0;
        minGainFreq = 'Infinity';
        minGain = 0;
        alpha2 = real(p(1))^2; sigma2 = imag(p(1))^2; alpha=-sqrt(alpha2); sigma=sqrt(sigma2);
        if sigma2>alpha2  % peaks
            maxGain = abs(k/(2*alpha*sigma));
            maxGainFreq = sqrt(sigma2-alpha2);
            halfPowerFreq = sqrt(sigma2-2*alpha*sigma-alpha2);
        else
            maxGain = abs(k)/(alpha2+sigma2);
            maxGainFreq = 0;
            halfPowerFreq = sqrt(sigma2-alpha2+sqrt(2)*sqrt(alpha2^2+sigma2^2));
        end
        halfPowerGain = maxGain/sqrt(2);
    case 'SO_HP'
        sZ = '0 + j0';
        sP = sprintf('%0.5g + j%0.5g',real(p(1)),abs(imag(p(1))));
        sQ = sprintf('%0.5g',-abs(p(1))/(2*real(p(1))));
        sWp = sprintf('%0.5g',abs(p(1)));
        sWz = '0';
        LFGain = 0;
        HFGain = abs(k);
        minGainFreq = 0;
        minGain = 0;
        alpha2 = real(p(1))^2; sigma2 = imag(p(1))^2; sigma=sqrt(sigma2); alpha=-sqrt(alpha2);
        if sigma2>alpha2 % peaks
            maxGainFreq = (sigma2+alpha2)/sqrt(sigma2-alpha2);
            maxGain = -abs(k)*(alpha2+sigma2)/(2*alpha*sigma);
            halfPowerFreq = (alpha2+sigma2)/sqrt(sigma2-2*alpha*sigma-alpha2);
        else
            maxGainFreq = 'Infinity';
            maxGain = abs(k);
            halfPowerFreq = sqrt(alpha2-sigma2+sqrt(2)*sqrt(sigma2^2+alpha2^2));
        end
        halfPowerGain = maxGain/sqrt(2);
    case 'SO_Notch'
        sZ = sprintf('%0.5g+j%0.5g',real(z(1)),abs(imag(z(1))));
        sP = sprintf('%0.5g+j%0.5g',real(p(1)),abs(imag(p(1))));
        sQ = sprintf('%0.5g',-abs(p(1))/(2*real(p(1))));
        sWp = sprintf('%0.5g',abs(p(1)));
        sWz = sprintf('%0.5g',abs(z(1)));
        LFGain = abs(k)*abs(z(1))^2/abs(p(1))^2;
        HFGain = abs(k);
        minGainFreq = abs(z(1));
        minGain = 0;
        alpha2 = real(p(1))^2; sigma2 = imag(p(1))^2; z2 = abs(z(1))^2; alpha = -sqrt(alpha2); sigma = sqrt(sigma2);
        if abs(p(1)) < abs(z(1)) % LP
            if sigma  <= -alpha % Q<1/2, so no hump
                maxGainFreq = 0;
                maxGain = abs(k*z2/(alpha2+sigma2));
            else % Q>1/2, so resonant hump
                maxGainFreq = sqrt((z2*(sigma2-alpha2)-(alpha2+sigma2)^2)/(z2+alpha2-sigma2));
                maxGain = sqrt(k^2*(z2^2+2*z2*(alpha-sigma)*(alpha+sigma)+(alpha2+sigma2)^2)/(4*alpha2*sigma2));

⌨️ 快捷键说明

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