📄 lpsiggui.m
字号:
function lpsiggui(mode)
%LPSIGGUI Graphical User Interface program for DT linear-phase 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
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');
xn_edt = ui(3);
mag_axs=ui(26);
phs_axs=ui(10);
pz_axs=ui(23);
sig_axs=ui(7);
clear_btn = ui(9);
curs_btn = ui(21);
curs_dsp = ui(17:20);
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;
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','Linear Phase Sequences','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','Linear Phase Sequences','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','lpsighlp');
uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
'callback','lpsiggui(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','lpsiggui(17)');
uim(7) = uimenu('label',' Zoom ON','separator','on',...
'callback','lpsiggui(18)');
uim(8) = uimenu('label',' Zoom OFF','separator','on',...
'callback','lpsiggui(19)');
uim(9) = uimenu('label',' RESIZE','callback','lpsiggui(20)');
%%%%%%%
lft = 10; btm = fig_h - 5;
ui(1) = uicontrol('style','frame','pos',[5,btm-142-24+90,175,60],...
'back',grey,'fore',ltgrey);
btm = btm - 42;
ui(2) = uicontrol('style','text','pos',[lft,btm,30,17],...
'string','x[n]','horiz','left');
ui(3) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
'back','w','string','1 2 3 2 1');%,'callback','lpsiggui(1)');
btm=btm - 27;
ui(4) = uicontrol('style','push','pos',[lft+20,btm,60,20],...
'string','Accept','callback','lpsigplt');%,'vis','off');
ui(9) = uicontrol('style','push','pos',[lft+85,btm,60,20],...
'string','Reset','callback','lpsiggui(1)');%,'vis','off');
uit = uicontrol('style','frame','pos',[5,btm-200+125,175,55],...
'back',grey,'fore',ltgrey);
btm = btm - 47;
ui(13) = uicontrol('style','text','pos',[lft,btm,80,17],...
'string','Freq Axis','fore','c','horiz','right');
ui(14) = uicontrol('style','popup','pos',[lft+85,btm,80,20],...
'string','F|Omega','back','w',...
'callback','lpsigplt');
btm = btm - 22;
ui(15) = uicontrol('style','text','pos',[lft,btm,80,17],...
'string','Freq Limits','fore','c','horiz','right','userdata',0);
ui(16) = uicontrol('style','edit','pos',[lft+85,btm,80,20],...
'string','0,0.5','back','w',...
'callback','lpsigplt');
ui(30) = uicontrol('style','frame','pos',[5,btm-160,175,140],...
'back',grey,'fore',ltgrey);
btm = btm -40;
ui(31) = uicontrol('style','text','pos',[lft,btm,165,17],...
'string','MULTIPLE ZEROS','fore','c','horiz','left');
btm = btm - 22;
ui(32) = uicontrol('style','text','pos',[lft,btm,165,20],...
'back','w','horiz','left');
btm = btm - 22;
ui(33) = uicontrol('style','text','pos',[lft,btm,165,20],...
'back','w','horiz','left');
btm = btm - 22;
ui(34) = uicontrol('style','text','pos',[lft,btm,165,20],...
'back','w','horiz','left');
btm = btm - 22;
ui(35) = uicontrol('style','text','pos',[lft,btm,165,20],...
'back','w','horiz','left');
btm = btm - 25;
ui(36) = uicontrol('style','text','pos',[lft,btm,165,20],...
'back','w','horiz','left');
btm = btm -120;
ui(21) = uicontrol('style','check','pos',[lft+100,btm,70,20],...
'string','Cursor','back','y','callback','lpsiggui(7)');
pos = get(f,'pos');
lef = pos(3)-166;
bot = pos(4)-21;
ui(17) = uicontrol('style','text','pos',[lef,bot,20,20],...
'string','X ','horiz','right');
ui(18) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
'string','','back','w');
ui(19) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
'string','Y ','horiz','right');
ui(20) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
'string','','back','w');
set(ui(17:20),'vis','off');
ui(7) = axes('units','pixel','pos',[220,35,160,160],'box','on',...
'color','k','xgrid','on','ygrid','on');
title('Linear Phase Signal x[n]');
xlabel('DT Index [n]');
ui(8) = line('xdata',0,'ydata',0,'color','m','erase','back');
if ver4,
ui(12) = line('xdata',0,'ydata',0,'color','c','linestyle','o',...
'erase','back');
else
ui(12) = line('xdata',0,'ydata',0,'color','m','linestyle','none',...
'marker','o','erase','back');
end
set(ui(7),'userdata',ui([8,12]));
ui(10) = axes('units','pixel','pos',[430,35,160,160],'box','on',...
'xlim',[-0.5,0.5],'color','k',...
'xgrid','on','ygrid','on');
title('Phase Spectrum [deg]');
xlabel('Digital Frequency [F]');
ui(11) = line('xdata',0,'ydata',0,'color','y','erase','back');
set(ui(10),'userdata',ui(11));
set(ui(3),'userdata',ui(10));
ui(23) = axes('units','pixel','pos',[220,240+5,160,160],'box','on',...
'color','k','xgrid','on','ygrid','on');
title('Zero Locations');
ui(25) = line('xdata',0,'ydata',0,'color','y','erase','back');
if ver4,
ui(24) = line('xdata',0,'ydata',0,'color','c','linestyle','o',...
'erase','back');
else
ui(24) = line('xdata',0,'ydata',0,'color','c','linestyle','none',...
'marker','o','erase','back','markersize',8);
end
% axis('equal');
set(ui(23),'userdata',ui(24:25));
ui(26) = axes('units','pixel','pos',[430,240+5,160,160],'box','on',...
'xlim',[-0.5,0.5],'color','k',...
'xgrid','on','ygrid','on');
title('Amplitude Spectrum');
xlabel('Digital Frequency [F]');
ui(27) = line('xdata',0,'ydata',0,'color','y','erase','back');
set(ui(26),'userdata',ui(27));
set(f,'userdata',ui);
set(ui(1),'userdata',ui(10));
lpsigplt;
drawnow;
set(f,'vis','on');
elseif mode == 1, % reset
set(xn_edt,'string','1 2 3 2 1');
lpsigplt;
elseif mode == 7, % cursor
if get(curs_btn,'value')
set(curs_dsp,'vis','on');
set(f,'WindowButtonMotionFcn','lpsiggui(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
lpsigplt;
fstr=get(ui(14),'string');fval=get(ui(14),'value');fstr=fstr(fval,:); %Hz
str1='Export signal x[n] as';
str2='Export zeros of x[n] as';
str3='Export amplitude spectrum as';
str4='Export phase (deg) as';
str5=['Export digital freqency ' fstr ' as'];
exp_str={str1,str2,str3,str4,str5};
exp_var={'lpsig','zlpsig','amplp','phaselp','flp'};
expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
na=get(ui(17),'userdata');%%% FIX FOR UIs
da=get(ui(18),'userdata');%%% FIX FOR UIs
fm=get(ui(19),'userdata');
fp=get(ui(20),'userdata');
if ~isempty(expect{1}),assignin('base',expect{1},na);end
if ~isempty(expect{2}),assignin('base',expect{2},da);end
if ~isempty(expect{3}),assignin('base',expect{3},fm(:,2));end
if ~isempty(expect{4}),assignin('base',expect{4},fp);end
if ~isempty(expect{5}),assignin('base',expect{5},fm(:,1));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),lpsiggui(16);
else
set(curs_btn,'value',0);
lpsiggui(7); %%% REPLACE number BY CURSOR MODE
if any(cur_axs==ui([7,10,23,26])),%%%% CHANGE UI numbers
if cur_axs==ui(7),txt='Linear-phase signal';%%%% CHANGE UI numbers
elseif cur_axs==ui(23),txt='Pole-zero plot';%%%% CHANGE UI numbers
elseif cur_axs==ui(26),txt='Amplitude';%%%% CHANGE UI numbers
elseif cur_axs==ui(10),txt='Phase';%%%% CHANGE UI numbers
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log, [1 0]=auto, no linear/log
else
lpsiggui(16);
end
end
elseif mode == 18, % zoom on
set(curs_btn,'value',0);
lpsiggui(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);
lpsiggui(7); % Use CURSOR MODE
if get(ui(15),'userdata')==1
%%%%%Insert old zoom off here
set(f,'currentaxes',ui(7));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(10));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(23));
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, % 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),lpsiggui(16);return,end
if any(cur_axs == [mag_axs,phs_axs,pz_axs,sig_axs]),
axes(cur_axs);
axs_pos = get(cur_axs,'pos');
if axs_pos(4) == 160, % need to maximize
set(mag_axs,'pos',[-600 35 160 160]);
set(phs_axs,'pos',[-600 35 160 160]);
set(pz_axs,'pos',[-600 240+5 160 160]);
set(sig_axs,'pos',[-600 240+5 160 160]);
if cur_axs==pz_axs
set(cur_axs,'pos',[210,35,375,375]);
else
set(cur_axs,'pos',[210,35,400,365]);
end
else % minimization
set(mag_axs,'pos',[430 240+5 160 160]);
set(phs_axs,'pos',[430 35 160 160]);
set(pz_axs,'pos',[220 240+5 160 160]);
set(sig_axs,'pos',[220 35 160 160]);
end
else
lpsiggui(16);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -