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

📄 ftprpgui.m

📁 ADSP TOOLBOX: Version 2.0 and gui m-files
💻 M
字号:
function ftprpgui(mode)
%FTPRPGUI Graphical User Interface program for Fourier transform properties.


% 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


%%%%%%%%% VERSION CHECK AT START %%%%%%%%%%%%%%%%%%%
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');
   sig_edt = ui(3);
   prop_edt = ui(6);
   disp_edt = ui(9);
   autoplot = ui(11);
   plt_btn  = ui(12);
   axs1      = ui(20);
   axs2      = ui(23);
   lin1      = ui(21);
   lin2      = ui(24);
   curs_btn = ui(13);
   curs_dsp = ui(14:17);
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 = 440;
   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','Fourier Transform Properties','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','Fourier Transform Properties','numbertitle','off',...
           'resize','off','vis','off','interruptible',int_str,...
           'color',dkgrey,'defaultaxesfontsize',8,...
           'defaultuicontrolback',[0.5,0.5,0.5],...
           'defaulttextfontsize',8);
   end

%%% OPTIONS: Change NAME to gui name e.g. bode %%%%%%%%%%%%%%%
   uim(1) = uimenu('label','OPTIONS');
   uim(2) = uimenu(uim(1),'label','Help and Info','callback','ftprphlp');
%   uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
%                          'callback','ftprpgui(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 CONTROL','separator','on',...
%                          'callback','');
%   uim(7) = uimenu(uim(6),'label','   Explain','callback','ftprpgui(16)');
%   uim(8) = uimenu(uim(6),'label','   Execute','separator','on',...
%                          'callback','ftprpgui(17)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



   lft = 10; btm = fig_h - 5;
   btm1 = 35; btm2 = 10;
   ui(1) = uicontrol('style','frame','pos',[5,btm-127+44+22,175,119-44-22],...
           'back',grey,'fore',ltgrey);

   btm = btm - 33;

   ui(2) = uicontrol('style','text','pos',[lft,btm,165,17],...
           'string','Signal','back',ltgrey,'fore','c','horiz','left');

   btm = btm - 22;

   ui(3) = uicontrol('style','popup','pos',[lft,btm,164,17],...
           'string','rect(t)|tri(t)|exp(-t)|t*exp(-t)|sinc(t)|sinc^2(t)',...
           'back','w','callback','ftprpgui(1)');


   ui(4) = uicontrol('style','frame','pos',[5,btm-40-25,175,27+25],...
           'back',grey,'fore',ltgrey);

   btm = btm - 35;

    ui(5) = uicontrol('style','text','pos',[lft,btm,165,17],...
           'string','Property','horiz','left','fore','c');

   btm = btm - 25;

   ui(6) = uicontrol('style','popup','pos',[lft,btm,164,20],...
           'string','Time Scaling|Delay|Modulation',...
           'back','w','callback','ftprpgui(1)');


   ui(7) = uicontrol('style','frame','pos',[5,btm-40-25,175,27+25],...
           'back',grey,'fore',ltgrey);

   btm = btm - 35;

   ui(8) = uicontrol('style','text','pos',[lft,btm,165,17],...
           'string','Spectrum Display','horiz','left','fore','c');

   btm = btm - 25;

   ui(9) = uicontrol('style','popup','pos',[lft,btm,164,20],...
           'string','Magnitude|Phase',...
           'back','w','callback','ftprpgui(1)');



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

  btm = btm - 35;

   ui(11) = uicontrol('style','check','pos',[lft,btm,80,17],...
           'string','AutoPlot','value',0,'fore','c','callback','ftprpgui(3)');

   ui(12) = uicontrol('style','push','pos',[lft+95,btm-2,70,20],...
           'string','Plot','callback','ftprpplt');

   btm = btm -32;



   ui(13) = uicontrol('style','check','pos',[lft+95,btm,70,20],...
           'string','Cursor','back','y','callback','ftprpgui(4)');





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

%%%%%%   This also works
%   lef = fig_w-166;
%   bot = fig_h-21;

   ui(14) = uicontrol('style','text','pos',[lef,bot,20,20],...
           'string','X ','horiz','right');
   ui(15) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
           'string','','back','w');
   ui(16) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
           'string','Y ','horiz','right');
   ui(17) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
           'string','','back','w');


   set(ui(14:17),'vis','off');


   ui(20) = axes('units','pixel','pos',[210,255,390,160],'box','on',...
            'xlim',[-2,2],'ylim',[0,2],'color','k',...
            'xgrid','on','ygrid','on');

   t_axs=-2:0.01:2;
   sig = urect(t_axs);

   title('Signal');
   xlabel('Variable  t')
   ui(21) = line('xdata',t_axs,'ydata',sig,'color','y');
   ui(22) = line('xdata',[],'ydata',[],'color','r');
   set(ui(1),'userdata',ui(20));


   f_axs=-3:0.01:3;
   spec = sinc(f_axs);

   ui(23) = axes('units','pixel','pos',[210,40,390,160],'box','on',...
            'xlim',[-3,3],'ylim',[-1,3.5],'color','k',...
            'xgrid','on','ygrid','on');
   title('Spectrum');
   xlabel('Variable  f')

   ui(24) = line('xdata',f_axs,'ydata',spec,'color','c');
   ui(25) = line('xdata',[],'ydata',[],'color','m');
   set(ui(2),'userdata',ui(23));


   set(f,'userdata',ui);
%   set(ui(1),'userdata',ui(10));
%   ftprpplt;
   drawnow;

   set(f,'vis','on');

elseif mode == 1, % set values for signal
   val = get(sig_edt,'value');
   disp = get(disp_edt,'value');
   ylim1=[0, 1.5];
   if val == 1 %rect
   t=-5:0.01:5;xlim1 = [-2,2];
   sig = urect(t);flim1 = [-3,3];
   f_axs=-3:0.01:3;
   if disp == 1
      spec = sinc(f_axs);ylim=[-1 3.5];
   else
      spec = 0*f_axs;ylim=[-5 5];
   end

   elseif val == 2 %tri
   t=-4:0.01:4;xlim1 = [-4,4];
   sig = tri(t);
   f_axs=-3:0.01:3; flim1 = [-3,3];
   tf = sinc(f_axs);
   if disp == 1
      spec = tf.*tf;ylim=[0,3.5];
   else
      spec = 0*f_axs;ylim=[-5 5];
   end

   elseif val == 3
   t=-1:0.01:3;xlim1 = [-1,3];
   sig = exp(-t).*(t>=0);
   f_axs=-5:0.01:5;
   j=sqrt(-1);
   trans = '(1)./(1+j*2*pi*f_axs)';
   if disp == 1
      f_axs=-5:0.01:5;flim1=[-5,5];
      spec = abs(eval(trans));ylim=[0 3];
   else         
      f_axs=-2:0.01:2;flim1 = [-2,2];
      spec = angle(eval(trans));ylim=[-8 8];
   end

   elseif val == 4
   ylim1 = [0, 0.5];
   t=-1:0.01:3;xlim1 = [-1,3];
   sig = t.*exp(-t).*(t>=0);
   f_axs=-5:0.01:5;
   j=sqrt(-1);
   trans = '(1)./(1+j*2*pi*f_axs)';
   if disp == 1
      f_axs=-5:0.01:5;flim1=[-5,5];
      tf = eval(trans);
      spec = abs(tf.*tf);ylim=[0 3];
   else         
      f_axs=-2:0.01:2;flim1 = [-2,2];
      tf = eval(trans);
      spec = angle(tf.*tf);ylim=[-8 8];
   end

   elseif val == 5 %sinc
   t=-8:0.02:8;xlim1 = [-8,8];ylim1=[-0.5,1.5];
   sig = sinc(t);
   f_axs=-2:0.01:2; flim1 = [-2,2];
   tf = urect(f_axs);
   if disp == 1
      spec = tf;ylim=[0,3];
   else
      spec = 0*f_axs;ylim=[-5 5];
   end

   elseif val == 6 %sinc^2
   t=-8:0.02:8;xlim1 = [-8,8];ylim1=[0,1.2];
   sig = sinc(t);sig=sig.*sig;
   f_axs=-2:0.01:2; flim1 = [-2,2];
   tf = tri(f_axs);
   if disp == 1
      spec = tf;ylim=[0,3];
   else
      spec = 0*f_axs;ylim=[-5 5];
   end

   end
   
   set(axs1,'xlim',xlim1,'ylim',ylim1);
   set(lin1,'xdata',t,'ydata',sig);

   set(axs2,'xlim',flim1,'ylim',ylim);
   set(lin2,'xdata',f_axs,'ydata',spec);
   


   if get(autoplot,'value'),ftprpplt,end

%elseif mode == 2, % edit values for math functions

%    if get(help_edt,'value')  %Help button
%       stt=['FT Properties'];
%       st1=['Test Test1'];
%       st2 =['Test Test Test2'];
%       helpfun(stt,st1,st2);
%    end

%    if get(autoplot,'value'),ftprpplt,end


elseif mode == 3, % autoplot 

    if get(autoplot,'value'),
       set(plt_btn,'enable','off');
       ftprpplt
    else
       set(plt_btn,'enable','on');
    end

elseif mode == 4, % cursor

%    if get(ui(18),'value')
%    set(ui(14:17),'vis','on');
    if get(curs_btn,'value')
    set(curs_dsp,'vis','on');


    set(f,'WindowButtonMotionFcn','ftprpgui(5)',...
        'WindowButtonDownFcn','ftprpgui(5)');
    else

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

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

    end

elseif mode == 5, % cursor movement

       h=gca;
       set(f,'currentaxes',h);
       lim=get(h,'pos');  % get current axis position

%       lim=get(axs,'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(ui(15),'string','');
%        set(ui(17),'string','');
        set(curs_dsp(2),'string','');
        set(curs_dsp(4),'string','');

     else
        curr_pt=get(h,'CurrentPoint');  % get current mouse position
%        curr_pt=get(axs,'CurrentPoint');  % get current mouse position
        set(f,'Pointer','crosshair');

%        set(ui(15),'string',num2str(curr_pt(1,1)));
%        set(ui(17),'string',num2str(curr_pt(1,2)));
        set(curs_dsp(2),'string',num2str(curr_pt(1,1)));
        set(curs_dsp(4),'string',num2str(curr_pt(1,2)));
     end



end


⌨️ 快捷键说明

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