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

📄 filtdes.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 5 页
字号:
                    end
                    set(fig,oldptr{:}) 
                end
                L.delayrender = 'off';
            case 'up'
                done = 1;
            end
        end
        
        if ~autoDesign  % don't need to design if last motion function
                        % already did so
            % design filter
            oldptr = getptr(fig);   
            setptr(fig,'watch') 
            [newfilt, errstr] = fdutil('callModuleApply',...
                                   ud.currentModule,newfilt,'up',L);
            if isempty(errstr) & ~isequal(ud.filt,newfilt)
                newfiltFlag = 1;
                set([ud.ht.revert ud.ht.apply],'enable','off')    
            end
            set(fig,oldptr{:}) 
        end
        
        if length(lineud.segmentenddragcallback)>1
            segmentenddragcallback = lineud.segmentenddragcallback{segind};
        else
            segmentenddragcallback = lineud.segmentenddragcallback{1};
        end
        evalin('base',segmentenddragcallback)
        
        
        set(fig,'windowbuttonmotionfcn',save_wbmf)
        set(fig,'windowbuttonupfcn','')
        clear global fd_line_motion_message
    end
    
    if ~isempty(lineud.buttonupfcn)
        evalin('base',lineud.buttonupfcn)
    end
    
    if ~isempty(errstr)
        msgstr = {'Sorry, this filter could not be designed.' 
                  'Reverting to last valid filter.' 
                  'Error message:' 
                  errstr};
        msgbox(msgstr,'Error',...
               'error','modal')
        filtdes('revert')
        return
    end
    
    if newfiltFlag
        ud = get(fig,'userdata');
        ud.filt = newfilt;
        ud.filt = importFiltNoLineinfo(ud.filt);
        set(fig,'userdata',ud)
        sptool('import',ud.filt,1)
        for i = 1:length(ud.Objects.fdspec)
            ud.Objects.fdspec(i).lastvalue = ud.Objects.fdspec(i).value;
            ud.Objects.fdspec(i).revertvalue = ud.Objects.fdspec(i).value;
        end
    end
    
%-------------------------------------------------------------------
% enable = filtdes('autodesign',fig)
%   Returns value of AutoDesign checkbox (1 or 0)
%   fig is optional; if not supplied, it is found using findobj
%
case 'autodesign'
    if nargin < 2
        fig = findobj('tag','filtdes');
    else
        fig = varargin{2};
    end
    ud = get(fig,'userdata');
    
    varargout{1} = get(ud.ht.autoDesign,'value'); 
    
%-------------------------------------------------------------------
% enable = filtdes('getenable',fig)
%   Returns 'on' or 'off' based on apply button's enable property
%   fig is optional; if not supplied, it is found using findobj
%
case 'getenable'
    if nargin < 2
        fig = findobj('tag','filtdes');
    else
        fig = varargin{2};
    end
    ud = get(fig,'userdata');
    
    varargout{1} = get(ud.ht.apply,'enable'); 
    
%-------------------------------------------------------------------
% filtdes('setenable',enable,fig)
%   Set revert and apply button's enable properties
%   fig is optional; if not supplied, it is found using findobj
case 'setenable'
    if nargin < 3
        fig = findobj('tag','filtdes');
    else
        fig = varargin{3};
    end
    ud = get(fig,'userdata');

    switch varargin{2}
    case 'on'
        if get(ud.ht.autoDesign,'value')==1
            filtdes('apply')
        else
            set([ud.ht.revert ud.ht.apply],'enable',varargin{2})
        end
    case 'off'
        set([ud.ht.revert ud.ht.apply],'enable',varargin{2})
    otherwise
        error('enable property of filtdes must be ''on'' or ''off''')
    end
%------------------------------------------------------------------------
%filtdes('zoom',button)
%  zoom function for filtdes
%   button is a string and can be any of:
%     mousezoom, zoomout, zoominy, zoomouty, zoominx,
%          zoomoutx, or passband
case 'zoom'

    if nargin < 3
        fig = gcbf;
    else
        fig = varargin{2};
    end
    ud = get(fig,'userdata');
    

    if ud.pointer==2   % help mode
        if strcmp(varargin{2},'mousezoom')
            state = btnstate(fig,'zoomgroup',7);
            if state
                btnup(fig,'zoomgroup',7)  % toggle button state back to
                                            % the way it was
            else
                btndown(fig,'zoomgroup',7) 
            end
        end
        spthelp('exit','fdzoom',varargin{2})
        return
    end
    
    switch varargin{2}
    case 'mousezoom'
        state = btnstate(fig,'zoomgroup','mousezoom');
        if state == 1   % button is currently down
            set(fig,'windowbuttondownfcn','filtdes(''zoom'',''mousedown'')')
            ud.pointer = 1;  
            set(fig,'userdata',ud)
            setptr(fig,'arrow')
        else   % button is currently up - turn off zoom mode
            set(fig,'windowbuttondownfcn','')
            ud.pointer = 0;
            set(fig,'userdata',ud)
            setptr(fig,'arrow')
        end

    case 'mousedown'  % this is a self callback prompted by a mouse click
                      % in the figure while the mousezoom button is down
        ud.justzoom = get(fig,'currentpoint');
        set(fig,'userdata',ud)

        pstart = get(fig,'currentpoint');

        % don't do anything if click is outside axes area
        fp = get(fig,'position');   % in pixels already
    
        afp = get(ud.ht.axFrame,'position');
        
        %click is outside of axes frame panel:
        if ~pinrect(pstart,[afp(1) afp(1)+afp(3) afp(2) afp(2)+afp(4)])
            if ~ud.prefs.tool.zoompersist
                % if click was on Mouse Zoom button, don't turn off button
                % because it will get turned off by its own callback  
                zg = findobj(fig,'type','axes','tag','zoomgroup');
                zgPos = get(zg,'position');
                if ~pinrect(pstart,[zgPos(1)+6*zgPos(3)/7 zgPos(1)+zgPos(3) ...
                                zgPos(2) zgPos(2)+zgPos(4)])
                    btnup(fig,'zoomgroup','mousezoom');
                    filtdes('zoom','mousezoom')
                end
            end
            return
        end

        r = rbbox([pstart 0 0],pstart);

        % Find out which axes was clicked in according to rules:
        % rule 1: click inside an axes - zoom in that axes
        % rule 2: current point is not in any axes - zoom in on axes most
        %         overlapping dragged rectangle
        
        if isempty(ud.Objects.fdax)
            return
        end
        
        open_axes = ud.Objects.fdax.h;
        if iscell(open_axes)
            open_axes = [open_axes{:}];
        end
        rects = [];
        target_axes = [];
        for i=1:length(open_axes)
            rects = [rects; get(open_axes(i),'position')];
            if pinrect(pstart,rects(i,[1 1 2 2])+[0 rects(i,3) 0 rects(i,4)])
                target_axes = open_axes(i);
            end
        end    
        if isempty(target_axes)
            overlap = rectint(r,rects);
            overlap = overlap(:)...
                  ./ (rects(:,3).*rects(:,4));
                % what percentage of the area of the axis is 
                %  covered by the dragged out rectangle?
            [maxoverlap,k] = max(overlap);
            if maxoverlap > 0
                target_axes = open_axes(k);
            end
        end

        if isempty(target_axes)
            return   % stay in zoom mode and return
        end
        oldxlim = get(target_axes,'xlim');
        oldylim = get(target_axes,'ylim');
    
        if all(r([3 4])==0)
        % just a click - zoom about that point
             p1 = get(target_axes,'currentpoint');

             xlim = get(target_axes,'xlim');
             ylim = get(target_axes,'ylim');

             switch get(fig,'selectiontype')
             case 'normal'     % zoom in
                 xlim = p1(1,1) + [-.25 .25]*diff(xlim);
                 ylim = p1(1,2) + [-.25 .25]*diff(ylim);
             otherwise    % zoom out
                 xlim = p1(1,1) + [-1 1]*diff(xlim);
                 ylim = p1(1,2) + [-1 1]*diff(ylim);
             end
        
        elseif any(r([3 4])==0)  
        % zero width or height - stay in zoom mode and 
        % try again
            return

        else 
        % zoom to the rectangle dragged
            set(fig,'currentpoint',[r(1) r(2)])
            p1 = get(target_axes,'currentpoint');
            set(fig,'currentpoint',[r(1)+r(3) r(2)+r(4)])
            p2 = get(target_axes,'currentpoint');
        
            xlim = [p1(1,1) p2(1,1)];
            ylim = [p1(1,2) p2(1,2)];
        end

        axesIndex = find(target_axes == open_axes);
        xlimbound = ud.Objects.fdax(axesIndex).xlimbound;
        ylimbound = ud.Objects.fdax(axesIndex).ylimbound;
        if ~isstr(xlimbound)
            xlim = inbounds(xlim,xlimbound);
        end
        if ~isstr(ylimbound)
            ylim = inbounds(ylim,ylimbound);
        end
        
        set(target_axes,'xlim',xlim,'ylim',ylim)
        
        if ~ud.prefs.tool.zoompersist
            setptr(fig,'arrow')
            set(fig,'windowbuttondownfcn','')
            btnup(fig,'zoomgroup','mousezoom');
            ud.pointer = 0;  
            set(fig,'userdata',ud)
        end
        
        set(fig,'currentpoint',ud.justzoom)

    case 'zoomout'
        if isempty(ud.Objects.fdax)
            return
        end

        open_axes = ud.Objects.fdax.h;
        if iscell(open_axes)
            open_axes = [open_axes{:}];
        end
        for i=1:length(open_axes)
            % temporarily hide lines which don't affect limit calculations
            L = filtdes('findobj','fdline','parent',open_axes(i),...
                    'affectlimits','off');
            Lh = L.h;  if iscell(Lh), Lh = [Lh{:}]; end
            saveVis = get(Lh,'visible');
            set(Lh,'visible','off')
            if isstr(ud.Objects.fdax(i).xlimbound)
                set(open_axes(i),'xlimmode','auto')
                set(open_axes(i),'xlim',get(open_axes(i),'xlim'))
            else
                set(open_axes(i),'xlim',ud.Objects.fdax(i).xlimbound)
            end
            if isstr(ud.Objects.fdax(i).ylimbound)
                set(open_axes(i),'ylimmode','auto')
                set(open_axes(i),'ylim',get(open_axes(i),'ylim'))
            else
                set(open_axes(i),'ylim',ud.Objects.fdax(i).ylimbound)
            end
            if ~iscell(saveVis)
                saveVis = {saveVis};
            end
            set(Lh,{'visible'},saveVis)
        end
    case 'zoominy'
        if isempty(ud.Objects.fdax)
            return
        end
        open_axes = ud.Objects.fdax.h;
        if iscell(open_axes)
            open_axes = [open_axes{:}];
        end
        for i=1:length(open_axes)
            ylim = get(open_axes(i),'ylim');
            newylim = .25*[3 1]*ylim' + [0 diff(ylim)/2];
            if diff(newylim) > 0
                set(open_axes(i),'ylim',newylim)
            end
        end
    case 'zoomouty'
        if isempty(ud.Objects.fdax)
            return
        end

        open_axes = ud.Objects.fdax.h;
        if iscell(open_axes)
            open_axes = [open_axes{:}];
        end
        for i=1:length(open_axes)
            ylim = get(open_axes(i),'ylim');
            ylim = .5*[3 -1]*ylim' + [0 diff(ylim)*2];
            ylimbound = ud.Objects.fdax(i).ylimbound;
            if ~isstr(ylimbound)
                ylim = [max(ylim(1),ylimbound(1)) min(ylim(2),ylimbound(2))];
            end
            set(open_axes(i),'ylim',ylim)
        end
    case 'zoominx'
        if isempty(ud.Objects.fdax)
            return
        end

        open_axes = ud.Objects.fdax.h;
        if iscell(open_axes)
            open_axes = [open_axes{:}];
        end
        for i=1:length(open_axes)
            xlim = get(open_axes(i),'xlim');
            newxlim = .25*[3 1]*xlim' + [0 diff(xlim)/2];
            if diff(newxlim) > 0
                set(open_axes(i),'xlim',newxlim)
            end
        end
    case 'zoomoutx'
        if isempty(ud.Objects.fdax)
            return
        end

        open_axes = ud.Objects.fdax.h;
        if iscell(open_axes)
            open_axes = [open_axes{:}];
        end

⌨️ 快捷键说明

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