Вы находитесь на странице: 1из 8

OpenStax-CNX module: m10577 1

Linear-Phase Fir Filter Design By



Least Squares

Ivan Selesnick

This work is produced by OpenStax-CNX and licensed under the


Creative Commons Attribution License 1.0

Abstract
This module describes the design of linear-phase FIR lters based on the square error criterion. It
includes derivation and an example.

1 Linear-Phase FIR Filter Design by Least Squares

This module describes the design of linear-phase FIR lters based on the square error criterion. We will see
that FIR lters that minimize the square error can be found by solving a linear system of equations. This
technique is straight-forward and is applicable to arbitrary desired frequency responses. In addition, linear
constraints on the coecients are easily included.
Linear-phase lter design by least squares has several advantages.
Optimal with respect to square error criterion.
Simple, non-iterative method.
Analytic solutions sometimes possible, otherwise solution is obtained via solution to linear system of
equations.
Allows the use of a frequency dependent weighting function.
Suitable for arbitrary D () and W ().
Easy to include arbitrary linear constraints.

1.1 Derivation

The weighted integral square error (or " L2 error") is dened by


Z
2 =
2
W () (A () D ()) d (1)
0

where
A () : the actual amplitude response
D () : the ideal amplitude response
W () : nonnegative weighting function
Version 2.6: Aug 9, 2005 2:36 pm -0500
http://creativecommons.org/licenses/by/1.0

http://cnx.org/content/m10577/2.6/
OpenStax-CNX module: m10577 2

The weighting function can be used to assign more importance to specic parts of the frequency response.
For example, it is common to weight the stop-band more heavily than the pass-band. Once the length N and
the Type of the lter (I, II, III, IV) is chosen, the goal is to nd the lter coecients h (n) that minimizes
2 . To develop this approach, we will consider the design of Type I FIR lters. The design of the other 3
linear-phase FIR lter types can be developed similarly.
Recall that for a Type I FIR lter, the amplitude response if given by
M
X
A () = a (n) cos (n)
n=0

where
a (0) = h (M )

a (n) = 2h (M n)

1nM

N 1
M=
2
To obtain the coecients a (n) to minimize 2 , we can set the derivatives equal to zero,
d
(2 ) = 0
dak

0kM
The derivatives of 2 with respect to a (k) can be found as:
d
R dW ()(A()D())2
dak (2 ) = 0 dak d
(2)
R
= 2 0 W () (A () D ()) dA()
dak d
R
= 2 0 W () (A () D ()) cos (k) d

Therefore, d
dak (2 ) = 0 becomes
Z Z
W () A () cos (k) d = W () D () cos (k) d
0 0

or Z M
X Z
W () a (n) cos (n) cos (k) d = W () D () cos (k) d
0 n=0 0

or
M
X Z Z
a (n) W () cos (n) cos (k) d = W () D () cos (k) d
n=0 0 0

If we dene Z
1
Q (k, n) = W () cos (n) cos (k) d (3)
0
and Z
1
b (k) = W () D () cos (k) d (4)
0

http://cnx.org/content/m10577/2.6/
OpenStax-CNX module: m10577 3

then the derivative conditions can be written as


M
(5)
X
Q (k, n) a (n) = b (k)
n=0

where
0kM
This is a linear system of equations, and can be written in matrix form as

Q (0, 0) Q (0, 1) ... Q (0, M ) a (0) b (0)

Q (1, 0) Q (1, 1) ... Q (1, M )
a (1)
b (1)
.. .. .. .. .. = ..

. . . . . .



Q (M, 0) Q (M, 1) . . . Q (M, M ) a (M ) b (M )

or
Qa = b
Therefore, the Type 1 FIR lter that minimizes the square error can be obtained by solving this linear
system of equations.
a = Q1 b

1.2 Structure of the Matrix Q

It turns out that the matrix Q has a special structure. Note that
1 1
cos (n) cos (k) = cos ((k n) ) + cos ((k + n) ) (6)
2 2
so that
1
R
Q (k, n) = 0 W () cos (n) cos (k) d
1
R 1
R (7)
= 2 0 W () cos ((k n) ) d + 2 0
W () cos ((k + n) ) d
or
1 1
Q (k, n) = Q1 (k, n) + Q2 (k, n) (8)
2 2
where Q1 and Q2 are dened as
Z
1
Q1 (k, n) = W () cos ((k n) ) d (9)
0

and Z
1
Q2 (k, n) = W () cos ((k + n) ) d (10)
0
Accordingly, we can write
Q1 (k, n) = q (k n) (11)

Q2 (k, n) = q (k + n) (12)
where Z
1
q (n) = W () cos (n) d (13)
0

http://cnx.org/content/m10577/2.6/
OpenStax-CNX module: m10577 4

With this notation, the matrices Q1 and Q2 are written as



q (0) q (1) ... q (M )

q (1) q (0) ... q (M 1)
Q1 =

.. .. .. ..

(14)
. . . .



q (M ) q (M 1) ... q (0)

and
q (0) q (1) ... q (M )

q (1) q (2) ... q (M + 1)
Q2 =

. .. .. ..

(15)
.. . . .



q (M ) q (M + 1) ... q (2M )
Note that we have used q (n) = q (n) here. The matrix Q1 is a symmetric Toeplitz matrix (constant along
its diagonals), and the matrix Q2 is a Hankel matrix (constant along its anti-diagonals). Consequently,
1. the matrices can be stored with less memory than arbitrary matrices ( 2M + 1 numbers instead of
(M + 1) numbers),
2

2. there are fast algorithms to compute the solution to 'Toeplitz plus Hankel' systems with computational
complexity O M 2 instead of O M 3 . (In fact, the complexity can be reduced further, but with higher


overhead.)

1.3 Relation to the DTFT

To express q (k) and b (k) using the inverse Fourier transform, extend D () and W () symmetrically, so
that D () = D () and W () = W (). Then we can write
Z
1
q (n) = W () cos (n) d (16)
2

As sine is an anti-symmetric function


Z
W () sin (n) d = 0 (17)

so we can write Z
1
q (n) = W () (cos (n) + isin (n)) d (18)
2
or Z
1
q (n) = W () ein d (19)
2

which we recognize as the inverse discrete-time Fourier transform


 
q (n) = DTFT1 W () (20)

Similarly,  
q (n) = DTFT1 W () D () (21)

http://cnx.org/content/m10577/2.6/
OpenStax-CNX module: m10577 5

1.4 Low-Pass: Weighted Square Error

The weighting function W () can be used to improve the FIR low-pass lter because
1. it allows you to eliminate Gibbs phenomenon by deleting a neighborhood around the band edge, and
2. it allows you to assign dierent weights to the pass-band and the stop-band.
For example, if the ideal low-pass amplitude response is as shown in Figure 1.

Figure 1

and if the weighting function is as shown, Figure 2.

http://cnx.org/content/m10577/2.6/
OpenStax-CNX module: m10577 6

Figure 2

where p < o < s , then the square error criterion becomes


Z p Z
2 =
2
(A () 1) d + K A2 () d (22)
0 s

To nd the matrix Q and the vector b to this weighting function it is useful to recall
Z 2
1 2    
cos (n) d = sinc
2
n
1
sinc
1
n (23)
1
Then
1
R
q (k) = 0 W () cos (k) d
1 p
R
cos (k) d + K
R
= cos (k) d

0 s
(24)
p + K 1 s 
if
k=0
=
p sinc p k K s sinc s k if k 6= 0
 

Similarly,
1
R
b (k) = 0 W () D () cos (k) d
1 p (25)
R
= 0 cos (k) d
p p 
= sinc k

1.5 Weighted Low-Pass Example

In the following example, we design a Type 1 FIR low-pass lter of length 31, with band-edges p = 0.26 ,
s = 0.34 and a stop-band weight of K = 10. (See Figure 3)

http://cnx.org/content/m10577/2.6/
OpenStax-CNX module: m10577 7

Figure 3: The second gure shows the pass-band edge detail.

Compared to the Impulse Response Truncation (IRT) method the peak error is reduced. The lter
was designed using the following Matlab code.

% WEIGHTED LEAST SQUARE LOWPASS FILTER

% filter length
N = 31;
M = (N-1)/2;

% set band-edges and stop-band weighting


wp = 0.26*pi;
ws = 0.34*pi;
K = 10;

% normalize band-edges for convenience

http://cnx.org/content/m10577/2.6/
OpenStax-CNX module: m10577 8

fp = wp/pi;
fs = ws/pi;

% construct q(k)
q = [fp+K*(1-fs), fp*sinc(fp*[1:2*M])-K*fs*sinc(fs*[1:2*M])];

% construct Q1, Q2, Q


Q1 = toeplitz(q([0:M]+1));
Q2 = hankel(q([0:M]+1),q([M:2*M]+1));
Q = (Q1 + Q2)/2;

% construct b
b = fp*sinc(fp*[0:M]');

% solve linear system to get a(n)


a = Q\b;

% form impulse response h(n)


h = [a(M+1:-1:2)/2; a(1); a(2:M+1)/2];

http://cnx.org/content/m10577/2.6/

Вам также может понравиться