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

📄 dtcongui.m

📁 ADSP TOOLBOX: Version 2.0 and gui m-files
💻 M
📖 第 1 页 / 共 2 页
字号:
function dtcongui(mode)
%DTCONGUI Graphical User Interface program for discrete convolution


% ADSP Toolbox: Version 2.0 
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998

% Assisted by Craig Borghesani
% http://world.std.com/~borg/


v=matverch;
if v<5,
errordlg('This gui requires MATLAB 5.x and above','Version Error');
return,
end

if nargin == 0, mode = 0; end

if mode ~= 0,
   f = gcf;
   ui = get(f,'userdata');
   action_pop  = ui(13);
   n_edt      = ui(4);
   xn_edt     = ui(6);
   h_edt      = ui(10);
   hn_edt     = ui(12);
   accept_btn = ui(7);
   top_axs     = ui(29);
   bot_axs     = ui(32);
   xh_axs     = ui(35);
   xhopr_axs     = ui(40);
   auto_check = ui(51);
end

if mode == 0,
   grey = [0.5,0.5,0.5];
   ltgrey = grey*1.5;
   dkgrey = grey*0.5;
   scrn_size = get(0,'screensize');
   fig_w = 620; fig_h = 450;
   flft = (scrn_size(3) - fig_w)/2;
   fbtm = (scrn_size(4) - fig_h)/2;


   ver_str = version;
   ver4    = length(findstr('4.',ver_str));
   if ver4,
      int_str = 'yes';
      f = figure('pos',[flft,fbtm,fig_w,fig_h],'menubar','none',...
            'name','Discrete Convolution','numbertitle','off',...
            'resize','off','vis','off','interruptible',int_str,...
            'color',dkgrey,'defaultaxesfontsize',10,...
          'defaulttextfontsize',10);
   else
      int_str = 'on';
      eval('f = colordef(''new'',''none'');');
      set(f,'pos',[flft,fbtm,fig_w,fig_h],'menubar','none',...
           'name','Discrete Convolution','numbertitle','off',...
           'resize','off','vis','off','interruptible',int_str,...
           'color',dkgrey,'defaultaxesfontsize',8,...
           'defaultuicontrolback',[0.5,0.5,0.5],...
           'defaulttextfontsize',8);
   end

%%% OPTIONS: 
   uim(1) = uimenu('label','OPTIONS');
   uim(2) = uimenu(uim(1),'label','Help and Info','callback','dtconhlp');
   uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
                          'callback','dtcongui(15)');
   uim(4) = uimenu(uim(1),'label','Print Figure','separator','on',...
                          'callback','printdlg(gcf)');
   uim(5) = uimenu(uim(1),'label','Close and Exit','separator','on',...
                          'callback','close(gcf)');
%%%%%%%


   lft = 10; btm = fig_h - 5;
   ui(1) = uicontrol('style','frame','pos',[5,btm-142-60+20,175,75+100],...
           'back',grey,'fore',ltgrey);

   btm = btm - 52+20;
   ui(2) = uicontrol('style','text','pos',[lft,btm,160,17],...
           'horiz','left','fore','c','string','Signal x[n]');

   btm = btm - 22;
   ui(3) = uicontrol('style','text','pos',[lft,btm,55,17],...
           'string','Range n','horiz','left');
   ui(4) = uicontrol('style','edit','pos',[lft+60,btm,105,18],...
           'back','w','string','-2,2');

   btm = btm - 22;
   ui(5) = uicontrol('style','text','pos',[lft,btm,30,17],'string','x[n]');
   ui(6) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
           'back','w','string','1 2 3 4 5');


   btm = btm - 30;
   ui(8) = uicontrol('style','text','pos',[lft,btm,160,17],...
           'horiz','left','fore','c','string','Signal h[n]','userdata',[]);

   btm = btm - 22;
   ui(9) = uicontrol('style','text','pos',[lft,btm,55,17],...
           'horiz','right','string','Range n');
   ui(10) = uicontrol('style','edit','pos',[lft+60,btm,105,18],...
           'back','w','string','-1,1');
   btm = btm - 22;
   ui(11) = uicontrol('style','text','pos',[lft,btm,30,17],'string','h[n]');
   ui(12) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
           'back','w','string','0 1 2');


   btm = btm - 25;
   ui(7) = uicontrol('style','push','pos',[lft+55,btm,70,17],...
           'string','Accept','callback','dtcongui(2)','userdata',[]);


   btm = btm - 45;
   ui(18) = uicontrol('style','text','pos',[lft,btm,50,17],...
           'back','r','string','Action');
   ui(13) = uicontrol('style','popup','pos',[lft+55,btm,115,20],...
           'string',['Edit Signals|Convolution Yxh|Convolution Yhx|',...
           'Correlation Rxh|Correlation Rhx'],...
           'back','w','callback','dtcongui(1)','interruptible',int_str);
   ui(54) = uicontrol('style','frame','pos',[5,btm-102,175,30],...
           'back',grey,'fore',ltgrey);

   btm = btm - 100;
   ui(53) = uicontrol('style','text','pos',[lft,btm+3,55,17],...
           'string','RESULT');
   ui(52) = uicontrol('style','text','pos',[lft+60,btm+3,105,20],...
           'horiz','left','back','w','userdata','');



   ui(29) = axes('units','pixel','pos',[210,260,390,150],'box','on',...
             'xgrid','on','ygrid','on','color','k');
  title('Signal x[n]');
   xlabel('Index n');
   ui(30) = line('xdata',0,'ydata',0,'color','y');
if ver4
   ui(31) = line('xdata',0,'ydata',0,'color','y','linestyle','o',...
            'userdata','o');
else
   ui(31) = line('xdata',0,'ydata',0,'color','y','linestyle','none',...
            'marker','o','userdata','o');
end
   set(get(ui(29),'title'),'userdata','-5,5');
  
   ui(32) = axes('units','pixel','pos',[210,60,390,150],'box','on',...
             'xgrid','on','ygrid','on','color','k');
  title('Signal h[n]');
   xlabel('Index n');
   ui(33) = line('xdata',0,'ydata',0,'color','g');
if ver4
   ui(34) = line('xdata',0,'ydata',0,'color','g','linestyle','o',...
            'userdata','o');
else
   ui(34) = line('xdata',0,'ydata',0,'color','g','linestyle','none',...
            'marker','o','userdata','o');
end
   set(get(ui(32),'title'),'userdata','-5,5');
  
   ui(35) = axes('units','pixel','pos',[-600,260,390,150],'box','on',...
             'xgrid','on','ygrid','on','xlim',[0,1],'color','k');
  title('Signals x and h Ready to Start Operation');
   xlabel('Dummy Index k');

    ui(36) = line('xdata',0,'ydata',0,'color','y');
if ver4
   ui(37) = line('xdata',0,'ydata',0,'color','y','linestyle','o',...
            'userdata','o');
else
   ui(37) = line('xdata',0,'ydata',0,'color','y','linestyle','none',...
            'marker','o','userdata','o');
end
   ui(38) = line('xdata',0,'ydata',0,'color','m','linewidth',2);
if ver4
   ui(39) = line('xdata',0,'ydata',0,'color','m','linestyle','*',...
            'userdata','*');
else
   ui(39) = line('xdata',0,'ydata',0,'color','m','linestyle','none',...
            'marker','*','userdata','*');
end

   ui(40) = axes('units','pixel','pos',[-600,60,390,150],'box','on',...
             'xgrid','on','ygrid','on','xlim',[0,1],'color','k');
  title('Results of Operation');
   xlabel('Index n');
   ui(41) = line('xdata',0,'ydata',0,'color','c');
if ver4
   ui(42) = line('xdata',0,'ydata',0,'color','c','linestyle','o',...
            'userdata','o');
else
   ui(42) = line('xdata',0,'ydata',0,'color','c','linestyle','none',...
            'marker','o','userdata','o');
end
   if ver4
   set(ui([36:39,41:42]),'erase','normal');
   else
   set(ui([36:39,41:42]),'erase','xor');
   end  
   set(ui(40),'userdata',ui(41:42));


ui(49) = uicontrol('style','push','pos',[370,5,90,20],...
           'string','<< Shift Left','callback','dtcongui(10)');
ui(50) = uicontrol('style','push','pos',[470,5,90,20],...
           'string','Shift Right >>','callback','dtcongui(11)');
ui(51) = uicontrol('style','push','pos',[270,5,90,20],...
           'string','AUTO','callback','dtcongui(12)',...
           'interruptible',int_str,'value',0);




   set(f,'userdata',ui);
   dtcongui(1);
   drawnow;
   set(f,'vis','on');

elseif mode == 1, % signal popup
   action = get(action_pop,'value');
   if action == 1
set(ui(7),'userdata',[]);
set(ui(8),'userdata',[]);
   set(ui([4,6,7,10,12]),'enable','on');
   set(ui([49:51]),'enable','off');
   set(top_axs,'pos',[210 260 390 150]);
   set(bot_axs,'pos',[210 60 390 150]);
   set(ui(35),'pos',[-600 260 390 150]);
   set(ui(40),'pos',[-600 60 390 150]);
   dtcongui(2);
   else
   dtcongui(2);
   end

elseif mode == 2, % accept

% obtain local range values
   n_str = get(n_edt,'string');
   if isempty(n_str)
      errordlg('No values entered for range for x[n].','Input Error');
      set(action_pop,'value',1);
      return;
   end
   n_val = eval(['[',n_str,']'],'[]');
   if isempty(n_val)
      errordlg('MATLAB syntax error for range of x[n].','Input Error');
      set(action_pop,'value',1);
      return;
   end
   if length(n_val)~=2
      errordlg('Range for x[n] requires 2 end values.','Input Error');
      set(action_pop,'value',1);
      return;
   end
   minn=n_val(1);maxn=n_val(2);
   if minn >= maxn,
      errordlg('Range for x[n]  must be entered as  min, max.','Input Error');
       set(action_pop,'value',1);
       return;
   end
   if rem(minn,1)| rem(maxn,1),
      errordlg('Range for x[n] must be integer valued.','Input Error');
       set(action_pop,'value',1);
       return;
   end


      xn_str = get(xn_edt,'string');
          if ~length(xn_str)
             errordlg('No Matlab array entered for x[n]!','Input Error');
       set(action_pop,'value',1);
             return;
          end

problem=0;if xn_str(1)=='W',
xn_str(1)=[];evalin('base',[xn_str ';'],'problem=1;')
if problem==0, xn_str=evalin('base',xn_str);
else
   errordlg('MATLAB Syntax error.','Input Error');
   return
end
end
      n = minn:maxn;

if isstr(xn_str)
      xn_str = ['[',xn_str,']'];
      ttt=0;
      eval([xn_str ';'],'ttt=1;');
      if ttt
         errordlg('Incorrect Matlab syntax for x[n].','Input Error');
       set(action_pop,'value',1);
         return;
      end
      xn_eval = eval(xn_str);
else
      xn_eval = xn_str;
end
      if length(xn_eval) ~= length(n) & length(xn_eval) ~= 1
     errordlg('Array length must equal range length for x[n].','Input Error');
       set(action_pop,'value',1);
         return;
      end
      if length(xn_eval)==1
         xn_eval=xn_eval*ones(size(n));
      end
   nx=n;
   set(n_edt,'userdata',n);
   set(xn_edt,'userdata',xn_eval);


% obtain local range values
   n_str = get(ui(10),'string');
   if isempty(n_str)
      errordlg('No values entered for range for h[n].','Input Error');
      set(action_pop,'value',1);
      return;
   end
   n_val = eval(['[',n_str,']'],'[]');
   if isempty(n_val)
      errordlg('MATLAB syntax error for range of h[n].','Input Error');
      set(action_pop,'value',1);
      return;
   end
   if length(n_val)~=2
      errordlg('Range for h[n] requires 2 end values.','Input Error');
      set(action_pop,'value',1);
      return;
   end
   minn=n_val(1);maxn=n_val(2);
   if minn >= maxn,
      errordlg('Range for h[n]  must be entered as  min, max.','Input Error');
       set(action_pop,'value',1);
       return;
   end
   if rem(minn,1)| rem(maxn,1),
      errordlg('Range for h[n] must be integer valued.','Input Error');
       set(action_pop,'value',1);
       return;
   end



      xn_str = get(ui(12),'string');
          if ~length(xn_str)
             errordlg('No Matlab array entered for h[n]!','Input Error');
       set(action_pop,'value',1);
             return;
          end
problem=0;if xn_str(1)=='W',
xn_str(1)=[];evalin('base',[xn_str ';'],'problem=1;')
if problem==0, xn_str=evalin('base',xn_str);
else
   errordlg('MATLAB Syntax error.','Input Error');
   return
end
end

      n = minn:maxn;

if isstr(xn_str)
      xn_str = ['[',xn_str,']'];
      ttt=0;

⌨️ 快捷键说明

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