📄 dtsimgui.m
字号:
function dtsimgui(mode,ele_loc)
%DTSIMGUI Graphical User Interface program for DT system response
% 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
% Assisted by Craig Borghesani
% http://world.std.com/~borg/
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');
stat_bar = ui(61);
ele_axs = get(ui(12),'userdata');
ele_mat = get(ui(1),'userdata');
last_mode = get(stat_bar,'userdata');
strs = ui(14:3:26);
edts = ui(15:3:27);
last_mode2 = get(ui(17),'userdata');
num_edt = ui(43);
den_edt = ui(45);
ic_chk = ui(46);
ic_edt = ui(47);
sig_axs = ui(29);
opr_axs = ui(32);
cust_str = ui(62);
cust_edt = ui(63);
curs_btn = ui(65);
curs_dsp = ui(66:69);
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;
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','DT System Response','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','DT System Response','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','dtsimhlp');
uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
'callback','dtsimgui(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','dtsimgui(17)');
uim(7) = uimenu('label',' Zoom ON','separator','on',...
'callback','dtsimgui(18)');
uim(8) = uimenu('label',' Zoom OFF','separator','on',...
'callback','dtsimgui(19)');
uim(9) = uimenu('label',' RESIZE','callback','dtsimgui(20)');
%%%%%%%%%
lft = 190; btm1 = 25; btm2 = 50; btm3 = 75;
lft2 = 10; btm1a = btm1-4.5+252+138;
btm2a = btm1-4.5+107+190-5;
btma = btm1+287-45-35;
ui(1) = uicontrol('style','text','pos',[10,btma+78.5-20,166,17],'back',...
grey,'fore','c','string','Components of Input x[n]','horiz','left');
ui(2) = axes('units','pixel','pos',[6,btma-4.5-20,175,102],'box','on',...
'xtick',[],'ytick',[],'color',ltgrey,'xcolor',ltgrey,...
'ycolor',ltgrey,'fontsize',10);
uit = uicontrol('style','slider','pos',[166,btma-6-20,15,103],'min',-1,...
'max',0,'callback','dtsigedt(4)','vis','off');
set(ui(2),'userdata',uit);
uicontrol('style','frame','pos',[5.5,btma-35-20,175,25],...
'back',grey,'fore',ltgrey);
btma = btma-31;
ui(8) = uicontrol('style','text','pos',[lft2,btma-20,70,17],...
'string','Plot Limits','horiz','right');
ui(9) = uicontrol('style','edit','pos',[lft2+75,btma-20,90,18],...
'back','w','string','0,20',...
'callback','dtsimgui(4)');
ui(10) = uicontrol('style','text','pos',[lft2+107,btma-20,20,17],...
'string','','userdata',3,'vis','off');
ui(3) = uicontrol('style','frame','pos',[lft2-4.5,btm1a-90,176,95-5+20],...
'back',grey,'fore',ltgrey);
ui(4) = uicontrol('style','text','pos',[lft2,btm1a-5,45,20],...
'string','Signal');
ui(5) = uicontrol('style','popup','pos',[lft2+49,btm1a-5,120,20],...
'back','w','string',['General form|',...
'MATLAB Expn'],'callback','dtsimgui(1)');
btm4 = btm1a-25;
ui(11) = uicontrol('style','text','pos',[lft2,btm4,168,17],...
'string','K*(a^n)(n^b)cos(w*n+r)','horiz','left','fore','g');
btm4 = btm4 -20;
ui(62) = uicontrol('style','text','pos',[lft2,btm4,25,17],...
'string','x[n]','vis','off');
ui(63) = uicontrol('style','edit','pos',[lft2+25,btm4,143,18],...
'back','w','vis','off');
ui(14) = uicontrol('style','text','pos',[lft2,btm4,15,17],...
'horiz','right','string','K');
ui(15) = uicontrol('style','edit','pos',[lft2+15,btm4,38,18],...
'back','w','string','2','userdata',0);
ui(17) = uicontrol('style','text','pos',[lft2+58,btm4,15,17],...
'horiz','right','string','a');
ui(18) = uicontrol('style','edit','pos',[lft2+73,btm4,38,18],...
'back','w','string','0.8');
ui(20) = uicontrol('style','text','pos',[lft2+116,btm4,15,17],...
'horiz','right','string','b');
ui(21) = uicontrol('style','edit','pos',[lft2+131,btm4,38,18],...
'back','w','string','0');
btm4 = btm4-20;
ui(23) = uicontrol('style','text','pos',[lft2,btm4,15,17],...
'horiz','right','string','w');
ui(24) = uicontrol('style','edit','pos',[lft2+15,btm4,48,18],...
'back','w','string','0');
ui(26) = uicontrol('style','text','pos',[lft2+68,btm4,45,17],...
'horiz','right','string','r');
ui(27) = uicontrol('style','edit','pos',[lft2+113,btm4,55,18],...
'back','w','string','0');
btm4 = btm4-20;
ui(12) = uicontrol('style','text','pos',[lft2,btm4,15,17],...
'string','n','userdata',ui(2));
ui(13) = uicontrol('style','edit','pos',[lft2+15,btm4,55,18],...
'back','w','string','0,20');
ui(6) = uicontrol('style','push','pos',[lft2+80,btm4,40,17],...
'string','ADD','callback','dtsimgui(2)');
ui(7) = uicontrol('style','push','pos',[lft2+130,btm4,38,17],...
'string','DEL','callback','dtsigedt(7);dtsimplt','enable','off');
btm=btm2a-110;lft=lft2;
ui(40) = uicontrol('style','frame','pos',[5,btm-125-2-20,175,115+2],...
'back',grey,'fore',ltgrey);
btm = btm - 33-20;
ui(41) = uicontrol('style','text','pos',[lft,btm,62,17],...
'string','Sys Resp','horiz','left','fore','c');
ui(48) = uicontrol('style','popup','pos',[lft+67,btm-2,98,20],'back','w',...
'string','Total|Zero-Input|Zero-State', ...
'callback','dtsimplt');
btm = btm - 22;
ui(42) = uicontrol('style','text','pos',[lft,btm,30,17],...
'string','Num','horiz','left');
ui(43) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
'back','w','string','1 0');
btm = btm - 22;
ui(44) = uicontrol('style','text','pos',[lft,btm,30,17],...
'string','Den','horiz','left');
ui(45) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
'back','w','string','1 -0.5');
btm = btm - 22;
ui(46) = uicontrol('style','text','pos',[lft,btm,30,17],...
'string','IC');
ui(47) = uicontrol('style','edit','pos',[lft+35,btm,130,18],...
'back','w','string','');
btm = btm - 25;
ui(49) = uicontrol('style','push','pos',[lft+17,btm,60,20],...
'string','Accept','callback','dtsimplt');
ui(50) = uicontrol('style','push','pos',[lft+87,btm,60,20],...
'string','Reset','callback','dtsimgui(3)');
btm = btm - 30;
ui(65) = uicontrol('style','check','pos',[lft2+100,btm,70,20],...
'string','Cursor','back','y','callback','dtsimgui(9)');
ui(61) = uicontrol('style','text','pos',[5,1,610,17],'horiz','left',...
'userdata',0,'fore','b','back',offwhite);
ui(29) = axes('units','pixel','pos',[210,260,390,155],'box','on',...
'color','k','xcolor','w','ycolor','w','xgrid','on','ygrid','on');
title('Input Signal x[n]');
xlabel('DT Index [n]')
ui(30) = line('xdata',0,'ydata',0,'color','y');
if ver4
ui(31) = line('xdata',0,'ydata',0,'color','y','linestyle','o');
else
ui(31) = line('xdata',0,'ydata',0,'color','y','linestyle','none',...
'marker','o');
end
set(ui(29),'userdata',ui(30:31));
set(ui(6),'userdata',ui(29));
ui(32) = axes('units','pixel','pos',[210,50,390,155],'box','on',...
'color','k','xcolor','w','ycolor','w','xgrid','on','ygrid','on');
title('Total Response');
xlabel('DT Index [n]')
ui(33) = line('xdata',0,'ydata',0,'color','g');
if ver4
ui(34) = line('xdata',0,'ydata',0,'color','g','linestyle','o');
else
ui(34) = line('xdata',0,'ydata',0,'color','g','linestyle','none',...
'marker','o');
end
set(ui(32),'userdata',ui(33:34));
pos = get(f,'pos');
lef = pos(3)-166;
bot = pos(4)-21;
ui(66) = uicontrol('style','text','pos',[lef,bot,20,20],...
'string','X ','horiz','right');
ui(67) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
'string','','back','w');
ui(68) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
'string','Y ','horiz','right');
ui(69) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
'string','','back','w');
set(ui(66:69),'vis','off');
set(f,'userdata',ui);
set(ui(6),'userdata',ui(29));
dtsimgui(1);
dtsigplt(1);
set(ui(6),'userdata',ui(32));
dtsigplt(1);
dtsimplt;
set(ui(6),'userdata',ui(29));
dtsimgui(2);
drawnow;
set(f,'vis','on');
elseif any(mode == [1,8]), % popup selection
val = get(ui(5),'value');
set(stat_bar,'userdata',mode);
if mode == 1, % popup selection
if length(get(ui(14),'userdata')),
set(get(ele_axs,'chil'),'color','k');
end
set(stat_bar,'string','Mode: ADD. Change values and click on Add.');
set(ui(13),'string','0,20');
set(ui(14),'userdata',[]);
set(ui(3),'userdata',[]);
set(ui(7),'enable','off'); set(ui(6),'enable','on');
set([edts,ui(13),cust_edt],'callback','');
else
set(stat_bar,'string','EDIT values & click on component or click DEL to delete.');
set(ui(7),'enable','on'); set(ui(6),'enable','off');
set([edts,ui(13),cust_edt],'callback','dtsigedt(6)');
end
if val == 1, % Exponential
set(ui(11),'string','K*(a^n)(n^b)cos(w*n+r)');
elseif val == 2,
set(ui(11),'string','Example: 4:9 or (2).^(n)');
end
if val == 1,
set([strs,edts],'vis','on');
set([cust_str,cust_edt],'vis','off');
if mode == 1,
set(edts,'enable','on');
else
ele_mat = get(ui(1),'userdata');
ele_vec = ele_mat(ele_loc,:);
set(edts(1),'string',num2str(ele_vec(1)),'enable','on');
set(edts(2),'string',num2str(ele_vec(2)),'enable','on');
set(edts(3),'string',num2str(ele_vec(3)),'enable','on');
set(edts(4),'string',num2str(ele_vec(4)),'enable','on');
set(edts(5),'string',num2str(ele_vec(5)),'enable','on');
set(ui(13),'string',[int2str(ele_vec(7)),',',int2str(ele_vec(9))]);
end
elseif val == 2,
set([strs,edts],'vis','off');
set([cust_str,cust_edt],'vis','on');
if mode == 1
set(cust_edt,'string','');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -