📄 dtfplt.m
字号:
function dtfplt
% DTFPLT Support file for DTFGUI.
% 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
f = gcf;
ui = get(f,'userdata');
num_edt = ui(3);
den_edt = ui(5);
clear_btn = ui(9);
time_edt = ui(44);
sig_axs = ui(7);
sig_line = ui([8,12]);
resp_axes = ui(10);
resp_line = ui(11);
mag_axes = ui(27);
mag_line = ui(28);
pz_axes = ui(23);
uc_line = ui(26);
z_line = ui(24);
p_line = ui(25);
freq_pop = ui(14);
freq_edt = ui(16);
%%%%%
if get(ui(5),'userdata')==1
set(f,'currentaxes',ui(7));
zoom out,zoom reset
set(f,'currentaxes',ui(10));
zoom out,zoom reset
set(f,'currentaxes',ui(23));
zoom out,zoom reset
set(f,'currentaxes',ui(27));
zoom out,zoom reset
end
%%%%%
axs_han=get(ui(1),'userdata');
f_axis = get(freq_pop,'value');
f_lim = eval(['[',get(freq_edt,'string'),']']);
if length(f_lim)<2
errordlg('Limits must be in the form Min,Max.','Input Error');
return
end
if f_lim(1)>=f_lim(2)
errordlg('Limits must be in the form Min,Max.','Input Error');
return
end
n_lim = eval(['[',get(time_edt,'string'),']']);
if length(n_lim)<2
errordlg('Limits must be in the form Min,Max.','Input Error');
return
end
if n_lim(1)>=n_lim(2)
errordlg('Limits must be in the form Min,Max.','Input Error');
return
end
n=n_lim(1):n_lim(2);
% 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
set(ui(13),'userdata',hn);
set(ui(14),'userdata',hd);
ln=length(hn);ld=length(hd);
tdd=get(ui(47),'value');
if tdd==1
h_impn=izt('tf',hn,hd);tit='Impulse Response h[n]';
elseif tdd==2
h_impn=izt('tf',[hn 0],conv(hd,[1 -1]));tit='Step Response s[n]';
end
if ~isempty(h_impn)
h_imp=eval(h_impn);
h_imp=h_imp.*(abs(h_imp)>1e-6);
else
h_imp=0*n;
end
td_resp=[tit ' = ' h_impn];
set(ui(61),'string',td_resp);
set(ui(15),'userdata',h_impn);
f=linspace(f_lim(1),f_lim(2),501);
set(ui(16),'userdata',f(:));
if f_axis == 2
F=f/2/pi;f_label = 'Digital Frequency [Omega]';
else
F=f;f_label='Digital Frequency [F]';
end
%H=freqz(hn,hd,2*pi*F);
z_w=exp(sqrt(-1)*2*pi*F);
H = polyval(hn,z_w)./polyval(hd,z_w);
Hm=abs(H);
%Impulse Response
hmin=min(h_imp);hmax=max(h_imp);
if hmax==hmin
hmax=hmax+0.5;hmin=hmin-0.5;
end
if hmin>0, hmin=0;end
if hmax<0, hmax=0;end
set(sig_axs,'xlim',[n_lim(1),n_lim(2)],'ylim',[hmin,hmax]);
dtstem(sig_line,n,h_imp);
ptt=get(sig_axs,'title');
set(ptt,'string',tit);
set(sig_axs,'userdata',tit);
%Magnitude
set(mag_line,'xdata',f,'ydata',Hm);
set(ui(17),'userdata',Hm(:));
Hmax=max(Hm);if ~any(abs(diff(Hm))>100*eps),Hmax=1.2*Hmax;end
set(mag_axes,'xlim',[min(f) max(f)],'ylim',[0,Hmax]);
mtt=get(mag_axes,'xlabel');
set(mtt,'string',f_label);
%Phase
%l=ln-ld;
Pd=unwrap(angle(H));
%if l>0,Pd=Pd+2*pi*F*l;end
Pd=Pd*180/pi; Pd=Pd.*(abs(Pd)>1e-6);
set(resp_line,'xdata',f,'ydata',Pd);
set(ui(18),'userdata',Pd(:));
%set(resp_axes,'xlim',[min(f) max(f)]);
Pmax=max(Pd);Pmin=min(Pd);
if Pmax>Pmin
set(resp_axes,'xlim',[min(f),max(f)],'ylim',[Pmin,Pmax]);
else
set(resp_axes,'xlim',[min(f),max(f)],'ylim',[Pmin-5,Pmax+5]);
end
ptt=get(resp_axes,'xlabel');
set(ptt,'string',f_label);
%Pole-zero plot
fr=0:1/360:1;
phi=fr*2*pi;
cir=exp(sqrt(-1)*phi);
set(uc_line,'xdata',real(cir),'ydata',imag(cir))
zz=roots(hn);
%After evaluating zz
i=find(max(abs(zz))>1e4);zz(i)=[];
set(z_line,'xdata',real(zz),'ydata',imag(zz));
set(ui(30:34),'vis','off');
if ~isempty(zz)
[z,m]=msort(zz);
i=find(m>1);
if ~isempty(i)
li=length(i);l=min(3,li);
set(ui(30:31),'vis','on');
for j=1:l
p=i(j);rt=z(p);mult=int2str(m(p));
rrt=num2str(real(rt),3);if eval(rrt)==0,rrt=[];end
irt=num2str(abs(imag(rt)),3);
if eval(irt)==0,irt=[];else,irt=['+j' irt];end
str=[rrt irt];if isempty(str),str='0';end
if ~isempty(irt), str=[str ' & Conj'];end
set(ui(31+j),'vis','on','string',[mult ' @ ' str]);
end
if li>3
k=li-2;
set(ui(34),'vis','on','string',[int2str(k) ' more sets of multiple zeros']);
end
end
end
pp=roots(hd);
rmin=min([real(pp);real(zz);-1]);rmax=max([real(pp);real(zz);1]);
imin=min([imag(pp);imag(zz);-1]);imax=max([imag(pp);imag(zz);1]);
%set(pz_axes,'xlim',[rmin, rmax],'ylim',[imin, imax]);
%After evaluating rmax,imax etc
maxx=max(abs([rmax,imax,rmin,imin]));
set(pz_axes,'xlim',[-maxx, maxx],'ylim',[-maxx, maxx]);
set(p_line,'xdata',real(pp),'ydata',imag(pp));
set(ui(37:41),'vis','off');
if ~isempty(pp)
[z,m]=msort(pp);
i=find(m>1);
if ~isempty(i)
li=length(i);l=min(3,li);
set(ui(37:38),'vis','on');
for j=1:l
p=i(j);rt=z(p);mult=int2str(m(p));
rrt=num2str(real(rt),3);if eval(rrt)==0,rrt=[];end
irt=num2str(abs(imag(rt)),3);
if eval(irt)==0,irt=[];else,irt=['+j' irt];end
str=[rrt irt];if isempty(str),str='0';end
if ~isempty(irt), str=[str ' & Conj'];end
set(ui(38+j),'vis','on','string',[mult ' @ ' str]);
end
if li>3
k=li-2;
set(ui(41),'vis','on','string',[int2str(k) ' more sets of multiple poles']);
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -