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

📄 filtview.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 5 页
字号:
                    'parent',ud.ht.a(5),...
                    'buttondownfcn','filtview(''mdown'')');
            end
            set(ud.lines(i).impc,'color',lineColor,'markerfacecolor',lineColor)
            if isempty(ud.lines(i).impstemc)
                ud.lines(i).impstemc = line(nan,nan,'tag','implinestemc',...
                    'linestyle','-',...
                    'parent',ud.ht.a(5),...
                    'buttondownfcn','filtview(''mdown'')');
            end
            set(ud.lines(i).impstemc,'color',lineColor,'linestyle',lineStyle)
            setstem([ud.lines(i).imp ud.lines(i).impstem],ud.filt(i).t,...
                    real(ud.filt(i).imp))
            if sum(imag(ud.filt(i).imp).^2) > 1e-10*sum(real(ud.filt(i).imp).^2)
                setstem([ud.lines(i).impc ud.lines(i).impstemc],ud.filt(i).t,...
                        imag(ud.filt(i).imp))
                set([ud.lines(i).impc ud.lines(i).impstemc],'visible','on')
            else
                set([ud.lines(i).impc ud.lines(i).impstemc],'visible','off')
            end
            set([ud.lines(i).imp ud.lines(i).impstem],'visible','on')
        end
        
        if plots(6)
            if isempty(ud.lines(i).step)
                ud.lines(i).step = line(nan,nan,'tag','steplinedots',...
                    'linestyle','none','marker','o',...
                    'parent',ud.ht.a(6),...
                    'buttondownfcn','filtview(''mdown'')');
            end
            set(ud.lines(i).step,'color',lineColor,'markerfacecolor',lineColor)
            if isempty(ud.lines(i).stepstem)
                ud.lines(i).stepstem = line(nan,nan,'tag','steplinestem',...
                    'linestyle','-',...
                    'parent',ud.ht.a(6),...
                    'buttondownfcn','filtview(''mdown'')');
            end  
            set(ud.lines(i).stepstem,'color',lineColor,'linestyle',lineStyle)
            if isempty(ud.lines(i).stepc)
                ud.lines(i).stepc = line(nan,nan,'tag','steplinedotsc',...
                    'linestyle','none','marker','*',...
                    'parent',ud.ht.a(6),...
                    'buttondownfcn','filtview(''mdown'')');
            end
            set(ud.lines(i).stepc,'color',lineColor,'markerfacecolor',lineColor)
            if isempty(ud.lines(i).stepstemc)
                ud.lines(i).stepstemc = line(nan,nan,'tag','steplinestemc',...
                    'linestyle','-',...
                    'parent',ud.ht.a(6),...
                    'buttondownfcn','filtview(''mdown'')');
            end 
            set(ud.lines(i).stepstemc,'color',lineColor,'linestyle',lineStyle)
            ud.filt(i).step = filter(ud.filt(i).tf.num,ud.filt(i).tf.den,...
                ones(1,length(ud.filt(i).t)));
            setstem([ud.lines(i).step ud.lines(i).stepstem],ud.filt(i).t,...
                real(ud.filt(i).step))
            if sum(imag(ud.filt(i).step).^2) > 1e-10*sum(real(ud.filt(i).step).^2)
                setstem([ud.lines(i).stepc ...
                        ud.lines(i).stepstemc],ud.filt(i).t,...
                        imag(ud.filt(i).step))
                set([ud.lines(i).stepc ud.lines(i).stepstemc],'visible','on')
            else
                set([ud.lines(i).stepc ud.lines(i).stepstemc],'visible','off')
            end
            set([ud.lines(i).step ud.lines(i).stepstem],'visible','on')
            set(ud.ht.a(6),'ylimmode','auto',...
                'xlim',[ud.filt(i).t(1)-1/Fs  ud.filt(i).t(end)+1/Fs])
            
        end
         
        set(fig,'userdata',ud)
        sptool('import',ud.filt(i))
    end % looping trough selected filters
    
    % set all axes properties only once:
    if plots(1)
        % Make sure that proper scale is used for magnitude axis
        if get(ud.ht.magpop,'value') == 2
            set(ud.ht.a(1),'yscale','log')
        else
            set(ud.ht.a(1),'yscale','linear')        
        end
        set(ud.ht.a(1),'ylimmode','auto','xlim',flim)
    end
    
    if plots(2), set(ud.ht.a(2),'ylimmode','auto','xlim',flim), end
    if plots(3)  % set ylims of group delay plot
        gd_ylim = filtview('gd_ylim',ud.filt);
        set(ud.ht.a(3),'ylim',gd_ylim)
        set(ud.ht.a(3),'xlim',flim)
    end
    %if plots(3), set(ud.ht.a(3),'ylimmode','auto','xlim',flim), end

    if any(plots(1:3))  % Make sure that proper scale is used for freq axis
        if get(ud.ht.fscalepop,'value') == 2
            set(ud.ht.a(find(plots(1:3))),'xscale','log')
        else
            set(ud.ht.a(find(plots(1:3))),'xscale','linear')        
        end
    end
    
    if plots(4)
        [xlim1,xlim2,ylim1,ylim2] = zeropolePlotLims(ud.filt);
        set(get(ud.ht.a(4),'xlabel'),'userdata',[xlim1 xlim2 ylim1 ylim2]);
    end

    if any(plots([5 6]))
        tmax = -inf;
        for i = 1:length(ud.filt)
            tmax = max([tmax; ud.filt(i).t(end)]);
        end
        
        xlim = [-1/maxFs tmax+1/maxFs];
        if plots(5),set(ud.ht.a(5),'ylimmode','auto','xlim',xlim), end
        if plots(6),set(ud.ht.a(6),'ylimmode','auto','xlim',xlim), end
    end

%------------------------------------------------------------------------
%   gd_ylim = filtview('gd_ylim',filt)
%      compute ylimits for group delay plot
%      assumes .H and .G fields of filt struct are set correctly
case 'gd_ylim' 
    filt = varargin{2};
    if length(filt)==0
        gd_ylim = [0 1];
    else
        gd_ylim = [Inf -Inf];
    end
    for i=1:length(filt)
        ind = find( abs(filt(i).H) > (max(abs(filt(i).H))*1e-10) );
        gd_ylim = [min(gd_ylim(1),min(filt(i).G(ind))-1) ...
                 max(gd_ylim(2),max(filt(i).G(ind))+1)]; 
    end
    varargout{1} = gd_ylim;
    
%------------------------------------------------------------------------
% filtview('changefocus')
%  callback of sptlegend
%
case 'changefocus'
    
    newfocusIndex = sptlegend('value');
    fig = gcbf;
    ud = get(fig,'userdata');
    plotIndex = find(ud.mainaxes == ud.ht.a);

    realFilterFlag = (isreal(ud.filt(newfocusIndex).tf.num) &...
        isreal(ud.filt(newfocusIndex).tf.den));

    % Make sure that ruler popup is updated correctly when changing from a
    % real filter to a complex filter and vice versa.
    if ud.prefs.tool.ruler & ~isempty(ud.filt)
        currentPopupVal = get(ud.ruler.hand.rulerpopup,'value');   
        newPlottitles = filtview('plotTitles',realFilterFlag);
        newPopupVal = cmplxFiltPopupVal(currentPopupVal,newPlottitles,...
                                                       ud.prefs.plottitles);
        ud.prefs.plottitles = newPlottitles;
        set(fig,'userdata',ud)
        updateRulrPopupList(fig,newPlottitles,ud.ht.a,...
                                      ud.mainaxes,realFilterFlag)
        str = ruler('getpopup',fig);
        ruler('setpopup',fig,str,newPopupVal)
    end
        
    if isempty(ud.focusIndex) 
        h = [];
    else
        hstepc = ud.lines(ud.focusIndex).stepc;
        himpc = ud.lines(ud.focusIndex).impc;
        h = [hstepc himpc];
    end
    if  isempty(ud.focusline) | isempty(h) | realFilterFlag | ...
            all(ud.focusline~=h)
        realDataFlag = 1;   % data is real
    else    
        realDataFlag = 0;   % data is complex
    end

    ud.focusline = setFocusLine(ud.mainaxes,ud.lines,...
                                plotIndex,newfocusIndex,realDataFlag);
    ud.focusIndex = newfocusIndex;
    set(fig,'userdata',ud)
    
    if ud.prefs.tool.ruler
        ruler('newsig',fig,plotIndex)
    end
    if isempty(find(ud.prefs.plots)) & ~isempty(ud.filt)
        sptlegend('setvalue',ud.legend.legendline,...
            ud.focusIndex,1,fig)
        set(ud.legend.legendline,'color',...
            ud.filt(ud.focusIndex).lineinfo.color)
    else
        sptlegend('setvalue',ud.focusline,ud.focusIndex,1,fig)
    end
    set(ud.legend.legendline,'linestyle', ...
                               ud.filt(ud.focusIndex).lineinfo.linestyle)
    bringToFront(fig,ud.focusIndex)
    
%------------------------------------------------------------------------
% filtview('newColor',lineColor,lineStyle)
%  newColorCallback of sptlegend
%  color and linestyle of ud.focusline have already been updated
%
case 'newColor'
    lineColor = varargin{2};
    lineStyle = varargin{3};
    
    fig = gcf;
    ud = get(fig,'userdata');
    
    indx = ud.focusIndex;
    if isempty(indx)
        indx = get(ud.legend.legendpopup,'value');
    end
    ud.filt(indx).lineinfo.color = lineColor;
    ud.filt(indx).lineinfo.linestyle = lineStyle;
 
    set(fig,'userdata',ud)
    
    % poke back into SPTool
    sptool('import',ud.filt(indx))

    % Only change the line style of lines, not markers; in other words
    % don't change the line style of circles, dots or asterisks.
    flds = {'mag'
            'phase'
            'grpdelay'
            'impstem'
            'impstemc'
            'stepstem'
            'stepstemc'};

    for i = 1:length(flds)
        lineHandle = eval(['ud.lines(', num2str(indx),  ').', flds{i}]);
        if ishandle(lineHandle)
            set(lineHandle,'linestyle',lineStyle)
        end
    end

    h = [ud.lines(indx).imp ud.lines(indx).imp  ud.lines(indx).step ...
            ud.lines(indx).stepc];
    set(h,'markerfacecolor',lineColor)
    handleCell = struct2cell(ud.lines(indx));
    h = [handleCell{:}];
    set(h,'color',lineColor)
    
%------------------------------------------------------------------------
% filtview('rulerpopup')
%   callback of the ruler popupmenu
%
case 'rulerpopup'
    fig = gcf;
    ud = get(fig,'userdata');
    [rulerPopupStr,rulerPopupVal] = ruler('getpopup',fig);
    realFilterFlag = length(rulerPopupStr) <= 7;
    none_indx = strcmp(rulerPopupStr{1},'<none>');

    if none_indx & (rulerPopupVal == 1)
        return
    end

    plotIndex = rulerPopupVal - none_indx;
    plotIndex = plotIndex - (~realFilterFlag &  ((plotIndex==6) | ...
        (plotIndex==7))) - 2*(~realFilterFlag & plotIndex>=8);
        
    if plotIndex == find(ud.mainaxes == ud.ht.a) & ...
            strcmp(get(ud.mainaxes,'visible'),'on')
        realDataFlag = (realFilterFlag | rem(rulerPopupVal-none_indx,2));
        focusline = setFocusLine(ud.mainaxes,ud.lines,...
            plotIndex,ud.focusIndex,realDataFlag);
        if isequal(ud.focusline,focusline)
            return
        end
    end
        
    if ~ud.prefs.plots(plotIndex)               % plot is not selected
        set(ud.ht.cb(plotIndex),'value',1);     % select checkbox
        filtview('cb',plotIndex)                % display plot 
        if ~realFilterFlag & any((rulerPopupVal-none_indx)==[6 8])
            if none_indx, rulerPopupStr = rulerPopupStr(2:end); end
            ruler('setpopup',fig,rulerPopupStr,rulerPopupVal-none_indx)
        end
        ud = get(fig,'userdata');
    end
    
    complxFlag = ~realFilterFlag & (any((rulerPopupVal-none_indx)==[6 8]));
    ud.mainaxes = ud.ht.a(plotIndex);
    ud.focusline = setFocusLine(ud.mainaxes,ud.lines,plotIndex,...
        ud.focusIndex,~complxFlag);
        
    ud = filtview('setudlimits',ud,ud.ht.a,plotIndex);
    set(fig,'userdata',ud)
    ruler('newaxes',fig,plotIndex,ud.mainaxes)
    noTrackZeroPole(fig,ud)                

%------------------------------------------------------------------------
% ud = filtview('setudlimits',ud,axesList,axesIndexes)
% Inputs:
%   ud - structure containing client's userdata
%   axesList - list of handles of the axes of all subplots
%   axesIndexes - indicies of the handles of all visible subplots
% Ouputs:
%   ud - structure containing client's modified userdata (new xlim and
%        ylim)
%
case 'setudlimits'

    ud = varargin{2};
    axesList = varargin{3};
    axesIndexes = varargin{4};

    for i = 1:length(axesIndexes)
        ud.limits(axesIndexes(i)).xlim=get(axesList(axesIndexes(i)),'xlim');
        ud.limits(axesIndexes(i)).ylim=get(axesList(axesIndexes(i)),'ylim');
    end
    
    varargout{1} = ud;

%------------------------------------------------------------------------
% filtview('settab')
%  open settings tabbed dialog box
%
case 'settab'
    fig = gcf;
    ud = get(fig,'userdata');

    if ud.pointer == 2  % help mode
        fvhelp('settab')
        return
    end

    if isempty(ud.tabfig)
        setptr(fig,'watch');
        ud.pointer = -1; 
        set(fig,'userdata',ud)
        tabfig1 = tabfig(0,'fvprefhand',ud.sz);
        ud.tabfig = tabfig1;

⌨️ 快捷键说明

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