📄 dfftgui.m
字号:
ui(45) = line('xdata',0,'ydata',0,'color','c','linestyle','none',...
'marker','o');
end
ui(61) = uicontrol('style','text','pos',[0,0,620,15],'horiz','left',...
'userdata',0,'fore','b','back',offwhite);
set(f,'userdata',ui,'currentobject',ui(50));
set(ui(61),'string','Mode: ADD. Change values and press Add.');
dfftgui(2);
drawnow;
set(f,'vis','on');
elseif mode == 1, % changing axis limits
edt = gco;
edt_val = eval(['[',get(edt,'string'),']']);
if edt == range_edt
set(fft_axs,'xlim',[min(edt_val),max(edt_val)]);
set(win_axs,'xlim',[min(edt_val),max(edt_val)]);
elseif edt == mag1_edt
set(fft_axs,'ylim',[min(edt_val),max(edt_val)]);
elseif edt == mag2_edt
set(win_axs,'ylim',[min(edt_val),max(edt_val)]);
end
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','Adding new signal...');
dfftplt;
dfftedt(1);
set(stat_bar,'string','Add new signal or click on a signal to edit/delete');
elseif mode == 3, % edit for sample freq and length
edt = gco;
edt_val = eval(['[',get(edt,'string'),']'],'[]');
if ~length(edt_val),
errordlg('You must enter a VALID number.','Input Error');
return;
end
if any(edt == ui(24))
if (edt_val < 1 | edt_val ~= round(edt_val)) ,
errordlg('You must enter a positive integer.','Input Error');
return;
end
if get(autoplot,'value'), dfftplt; end
elseif any(edt == ui(27))
if length(edt_val)==1
edt_val = [edt_val, edt_val];
end
if length(edt_val)~= 2,
errordlg('You must enter two values.','Input Error');
return;
end
if edt_val(1) < 1 | edt_val(2)<1|rem(edt_val(1),1)|rem(edt_val(2),1),
errordlg('You must enter a positive integer.','Input Error');
return;
end
if edt_val(2)<edt_val(1),
errordlg('Padded length cannot exceed signal length.','Input Error');
return;
end
if get(autoplot,'value'), dfftplt; end
elseif any(edt == [ripple_uis(2),beta_uis(2)]) % inspect cheb ripple
if edt_val <= 0,
errordlg('You must enter a positive value.','Input Error');
return;
end
set(edt,'string',num2str(edt_val));
if get(autoplot,'value'), dfftplt; end
elseif edt == harris_uis(2), % inspect harris type
if edt_val < 0 | edt_val > 7 | rem(edt_val,1)~=0,
errordlg('Enter integer type form 0 to 7.','Input Error');
return;
end
set(edt,'string',int2str(edt_val));
if get(autoplot,'value'), dfftplt; end
end
elseif mode == 4, % window popup
window_type = get(window_pop,'value');
if any(window_type == [(1:4)]),
set([beta_uis,ripple_uis,harris_uis],'vis','off');
elseif window_type == 5, %Kaiser
set(beta_uis,'vis','on');
set(ripple_uis,'vis','off');
set(harris_uis,'vis','off');
elseif window_type == 6, %Cheby
set(ripple_uis,'vis','on');
set(beta_uis,'vis','off');
set(harris_uis,'vis','off');
elseif window_type == 7, % Harris
set(ripple_uis,'vis','off');
set(beta_uis,'vis','off');
set(harris_uis,'vis','on');
end
if get(autoplot,'value'), dfftplt; end
elseif mode == 5, % auto plot
if get(autoplot,'value'),
set(plot_btn,'enable','off');
dfftplt;
else
set(plot_btn,'enable','on');
end
elseif mode == 7, % cursor
if get(curs_btn,'value')
set(curs_dsp,'vis','on');
set(f,'WindowButtonMotionFcn','dfftgui(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
%%%%%% PASTE AT END before last end statement %%%%%%%%%%%%%
elseif mode == 15, %Export data
dfftplt;
fstr=get(ui(32),'string');fval=get(ui(32),'value');fstr=fstr(fval,:);%dB
mstr=get(ui(50),'string');mval=get(ui(50),'value');mstr=mstr(mval,:);%dB
if mval==2,mstr=['normalized ' mstr];end
str1='Export original analog signal xa as';
str2='Export reconstructed signal xr as';
str3='Export time index for xa and xr as';
str4='Export sampled signal xs as';
str5='Export time index for xs as';
str6=['Export unwindowed ' mstr ' FFT magnitude as'];
str7=['Export windowed ' mstr ' FFT magnitude as'];
str8=['Export ' fstr ' of FFT samples as'];
exp_str={str1,str2,str3,str4,str5,str6,str7,str8};
exp_var={'xanalog','xrecon','tval','xsamp','tsamp','fftu','fftw','fftind'};
expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
na=get(ui(54),'userdata');%%% FIX FOR UIs
da=get(ui(55),'userdata');%%% FIX FOR UIs
fm=get(ui(56),'userdata');
if ~isempty(expect{1}),assignin('base',expect{1},na(:,1));end
if ~isempty(expect{2}),assignin('base',expect{2},na(:,2));end
if ~isempty(expect{3}),assignin('base',expect{3},na(:,3));end
if ~isempty(expect{4}),assignin('base',expect{4},da(:,1));end
if ~isempty(expect{5}),assignin('base',expect{5},da(:,2));end
if ~isempty(expect{6}),assignin('base',expect{6},fm(:,1));end
if ~isempty(expect{7}),assignin('base',expect{7},fm(:,2));end
if ~isempty(expect{8}),assignin('base',expect{8},fm(:,3));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),dfftgui(16);
else
set(curs_btn,'value',0);
dfftgui(7); %% CURSOR MODE
if any(cur_axs==ui([35,40,43])),
if cur_axs==ui(35),txt='Sampled signal';
elseif cur_axs==ui(40),txt='Unwindowed FFT';
elseif cur_axs==ui(43),txt='Windowed FFT';
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log, [1 0]=auto, no linear/log
else
dfftgui(16);
end
end
elseif mode == 18, % zoom on
set(curs_btn,'value',0);
dfftgui(7); % Use CURSOR MODE
if get(ui(58),'userdata')==0 %%Change ui(15) to whatever
zoom on
set(ui(58),'userdata',1);
else
msgbox('Zoom is already ON.','Zoom Info','help')
end
elseif mode == 19, % zoom off
set(curs_btn,'value',0);
dfftgui(7); % Use CURSOR MODE
if get(ui(58),'userdata')==1
%%%%%Insert old zoom off here
set(f,'currentaxes',ui(35));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(40));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(43));
zoom out,zoom reset,zoom off
set(ui(58),'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),dfftgui(16);return,end
if any(cur_axs == [sig_axs,fft_axs,win_axs]),
axes(cur_axs);
axs_pos = get(cur_axs,'pos');
if axs_pos(4) == 140, % need to maximize
set([sig_axs,fft_axs,win_axs],'vis','off');
set(cur_axs,'pos',[210,50,390,355],'vis','on');
else % minimization
set(sig_axs,'pos',[210,260,390,140],'vis','on');
set(fft_axs,'pos',[210,60,175,140],'vis','on');
set(win_axs,'pos',[425,60,175,140],'vis','on');
end
else
dfftgui(16);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -