📄 ctsimgui.m
字号:
function ctsimgui(mode)
%CTSIMGUI Graphical User Interface for simulation of analog systems
% 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
global HNUM HDEN
if nargin == 0, mode = 0; end
if mode ~= 0,
f = gcf;
ui = get(f,'userdata');
action_pop = ui(13);
num_edt = ui(4);
den_edt = ui(6);
n_edt = ui(10);
xn_edt = ui(12);
ic_edt = ui(20);
t_range = ui(16);
t_step = ui(18);
sig_axs = ui(23);
opr_axs = ui(45);
curs_btn = ui(25);
curs_dsp = ui(26:29);
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','CT System Response Simulation','numbertitle','off',...
'resize','off','vis','off','interruptible',int_str,...
'color',dkgrey,'defaultaxesfontsize',10,...
'defaulttextfontsize',10,'windowbuttondownfcn','ctsimgui(5)');
else
int_str = 'on';
eval('f = colordef(''new'',''none'');');
set(f,'pos',[flft,fbtm,fig_w,fig_h],'menubar','none',...
'name','CT System Response Simulation','numbertitle','off',...
'resize','off','vis','off','interruptible',int_str,...
'color',dkgrey,'defaultaxesfontsize',10,...
'defaultuicontrolback',[0.5,0.5,0.5],...
'defaulttextfontsize',10,'windowbuttondownfcn','ctsimgui(5)');
end
uim(1) = uimenu('label','Info');
uim(2) = uimenu(uim(1),'label','Help','callback','ctsimhlp');
% uim(3) = uimenu(uim(1),'label','Export data','separator','on',...
% 'callback','');
uim(4) = uimenu(uim(1),'label','Exit','separator','on',...
'callback','close(gcf)');
lft = 10; btm = fig_h - 5;
ui(1) = uicontrol('style','frame','pos',[5,btm-142-24+40,175,100],...
'back',grey,'fore',ltgrey);
btm = btm - 52;
ui(2) = uicontrol('style','text','pos',[lft,btm,168,17],...
'horiz','left','fore','c','string','System Transfer Function');
btm = btm - 22;
ui(3) = uicontrol('style','text','pos',[lft,btm,30,17],...
'string','Num','horiz','left');
ui(4) = uicontrol('style','edit','pos',[lft+35,btm,130,17],...
'back','w','string','1');
btm = btm - 22;
ui(5) = uicontrol('style','text','pos',[lft,btm,30,17],'string','Den');
ui(6) = uicontrol('style','edit','pos',[lft+35,btm,130,17],...
'back','w','string','1 1');
btm = btm - 22;
ui(19) = uicontrol('style','text','pos',[lft,btm,30,17],'string','IC');
ui(20) = uicontrol('style','edit','pos',[lft+35,btm,130,17],...
'back','w','string','0');
ui(7) = uicontrol('style','frame','pos',[5,btm-142+40-10+20,175,75],...
'back',grey,'fore',ltgrey);
btm = btm - 42;
ui(8) = uicontrol('style','text','pos',[lft,btm,160,17],...
'horiz','left','fore','c','string','Input Signal x(t)');
btm = btm - 22;
ui(9) = uicontrol('style','text','pos',[lft,btm,55,17],...
'horiz','right','string','Range t');
ui(10) = uicontrol('style','edit','pos',[lft+60,btm,105,17],...
'back','w','string','0,1');
btm = btm - 22;
ui(11) = uicontrol('style','text','pos',[lft,btm,30,17],'string','x(t)');
ui(12) = uicontrol('style','edit','pos',[lft+35,btm,130,17],...
'back','w','string','tri(t)');
btm = btm - 30;
ui(14) = uicontrol('style','frame','pos',[5,btm-142+5+100,175,50],...
'back',grey,'fore',ltgrey);
btm = btm - 10;
ui(15) = uicontrol('style','text','pos',[lft,btm,70,17],'string','Plot to t =');
ui(16) = uicontrol('style','edit','pos',[lft+75,btm,90,17],...
'back','w','string','3');
btm = btm - 22;
ui(17) = uicontrol('style','text','pos',[lft,btm,70,17],'string','Time Step');
ui(18) = uicontrol('style','edit','pos',[lft+75,btm,90,17],...
'back','w','string','0.01');
btm = btm - 35;
% ui(13) = uicontrol('style','popup','pos',[lft+15,btm,140,20],...
% 'string',['Edit Signals|Start Action'],...
% 'back','w','callback','ctsimgui(1)');
ui(13) = uicontrol('style','popup','pos',[lft+15,btm,140,20],...
'string',['Edit Values|Runge-Kutta 1|Runge-Kutta 2|',...
'Runge-Kutta 4|Simpson'],...
'back','w','callback','ctsimgui(1)');
%%%%%%%%%%%%%%%%%%%%% change position %%%%%%%%%%%%%%%%%%%%
btm = btm -105;
ui(25) = uicontrol('style','check','pos',[lft+95,btm,70,20],...
'string','Cursor','back','y','callback','ctsimgui(6)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pos = get(f,'pos');
lef = pos(3)-166;
bot = pos(4)-21;
ui(26) = uicontrol('style','text','pos',[lef,bot,20,20],...
'string','X ','horiz','right');
ui(27) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
'string','','back','w');
ui(28) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
'string','Y ','horiz','right');
ui(29) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
'string','','back','w');
set(ui(26:29),'vis','off');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ui(23) = axes('units','pixel','pos',[210,255,390,160],'box','on',...
'xgrid','on','ygrid','on','xlim',[0,3],'color','k');
% 'xlim',[0,1],'color','k');
title('Input Signal x(t)');
xlabel('Time t');
ui(24) = line('xdata',0,'ydata',0,'color','y');
set(ui(23),'userdata',ui(24));
set(ui(2),'userdata',ui(23));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ui(45) = axes('units','pixel','pos',[210,40,390,160],'box','on',...
'xgrid','on','ygrid','on','xlim',[0,3],'color','k');
% 'xlim',[0,1],'color','k');
% set(ui(45),'userdata',[]);
title('Response y(t)');
xlabel('Time t');
ui(21) = line('xdata',0,'ydata',0,'color','r');
set(ui(45),'userdata',ui(21));
set(ui(3),'userdata',ui(45));
set(f,'userdata',ui);
drawnow;
set(f,'vis','on');
elseif mode == 1, % signal popup
set(ui([4,6,10,12,16,18,20]),'enable','on');
ctsimgui(2);
action = get(action_pop,'value');
if action > 1
set(ui([4,6,10,12,16,18,20]),'enable','off');
ctsimplt;
end
elseif mode == 2, % edit
num_str = get(num_edt,'string');
if ~length(num_str)
errordlg('No Matlab array entered for numerator','Input Error');
set(action_pop,'value',1);
return;
end
% num_str = ['[',num_str,']'];
den_str = get(den_edt,'string');
if ~length(den_str)
errordlg('No Matlab array entered for denominator','Input Error');
set(action_pop,'value',1);
return;
end
den = eval(['[',den_str,']']);ld =length(den);
if ld<2
errordlg('Denominator length must be at least two','Input Error');
set(action_pop,'value',1);
return;
end
ic_str = get(ic_edt,'string');
ic = eval(['[',ic_str,']']);lc=length(ic);
if length(ic)>0
if lc ~= ld-1
errordlg('Wrong number of initial conditions','Input Error');
set(action_pop,'value',1);
return;
end
end
% obtain local range values
n_str = get(n_edt,'string');
loc_com = find(n_str == ',');
if length(loc_com),
minn = str2num(n_str(1:(loc_com-1)));
maxn = str2num(n_str((loc_com+1):length(n_str)));
else
errordlg('Range for x(t) be entered as min, max.','Input Error');
set(action_pop,'value',1);
return;
end
if ~length(minn) | (~length(maxn)),
errordlg('Range for x(t) must be entered as min, max.','Input Error');
set(action_pop,'value',1);
return;
elseif minn >= maxn,
errordlg('Range for x(t) must be entered as min, max.','Input Error');
set(action_pop,'value',1);
return;
elseif minn<0,
errordlg('Lower range limit must be positive.','Input Error');
set(action_pop,'value',1);
return;
end
set(n_edt,'userdata',n_str);
xn_str = get(xn_edt,'string');
if ~length(xn_str)
errordlg('No Matlab array entered for x(t)!','Input Error');
set(action_pop,'value',1);
return;
end
xn_str = ['[',xn_str,']'];
t = eval(['[',n_str,']']);
dt=(t(2)-t(1))/2;
t = t(1):dt:t(2);
ttt=0;
eval([xn_str ';'],'ttt=1;');
if ttt
errordlg('Incorrect Matlab syntax for x(t).','Input Error');
set(action_pop,'value',1);
return;
end
xn_eval = eval(xn_str);
if length(xn_eval) ~= length(t) & length(xn_eval) ~= 1
errordlg('x(t) must be a string function, not an array.','Input Error');
set(action_pop,'value',1);
return;
end
set(xn_edt,'userdata',xn_str);
t_str = get(t_range,'string');
if ~length(t_str)
errordlg('No value entered for plot time!','Input Error');
set(action_pop,'value',1);
return;
end
if eval(t_str)<=0
errordlg('Plot time must be positive!','Input Error');
set(action_pop,'value',1);
return;
end
t_stp = get(t_step,'string');
if ~length(t_stp)
errordlg('No value entered for time step!','Input Error');
set(action_pop,'value',1);
return;
end
if eval(t_stp)<=0
errordlg('Time step must be positive!','Input Error');
set(action_pop,'value',1);
return;
end
elseif mode == 3, % edit fields
% if get(autoplot,'value'), fsrplt; end
elseif mode == 5, % mouse functionality
sel_type = get(f,'selectiontype');
cur_obj = gco;
cur_par = get(cur_obj,'parent');
if cur_par == f,
cur_axs = cur_obj;
else
cur_axs = cur_par;
end
if any(cur_axs == [sig_axs,opr_axs]),
axes(cur_axs);
if strcmp(sel_type,'open'),
tit_str = get(get(cur_axs,'title'),'string');
axs_pos = get(cur_axs,'pos');
if axs_pos(4) == 160, % need to maximize
if cur_axs == sig_axs,
% set(opr_axs,'pos',[-150,0,1,1]);
set(opr_axs,'vis','off');
else
% set(sig_axs,'pos',[-150,0,1,1]);
set(sig_axs,'vis','off');
end
% set(cur_axs,'pos',[210,40,390,370]);
set(cur_axs,'pos',[210,40,390,370],'vis','on');
% set(get(cur_axs,'title'),'string',tit_str);
else % minimization
% if cur_axs == sig_axs,
% set(cur_axs,'pos',[210,255,390,160],'vis','on');
% set(opr_axs,'pos',[210,40,390,160],'vis','on');
% else
% set(cur_axs,'pos',[210,40,390,160],'vis','on');
% set(sig_axs,'pos',[210,255,390,160],'vis','on');
% end
set(sig_axs,'pos',[210,255,390,160],'vis','on');
set(opr_axs,'pos',[210,40,390,160],'vis','on');
end
% set(get(cur_axs,'title'),'string',tit_str);
else
ctsimgui(6);
end
end
elseif mode == 6, % cursor
if get(curs_btn,'value')
set(curs_dsp,'vis','on');
set(f,'WindowButtonMotionFcn','ctsimgui(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
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -