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

📄 filtview.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 5 页
字号:
function varargout = filtview(varargin)
%FILTVIEW Filter Viewer.
%   This graphical tool allows you to examine the magnitude and phase
%   responses, group delay, zeros and poles, and impulse and step responses
%   of a digital filter.
%
%   Type 'sptool' to start the Signal Processing GUI Tool and access
%   the Filter Viewer.
%
%   See also SPTOOL, SIGBROWSE, FILTDES, SPECTVIEW.

%   Copyright (c) 1988-98 by The MathWorks, Inc.
%       $Revision: 1.31 $

% NOTE: ud.limits is set to the current X- Y-limits of the plot.  This is
% necessary because ruler.m uses ud.limits, and to avoid the rulers from
% dictating the XY limits of the plot we must keep the rulers inside the
% axes. ud.limits does not contain the largest X- Y-limits possible for
% that plot, as it might be the case in other clients that use ud.limits.

if nargin == 0,
    if isempty(findobj(0,'tag','sptool'))
        disp('Type ''sptool'' to start the Signal GUI.')
    else
        disp('To use the Filter Viewer, click on a filter in the ''Filters''')
        disp('column in the ''SPTool'', and then click on the ''View'' button.')
    end
    return
elseif ~isstr(varargin{1})
    fvinit(varargin{:})
    drawnow
    shh = get(0,'showhiddenhandles');
    set(0,'showhiddenhandles','on')
    ud = get(gcf,'userdata');

    set(ud.toolbar.zoomgroup,'visible','on')
    set(ud.toolbar.helpgroup,'visible','on')
    set(0,'showhiddenhandles',shh)
    return
end

action = varargin{1};

switch action
% ----------------------------------------------------------------------
% plotTitles = filtview('plotTitles',realFilterFlag)
%   
% Inputs:
%     realFilterFlag - flag indicating that filter being viewed is real
% Outputs:
%     plotTitles - list of plots available to focus on by rulers
%
case 'plotTitles'

    realFilterFlag = varargin{2};
    if realFilterFlag
        plotTitles ={'Magnitude','Phase','Group Delay',...
	        'Zeros and Poles','Impulse Response','Step Response',};
    else % Complex filter
        plotTitles ={'Magnitude','Phase','Group Delay',...
                'Zeros and Poles','Impulse (Real)',...
                'Impulse (Imag)','Step (Real)','Step (Imag)'};
    end
    varargout{1} = plotTitles;

%----------------------------------------------------------------------
% [FsStr filtLabelStr] = filtview('filtFsLabelStrs',ud.prefs,ud.ht,ud.filt)
%   Call local function to determine the correct strings for Fs and filter
%   label (the label which lists the names of the filters currently being
%   viewed).
%
case 'filtFsLabelStrs'

    [FsStr filtLabelStr] = ...
        filtFsLabelStrs(varargin{2},varargin{3},varargin{4});
    varargout{1} = FsStr;
    varargout{2} = filtLabelStr;

%----------------------------------------------------------------------
% [ud.lines] = filtview('emptyLinesStruct')
%  fvinit.m uses this case to access the local function emptyLineStruct.
%
case 'emptyLinesStruct'

    initializedLines = emptyLinesStruct;
    varargout{1} = initializedLines;
    
%----------------------------------------------------------------------
% [xlim1,xlim2,ylim1,ylim2] = filtview('zeropolePlotLims',ud.filt)
%   Call local function to alculate the limits for the zero-pole plot
%   (must keep the aspect ratio correct)
%
case 'zeropolePlotLims'

    filtStruct = varargin{2};
    [xlim1,xlim2,ylim1,ylim2] = zeropolePlotLims(filtStruct);
    
    varargout{1} = xlim1;
    varargout{2} = xlim2;
    varargout{3} = ylim1;
    varargout{4} = ylim2;

%----------------------------------------------------------------------
% filtview('cb',checkboxnum)
%   callback of checkbox to turn plots on/off
%
case 'cb'
    cbnum = varargin{2};
    fig = gcf;
    ud = get(fig,'userdata');
    ud.prefs.plots(cbnum) = 1-ud.prefs.plots(cbnum);
    set(fig,'userdata',ud)
    fvresize(1,fig)  % Add or remove axes and resize all other axes

    if ud.prefs.plots(cbnum)
        pflag = [0 0 0 0 0 0]';
        pflag(cbnum) = 1;
        filtview('plots',pflag)

        % Update the ud.limits of new plots as they're made visible
        ud = get(fig,'userdata');
        new_ud = filtview('setudlimits',ud,ud.ht.a,cbnum);
        set(fig,'userdata',new_ud)
        ud = get(fig,'userdata');
        
        if ud.prefs.tool.ruler  &  sum(ud.prefs.plots) == 1
            % Coming from a "no visible plots" state; make one plot visible
            ud.mainaxes = ud.ht.a(cbnum);
            ud.focusIndex = sptlegend('value',fig);
            [rulerPopupStr, rulerPopupVal] = ruler('getpopup',fig);

            % Account for the case where the filter was cleared
            % while viewing it in the filter viewer
            if isfield(ud,'filt.tf.num') 
                realFilterFlag = (isreal(ud.filt(ud.focusIndex).tf.num) &...
                    isreal(ud.filt(ud.focusIndex).tf.den));
            else
                realFilterFlag = 1;
            end
            
            if rulerPopupVal == 1  % Selection made via check box
                realDataFlag = 1;
            else                   % Selection made via ruler popup
                realDataFlag = (realFilterFlag | ~rem(rulerPopupVal,2));
            end
            ud.focusline = setFocusLine(ud.mainaxes,ud.lines,...
                cbnum,ud.focusIndex,realDataFlag);
            set(fig,'userdata',ud)
            rulerPopupVal = cbnum + (~realFilterFlag & (cbnum == 6));
            ruler('setpopup',fig,ud.prefs.plottitles,rulerPopupVal)
            ruler('newaxes',fig,cbnum,ud.mainaxes);    
            noTrackZeroPole(fig,ud)
        elseif ud.prefs.tool.ruler
            % Either, an invisible plot was selected via the ruler popup
            % OR, mainaxes limits changed because new plots were added
            plotIndex = find(ud.mainaxes == ud.ht.a);
            ruler('newlimits',fig,plotIndex,ud.focusline)
        end
    else     % If we're turning off a plot, zoom out of that plot
        fvzoom('zoomout',[zeros(1,cbnum-1) 1 zeros(1,6-cbnum)],fig)
        if ud.prefs.tool.ruler 
            if strcmp(get(ud.mainaxes,'visible'), 'off')
                if any(strcmp(get(ud.ht.a,'visible'),'on'))
                    % If other plots exist move rulers to the next plot.
                    [ud.mainaxes,ud.focusline,plotIndex,visPlots] = ...
                        setMainaxes(ud.mainaxes,ud.ht.a,ud.lines,1);
                    ud = filtview('setudlimits',ud,ud.ht.a,plotIndex);
                    set(fig,'userdata',ud)
                    ruler('newaxes',fig,plotIndex,ud.mainaxes)
                    noTrackZeroPole(fig,ud)
                else    % no visible plots
                    ud.focusline = [];
                    ud.focusIndex = [];
                    set(fig,'userdata',ud)
                    ruler('hidelines',fig,'all')
                    ruler('newsig',fig)          % sets the ruler values
                end
                ud = get(fig,'userdata');

                % Account for the case where the filter was cleared
                % while viewing it in the filter viewer
                if isfield(ud,'filt.tf.num')
                    realFilterFlag=(isreal(ud.filt(ud.focusIndex).tf.num)...
                        & isreal(ud.filt(ud.focusIndex).tf.den));
                else
                    realFilterFlag = 1;
                end
                
                updateRulrPopupList(fig,ud.prefs.plottitles,ud.ht.a,...
                    ud.mainaxes,realFilterFlag)
            else
                % Set ruler XY limits because subplots have been resized.
                plotIndex = find(ud.mainaxes == ud.ht.a);
                ud = filtview('setudlimits',ud,ud.ht.a,plotIndex);
                set(fig,'userdata',ud)
                ruler('newlimits',fig,plotIndex,ud.focusline)
            end
        end
    end

    % Disable and enable Magnitude and Phase popupmenus as appropriate
    if get(ud.ht.cb(1),'value') == 0
        set(ud.ht.magpop,'enable','off')
    else
        set(ud.ht.magpop,'enable','on')       
    end
    
    if get(ud.ht.cb(2),'value') == 0
        set(ud.ht.phasepop,'enable','off')
    else
        set(ud.ht.phasepop,'enable','on')       
    end
    
% ----------------------------------------------------------------------
% filtview('magpop')
%   callback of magnitude linear/log popup
%
case 'magpop'
    fig = gcf;
    ud = get(fig,'userdata');
    oldmode = ud.prefs.magmode;
    popupval = get(ud.ht.magpop,'value');
    popupstr = get(ud.ht.magpop,'string');
    if strcmp(oldmode,popupstr{popupval})
        return
    end

    switch popupval
    case 1
        ud.prefs.magmode = 'linear';
        set(ud.ht.a(1),'yscale','linear')
    case 2
        ud.prefs.magmode = 'log';
        set(ud.ht.a(1),'yscale','log')
     case 3
        ud.prefs.magmode = 'decibels';
        set(ud.ht.a(1),'yscale','linear')
    end
    set(fig,'userdata',ud)

    if ud.prefs.plots(1)
       filtview('plots',[1 0 0 0 0 0])
       fvzoom('zoomout',[1 0 0 0 0 0],fig)  % sets userdata
       ud = get(fig,'userdata');
       
       if ud.prefs.tool.ruler & (ud.ht.a(1) == ud.mainaxes)
           ruler('newsig',fig,1)           
           ruler('inbounds',fig,'ylim',1)  % make sure ruler limits are 
                                           % within the new axes limits
       end
    end
    
    p = sptool('getprefs','filtview1');
    p.magscale = popupval;
    sptool('setprefs','filtview1',p)
    
% ----------------------------------------------------------------------
% filtview('phasepop')
%   callback of phase degrees/radians popup
%
case 'phasepop'
    fig = gcf;
    ud = get(fig,'userdata');
    oldmode = ud.prefs.phasemode;
    popupval = get(ud.ht.phasepop,'value');
    popupstr = get(ud.ht.phasepop,'string');
    if strcmp(oldmode,popupstr{popupval})
        return
    end

    switch popupval
    case 1
        ud.prefs.phasemode = 'degrees';
        set(get(ud.ht.a(2),'title'),'string',ud.titles{2}{1})
    case 2
        ud.prefs.phasemode = 'radians';
        set(get(ud.ht.a(2),'title'),'string',ud.titles{2}{2})
    end
    set(fig,'userdata',ud)

    if ud.prefs.plots(2)
        filtview('plots',[0 1 0 0 0 0])
        fvzoom('zoomout',[0 1 0 0 0 0],fig) % sets userdata
        ud = get(fig,'userdata');
        
        if ud.prefs.tool.ruler & (ud.ht.a(2) == ud.mainaxes)
            ud = filtview('setudlimits',ud,ud.ht.a,2);
            set(fig,'userdata',ud)
            ruler('newlimits',fig,2,ud.focusline)
            ruler('newsig',fig,2)
            ud = get(fig,'userdata');
            ruler('inbounds',fig,'ylim',2) % make sure ruler limits are 
                                           % within the new axes limits
        end
    end

    p = sptool('getprefs','filtview1');
    p.phaseunits = popupval;
    sptool('setprefs','filtview1',p)

% ----------------------------------------------------------------------
% filtview('fscalepop')
%   callback of frequency scale linear/log popup
%    
case 'fscalepop'
    fig = gcf;
    ud = get(fig,'userdata');
    oldmode = ud.prefs.freqscale;    
    popupval = get(ud.ht.fscalepop,'value');
    popupstr = get(ud.ht.fscalepop,'string');
    if strcmp(oldmode,popupstr{popupval})
        return
    end
    
    switch popupval
    case 1
        ud.prefs.freqscale = 'linear';
        set(fig,'userdata',ud)
        set(ud.ht.a([1 2 3]),'xscale','linear')
        fvzoom('zoomout',[1 1 1 0 0 0],fig)

    case 2
        ud.prefs.freqscale = 'log';
        set(fig,'userdata',ud)

        if ud.prefs.freqrange == 3  % can't have negative frequencies
                                 % in logarithmic scale - change to [0..Fs/2]
            % so... change range!
            msgbox({'Sorry, you can''t have the Frequency Axis Scaling set'...
                'to logarithmic when the range includes negative frequencies.'...
                'Changing the range to positive frequencies only.'},...
                'Logarithmic Scaling Conflict','warn','modal')

            set(ud.ht.frangepop,'value',1)
            filtview('frangepop',fig)
            ud = get(fig,'userdata');
        end

⌨️ 快捷键说明

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