📄 f_pzplot.asv
字号:
function pos = f_pzplot (b,a,caption)
%F_PZPLOT: Construct plot showing transfer function poles and zeros
%
% H(z) = b(z)/a(z)
%
% Usage: pos = f_pzplot (b,a,caption);
%
% Descripion: Plot the poles and zeros of the linear discrete-time system
%
% On entry: b = vector containing numerator coefficients
% a = vector containing denominator coefficients
% caption = plot title
%
% On exit: pos = 1 by 4 position vector of pole-zero plot
%-----------------------------------------------------------------------------------
% Find poles and zeros
pole = roots(a);
zero = roots(b);
r = length(zero) - length(pole);
if r > 0
pole = [pole ; zeros(r,1)];
elseif r < 0
zero = [zero ; zeros(-r,1)];
end
np = length(pole);
nz = length(zero);
% Look for pole-zero cancellation
cancel = 1;
while cancel == 1
cancel = 0;
for i = 1 : np
for j = 1 : nz
dist = abs(zero(j)-pole(i));
if dist < 1.e-6
cancel = 1;
pole = [pole(1:i-1) ; pole(i+1:np)];
np = length(pole);
zero = [zero(1:j-1) ; zero(j+1:nz)];
nz = length(zero);
break;
end
end
if cancel == 1
break
end
end
end
% Plot poles and zeros
phi = linspace(0,2*pi,361);
x0 = cos(phi);
y0 = sin(phi);
hold off
box off
plot(x0,y0,'k',[-2 2],[0 0],'k',[0 0],[-2 2],'k')
axis square
hold on
for i = 1 : np
plot(real(pole(i)),imag(pole(i)),'rx')
end
for i = 1 : nz
plot(real(zero(i)),imag(zero(i)),'ro')
end
xmax = max(abs(get(gca,'Xlim')));
ymax = max(abs(get(gca,'Ylim')));
range = max(xmax,ymax);
axis([-range range -range range])
plot([-range range],[0 0],'k',[0 0],[-range range],'k')
% Labels
set (gca,'FontSize',9)
f_labels ('','Re(z)','Im(z)')
if (nargin < 3)
f_labels ('Pole-Zero Plot','Re(z)','Im(z)')
else
f_labels (caption,'Re(z)','Im(z)')
end
pos = get(gca,'Position');
%-----------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -