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

📄 yhzfdesini.m

📁 信号实验常用的simulink模型和mfile,可直接在matlan下运行。
💻 M
字号:
function yhzfdesini(varargin)
%yhzfdesini Initialization routine for Filter Designer.
%   Create yhzfiltdes in new figure window
%   whichone is the instance of the yhzfiltdes 
%
 
%   Copyright (c) 1988-97 by The MathWorks, Inc.
% $Revision: 1.20 $

    shh = get(0,'showhiddenhandles');   % save and restore this value later
    set(0,'showhiddenhandles','on')

    %load fdestry.mat;  %filtStruc
    filtStruc=setFiltStruc;  % load filter parameters
    % ====================================================================
    % set defaults and initialize userdata structure
    %yhzfiltdesPrefs = sptool('getprefs','yhzfiltdes');
    ud.prefs.tool.zoompersist = 0;  %yhzfiltdesPrefs.zoomFlag;
    
    ud.prefs.Fs = '1';       % string for sampling frequency
    ud.prefs.gridding = 1; %yhzfiltdesPrefs.gridflag;   % snap to grid ?
    ud.prefs.nfft = 1024; %evalin('base',yhzfiltdesPrefs.nfft);    % frequency resolution
    xgridsize = 1e-03; %evalin('base',yhzfiltdesPrefs.fgrid);        %  Hz  grid size
    ygridsize = 1e-03; %evalin('base',yhzfiltdesPrefs.mgrid);        %  dB  grid size
    ud.prefs.gridsize = [xgridsize ygridsize];
    ud.prefs.minsize = [180 220]; 
      % minsize(1)   - minimum width of main axes in pixels
      % minsize(2)   - minimum height of main axes in pixels
      
    %ud.sz = sptsizes;
    ud.sz.ih= 47;
    ud.sz.iw= 42;
    ud.sz.lw= 130;
    ud.sz.fus= 5;
    ud.sz.ffs= 5;
    ud.sz.lfs= 3;
    ud.sz.lh= 18;
    ud.sz.uh= 20;
    ud.sz.rw= 130;
    ud.sz.rih= 40;
    ud.sz.riw= 55;
    ud.sz.pmw= 14;
    ud.sz.lbs= 3;
    ud.sz.as= [57.7350 46.1880 23.0940 34.6410];
    ud.sz.ph= 60;
    ud.sz.bw= 110;
    
    % filter specifications:
    ud.specs = filtStruc.specs;
    ud.label = filtStruc.label;
    ud.num = filtStruc.tf.num;
    ud.den = filtStruc.tf.den;
    ud.needEst = filtStruc.needEst;
    ud.filt = [ ];
    
    ud.justzoom = [0 0];

    %ud.filtviewfig = [];  %handle of filtview tool linked to this tool
    ud.tabfig = [];  % settings figure handle
    %ud.paramdlg = [];  % figure handle of parameters dialog figure
    
    ud.pointer = 0;  % pointer mode ...  == -1 watch, 0 arrow/drag indicators, 1 zoom,
                     %     2 help
    %ud.saved = 1;  % flag which tells if specifications have been saved or not
    
    ud.filtind=1;   % index to the number of filters shown in the window
    
    figname = prepender('滤波器设计与比较');
    fig = findobj('type','figure','name',figname);
    if ~isempty(fig)  % if figure is present, just make it current and return
        figure(fig)
        return
    end
    
    %==================================
    % create NEW figure
    % set interruptible to 'on' so we don't lose mouse ups during long
    %   mouse motion callbacks.
    figNumber=figure( ...
        'Name',figname, ...
        'units','pixels',...
        'interruptible','on',...
        'visible','off',...
        'menubar','none',...
        'integerhandle','off',...
        'handlevisibility','callback',...
        'tag','yhzfiltdes',...
        'closerequestfcn','delete(gcf)',...     %yhzfiltdes(''close'')',...
        'inverthardcopy','off',...
        'paperpositionmode','auto',...
        'NumberTitle','off');

    %==================================
    % Set up the frequency response axes
    ud.ht.ax1 = axes('Units','pixels', ...
        'xlim',[0 ud.specs.Fs/2],'ylim',[-ud.specs.Rs-20 5], ...
        'visible','on',...
        'tag','yhzmainaxes',...
        'Box','on');
    % create the magnitude line; 
    colors = get(gca,'colororder'); 
    ud.ht.magline = line(0,0,'tag','yhzmagline','color',colors(1,:),...
                         'buttondownfcn','yhzfiltdes(''mdown'',3)');
    ud.ht.panfcnline = line(0,0,'tag','yhzpfline','color',colors(1,:),'visible','off');

    xlabel('频率轴','tag','yhzmainaxes')
    ylabel('幅度(分贝)','tag','yhzmainaxes')

    % create the pass and stopband lines
    colors = get(gca,'colororder'); 
    speccolor = colors(min(size(colors,1),2),:);
    % passband ripple line:
    ud.ht.specline1 = line('color',speccolor,'linewidth',2,...
                 'erasemode','normal','tag','yhzpbripline',...
                 'buttondownfcn','yhzfiltdes(''mdown'',1)','xdata',0,'ydata',0);  
    % stopband attenuation line:
    ud.ht.specline2 = line('color',speccolor,'linewidth',2,...
                 'erasemode','normal','tag','yhzsbattenline',...
                 'buttondownfcn','yhzfiltdes(''mdown'',2)','xdata',0,'ydata',0);  
 
    %====================================
    % The CONSOLE frame

    ud.ht.consoleframe=uicontrol( ...
        'units','pixels',...
        'Style','frame','tag','yhzconsoleframe');

    %====================================
    % The Filter Type Selection Menu
    labelStr=['低通|高通|带通'];
    %   ['Equiripple|Least Square|Kaiser Window|' ...
    %          'Butterworth|Chebyshev 1|Chebyshev 2|Elliptic'];
    callbackStr='yhzfiltdes(''changeFType'');';
    ud.ht.FType=uicontrol( ...
        'units','pixels',...
        'value',1,...
        'tag','yhzfilttypepop',...
        'Style','popupmenu', ...
        'String',labelStr, ...
        'Callback',callbackStr);

    %====================================
    % The FIR Method Selection Menu
    labelStr=['矩形窗|海宁窗|汉明窗|不莱克曼窗|凯撒窗|频率采样法']; %Lowpass|Highpass|Bandpass|Bandstop';
    callbackStr='yhzfiltdes(''changefirmethod'');';
    ud.ht.firmethod=uicontrol( ...
        'units','pixels',...
        'Style','popupmenu', ...
        'tag','yhzfiltfirpop',...
        'String',labelStr, ...
        'Callback',callbackStr);

    %====================================
    % The IIR Method Selection Menu1/AFPrototype
    labelStr=['巴特沃斯|切比雪夫I|切比雪夫II'];
    callbackStr='yhzfiltdes(''changeiirmethod1'');';
    ud.ht.iirmethod1=uicontrol(...
       'units','pixels',...
       'Style','popupmenu',...
       'tag','yhzfiltiirpop1',...
       'string',labelStr,...
       'Callback',callbackStr);
     
    %====================================
    % The IIR Method Selection Menu2/BLT/IRI
    labelStr=['双线性变换法|脉冲相应不变法'];
    callbackStr='yhzfiltdes(''changeiirmethod2'');';
    ud.ht.iirmethod2=uicontrol(...
       'units','pixels',...
       'Style','popupmenu',...
       'tag','yhzfiltiirpop2',...
       'string',labelStr,...
       'Callback',callbackStr);
    %====================================
    % 'tall' fields for labels and specifications
    labelStr=sprintf(' fp:\n fs:\n\n Rp:\n Rs:\n');
    ud.ht.labelHndl=uicontrol( ...
        'units','pixels',...
        'Style','text', ...
        'horizontalalignment','right',...
        'String',labelStr, ...
        'max',2,...
        'value',0, ...
        'tag','yhzspeclabels');

    callbackStr = 'yhzfiltdes(''edit'')';
    %defaultstr = fdspecstr(ud.specs);
    if ud.specs.FType <= 2
        defaultstr = sprintf('%4.3g\n%4.3g\n\n%4.3g\n%4.3g',ud.specs.f(1),ud.specs.f(2),...
          ud.specs.Rp,ud.specs.Rs);
 %         spec.Rp,spec.Rs); 
% sprintf('%g\n%g\n\n%g\n%g',ud.specs.f(1),ud.specs.f(2),...
%          ud.specs.Rp,ud.specs.Rs);
    else
       defaultstr = sprintf('%4.3g%s%4.3g\n%4.3g%s%4.3g\n\n%4.3g\n%4.3g',ud.specs.f(1,1),'   ',...
          ud.specs.f(1,2),ud.specs.f(2,1),'   ',ud.specs.f(2,2),...
          ud.specs.Rp,ud.specs.Rs);
    end
    ud.ht.specHndl = uicontrol( ...
        'units','pixels',...
        'Style','edit', ...
        'HorizontalAlignment','left', ...
        'Background','white', ...
        'Foreground','black', ...
        'String',defaultstr, ...
        'max',2,...
        'tag','yhzspectextbox',...
        'callback',callbackStr);

    %====================================
    % fields for label and sampling frequency
    labelStr=sprintf(' Fs:');
    ud.ht.labelHndl1=uicontrol( ...
        'units','pixels',...
        'Style','text', ...
        'String',labelStr, ...
        'horizontalalignment','right',...
        'value',0, ...
        'tag','yhzFs');
     
    callbackStr = 'yhzfiltdes(''setFs'')';
    defaultstr = sprintf('%g',ud.specs.Fs);
    ud.ht.FsHndl = uicontrol( ...
        'units','pixels',...
        'Style','edit', ...
        'Horizontalalignment','left', ...
        'enable','on',... %inactive',...
        'String',defaultstr, ...
        'userdata',ud.specs.Fs,...
        'tag','yhzFs',...
        'callback',callbackStr);

    %====================================
    % fields for FIR window length or sampling length
    if ud.specs.firmethod==5
       labelStr=sprintf(' N:\nbeta:');
    else   
       labelStr=sprintf(' N:');
    end   
    ud.ht.firlabelHndl=uicontrol( ...
        'units','pixels',...
        'Style','text', ...
        'String',labelStr, ...
        'horizontalalignment','right',...
        'value',0, ...
        'tag','yhzfirN');
     
    callbackStr = 'yhzfiltdes(''setfirN'')';
    if ud.specs.firmethod==5
       defaultstr = sprintf('%g\n%g',ud.specs.firN,ud.specs.kaiserbeta);
    else
       defaultstr = sprintf('%g',ud.specs.firN);
    end   
    ud.ht.firNHndl = uicontrol( ...
        'units','pixels',...
        'Style','edit', ...
        'Horizontalalignment','left', ...
        'Background','white', ...
        'Foreground','black', ...
        'enable','on',...
        'String',defaultstr, ...
        'userdata',ud.specs.firN,...
        'tag','yhzfirN',...
        'max',2,...
        'callback',callbackStr);

     
     
    %====================================
    % IIR Filter Order text label 
    labelStr=sprintf('阶数:');
    ud.ht.iirlabelHndl=uicontrol( ...
        'units','pixels',...
        'Style','text', ...
        'String',labelStr, ...
        'horizontalalignment','right',...
        'value',0, ...
        'tag','yhziirorder');
     
    callbackStr = 'yhzfiltdes(''setiirorder'')';
    defaultstr = sprintf('%g',ud.specs.iirorder);
    ud.ht.iirorderHndl = uicontrol( ...
        'units','pixels',...
        'Style','edit', ...
        'Horizontalalignment','left', ...
        'enable','on',...
        'Background','white', ...
        'Foreground','black', ...
        'String',defaultstr, ...
        'userdata',ud.specs.iirorder,...
        'tag','yhziirorder',...
        'callback',callbackStr);
    %ud.ht.orderLabel = uicontrol( ...
    %    'units','pixels',...
    %    'Style','text', ...
    %    'Horiz','center', ...
    %    'tag','yhzordertext',...
    %    'String','Order');
%
    %====================================
    % radiobutton for FIR choose
    %%%Estimate radio button and text field
    labelStr='FIR滤波器设计';
    callbackStr='yhzfiltdes(''changefir'')';
    ud.ht.changefir=uicontrol( ...
        'units','pixels',...
        'Style','radiobutton', ...
        'String',labelStr, ...
        'value',1,...
        'tag','yhzfirradio',...
        'Callback',callbackStr);
    %ud.ht.ord1Hndl = uicontrol( ...
    %    'units','pixels',...
    %    'Style','text', ...
    %    'tag','autoradio',...
    %    'HorizontalAlignment','left', ...
    %    'String',num2str(ud.specs.order.auto));

    %====================================
    % radiobutton for IIR choose
    %%%% Specify radio button and text field
    labelStr='IIR滤波器设计';
    callbackStr='yhzfiltdes(''changeiir'');';
    ud.ht.changeiir=uicontrol( ...
        'units','pixels',...
        'Style','radiobutton', ...
        'String',labelStr, ...
        'value',0, ...
        'tag','yhziirradio',...
        'Callback',callbackStr);
    %callbackStr = 'yhzfiltdes(''setord'')';
    %ud.ht.ord2Hndl = uicontrol( ...
    %    'units','pixels',...
    %    'Style','edit', ...
    %    'HorizontalAlignment','left', ...
    %    'Background','white', ...
    %    'Foreground','black', ...
    %    'tag','setradio',...
    %    'String',num2str(ud.specs.order.manual), ...
    %    'callback',callbackStr);
    
    %====================================
    % MENUS

 %  MENU LABEL                     CALLBACK                                   TAG
mc={  
'&File'                     ' '                                                'File'
'>&Close^w'                 'delete(''gcf'')'                               'close'
'&Options'                     ' ' ' ' 
%'>&Special Design Parameters...^p' 'sbswitch(''fdspdlg'',''paramdialog'')'     'paramdialog'
'&Window'                    winmenu('callback')                              'winmenu'};

    handles = makemenu(gcf, char(mc(:,1)), ...
                            char(mc(:,2)), char(mc(:,3)));

    set(handles,'handlevisibility','callback')

    winmenu(gcf)  % initialize windows menu

    % NOW the uicontrols and other objects are set up
    
   % ud.ht.Omenu1 = findobj(gcf,'type','uimenu','tag','Omenu1');
   % ud.ht.designmenu = findobj(gcf,'type','uimenu','tag','designnow');
    
    ud.limits.xlim = [0 ud.specs.Fs/2];
    ud.limits.ylim = [-300 10];
    
    drawnow  % draw all these invisible objects

    set(figNumber,'UserData',ud);

    % ====================================================================
    % now add toolbar for Filter Designer
    btnlist = {  'zoominy' 'zoomouty' 'zoominx' ...
              'zoomoutx'  'passband' 'zoomout' 'mousezoom' 'help'}';
    tb_callbackstr = {
       'sbswitch(''yhzfdzoom'',''zoominy'')'
       'sbswitch(''yhzfdzoom'',''zoomouty'')'
       'sbswitch(''yhzfdzoom'',''zoominx'')'
       'sbswitch(''yhzfdzoom'',''zoomoutx'')'
       'sbswitch(''yhzfdzoom'',''passband'')'
       'sbswitch(''yhzfdzoom'',''zoomout'')'
       'sbswitch(''yhzfdzoom'',''mousezoom'')'
       'sbswitch(''yhzfiltdes'',''help'')' };
    yhzzoombar('fig',figNumber,'btnlist',btnlist,'callbacks',tb_callbackstr,...
            'left_width',0); 
    yhzfdresize(1,figNumber)
    set(figNumber,'resizefcn',...
            yhzappstr(get(figNumber,'resizefcn'),'sbswitch(''yhzfdresize'')'))

    set(figNumber, 'Visible','on');
    set(get(ud.ht.ax1,'title'),'Interpreter','none','tag','title')
  %  yhzfiltdes('specchange')
  %  yhzfiltdes('copyspecials')
    eval('yhzfiltdes(''setfilt'',filtStruc,figNumber)');
    
    set(get(ud.ht.ax1,'zlabel'),'userdata',[0 ud.specs.Fs/2  -ud.specs.Rs-20 5])
    
    %set(figNumber,'windowbuttonmotionfcn','sbswitch(''fdmotion'',''1'')')

    set(0,'showhiddenhandles',shh)

⌨️ 快捷键说明

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