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

📄 chirpgui.m

📁 ADSP TOOLBOX: Version 2.0 and gui m-files
💻 M
字号:
function chirpgui(mode)
%CHIRPGUI  Graphical User Interface program for chirp signals


% 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



if nargin == 0, mode = 0; end

if mode ~= 0,
   f = gcf;
   ui = get(f,'userdata');
  
   sig_axs=ui(22);
   opr_axs=ui(24);
   tf_axs=ui(26);
   curs_btn=ui(30);
   curs_dsp=ui(31:34);
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','Chirp Signals and their Spectra','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','Chirp Signals and their Spectra','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','chirphlp');
   uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
                          'callback','chirpgui(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','chirpgui(17)');
   uim(7) = uimenu('label','   Zoom ON','separator','on',...
                          'callback','chirpgui(18)');
   uim(8) = uimenu('label','   Zoom OFF','separator','on',...
                          'callback','chirpgui(19)');
   uim(9) = uimenu('label','   RESIZE','callback','chirpgui(20)');


%%%%%%%%%



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

   btm = btm - 46;
   ui(2) = uicontrol('style','text','pos',[lft,btm,160,17],...
           'horiz','left','fore','c','string','Chirp Signal');

   btm = btm - 22;
   ui(3) = uicontrol('style','text','pos',[lft,btm,70,17],...
           'string','From F0 =','horiz','right');
   ui(4) = uicontrol('style','edit','pos',[lft+75,btm,90,18],...
           'back','w','string','0.2','callback','chirpgui(2)');

   btm = btm - 22;
   ui(6) = uicontrol('style','text','pos',[lft,btm,70,17],...
           'string','To F1 =','horiz','right');
   ui(7) = uicontrol('style','edit','pos',[lft+75,btm,90,18],...
           'back','w','string','0.4','callback','chirpgui(2)');

   btm = btm - 22;
   ui(9) = uicontrol('style','text','pos',[lft,btm,70,17],...
           'string','Samples','horiz','right');
   ui(10) = uicontrol('style','edit','pos',[lft+75,btm,90,18],...
           'back','w','string','500','callback','chirpgui(2)');

   ui(5) = uicontrol('style','frame','pos',[5,btm-45,175,30],...
           'back',grey,'fore',ltgrey);

   btm = btm - 40;
   ui(12) = uicontrol('style','text','pos',[lft,btm,50,17],...
           'string','Method','horiz','right');

   ui(13) = uicontrol('style','popup','pos',[lft+52,btm,113,20],...
           'string','Periodogram|Welch|Blackman/Tukey','back','w',...
           'callback','chirpplt');

   btm = btm - 35;
   ui(16) = uicontrol('style','text','pos',[lft,btm,100,17],...
           'string','Section Length','horiz','right','vis','off');
   ui(17) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
           'back','w','string','50','callback','chirpgui(2)','vis','off');

   btm = btm - 22;
   ui(19) = uicontrol('style','text','pos',[lft,btm,100,17],...
           'string','% Overlap','horiz','right','vis','off');
   ui(20) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
           'back','w','string','50','callback','chirpgui(2)','vis','off');

   btm = btm - 30;
   ui(14) = uicontrol('style','text','pos',[lft,btm,60,17],...
           'string','Window','horiz','right','vis','off');

   ui(15) = uicontrol('style','popup','pos',[lft+65,btm,100,20],...
           'back','w','string','von Hann|Hamming|Bartlett|Blackman',...
           'callback','chirpplt','vis','off','userdata',0);

   btm = btm -35;
   ui(30) = uicontrol('style','check','pos',[lft+95,btm,70,20],...
           'string','Cursor','back','y','callback','chirpgui(6)');


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

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



   ui(22) = axes('units','pixel','pos',[210,250,390,160],'box','on',...
            'ylim',[-1.2,1.2],'color','k',...
            'xcolor','w','ycolor','w');
   title('Chirp Signal with Digital Frequency from F0 to F1');
   xlabel('DT Index  [n]');
   ui(23) = line('xdata',0,'ydata',0,'color','c');
   set(ui(22),'userdata',ui(23));


   ui(24) = axes('units','pixel','pos',[210,40,175,160],'box','on',...
            'xlim',[0,0.5],'color','k',...
            'xcolor','w','ycolor','w','xgrid','on','ygrid','on');
   title('Its PSD Estimate');
   xlabel('Digital Frequency  [F]');
   ui(25) = line('xdata',0,'ydata',0,'color','y');
   set(ui(24),'userdata',ui(25));

   ui(26) = axes('units','pixel','pos',[425,40,175,160],'box','on',...
            'xlim',[0,0.5],'color','k',...
            'xcolor','w','ycolor','w');
   ui(27) = line('xdata',0,'ydata',0,'color','m');
   set(ui(26),'userdata',ui(27));



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


elseif mode == 2,  % update edits
   h = gco;
    if strcmp(get(h,'style'),'edit'),
      edt = h;
      val = str2num(get(edt,'string'));
       if ~length(val),
         errordlg('You must enter a VALID number.','Input Error');
         return;
      end
    end
   chirpplt;



elseif mode == 6, % cursor
    if get(curs_btn,'value')
    set(curs_dsp,'vis','on');
    set(f,'WindowButtonMotionFcn','chirpgui(7)');
    else
    set(f,'Pointer','arrow','WindowButtonMotionFcn','');
    set(curs_dsp,'vis','off')
    set(curs_btn,'value',0),
    end


elseif mode == 7, % 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


%%%%%%PASTE AT END before last end statement %%%%%%%%%%%%%
elseif mode == 15, % Export data
chirpplt;
str1='Export Chirp signal as';
str2='Export Chirp signal index as';
str3='Export PSD estimate as';
str4='Export PSD frequency as';
str5='Export waterfall magnitudes as';
str6='Export waterfall time index as';
exp_str={str1,str2,str3,str4,str5,str6};
exp_var={'chirpsig','chirpind','psdest','psdind','tfmag','tfind'};
expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
csig=get(ui(1),'userdata');%%% FIX FOR UIs 
psd=get(ui(2),'userdata');%%% FIX FOR UIs 
tfi=get(ui(3),'userdata');%%% FIX FOR UIs 
tfm=get(ui(4),'userdata');%%% FIX FOR UIs 

if ~isempty(expect{1}),assignin('base',expect{1},csig(:,2));end
if ~isempty(expect{2}),assignin('base',expect{2},csig(:,1));end
if ~isempty(expect{3}),assignin('base',expect{3},psd(:,2));end
if ~isempty(expect{4}),assignin('base',expect{4},psd(:,1));end
if ~isempty(expect{5}),assignin('base',expect{5},tfm);end
if ~isempty(expect{6}),assignin('base',expect{6},tfi);end
end

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

elseif mode == 17, % Axis Control Execute only when plot is clicked.
 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),chirpgui(16);
else
set(curs_btn,'value',0),  %Prevent callback error when cursor is on
chirpgui(6);
if any(cur_axs==ui([22:2:26])),  %Top or bottom axes
if cur_axs==ui(22),txt='Chirp Signal';
elseif cur_axs==ui(24),txt='PSD of Chirp';
elseif cur_axs==ui(26),txt='Time-Freq Plot';
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log,  [1 0]=auto, no linear/log
else
chirpgui(16);
end
end


elseif mode == 18, % zoom on
set(curs_btn,'value',0);
chirpgui(6);                    % 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);
chirpgui(6);                    % Use CURSOR MODE 
if get(ui(15),'userdata')==1

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


elseif mode == 20, % resize
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),chirpgui(16);return,end


   if any(cur_axs == [sig_axs,opr_axs,tf_axs]),
      axes(cur_axs);
         axs_pos = get(cur_axs,'pos');
         if axs_pos(4) == 160, % need to maximize
               set([sig_axs,opr_axs,tf_axs],'vis','off');
            set(cur_axs,'pos',[210,40,390,370],'vis','on');

         else % minimization
              set(sig_axs,'pos',[210,250,390,160],'vis','on');
              set(opr_axs,'pos',[210,40,175,160],'vis','on');
              set(tf_axs,'pos',[425,40,175,160],'vis','on');
         end
   else
        chirpgui(16);
   end


end

⌨️ 快捷键说明

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