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

📄 sosdemo.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 2 页
字号:
function sosdemo(action,s);
%SOSDEMO Second Order Sections Demontration for the Signal Processing Toolbox.

%   Copyright (c) 1988-98 by The MathWorks, Inc.
%   $Revision: 1.16 $  $Date: 1997/12/02 18:36:28 $

% Possible actions:
% initialize
% createplot
% viewtoggle
% filter
% grids
% slide
% showtoggle
% clickline
% puttitle
% order
% cutoff
% closehelp
% info

% button callbacks:
% info


if nargin<1,
    action='initialize';
end;

if strcmp(action,'createplot'), % create and plot Second order sections
    set(gcf,'Pointer','watch');
    hndlList=get(gcf,'Userdata');
    upHndl = hndlList(1);
    filterHndl = hndlList(2);
    orderHndl = hndlList(3);
    cutoffHndl = hndlList(4);
    btn1Hndl = hndlList(5);
    btn2Hndl = hndlList(6);
    slideHndl = hndlList(7);
    leftHndl = hndlList(8);
    rightHndl = hndlList(9);
    cascadeHndl = hndlList(12);
    gridHndl = hndlList(13);

    v = get(filterHndl,'value');
    op = get(filterHndl,'string'); op = deblank(op(v,:));
    n = get(orderHndl,'UserData');
    wn = get(cutoffHndl,'UserData');
    section = get(slideHndl,'value');
    v = get(upHndl,'value');
    updown = get(upHndl,'String'); updown = deblank(updown(v,:));
    cascade = get(cascadeHndl,'value');
    gr = get(gridHndl,'value');

    sos = get(filterHndl,'UserData');

    set(gcf,'nextplot','add')

    % Now plot response
    ax = newplot; 
    np = 256; m = size(sos,1);
    h = []; H = zeros(np,m);
    [H(:,1),F] = freqz(sos(1,1:3),sos(1,4:6),np,2);
    for i=2:m,
      if cascade,
          H(:,i) = H(:,i-1).*freqz(sos(i,1:3),sos(i,4:6),np,2);
      else
          H(:,i) = freqz(sos(i,1:3),sos(i,4:6),np,2);
      end
    end
    warnsave = warning;  % turn off "Log of zero" messages
    warning('off')
    H = 20*log10(abs(H));
    warning(warnsave)
    max_pt = max(max(H));
    for i=1:m,
       cb = sprintf('sosdemo(''lineclick'',%g)',i);
       h=[h,line((i)*ones(np,1),F,H(:,i),'color',linecolor(1),'buttondownfcn',cb)];
    end
    set(h(section),'color',linecolor(2));
    if get(btn1Hndl,'value')==0,
        invis = 1:m; invis(section) = []; set(h(invis),'visible','off');
    end
    if get(btn2Hndl,'value')==1, 
        view(60,30) 
        zlim = get(gca,'zlim');
        set(gca,'zlim',[max(zlim(1),-100) max(max_pt,10) ],...
             'xlim',[1 m+.01],'ylim',[0 1])
    else 
        view(90,0)
        zlim = get(gca,'zlim');
        set(gca,'zlim',[max(zlim(1),-100) max(max_pt,10) ],...
             'xlim',[1 m+.01],'ylim',[0 1])
    end
    
    if gr, grid on, else grid off, end
    axis(axis)

    set(rightHndl,'String',int2str(m),'UserData',m)
    set(slideHndl,'Max',m,'Value',section)

    sosdemo('puttitle')

    xlabel('Section'), ylabel('Frequency'), zlabel('Magnitude (dB)')
    set(gca,'UserData',h)
    set(gcf,'handlevisibility','callback')
    set(gcf,'Pointer','arrow');
    return

elseif strcmp(action,'initialize'),
    shh = get(0,'ShowHiddenHandles');
    set(0,'ShowHiddenHandles','on')
    figNumber=figure( ...
        'Name','Second Order Sections Demo', ...
        'handlevisibility','callback',...
        'IntegerHandle','off',...
        'NumberTitle','off');

    %==================================
    % Set up the axes
    axes( ...
        'Units','normalized', ...
        'Position',[0.10 0.22 0.60 0.7], ...
        'XTick',[],'YTick',[], ...
        'Box','on');
    set(figNumber,'defaultaxesposition',[0.10 0.22 0.60 0.7])

    %=================================
    % Set up the scroll bar
    sbBottom=0.1;
    sbLeft=0.05;
    barHeight = 0.04; 
    barWidth = .675;
    textWidth = barWidth/2;
    scrollPos = [sbLeft sbBottom barWidth barHeight];
    callbackStr = 'sosdemo(''slide'')';
    slideHndl = uicontrol( ...
         'Style','slider', ...
        'Units','normalized', ...
         'Position',scrollPos, ...
         'Value',6, ...
         'userdata',6, ...
         'min',1, ...
         'max',6, ...
        'Interruptible','off', ...
        'Callback',callbackStr);
    % Left and right range indicators
    c = get(gcf,'Color');
    if [.298936021 .58704307445 .114020904255]*c'<.5,
      fgColor = [1 1 1];
    else
      fgColor = [0 0 0];
    end
    rangePos = [sbLeft sbBottom-barHeight textWidth barHeight];
    leftHndl = uicontrol( ...
		'Style','text', ...
        'Units','normalized', ...
		'Position',rangePos, ...
		'Horiz','left', ...
		'Background',c, ...
        'Foreground',fgColor, ...
		'String','1');
    rangePos = [sbLeft+barWidth/2 sbBottom-barHeight textWidth barHeight];
    rightHndl = uicontrol( ...
		'Style','text', ...
        'Units','normalized', ...
		'Position',rangePos, ...
		'Horiz','right', ...
		'Background',c, ...
        'Foreground',fgColor, ...
		'String','6');

    %====================================
    % Information for all buttons (and menus)
    labelColor=[0.8 0.8 0.8];
    yInitPos=0.90;
    menutop=0.95;
    top=0.4;
    left=0.785;
    btnWid=0.175;
    btnHt=0.06;
    textHeight = 0.05;
    textWidth = 0.07;

    % Spacing between the button and the next command's label
    spacing=0.025;
    
    %====================================
    % The CONSOLE frame
    frmBorder=0.019; frmBottom=0.04; 
    frmHeight = 0.92; frmWidth = btnWid;
    yPos=frmBottom-frmBorder;
    frmPos=[left-frmBorder yPos frmWidth+2*frmBorder frmHeight+2*frmBorder];
    h=uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
	'BackgroundColor',[0.5 0.5 0.5]);

    %====================================
    % The UPDOWN Menu
    menuNumber=1;
    yPos=menutop-(menuNumber-1)*(btnHt+spacing);
    labelStr='Up|Down';
    callbackStr='sosdemo(''filter'')';

    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    upHndl=uicontrol( ...
        'Style','popupmenu', ...
        'Units','normalized', ...
        'Position',btnPos, ...
        'String',labelStr, ...
        'Interruptible','on', ...
        'Callback',callbackStr);

    %====================================
    % The FILTER Menu
    menuNumber=2;
    yPos=menutop-(menuNumber-1)*(btnHt+spacing);
    labelStr='Butter|Cheby1|Cheby2|Ellip';
    callbackStr='sosdemo(''filter'');';

    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    filterHndl=uicontrol( ...
        'Style','popupmenu', ...
        'Units','normalized', ...
        'Position',btnPos, ...
        'String',labelStr, ...
        'Interruptible','on', ...
        'Value',3,...   % chebyshev type 2
        'Callback',callbackStr);

    %===================================
    % Filter order
    top = yPos - btnHt - spacing;
    labelWidth = frmWidth-textWidth-.01;
    labelBottom=top-textHeight;
	labelLeft = left;
    labelRight = left+btnWid;
    labelPos = [labelLeft labelBottom labelWidth textHeight];
    h = uicontrol( ...
		'Style','text', ...
        'Units','normalized', ...
		'Position',labelPos, ...
        'Horiz','left', ...
        'String','Order:', ...
        'Interruptible','off', ...
		'BackgroundColor',[0.5 0.5 0.5], ...
        'ForegroundColor','white');
	% Text field
    textPos = [labelRight-textWidth labelBottom textWidth textHeight];
    callbackStr = 'sosdemo(''order'')';
    orderHndl = uicontrol( ...
		'Style','edit', ...
        'Units','normalized', ...
		'Position',textPos, ...
		'Horiz','right', ...
		'Background','white', ...
        'Foreground','black', ...
		'String','6','Userdata',6, ...
        'callback',callbackStr);

    %===================================
    % Filter cutoff
    top = yPos - 2*btnHt - 2*spacing;
    labelWidth = frmWidth-textWidth-.01;
    labelBottom=top-textHeight;
    labelLeft = left;
    labelRight = left+btnWid;
    %labelPos = [labelLeft labelBottom labelWidth textHeight];
    labelPos = [labelLeft labelBottom btnWid textHeight];
    h = uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'Horiz','left', ...
        'String','Cutoffs:', ...
        'Interruptible','off', ...
        'BackgroundColor',[0.5 0.5 0.5], ...
        'ForegroundColor','white');
	% Text field
    %textPos = [labelRight-1.5*textWidth labelBottom 1.5*textWidth textHeight];
    textPos = [labelLeft labelBottom-btnHt btnWid textHeight];
    callbackStr = 'sosdemo(''cutoff'')';
    cutoffHndl = uicontrol( ...
        'Style','edit', ...
        'Units','normalized', ...
        'Position',textPos, ...
        'Horiz','right', ...
        'Background','white', ...
        'Foreground','black', ...
        'String','[0.4 0.7]','Userdata',[.4 .7], ...
        'callback',callbackStr);

    top = labelBottom-4*spacing;

    %====================================
    % button 1
    btnNumber=1;
    yPos=top-(btnNumber-1)*(btnHt+spacing);
    labelStr='Show all';
    callbackStr='sosdemo(''showtoggle'');';

    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    btn1Hndl=uicontrol( ...
        'Style','checkbox', ...
        'Units','normalized', ...
        'Position',btnPos, ...
        'String',labelStr, ...
        'Value',1, ...
        'Callback',callbackStr);

    %====================================
    % button 2
    btnNumber=2;
    yPos=top-(btnNumber-1)*(btnHt+spacing);
    labelStr='3-D plot';
    callbackStr='sosdemo(''viewtoggle'');';

    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    btn2Hndl=uicontrol( ...
        'Style','checkbox', ...
        'Units','normalized', ...
        'Position',btnPos, ...
        'String',labelStr, ...
        'Value',1, ...
        'Callback',callbackStr);

    %====================================
    % button 3
    btnNumber=3;
    yPos=top-(btnNumber-1)*(btnHt+spacing);
    labelStr='Cascade';
    callbackStr='sosdemo(''createplot'');';

    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    btn3Hndl=uicontrol( ...

⌨️ 快捷键说明

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