📄 dfirgui.m
字号:
set(ui(47),'enable','off');
set(ui(32:3:44),'enable','off');
elseif mode == 1, % filter, method, and window popup
filter_type = get(filter_uis(2),'value');
edt_val = eval(['[',get(ui(11),'string'),']'],'[]');
if filter_type <3,val=2;else,val=4;end
len=length(edt_val);
if len~=val
set(autoplot,'value',0),
set(plot_btn,'enable','on');
set(autodes,'value',0);
set(mandes,'value',0);
end
flag = 1;
if get(autodes,'value'),
flag = dfirdes;
end
if get(autoplot,'value') & flag, dfirplt; end
elseif any(mode == [2:3]), % filter, method, and window popup
method_type = get(method_uis(2),'value');
window_type = get(window_uis(2),'value');
set(ui([34:3:43,64:2:70,35:3:44]),'vis','off');
if method_type == 1, % optimal
set(window_uis,'vis','off');
set(samp_uis,'vis','on');
set([ui(78),ui(79)],'vis','off');
else
set(window_uis,'vis','on');
set(ui([34,35,64]),'vis','on');
if window_type == 4, % kaiser
set(ui([40,41,68]),'vis','on');
elseif window_type == 5, % chebyshev
set(ui([43,44,70]),'vis','on');
elseif window_type == 6, % harris
set(ui([37,38,66]),'vis','on');
end
if method_type == 3,
set(samp_uis,'vis','off');
set([ui(78),ui(79)],'vis','on');
set([cutoff_uis,ui(64)],'vis','off');
else
set(samp_uis,'vis','on');
set([ui(78),ui(79)],'vis','off');
set([cutoff_uis,ui(64)],'vis','on');
end
end
flag = 1;
if get(autodes,'value'),
flag = dfirdes;
end
if get(autoplot,'value') & flag, dfirplt; end
elseif mode == 4, % edit fields
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(11)),
filter_type = get(filter_uis(2),'value');
if filter_type <3,val=2;else,val=4;end
len=length(edt_val);
if len~=val
set(autoplot,'value',0),
set(plot_btn,'enable','on');
set(autodes,'value',0);
set(mandes,'value',0);
end
end
if edt == length_uis(2), % do various checks on length
if edt_val <= 1,
errordlg('N must be > 1.','Input Error');
return;end
if rem(edt_val,1),
errordlg('N must be an integer.','Input Error');
return;end
if ~rem(edt_val,2),
filter_type = get(filter_uis(2),'value');
method_type = get(method_uis(2),'value');
window_type = get(window_uis(2),'value');
if (method_type>1 & window_type == 5)|filter_type == 4| method_type == 3,
errordlg('This setup requires odd N.','Input Error');
return;end
end
elseif edt == cutoff_uis(2), % inspect range of cutoff
if edt_val <= 0 | edt_val > 0.5,
errordlg('Cutoff: only 0 < Fc <= 0.5.','Input Error');
return;
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 from 0 to 7','Input Error');
return;
end
elseif any(edt == [harris_uis(2),beta_uis(2),ripple_uis(2)]),
if edt_val <= 0,
errordlg('Input must be >= 0.','Input Error');
return;
end
end
flag = 1;
if get(autodes,'value'),
flag = dfirdes;
end
if get(autoplot,'value') & flag, dfirplt; end
elseif mode == 7,
if get(autoplot,'value'),
set(plot_btn,'enable','off');
dfirplt;
else
set(plot_btn,'enable','on');
end
elseif mode == 8, % auto design
flag = 1;
if get(autodes,'value'),
set(mandes,'value',0);
set(autoplot,'value',1);
set(plot_btn,'enable','off');
set(ui(32:3:44),'enable','off');
flag = dfirdes;
else
set(autodes,'value',0);
set(mandes,'value',1);
set(autoplot,'value',0);
set(plot_btn,'enable','on');
set(ui(32:3:44),'enable','on');
end
if flag,
dfirplt;
end
elseif mode == 13, % manual design
if get(mandes,'value'),
set(autodes,'value',0);
set(plot_btn,'enable','on');
set(autoplot,'value',0);
set(ui(32:3:44),'enable','on');
else
set(autodes,'value',1);
set(mandes,'value',0);
set(autoplot,'value',1);
set(plot_btn,'enable','off');
set(ui(32:3:44),'enable','off');
end
elseif mode == 10, % cursor
if get(curs_btn,'value')
set(curs_dsp,'vis','on');
set(f,'WindowButtonMotionFcn','dfirgui(11)');
else
set(f,'Pointer','arrow','WindowButtonMotionFcn','');
set(curs_dsp,'vis','off')
set(curs_btn,'value',0),
end
elseif mode == 11
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
dfirplt;
mstr=get(ui(33),'string');mval=get(ui(33),'value');mstr=mstr(mval,:);
str1='Export impulse response coefficients as';
str2=['Export ' mstr ' magnitude as'];
str3='Export phase (deg) as';
str4='Export analog frequency in Hz as';
exp_str={str1,str2,str3,str4};
exp_var={'firhn','firgain','firphase','firfreq'};
expect=inputdlg(exp_str,'Save Variables as',1,exp_var);
if ~isempty(expect)
ht=get(ui(14),'userdata');%%% FIX FOR UIs
ha=get(ui(15),'userdata');%%% FIX FOR UIs
hp=get(ui(16),'userdata');
if ~isempty(expect{1}),assignin('base',expect{1},ht);end
if ~isempty(expect{2}),assignin('base',expect{2},ha(:,2));end
if ~isempty(expect{3}),assignin('base',expect{3},hp);end
if ~isempty(expect{4}),assignin('base',expect{4},ha(:,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),dfirgui(16);
else
set(curs_btn,'value',0);
dfirgui(10);
if any(cur_axs==ui([73,22,85,90])),
if cur_axs==ui(73),txt='Filter Magnitude';
elseif cur_axs==ui(22),txt='Filter Phase';
elseif cur_axs==ui(85),txt='Pole-Zero Plot';
elseif cur_axs==ui(90),txt='Impulse Response';
end
axlimdlg(txt,[1 1]); %[1 1]=auto +linear/log, [1 0]=auto, no linear/log
else
dfirgui(16);
end
end
elseif mode == 18, % zoom on
set(curs_btn,'value',0);
dfirgui(10); % Use CURSOR MODE
if get(ui(18),'userdata')==0 %%Change ui(15) to whatever
zoom on
set(ui(18),'userdata',1);
else
msgbox('Zoom is already ON.','Zoom Info','help')
end
elseif mode == 19, % zoom off
set(curs_btn,'value',0);
dfirgui(10); % Use CURSOR MODE
if get(ui(18),'userdata')==1
%%%%%Insert old zoom off here
set(f,'currentaxes',ui(73));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(22));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(85));
zoom out,zoom reset,zoom off
set(f,'currentaxes',ui(90));
zoom out,zoom reset,zoom off
set(ui(18),'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),dfirgui(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+6 160 160]);
set(sig_axs,'pos',[-600 240+6 160 160]);
if cur_axs==pz_axs
set(cur_axs,'pos',[210,35,380,380]);
else
set(cur_axs,'pos',[210,35,400,365]);
end
else % minimization
set(mag_axs,'pos',[430 240 160 160]);
set(phs_axs,'pos',[430 35 160 160]);
set(pz_axs,'pos',[220 240+6 160 160]);
set(sig_axs,'pos',[220 35 160 160]);
end
else
dfirgui(16);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -