📄 dfirgui.m
字号:
function dfirgui(mode)
% DFIRGUI Design of finite impulse response (FIR) filters.
%
% 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');
filter_uis = ui(3:4);
method_uis = ui(5:6);
window_uis = ui(7:8);
edge_edt = ui(11);
attn_edt = ui(13);
samp_uis = ui(19:20);
length_uis = ui([31:32]);
cutoff_uis = ui([34:35]);
harris_uis = ui([37:38]);
beta_uis = ui([40:41]);
ripple_uis = ui([43:44]);
autoplot = ui(46);
plot_btn = ui(47);
autodes = ui(71);
mandes = ui(72);
curs_btn = ui(14);
curs_dsp = ui(15:18);
mag_axs = ui(73);
phs_axs = ui(22);
pz_axs = ui(85);
sig_axs = ui(90);
lin_rad = ui(33);
des_btn = ui(72);
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','FIR Filter Design','numbertitle','off',...
'resize','off','vis','off','interruptible',int_str,...
'color',dkgrey,'defaultaxesfontsize',10,...
'defaulttextfontsize',10);
edt_ht = 18;
else
int_str = 'on';
eval('f = colordef(''new'',''none'');');
set(f,'pos',[flft,fbtm,fig_w,fig_h],'menubar','none',...
'name','FIR Filter Design','numbertitle','off',...
'resize','off','vis','off','interruptible',int_str,...
'color',dkgrey,'defaultaxesfontsize',8,...
'defaultuicontrolback',[0.5,0.5,0.5],...
'defaulttextfontsize',8);
edt_ht = 20;
end
%%% OPTIONS:
uim(1) = uimenu('label','OPTIONS');
uim(2) = uimenu(uim(1),'label','Help and Info','callback','dfirhlp');
uim(3) = uimenu(uim(1),'label','Export Data','separator','on',...
'callback','dfirgui(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','dfirgui(17)');
uim(7) = uimenu('label',' Zoom ON','separator','on',...
'callback','dfirgui(18)');
uim(8) = uimenu('label',' Zoom OFF','separator','on',...
'callback','dfirgui(19)');
uim(9) = uimenu('label',' RESIZE','callback','dfirgui(20)');
%%%%%%%
lft = 9; btm = fig_h - 39;
ui(1) = uicontrol('style','frame','pos',[lft-5,btm-160,175,190],...
'back',grey,'fore',ltgrey);
ui(2) = uicontrol('style','text','pos',[lft,btm+7,165,17],...
'horiz','left','fore','c','string','Design Specifications');
btm = btm - 18;
ui(3) = uicontrol('style','text','pos',[lft,btm,50,17],...
'string','Filter','horiz','left');
ui(4) = uicontrol('style','popup','pos',[lft+55,btm,110,20],...
'string','Lowpass|Highpass|Bandpass|Bandstop',...
'back','w','value',3,'callback','dfirgui(1)');
btm = btm - 25;
ui(5) = uicontrol('style','text','pos',[lft,btm,50,17],...
'string','Method','horiz','left');
ui(6) = uicontrol('style','popup','pos',[lft+55,btm,110,20],...
'string','Optimal|Window|Halfband',...
'back','w','callback','dfirgui(2)');
btm = btm - 25;
ui(7) = uicontrol('style','text','pos',[lft,btm,50,17],...
'string','Window');
ui(8) = uicontrol('style','popup','pos',[lft+55,btm,110,20],...
'string',['Hamming|von Hann|Blackman|Kaiser|Chebyshev|Harris'],...
'back','w','callback','dfirgui(3)');
set(ui(7:8),'vis','off');
btm = btm - 22;
ui(9) = uicontrol('style','text','pos',[lft,btm,165,17],...
'horiz','left','string','Band Edges in Hz');
btm = btm - 22;
% ui(10) = uicontrol('style','text','pos',[lft,btm,60,17],...
% 'horiz','left','string','Edge(Hz)');
ui(11) = uicontrol('style','edit','pos',[lft,btm,165,edt_ht],...
'back','w','string','10, 20, 30, 40','callback','dfirgui(4)',...
'horiz','right');
btm = btm - 22;
ui(12) = uicontrol('style','text','pos',[lft,btm,165,17],...
'horiz','left','string','Attenuation in dB');
btm = btm - 22;
ui(10) = uicontrol('style','text','pos',[lft,btm,60,17],...
'horiz','left','string','[Ap, As]');
ui(13) = uicontrol('style','edit','pos',[lft+65,btm,100,edt_ht],...
'back','w','string','2, 40','callback','dfirgui(4)',...
'horiz','right');
btm = btm - 25;
ui(19) = uicontrol('style','text','pos',[lft,btm,60,17],...
'horiz','left','string','Samp (Hz)');
ui(20) = uicontrol('style','edit','pos',[lft+65,btm,100,edt_ht],...
'back','w','string','100','callback','dfirgui(4)',...
'horiz','right');
ui(78) = uicontrol('style','text','pos',[lft,btm,65,17],...
'horiz','left','string','Samp (Hz)','vis','off');
ui(79) = uicontrol('style','text','pos',[lft+70,btm,90,17],...
'back',ltgrey,'string','','vis','off');
btm = btm - 22;
uicontrol('style','text','pos',[lft,btm,60,17],...
'horiz','left','string','Magnitude');
ui(33) = uicontrol('style','popup','pos',[lft+65,btm,100,20],...
'string','Linear|decibel','value',2,...
'back','w','callback','dfirplt');
btm = btm - 25;
ui(46) = uicontrol('style','check','pos',[lft,btm,90,17],...
'string','AutoPlot','callback','dfirgui(7)',...
'value',0);
ui(47) = uicontrol('style','push','pos',[lft+95,btm-2,70,20],...
'string','Plot','callback','dfirplt;');
btm = btm - 22;
ui(30) = uicontrol('style','text','pos',[lft,btm,39,17],...
'horiz','left','fore','c','string','Mode');
ui(71) = uicontrol('style','check','pos',[lft+40,btm,55,17],...
'string','Auto','callback','dfirgui(8)',...
'value',1,'fore','b','back','g');
ui(72) = uicontrol('style','check','pos',[lft+96,btm,75,17],...
'value',0,'string','Manual','callback','dfirgui(13)',...
'fore','b','back','r');
btm = btm - 22;
ui(31) = uicontrol('style','text','pos',[lft,btm,50,17],...
'horiz','left','string','Length');
ui(62) = uicontrol('style','text','pos',[lft+52,btm,65,17],...
'back',ltgrey);
ui(32) = uicontrol('style','edit','pos',[lft+120,btm,50,edt_ht],...
'back','w','string','7','callback','dfirgui(4)');
btm = btm - 22;
ui(34) = uicontrol('style','text','pos',[lft,btm,50,17],...
'horiz','left','string','LPP Fc');
ui(64) = uicontrol('style','text','pos',[lft+52,btm,55,17],...
'back',ltgrey);
ui(35) = uicontrol('style','edit','pos',[lft+110,btm,60,edt_ht],...
'back','w','string','0.25','callback','dfirgui(4)');
btm = btm - 22;
ui(37) = uicontrol('style','text','pos',[lft,btm,40,17],...
'horiz','left','string','Type');
ui(66) = uicontrol('style','text','pos',[lft+45,btm,60,17],...
'back',ltgrey);
ui(38) = uicontrol('style','edit','pos',[lft+110,btm,60,edt_ht],...
'back','w','string','3','callback','dfirgui(4)');
ui(40) = uicontrol('style','text','pos',[lft,btm,40,17],...
'horiz','left','string','Beta');
ui(68) = uicontrol('style','text','pos',[lft+45,btm,60,17],...
'back',ltgrey);
ui(41) = uicontrol('style','edit','pos',[lft+110,btm,60,edt_ht],...
'back','w','string','2','callback','dfirgui(4)');
ui(43) = uicontrol('style','text','pos',[lft,btm,80,17],...
'horiz','left','string','Ripple dB');
ui(70) = uicontrol('style','text','pos',[lft+85,btm,40,17],...
'back',ltgrey);
ui(44) = uicontrol('style','edit','pos',[lft+130,btm,40,edt_ht],...
'back','w','string','60','callback','dfirgui(4)');
set(ui([34:3:43,64:2:70,35:3:44]),'vis','off');
btm = btm - 22;
ui(49) = uicontrol('style','text','pos',[lft,btm,40,17],...
'horiz','right','string','Ap =','fore','y');
ui(50) = uicontrol('style','text','pos',[lft+45,btm,125,17],...
'back',ltgrey);
btm = btm - 18;
ui(51) = uicontrol('style','text','pos',[lft,btm,40,17],...
'horiz','right','string','As =','fore','y');
ui(52) = uicontrol('style','text','pos',[lft+45,btm,125,17],...
'back',ltgrey);
btm = btm - 18;
ui(94) = uicontrol('style','text','pos',[lft,btm,40,17],...
'horiz','right','string','PSL =','fore','y');
ui(95) = uicontrol('style','text','pos',[lft+45,btm,125,17],...
'back',ltgrey);
btm = btm -25;
ui(14) = uicontrol('style','check','pos',[lft+95,btm,70,20],...
'string','Cursor','back','y','callback','dfirgui(10)');
pos = get(f,'pos');
lef = pos(3)-166;
bot = pos(4)-21;
ui(15) = uicontrol('style','text','pos',[lef,bot,20,20],...
'string','X ','horiz','right');
ui(16) = uicontrol('style','text','pos',[lef+20,bot,60,20],...
'string','','back','w');
ui(17) = uicontrol('style','text','pos',[lef+85,bot,20,20],...
'string','Y ','horiz','right');
ui(18) = uicontrol('style','text','pos',[lef+105,bot,60,20],...
'string','','back','w','userdata',0);
set(ui(15:18),'vis','off');
ui(73) = axes('units','pixel','pos',[430,240+6,160,160],'box','on',...
'xlim',[0,0.5],'color','k','xgrid','on','ygrid','on');
title('Magnitude Spectrum ');
xlabel('Analog Frequency [Hz]');
ui(74) = line('xdata',0,'ydata',0,'color','g','erase','norm');
if ver4,
ui(75) = line('xdata',0,'ydata',0,'color','y','erase','norm',...
'linestyle','o');
else
ui(75) = line('xdata',0,'ydata',0,'color','y','erase','norm',...
'linestyle','none','marker','o');
end
ui(76) = line('xdata',0,'ydata',0,'color','m','erase','norm',...
'linestyle',':');
ui(93) = line('xdata',0,'ydata',0,'color','y','erase','norm',...
'linestyle',':');
set(ui(73),'userdata',ui([74:76,93]));
ui(22) = axes('units','pixel','pos',[430,35,160,160],'box','on',...
'xlim',[0,0.5],'color','k','xgrid','on','ygrid','on');
title('Phase (degrees)');
xlabel('Analog Frequency [Hz]');
ui(23) = line('xdata',0,'ydata',0,'color','m','erase','back',...
'linestyle','-');
set(ui(22),'userdata',ui(23));
ui(85) = axes('units','pixel','pos',[220,240+6,160,160],'box','on',...
'color','k','xgrid','on','ygrid','on');
title('Pole-Zero Plot');
ui(88) = line('xdata',0,'ydata',0,'color','y','erase','back');
if ver4,
ui(86) = line('xdata',0,'ydata',0,'color','c','linestyle','o',...
'erase','back');
else
ui(86) = line('xdata',0,'ydata',0,'color','c','linestyle','none',...
'marker','o','erase','back','markersize',8);
end
if ver4,
ui(87) = line('xdata',0,'ydata',0,'color','g','linestyle','x',...
'erase','back');
else
ui(87) = line('xdata',0,'ydata',0,'color','g','linestyle','none',...
'marker','x','erase','back','markersize',11);
end
% axis('equal');
set(ui(85),'userdata',ui(86:88));
ui(90) = axes('units','pixel','pos',[220,35,160,160],'box','on',...
'color','k',...
'xgrid','on','ygrid','on');
title('Impulse Response h[n]');
xlabel('DT Index [n]');
ui(91) = line('xdata',0,'ydata',0,'color','m','erase','back');
%For drawing dt signals with markers
if ver4,
ui(92) = line('xdata',0,'ydata',0,'color','m','linestyle','o',...
'erase','back');
else
ui(92) = line('xdata',0,'ydata',0,'color','m','linestyle','none',...
'marker','o','erase','back');
end
set(ui(90),'userdata',ui([91:92]));
set(f,'userdata',ui);
set(ui(71),'value',1),
dfirgui(8);
drawnow;
set(f,'vis','on');
set(ui(71),'value',1);
set(ui(72),'value',0);
set(ui(46),'value',1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -