【正确答案】下面给出的函数dir2par将直接系数和转化为并联系数:
function [C,B,A]=dir2par(b,a);
程序如下:
/%DIRECT-form tO ARALLEL-form conyersion
/%-------------------------
/%[C,B,A]=dir2par(b,a);
/%C=Polynomial part when length(b)>=length(a)
/%B=K by 2 matrix of real coefficients containing bk's
/%A=K by 3 matrix of real coefficients containing ak's
/%b=number polynomial coefficients of DIRECT form
/%a=denomirnator polynomial coefficients of DIRECT form
/%
M=length(b);N=length(a):
[r1,p1,C]=residuez(b,a);
p=cplxpair(p1,10000000*eps);
I=cplxcomp(1l,p);
R=r1(I):
K=floor(N/2);B=zero(K,2);A=zero(K,3);
If K*2==N;/%N even,order of A(z)odd,one factor is first order
fori=1: 2:N-2
Brow=r(i: 1: i+1,: );
Arow=p(i: 1: i+1,: );
[Brow,Arow]=residuez(r(N-1),p(N-1),[]);
B(K,: )=[real(Brow) 0]; A(K,: )=[real(Arow) 0];
else
for i=1: 2:N-1
Brow=r(i: 1: i+1. : );
Arow=p(i: 1: i+1. : );
[Brow, Arow] = residuez(Brow, Arow, []) ;
B(fix((i+2)/2) ,: )=real(Brow) ;
A(fix((i+2)/2) ,: )=real(Arow) ;
end
end
function I = cplxcomp( p1, p2 )
/%I= cplcomp ( p1, p2 )
/%Compares two complex pairs which contain the same scalar elements
/%but(possibly) at different indices. This routine shoule be
/%used after CPLXPAIR routine for rearranging pole vector and its corresponding residue /%vector.
corresponding residue vector.
/%P2 = cplxpairz( p1 )
I=[];
for j=1: 1: length(p2)
If(abs(pl(i) - p2(j) ) <0.0001
I[I, i] ;
end
end
end
I=I';
>>b=[1 -3 11 -27 18];
>>a=[16 12 2 -4 -I];
>>[C, B, A] = dir2par(b, a)
C=
-18
B=
10.500 -3.9500
28.1125 -13.3625
A=
1.0000 1.0000 0.5000
1.0000 -0.2500 -0.1250
下面给出的函数dir2cas将直接系数化为级联系数
/%function[b0, B, A] = dir2cas( b, a) ;
/%DIRECT-form to CASCADE- form conversion(cplxpair version)
/%------------------
/%[b0, B, A] = dir2cas ( b, a)
/%b0 = gain coefficient
/%B=K by 3 matrix of real coefficients containing bk's
/%A=K by 3 matrix of real coefficients containing ak's
/%b= numerator polynomial coefficients of DIRECT form
/%a= denominator polynomial coefficients of DIRECT form
/%compute gain coefficient b0
b0=b(1) ; b= b/b0;
a0--a(1); a=a/a0:
b0 = b0/a0 ;
/%
M=length(b) ; N=length(a);
if M>N
b=[b zeros(1,N-M)]; N=M;
elseif M>N
a=[a zeros(1,M-N)]; N=M;
else
NM=0;
end
/%
K=floor(N/2) ; B=zeros(K,3) ; A=zeros(K,3) ; A=zeros(K,3) ;
if K*2=N;
b=[b 0];
a=[a 0];
end
/%
broots = cplxpair( roots (b) ) ;
broots= cplxpair(roots(a) ) ;
for i=1: 2: 2*K
Brow= broots( i: 1: i+1,: );
Brow= real( poly(Brow));
B(fix((i+1)/2),: )= Brow;
Arow=aroots(i: 1: i+1,: );
Arow = real ( poly(Arow) ) ;
A(fix(i+1/2),: )= Arow;
end
MATLAB脚本
>>b=[1 -3 11 -27 18];
>>a=[l6 12 2 -4 -1 ];
>>[b0,B,A]=dircas(b,a)
b0=0.0625
B=
1.0000 -0.0000 9.0000
1.0000 -3.0000 2.0000
A=
1.0000 1.0000 0.5000
1.0000 -0.2500 -0.1250
【答案解析】