1 function [tg,fr]=group(npts,a1i,a2i,b1i,b2i)
2 //Calculate the group delay of a digital filter
3 //with transfer function h(z).
4 //The filter specification can be in coefficient form,
5 //polynomial form, rational polynomial form, cascade
6 //polynomial form, or in coefficient polynomial form.
7 // npts :Number of points desired in calculation of group delay
8 // a1i :In coefficient, polynomial, rational polynomial, or
9 // :cascade polynomial form this variable is the transfer
10 // :function of the filter. In coefficient polynomial
11 // :form this is a vector of coefficients (see below).
12 // a2i :In coeff poly form this is a vector of coeffs
13 // b1i :In coeff poly form this is a vector of coeffs
14 // b2i :In coeff poly form this is a vector of coeffs
15 // tg :Values of group delay evaluated on the grid fr
16 // fr :Grid of frequency values where group delay is evaluated
18 //In the coefficient polynomial form the tranfer funtion is
19 //formulated by the following expression:
21 // h(z)=prod(a1i+a2i*z+z**2)/prod(b1i+b2i*z+z^2)
24 //author: C. Bunks date: 2 March 1988
27 //get frequency grid values in [0,.5)
29 fr=(0:.5/npts:.5*(npts-1)/npts);
31 //get the of arguments used to called group
35 //if the number of arguments is 2 then
36 //the case may be non-cascade
41 //get the type of h and the variable name
46 //if ht==1 then h is a vector containing filter coefficients
50 //make h a rational polynomial
55 h=gtild(h,'d')*(1/z^(hs-1));
59 //if ht==16 then h is a rational polynomial
60 //(perhaps in cascade form)
62 //-compat ht==15 retained for list/tlist compatibility
68 //if the rational polynomial is not in cascade form then
72 //if ht==2 then h is a regular polynomial
78 //get the derivative of h(z)
82 //get the group delay of h(z)
90 tg=real(freq(tgz(2),tgz(3),rfr));
92 //done with non-cascade calculation of group delay
97 //re-organize if h is in cascade form
100 xc=[coeff(h(2)),coeff(h(3))];
103 b2i=xc(3*hcs+1:4*hcs);
104 b1i=xc(4*hcs+1:5*hcs);
108 //if implementation is in cascade form
112 //a1i,a2i,b1i,b2i are the coefficients of a
113 //second order decomposition of the filter
114 //(i.e. in cascade form, see Deczky)
118 ejw=freq(z,1,exp(%i*phi));
119 emjw=freq(z,1,exp(-%i*phi));
126 emjw=ones(a1i)'*emjw;
128 aterm=(a1+2*ejw)./(a1+ejw+a2.*emjw);
129 bterm=(b1+2*ejw)./(b1+ejw+b2.*emjw);
131 tgi=real(bterm-aterm);
134 //done with cascade calculation of group delay