📄 modgui.m
字号:
function modgui(mode,ele_loc)
%MODGUI Graphical User Interface program for modulation concepts.
% 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');
stat_bar = ui(61);
ele_axs = get(ui(12),'userdata');
ele_mat = get(ui(1),'userdata');
last_mode = get(stat_bar,'userdata');
last_mode2 = get(ui(17),'userdata');
strs = ui(14:3:20);
edts = ui(15:3:21);
top_axs = ui(29);
bot_axs = ui(34);
curs_btn = ui(50);
curs_dsp = ui(51:54);
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 = 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','Modulation','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','Modulation','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','modhlp');
uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
'callback','modgui(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','modgui(17)');
uim(7) = uimenu('label',' Zoom ON','separator','on',...
'callback','modgui(18)');
uim(8) = uimenu('label',' Zoom OFF','separator','on',...
'callback','modgui(19)');
uim(9) = uimenu('label',' RESIZE','callback','modgui(20)');
%%%%%%%%
lft = 10; btm = fig_h - 15 - 102;
ui(1) = uicontrol('style','text','pos',[lft,btm+83,150,17],'back',grey,...
'fore','c','string','Message Components','horiz',...
'left','callback','modgui(6)','value',1);
ui(2) = axes('units','pixel','pos',[6,btm,175,102],'box','on',...
'xtick',[],'ytick',[],'color',offwhite,'xcolor',ltgrey,...
'ycolor',ltgrey');
uit = uicontrol('style','slider','pos',[166,btm-2,15,103],'min',-1,...
'max',0,'callback','modedt(4)','vis','off');
set(ui(2),'userdata',uit);
ui(3) = uicontrol('style','frame','pos',[5,btm-126,175,121],...
'back',grey,'fore',ltgrey);
btm = btm - 30;
ui(4) = uicontrol('style','text','pos',[lft,btm,160,17],...
'horiz','center','fore','g','string','m * cos(2*pi*f*t + phi)');
btm = btm - 22;
ui(6) = uicontrol('style','push','pos',[lft+17,btm,60,20],...
'string','Add','callback','modgui(2)');
ui(7) = uicontrol('style','push','pos',[lft+87,btm,60,20],...
'string','Del','callback','modedt(7)','enable','off');
btm = btm - 25;
ui(14) = uicontrol('style','text','pos',[lft,btm,100,17],...
'horiz','right','string','Magnitude (m)');
ui(15) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
'back','w','userdata',0,'string','1');
btm = btm - 22;
ui(17) = uicontrol('style','text','pos',[lft,btm,100,17],...
'horiz','right','string','Freq f (Hz)');
ui(18) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
'back','w','string','1');
btm = btm - 22;
ui(20) = uicontrol('style','text','pos',[lft,btm,100,17],...
'horiz','right','string','Phi (degrees)');
ui(21) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
'back','w','string','0');
btm = btm - 5;
ui(5) = uicontrol('style','frame','pos',[5,btm-54,175,49],...
'back',grey,'fore',ltgrey,'userdata',0);
btm = btm - 27;
ui(23) = uicontrol('style','text','pos',[lft,btm,100,17],...
'string','Carrier f (Hz)','horiz','right','userdata',ui(2));
ui(24) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
'back','w','string','20','callback','modgui(3)');
btm = btm - 22;
ui(26) = uicontrol('style','text','pos',[lft,btm,100,17],...
'string','Duration (sec)','horiz','right');
ui(27) = uicontrol('style','edit','pos',[lft+105,btm,60,18],...
'back','w','string','1','callback','modgui(3)');
btm = btm - 5;
ui(8) = uicontrol('style','frame','pos',[5,btm-80,175,75],...
'back',grey,'fore',ltgrey);
btm = btm - 30;
ui(9) = uicontrol('style','text','pos',[lft,btm+2,50,17],...
'string','Method','horiz','right');
ui(10) = uicontrol('style','popup','pos',[lft+55,btm,110,20],...
'back','w','string',['DSB SC AM|Standard AM|SSB AM|',...
'PM|FM'], 'callback','modgui(4)');
btm = btm - 25;
ui(40) = uicontrol('style','text','pos',[lft,btm+2,115,17],...
'string','Mod Index (beta)','vis','off');
ui(41) = uicontrol('style','edit','pos',[lft+115,btm+2,50,18],...
'back','w','string','0.5','vis','off','callback','modgui(3)');
ui(45) = uicontrol('style','text','pos',[lft,btm+2,115,17],...
'string','Kp (rad/unit)','vis','off');
ui(46) = uicontrol('style','edit','pos',[lft+115,btm+2,50,18],...
'back','w','string','5','vis','off','callback','modgui(3)');
ui(47) = uicontrol('style','text','pos',[lft,btm+2,115,17],...
'string','Kf (Hz/unit)','vis','off');
ui(48) = uicontrol('style','edit','pos',[lft+115,btm+2,50,18],...
'back','w','string','5','vis','off','callback','modgui(3)');
ui(49) = uicontrol('style','popup','pos',[lft+55,btm,110,20],...
'back','w','string',['USB Signal|LSB Signal'],'vis','off',...
'callback','modplt');
btm = btm - 22;
ui(42) = uicontrol('style','check','pos',[lft,btm,80,17],...
'string','Env Det','horiz','left','callback','modplt');
ui(43) = uicontrol('style','text','pos',[lft+90,btm,25,17],...
'string','tau','horiz','right');
ui(44) = uicontrol('style','edit','pos',[lft+115,btm,50,18],...
'back','w','string','0.1','callback','modplt');
btm = btm -35;
ui(50) = uicontrol('style','check','pos',[lft+95,btm,70,20],...
'string','Cursor','back','y','callback','modgui(6)');
pos = get(f,'pos');
lef = pos(3)-166;
bot = pos(4)-21;
ui(51) = uicontrol('style','text','pos',[lef,bot,20,20],...
'string','X ','horiz','right');
ui(52) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
'string','','back','w');
ui(53) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
'string','Y ','horiz','right');
ui(54) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
'string','','back','w');
set(ui(51:54),'vis','off');
ui(29) = axes('units','pixel','pos',[210,260,390,140],'box','on',...
'color','k','xcolor','w','ycolor','w','xgrid','on','ygrid','on');
title('Message Signal');
xlabel('Time [s]');
ui(30) = line('xdata',0,'ydata',0,'color','y');
set(ui(29),'userdata',ui(30));
ui(34) = axes('units','pixel','pos',[210,60,390,140],'box','on',...
'color','k',...
'xcolor','w','ycolor','w','xgrid','on','ygrid','on');
title('Modulated Signal');
xlabel('Time [s]')
ui(35) = line('xdata',0,'ydata',0,'color','m');
ui(36) = line('xdata',0,'ydata',0,'color','c');
set(ui(34),'userdata',ui(35:36));
ui(61) = uicontrol('style','text','pos',[0,0,620,15],'horiz','left',...
'userdata',0,'fore','b','back',offwhite);
set(f,'userdata',ui);
set(ui(61),'string','Mode: ADD. Change values and press Add.');
set(f,'userdata',ui);
modgui(2);
drawnow;
set(f,'vis','on');
elseif mode == 2, % adding
val1 = str2num(get(edts(1),'string'));
val2 = str2num(get(edts(2),'string'));
val3 = str2num(get(edts(3),'string'));
if ~length(val2), val2 = 0; end
if ~length(val3), val3 = 0; end
val_vec = [val1, val2, val3];
ele_mat = [ele_mat;val_vec];
set(ui(1),'userdata',ele_mat);
set(stat_bar,'string','Add new signal or click on a signal to edit/del');
modplt;
modedt(1);
elseif mode == 3, % edit for sample freq and duration
edt = gco;
edt_val = str2num(get(edt,'string'));
if ~length(edt_val),
errordlg('You must enter a VALID number.','Input Error');
return;
elseif edt_val <= 0,
errordlg('Value must be positive.','Input Error');
return;
end
modplt;
elseif mode == 4, % Method popup
method = get(ui(10),'value');
set(ui([40:49]),'vis','off');
if method == 1
set(ui([42:44]),'vis','on');
elseif method == 2, %Standard AM
set(ui([40:44]),'vis','on');
elseif method == 3
set(ui(49),'vis','on');
elseif method == 4
set(ui([45,46]),'vis','on');
elseif method == 5
set(ui([47,48]),'vis','on');
end
modplt;
elseif mode == 6, % cursor
if get(curs_btn,'value')
set(curs_dsp,'vis','on');
set(f,'WindowButtonMotionFcn','modgui(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
elseif mode == 15, %Export data
modplt;
meth=get(ui(10),'value');
envd=get(ui(42),'value');
str1='(Export time index as';
str2='(Export message signal as';
str3='Export modulated signal as';
str4='Export envelope detector output';
if envd & meth<3,
exp_str={str1,str2,str3,str4};
exp_var={'tsec','messig','modsig','detsig'};
else
exp_str={str1,str2,str3};
exp_var={'tsec','messig','modsig'};
end
expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
tt=get(ui(50),'userdata');
ht=get(ui(51),'userdata');%%% FIX FOR UIs
hd=get(ui(52),'userdata');%%% FIX FOR UIs
if ~isempty(expect{1}),assignin('base',expect{1},tt);end
if ~isempty(expect{2}),assignin('base',expect{2},ht(:,1));end
if ~isempty(expect{3}),assignin('base',expect{3},ht(:,2));end
if envd & meth<3,
if ~isempty(expect{4}),assignin('base',expect{4},hd);end
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),modgui(16);
else
set(curs_btn,'value',0);
modgui(6); %%% REPLACE number BY CURSOR MODE
if any(cur_axs==ui([29,34])),%%%% CHANGE UI numbers
if cur_axs==ui(29),txt='Message signal';%%%% CHANGE UI numbers
elseif cur_axs==ui(34),txt='Modulated signal';%%%% CHANGE UI numbers
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log, [1 0]=auto, no linear/log
else
modgui(16);
end
end
elseif mode == 18, % zoom on
set(curs_btn,'value',0);
modgui(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);
modgui(6); % Use CURSOR MODE
if get(ui(5),'userdata')==1
%%%%%Insert old zoom off here
set(f,'currentaxes',ui(29));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(34));
zoom out,zoom reset,zoom off
set(ui(5),'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),modgui(16);return,end
if any(cur_axs == [top_axs,bot_axs]),
axes(cur_axs);
axs_pos = get(cur_axs,'pos');
if axs_pos(4) == 140, % need to maximize
set([top_axs,bot_axs],'vis','off');
set(cur_axs,'pos',[210,60,390,355],'vis','on');
else % minimization
set(top_axs,'pos',[210,260,390,140],'vis','on');
set(bot_axs,'pos',[210,60,390,140],'vis','on');
end
else
modgui(16);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -