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

📄 maplpgui.m

📁 ADSP TOOLBOX: Version 2.0 and gui m-files
💻 M
字号:
function maplpgui(mode)
%MAPLPGUI Graphical User Interface program for filter transformations


% 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


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');
   type_edt = ui(3);
   sig_axs=ui(32);
   opr_axs=ui(34);
   clear_btn = ui(14);
   curs_btn = ui(31);
   curs_dsp = ui(27:30);
   autoplot    = ui(13);
   plot_btn    = ui(14);

end

if mode == 0,
   grey = [0.5,0.5,0.5];
   ltgrey = grey*1.5;
   dkgrey = grey*0.5;
   offwhite = grey*1.9;
   scrn_size = get(0,'screensize');
   fig_w = 620; fig_h = 440+16;
   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','Filter Transformations','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','Filter Transformations','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','maplphlp');
   uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
                          'callback','maplpgui(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)');
   uim(6) = uimenu('label','   Axis Limits','separator','on',...
                          'callback','maplpgui(17)');
   uim(7) = uimenu('label','   Zoom ON','separator','on',...
                          'callback','maplpgui(18)');
   uim(8) = uimenu('label','   Zoom OFF','separator','on',...
                          'callback','maplpgui(19)');
   uim(9) = uimenu('label','   RESIZE','callback','maplpgui(20)');


%%%%%%%%%



   lft = 10; btm = fig_h - 5;
   ui(1) = uicontrol('style','frame','pos',[5,btm-200+138-20+44,175,72-44],...
           'back',grey,'fore',ltgrey);


   btm = btm - 35;
   ui(2) = uicontrol('style','text','pos',[lft,btm,40,17],...
           'string','Type','fore','c','horiz','left');
   ui(3) = uicontrol('style','popup','pos',[lft+41,btm,125,20],...
        'string',['Analog to analog|Analog to digital|Digital to digital'],...
           'back','w','callback','maplpgui(2)');

   btm=btm-12;
   ui(4) = uicontrol('style','frame','pos',[5,btm-142-24+100-22,175,65+22],...
           'back',grey,'fore',ltgrey);

   btm = btm - 22;
   ui(5) = uicontrol('style','text','pos',[lft,btm,130,17],...
           'string','Lowpass Transfer Function','horiz','left','fore','c');
   ui(6) = uicontrol('style','text','pos',[lft+135,btm,30,17],...
           'string','H(s)','back',offwhite);

   btm = btm - 20;
   ui(7) = uicontrol('style','text','pos',[lft,btm,30,17],...
           'string','Num','horiz','left');
%   ui(8) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
%           'back','w','string','1','callback','maplpgui(4)');
   ui(8) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
           'back','w','string','1');

   btm=btm - 20;
   ui(9) = uicontrol('style','text','pos',[lft,btm,30,17],...
           'string','Den','horiz','left');
%   ui(10) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
%           'back','w','string','1 0.5','callback','maplpgui(4)');
   ui(10) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
           'back','w','string','1 0.5');
   btm=btm - 20;
   ui(11) = uicontrol('style','text','pos',[lft,btm,60,17],...
           'string','Cutoff Freq','horiz','left');
   ui(12) = uicontrol('style','edit','pos',[lft+65,btm,100,18],...
           'back','w','string','1','callback','maplpgui(4)');

   ui(15) = uicontrol('style','frame','pos',[5,btm-200+138-20-22,175,72+22],...
           'back',grey,'fore',ltgrey,'userdata',0);

   btm = btm - 35;
   ui(16) = uicontrol('style','text','pos',[lft,btm,70,17],...
           'string','Method','fore','c','horiz','left');
   ui(17) = uicontrol('style','popup','pos',[lft+75,btm,90,20],...
           'string','LP2LP|LP2HP|LP2BP|LP2BS','back','w',...
           'callback','maplpgui(1)');

   btm = btm - 22;
   ui(18) = uicontrol('style','text','pos',[lft,btm,70,17],...
           'string','Band edge(s)','fore','c','horiz','left');
   ui(19) = uicontrol('style','edit','pos',[lft+75,btm,90,20],...
           'string','4','back','w',...
           'callback','maplpgui(4)');

  btm = btm - 22;
   ui(20) = uicontrol('style','text','pos',[lft,btm,70,17],...
           'string','Plot to (Hz)','fore','c','horiz','left');
   ui(21) = uicontrol('style','edit','pos',[lft+75,btm,90,20],...
           'string','10','back','w',...
           'callback','maplpgui(4)');
   ui(22) = uicontrol('style','text','pos',[lft,btm,70,17],...
           'string','Sampling Freq','fore','c','vis','off','horiz','left');
   ui(23) = uicontrol('style','edit','pos',[lft+75,btm,90,20],...
           'string','20','back','w',...
           'callback','maplpgui(4)','vis','off');

 btm = btm - 22;
   ui(24) = uicontrol('style','text','pos',[lft,btm,95,17],...
           'string','Center freq (opt)','fore','c','horiz','left','vis','off');
   ui(25) = uicontrol('style','edit','pos',[lft+100,btm,65,20],...
           'string','','back','w',...
           'callback','maplpgui(3)','vis','off');

   btm=btm - 28;
   ui(13) = uicontrol('style','check','pos',[lft,btm,90,17],...
           'string','AutoPlot','callback','maplpgui(5)',...
           'value',0);
   ui(14) = uicontrol('style','push','pos',[lft+95,btm-2,70,20],...
           'string','Plot','callback','maplpplt;');

   btm = btm -55;
   ui(31) = uicontrol('style','check','pos',[lft+100,btm,70,20],...
           'string','Cursor','back','y','callback','maplpgui(7)');



   pos = get(f,'pos');
   lef = pos(3)-166;
   bot = pos(4)-21;

   ui(27) = uicontrol('style','text','pos',[lef,bot,20,20],...
           'string','X ','horiz','right');
   ui(28) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
           'string','','back','w');
   ui(29) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
           'string','Y ','horiz','right');
   ui(30) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
           'string','','back','w');
   set(ui(27:30),'vis','off');


   ui(32) = axes('units','pixel','pos',[210,260,390,155],'box','on',...
            'color','k','xcolor','w','ycolor','w','xgrid','on','ygrid','on');
   title('Gain of original filter');
   xlabel('Analog frequency  [Hz]')
   ui(33) = line('xdata',0,'ydata',0,'color','m');
   set(ui(32),'userdata',ui(33));

   ui(34) = axes('units','pixel','pos',[210,50,390,155],'box','on',...
            'color','k','xcolor','w','ycolor','w','xgrid','on','ygrid','on');
   title('Gain of transformed filter');
   xlabel('Analog frequency  [Hz]')
   ui(35) = line('xdata',0,'ydata',0,'color','y');
   set(ui(34),'userdata',ui(35));



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

elseif mode == 1, 
   filter_type = get(ui(17),'value');
   edt_val = eval(['[',get(ui(19),'string'),']'],'[]');
   if filter_type <3,val=1;else,val=2;end
   len=length(edt_val);
     if len~=val
      set(autoplot,'value',0),
      set(plot_btn,'enable','on');
     end

  if get(ui(3),'value')==2 & filter_type > 2
     set(ui([24,25]),'vis','on');
  else
     set(ui([24,25]),'vis','off');
  end

   if get(autoplot,'value'), maplpplt; end



elseif mode == 2, 
type = get(type_edt,'value');
  if type <3
     set(ui(6),'string','H(s)');
  else
     set(ui(6),'string','H(z)');
  end 

  if type == 1
     set(ui([20,21]),'vis','on');
     set(ui([22,23]),'vis','off');
  else
     set(ui([20,21]),'vis','off');
     set(ui([22,23]),'vis','on');
  end
  if type == 2  & get(ui(17),'value')>2
     set(ui([24,25]),'vis','on');
  else
     set(ui([24,25]),'vis','off');
  end

   if get(autoplot,'value'), maplpplt; end

elseif mode == 3, 
   if get(autoplot,'value'), maplpplt; end

elseif mode == 4
   edt = gco;
   edt_val = eval(['[',get(edt,'string'),']'],'[]');

   if ~length(edt_val),
      errordlg('You must enter a VALID number.','Input Error');
      return;
   end
   if any(edt ==ui(19)),
   filter_type = get(ui(17),'value');
   if filter_type <3,val=1;else,val=2;end
   len=length(edt_val);
     if len~=val
      set(autoplot,'value',0),
      set(plot_btn,'enable','on');
     end
   end
   if get(autoplot,'value'), maplpplt; end


elseif mode == 5, % autoplot
   if get(autoplot,'value'),
      set(plot_btn,'enable','off');
      maplpplt;
   else
      set(plot_btn,'enable','on');
   end


elseif mode == 7, % cursor
    if get(curs_btn,'value')
    set(curs_dsp,'vis','on');

    set(f,'WindowButtonMotionFcn','maplpgui(8)');

    else

  set(f,'Pointer','arrow','WindowButtonMotionFcn','');


   set(curs_dsp,'vis','off')
   set(curs_btn,'value',0),

    end


elseif mode == 8, % cursor movement
       h=gca;
       set(f,'currentaxes',h);
       lim=get(h,'pos');  % get current axis position
       c_p = [lim(1) lim(1)+lim(3) lim(2) lim(2)+lim(4)];
       f_p=get(f,'CurrentPoint'); % get co-ordinates of current point

     if f_p(1) < c_p(1) | f_p(1) > c_p(2) | f_p(2) < c_p(3) | f_p(2) > c_p(4)
        set(f,'Pointer','arrow');

        set(curs_dsp(2),'string','');
        set(curs_dsp(4),'string','');

     else
        curr_pt=get(h,'CurrentPoint');  % get current mouse position
        set(f,'Pointer','crosshair');
        set(curs_dsp(2),'string',num2str(curr_pt(1,1)));
        set(curs_dsp(4),'string',num2str(curr_pt(1,2)));
     end


elseif mode == 15, %Export data
maplpplt;
str1='Export numerator of original filter as';
str2='Export denominator of original filter as';
str3='Export numerator of transformed filter as';
str4='Export denominator of transformed filter as';
str5='Export magnitude of original filter as';
str6='Export magnitude of transformed filter as';
str7='Export analog frequency in Hz as';
exp_str={str1,str2,str3,str4,str5,str6,str7};
exp_var={'norig','dorig','ntrans','dtrans','Morig','Mtrans','freqvar'};

expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
no=get(ui(27),'userdata');%%% FIX FOR UIs 
do=get(ui(28),'userdata');
nt=get(ui(29),'userdata');
dt=get(ui(30),'userdata');
hh=get(ui(31),'userdata');%%% FIX FOR UIs 

if ~isempty(expect{1}),assignin('base',expect{1},no);end
if ~isempty(expect{2}),assignin('base',expect{2},do);end
if ~isempty(expect{3}),assignin('base',expect{3},nt);end
if ~isempty(expect{4}),assignin('base',expect{4},dt);end
if ~isempty(expect{5}),assignin('base',expect{5},hh(:,1));end
if ~isempty(expect{6}),assignin('base',expect{6},hh(:,2));end
if ~isempty(expect{7}),assignin('base',expect{7},hh(:,3));end
end


elseif mode == 16, % Axis Control Help
msgbox([' First click in a plot window.                             ',... 
'                  Then, come back and execute'],...
'Axis Control Info','help')


elseif mode == 17, % Axis Control
cur_axs=[];   cur_obj = gco;
   cur_par = get(cur_obj,'parent');
if ~isempty(cur_par)
   if cur_par == f,
      cur_axs = cur_obj;
   else
      cur_axs = cur_par;
   end
end

if isempty(cur_axs),maplpgui(16);
else
set(curs_btn,'value',0);
maplpgui(7);
if any(cur_axs==ui([32,34])),
if cur_axs==ui(32),txt='Original filter';
elseif cur_axs==ui(34),txt='Transformed filter';
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log,  [1 0]=auto, no linear/log
else
maplpgui(16);
end
end


elseif mode == 18, % zoom on
set(curs_btn,'value',0);
maplpgui(7);                    % Use CURSOR MODE 
if get(ui(15),'userdata')==0  %%Change ui(15) to whatever
zoom on
set(ui(15),'userdata',1);
else
msgbox('Zoom is already ON.','Zoom Info','help')
end

elseif mode == 19, % zoom off
set(curs_btn,'value',0);
maplpgui(7);                    % Use CURSOR MODE 
if get(ui(15),'userdata')==1

%%%%%Insert old zoom off here
set(f,'currentaxes',ui(32));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(34));
zoom out,zoom reset,zoom off
set(ui(15),'userdata',0);
else
msgbox('Zoom is already OFF.','Zoom Info','help')
end



elseif mode == 20, % mouse functionality
cur_axs = [];   cur_obj = gco;
   cur_par = get(cur_obj,'parent');

if ~isempty(cur_par)
   if cur_par == f,
      cur_axs = cur_obj;
   else
      cur_axs = cur_par;
   end
end


if isempty(cur_axs),maplpgui(16);return,end


   if any(cur_axs == [sig_axs,opr_axs]),
      axes(cur_axs);
         tit_str = get(get(cur_axs,'title'),'string');
         axs_pos = get(cur_axs,'pos');
         if axs_pos(4) == 155, % need to maximize
               set([sig_axs,opr_axs],'vis','off');
            set(cur_axs,'pos',[210,50,390,365],'vis','on');

         else % minimization
              set(sig_axs,'pos',[210,260,390,155],'vis','on');
              set(opr_axs,'pos',[210,50,390,155],'vis','on');

         end
   else
         maplpgui(16);
   end


end

⌨️ 快捷键说明

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