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

📄 cztdemo.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 2 页
字号:
        'Callback',callbackStr);

    %===================================
    % Wmax frequency label and text field
    labelBottom=top-3*textHeight-2*spacing;
	labelLeft = left;
    labelPos = [labelLeft labelBottom labelWidth textHeight];
    h = uicontrol( ...
		'Style','text', ...
        'Units','normalized', ...
		'Position',labelPos, ...
        'String','Fmax', ...
        'Horiz','left', ...
        'Interruptible','off', ...
		'Background',[0.5 0.5 0.5], ...
        'Foreground','white');
	% Text field
    textPos = [labelRight-textWidth labelBottom textWidth textHeight];
    callbackStr = 'cztdemo(''Wmax'')';
    WmaxHndl = uicontrol( ...
		'Style','edit', ...
        'Units','normalized', ...
		'Position',textPos, ...
		'Horiz','center', ...
		'Background','white', ...
        'Foreground','black', ...
		'String','350','Userdata',350, ...
        'Callback',callbackStr);

    %===================================
    % Number of points label and text field
    labelBottom=top-4*textHeight-3*spacing;
	labelLeft = left;
    labelPos = [labelLeft labelBottom labelWidth textHeight];
    h = uicontrol( ...
		'Style','text', ...
        'Units','normalized', ...
		'Position',labelPos, ...
        'String','Npoints', ...
        'Horiz','left', ...
        'Interruptible','off', ...
		'Background',[0.5 0.5 0.5], ...
        'Foreground','white');
	% Text field
    textPos = [labelRight-textWidth labelBottom textWidth textHeight];
    callbackStr = 'cztdemo(''points'')';
    pointsHndl = uicontrol( ...
		'Style','edit', ...
        'Units','normalized', ...
		'Position',textPos, ...
		'Horiz','center', ...
		'Background','white', ...
        'Foreground','black', ...
		'String','300','Userdata',300, ...
        'Callback',callbackStr);

    %===================================
    % Radius (1) label and text field
    labelBottom=top-5*textHeight-4*spacing;
	labelLeft = left;
    labelPos = [labelLeft labelBottom labelWidth textHeight];
    h = uicontrol( ...
		'Style','text', ...
        'Units','normalized', ...
		'Position',labelPos, ...
        'String','R1', ...
        'Horiz','left', ...
        'Interruptible','off', ...
		'Background',[0.5 0.5 0.5], ...
        'Foreground','white');
	% Text field
    textPos = [labelRight-textWidth labelBottom textWidth textHeight];
    callbackStr = 'cztdemo(''radius1'')';
    radius1Hndl = uicontrol( ...
		'Style','edit', ...
        'Units','normalized', ...
		'Position',textPos, ...
		'Horiz','center', ...
		'Background','white', ...
        'Foreground','black', ...
		'String','1','Userdata',1, ...
        'Callback',callbackStr);

    %===================================
    % Radius (2) label and text field
    labelBottom=top-6*textHeight-5*spacing;
	labelLeft = left;
    labelPos = [labelLeft labelBottom labelWidth textHeight];
    h = uicontrol( ...
		'Style','text', ...
        'Units','normalized', ...
		'Position',labelPos, ...
        'String','R2', ...
        'Horiz','left', ...
        'Interruptible','off', ...
		'Background',[0.5 0.5 0.5], ...
        'Foreground','white');
	% Text field
    textPos = [labelRight-textWidth labelBottom textWidth textHeight];
    callbackStr = 'cztdemo(''radius2'')';
    radius2Hndl = uicontrol( ...
		'Style','edit', ...
        'Units','normalized', ...
		'Position',textPos, ...
		'Horiz','center', ...
		'Background','white', ...
        'Foreground','black', ...
		'String','1','Userdata',1, ...
        'Callback',callbackStr);

    %====================================
    % The INFO button
    labelStr='Info';
    callbackStr='cztdemo(''info'')';
    helpHndl=uicontrol( ...
        'Style','pushbutton', ...
        'Units','normalized', ...
        'Position',[left frmBottom+btnHt+spacing btnWid btnHt], ...
        'String',labelStr, ...
        'Callback',callbackStr);

    %====================================
    % The CLOSE button
    labelStr='Close';
    callbackStr='close(gcf)';
    closeHndl=uicontrol( ...
        'Style','pushbutton', ...
        'Units','normalized', ...
        'Position',[left frmBottom btnWid btnHt], ...
        'String',labelStr, ...
        'Callback',callbackStr);

    hndlList=[zplaneHndl responseHndl FsHndl WminHndl WmaxHndl pointsHndl ...
              radius1Hndl radius2Hndl btn1Hndl btn2Hndl helpHndl closeHndl];
    set(figNumber, ...
	'Visible','on', ...
	'UserData',hndlList);

    cztdemo('design')
    set(0,'showhiddenhandles',shh)
    return

elseif strcmp(action,'Fs'),
    hndlList = get(gcf,'UserData');
    Wmax = get(hndlList(5),'UserData');
    v = get(gco,'Userdata');
    s = get(gco,'String');
    vv = eval(s,num2str(v));
    if vv<Wmax*2, vv = v; end
    vv = round(vv*100)/100;
    set(gco,'Userdata',vv,'String',num2str(vv))
    cztdemo('design')
    return

elseif strcmp(action,'Wmin'),
    hndlList = get(gcf,'UserData');
    Fs = get(hndlList(3),'UserData');
    Wmax = get(hndlList(5),'UserData');
    v = get(gco,'Userdata');
    s = get(gco,'String');
    vv = eval(s,num2str(v));
    if vv>=Wmax, vv = v; end
    vv = round(vv*100)/100;
    set(gco,'Userdata',vv,'String',num2str(vv))
    cztdemo('design')
    return

elseif strcmp(action,'Wmax'),
    hndlList = get(gcf,'UserData');
    Fs = get(hndlList(3),'UserData');
    Wmin = get(hndlList(4),'UserData');
    v = get(gco,'Userdata');
    s = get(gco,'String');
    vv = eval(s,num2str(v));
    if vv<=Wmin, vv = v; end
    vv = round(vv*100)/100;
    set(gco,'Userdata',vv,'String',num2str(vv))
    cztdemo('design')
    return

elseif strcmp(action,'points'),
    v = get(gco,'Userdata');
    s = get(gco,'String');
    vv = eval(s,num2str(v));
    hndlList=get(gcf,'Userdata');  
    if vv<length(get(hndlList(10),'UserData')), vv = v; end
    vv = round(vv*100)/100;
    set(gco,'Userdata',vv,'String',num2str(vv))
    cztdemo('design')
    return

elseif strcmp(action,'radius1'),
    v = get(gco,'Userdata');
    s = get(gco,'String');
    vv = eval(s,num2str(v));
    if vv<=0 | vv>10, vv = v; end
    vv = round(vv*1000)/1000;
    set(gco,'Userdata',vv,'String',num2str(vv))
    cztdemo('design')
    return

elseif strcmp(action,'radius2'),
    v = get(gco,'Userdata');
    s = get(gco,'String');
    vv = eval(s,num2str(v));
    if vv<=0 | vv > 10, vv = v; end
    vv = round(vv*1000)/1000;
    set(gco,'Userdata',vv,'String',num2str(vv))
    cztdemo('design')
    return

elseif strcmp(action,'radio'),
    axHndl=gca;
    hndlList=get(gcf,'Userdata');
    for i=9:10,
      set(hndlList(i),'value',0) % Disable all the buttons
    end
    set(hndlList(s+8),'value',1) % Enable selected button
    set(hndlList(9),'Userdata',s) % Remember selected button
    cztdemo('design')
    return

elseif strcmp(action,'info'),
    set(gcf,'pointer','arrow')
	ttlStr = get(gcf,'Name');
	hlpStr1= [...
         ' This demo lets you explore two different Z-tran-'
         ' sform algorithms.  They are                     '
         '    FFT - the Fast Fourier Transform             '
         '    CZT - the Chirp-Z Transform                  '
         '                                                 '
         ' The upper plot shows the transform domain, and  '
         ' the lower plot shows the transform of a band-   '
         ' pass elliptic digital filter on the points with-'
         ' in the wedge show on the upper plot. The filter '
         ' has a passband from .4 to .7 of the Nyquist     '
         ' frequency (Nyquist = Fs/2).                     '
         '                                                 '
         ' The FFT computes the Z-transform on equally     '
         ' spaced points around the unit circle.           '
         '                                                 '
         ' The CZT computes the Z-transform on a spiral    '
         ' or "chirp" contour.  The contour is defined by  '
         ' initial frequency Fmin and radius R1, and final '
         ' frequency Fmax and radius R2.                   '];
	hlpStr2 = [...
         ' Fs is the sampling frequency.                   '
         '                                                 '
         ' Fmin and Fmax define a "wedge" of the unit      '
         ' circle.                                         '
         '                                                 '
         ' Npoints is the number of Z-transform points     '
         ' computed on the unit circle in the wedge        '
         ' defined by Fmin and Fmax.                       '
         '                                                 '  
         ' With FFT, the length of the transform is        '
         ' Npoints*Fs/(Fmax-Fmin), which computes          '
         ' Npoints points in the range Fmin to Fmax.       '
         ' If you are interested in a small frequency      '
         ' range, the CZT is much more efficient           '
         ' because it can "zoom-in" on the range you       '
         ' are interested in.                              '
         '                                                 '  
         ' Filename: cztdemo.m                             '];

    myFig = gcf;
    helpfun(ttlStr,hlpStr1,hlpStr2);
    return  % avoid fancy, self-modifying code which
    % is killing the callback to this window's close button
    % if you press the info button more than once.
    % Also, a bug on Windows MATLAB is killing the 
    % callback if you hit the info button even once!

    % Protect against gcf changing -- Change close button behind
    % helpfun's back
    ch = get(gcf,'ch');
    for i=1:length(ch),
      if strcmp(get(ch(i),'type'),'uicontrol'),
        if strcmp(lower(get(ch(i),'String')),'close'),
          callbackStr = [get(ch(i),'callback') ...
            '; cztdemo(''closehelp'',' num2str(myFig) ')'];
          set(ch(i),'callback',callbackStr)
          return
        end
      end
    end
    return

elseif strcmp(action,'closehelp'),
    % Restore close button help behind helpfun's back
    ch = get(gcf,'ch');
    for i=1:length(ch),
      if strcmp(get(ch(i),'type'),'uicontrol'),
        if strcmp(lower(get(ch(i),'String')),'close'),
          callbackStr = get(ch(i),'callback');
          k = findstr('; cztdemo(',callbackStr);
          callbackStr = callbackStr(1:k-1);
          set(ch(i),'callback',callbackStr)
          break;
        end
      end
    end
    ch = get(0,'ch');
    if ~isempty(find(ch==s)), figure(s), end % Make sure figure exists

end    % if strcmp(action, ...lose all

⌨️ 快捷键说明

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