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

📄 yhzfdview.m

📁 信号实验常用的simulink模型和mfile,可直接在matlan下运行。
💻 M
📖 第 1 页 / 共 2 页
字号:
        apos = get(ud.ht.a(4),'Position');
        set(ud.ht.a(4),'DataAspectRatio',[1 1 1],... %???
            'PlotBoxAspectRatio',apos([3 4 4]))
        xlim1 = min(real([ud.filt.zpk.z(:); ud.filt.zpk.p(:)]));
        xlim2 = max(real([ud.filt.zpk.z(:); ud.filt.zpk.p(:)]));
        ylim1 = min(imag([ud.filt.zpk.z(:); ud.filt.zpk.p(:)]));
        ylim2 = max(imag([ud.filt.zpk.z(:); ud.filt.zpk.p(:)]));
        if isempty(xlim1)
            xlim1 = -1.5;
        end
        if isempty(xlim2)
            xlim2 = 1.5;
        end
        if isempty(ylim1)
            ylim1 = -1.5;
        end
        if isempty(ylim2)
            ylim2 = 1.5;
        end
        if xlim1 == xlim2
            xlim1 = xlim1-1;
            xlim2 = xlim2+1;
        end
        if ylim1 == ylim2
            ylim1 = ylim1-1;
            ylim2 = ylim2+1;
        end
        set(get(ud.ht.a(4),'xlabel'),'userdata',[xlim1 xlim2 ylim1 ylim2]);
    end
    if any(plots([5 6]))
        [ud.filt.imp,ud.filt.t] = ...
              impz(ud.filt.num,ud.filt.den,[],Fs);
    end
    if plots(5)
        if isempty(ud.lines.imp)
            ud.lines.imp = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','none','marker','.',...
                 'tag','implinedots',...
                 'markerfacecolor',ud.prefs.linecolor,...
                 'parent',ud.ht.a(5),...
                 'buttondownfcn','yhzfdview(''mdown'')');
        end
        if isempty(ud.lines.impstem)
            ud.lines.impstem = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','-',...
                 'tag','implinestem',...
                 'parent',ud.ht.a(5),...
                 'buttondownfcn','yhzfdview(''mdown'')');
        end
        if isempty(ud.lines.impc)
            ud.lines.impc = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','none','marker','*',...
                 'tag','implinedots',...
                 'markerfacecolor',ud.prefs.linecolor,...
                 'parent',ud.ht.a(5),...
                 'buttondownfcn','yhzfdview(''mdown'')');
        end
        if isempty(ud.lines.impstemc)
            ud.lines.impstemc = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','-',...
                 'tag','implinestem',...
                 'parent',ud.ht.a(5),...
                 'buttondownfcn','yhzfdview(''mdown'')');
        end
        Localsetstem([ud.lines.imp ud.lines.impstem],ud.filt.t,real(ud.filt.imp))
        %function Localsetstem(h,x,y)
        %%Localsetstem Set xdata and ydata of two handles for stem plots

%        set(h(1),'xdata',x,'ydata',y)
%        x = x(:);  % make it a column
%        xx = x(:,[1 1 1])';
%        xx = xx(:);
%        n = nan;
%        y = [zeros(size(x)) y(:) n(ones(length(x),1),:)]';
%        set(h(2),'xdata',xx,'ydata',y(:));

        if sum(imag(ud.filt.imp).^2) > 1e-10 * sum(real(ud.filt.imp).^2)  %???
            Localsetstem([ud.lines.impc ud.lines.impstemc],ud.filt.t,imag(ud.filt.imp))
            set([ud.lines.impc ud.lines.impstemc],'visible','on')
        else
            set([ud.lines.impc ud.lines.impstemc],'visible','off')
        end
        set([ud.lines.imp ud.lines.impstem],'visible','on')
        set(ud.ht.a(5),'ylimmode','auto',...
                       'xlim',[ud.filt.t(1)-1/Fs  ud.filt.t(end)+1/Fs])
    end
    if plots(6)
        if isempty(ud.lines.step)
            ud.lines.step = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','none','marker','.',...
                 'tag','steplinedots',...
                 'markerfacecolor',ud.prefs.linecolor,...
                 'parent',ud.ht.a(6),...
                 'buttondownfcn','yhzfdview(''mdown'')');
        end
        if isempty(ud.lines.stepstem)
            ud.lines.stepstem = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','-',...
                 'tag','steplinestem',...
                 'parent',ud.ht.a(6),...
                 'buttondownfcn','yhzfdview(''mdown'')');
        end            
        if isempty(ud.lines.stepc)
            ud.lines.stepc = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','none','marker','*',...
                 'tag','steplinedots',...
                 'markerfacecolor',ud.prefs.linecolor,...
                 'parent',ud.ht.a(6),...
                 'buttondownfcn','yhzfdview(''mdown'')');
        end
        if isempty(ud.lines.stepstemc)
            ud.lines.stepstemc = line(nan,nan,'color',ud.prefs.linecolor,...
                 'linestyle','-',...
                 'tag','steplinestem',...
                 'parent',ud.ht.a(6),...
                 'buttondownfcn','yhzfdview(''mdown'')');
           end         
        stepA=ud.filt.den;
        stepB=ud.filt.num;
        stepX=ones(1,length(ud.filt.t));
        ud.filt.step = myfilter(stepB,stepA,stepX);%ud.filt.num,ud.filt.den,ones(1,length(ud.filt.t)));
        Localsetstem([ud.lines.step ud.lines.stepstem],ud.filt.t,real(ud.filt.step))
        if sum(imag(ud.filt.step).^2) > 1e-10 * sum(real(ud.filt.step).^2)   %???
            Localsetstem([ud.lines.stepc ud.lines.stepstemc],ud.filt.t,imag(ud.filt.step))
            set([ud.lines.stepc ud.lines.stepstemc],'visible','on')
        else
            set([ud.lines.stepc ud.lines.stepstemc],'visible','off')
        end
        set([ud.lines.step ud.lines.stepstem],'visible','on')
        set(ud.ht.a(6),'ylimmode','auto',...
                       'xlim',[ud.filt.t(1)-1/Fs  ud.filt.t(end)+1/Fs])
    end

    set(fig,'userdata',ud)
    %sptool('import',ud.filt)

%------------------------------------------------------------------------
% yhzfdview('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;
%        ud.pointer = 0; 
%        set(fig,'userdata',ud);
%        fvmotion(ud.toolnum)
%    else
%        set(ud.tabfig,'visible','on')
%        figure(ud.tabfig)
%    end
    
%------------------------------------------------------------------------
% yhzfdview('mdown')
%  mouse down event on one of the lines
%
case 'mdown'
    [l,fig] = gcbo;
    ud = get(fig,'userdata');
    %if ud.pointer == 2  % help mode
    %    fvhelp('line')  %???
    %    return
    %end
    
    if ~Localjustzoom(fig)
        ax = get(l,'parent');
        if ax==ud.ht.a(5) | ax==ud.ht.a(6)
            erasemode = 'xor';
        else
            erasemode = 'background';
        end
        
        xlim = get(ax,'xlim');
        ylim = get(ax,'ylim');
        set(ax,'ylimmode','auto','xlimmode','auto')
        bounds.xlim = get(ax,'xlim');
        bounds.ylim = get(ax,'ylim');
        set(ax,'ylim',ylim,'xlim',xlim)
        panfcn('erasemode',erasemode,'bounds',bounds)
    end
    
%------------------------------------------------------------------------
% enable = yhzfdview('selection',action,msg,SPTfig)
%  respond to selection change in SPTool
% possible actions are
%    'view'
%  Button is enabled when
%     a) there is a filter selected
%
%case 'selection'
%    msg = varargin{3};
%    SPTfig = varargin{4};
%    f = sptool('Filters',0,SPTfig);
%    if isempty(f)
%        varargout{1} = 'off';
%    else
%        varargout{1} = 'on';
%    end

%    fig = findobj('type','figure','tag','yhzfdview');
%    if ~isempty(fig)  % update filter viewer
%        ud = get(fig,'userdata');
%        if ~isequal(f,ud.filt)
%            if isempty(f)
%                set(ud.ht.Fsedit,'string','')
%                set(ud.ht.filterLabel,'string',['Filter: <none>'])
%                ud.filt.tf = [];
%                h = struct2cell(ud.lines);
%                h = [h{:}];
%                delete(h)
%                flds = fieldnames(ud.lines);
%                for i = 1:length(flds)
%                    eval(['ud.lines.' flds{i} '=[];'])
%                end
%            else         
%                ud.filt = f; 
%                ud.prefs.Fs = sprintf('%.9g',f.Fs);
%                set(ud.ht.filterLabel,'string',['Filter: ' ud.filt.label])
%                set(ud.ht.Fsedit,'string',['Fs = ' ud.prefs.Fs])
%            end
%            set(fig,'userdata',ud)
%            yhzfdview('plots',ud.prefs.plots,fig)
%        end
%    end
    
%------------------------------------------------------------------------
% enable = yhzfdview('action',verb.action)
%  respond to button push in SPTool
% possible actions are
%    'view'
%
%case 'action'
%    SPTfig = gcf;
%    f = sptool('Filters',0,SPTfig);  % get selected filter
%    fig = findobj('type','figure','tag','yhzfdview');
%    if isempty(fig)  % create the yhzfdview tool
%        yhzfdview(f)
%    else % activate the yhzfdview
%        set(fig,'visible','on')
%        figure(fig)
%        ud = get(fig,'userdata');
%        if ~isequal(f,ud.filt)
%            ud.filt = f; 
%            ud.prefs.Fs = sprintf('%.9g',f.Fs);
%            set(ud.ht.Fsedit,'string',ud.prefs.Fs)
%            set(fig,'userdata',ud)
%            yhzfdview('plots',ud.prefs.plots,fig)
%            set(ud.ht.filterLabel,'string',['Filter: ' ud.filt.label])
%            set(ud.ht.Fsedit,'string',['Fs = ' ud.prefs.Fs])
%        end
%    end
%------------------------------------------------------------------------
% yhzfdview('SPTclose',verb.action)
%  respond to SPTool closing
% possible actions are
%    'view'
%
%case 'SPTclose'
%    fig = findobj('type','figure','tag','yhzfdview');
%    if ~isempty(fig)  % destroy the yhzfdview tool
%        ud = get(fig,'userdata');
%       delete(fig)
%    end
%------------------------------------------------------------------------
% yhzfdview('print')
%  print contents of yhzfdview (assumed in gcf)
%
%case 'print'
    

%------------------------------------------------------------------------
% yhzfdview('help')
% Callback of help button in toolbar
case 'help'
    fig = gcf;
    ud = get(fig,'userdata');
    if ud.pointer ~= 2   % if not in help mode
        % enter help mode
        saveEnableControls = [];
        ax = [ud.ht.a ud.toolbar.toolbar];
        titleStr = '滤波器设计_分析_帮助';
        helpFcn = 'yhzfvhelpstr';
        yhzspthelp('enter',fig,saveEnableControls,ax,titleStr,helpFcn)
    else
        yhzspthelp('exit')
    end
    
%------------------------------------------------------------------------
% errstr = yhzfdview('setprefs',panelName,p)
% Set preferences for the panel with name panelName
%
% Inputs:
%   panelName - string; must be either 'ruler','color', 'yhzfdview1', 
%               or 'yhzfdview2'
%              (see sptprefreg for definitions)
%   p - preference structure for this panel
%
%case 'setprefs'
%    errstr = '';
%    panelName = varargin{2};
%    p = varargin{3};
%    % first do error checking
%    switch panelName        
%    case 'yhzfdview1'
%        arbitrary_obj = {'arb' 'obj'};
%        nfft = evalin('base',p.nfft,'arbitrary_obj');
%        if isequal(nfft,arbitrary_obj)
%            errstr = 'Sorry, the FFT Length you entered could not be evaluated';
%        elseif isempty(nfft) | (round(nfft)~=nfft | nfft<=0 | ~isreal(nfft))
%            errstr = ['The FFT Length must be a positive integer.'];
%        end
%        if isempty(errstr)
%            nimp = evalin('base',p.nimp,'arbitrary_obj');
%            if isequal(nimp,arbitrary_obj)
%                errstr = 'Sorry, the Time Response Length you entered could not be evaluated';
%            elseif ~isempty(nimp) & (round(nimp)~=nimp | nimp<=0 | ~isreal(nimp))
%                errstr = ['The Time Response Length must be a positive integer' ...
%                          ' or the empty matrix ''[]'' (to get the default value).'];
%           end
%        end
%        if isempty(errstr) & (p.freqscale == 2 & p.freqrange == 3)
%            errstr = ['You can''t have frequency log scaling with a negative ' ...
%                      'frequency range.'];
%        end
%
%    case 'yhzfdview2'  % tiling
%    end
%    
%    varargout{1} = errstr;
%    if ~isempty(errstr)
%        return
%    end
%        
%    % now set preferences
%    fig = findobj('type','figure','tag','yhzfdview');
%    if ~isempty(fig)
%        ud = get(fig,'userdata');
 %       newprefs = ud.prefs;
%        switch panelName
%        case 'yhzfdview1'
%            newprefs.tool.zoompersist = p.zoomFlag;
%            newprefs.nfft = evalin('base',p.nfft);
%            newprefs.nimp = evalin('base',p.nimp);
%            
%            set(ud.ht.magpop,'value',p.magscale)
%            set(ud.ht.phasepop,'value',p.phaseunits)
%            set(ud.ht.fscalepop,'value',p.freqscale)
%            set(ud.ht.frangepop,'value',p.freqrange)
%                        
%            newprefs.magmode = {'linear' 'log' 'decibels'};
%            newprefs.magmode = newprefs.magmode{p.magscale};
%            newprefs.phasemode = {'degrees' 'radians'};
%            newprefs.phasemode = newprefs.phasemode{p.phaseunits};
%            newprefs.freqscale = {'linear' 'log'};
%            newprefs.freqscale = newprefs.freqscale{p.freqscale};
%            newprefs.freqrange = p.freqrange;
%                        
%        case 'yhzfdview2'
%            if p.mode1
%                newprefs.tilemode = [2 3];
%            elseif p.mode2
%                newprefs.tilemode = [3 2];
%            elseif p.mode3
%                newprefs.tilemode = [6 1];
%            elseif p.mode4
%            end
%        end
%        ud.prefs = newprefs;
%        set(fig,'userdata',ud)
%        
%        fvresize(1,fig)
%        yhzfvzoom('zoomout',ud.prefs.plots,fig)
%        yhzfdview('plots',ud.prefs.plots,fig)
%
%    end
%    
end  % of switch statement

function Localsetstem(h,x,y)           %???
%Localsetstem Set xdata and ydata of two handles for stem plots

    set(h(1),'xdata',x,'ydata',y)
    x = x(:);  % make it a column
    xx = x(:,[1 1 1])';
    xx = xx(:);
    n = nan;
    y = [zeros(size(x)) y(:) n(ones(length(x),1),:)]';
    set(h(2),'xdata',xx,'ydata',y(:));


function flag = Localjustzoom(fig)
%JUSTZOOM Determines whether the current buttondownfcn follows a 
%           zoom windowbuttondownfcn for the signal browser in figure fig.
%   Meant to be called by any buttondownfcn (eg, pickfcn, ruldown, 
%    pandown) that might be called AFTER the windowbuttondownfcn.
%   Writes userdata and clears flag if so.
 
%   Copyright (c) 1988-97 by The MathWorks, Inc.
% $Revision: 1.3 $

if nargin < 1
    fig = gcf;
end

ud = get(fig,'userdata');

if isequal(ud.justzoom,get(fig,'currentpoint'))
    flag = 1;
    ud.justzoom = [0 0];
    set(fig,'userdata',ud)
else
    flag = 0;
end



   

⌨️ 快捷键说明

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