Design of FIR filters

Design of FIR filters
Giuseppe Scarpa
ENS 2013
Contents
1
Problem statement
2
2
Linear-phase FIR
2.1 Type-I-IV linear-phase FIR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Amplitude response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Zero locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
5
7
9
3
Windowing
3.1 Direct truncation of an ideal impulse response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Smoothing the frequency response using fixed windows . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Filter design using the adjustable Kaiser window . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
10
12
14
4
Frequency-sampling
18
5
Minimax
5.1 Definition and properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2 Minimax approximation optimality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
20
22
6
Equiripple
6.1 Problem formulation . . . . . . . . . . . . . . . .
6.2 Specifying the optimum Chebyshev approximation
6.3 Finding the optimum Chebyshev approximation . .
6.4 Design examples using MATLAB . . . . . . . . .
.
.
.
.
22
22
23
24
25
Special FIR
7.1 Discrete-time differentiators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2 Discrete-time Hilbert transformers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3 Ideal raised-cosine pulse-shaping lowpass filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
26
27
27
7
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
Problem statement
Steps for discrete-time filter design
1. Specification (in this lecture) .... of the desired frequency response
2. Approximation (in this lecture) To find the rational or polynomial transfer function minimizing the implementation cost and satisfies the give specification
3. Quantization (out of the scope of this course)
4. Verification (partly covered in this course) Check whether the filter satisfies the performance requirements by
simulation or testing with real data. If the filter does not satisfy the requirements, iterate the process and change
the requirements or the approximation.
5. Implementation (Structures for discrete-time filters)
Specification
Practical realizability has three key implications:
• Not flat passband response
• Not null stopband response
• Finite transition band
The specifications of practical filters usually take the form of a tolerance diagram
|H(ejω )|
Specifications
Analog
1
√
1 + δp
0
Ap
Passband
Brick wall
1
1
1+2
As
1/A
Transition band
Relative Absolute
1 − δp
Passband
ripple
Stopband ripple
Stopband
δs
ω
ωp ωc ωs
Passband edge
Cutoff-freq.
π
Stopband edge
Absolute specifications [δp , δs ]
(
1 − δp ≤ |H(ejω )| ≤ 1 + δp , 0 ≤ ω ≤ ωp
|H(ejω )| ≤ δs ,
ωs ≤ ω ≤ π
The peak ripples, δp and δs , specify the acceptable tolerances in terms of absolute values.
Good filters: δp , δs << 1
Relative specifications [Ap , As ]
(
−Ap ≤ |H(ejω )|dB ≤ 0, 0 ≤ ω ≤ ωp
|H(ejω )|dB − As ,
ωs ≤ ω ≤ π
Ap , 20 log10
1+δp
1−δp
(passband ripple)
2
1+δ
As , 20 log10 δs p ≈ −20 log10 δs (stopband attenuation)
Good filters: Ap → 0 and As → ∞
Analog specifications [Fpass , Fstop , , A]
Specifications may refer to an underlying analog problem:
ωp = 2π
Fpass
,
Fs
ωs = 2π
Fstop
,
Fs
F s, sampling freq.
(normalized frequencies obtained from those in Hz)
Analog filter masks are usually defined through and A:
(
(
√
√
= 100.1Ap − 1
20 log10
1 + 2 = Ap
⇔
20 log10 A = As
A = 100.05As
Observe that some classes of filters (differentiators, Hilbert transformers, shaping lowpass) cannot be designed
specifying a tolerance mask.
Approximation
Given a desired response hd [n] (or Hd (ejω )) we need to find a practically realizable filter H(ejω ) approximating
Hd (ejω ) within a given tolerance.
“Practically” means:
• causal
• stable
• with finite-order, rational or polinomial, transfer function:
M
P
bk z
k=0
N
P
H(z) =
−k
ak z −k
1+
k=1
Implications of causality
Theorem 1 (Paley-Wiener). If h[n] has finite energy and h[n] = 0 for n < 0, then
Z π
ln H ejω dω < ∞
−π
Conversely, for any square integrable |H(ejω )| satisfying the above inequality there exist a phase response ∠H(ejω )
jω
such that |H(ejω )| e∠H(e ) is causal.
Only one such phase response gives a minimum-phase H(z).
Important to know: for rational system functions there exist 2M +N possible phase responses which give causality!
Consequences:
• Ideal LPF, HPF,... are non-causal
• Typical specifications on the phase response are:
3
– no requirements
– linear response
In any case there is a finite set (2M +N ) of possible solutions
• Real and imaginary part of the spectral response of a real, stable and causal system are strictly related by the
discrete Hilbert transform
Z π
ω−θ
1
jω
jω
HR (e ) cot
HI (e ) = −
dθ
2π −π
2
Consequently amplitude and phase responses are interdependent, as well.
Optimality Criteria
• Mean-squared-error approximation. That is the minimization of
1
E2 ,
2π
Z
Hd (ejω ) − H(ejω )2 dω
1/2
B
• Minimax approximation. The minimization of the maximum absolute deviation:
E∞ , max |Hd (ejω ) − H(ejω )|
ω∈B
The solution is called minimax or best uniform or Chebyshev approximation
• Maximally-flat approximation. Indicated if the maximum fidelity is required in the neighbourhood of a given
frequency ω0 .
– This is achieved imposing the larger number of derivatives of Hd (ejω ) and H(ejω ) to be equal.
– Formalization requires the Taylor’s expansion
– A special case is the well known Butterworth approximation
2
Linear-phase FIR
Without loss of generality let us focus on an ideal low pass with linear phase response:

e−jαω , |ω| < ωc
sin ωc (n − α)
jω
Hlp (e ) =
←→ hlp [n] =
0,
π(n − α)
ω < |ω| ≤ π
c
hlp [n] can be obtained by sampling the corresponding ideal continuous-time LPF with cutoff frequency Ωc =
ωc /T at t = nT :
sin Ωc (t − αT ) c
hlp [n] = hlp (t)|t=nT =
π(t − αT ) t=nT
hclp (t)
Observe that
is always symmetric about αT , while hlp [n] is symmetric depending on α...
In particular, there are three cases for the delay α:
• α = nd ∈ Z ⇒ symmetric about nd
• α = m + 21 , m ∈ Z ⇒ symmetric about α (not integer)
• 2α ∈
/ Z ⇒ not symmetric
4
α=6
n
6
12
α = 6.5
n
6.5
13
α = 6.25
n
6.25
12
Focusing on the symmetric case, for which M , 2α ∈ Z, let’s create a causal FIR by setting

hlp [n], 0 ≤ n ≤ M
h[n] =
0,
elsewhere
Observe that:
• the time delay α =
M
2
is integer only for M even
• h[n] is a practically realizable FIR with linear phase response or, equivalently, constant group delay
τgd , −
d∠H(ejω )
dω
• The amplitude of the spectral response is, instead, only approximatively that of a LPF
In general
Practical filters with linear phase
It can be shown that any causal IIR with rational response cannot have linear phase response. Therefore practical
filters having linear phase response are necessarily FIR satisfying one of the following 4 symmetry conditions:
h[n] = ±h[M − n],
M even/odd
• M is the filter order (polynomial order)
• L = M + 1 will be the length of h[n]
2.1
Type-I-IV linear-phase FIR
Type-I
This is the case symmetric (h[n] = h[M − n]) with even M .
Example 2. Let M = 4 ⇒ h[4] = h[0], h[3] = h[1]. Therefore:
H(ejω )
= h[0] + h[1]e−jω + h[2]e−j2ω + h[3]e−j3ω + h[4]e−j4ω
=
(h[2] + 2h[1] cos ω + 2h[0] cos 2ω) e−j2ω
, (a[0] + a[1] cos ω + a[2] cos 2ω) e−j2ω
5
In general:
Type-I FIR

M/2
H(ejω ) = 
X

a[k] cos kω e−jωM/2 , A(ejω )e−jωM/2
k=0
• A(ejω ) real, even and periodic.
• a[0] , h[M/2];
a[k] , 2h [M/2 − k],
k = 1, 2, . . . , M/2.
Type-II
Similar manipulations lead to the Type-II spectrum
Type-II FIR (symmetric h[n] and odd M )
H(ejω ) = A(ejω )e−jωM/2
with
M +1
2
A(ejω ) =
X
k=1
M −1
2
1
ω X
b[k] cos ω k −
b̃[k] cos kω
= cos
2
2
k=0
where

1

k=1
 2 (b̃[1] + 2b̃[0]),


M +1
b[k] , 2h
− k = 21 (b̃[k] + b̃[k − 1]), 2 ≤ k ≤ M2−1

2


 1 b̃ M −1 ,
k = M2+1
2
2
Observe: ω = π ⇒ A(ejω ) = 0 ⇒ unsuited for highpass filtering.
Type-III
Type-III FIR (antisymmetric h[n] and even M )
H(ejω ) = jA(ejω )e−jωM/2
with
M/2
A(ejω ) =
X
M/2
c[k] sin kω = sin ω
k=1
X
c̃[k] cos kω
k=0
where

 21 (2c̃[0] − c̃[1]),
k=1



M
− k = 12 (c̃[k − 1] − c̃[k]), 2 ≤ k ≤ M
c[k] , 2h
2 −1

2

1 M

k = M/2
2 c̃ 2 − 1 ,
(
Observe:
ω ∈ {0, π} ⇒ A(ejω ) = 0
imaginary frequency responce
⇒ differentiators, Hibert tr.
6
Type-IV
Type-IV FIR (antisymmetric h[n] and odd M )
H(ejω ) = jA(ejω )e−jωM/2
with
M +1
2
X
A(ejω ) =
k=1
M −1
2
1
ω X
˜ cos kω
d[k] sin ω k −
d[k]
= sin
2
2
k=0
where

1
˜ − d[1]),
˜

k=1
 2 (2d[0]


M +1
˜ − 1] − d[k]),
˜
d[k] , 2h
− k = 12 (d[k
2 ≤ k ≤ M2−1

2


 1 d˜ M −1 ,
k = M2+1
2
2
(
Observe:
2.2
ω = 0 ⇒ A(ejω ) = 0
imaginary frequency responce
⇒ differentiators, Hibert tr.
Amplitude response
Eventually all linear-phase FIRs share a spectral response of the kind
H(ejω ) =
M
X
h[n]e−jωn , A(ejω )eΨ(e
jω
n=0
where
• A(ejω ), the amplitude response (takes real, positive or negative, values)
• Ψ(ejω ) , −αω + β, the generalized linear phase
(β accounts for the eventual presence of j)
jω
• Group delay: τgd (ω) = − dΨ(e
dω
)
=α
The use of A(ejω ) and Ψ(ejω ) is preferable because:
• A(ejω ) is analytic while |H(ejω )| is not
• Ψ(ejω ) is continuous while ∠H(ejω ) is not
allowing for optimization techniques.
Properties of the linear-phase FIR responses
7
)
Type
h[k]
M
I
even
even
A(ejω )
A(ejω )
Ψ(ejω )
M/2
P
a[k] cos ωk
even
no restriction
− ωM
2
b[k] cos ω k − 21
even
A(ejπ ) = 0
− ωM
2
c[k] sin ωk
odd
A(ej0 ) = 0
A(ejπ ) = 0
π
2
−
ωM
2
d[k] sin ω k − 12
odd
A(ej0 ) = 0
π
2
−
ωM
2
k=0
M +1
2
II
even
odd
P
k=1
III
odd
even
M/2
P
k=1
M +1
2
IV
odd
odd
P
k=1
Recall the following symmetry properties:

x[n] real, even ←−DTFT
−−−−→ X(ejω ) real, even
DTFT

x[n] real, odd ←−−−−−→ X(ejω ) immaginary, odd
Therefore:

he [n] ←−DTFT
−−−−→ Ae (ejω )
⇒ he [n − α] ←−−−−−→ Ae (ejω )e−jωα
DTFT

ho [n] ←−−−−−→ jAo (ejω )
⇒ ho [n − α] ←−−−−−→ Ao (ejω )e−jωα+jπ/2
DTFT
DTFT
with
• he [n], Ae (ejω ): real and even
• ho [n], Ao (ejω ): real and odd
M ATLAB problem
Computation of the amplitude response A(ejω )
Write a matlab function A = amplresp(h,w) whose output A is the amplitude response A(ejω ) computed at
frequency locations given in w, being h the impulse response of any linear-phase causal FIR (type-I–IV).
Unified representation
The filter design by minimax criterion can be unified considering the following factorization
A(ejω ) = Q(ejω )P (ejω )
where:
• Q(ejω ) is a fixed function dependent on the type of the filter
• P (ejω ) is combination of cosines dependent on the filter coefficients
8
Type
M
Q(ejω )
I
even
1
P (ejω )
M/2
P
H(ejω ) = 0
LP, HP, BP, BS
multiband filters
ã[k] cos ωk
k=0
II
III
odd
even
M −1
2
cos ω2
P
b̃[k] cos ωk
ω=π
LP, BP
c̃[k] cos ωk
ω = 0, π
differentiators
Hilbert transform.
ω=0
differentiators
Hilbert transform.
k=0
M/2
P
sin ω
k=0
IV
2.3
odd
Uses
M −1
2
P ˜
d[k] cos ωk
sin ω2
k=0
Zero locations
The above mentioned restrictions on the amplitude response of type-I–IV filters can be also recognized in terms of
zero locations.
In fact, for these filters we have:
H(z) = ±z −M H(z −1 )
(mirror − image polynomial)
For example, for type-I or type-II, we have
H(z) =
M
X
h[n]z
−n
n=0
=
M
X
h[M − n]z
−n
n=0
=
0
X
h[k]z k z −M = z −M H(z −1 )
k=M
As direct consequence we have the mirror-image symmetry wrt the unit circle:
H(z0 ) = 0 =⇒ H(z0−1 ) = 0
Moreover, is h[n] is real than:
H(z0 ) = 0 =⇒ H(z0∗ ) = 0
Hence for real linear-phase FIR possible zero patterns are:
• Neither real nor on the unit circle:
(1 − rejθ z −1 )(1 − re−jθ z −1 )(1 − r−1 ejθ z −1 )(1 − r−1 e−jθ z −1 )
• On unit circle, not real:
(1 − rejθ z −1 )(1 − re−jθ z −1 )
• Real but 6= ±1:
(1 ± rz −1 )(1 ± r−1 z −1 )
• ±1:
(1 ± z −1 )
In addition the following constraints apply:
• −1 is always a zero of H(z) for type-II and type-III. Indeed:
9
type-II: H(−1) = (−1)M H(−1) = −H(−1) ⇒ H(−1) = 0
type-III: H(−1) = −(−1)M H(−1) = −H(−1) ⇒ H(−1) = 0
• 1 is always a zero of H(z) for type-III and type-IV. Indeed:
H(1) = −(1)M H(1) = −H(1) ⇒ H(1) = 0
M ATLAB : type-I–IV filters analysis
M ATLAB : linphaseFIR.m
% Linear-phase FIR
h=[1 2 3 -2 5 -2 3 2 1]; % type-I (M=8)
% h=[1 2 3 -2 -2 3 2 1]; % type-II (M=7)
% h=[1 2 3 -2 0 2 -3 -2 -1]; %type-III (M=8)
% h=[1 2 3 -2 2 -3 -2 -1]; %type-IV (M=7)
M=length(h)-1;
[H W] = freqz(h); % frequency responce in [0, π)
W4 = [W; W+pi; W+2*pi; W+3*pi]; % span over [0, 4π)
H4 = [H; flipud(conj(H)); H; flipud(conj(H))];
E = exp(-i*W4*M/2);
if h(1) ∼= h(M+1),
E=i*E; % only for type-III and type-IV
end
A4=real(H4./E); % recall: H(ejω ) = jA(ejω )e−jωM/2
jω
Psi4=angle(H4./A4); % recall: H(ejω ) = A(ejω )ejΨ(e )
3
Design by window method
• The easiest way to get a FIR in the time domain is truncation of the IIR response
• Direct truncation minimizes the mean square error of the spectral response
• Gives unacceptable size ripples
• Designing filters by windowing means reshape and truncate to minimize the ripples
• The resulting FIR is no longer optimal in the mean square error sense
3.1
Direct truncation of an ideal impulse response
Minimum square error truncation
∞
P
Let Hd (ejω ) =
hd [n]e−jωn be the desired response, and h[n], 0 ≤ n ≤ M a candidate FIR approximating
n=−∞
the target IIR.
Question: which is the FIR which minimizes the mean-square error?
2
=
=
1
2π
Z
M
X
π
∞
X
Hd (ejω ) − H(ejω )2 dω =
(hd [n] − h[n])2
−π
n=−∞
2
(hd [n] − h[n]) +
n=0
−1
X
n=−∞
10
h2d [n]
+
∞
X
n=M +1
h2d [n]
Therefore 2 is minimized wrt h[n] if and only if
h[n] = hd [n], 0 ≤ n ≤ M
Frequency domain effects of truncation
DTFT
h[n] = hd [n]w[n] ←−−−−−→ H(ejω ) =
1
2π
Z
π
Hd (ejθ )W (ej(ω−θ) )dω
−π
Direct truncation corresponds to the rectangular window whose spectral response is
jω
W (e )
=
M
X
e−jωn =
n=0
,
sin[ω(M + 1)/2] −jωM/2
1 − e−jω(M +1)
=
e
1 − e−jω
sin[ω/2]
AW (ejω )e−jωM/2
To understand the effect of the circular convolution between the spectrum of the window the desired filter response,
focus on an ideal lowpass filter and convolve the corresponding amplitude responses...
AW (ej(ω0 −θ) ), Ad (ejθ )
AW (ej(ω0 −θ) ), Ad (ejθ )
ω0 = 0
ω0 = −ωc +
2π
L
θ
−π
−ωc
ω0
ωc
π
θ
ω0
−π
2π
L
π
AW (ej(ω) ) ~ Ad (ejω )
AW (ej(ω0 −θ) ), Ad (ejθ )
ω0 = −ωc −
ωc
ω1 ≈ −ωc −
2π
L
ω2 ≈ −ωc +
2π
L
θ
−π
ω0
ωc
π
ω
−π
ω1
ω2
π
For large values of M , it can be easily proved that
• Ripples (bandpass and stopband) are symmetrical, therefore:
– same distance from ωc , about 2π/(M + 1)
– about the same maximum peak deviation
• Ripple peak deviation is insensitive to M . In particular:
(
1+δ
20 log10 1 p ≈ 0.75dB
δp ≈ δs ≈ 0.0895 ⇔
20 log10 δ1s ≈ 21dB
11
(passband ripple)
(stopband attenuation)
Ad (ejω )
1 + δp
A(ejω )
1
1 − δp
∆ω = ωs − ωp ≈
1.8π
M
≤
4π
L
δp = δs ≈ 0.09
δs
ω
ωc
−δs
π
∆ω
4π/L ←− window main lobe bandwidth
• The window size L = M + 1 controls the transition bandwidth
1.8π
4π
≤
M
L
∆ω , ωs − ωp ≈
• The ripple peak, instead, is only related to the window shape.
3.2
Smoothing the frequency response using fixed windows
Window selection table
Window
Side lobe
name
level (dB)
Upper
bound ∆ω
Exact
∆ω
δp ≈ δs
Ap
(dB)
As
(dB)
Rectang.
−13
4π/L
1.8π/M
0.09
0.75
21
Bartlett
−25
8π/L
6.1π/M
0.05
0.45
26
Hann
−31
8π/L
6.2π/M
0.0063
0.055
44
Hamming
−41
8π/L
6.6π/M
0.0022
0.019
53
Blackman
−57
12π/L
11π/M
0.0002
0.0017
74
where the Blackman window is defined as
(
0.42 − 0.5 cos(2πn/M ) + 0.08 cos(4πn/M ),
w[n] =
0,
0≤n≤M
otherwise
Observe that the Hamming window gives the best compromise
Moreover, since all windows satisfy the symmetry condition
w[n] = w[M − n],
0≤n≤M
then
hd [n] ± hd [M − n]
⇓
h[n] = w[n]hd [n] = ±w[M − n]hd [M − n]= ±h[M − n]
Hence, the windowing preserves the eventual symmetry (linear-phase systems)
12
The following steps describe how to design a lowpass filter using fixed windows. The same procedure can be
easily generalized to other filters.
Design using fixed windows
Let {ωp , ωs , Ap , As } be the specifications
1. {Ap , As } ⇒ {δp , δs } ⇒ δ = min{δp , δs }
2. set ωc = (ωp + ωs )/2 (ideal lowpass cutoff frequency)
3. set A = −20 log10 δ and ∆ω = ωs − ωp (design parameters)
4. select window (from table):
• select the window shape having the smallest As larger than A
• select minimum window length such that ∆ω ≥ απ/M ⇒ M = dαπ/∆ωe
• for odd M , if needed, increase it by one to get a more flexible type-I filter
5. Compute the impulse response of the ideal lowpass filter by
hd [n] =
sin[ωc (n − M/2)]
= (ωc /pi)*sinc((ωc /pi)*(n-M/2))
π(n − M/2)
6. Compute the windowed impulse response by h[n] = hd [n]w[n]
7. Verify that the specifications are satisfied; if not, increase M and go back to 5.
Example 3. Specifications: ωp = 0.25π, ωs = 0.35π, Ap = 0.1dB, As = 50dB
(
(
Ap /20
1+δ
−1
Ap = 20 log10 1−δpp
δp = 10
= 0.0058
10Ap /20 +1
⇔
−As
As ≈ −20 log10 δs
δs = 10 20 = 0.0032 = δ ⇒ A = 50dB
⇒ Hamming (⇒ α = 6.6)
M = dαπ/∆ωe = d6.6π/(0.1π)e= 66
Since M = 66 (even) we have a type-I filter.
(M +1)
h[n] = wham
c (n−M/2)]
[n] sin[ω
π(n−M/2) ,
ωc = (ωs + ωp )/2 = 0.3π
Finally verify that the specifications are satisfied, for example, by means of freqz...
Using M ATLAB : fixwindesign.m
13
» wp = 0.25*pi; ws = 0.35*pi; Ap = 0.1; As = 50; %
spec.
» %
» deltap = (10ˆ(Ap/20)-1)/(10ˆ(Ap/20)+1);
» deltas = (1+deltap)/(10ˆ(As/20));
» delta = min(deltap,deltas); A = -20*log10(delta)
A =
50
» Deltaw = ws-wp; omegac = (ws+wp)/2;
» M = ceil(6.6*pi/Deltaw); L=M+1;
» n = 0:M;
» h = hamming(L)’.*(omegac/pi).*sinc((omegac/pi)*(n-M/2));
» %
» % verification
» figure(1); freqz(h);
» Wlow= W(find(W<=wp)); NP=length(Wlow);
» Whigh= W(find(W>=ws)); NS =length(Whigh); N =
length(W);
» errp=abs(H(1:NP))-1; errs=abs(H(N-NS+1:N));
» figure(2); plot(Wlow,errp,Whigh,errs);
3.3
Filter design using the adjustable Kaiser window
• The main limitation of the fixed window method is that the only controllable parameter is M , and it plays a role
on the roll-off of the transition bandwidth
• There is no control over the ripple size
• ⇒ parametrized variable-shape windows (like the Kaiser’s window)
Kaiser window
w[n] ,
where α =
M
2
 h √
i
 I0 β 1−[(n−α)/α]2
I0 (β)
0,
, 0≤n≤M
otherwise
and I0 (x) is the zero-order modified Bessel function of the first kind I0 (x) = 1 +
i
∞ h
P
(x/2)2
m=1
m!
• The Kaiser windows approximate (in the discrete-time domain) the “optimal” prolate spheroidal wave functions
• Prolate functions are optimal continuous-time windows which get the best trade-off between mainlobe bandwidth and relative height of the side lobes
• M ATLAB : kaiser(L,beta)
Now, the fundamental question is how to relate the two parameters, M and β, to the specifications A and ∆ω.
Setting Kaiser parameters
14
Kaiser has found experimentally the following relationship


0,
A < 21



β = 0.5842(A − 21)0.4 + 0.07886(A − 21), 21 ≤ A ≤ 50



0.1102(A − 8.7),
A > 50.
where A = −20 log10 δ, with δ = min{δp , δs }.
The transition bandwidth can be controlled, instead, through the length
M=
8
A−8
2.285∆ω
β
Blackman
6
2
Hamming
Hann
4
Bartlett
A
Rectangular
20
40
60
M ATLAB : kaiserWinAnalysis.m
15
80
M=[10,20,40]; beta = [0,5,8];
figure(1); hold on; title(’...’); ...
for k=1:3,
win=kaiser(M(2)+1,beta(k))’;
plot(0:M(2),win,col(k));
end
figure(2); hold on; title(’...’); ...
for k=1:3,
win=kaiser(M(2)+1,beta(k))’; [H W] =
freqz(win);
plot(W,20*log10(abs(H)/abs(H(1))),col(k));
end
figure(3); hold on; title(’...’); ...
for k=1:3,
win=kaiser(M(k)+1,beta(2))’; [H W] =
freqz(win);
plot(W,20*log10(abs(H)/abs(H(1))),col(k));
end
The following steps describe how to design a lowpass filter using Kaiser windows.
Design using Kaiser windows
Let {ωp , ωs , Ap , As } be the specifications
1. {Ap , As } ⇒ {δp , δs } ⇒ δ = min{δp , δs }
2. set ωc = (ωp + ωs )/2 (ideal lowpass cutoff frequency)
3. set A = −20 log10 δ and ∆ω = ωs − ωp (design parameters)
4. determine the setting parameters, M and β, through the above relationships between {A, ∆ω} and {M, β}
(increase by 1 the value of M if needed to get a different type of filter)
5. Compute the impulse response of the ideal lowpass filter by
hd [n] =
sin[ωc (n − M/2)]
= (ωc /pi)*sinc((ωc /pi)*(n-M/2))
π(n − M/2)
6. Compute the windowed impulse response by h[n] = hd [n]w[n]
7. Verify that the specifications are satisfied; if not, increase M and go back to 5.
16
Generalization
The generalization of the above procedures (fixed and Kaiser windows) can be achieved as long as an analytical
expression for the required ideal impulse response hd [n] is given.
For example:
Bandpass: hbp [n] =
sin[ωc2 (n−M/2)]
π(n−M/2)
Multiband: hmb [n] =
K
P
−
(Ak − Ak+1 )
k=1
sin[ωc1 (n−M/2)]
π(n−M/2)
sin[ωck (n−M/2)]
π(n−M/2)
where |Hmb (ejω )| = Ak for ωk−1 ≤ ω ≤ ωk , 1 ≤ k ≤ K and AK+1 = 0
Highpass: it is a particular case (ωc2 = π) of the bandpass
Observe that only one ripple size (the minimum) and only one transition bandwidth (the minimum) can be controlled
M ATLAB
Further M ATLAB utility for FIR design by windowing are:
• fir1: outputs impulse responses of different kinds (lowpass, multiband, ...) and different windows (hamming
[default] or user-defined ones)
• kaiserord: computes the parameters M and β for given specifications ∆ω and A.
• fdatool the Filter Design and Analysis tool
Limitations of the windowing method
• (Nearly) equal size ripples
• Maximum ripple sizes and edges of each band cannot be specified precisely (because of convolution)
• Difficult analytical derivation of impulse responses for arbitrary frequency responses
• No specific optimality criterion is satisfied (with the exception of the rectangular window which minimizes the
mean square error)
M ATLAB practice
• Design (and verify) a multiband FIR with the technique of the fixed window satisfying the following constraints:
– 0.47 ≤ |H(ejω )| ≤ 0.53,
0 ≤ ω ≤ 0.3π
jω
0.32 ≤ ω ≤ 0.62π
jω
0.68 ≤ ω ≤ π
– 0.98 ≤ |H(e )| ≤ 1.02,
– 0.68 ≤ |H(e )| ≤ 0.72,
• Redesign the filter using the a Kaiser window (explore the use of kaiserord)
• Explore the use of the function fir1 on the given specifications
• Explore the use of the fdatool on the given specifications
17
4
Design by frequency sampling
Let Hd (ejω ) be the desired frequency response
DTFT
Hd (ejω ) ←−−−−−→ hd [n]
Assume to know only L equispaced (on the unit circle) samples:
Hd [k] , Hd (ej2πk/L ),
k = 0, 1, . . . , L − 1
Hence, the inverse DFT yields
L−1
∞
X
1 X
Hd [k]WL−kn , h̃[n] =
hd [n − mL].
L
m=−∞
k=0
Finally, a windowing of h̃[n] yields a FIR:
DTFT
h[n] = h̃[n]w[n] ←−−−−−→ H(ejω ) =
L−1
1 X
Hd [k]W (ej(ω−2πk/L) )
L
k=0
Fundamental question: how do frequency sampling and time-domain windowing affect the fitting of H(ejω )
with the desired Hd (ejω )?
sampling: ⇒ time-domain aliasing:
The faster the variations in the frequency domain (for example, ideal LPF), the larger the number of samples L
to avoid/mitigate the aliasing
windowing: Using an L-points rectangular window yields the ideal interpolation with Dirichlet functions.
The rectangular window ensures H(ej2πk/L ) = Hd (ej2πk/L ) (exact fitting in the sampled frequencies) which
is paid with a strong side effect (Gibbs phenomenon)
Which strategies can be used to reduce the fitting error?
Oversampling For a fixed required response length (say M ), it is anyhow convenient to use a much larger L to reduce
the aliasing effect, then keep only the first M elements of the retrieved impulse response
Smoothing To reduce the Gibbs effect more regular windows can be used. Exact matching at the sampling frequencies
is lost, but it is a negligible price to pay.
In addition, it is worth noting that no specifications need to be satisfied within the transition bands, hence:
Smooth transitions One can fix arbitrarily the samples of Hd (ejω ) in the transition bands. But, in particular, it is
convenient to force regularity by distributing the samples with linear law or, even better, with a rised-cosine
function.
Linear-phase filters
In order to have linear-phase filters additional constraints have to be superimposed. In particular, the samples of
the spectral response, Hd [k] = Ad [k]ejΨd [k] , should be assigned according to the following table:
18
Type
h[k]
M
I
even
even
A(ejω )
A(ejω )
Ψ(ejω )
M/2
P
a[k] cos ωk
even
no restriction
− ωM
2
b[k] cos ω k − 21
even
A(ejπ ) = 0
− ωM
2
c[k] sin ωk
odd
A(ej0 ) = 0
A(ejπ ) = 0
π
2
−
ωM
2
d[k] sin ω k − 12
odd
A(ej0 ) = 0
π
2
−
ωM
2
k=0
M +1
2
II
even
P
odd
k=1
III
odd
M/2
P
even
k=1
M +1
2
IV
odd
P
odd
k=1
Advantages and weakness
• There is no automatic procedure to optimize the filter design for fixed specifications. Iterative procedures can
be used, instead.
• Unsuited for selective filtering (LPF, BPF, etc.)
• Useful for equalization
DAC equalization
Digital-to-Analog Converters (DAC) are usually implemented by means of sample and hold interpolation. This
interpolation introduce a sinc-shaped distortion of the spectrum.
It can be compensated with a proper equalizer in the discrete domain prior to make the conversion
Hd (ejω ) =
ω/2
,
sin(ω/2)
−π ≤ ω ≤ π
Hd (ejω )
1
ω
π
jω
Observe that Hd (e ) 6= 0 for ω ∈ {0, π}, therefore we need a type-I FIR.
M ATLAB implementation of DAC equalizer (dac.m)
19
% DAC Equalizer
M = 40; L = M+1; k = -M/2:M/2;
Ad = 1./sinc(k/L); % Hd over −π ≤ ω ≤ π
Ad = ifftshift(Ad); % Hd over 0 ≤ ω ≤ 2π
alpha = M/2; Q = floor(alpha); % phase delay
parameters
om = linspace(0,2*pi,1001); % Frequency array
psid = -alpha*2*pi/L*[(0:Q),-(L-(Q+1:M))]; % Desired
Phase
Hd = Ad.*exp(1j*psid); % Desired Freq Resp Samples
hd = real(ifft(Hd)); % Desired Impulse response
h = hd.*rectwin(L)’; % Actual Impulse response
% h = hd.*hamming(L)’; % Alternative windowing
figure(1); stem(0:M,h); figure(2); freqz(h,1,om);
[H W]=freqz(h,1,om); % Actual frequency response
figure(3); plot(W,abs(H),linspace(0,2*pi-2*pi/L,L),abs(Hd));
M ATLAB functions for frequency sampling FIR design
• Indeed M ATLAB provides the function fir2 which simplify the design...
• The minimal invocation h=fir2(M,f,A) designs a M -th order linear-phase FIR with specified response
(f,A), where f=[0,...,1] are the normalized (1 corresponds to ω = π) sampled frequencies.
• The previous DAC equalizer can be obtained by
» h=fir2(40,[0:20]/20,Ad(1:21),rectwin(41));
• Additional functions for specific design technique are: firls, fircls and fircls1
5
5.1
Chebyshev polynomials and minimax approximation
Definition and properties
Let us start observing the following correspondence between real numbers x ∈ [−1, 1] and complex numbers on the
unit circle w = ejθ :
x =
=
1
w + w−1
2
cos θ ∈ [−1, 1]
Re [w] =
y
w = ejθ
x = Re [w] = cos(θ)
θ
-1
1
x
w−1 = e−jθ
x and w are uniquely related for 0 ≤ θ ≤ π.
20
Chebyshev polynomial
The mth-order Chebyshev polynomial, denoted Tm (x), is defined by
Tm (x) , Re [wm ] =
1 m
(w + w−m ) = cos(θm) = cos[m cos−1 (x)]
2
By means of the trigonometric identity
cos[(m + 1)θ] = 2 cos(θ) cos(mθ) − cos[(m − 1)θ],
it is easy to prove the following recursive relationship


T0 (x) = 1
T1 (x) = x


Tm+1 (x) = 2xTm (x) − Tm−1 (x),
m≥1
m≥1
which allow one to generate Chebyshev polynomial of any desired order.
Low order Chebyshev polynomials
Order Polynomial Tm (x) = cos[m cos−1 (x)]
0
1
2
3
4
5
6
T0 (x) = 1
T1 (x) = x
T2 (x) = 2x2 − 1
T3 (x) = 4x3 − 3x
T4 (x) = 8x4 − 8x2 + 1
T5 (x) = 16x5 − 20x3 + 5x
T6 (x) = 32x6 − 48x4 + 18x2 − 1
Properties of the Chebyshev polynomials
• leading coefficient equal to 2m−1 for m ≥ 1
• |Tm (x)| ≤ 1 for x ∈ [−1, 1]
• all Chebyshev polynomials have integer coefficients
• Tm (−x) = (−1)m
T (x)
• m zeros in [−1, 1] at xk = cos
2k−1 π
m 2
, k = 1, 2, . . . , m
• m + 1 extrema in [−1, 1] at ξk = cos(kπ/m), k = 0, 1, . . . , m, with Tm (ξk ) = (−1)k (equiripple property)
Tm (x)
T4 (x)
T7 (x)
1
x
−1
1
−1
21
Observe that any (freq. resp.) finite trigonometric series in cos(ωm) can be expressed as linear combination of
Chebyshev polynomials:
Example
P (ω) ,
2 + cos(ω) + cos(2ω) + cos(3ω)
=
[2T0 (x) + T1 (x) + T2 (x) + T3 (x)]|x=cos(ω)
1 − 2x + 2x2 + 4x3 =
x=cos(ω)
Trigonometric series in cos(ωm)
jω
P (e ) =
R
X
p̃[k] cos ωk =
k=0
R
X
p̃[k]Tk (x) =
k=0
R
X
k=0
pk x k
x=cos ω
⇒ it allows us to express the amplitude response of linear-phase FIR
5.2
Minimax approximation optimality
Theorem 4 (Chebyshev). Of all polynomials of degree m with coefficient of xm equal to 1, the Chebyshev polynomial
2−(m−1) Tm (x) has the least maximum amplitude on the interval [−1, 1].
⇓
If we can express the error as a single Chebyshev polynomial, then we have the best minimax polynomial
approximation
Another important theorem is the following
Theorem 5 (Alternation). Suppose that f (x) is a continuous function.
Then Pm (x) is the best mth-order minimax approximating polynomial to f (x) if and only if the error e(x) =
f (x) − Pm (x) has an (m + 2)-point equiripple property.
• The above theorem establishes a characterization of the minimax approximations, but does not provide a solution
to find one
• An effective solution is given by the iterative Remez exchange algorithm
6
Equiripple optimum Chebyshev FIR design
6.1
Problem formulation
Let
• Ad (ejω ) desired amplitude response
• A(ejω ) amplitude response of the implemented approximating filter
• W (ω) a nonnegative weighting function. W (ω) enables us to control the relative size of the error in different
frequency bands.
The approximation error is defined by
E(ω) , W (ω)[Ad (ejω ) − A(ejω )]
Then, the design objective is to find the coefficients of a type I–IV FIR that minimize the weighted Chebyshev error:
22
||E(ω)||∞ = max |E(ω)|
ω∈B
B, union of disjoint closed subsets (frequency bands) of [0, π].
For linear-phase FIR the amplitude response can be written as
A(ejω ) = Q(ejω )P (ejω ),
where


1,
Type I




cos(ω/2), Type II
Q(ejω ) =
,

sin(ω),
Type III




sin(ω/2), Type IV
P (ejω ) =
R
X
p[k] cos(ωk)
k=0
(
M/2,
M even
with R = bM/2c =
(M − 1)/2, M odd
Observe that Q(ejω ) does not depend on the filter coefficient ⇒ can be incorporated in weighting function
W (ω),...
... yielding
E(ω) = W (ω) Ad (ejω ) − P (ejω )
where
• W (ω) , W (ω)Q(ejω )
• Ad (ejω ) ,
Ad (ejω )
Q(ejω )
Now we can formulate the
Chebyshev approximation problem
Given the filter order M , determine the coefficients of P (ejω ) that minimize the maximum absolute value of E(ω)
over the frequency bands of interest, that is, choose P (ejω ) so that
||E(ω)||∞ = max W (ω)[Ad (ejω ) − P (ejω )]
ω∈B
is minimum.
P (ejω ) is a trigonometric series, hence, a Chebyshev polynomial in x = cos ω.
6.2
Specifying the optimum Chebyshev approximation
The solution of the minimax problem is strictly related to the alternation theorem. A more suited formulation of
theorem for the purpose of FIR design is the following:
Theorem 6 (Alternation theorem for FIR filters). A necessary and sufficient condition that P (ejω ) be the unique
solution minimizing ||E(ω)||∞ is that the weighted error function E(ω) exhibit at least R + 2 alternations in B. That
is, there must exist R + 2 extremal frequencies ω1 < ω2 < · · · < ωR+2 such that for every k = 1, 2, . . . , R + 2
E(ωk ) = −E(ωk+1 ),
|E(ωk )| = max E(ω) , δ
ω∈B
being P (ejω ) and R the entities involved in the definition of the amplitude response of a linear-phase FIR
Implications:
23
• the best Chebyshev approximation have equiripple E(ω)
• given B, M and W (ω), there is a unique best approximation
• R = bM/2c
• B is the union of passband and stopband compact intervals
• Ad (ejω ) should be defined and be continuous only within B
• W (ω), defined only within B, includes the approximation error parameters
• once fixed the above parameters there exist a unique “best” solution; this solution is equiripple and the will have
a given maximum error δ = max E(ω).
ω∈B
• if δ does not match the specifications, we need to increase the filter order M and compute1 the new minimax
solution.
Ad (ejω )
{f1 , f2 , f3 , f4 } = {0.2, 0.25, 0.5, 0.6}
1 + δ1
1
1 − δ1
{δ1 , δ2 , δ3 } = {0.1, 0.05, 0.15}
{δ1 /δ1 , δ1 /δ2 , δ1 /δ3 } = {1, 2, 2/3} → W (ω)
B = [0, πf1 ] ∪ [πf2 , πf3 ] ∪ [πf4 , 1]
0.5 + δ3
0.5
0.5 − δ3
δ2
−δ2
ω/π
f1 f2
f3
f4
1
M ATLAB specification:
»
»
»
»
fo = [0, 0.2, 0.25, 0.5, 0.6, 1]; % band edges
ao = [1, 1, 0, 0, 0.5, 0.5] % amp. resp. at fk
W = [1, 2, 2/3]; % weights
M = ??? % FIR order
Observe: W (ω) controls the rela-
tive error proportions; the absolute error is function of M .
6.3
Finding the optimum Chebyshev approximation
To design a minimax optimal FIR it is now necessary to answer two fundamental questions:
• how to determine the best minimax approximation given B, W (ω) and Ad (ejω )?
• how to determine the smallest value of M for a fixed absolute maximum error?
These problems have been widely studied and there exists different solutions. One of the most common solution
is the Parks and McClellan algorithm, whose theoretical formulation is here skipped. This technique is a standard
technique and is available under several professional tools (i.e. M ATLAB ).
In particular the two above questions are addressed by the following M ATLAB functions respectively:
• [h, delta] = firpm(M, fo, Ao, W)
• [M, fo, Ao, W] = firpmord(F, A, dev,Fs)
1 We
still have to discuss how to find the minimax
24
Observe that the default value of Fs is 2 ⇒ implicit use of normalized frequencies F (Nyquist frequency Fs = 1)
where:
• F: % band edges (0 and Fs/2 are implicit, always)
• A: % amplitude resp.
• dev:
in each band
% absolute deviations δb in each band
• Fs:
% sampling frequency
• fo:
% normalized band edges
• Ao:
% amplitude resp.
and
in each band
• W: % error weights for the different bands
• M: % filter order
A empirical formula to estimate the filter order M from the specifications is due to Kaiser:
p
−20 log10 δp δs − 13
M=
2.324∆ω
Observe that it depends on both transition bandwidth and ripple sizes.
6.4
Design examples using MATLAB
Filter design using firpm (Parks and McClellan)
[parks.m]
% ParksMcClellan filter design
close all; clear all;
f=[0.2,0.25,0.5,0.60]’; a=[1,0,0.5]’;
d1=0.1; d2=0.05; d3=0.15; dev=[d1,d2,d3]’;
[M,fo,ao,W]=firpmord(f,a,dev); % W=[1, 2, 2/3];
[h,delta]=firpm(M,fo,ao,W);
[H w]=freqz(h); w=w/pi;
% VERIFICATION
% ...
plot(...)
Observe that firpmord may underestimate M . The obtained value is an initial guess to be refined, usually
incrementing it.
DAC equalization using firpm [DACbyParks.m]
25
% DAC equalizer designed using firpm
clear all; close all;
% DAC Specifications
fdac = 0:0.05:0.55; % fdac = 0:0.01:0.55;
adac = 1./sinc(fdac/2);
deltap = 0.01; deltas = 0.005;
ws = 0.65*pi;
% Filter Design using FIRPM function
fo = [fdac,ws/pi,1]; % Band-edge array
ao = [adac,0,0]; % Band-edge desired gain
W = ([deltap*ones(1,length(fdac)/2),deltas]/deltas).ˆ(-1);
M = 41; % M=46;
[h,delta] = firpm(M,fo,ao,W);
% PLOT and VERIFICATION ...
7
Design of some special FIR
7.1
Discrete-time differentiators
In the continuous-time domain the derivation is characterized as follows:
yc (t) =
dxc (t)
↔ Hc (jΩ) = jΩ
dt
An ideal bandlimited differentiator is defined by
(
Hc (jΩ) =
jΩ, |Ω| < π/T
0,
|Ω| ≥ π/T
The corresponding discrete-time differentiator with linear phase is
H(ejω ) = (jω)e−jωα ,
|ω| < π
Notice that the constant group delay is necessary to have a causal system (after windowing).
The inverse transforming of H(ejω ) is given by
h[n] =
cos[π(n − α)] sin[π(n − α)]
−
,
(n − α)
π(n − α)2
−∞ < n < ∞
Observations:
• we should use type III or IV for which H(ejω ) = jA(ejω )e−jωM/2
• Type III has a null in π, hence unsuitable for fullband differentiator:
– it can be used in a restricted band, i.e. [0, 0.8π]
– it has an integer delay
• Type IV is more suited:
– more accurate and applicable to the full band [0, π]
– it has a non-integer delay
26
Proceed with M ATLAB ...
Implementation of a differentiator type-IV
Experience the design of a type-IV discrete-time differentiator using the following methods and tools
Kaiser window: M = 21 and β = 4.5 (plot impulse/magnitude responce and approximation error)
Parks-McClellan: M = 21 (same plots)
FDATool: Repeat the above design tasks by means of fdatool
7.2
Discrete-time Hilbert transformers
The ideal Hilbert transformer is an allpass system that introduces a 90-degree phase shift. Its discrete-time version is
defined by:
(
−jsgn(ω)e−jωα , ω1 < |ω| < ω2
jω
H(e ) =
0,
otherwise
corresponding to
h[n] =
cos(ω1 [n − α]) − cos(ω2 [n − α])
π(n − α)
In this case, the most suited linear-phase fir is the type-III.
Design of a Hilbert transformer
Design a type-III FIR approximating a Hilbert transformer using M = 40, by means of the fixed window method. Use
in particular the Hamming window.
Repeat the design by using fdatool
7.3
Ideal raised-cosine pulse-shaping lowpass filters
Another special filter commonly used in practice is the raised-cosine pulse-shaping lowpass:



1,h
i 0 ≤ |ω| < (1 − β)ωc
H(ejω ) =
1
2


0,
1 − sin
π ω−ωc
2 βωc
, (1 − β)ωc ≤ |ω| ≤ (1 + β)ωc
(1 + β)ωc < |ω| ≤ π
Design of a raised-cosine pulse-shaping filter
Experience the use of fdatool on the design a raised-cosine pulse-shaping filter.
27