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

📄 fssyngui.m

📁 trabajos en matlab para verificar son muy buenos
💻 M
字号:
function fssyngui(mode)
%FSSYNGUI Graphical User Interface program for Fourier series synthesis.


% 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');
   sym_pop     = ui(8);
   n_edt       = ui(11);
   exp_uis     = ui(16:17);
   autoplot    = ui(27);
   plot_btn    = ui(28);
   axs         = ui(37);
   curs_btn = ui(32);
   curs_dsp = ui(33:36);
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=0;   %ver4    = length(findstr('4.',ver_str));

   if ver4,
      int_str = 'yes';
      f = figure('pos',[flft,fbtm,fig_w,fig_h],'menubar','none',...
            'name','Fourier Series Synthesis','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 Series Synthesis','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','fssynhlp');
   uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
                          'callback','fssyngui(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','fssyngui(17)');
   uim(7) = uimenu('label','   Zoom ON','separator','on',...
                          'callback','fssyngui(18)');
   uim(8) = uimenu('label','   Zoom OFF','separator','on',...
                          'callback','fssyngui(19)');

%%%%%%%%%%



   lft = 10; btm = fig_h - 5;
   ui(12) = uicontrol('style','frame','pos',[5,btm-130+47-22,175,120-45+22],...
           'back',grey,'fore',ltgrey);


   btm = btm - 35+2;
   ui(14) = uicontrol('style','text','pos',[lft,btm,165,17],...
           'horiz','left','fore','c','string','Exp FS Coefficients X[k]');

   btm = btm - 22;
   ui(5) = uicontrol('style','text','pos',[lft,btm,95,17],...
           'horiz','right','string','dc value k=0','userdata',0);
   ui(6) = uicontrol('style','edit','pos',[lft+95,btm,70,18],...
           'back','w','string','0');

   btm = btm - 22;
   ui(7) = uicontrol('style','text','pos',[lft,btm,95,17],...
           'horiz','right','string','harmonics k>0');

   ui(8) = uicontrol('style','popup','pos',[lft+95,btm-1,70,19],...
           'string',['All k|k Odd|k Even'],'back','w');

   btm = btm - 22;
   ui(16) = uicontrol('style','text','pos',[lft,btm,55,17],...
           'horiz','right','string','X[k] k>0');
   ui(17) = uicontrol('style','edit','pos',[lft+60,btm,105,18],...
           'back','w','string','(j)./(k*pi)');

   btm = btm - 22;
   ui(41) = uicontrol('style','frame','pos',[5,btm-130+44+25,175,120-47],...
           'back',grey,'fore',ltgrey);


   btm = btm - 12;
   ui(42) = uicontrol('style','check','pos',[lft,btm,160,17],...
           'string','Special Values','callback','fssyngui(4)',...
           'value',0,'fore','c');

   btm = btm - 24+2;
   ui(45) = uicontrol('style','text','pos',[lft,btm,40,17],...
           'horiz','right','string','k (>0)');
   ui(46) = uicontrol('style','edit','pos',[lft+45,btm,120,18],...
           'back','w','string','');
 
   btm = btm - 22;
   ui(47) = uicontrol('style','text','pos',[lft,btm,40,17],...
           'horiz','right','string','X[k]');
   ui(48) = uicontrol('style','edit','pos',[lft+45,btm,120,18],...
           'back','w','string','');
   set(ui(45:48),'vis','off');


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

   btm = btm - 35+5;
   ui(18) = uicontrol('style','push','pos',[lft,btm,80,17],...
           'string','Accept','callback','fssynplt');

   ui(19) = uicontrol('style','push','pos',[lft+85,btm,80,17],...
           'string','Reset','callback','fssyngui(1)');


   ui(1) = uicontrol('style','frame','pos',[5,btm-142+78+10,175,140-88-5],...
           'back',grey,'fore',ltgrey);

   btm = btm - 35+10-3;
   uicontrol('style','text','pos',[lft,btm,100,17],...
           'horiz','right','string','Time Period T');
   ui(2) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
           'back','w','string','1','callback','fssyngui(3)');


   btm = btm - 22;
   ui(3) = uicontrol('style','text','pos',[lft,btm,100,17],...
           'horiz','right','string','Plot Range');
   ui(4) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
           'back','w','string','-1 1','callback','fssyngui(3)');

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

   btm = btm - 35;
   ui(10) = uicontrol('style','text','pos',[lft,btm,100,17],...
           'horiz','right','string','# of Harmonics');
   ui(11) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
           'back','w','string','25','callback','fssyngui(5)');

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

   btm = btm - 35;
   uicontrol('style','text','pos',[lft,btm-3,60,20],...
           'string','Counter');
   ui(43) = uicontrol('style','push','pos',[lft+65,btm-2,50,20],...
           'string','<<','callback','fssyngui(8)');
   ui(44) = uicontrol('style','push','pos',[lft+115,btm-2,50,20],...
           'string','>>','callback','fssyngui(9)');

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

   btm = btm - 35;
   ui(27) = uicontrol('style','check','pos',[lft,btm,80,17],...
           'string','AutoPlot','callback','fssyngui(5)',...
           'value',0);
   ui(28) = uicontrol('style','push','pos',[lft+95,btm-2,70,20],...
           'string','Plot','callback','fssynplt');

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

   btm = btm - 15;
   ui(30) = uicontrol('style','text','pos',[lft,btm,38,17],...
           'string','Show');
   ui(31) = uicontrol('style','popup','pos',[lft+40,btm,127,17],...
           'string',['Reconstruction|',...
           'Magnitude Spectrum|Phase Spectrum'],...
           'back','w','callback','fssynplt'); %was fssyngui(6)

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


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

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



   ui(37) = axes('units','pixel','pos',[210,50,390,350],'box','on',...
            'xlim',[0,1],'color','k','xgrid','on','ygrid','on');
   title('Magnitude  Spectrum');
   xlabel('Digital Frequency [F]');

   ui(38) = line('xdata',0,'ydata',0,'color','y');
   ui(40) = line('xdata',0,'ydata',0,'color','m');
   if ver4,
      ui(39) = line('xdata',0,'ydata',0,'color','g','linestyle','o');
   else
      ui(39) = line('xdata',0,'ydata',0,'color','g','linestyle','none',...
                    'marker','o');
   end




   set(f,'userdata',ui);
   set(ui(7),'userdata',ui(37));
   fssynplt;
   drawnow;
   set(f,'vis','on');

elseif mode == 1, % signal popup
   set(ui(17),'string','(j)./(k*pi)');
   set([sym_pop],'value',1);
   set([ui(42),autoplot],'value',0);
   set(ui([46,48]),'string','');
   set(ui(2),'string','1');
   set(ui(4),'string','-1 1');
   set(ui(6),'string','0');
   set(n_edt,'string','25');
   set(plot_btn,'enable','on');
   set(exp_uis,'vis','on');
   set(ui(45:48),'vis','off');
   fssynplt;

elseif mode == 2, % window popup
      set(exp_uis,'vis','on');

   if get(ui(42),'value') == 0
   set(ui(45:48),'vis','off');
   else
      set(ui(45:48),'vis','on');
   end


elseif mode == 3, % edit fields
   edt = gco;
    fssyngui(5);

elseif mode == 4, % Special values
   if get(ui(42),'value') == 0
   set(ui(45:48),'vis','off');
   else
   set(ui(45:48),'vis','on');
   end

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


elseif mode == 8,
   k_str=get(ui(11),'string');
   if isempty(k_str),
      k_val=0;
   else
      k_val= eval(['[',k_str,']'],[]);
        if isempty(k_val),
        errordlg('Matlab syntax error.','Input Error');
        return
        end
        if rem(k_val,1)|k_val<0,
        errordlg('# of harmonics must be an integer.','Input Error');
        return
        end
   end
   k_val=k_val-1;if k_val<0,k_val=0;end
   k_str=int2str(k_val);
   set(ui(11),'string',k_str);
   fssynplt;

elseif mode == 9, % edit fields
   k_str=get(ui(11),'string');
   if isempty(k_str),
      k_val=0;
   else
      k_val= eval(['[',k_str,']'],[]);
        if isempty(k_val),
        errordlg('Matlab syntax error.','Input Error');
        return
        end
        if rem(k_val,1)|k_val<0,
        errordlg('# of harmonics must be an integer.','Input Error');
        return
        end
   end
   k_str=int2str(k_val+1);
   set(ui(11),'string',k_str);
   fssynplt;

elseif mode == 6, % cursor
  if get(curs_btn,'value')
    set(curs_dsp,'vis','on');
    set(f,'WindowButtonMotionFcn','fssyngui(7)',...
        'WindowButtonDownFcn','fssyngui(7)');
  else
   set(f,'Pointer','arrow','WindowButtonMotionFcn','','WindowButtonDownFcn','')
   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


elseif mode == 15, %Export data
fssynplt;
str1='Export signal reconstruction as';
str2='Export time index for signal as';
str3='Export harmonic magnitude as';
str4='Export harmonic phase as';
str5='Export harmonic index as';
str6='Export symbolic form for X[k],k>0 (no special values) as';
exp_str={str1,str2,str3,str4,str5,str6};
exp_var={'sigfs','timefs','Mfs','Pfs','Nfs','XK'};

expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
xd=get(ui(32),'userdata');%%% FIX FOR UIs 
hd=get(ui(33),'userdata');%%% FIX FOR UIs 
xc=get(ui(34),'userdata');
if ~isempty(expect{1}),assignin('base',expect{1},xd(:,1));end
if ~isempty(expect{2}),assignin('base',expect{2},xd(:,2));end
if ~isempty(expect{3}),assignin('base',expect{3},hd(:,1));end
if ~isempty(expect{4}),assignin('base',expect{4},hd(:,2));end
if ~isempty(expect{5}),assignin('base',expect{5},hd(:,3));end
if ~isempty(expect{6}),assignin('base',expect{6},xc);end
end


elseif mode == 16, % Axis Control Help
msgbox(['Turn Cursor off. Click in a plot window.                  ',... 
'                  Then, come back and click on 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),fssyngui(16);
else
set(curs_btn,'value',0);
fssyngui(6); %%% REPLACE number BY CURSOR MODE 
if any(cur_axs==ui([37])),%%%% CHANGE UI numbers
val=get(ui(31),'value');
if val==1,txt='Reconstruction';%%%% CHANGE UI numbers
elseif val==2,txt='Harmonic magnitude';%%%% CHANGE UI numbers
elseif val==3,txt='Harmonic phase';%%%% CHANGE UI numbers
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log,  [1 0]=auto, no linear/log
else
fssyngui(16);
end
end


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

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

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



end

⌨️ 快捷键说明

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