MAXIMALLY FLAT FIR FILTERS This section describes a family of

advertisement

MAXIMALLY FLAT FIR FILTERS

This section describes a family of maximally flat symmetric FIR filters first introduced by Herrmann [2]. The design of these filters is particularly simple due to the availability of closed form solutions. In addition, they can be implemented efficiently using certain hardware architectures. The derivation of the maximally flat filters by Herrmann begins with a transformation of the problem using a change of variables.

A CHANGE OF VARIABLES

The following change of variables is used to convert a Type I linearphase transfer function H ( z ) into a polynomial P ( x ) . The values of P ( x ) for real values of x between 0 and 1 will give the values of

H ( z ) for complex values of z on the unit circle.

To describe the change of variables we begin with a polynomial

P ( x ) of degree M .

P ( x ) = p

0

+ p

1 x + p

2 x

2

+ · · · + p

M x

M

=

M

X p m x m m =0

The change of variables, used to obtain a Type I FIR filter, is given by, x =

− z + 2 − z

− 1

.

4

(1)

I. Selesnick EL 713 Lecture Notes 1

Using this transformation, we obtain the following transfer function

H ( z ) .

H ( z ) = P

− z + 2 − z

− 1

4

(2)

=

M

X p m

− z + 2 − z

− 1 m

(3)

4 n =0

The filter will be a Type I FIR filter. The symmetric impulse response h ( n ) will be of length N = 2 M + 1 ; h ( n ) will be supported on − M ≤ n ≤ M . For example, if

P ( x ) = 2 − 9 x + 13 x

2 − 6 x

3

(4) then

1

H ( z ) =

32

3 z

3

+ 8 z

2

+ 13 z + 16 + 13 z

− 1

+ 8 z

− 2

+ 3 z

− 3

.

(5) and h ( n ) =

1

32

{ 3 , 8 , 13 , 16 , 13 , 8 , 3 } where 16 represents h (0) . The following Matlab program x2z converts the polynomial coefficients p n to filter coefficients h ( n ) . The program is based directly on equation (3).

function h = x2z(p)

N = length(p); h = p(1); g = 1; for k = 2:N g = conv(g,[-1 2 -1]/4); h = [0 h 0] + p(k)*g; end

This program assumes that the coefficients of the polynomial P ( x ) are ordered in increasing powers (this is contrary to the Matlab convention for polynomials).

I. Selesnick EL 713 Lecture Notes 2

>> p = [2 -9 13 -6];

>> h = x2z(p);

>> h*32 ans =

3 8 13 16 13 8 3

The frequency response of the filter H ( z ) can be directly related to P ( x ) by noting the following identity.

− z + 2 − z

− 1

4 z = e jω

=

1

2

1

4

( e jω

+ e

− jω

)

=

1

2

1

2 cos( ω )

Now the frequency response of the filter is given by evaluating P ( x ) appropriately.

H f

( ω ) := H ( e jω

)

= P

1

2

1

2 cos( ω )

Therefore, the frequency response of the filter obtained via (2) is similar to the graph of P ( x ) . The only difference is a warping of the independent variable, given by, x =

1

2

1

2 cos( ω ) .

This warping is shown in the following figure for 0 ≤ ω ≤ π .

(6)

I. Selesnick EL 713 Lecture Notes 3

1

0.8

0.6

0.4

0.2

0

0 0.25

π

0.5

π

0.75

π

ω

π

Note that x and ω have the corresponding values:

0 ≤ ω ≤ 1 ↔ 0 ≤ x ≤ 1

ω = 0 ↔ x = 0

ω = π ↔ x = 1

For the polynomial P in (4), the graph of P ( x ) and the frequency response H f ( ω ) are shown in the following figure.

2

1.5

1

0.5

0

−0.5

0 0.1

0.2

0.3

0.4

0.5

x

0.6

0.7

0.8

0.9

1

2

1.5

1

0.5

0

−0.5

0 0.1

0.2

0.3

0.4

0.5

ω

/

π

0.6

0.7

0.8

0.9

1

Notice that the frequency warping is most pronounced near the endpoints of the interval [0 , 1] .

I. Selesnick EL 713 Lecture Notes 4

We can also transform any Type I FIR filter into a polynomial, by reversing the procedure. The following Matlab program z2x performs the reverse transformation.

function p = z2x(h)

N = length(h);

M = (N-1)/2;

P = []; g = 1; for k = 1:M end g = conv(g,[-1 2 -1]/4); for k = 0:M

[q,r] = deconv(h,g); p(M+1-k) = q; h = r(2:end-1); end g = deconv(g,[-1 2 -1]/4);

We can illustrate that the programs z2x and x2z are inverses of one another as in the following example.

>> % check that z2x(x2z(p)) gives p

>> p = [35 19 43 43 30];

>> z2x(x2z(p)) ans =

35 19 43 43 30

>> % check that x2z(z2x(h)) gives h

>> h = [-3 25 -93 244 -93

>> x2z(z2x(h)) ans =

-3 25 -93 244 -93 25

25

-3

-3];

I. Selesnick EL 713 Lecture Notes 5

MAXIMALLY FLAT TYPE I FIR FILTERS

A maximally flat Type I FIR filter is a filter of minimal length satisfying the constraints:

H f

(0) = 1 d i H f ( ω ) dω i

ω =0 d i H f ( ω ) dω i

ω = π

= 0 , i = 1 , . . . , 2 L + 1

= 0 , i = 0 , . . . , 2 K − 1

(7)

(8)

(9)

Note that the odd derivatives of H f ( ω ) are automatically zero at

ω = 0 and ω = π for Type I filters. These derivative constraints represent a set of linear equations for the filter coefficients h ( n ) . By using the transformation x =

1

2

− 1

2 cos( ω ) the problem of obtaining the solution is simplified. Instead of finding h ( n ) , we can instead find a polynomial P ( x ) which can be converted into a Type I FIR filter. In this case, the problem is to find a polynomial P ( x ) of minimal degree satisfying the constraints:

P

P

P

( i )

(0) = 0 , i = 1 , . . . , L

( i )

(0) = 1

(1) = 0 , i = 0 , . . . , K − 1

Equivalently, P ( x ) can be factored as

P ( x ) = A ( x ) (1 − x )

K

(10)

(11)

(12)

(13) and 1 − P ( x ) can be factored as

1 − P ( x ) = B ( x ) x

L +1

.

I. Selesnick EL 713 Lecture Notes

(14)

6

Combining (13) and (14), we have

1 = A ( x ) (1 − x )

K

+ B ( x ) x

L +1

.

(15)

One method for obtaining the polynomials A ( x ) and B ( x ) of minimal degree is to use the extended Euclidean algorithm for polynomial GCDs. From the Euclidean algorithm, it is known that the degrees of A ( x ) and B ( x ) are L and K − 1 respectively. Therefore, the degree of P ( x ) is L + K .

Another method to obtain A ( x ) and B ( x ) is to rewrite (15) as

A ( x ) =

1 − B ( x ) x L +1

.

(1 − x ) K and to then write 1 / (1 − x ) K as a Taylor series around x = 0

1

(1 − x ) K

=

X c n x n

.

n =0

We then have

A ( x ) = 1 − B ( x ) x

L +1

X c n x n

.

n =0

Because the degree of A ( x ) is L , it must be given by

A ( x ) =

L

X c n x n

.

n =0

A formula for the constants c n is given by the binomial theorem.

The binomial theorem states that

( a + b )

K

=

X n

K n a

K − n where the binomial coefficient is defined as b n

K n

K !

=

( K − n )!

n !

(16)

I. Selesnick EL 713 Lecture Notes 7

for K ≥ 0 , n ∈ Z . If K is negative, we can still use the binomial theorem, but we need to know how to extend binomial coefficients to negative values of K . The following identity specifies how binomial coefficients can be evaluated when the upper entry is negative

[1].

− K n

= ( − 1)

Using this identity in (16) we get n

K + n n

− 1

1

( a + b ) K

=

X n

1

= a K n

− K n a

− K − n

X

( − 1) n

K b n

+ n n

− 1 b a n

Setting a = 1 and b = − x , we get an expression for 1 / (1 − x ) K .

1

(1 − x ) K

=

X

( − 1) n n

=

X n

K +

K + n − 1 n n x

− n

.

1 n

( − x ) n

(17)

(18)

Therefore,

A ( x ) =

L

X n =0

K + n n

− 1 x n and

P ( x ) = (1 − x )

K

L

X n =0

K + n n

− 1 x n

.

(19)

Using the change of variables (1), we obtain the transfer function

H ( z ) = z + 2 + z

− 1

4

K L

X n =0

K + n − 1 − z + 2 − z

− 1 n 4 n

.

I. Selesnick EL 713 Lecture Notes 8

Notice that we never determined B ( x ) . It was not needed.

With the identities, z + 2 + z

− 1 z = e jω

ω 2

4

− z + 2 − z

− 1

= cos

2

ω

4 z = e jω

= sin

2 the frequency response H ( e jω ) can be written as

2

,

H ( e jω

) = cos

ω

2

2 K

L

X

K + n − 1 n sin

ω

2

2 n

.

n =0

The following pseudo program computes the impulse response h ( n ) .

Q ( z ) ← 1

H ( z ) ← 1 for n from 1 to L

Q ( z ) ← Q ( z )

H ( z ) ← H ( z ) +

− z + 2 − z

− 1

4

K + n − 1 n

Q ( z ) end for k from 1 to K

H ( z ) ← H ( z ) z + 2 + z

− 1

4 end

If we call c n

= by

K + n − 1 n

, we can note that the ratio c n

/c n − 1 is given c n c n − 1

=

( K + n − 1)!

· n ! ( K − 1)!

( n − 1)! ( K − 1)!

=

( K + n − 2)!

K + n − 1

.

(20) n

I. Selesnick EL 713 Lecture Notes 9

Therefore, the pseudo program can be modified to include the binomial coefficient computation, as follows.

Q ( z ) ← 1

H ( z ) ← 1 c ← 1 for n from 1 to L

Q ( z ) ← Q ( z )

− z + 2 − z

− 1

4 c ← c · ( K + n − 1) /n

H ( z ) ← H ( z ) + c · Q ( z ) end for k from 1 to K

H ( z ) ← H ( z ) z + 2 + z

− 1

4 end

The following Matlab program maxflatI implements the pseudo program. The vector h is the impulse response of the filter.

function h = maxflatI(K,L) h = 1; q = 1; c = 1; for n = 1:L q = conv(q,[-1 2 -1]/4); c = c*(K-1+n)/n; end h = [0 h 0] + c*q; for k = 1:K end h = conv(h,[1 2 1]/4);

I. Selesnick EL 713 Lecture Notes 10

Example When K = 3 , L = 5 , the impulse response h ( n ) , frequency response magnitude | H f ( ω ) | , and zero diagram are as shown. Notice that exactly 2 L zeros that contribute to the shape of the passband, and exactly 2 K zeros are located at z = − 1 .

MAXIMALLY FLAT TYPE I FIR FILTER

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0

−0.1

0 2 4 6 8 10 12 14 16

1.2

1

0.8

0.6

0.4

0.2

0

0 0.1

0.2

0.3

0.4

0.5

ZERO DIAGRAM

0.6

2

1

0

−1

−2

−4 −2

6

0 2 4

0.7

0.8

0.9

6

1

I. Selesnick EL 713 Lecture Notes 11

General Stopbands

The procedure used to obtain maximally flat passbands can be modified to include zeros located at points other than z = − 1 . For example, suppose it is desired that H f

( ω s

) = 0 where the ω s is a specified frequency in the stopband. The resulting filter will be maximally flat in the passband, but not in the stopband. We can again construct a polynomial P ( x ) which can then be converted into a Type I FIR filter. Modifying the constraints on P ( x ) , we have

P ( x ) = A ( x ) (1 − x )

K − 1

( x s

− x ) where x s

=

1

2

1

2 cos ω s and A ( x ) is a polynomial (of degree L ) to be determined. As before, the derivative constraints at x = 0 can be included by the condition that 1 − P ( x ) factors as

1 − P ( x ) = B ( x ) x

L +1

.

Combining, we have

1 = A ( x ) (1 − x )

K − 1

( x s

− x ) + B ( x ) x

L +1 or

A ( x ) =

(1

1 − B ( x ) x

L +1

− x ) K − 1 ( x s

− x )

.

If we know the Taylor series of 1 / [(1 − x ) K − 1 ( x s

− x )] around x = 0 ,

1

(1 − x ) K − 1 ( x s

− x )

=

X f n x n

, n =0

I. Selesnick EL 713 Lecture Notes 12

then we can write, as before,

A ( x ) = 1 − B ( x ) x

L +1

X f n x n

= n =0

X f n x n − B ( x ) x

L +1

X f n x n

.

n =0 n =0

Because we know that the polynomial A ( x ) if of degree L , and because the second term contains terms of powers greater than L only, A ( x ) must be given by

A ( x ) =

L

X f n x n n =0

(21) and P ( x ) is given by

P ( x ) = (1 − x )

K − 1

( x s

− x )

L

X f n x n

.

n =0

To find the Taylor series expansion of 1 / [(1 − x ) K − 1 ( x s

− x )] we can use

1

(1 − x ) K − 1

=

X c n x n

, n =0 c n

=

K + n n

− 2 and

1 x s

− x

=

X d n x n

, n =0 d n

= x

1 s n +1 to write

1

(1 − x ) K − 1

1

· x s

− x

=

X c i x i ·

X d j x j i =0 j =0

=

X

" n

X c m − n d n

# x n n =0

| m =0

{z f n

}

I. Selesnick EL 713 Lecture Notes 13

Therefore, we can find the coefficients f n by convolving c n and d n

, f n

= c n

∗ d n

.

In (21) we only need f n for 0 ≤ n ≤ L . To compute f n over this range, we must compute c n

, d n for 0 ≤ n ≤ L also. The convolution of those two finite-length sequences will be of length

2 L + 1 . The values f n are obtained by truncation down to length

L + 1 .

Example The following Matlab program implements this procedure where we use K = 3 , L = 5 as in the previous example. The frequency ω s is taken to be ω s

= 0 .

7 π here.

K = 3;

L = 5; ws = 0.7*pi; xs = 1/2 - cos(ws)/2; n = 0:L; c = binom(K+n-2,n); d = (1/xs).^(n+1); f = conv(c,d); a = f(1:L+1); k = 0:K-1; p = conv(a,binom(K-1,k).*(-1).^k); p = conv(p,[xs -1]); h = x2z(p);

The following figures illustrate the results. It can be seen that there are 2( K − 1) zeros at z = − 1 and 2 L zeros corresponding to the passband.

I. Selesnick EL 713 Lecture Notes 14

TYPE I FIR FILTER (MAXIMALLY FLAT PASSBAND)

0.6

0.5

0.4

0.3

0.2

0.1

0

−0.1

0 2 4 6 8 10 12 14 16

0.6

0.4

0.2

0

0

1.2

1

0.8

0.1

0.2

0.3

2

1

0

−1

4

−2

−4 −3 −2 −1 0

0.4

0.5

ZERO DIAGRAM

0.6

1 2 3

0.7

4 5

0.8

6

0.9

1

This procedure is quite general. It calls only for the Taylor series expansion of a certain function (associated with the stopband). The program binom , for computing binomial coefficients, is given at the end of these notes.

I. Selesnick EL 713 Lecture Notes 15

And General Passbands

In addition to specified zeros in the stopband, it may be desired that a flat filter have points of unity gain in the passband, at frequencies other than ω = 0 . For example, we might want 1 − H f ( ω ) to have a double root at a frequency ω p

. In this case we can write the condition as

1 − P ( x ) = B ( x ) x

L − 1

( x p

− x )

2 where x p

=

1

2

1

2 cos ω p

.

In this condition, we have reduced the degree of flatness at x = 0 correspondingly.

Placing a zero at x s as in the previous section, we have again

P ( x ) = A ( x ) (1 − x )

K − 1

( x s

− 1) .

Combining, we have

1 = A ( x ) (1 − x )

K − 1

( x s

− 1) + B ( x ) x

L − 1

( x p

− x )

2

.

The procedure described before will not work here, so lets compute

A ( x ) and B ( x ) together by solving a linear system of equations.

Defining,

R ( x ) := (1 − x )

K − 1

( x s

− 1)

S ( x ) := x

L − 1

( x p

− x )

2

,

(22)

(23) we have:

1 = A ( x ) R ( x ) + B ( x ) S ( x ) .

I. Selesnick EL 713 Lecture Notes 16

We can write this in terms of matrices as

1

0

...

...

=

0

 r

0

... ...

...

 r

K

. . .

|{z} e

| {z

R r

K

 r

0

...

...

 a

0

...

 a

L

+

 s

0

...

. . .

...

 s

L +1

. . .

} | {z

S

 s

...

...

0 s

L +1

 b

K − 1

 b

0

...

} or h

R S i

" a

#

= e .

b

This is a square system of equations, so we can solve for A ( x ) and

B ( x ) directly.

Example The following Matlab program implements this procedure, with ω p

= 0 .

5 π and ω s

= 0 .

75 π , K = 3 and L = 5 . The resulting filter is shown in the figure.

K = 3;

L = 5; wp = 0.5*pi; ws = 0.75*pi; xp = 1/2 - cos(wp)/2; xs = 1/2 - cos(ws)/2; r = conv(binom(K-1,0:K).*(-1).^(0:K),[xs -1]); r = r(1:K+1); s = [zeros(1,L-1) xp^2 -2*xp 1];

R = convmtx(r’,L+1);

S = convmtx(s’,K);

V = [R S];

T = V\[1; zeros(L+K,1)]; a = T(1:L+1)’; b = T(L+2:L+K+1)’;

I. Selesnick EL 713 Lecture Notes 17

p = conv(a,r); h = x2z(p);

TYPE I FIR FILTER

0.8

0.6

0.4

0.2

0

−0.2

0 2 4 6 8 10 12 14 16

1.2

1

0.8

0.6

0.4

0.2

0

0

1.5

1

0.5

0

−0.5

−1

−1.5

0.1

0.2

0.3

0.4

0.5

ZERO DIAGRAM

0.6

0.7

0.8

0.9

4

−3 −2 −1 0 1 2 3 4 5

1

I. Selesnick EL 713 Lecture Notes 18

MAXIMALLY FLAT TYPE II FIR FILTERS

As we have seen, if H

1

( z ) is a Type I transfer function, then H

1 f

( ω ) can be written as

H f

1

( ω ) = P

1

1

2

1

2 cos( ω ) where P

1

( x ) is a polynomial,

P

1

( x ) = p

0

+ p

1 x + · · · + p

M x

M

.

A Type II transfer function H

2

( z ) can always be written as

H

2

( z ) =

1

2

(1 + z

− 1

) H

1

( z ) where H

1

( z ) is a Type I transfer function. Note that

H

2 f

( ω ) =

=

=

1

(1 + e

− jω

2

1

2 e

− jω/ 2 e

) H

1 f jω/ 2

( ω )

+ e

− jω/ 2 e

− jω/ 2 cos( ω/ 2) H

1 f

( ω )

H f

1

(

= e

− jω/ 2 r

1

2

+

1

2 cos( ω ) H

1 f

( ω ) .

ω )

(Note double angle formula.) Now if we define P

2

( x ) as

P

2

( x ) :=

1 − x P

1

( x ) =

1 − x p

0

+ p

1 x + · · · + p

M x

M then

P

2

1

2

1

2 cos( ω ) = r

1

2

+

1

2 cos( ω ) P

1

= r

1

2

+

1

2 cos( ω ) H

1 f

( ω )

= e jω/ 2

H

2 f

( ω )

1

2

1

2 cos( ω )

I. Selesnick EL 713 Lecture Notes 19

Therefore,

H

2 f

( ω ) = e

− jω/ 2

1 − x P

1

( x ) (24) where x =

1

2

1

2 cos( ω ) .

Therefore, to obtain a maximally flat Type II FIR filter H

2 first obtain a polynomial P

1

( x ) such that P

2

( x ) =

( z ) we can

1 − x P

1

( x ) is maximally flat, and then convert P

1

( x ) to H

1

( z ) and set H

2

( z ) =

1

2

(1 + z

− 1 ) H

1

( z ) . In this case, the problem is to find a polynomial

P

1

( x ) of degree L + K satisfying the constraints,

(25)

(26)

(27)

P

2

(0) = 1

P

2

( i )

(0) = 0 , i = 1 , . . . , L

P

2

( i )

(1) = 0 , i = 0 , . . . , K where

P

2

( x ) =

1 − x P

1

( x ) .

Equivalently, P

2

( x ) can be factored as

P

2

( x ) = A ( x )

1 − x (1 − x )

K and 1 − P

2

( x ) can be factored as

1 − P

2

( x ) = B ( x ) x

L +1

, where A ( x ) is a polynomial of degree L . Combining the conditions, we have

1 = A ( x )

1 − x (1 − x )

K

+ B ( x ) x

L +1 or

A ( x ) =

1 − B ( x ) x L +1

.

(1 − x ) K +

1

2

I. Selesnick EL 713 Lecture Notes 20

If we write 1 / (1 − x )

K + 1

2 as a Taylor series around x = 0 ,

1

(1 − x ) K +

1

2

=

X c n x n n =0 then we have

A ( x ) = 1 − B ( x ) x

L +1 n =0

=

L

X c n x n

+ higher terms .

n =0

X c n x n

Since A ( x ) is of degree L , we have

A ( x ) =

L

X c n x n n =0 and

P

1

( x ) = (1 − x )

K

L

X c n x n

.

n =0

It only remains to find the values c n in the Taylor expansion of

1 / (1 − x ) K +

1

2

. We can use the equation (18) again, with K +

1

2 in place of K ,

1

(1 − x ) K +

1

2

=

X n

K +

Then we have

P

2

( x ) =

1 − x (1 − x )

K X n

1

2

+ n − 1 n

K +

1

2 x n

.

+ n − 1 n and x n

H

2

( z ) =

1

2

(1+ z

− 1

) z + 2 +

4 z

− 1

K L

X n =0

K +

1

2

+ n − 1 − z + 2 − z

− 1 n 4 n

.

I. Selesnick EL 713 Lecture Notes 21

To evaluate the binomial coefficient for fractional values of the upper entry, we can use the Gamma function Γ .

The Gamma function interpolates the factorial function on the integers,

Γ( n + 1) = n !

for n ∈ Z , so we have

K +

1

2

+ n − 1 n

=

Γ(

Γ( K +

K +

1

+ n )

2

1

2

) Γ( n + 1)

.

The Gamma function also satisfies

Γ( α + 1) = α Γ( α ) , so if we define c ( n ) := c ( n ) /c ( n − 1) as

K +

1

2

+ n n − 1 then we can write the ratio c ( n ) c ( n − 1)

=

Γ(

Γ( K +

K + 1

2

1

2

+ n )

) Γ( n + 1)

·

Γ( K

Γ( K +

+

1

2

1

2

) Γ( n )

+ n − 1)

=

K +

1

2

+ n − 1

.

n

Also note that c (0) = 1 (using the Taylor series rule for c (0) ). With the rule c ( n ) =

K + n − 1

2 n

· c ( n − 1) (28) for n > 0 we can then compute the values c ( n ) which are needed.

The following pseudo program computes H

2

( z ) . Note the similarity with the pseudo program for the design of maximally flat Type I

I. Selesnick EL 713 Lecture Notes 22

filters.

Q ( z ) ← 1

H

2

( z ) ← 1 c ← 1 for n from 1 to L

Q ( z ) ← Q ( z )

− z + 2 − z

− 1

4 c ← c · ( K + n − 1 / 2) /n

H

2

( z ) ← H

2

( z ) + c · Q ( z ) end for k from 1 to K

H

2

( z ) ← H

2

( z ) z + 2 + z

− 1

4 end

H

2

( z ) ←

1

2

(1 + z

− 1

) H

2

( z )

The following Matlab program maxflatII implements the pseudo program. The vector h is the impulse response of the filter.

function h = maxflatII(K,L) h = 1; q = 1; c = 1; for n = 1:L q = conv(q,[-1 2 -1]/4); c = c*(K-1/2+n)/n; h = [0 h 0] + c*q; end for k = 1:K h = conv(h,[1 2 1]/4); end h = conv(h,[1 1]/2)

I. Selesnick EL 713 Lecture Notes 23

Example When K = 3 , L = 5 , the impulse response h ( n ) , frequency response magnitude | H

2 f

( ω ) | , and zero diagram are as shown. Notice that exactly 2 L zeros that contribute to the shape of the passband, and exactly 2 K + 1 zeros are located at z = − 1 .

MAXIMALLY FLAT TYPE II FIR FILTER

0.6

0.5

0.4

0.3

0.2

0.1

0

−0.1

0 2 4 6 8 10 12 14 16 18

2

1

0

−1

−2

1.2

1

0.8

0.6

0.4

0.2

0

0 0.1

0.2

0.3

0.4

0.5

ZERO DIAGRAM

0.6

0.7

0.8

0.9

1

7

−4 −2 0 2 4 6

I. Selesnick EL 713 Lecture Notes 24

A PROGRAM FOR BOTH TYPE I AND TYPE II FILTERS

Notice that the programs maxflatI and maxflatII are very similar. With a slight modification, a single program can be written to handle both Type I and Type II filters.

Let us denote the number of zeros at z = − 1 by Z

π

. The maximally flat Type I FIR filter described above has Z

π

= 2 K zeros at z = − 1 .

That is, K = Z

π

/ 2 . Therefore, the rule (20) for computing the values c ( n ) c ( n ) =

K + n − 1 n c ( n − 1) can be written as c ( n ) =

Z

π

/ 2 + n − 1 n c ( n − 1) .

(29)

On the other hand, the maximally flat Type II FIR filter has Z

π

=

2 K + 1 zeros at z = − 1 . That is, K = Z

π

/ 2 − 1 / 2 . Therefore, the rule (28) for computing the values c ( n ) c ( n ) =

K + n − 1 / 2 n c ( n − 1) can be written as c ( n ) =

Z

π

/ 2 + n − 1 n c ( n − 1) .

(30)

Because equations (29) and (30) are the same when the parameter

Z

π is used, the two programs maxflatI and maxflatII can be combined into a single program. The following program symflat handles both Type-I and Type-II maximally flat FIR filters.

I. Selesnick EL 713 Lecture Notes 25

function h = symflat(Zpi,L)

% Maximally flat FIR filter (Type-I and II)

% 1) Zpi zeros at z=-1

% 2) 2L zeros away from z=-1

% 3) length(h) = Zpi+2L+1

% 4) If Zp = 2L+2, then h is halfband h = 1; q = 1; c = 1; for n = 1:L q = conv(q,[-1 2 -1]/4); c = c*(Zpi/2-1+n)/n; end h = [0 h 0] + c*q; for k = 1:Zpi h = conv(h,[1 1]/2); end

I. Selesnick EL 713 Lecture Notes 26

Appendix: A Program for Binomial Coefficients

The following program for computing the binomial coefficients allows n and k to be scalars or vectors.

n k function a = binom(n,k)

%

% a = binom(n,k)

% BINOMIAL COEFFICIENTS

%

%

%

%

% allowable inputs:

% n : integer, k : integer

% n : integer vector, k : integer n : integer, k : integer vector n : integer vector, k : integer vector (of equal dimension) nv = n; kv = k; if (length(nv) == 1) & (length(kv) > 1) nv = nv * ones(size(kv)); elseif (length(nv) > 1) & (length(kv) == 1) kv = kv * ones(size(nv)); end a = nv; for i = 1:length(nv) n = nv(i); k = kv(i); if n >= 0 if k >= 0 if n >= k c = prod(1:n)/(prod(1:k)*prod(1:n-k)); else c = 0; end else c = 0; end else if k >= 0 c = (-1)^k * prod(1:k-n-1)/(prod(1:k)*prod(1:-n-1)); else if n >= k

I. Selesnick EL 713 Lecture Notes 27

c = (-1)^(n-k)*prod(1:-k-1)/(prod(1:n-k)*prod(1:-n-1)); else end end c = 0; end end a(i) = c;

I. Selesnick EL 713 Lecture Notes 28

REFERENCES REFERENCES

References

[1] R. L. Graham, D. E. Knuth, and O. Patashnik.

Concrete Mathematics: A Foundation for

Computer Science . Addison-Wesley Publishing Co., 1994.

[2] O. Herrmann. On the approximation problem in nonrecursive digital filter design.

IEEE

Trans. on Circuit Theory , 18(3):411–413, May 1971. Also in [ ?

].

I. Selesnick EL 713 Lecture Notes 29

Download