📄 s2zmatch.m
字号:
function [n,d,g1]=s2zmatch(n1,d1,sf,ty,w)
% S2ZMATCH Convert H(s) to H(z) using matched z-Transform
%
% [NUMz,DENz,G]=S2ZMATCH(NUMs,DENs,SF,TY,FM)
% Converts H(s) to H(z) using the matched z-transformation
% For H(s), NUMs and DENs are in descending powers of s
% SF = sampling frequency, SF, in HERTZ.
% TY determines the s2z mapping rule as follows (DEFAULT TY='2'):
% TY = '0', Numerator term z^N is kept in tact.
% TY = '1', Numerator term z^N is replaced by (z+1)^N.
% TY = '2', Numerator term z^N is replaced by (z+1)^(N-1).
% FM= OPTIONAL frequency (Hz) at which gain of H(z) and H(s) is matched.
% FM = [FA, FD] specifies analog and digital match frequencies in HERTZ.
% NUMz and DENz return numerator and denominator of H(z)
% G is the gain such that DC gain of G*H(z) matches H(s) (if nonzero).
%
% S2ZMATCH (with no input arguments) invokes the following example:
%
% % Transform H(s)=2/(s+2) with sf=10Hz and match frequency of 3Hz
% % and plot/compare H(z) and H(s)
% >>[nr,dr] = s2zmatch(2,[1 2],10,'0',3)
% >>[h1 p1 f1]=tfplot('s',2,[1 2],[0 10]);
% >>[h2 p2 f2]=tfplot('z',nr,dr,[0 0.5]);plot(f1/sf,h1,f2,h2)
% 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
if nargin==0,help s2zmatch,disp('Strike a key to see results of the example')
pause,[nr,dr,gr]=s2zmatch(2,[1 2],10,'0',3)
[h1 p1 f1]=tfplot('s',2,[1 2],[0 10]);[h2 p2 f2]=tfplot('z',nr,dr,[0 0.5]);
vx=matverch;
if vx < 4, eval('clg');else,eval('clf');end
plot(f1/10,h1,f2,h2),grid,return,end
if nargin<5,w=[];end,
if nargin<4,ty='2';end,
if nargin<3,sf=1;end,
t=1/sf;
while abs(n1(1))<50*eps,n1(1)=[];end,
while abs(d1(1))<50*eps,d1(1)=[];end
mm=length(n1);nn=length(d1);
l=nn-mm;g0=n1(1)/d1(1);n2=n1;d2=d1;
if ~isempty(w),fa=w(1);
if length(w)>1,fd=w(2);else,fd=fa;end,
if 2*t*fd>=1,error('Digital match freq. exceeds 0.5fsamp'),return,end
fd1=fd/sf;
if fa>0,fn=fd1/fa;
if fn~=1,[n1,d1]=lp2af('lp',n1,d1,fn);sf=1;t=1;end
end
end
p=roots(d1);z=[];
if mm>1,z=roots(n1);end,
p=exp(p*t);
if mm>0,z=exp(z*t);end
% You could replace the above 4 lines with
%p=exp(roots(d1));z=exp(roots(n1));
if ty=='0',z=[zeros(l,1);z];else,z=[-ones(l,1);z];end
if ty=='2',if l>0,z(1)=[];end,end
n=real(poly(z));d=real(poly(p));
if ~isempty(w),
j=sqrt(-1);
w2=j*2*pi*fa;gc=abs(polyval(n2,w2)./polyval(d2,w2));
w1=exp(j*2*pi*fd1);gd=abs(polyval(n,w1)./polyval(d,w1));
g0=gc/gd;n=g0*n;
end
gc=abs(polyval(n2,0)./polyval(d2,0));
if sum(d)~=0,gd=abs(sum(n)/sum(d));
if gd~=0,g1=gc/gd;end
end
ln=length(n);ld=length(d);n=[zeros(1,ld-ln) n];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -