LATTICE FILTER STRUCTURES
6.4 LATTICE FILTER STRUCTURES
The lattice filter is extensively used in digital speech processing and in the implementation of adaptive filters. It is a preferred form of realization over other FIR or IIR filter structures because in speech analysis and in speech synthesis the small number of coefficients allows a large number of formants to be modeled in real time. The all-zero lattice is the FIR filter representation of the lattice filter, while the lattice ladder is the IIR filter representation.
6.4.1 ALL-ZERO LATTICE FILTERS An FIR filter of length M (or order M − 1) has a lattice structure with M − 1 stages as shown in Figure 6.18. Each stage of the filter has an input and output that are related by the order-recursive equations [23]:
f m (n) = f m−1 (n) + K m g m−1 (n − 1), m = 1, 2, . . . , M − 1 (6.16)
g m (n) = K m f m−1 (n) + g m−1 (n − 1), m = 1, 2, . . . , M − 1 where the parameters K m , m = 1, 2, . . . , M − 1, called the reflection
coefficients , are the lattice filter coefficients. If the initial values of f m (n) and g m (m) are both the scaled value (scaled by K 0 ) of the filter input
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Chapter 6
IMPLEMENTATION OF DISCRETE-TIME FILTERS
FIGURE 6.18 All-zero lattice filter x(n), then the output of the (M − 1) stage lattice filter corresponds to
the output of an (M − 1) order FIR filter; that is,
f 0 (n) = g 0 (n) = K 0 x(n)
y(n) = f M −1 (n) If the FIR filter is given by the direct form
M −1
M −1
H(z) =
and if we denote the polynomial A M −1 (z) by
M −1
(m)z − M −1 m M −1 ;
then the lattice filter coefficients {K m } can be obtained by the following recursive algorithm [23]:
K 0 =b 0 K M −1 =α M −1 (M − 1)
m (z) = z − m
m = M − 1, . . . , 1 (6.20)
m = M − 2, . . . , 1 Note that this algorithm will fail if |K m | = 1 for any m = 1, . . . , M − 1.
K m =α m (m),
Clearly, this condition is satisfied by linear-phase FIR filters since
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Lattice Filter Structures 241
Therefore, linear-phase FIR filters cannot be implemented using lattice structures.
6.4.2 MATLAB IMPLEMENTATION Given the coefficients {b n } of the direct form, we can obtain the lattice fil- ter coefficients {K m } using (6.20). This is done by the following MATLAB function dir2latc. Note that the equation to compute J m (z) implies that the polynomial J m (z) is a fliplr operation on the A m (z) polynomial.
function [K] = dir2latc(b) % FIR Direct form to All-Zero Lattice form Conversion % --------------------------------------------------- % [K] = dir2latc(b) % K = Lattice filter coefficients (reflection coefficients) %
b = FIR direct form coefficients (impulse response)
% M = length(b); K = zeros(1,M); b1 = b(1); if b1 == 0 error(’b(1) is equal to zero’) end K(1) = b1; A = b/b1; for m=M:-1:2 K(m) = A(m); J = fliplr(A);
A = (A-K(m)*J)/(1-K(m)*K(m));
A = A(1:m-1);
end
The lattice filter is implemented using (6.16) and (6.17), which is done by
a latcfilt function, as shown here. function [y] = latcfilt(K,x)
% LATTICE form realization of FIR filters % --------------------------------------- % y = latcfilt(K,x) %
y = output sequence
K = LATTICE filter (reflection) coefficient array
x = input sequence
% Nx = length(x)-1; x = K(1)*x; M = length(K)-1; K = K(2:M+1);
fg = [x; [0 x(1:Nx)]];
for m = 1:M fg = [1,K(m);K(m),1]*fg; fg(2,:) = [0 fg(2,1:Nx)]; end y = fg(1,:);
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Chapter 6
IMPLEMENTATION OF DISCRETE-TIME FILTERS
The equations (6.20) can also be used to determine the direct, form coefficients {b m } from the lattice filter coefficients {K m } using a recursive procedure [22]:
A 0 (z) = J 0 (z) = 1
A m (z) = A m−1 (z) + K m z − 1 J m−1 (z) , m = 1, 2, . . . , M − 1 (6.21)
J m (z) = z − m
m = 1, 2, . . . , M − 1
m = 0, 1, . . . , M − 1 The following MATLAB function latc2dir implements (6.21). Note
b m =K 0 α M −1 (m),
that the product K m z − 1 J m−1 (z) is obtained by convolving the 2 corre- sponding arrays, whereas the polynomial J m (z) is obtained by using a fliplr operation on the A m (z) polynomial.
function [b] = latc2dir(K) % All-Zero Lattice form to FIR Direct form Conversion % --------------------------------------------------- % [b] = latc2dir(K) %
b = FIR direct form coefficients (impulse response) % K = Lattice filter coefficients (reflection coefficients) % M = length(K); J = 1; A = 1; for m=2:1:M
A = [A,0]+conv([0,K(m)],J); J = fliplr(A); end b=A*K(1);
EXAMPLE 6.8
An FIR filter is given by the difference equation
y(n) = 2x(n) +
12 x(n − 1) + 4 x(n − 2) + 3 x(n − 3)
Determine its lattice form.
Solution
MATLAB script:
>> b=[2, 13/12, 5/4, 2/3]; K=dir2latc(b) K=
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Lattice Filter Structures 243
FIGURE 6.19 FIR filter structures in Example 6.8: (a) direct form (b) lattice form
Hence 1 1 1
K 0 = 2, K 1 = ,K 2 = ,K 3 = 4 2 3
The direct form and the lattice form structures are shown in Figure 6.19. To check that our lattice structure is correct, let us compute the impulse response of the filter using both forms.
>> [x,n] = impseq(0,0,3]; format long hdirect=filter(b,1,delta) hdirect =
0.66666666666667 >> hlattice=latcfilt(K,delta) hlattice =
6.4.3 ALL-POLE LATTICE FILTERS
A lattice structure for an IIR filter is restricted to an all-pole system function. It can be developed from an FIR lattice structure. Let an all- pole system function be given by
H(z) =
a N (m)z − m
m=1
which from (6.19) is equal to H(z) = 1/A N (z). Clearly, it is an inverse sys- tem to the FIR lattice of Figure 6.18 (except for factor b 0 ). This IIR filter of order N has a lattice structure with N stages, as shown in Figure 6.20.
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Chapter 6
IMPLEMENTATION OF DISCRETE-TIME FILTERS
FIGURE 6.20 All-pole lattice filter
Each stage of the filter has an input and output that are related by the order-recursive equations [23]:
f N (n) = x(n)
f m−1 (n) = f m (n) − K m g m−1 (n − 1),
m = N, N − 1, . . . , 1 (6.23)
g m (n) = K m f m−1 (n) + g m−1 (n − 1), m = N, N − 1, . . . , 1
y(n) = f 0 (n) = g 0 (n)
where the parameters K m , m = 1, 2, . . . , M − 1, are the reflection coeffi- cients of the all-pole lattice and are obtained from (6.20) except for K 0 ,
which is equal to 1.
6.4.4 MATLAB IMPLEMENTATION Since the IIR lattice coefficients are derived from the same (6.20) proce-
dure used for an FIR lattice filter, we can use the dir2latc function in MATLAB. Care must be taken to ignore the K 0 coefficient in the K array. Similarly, the latc2dir function can be used to convert the lattice {K m } coefficients into the direct form {a N (m)}, provided that K 0 = 1 is used as the first element of the K array. The implementation of an IIR lattice is given by (6.23), and we will discuss it in the next section.
EXAMPLE 6.9
Consider an all-pole IIR filter given by
H(z) =
1+ 13 z − 1 + 24 5 8 z − 2 + 1 3 z − 3
Determine its lattice structure.
Solution
MATLAB script:
>> a=[1, 13/24, 5/8, 1/3]; K=dir2latc(a) K=
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Lattice Filter Structures 245
FIGURE 6.21
IIR filter structures in Example 6.9: (a) direct form (b) lattice
The direct form and the lattice form structures of this IIR filter are shown in Figure 6.21.
6.4.5 LATTICE-LADDER FILTERS
A general IIR filter containing both poles and zeros can be realized as
a lattice-type structure by using an all-pole lattice as the basic building block. Consider an IIR filter with system function
b (k)z M − k
k=0
B M (z)
H(z) =
a N (k)z − k
k=1
where, without loss of generality, we assume that N ≥ M . A lattice- type structure can be constructed by first realizing an all-pole lattice with coefficients K m , 1 ≤ m ≤ N for the denominator of (6.24), and then adding a ladder part by taking the output as a weighted linear combination of {g m (n)}, as shown in Figure 6.22 for M = N . The result is a pole-zero IIR filter that has the lattice-ladder structure. Its output is given by
y(n) =
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Chapter 6
IMPLEMENTATION OF DISCRETE-TIME FILTERS
FIGURE 6.22 Lattice-ladder structure for realizing a pole-zero IIR filter
where {C m } are called the ladder coefficients that determine the zeros of the system function H(z). It can be shown [23] that {C m } are given by
where J m (z) is the polynomial in (6.20). From (6.26) one can obtain a recursive relation
B m (z) = B m−1 (z) + C m J m (z); m = 1, 2, . . . , M
or equivalently, " M
C m =b m +
C i α i (i − m); m = M, M − 1, . . . , 0 (6.27)
i=m+1
from the definitions of B m (z) and A m (z).
6.4.6 MATLAB IMPLEMENTATION To obtain a lattice-ladder structure for a general rational IIR filter, we can first obtain the lattice coefficients {K m } from A N (z) using the re- cursion (6.20). Then we can solve (6.27) recursively for the ladder coeffi- cients {C m } to realize the numerator B M (z). This is done in the following MATLAB function dir2ladr. It can also be used to determine the all-pole lattice parameters when the array b is set to b=[1].
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Lattice Filter Structures 247
function [K,C] = dir2ladr(b,a) % IIR Direct form to pole-zero Lattice/Ladder form Conversion % ----------------------------------------------------------- % [K,C] = dir2ladr(b,a) % K = Lattice coefficients (reflection coefficients), [K1,...,KN] %
C = Ladder Coefficients, [C0,...,CN]
b = Numerator polynomial coefficients (deg <= Num deg)
a = Denominator polynomial coefficients
% a1 = a(1); a = a/a1; b = b/a1; M = length(b); N = length(a); if M > N
error(’
*** length of b must be <= length of a ***’)
end b = [b, zeros(1,N-M)]; K = zeros(1,N-1); A = zeros(N-1,N-1); C = b; for m = N-1:-1:1 A(m,1:m) = -a(2:m+1)*C(m+1); K(m) = a(m+1); J = fliplr(a);
a = (a-K(m)*J)/(1-K(m)*K(m));
a = a(1:m);
C(m) = b(m) + sum(diag(A(m:N-1,1:N-m))); end
Note: To use this function, N ≥ M . If M > N , the numerator A N (z) should be divided into the denominator B M (z) using the deconv func- tion to obtain a proper rational part and a polynomial part. The proper rational part can be implemented using a lattice-ladder structure, while the polynomial part is implemented using a direct structure.
To convert a lattice-ladder form into a direct form, we first use the recursive procedure in (6.21) on {K m } coefficients to determine {a N (k)} and then solve (6.27) recursively to obtain {b M (k)}. This is done in the following MATLAB function ladr2dir.
function [b,a] = ladr2dir(K,C) % Lattice/Ladder form to IIR Direct form Conversion % ------------------------------------------------- % [b,a] = ladr2dir(K,C) %
b = numerator polynomial coefficients
a = denominator polymonial coefficients % K = Lattice coefficients (reflection coefficients) %
C = Ladder coefficients
% N = length(K); M = length(C);
C = [C, zeros(1,N-M+1)];
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Chapter 6
IMPLEMENTATION OF DISCRETE-TIME FILTERS
J = 1; a = 1; A = zeros(N,N); for m=1:1:N
a = [a,0]+conv([0,K(m)],J); A(m,1:m) = -a(2:m+1); J = fliplr(a); end b(N+1) = C(N+1); for m = N:-1:1
A(m,1:m) = A(m,1:m)*C(m+1); b(m) = C(m) - sum(diag(A(m:N,1:N-m+1)));
end
The lattice-ladder filter is implemented using (6.23) and (6.25). This is done in the following MATLAB function ladrfilt. It should
be noted that, due to the recursive nature of this implementation along with the feedback loops, this MATLAB function is neither an elegant nor an efficient method of implementation. It is not possible to exploit MATLAB’s inherent parallel processing capabilities in implementing this lattice-ladder structure.
function [y] = ladrfilt(K,C,x) % LATTICE/LADDER form realization of IIR filters % ---------------------------------------------- % [y] = ladrfilt(K,C,x) % y = output sequence % K = LATTICE (reflection) coefficient array % C = LADDER coefficient array % x = input sequence % Nx = length(x); y = zeros(1,Nx); N = length(C); f = zeros(N,Nx); g = zeros(N,Nx+1); f(N,:) = x; for n = 2:1:Nx+1
for m = N:-1:2 f(m-1,n-1) = f(m,n-1) - K(m-1)*g(m-1,n-1); g(m,n) = K(m-1)*f(m-1,n-1) + g(m-1,n-1);
end g(1,n) = f(1,n-1);
end y = C*g(:,2:Nx+1);
! EXAMPLE 6.10 Convert the following pole-zero IIR filter into a lattice-ladder structure.
1 + 2z − 1 + 2z − 2 +z − 3 H(z) = 1+ 13 5 24 1 z − 1 + 8 z − 2 + 3 z − 3
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Lattice Filter Structures 249
Solution
MATLAB script:
>> b = [1,2,2,1] a = [1, 13/24, 5/8, 1/3]; [K,C] = dir2ladrc(b) K=
C 0 = −0.2695, C 1 = 0.8281, C 2 = 1.4583, C 3 =1
FIGURE 6.23 IIR filter structures in Example 6.10: (a) direct form (b) lattice- ladder form
The resulting direct form and the lattice-ladder form structures are shown in Figure 6.23. To check that our lattice-ladder structure is correct, let us compute the first 8 samples of its impulse response using both forms.
>> [x,n]=impseq(0,0,7) format long hdirect = filter(b,a,x) hdirect =
Columns 1 through 4 1.00000000000000
0.58506944444444 -0.56170428240741 Columns 5 through 8 -0.54752302758488
0.28426911049255 -0.25435705167494 >> hladder = ladrfilt(K,C,x) hladder =
Columns 1 through 4 1.00000000000000
0.58506944444444 -0.56170428240741 Columns 5 through 8 -0.54752302758488
Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Chapter 6
IMPLEMENTATION OF DISCRETE-TIME FILTERS
Finally, we note that the SP toolbox also provides functions similar to the ones discussed in this section—the complementary functions, tf2latc and latc2tf, compute all-pole lattice, all-zero lattice, and lattice-ladder structure coefficients, and vice versa. Similarly, the function latcfilt (the same name as the book function) implements the all-zero lattice structure. The SP toolbox does not provide a function to implement the lattice-ladder structure.