📄 maplpplt.m
字号:
function maplpplt
% MAPLPPLT Plot control for MAPLPGUI.
% 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 GUIVAR
f = gcf;
ui = get(f,'userdata');
type_pop = ui(3);
num_edt = ui(8);
den_edt = ui(10);
cutoff_edt=ui(12);
method_pop = ui(17);
edge_edt = ui(19);
plot_edt=ui(21);
samp_edt=ui(23);
sig_axs = ui(32);
sig_line = ui(33);
resp_axs = ui(34);
resp_line = ui(35);
%%%%%%%%%%
if get(ui(15),'userdata')==1
set(f,'currentaxes',ui(32));
zoom out,zoom reset
set(f,'currentaxes',ui(34));
zoom out,zoom reset
end
%%%%%%%%
type =get(type_pop,'value');
method=get(ui(17),'value');
%edges = eval(['[',get(edge_edt,'string'),']']);
edges = eval(['[',get(edge_edt,'string'),']'],'[]');
if isempty(edges)
errordlg('MATLAB syntax error.','Input Error');
return
end
if method <3
if length(edges)>1
errordlg('LP and HP filters require only one band edge.','Input Error');
return
end
else
if length(edges)~=2
errordlg('BP and BS filters require two band edges.','Input Error');
return
end
if edges(1)>=edges(2)
errordlg('Band edges must be in the form Min,Max.','Input Error');
return
end
end
if type==1
fmax = eval(['[',get(plot_edt,'string'),']'],'[]');
if isempty(fmax)
errordlg('MATLAB syntax error.','Input Error');
return
end
else
samp = eval(['[',get(samp_edt,'string'),']'],'[]');
if isempty(samp)
errordlg('MATLAB syntax error.','Input Error');
return
end
if samp<=2*max(edges)
errordlg('Sampling frequency too low.','Input Error');
return
end
end
% Verify Transfer Function
hn_st = get(num_edt,'string');
if isempty(hn_st)
errordlg('Nothing entered.','Input Error');
return
end
problem=0;if hn_st(1)=='W',
hn_st(1)=[];evalin('base',[hn_st ';'],'problem=1;')
if problem==0, hn=evalin('base',hn_st);
if isstr(hn), hn=eval(['[',hn,']'],'[]');end
else
errordlg('MATLAB Syntax error.','Input Error');
return
end
else
hn = eval(['[',hn_st,']'],'[]');
end
if isempty(hn)
errordlg('MATLAB Syntax error.','Input Error');
return
end
hd_st = get(den_edt,'string');
if isempty(hd_st)
errordlg('Nothing entered.','Input Error');
return
end
problem=0;if hd_st(1)=='W',
hd_st(1)=[];evalin('base',[hd_st ';'],'problem=1;')
if problem==0, hd=evalin('base',hd_st);
if isstr(hd), hd=eval(['[',hd,']'],'[]');end
else
errordlg('MATLAB Syntax error.','Input Error');
return
end
else
hd = eval(['[',hd_st,']'],'[]');
end
if isempty(hd)
errordlg('MATLAB Syntax error.','Input Error');
return
end
if ~any(hn) | ~any(hd)
errordlg('Num and Den must contain nonzero elements.','Input Error');
return
end
while hn(1)==0,hn(1)=[];end
while hd(1)==0,hd(1)=[];end
ln=length(hn);ld=length(hd);
set(ui(27),'userdata',hn);
set(ui(28),'userdata',hd);
cut = eval(['[',get(cutoff_edt,'string'),']'],'[]');
if isempty(cut)
errordlg('MATLAB syntax error.','Input Error');
return
end
%%%% Find transformed filter %%%%%%
hnt=hn;hdt=hd;
if type < 3 & abs(1-cut*2*pi)>100*eps %%convert to unit radian LPP
[hnt,hdt]=polymap(hn,hd,[cut*2*pi 0],1);
end
if type==1
if method==1
[num,den]=lp2af('lp',hnt,hdt,2*pi*edges);
elseif method==2
[num,den]=lp2af('hp',hnt,hdt,2*pi*edges);
elseif method==3
f0=sqrt(prod(edges));bw=diff(edges);
[num,den]=lp2af('bp',hnt,hdt,2*pi*f0,2*pi*bw);
elseif method ==4
f0=sqrt(prod(edges));bw=diff(edges);
[num,den]=lp2af('bs',hnt,hdt,2*pi*f0,2*pi*bw);
end
set(ui(29),'userdata',num);
set(ui(30),'userdata',den);
f=linspace(0,fmax,501);
s=sqrt(-1)*2*pi*f;
H1=abs(polyval(hn,s)./polyval(hd,s));
H2=abs(polyval(num,s)./polyval(den,s));
set(sig_line,'xdata',f,'ydata',H1);
set(sig_axs,'xlim',[0 fmax],'ylim',[0,max(H1)]);
set(resp_line,'xdata',f,'ydata',H2);
set(resp_axs,'xlim',[0 fmax],'ylim',[0,max(H2)]);
set(ui(31),'userdata',[H1(:) H2(:) f(:)]);
elseif type==2
edges=edges/samp;
if method==1
[num,den]=lp2iir('lp','a',hnt,hdt,1,edges);
elseif method==2
[num,den]=lp2iir('hp','a',hnt,hdt,1,edges);
elseif method==3
f_center = eval(['[',get(ui(25),'string'),']'],'[]');
if isempty(f_center)
[num,den]=lp2iir('bp','a',hnt,hdt,1,edges);
else
[num,den]=lp2iir('bp','a',hnt,hdt,1,edges,f_center/samp);
end
elseif method==4
f_center = eval(['[',get(ui(25),'string'),']'],'[]');
if isempty(f_center)
[num,den]=lp2iir('bp','a',hnt,hdt,1,edges);
else
[num,den]=lp2iir('bp','a',hnt,hdt,1,edges,f_center/samp);
end
end
f=linspace(0,0.5,501);fmax=0.5*samp;
s=sqrt(-1)*2*pi*f*samp;z=exp(sqrt(-1)*2*pi*f);
H1=abs(polyval(hn,s)./polyval(hd,s));
H2=abs(polyval(num,z)./polyval(den,z));
set(sig_line,'xdata',f*samp,'ydata',H1);
set(sig_axs,'xlim',[0 fmax],'ylim',[0,max(H1)]);
set(resp_line,'xdata',f*samp,'ydata',H2);
set(resp_axs,'xlim',[0 fmax],'ylim',[0,max(H2)]);
set(ui(31),'userdata',[H1(:) H2(:) f(:)*samp]);
elseif type==3
%edges=edges/samp;cutd=cut/samp
if method==1
[num,den]=lp2iir('lp','d',hnt,hdt,samp,edges,cut);
elseif method==2
[num,den]=lp2iir('hp','d',hnt,hdt,samp,edges,cut);
elseif method==3
[num,den]=lp2iir('bp','d',hnt,hdt,samp,edges,cut);
elseif method==4
[num,den]=lp2iir('bs','d',hnt,hdt,samp,edges,cut);
end
f=linspace(0,0.5,501);fmax=0.5*samp;
z=exp(sqrt(-1)*2*pi*f);
H1=abs(polyval(hn,z)./polyval(hd,z));
H2=abs(polyval(num,z)./polyval(den,z));
set(sig_line,'xdata',f*samp,'ydata',H1);
set(sig_axs,'xlim',[0 fmax],'ylim',[0,max(H1)]);
set(resp_line,'xdata',f*samp,'ydata',H2);
set(resp_axs,'xlim',[0 fmax],'ylim',[0,max(H2)]);
set(ui(31),'userdata',[H1(:) H2(:) f(:)*samp]);
end
%mtt=get(sig_axs,'title');
%mtt=get(mag_axes,'xlabel');
%set(mtt,'string',f_label);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -