Are you sure?
This action might not be possible to undo. Are you sure you want to continue?
®∗
Ricardo A. Losada
†
The MathWorks, Inc.
May 18, 2008
∗
MATLAB® and Simulink® are registered trademarks of The MathWorks, Inc.
†
Ricardo Losada is with the Signal Processing and Communications develop
ment team at The MathWorks, Inc.
Contents
I Filter Design 8
1 Basic FIR Filter Design 9
1.1 Why FIR ﬁlters? . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2 Lowpass ﬁlters . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2.1 FIR lowpass ﬁlters . . . . . . . . . . . . . . . . . . . . 11
1.2.2 FIR ﬁlter design speciﬁcations . . . . . . . . . . . . . 11
1.2.3 Working with Hertz rather than normalized frequency 14
1.3 Optimal FIR ﬁlter design . . . . . . . . . . . . . . . . . . . . . 15
1.3.1 Optimal FIR designs with ﬁxed transition width and
ﬁlter order . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.2 Optimal equiripple designs with ﬁxed transition width
and peak passband/stopband ripple . . . . . . . . . . 22
1.3.3 Optimal equiripple designs with ﬁxed peak ripple
and ﬁlter order . . . . . . . . . . . . . . . . . . . . . . 26
1.3.4 Constrainedband equiripple designs . . . . . . . . . 27
1.3.5 Sloped equiripple ﬁlters . . . . . . . . . . . . . . . . . 28
1.4 Further notes on equiripple designs . . . . . . . . . . . . . . 32
1.4.1 Unusual endpoints in the impulse response . . . . . 32
1.4.2 Transition region anomalies . . . . . . . . . . . . . . . 33
1.5 Maximallyﬂat FIR ﬁlters . . . . . . . . . . . . . . . . . . . . . 35
1.6 Summary and look ahead . . . . . . . . . . . . . . . . . . . . 37
2 Basic IIR Filter Design 39
2.1 Why IIR ﬁlters . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.2 Classical IIR design . . . . . . . . . . . . . . . . . . . . . . . . 40
2.2.1 Cutoff frequency and the 3dB point . . . . . . . . . . 41
2.2.2 Butterworth ﬁlters . . . . . . . . . . . . . . . . . . . . 41
2.2.3 Chebyshev type I ﬁlters . . . . . . . . . . . . . . . . . 42
CONTENTS 3
2.2.4 Chebyshev type II designs . . . . . . . . . . . . . . . . 44
2.2.5 Elliptic ﬁlters . . . . . . . . . . . . . . . . . . . . . . . 47
2.2.6 Minimumorder designs . . . . . . . . . . . . . . . . . 48
2.2.7 Comparison to FIR ﬁlters . . . . . . . . . . . . . . . . 50
2.3 IIR designs directly in the digital domain . . . . . . . . . . . 52
2.4 Summary and look ahead . . . . . . . . . . . . . . . . . . . . 54
3 Nyquist Filters 56
3.1 Design of Nyquist ﬁlters . . . . . . . . . . . . . . . . . . . . . 57
3.1.1 Equiripple Nyquist ﬁlters . . . . . . . . . . . . . . . . 58
3.1.2 Minimumorder Nyquist ﬁlters . . . . . . . . . . . . . 61
3.2 Halfband ﬁlters . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.2.1 IIR halfband ﬁlters . . . . . . . . . . . . . . . . . . . . 63
3.3 Summary and look ahead . . . . . . . . . . . . . . . . . . . . 65
4 Multirate Filter Design 67
4.1 Reducing the sampling rate of a signal . . . . . . . . . . . . . 68
4.1.1 Decimating by an integer factor . . . . . . . . . . . . . 68
4.1.2 Decimating by a noninteger factor . . . . . . . . . . . 79
4.2 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.2.1 Fractionally advancing/delaying a signal . . . . . . . 80
4.2.2 Increasing the samplingrate of a signal . . . . . . . . 82
4.2.3 Design of FIR interpolation ﬁlters . . . . . . . . . . . 86
4.2.4 Design of IIR halfband interpolators . . . . . . . . . . 89
4.2.5 Design of interpolators when working with Hertz . . 90
4.3 Increasing the sampling rate by a fractional factor . . . . . . 92
4.4 Fractional decimation . . . . . . . . . . . . . . . . . . . . . . . 95
4.5 Summary and look ahead . . . . . . . . . . . . . . . . . . . . 96
5 Multistage/Multirate Filter Design 99
5.1 Interpolated FIR (IFIR) designs . . . . . . . . . . . . . . . . . 100
5.1.1 Further IFIR optimizations . . . . . . . . . . . . . . . 102
5.1.2 Multirate implementation of IFIR design . . . . . . . 104
5.2 Multistage/Multirate Designs . . . . . . . . . . . . . . . . . . 108
5.2.1 Setting the number of stages . . . . . . . . . . . . . . 111
5.3 Multistage/Multirate Nyquist ﬁlters . . . . . . . . . . . . . . 112
5.3.1 Using IIR halfband ﬁlters . . . . . . . . . . . . . . . . 113
5.4 Multistage interpolation . . . . . . . . . . . . . . . . . . . . . 115
Digital Filters with MATLAB Ricardo A. Losada
4 CONTENTS
5.5 Summary and look ahead . . . . . . . . . . . . . . . . . . . . 118
6 Special Multirate Filters 120
6.1 Hold interpolators . . . . . . . . . . . . . . . . . . . . . . . . 121
6.2 Linear interpolators . . . . . . . . . . . . . . . . . . . . . . . . 125
6.3 CIC interpolators . . . . . . . . . . . . . . . . . . . . . . . . . 130
6.3.1 Design of CIC interpolators . . . . . . . . . . . . . . . 132
6.3.2 Gain of CIC interpolators . . . . . . . . . . . . . . . . 134
6.3.3 Further details of CIC ﬁlters . . . . . . . . . . . . . . . 136
6.4 CIC decimators . . . . . . . . . . . . . . . . . . . . . . . . . . 137
6.4.1 Design parameters . . . . . . . . . . . . . . . . . . . . 138
6.5 CIC compensators . . . . . . . . . . . . . . . . . . . . . . . . . 139
6.6 Farrow Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
6.6.1 Higherorder polynomials . . . . . . . . . . . . . . . . 144
6.6.2 Design of Farrow fractional delays . . . . . . . . . . . 146
6.6.3 Multirate Farrow ﬁlters . . . . . . . . . . . . . . . . . 147
6.6.4 Polynomial interpolation and maximally ﬂat ﬁltering 149
6.6.5 Using Farrow samplerate converters in multistage
designs . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
II Filter Implementation 154
7 Implementing FIR Filters 155
7.1 Some basics on implementing FIR ﬁlters . . . . . . . . . . . . 155
7.1.1 Directform ﬁlter structure . . . . . . . . . . . . . . . . 156
7.1.2 Symmetric directform ﬁlter structure . . . . . . . . . 157
7.1.3 Transposed directform ﬁlter structure . . . . . . . . . 158
7.2 Fixedpoint implementation . . . . . . . . . . . . . . . . . . . 160
7.2.1 Quantizing the ﬁlter’s coefﬁcients . . . . . . . . . . . 160
7.2.2 Fixedpoint ﬁltering: Directform structure . . . . . . 165
7.2.3 Fixedpoint ﬁltering: Transposed directform structure168
7.2.4 Quantization of the output signal . . . . . . . . . . . . 169
7.2.5 Evaluating the performance of the ﬁxedpoint ﬁlter . 171
8 Implementing IIR Filters 177
8.1 Some basics of IIR implementation . . . . . . . . . . . . . . . 177
8.1.1 The use of secondorder sections . . . . . . . . . . . . 177
Digital Filters with MATLAB Ricardo A. Losada
CONTENTS 5
8.1.2 Allpassbased implementations . . . . . . . . . . . . . 178
8.2 Fixedpoint implementation . . . . . . . . . . . . . . . . . . . 181
8.2.1 Fixedpoint ﬁltering . . . . . . . . . . . . . . . . . . . 182
8.2.2 Autoscaling . . . . . . . . . . . . . . . . . . . . . . . . 187
8.2.3 Evaluating ﬁlter performance using the magnitude
response estimate . . . . . . . . . . . . . . . . . . . . . 188
III Appendices 190
A Summary of relevant ﬁlter design commands 191
A.1 Filter Design (fdesign) . . . . . . . . . . . . . . . . . . . . . . 191
A.1.1 Setup design speciﬁcations . . . . . . . . . . . . . . . 191
A.1.2 Design options . . . . . . . . . . . . . . . . . . . . . . 192
A.1.3 Design analysis/validation . . . . . . . . . . . . . . . 193
A.2 Selecting ﬁlter structure . . . . . . . . . . . . . . . . . . . . . 193
A.3 Scaling IIR SOS structures . . . . . . . . . . . . . . . . . . . . 194
A.4 Designing multirate ﬁlters . . . . . . . . . . . . . . . . . . . . 195
A.5 Converting to ﬁxed point . . . . . . . . . . . . . . . . . . . . 195
A.6 Generating Simulink blocks . . . . . . . . . . . . . . . . . . . 197
A.7 Graphical User Interface . . . . . . . . . . . . . . . . . . . . . 198
B Sampling, Downsampling, Upsampling, and Analog Reconstruc
tion 199
B.1 Sampling an analog signal . . . . . . . . . . . . . . . . . . . . 201
B.1.1 Bandpass sampling . . . . . . . . . . . . . . . . . . . . 205
B.2 Sampling a discretetime signal: downsampling . . . . . . . 206
B.2.1 Filtering to avoid aliasing when downsampling . . . 208
B.2.2 Downsampling bandpass signals . . . . . . . . . . . . 209
B.3 Increasing the sampling rate of a signal . . . . . . . . . . . . 209
B.4 Reconstructing an analog signal . . . . . . . . . . . . . . . . . 211
B.5 Practical sampling and analog reconstruction . . . . . . . . . 212
B.5.1 Oversampling . . . . . . . . . . . . . . . . . . . . . . . 214
C Case Study: Comparison of Various Design Approaches 219
D Overview of FixedPoint Arithmetic 222
D.1 Some ﬁxedpoint basics . . . . . . . . . . . . . . . . . . . . . 223
Digital Filters with MATLAB Ricardo A. Losada
6 CONTENTS
D.2 Quantization of signals and SNR . . . . . . . . . . . . . . . . 223
D.2.1 Quantizing impulse responses for FIR ﬁlters . . . . . 227
D.3 Fixedpoint arithmetic . . . . . . . . . . . . . . . . . . . . . . 228
D.3.1 Fixedpoint addition . . . . . . . . . . . . . . . . . . . 228
D.3.2 Fixedpoint multiplication . . . . . . . . . . . . . . . . 230
D.4 Quantization noise variance . . . . . . . . . . . . . . . . . . . 232
D.5 Quantization noise passed through a linear ﬁlter . . . . . . . 233
D.5.1 Computing the average power of the output noise . . 234
D.6 Oversampling noiseshaping quantizers . . . . . . . . . . . . 234
Digital Filters with MATLAB Ricardo A. Losada
Preface
This document
∗
constitutes a tutorial on design and implementation of
digital ﬁlters in MATLAB. The tutorial is based on functionality from the
Filter Design Toolbox™.
The document covers the design of FIR and IIR singlerate and mul
tirate ﬁlters. It also discusses advanced design techniques such as multi
rate/multistage decimation/interpolation and the use of special multirate
ﬁlters such as allpassbased polyphase IIR ﬁlters, CIC ﬁlters, and Farrow
ﬁlters.
The tutorial focuses on practical aspects of ﬁlter design and implemen
tation, and on the advantages and disadvantages of the different design
algorithms. The theory behind the design algorithms is kept to a minimal.
∗
This document may be updated from time to time. The latest version can be found at
www.mathworks.com/matlabcentral
Part I
Filter Design
Chapter 1
Basic FIR Filter Design
Overview
In this chapter we discuss the basic principles of FIR ﬁlter design. We con
centrate mostly on lowpass ﬁlters, but most of the results apply to other
response types as well. We discuss the basic trade offs and the degrees
of freedom available for FIR ﬁlter design. We motivate the use of optimal
designs and introduce both optimal equiripple and optimal leastsquares
designs. We then discuss optimal minimumphase designs as a way of
surpassing in some sense comparable optimal linearphase designs. We
introduce sloped equiripple designs as a compromise to obtain equiripple
passband yet nonequiripple stopband. We also mention a few caveats
with equiripple ﬁlter design. We end with an introductory discussion of
different ﬁlter structures that can be used to implement an FIR ﬁlter in
hardware.
The material presented here is based on [1] and [2]. However, it has
been expanded and includes newer syntax and features from the Filter
Design Toolbox.
1.1 Why FIR ﬁlters?
There are many reasons why FIR ﬁlters are very attractive for digital ﬁlter
design. Some of them are:
• Simple robust way of obtaining digital ﬁlters
10 Basic FIR Filter Design
• Inherently stable when implemented non recursively
• Free of limit cycles when implemented non recursively
• Easy to attain linear phase
• Simple extensions to multirate and adaptive ﬁlters
• Relatively straightforward to obtain designs to match custom mag
nitude responses
• Some vendors and specialized hardware only support FIR
• Low sensitivity to quantization effects compared to many IIR ﬁlters
FIR ﬁlters have some drawbacks however. The most important is that
they can be computationally expensive to implement. Another is that
they have a long transient response. It is commonly thought that IIR ﬁl
ters must be used when computational power is at a premium. This is
certainly true in some cases. However, in many cases, the use of multi
stage/multirate techniques can yield FIR implementations that can com
pete (and even surpass) IIR implementations while retaining the nice char
acteristics of FIR ﬁlters such as linearphase, stability, and robustness to
quantization effects.
∗
However, these efﬁcient multistage/multirate de
signs tend to have very large transient responses, so depending on the
requirements of the ﬁlter, IIR designs may still be the way to go.
In terms of the long transient response, we will show in Chapter 2
that minimumphase FIR ﬁlters can have a shorter transient response than
comparable IIR ﬁlters.
1.2 Lowpass ﬁlters
The ideal lowpass ﬁlter is one that allows through all frequency compo
nents of a signal below a designated cutoff frequency ω
c
, and rejects all
frequency components of a signal above ω
c
.
∗
That being said, there are also modern IIR design techniques that lend themselves to
efﬁcient multirate implementations and are extremely computationally efﬁcient. We are
referring here to more traditional IIR designs implemented using directformI or II struc
tures, possibly in cascaded secondorder section form.
Digital Filters with MATLAB Ricardo A. Losada
1.2 Lowpass ﬁlters 11
Its frequency response satisﬁes
H
LP
(e
jω
) =
1, 0 ≤ ω ≤ ω
c
0, ω
c
< ω ≤ π
(1.1)
The impulse response of the ideal lowpass ﬁlter (1.1) can easily be
found to be [3]
h
LP
[n] =
sin(ω
c
n)
πn
, −∞< n < ∞. (1.2)
1.2.1 FIR lowpass ﬁlters
Because the impulse response required to implement the ideal lowpass
ﬁlter is inﬁnitely long, it is impossible to design an ideal FIR lowpass ﬁlter.
Finite length approximations to the ideal impulse response lead to the
presence of ripples in both the passband (ω < ω
c
) and the stopband (ω >
ω
c
) of the ﬁlter, as well as to a nonzero transition width between the pass
band and stopband of the ﬁlter (see Figure 1.1).
1.2.2 FIR ﬁlter design speciﬁcations
Both the passband/stopband ripples and the transition width are unde
sirable but unavoidable deviations from the response of an ideal lowpass
ﬁlter when approximating with a ﬁnite impulse response. Practical FIR
designs typically consist of ﬁlters that meet certain design speciﬁcations,
i.e., that have a transition width and maximum passband/stopband rip
ples that do not exceed allowable values.
In addition, one must select the ﬁlter order, or equivalently, the length
of the truncated impulse response.
Auseful metaphor for the design speciﬁcations in FIRdesign is to think
of each speciﬁcation as one of the angles in a triangle as in Figure 1.2
∗
.
The metaphor is used to understand the degrees of freedom available
when designating design speciﬁcations. Because the sum of the angles is
ﬁxed, one can at most select the values of two of the speciﬁcations. The
third speciﬁcation will be determined by the design algorithm utilized.
∗
For the ripples we should more generally speak of some measure or norm of them.
The peak ripple corresponding to the L
∞
norm is the most commonly used measure, but
other norms are possible.
Digital Filters with MATLAB Ricardo A. Losada
12 Basic FIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−0.2
0
0.2
0.4
0.6
0.8
1
1.2
Normalized Frequency (×π rad/sample)
A
m
p
l
i
t
u
d
e
Zero−Phase Response
Ideal
lowpass
filter
Transition
width
Passband ripple
Stopband ripple
Figure 1.1: Illustration of the typical deviations from the ideal lowpass ﬁlter when ap
proximating with an FIR ﬁlter, ω
c
= 0.4π.
Moreover, as with the angles in a triangle, if we make one of the speciﬁca
tions larger/smaller, it will impact one or both of the other speciﬁcations.
Example 1 As an example, consider the design of an FIR ﬁlter that meets the
following speciﬁcations:
Speciﬁcations Set 1
1. Cutoff frequency: 0.4π rad/sample
2. Transition width: 0.06π rad/sample
3. Maximum passband/stopband ripple: 0.05
The ﬁlter can easily be designed with the truncatedandwindowed impulse re
sponse algorithm (a.k.a. the “window method”) if we use a Kaiser window
∗
:
∗
Notice that when specifying frequency values in MATLAB, the factor of π should be
omitted.
Digital Filters with MATLAB Ricardo A. Losada
1.2 Lowpass ﬁlters 13
Transition
width
peak passband/
stopband ripple
Filter order
Figure 1.2: FIR design speciﬁcations represented as a triangle.
Fp = 0.4  0.06/2; Fst = 0.4 + 0.06/2;
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',Fp,Fst,0.05,0.05,'linear');
design(Hf,'kaiserwin');
The zerophase response of the ﬁlter is shown in Figure 1.3. Note that since we
have ﬁxed the allowable transition width and peak ripples, the order is determined
for us.
Close examination at the passbandedge frequency
∗
, ω
p
= 0.37π, and at the
stopbandedge frequency, ω
s
= 0.43π, shows that the peak passband/stopband
ripples are indeed within the allowable speciﬁcations. Usually the speciﬁcations
are exceeded because the order is rounded to the next integer greater than the
actual value required.
∗
The passbandedge frequency is the boundary between the passband and the transition
band. If the transition width is T
w
, the passbandedge frequency ω
p
is given in terms of
the cutoff frequency ω
c
by ω
p
= ω
c
− T
w
/2. Similarly, the stopbandedge frequency is
given by ω
s
= ω
c
+ T
w
/2.
Digital Filters with MATLAB Ricardo A. Losada
14 Basic FIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Normalized Frequency (×π rad/sample)
A
m
p
l
i
t
u
d
e
Zero−phase Response
Figure 1.3: Kaiser window design meeting prescribed speciﬁcations.
1.2.3 Working with Hertz rather than normalized frequency
In many applications the speciﬁcations are given in terms of absolute fre
quency in Hertz rather than in terms of normalized frequency. Conversion
between one and the other is straightforward. Recall that normalized fre
quency is related to absolute frequency by
ω =
2πf
f
s
where f is absolute frequency in cycles/second, f
s
is the sampling fre
quency in samples/second, and ω is normalized frequency in radians/sample.
Suppose the speciﬁcations for a ﬁlter design problem include a pass
band frequency of 250 Hz, a stopband frequency of 300 Hz, and a sam
pling frequency of 1 kHz. The corresponding normalized passband and
stopband frequencies are 0.5π and 0.6π respectively.
However, it is not necessary to perform such conversion manually. It
is possible to specify design parameters directly in Hertz.
For example, the following two ﬁlters H1 and H2 are identical.
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.5,.6,1,80);
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 15
H1 = design(Hf);
Hf2 = fdesign.lowpass('Fp,Fst,Ap,Ast',250,300,1,80,1000);
H2 = design(Hf2);
Notice that we don’t add 'Fs' to the string 'Fp,Fst,Ap,Ast' (or any
other speciﬁcation string) when we specify parameters in Hertz. Simply
appending the sampling frequency to the other design parameters indi
cates that all frequencies speciﬁed are given in Hertz.
1.3 Optimal FIR ﬁlter design
While the truncatedandwindowed impulse response design algorithm
is very simple and reliable, it is not optimal in any sense. The designs
it produces are generally inferior to those produced by algorithms that
employ some optimization criteria in that it will have greater order, greater
transition width or greater passband/stopband ripples. Any of these is
typically undesirable in practice, therefore more sophisticated algorithms
come in handy.
1.3.1 Optimal FIR designs with ﬁxed transition width and
ﬁlter order
Optimal designs are computed by minimizing some measure of the de
viation between the ﬁlter to be designed and the ideal ﬁlter. The most
common optimal FIR design algorithms are based on ﬁxing the transition
width and the order of the ﬁlter. The deviation from the ideal response is
measured only by the passband/stopband ripples. This deviation or error
can be expressed mathematically as [4]
E(ω) = H
a
(ω) − H
LP
(e
jω
), ω ∈ Ω
where H
a
(ω) is the zerophase response of the designed ﬁlter and Ω =
[0, ω
p
] ∪ [ω
s
, π]. It is still necessary to deﬁne a measure to determine “the
size” of E(ω)  the quantity we want to minimize as a result of the op
timization. The most often used measures are the L
∞
norm (E(ω)
∞

minimax designs) and the L
2
norm (E(ω)
2
 leastsquares designs).
Digital Filters with MATLAB Ricardo A. Losada
16 Basic FIR Filter Design
In order to allow for different peak ripples in the passband and stop
band, a weighting function, W(ω) is usually introduced,
E
W
(ω) = W(ω)[H
a
(ω) − H
LP
(e
jω
)], ω ∈ Ω
Linearphase designs
A ﬁlter with linearphase response is desirable in many applications, no
tably image processing and data transmission. One of the desirable char
acteristics of FIR ﬁlters is that they can be designed very easily to have
linear phase. It is well known [5] that linearphase FIR ﬁlters will have
impulse responses that are either symmetric or antisymmetric. For these
types of ﬁlters, the zerophase response can be determined analytically
[5], and the ﬁlter design problem becomes a well behaved mathemati
cal approximation problem [6]: Determine the best approximation to a
given function (the ideal lowpass ﬁlter’s frequency response) by means of
a polynomial (the FIR ﬁlter) of a given order. By “best” it is meant the one
which minimizes the difference between them  E
W
(ω)  according to a
given measure.
The equiripple design implements an algorithm developed in [7] that
computes a solution to the design problem for linearphase FIR ﬁlters in
the L
∞
norm case. The design problem is essentially to ﬁnd a ﬁlter that
minimizes the maximum error between the ideal and actual ﬁlters. This
type of design leads to socalled equiripple ﬁlters, i.e. ﬁlters in which the
peak deviations from the ideal response are all equal.
The firls design implements an algorithm to compute solution for
linearphase FIR ﬁlters in the L
2
norm case. The design problem is to ﬁnd
a ﬁlter that minimizes the energy of the error between ideal and actual
ﬁlters.
Equiripple ﬁlters
Linearphase equiripple ﬁlters are desirable because they have the small
est maximum deviation from the ideal ﬁlter when compared to all other
linearphase FIR ﬁlters of the same order. Equiripple ﬁlters are ideally
suited for applications in which a speciﬁc tolerance must be met. For ex
ample, if it is necessary to design a ﬁlter with a given minimum stopband
attenuation or a given maximum passband ripple.
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 17
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35
0.96
0.97
0.98
0.99
1
1.01
1.02
1.03
1.04
1.05
1.06
Normalized Frequency (×π rad/sample)
A
m
p
l
i
t
u
d
e
Zero−phase Response
Kaiser−window design
Equiripple design
Figure 1.4: Passband ripple for of both the Kaiserwindowdesigned FIR ﬁlter and the
equirippledesigned FIR ﬁlter.
Example 2 The Kaiserwindow design of Example 1 was of 42nd order. With
this same order, an equiripple ﬁlter (with ﬁxed transition width) can be designed
that is superior to the Kaiserwindow design:
Fp = 0.4  0.06/2; Fst = 0.4 + 0.06/2;
Hf = fdesign.lowpass('N,Fp,Fst',42,Fp,Fst);
Heq = design(Hf,'equiripple');
Figure 1.4 shows the superposition of the passband details for the ﬁlters de
signed with the Kaiser window and with the equiripple design. Clearly the
maximum deviation is smaller for the equiripple design. In fact, since the ﬁlter
is designed to minimize the maximum ripple (minimax design), we are guaran
teed that no other linearphase FIR ﬁlter of 42nd order will have a smaller peak
ripple for the same transition width.
We can measure the passband ripple and stopband attenuation in dB units
using the measure command,
Meq = measure(Heq);
Digital Filters with MATLAB Ricardo A. Losada
18 Basic FIR Filter Design
If we compare the measurements of the equiripple design to those of the Kaiser
window design, we can verify for instance that the equiripple design provides a
minimum stopband attenuation of 29.0495 dB compared to 25.8084 dB for the
Kaiserwindow design.
Leastsquares ﬁlters
Equiripple designs may not be desirable if we want to minimize the en
ergy of the error (between ideal and actual ﬁlter) in the passband/stopband.
Consequently, if we want to reduce the energy of a signal as much as pos
sible in a certain frequency band, leastsquares designs are preferable.
Example 3 For the same speciﬁcations, Hf, as the equiripple design of Example
2, a leastsquares FIR design can be computed from
Hls = design(Hf,'firls');
The stopband energy for this case is given by
E
sb
=
2
2π
π
0.43π
H(e
jω
)
2
dω
where H(e
jω
) is the frequency response of the ﬁlter.
In this case, the stopband energy for the equiripple ﬁlter is approximately
3.5214004 while the stopband energy for the leastsquares ﬁlter is 6.6213e005.
(As a reference, the stopband energy for the Kaiserwindow design for this order
and transition width is 1.2329e004).
The stopband details for both equiripple design and the leastsquares design
are shown in Figure 1.5.
So while the equiripple design has less peak error, it has more “to
tal” error, measured in terms of its energy. However, although the least
squares design minimizes the energy in the ripples in both the passband
and stopband, the resulting peak passband ripple is always larger than
that of a comparable equiripple design. Therefore there is a larger distur
bance on the signal to be ﬁltered for a portion of the frequencies that the
ﬁlter should allow to pass (ideally undisturbed). This is a drawback of
leastsquares designs. We will see in Section 1.3.5 that a possible compro
mise is to design equiripple ﬁlters in such a way that the maximum ripple
in the passband is minimized, but with a sloped stopband that can reduce
the stopband energy in a manner comparable to a leastsquares design.
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 19
0.5 0.6 0.7 0.8 0.9 1
−0.05
0
0.05
0.1
0.15
Normalized Frequency: 0.4858398
Amplitude: 0.0352379
Normalized Frequency: 0.4299316
Amplitude: 0.08960634
Normalized Frequency (×π rad/sample)
A
m
p
l
i
t
u
d
e
Zero−phase Response
Equiripple design
Least−squares design
Figure 1.5: Comparison of an optimal equiripple FIR design and an optimal leastsquares
FIR design. The equiripple ﬁlter has a smaller peak error, but larger overall error.
Using weights
Both equiripple and leastsquares designs can be further controlled by
using weights to instruct the algorithm to provide a better approximation
to the ideal ﬁlter in certain bands. This is useful if it is desired to have less
ripple in one band than in another.
Example 4 In Example 2 above, the ﬁlter that was designed had the same ripples
in the passband and in the stopband. This is because we implicitly were using a
weight of one for each band. If it is desired to have a stopband ripple that is say ten
times smaller than the passband ripple, we must give a weight that is ten times
larger:
Heq2 = design(Hf,'equiripple','Wpass',1,'Wstop',10);
The result is plotted in Figure 1.6.
It would be desirable to have an analytic relation between the maxi
mum ripples in a band and the weight in such band. Unfortunately no
such relation exists. If the design speciﬁcations require a speciﬁc maxi
mum ripple amount, say δ
p
in the passband and δ
s
in the stopband (both
in linear units, not decibels), for a lowpass ﬁlter we can proceed as follows:
Digital Filters with MATLAB Ricardo A. Losada
20 Basic FIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−0.1
−0.08
−0.06
−0.04
−0.02
0
0.02
0.04
0.06
0.08
0.1
Normalized Frequency (× π rad/sample)
A
m
p
l
i
t
u
d
e
Passband and Stopband Ripples
Figure 1.6: Passband and stopband ripples obtained from weighing the stopband 10 times
higher than the passband.
1. Set the passband weight to one.
2. Set the stopband weight to
δ
p
δ
s
.
since both the ﬁlter order and the transition width are assumed to be ﬁxed,
this will not result in the desired ripples unless we are very lucky. How
ever, the relative amplitude of the passband ripple relative to the stopband
ripple will be correct. In order to obtain a ripple of δ
p
in the passband and
δ
s
in the stopband we need to vary either the ﬁlter order or the transition
width.
The procedure we have just described requires trialanderror since ei
ther the ﬁlter order or the transition width may need to be adjusted many
times until the desired ripples are obtained. Instead of proceeding in such
manner, later we will describe ways of designing ﬁlters for given pass
band/stopband ripples and either a ﬁxed transition width or a ﬁxed ﬁlter
order.
For leastsquares designs, the relative weights control not the ampli
tude of the ripple but its energy relative to the bandwidth it occupies. This
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 21
means that if we weigh the stopband ten times higher than the passband,
the energy in the stopband relative to the stopband bandwidth will be 10
times smaller than the energy of the ripples in the passband relative to the
passband bandwidth. For the case of lowpass ﬁlters these means that
E
sb
π −ω
s
=
2
2π(π −ω
s
)
π
ω
s
H(e
jω
)
2
dω
will be ten times smaller than
E
pb
ω
p
=
2
2π(ω
p
)
ω
p
0
H(e
jω
)
2
dω.
Minimumphase designs
One of the advantages of FIR ﬁlters, when compared to IIR ﬁlters, is the
ability to attain exact linear phase in a straightforward manner. As we
have already mentioned, the linear phase characteristic implies a symme
try or antisymmetry property for the ﬁlter coefﬁcients. Nevertheless, this
symmetry of the coefﬁcients constraints the possible designs that are at
tainable. This should be obvious since for a ﬁlter with N + 1 coefﬁcients,
only N/2 + 1 of these coefﬁcients are freely assignable (assuming N is
even). The remaining N/2 coefﬁcients are immediately determined by the
linear phase constraint.
If one is able to relax the linear phase constraint (i.e. if the application at
hand does not require a linear phase characteristic), it is possible to design
minimumphase equiripple ﬁlters that are superior to optimal equiripple
linearphase designs based on a technique described in [8].
Example 5 For the same speciﬁcation set of Example 2 the following minimum
phase design has both smaller peak passband ripple and smaller peak stopband
ripple
∗
than the linearphase equiripple design of that example:
Hmin = design(Hf,'equiripple','Wpass',1,'Wstop',10,...
'minphase',true);
It is important to note that this is not a totally unconstrained design.
The minimumphase requirement restricts the resulting ﬁlter to have all
∗
This can easily be veriﬁed using the measure command.
Digital Filters with MATLAB Ricardo A. Losada
22 Basic FIR Filter Design
its zeros on or inside the unit circle.
∗
However, the design is optimal in
the sense that it satisﬁes the minimumphase alternation theorem [9].
Having smaller ripples for the same ﬁlter order and transition width
is not the only reason to use a minimumphase design. The minimum
phase characteristic means that the ﬁlter introduces the lowest possible
phase offset (that is, the smallest possible transient delay) to a signal being
ﬁltered.
Example 6 Compare the delay introduced by the linearphase ﬁlter of Example 2
to that introduced by the minimumphase ﬁlter designed above. The signal to be
ﬁltered is a sinusoid with frequency 0.1π rad/sample.
n = 0:500;
x = sin(0.1*pi*n');
yeq = filter(Heq,x);
ymin = filter(Hmin,x);
The output from both ﬁlters are plotted overlaid in Figure 1.7. The delay intro
duced is equal to the group delay of the ﬁlter at that frequency. Since group
delay is the negative of the derivative of phase with respect to frequency, the
groupdelay of a linearphase ﬁlter is a constant equal to half the ﬁlter order.
This means that all frequencies are delayed by the same amount. On the other
hand, minimumphase ﬁlters do not have constant groupdelay since their phase
response is not linear. The groupdelays of both ﬁlters can be visualized using
fvtool(Heq,Hmin,'Analysis','Grpdelay');. The plot of the groupdelays
is shown in Figure 1.8.
1.3.2 Optimal equiripple designs with ﬁxed transition width
and peak passband/stopband ripple
We have seen that the optimal equiripple designs outperformKaiserwindow
designs for the same order and transition width. The differences are even
more dramatic when the passband ripple and stopband ripple speciﬁca
tions are different. The reason is that the truncatedandwindowed im
pulse response methods always give a result with approximately the same
passband and stopband peak ripple. Therefore, always the more stringent
∗
Given any linearphase FIR ﬁlter with non negative zerophase characteristic, it is pos
sible to extract the minimumphase spectral factor using the ﬁrminphase function.
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 23
0 10 20 30 40 50 60 70 80 90 100
−1
−0.8
−0.6
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1
Sample index (n)
A
m
p
l
i
t
u
d
e
Linear−phase filtered sinusoid
Minimum−phase filtered sinusoid
Figure 1.7: Sinusoid ﬁltered with a linearphase ﬁlter and a minimumphase ﬁlter of the
same order.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
5
10
15
20
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Linear−phase filter
Minimum−phase filter
Figure 1.8: Groupdelay of a linearphase ﬁlter and a minimumphase ﬁlter of the same
order.
Digital Filters with MATLAB Ricardo A. Losada
24 Basic FIR Filter Design
peak ripple constraint is satisﬁed, resulting in exceeding (possibly signif
icantly) all other ripple constraints at the expense of unnecessarily large
ﬁlter order.
To illustrate this, we turn to a different equiripple design in which both
the peak ripples and the transition width are ﬁxed. Referring back to the
triangle in Figure 1.2, this means the resulting ﬁlter order will come from
the design algorithm.
Example 7 Consider the following speciﬁcations:
Speciﬁcations Set 2
1. Cutoff frequency: 0.375π rad/sample
2. Transition width: 0.15π rad/sample
3. Maximum passband ripple: 0.13 dB
4. Minimum stopband attenuation: 60 dB
An equiripple design of this ﬁlter,
Fp = 0.375  0.15/2; Fst = 0.375 + 0.15/2;
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',Fp,Fst,0.13,60);
Heq = design(Hf,'equiripple');
cost(Heq)
results in a ﬁlter of 37th order (38 taps) as indicated by the cost command. By
comparison, a Kaiserwindow design requires a 49th order ﬁlter (50 taps) to meet
the same speciﬁcations. The passband details can be seen in Figure 1.9. It is evi
dent that the Kaiserwindow design oversatisﬁes the requirements signiﬁcantly.
Minimumphase designs with ﬁxed transition width and peak passband/stopband
ripple
The same procedure to design minimumphase ﬁlters with ﬁxed ﬁlter or
der and ﬁxed transition width can be used to design minimumphase ﬁl
ters with ﬁxed transition width and peak passband/stopband ripple. In
this case, rather than obtaining smaller ripples, the beneﬁt is meeting the
same transition width and peak passband/stopband ripples with a re
duced ﬁlter order.
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 25
0 0.05 0.1 0.15 0.2 0.25 0.3
0.992
0.994
0.996
0.998
1
1.002
1.004
1.006
1.008
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
Kaiser window design
Equiripple design
Figure 1.9: Passband ripple details for both the Kaiserwindowdesigned FIR ﬁlter and
the equirippledesigned FIR ﬁlter. The Kaiserwindow design oversatisﬁes the require
ment at the expense of increase number of taps.
Example 8 Consider the following speciﬁcations:
Speciﬁcations Set 3
1. Cutoff frequency: 0.13π rad/sample
2. Transition width: 0.02π rad/sample
3. Maximum passband ripple: 0.175 dB
4. Minimum stopband attenuation: 60 dB
The minimum order needed to meet such speciﬁcations with a linearphase
FIR ﬁlter is 262. This ﬁlter must be the result of an optimal equiripple design.
If we relax the linearphase constraint however, the equiripple design (based
on the algorithm proposed in [8]) results in a minimumphase FIR ﬁlter of 216th
order that meets the speciﬁcations:
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.12,.14,.175,60);
Hmin = design(Hf,'equiripple','minphase',true);
cost(Hmin)
Digital Filters with MATLAB Ricardo A. Losada
26 Basic FIR Filter Design
Note that for these designs minimumphase ﬁlters will have a much
smaller transient delay not only because of their minimumphase property
but also because their ﬁlter order is lower than that of a comparable linear
phase ﬁlter. In fact this is true in general we had previously seen that a
ﬁlter with the same transition width and ﬁlter order with minimumphase
has a smaller delay than a corresponding linearphase ﬁlter. Moreover,
the minimumphase ﬁlter has smaller ripples so that the two ﬁlters are not
really comparable. In order to compare apples to apples, the order of the
linearphase ﬁlter would have to increased until the ripples are the same
as those of the minimumphase design. This increase in ﬁlter order would
of course further increase the delay of the ﬁlter.
1.3.3 Optimal equiripple designs with ﬁxed peak ripple
and ﬁlter order
So far we have illustrated equiripple designs with ﬁxed transition width
and ﬁxed order and designs with ﬁxed transition width and ﬁxed peak
ripple values. The Filter Design Toolbox also provides algorithms for de
signs with ﬁxed peak ripple values and ﬁxed ﬁlter order [10]. This gives
maximumﬂexibility in utilizing the degrees of freedomavailable to design
an FIR ﬁlter.
We have seen that, when compared to Kaiserwindow designs, ﬁxing
the transition width and ﬁlter order results in an optimal equiripple de
sign with smaller peak ripple values, while ﬁxing the transition width and
peak ripple values results in a ﬁlter with less number of taps. Naturally,
ﬁxing the ﬁlter order and the peak ripple values should result in a smaller
transition width.
Example 9 Consider the following design of an equiripple with the same cutoff
frequency as in Example 7. The ﬁlter order is set to be the same as that needed for
a Kaiserwindow design to meet the ripple speciﬁcations
Hf = fdesign.lowpass('N,Fc,Ap,Ast',49,0.375,0.13,60);
Heq = design(Hf,'equiripple');
The comparison of this new design with the Kaiserwindow design is shown in
Figure 1.10. The transition width has been reduced from 0.15π to approximately
0.11π.
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 27
0.32 0.34 0.36 0.38 0.4 0.42 0.44
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Normalized Frequency (×π rad/sample)
A
m
p
l
i
t
u
d
e
Zero−phase Response
Kaiser−window design
Equiripple design
Figure 1.10: Comparison of a Kaiserwindowdesigned FIR ﬁlter and an optimal equirip
ple FIR ﬁlter of the same order and peak ripple values. The equiripple design results in a
reduced transitionwidth.
Minimumphase designs with ﬁxed peak ripple and ﬁlter order
Once again, if linearphase is not a requirement, a minimumphase ﬁlter
can be designed that is a superior in some sense to a comparable linear
phase ﬁlter. In this case, for the same ﬁlter order and peak ripple value, a
minimumphase design results in a smaller transition width than a linear
phase design.
Example 10 Compared to the 50th order linearphase design Heq, the following
design has a noticeably smaller transition width:
Hmin = design(Hf,'equiripple','minphase',true);
1.3.4 Constrainedband equiripple designs
Sometimes when designing lowpass ﬁlters (for instance for decimation
purposes) it is necessary to guarantee that the stopband of the ﬁlter begins
at a speciﬁc frequency value and that the ﬁlter provides a given minimum
stopband attenuation.
Digital Filters with MATLAB Ricardo A. Losada
28 Basic FIR Filter Design
If the ﬁlter order is ﬁxed  for instance when using specialized hard
ware  there are two alternatives available in the Filter Design Toolbox for
optimal equiripple designs. One possibility is to ﬁx the transition width,
the other is to ﬁx the passband ripple.
Example 11 For example, the design speciﬁcations of Example 7 call for a stop
band that extends from 0.45π to π and provide a minimum stopband attenuation
of 60 dB. Instead of a minimumorder design, suppose the ﬁlter order available is
40 (41 taps). One way to design this ﬁlter is to provide the same maximum pass
band ripple of 0.13 dB but to give up control of the transition width. The result
will be a ﬁlter with the smallest possible transition width for any linearphase FIR
ﬁlter of that order that meets the given speciﬁcations.
Hf = fdesign.lowpass('N,Fst,Ap,Ast',40,.45,0.13,60);
Heq = design(Hf,'equiripple');
If instead we want to ﬁx the transition width but not constrain the pass
band ripple, an equiripple design will result in a ﬁlter with the smallest
possible passband ripple for any linearphase FIR ﬁlter of that order that
meets the given speciﬁcations.
Hf = fdesign.lowpass('N,Fp,Fst,Ast',40,.3,.45,60);
Heq = design(Hf,'equiripple');
The passband details of the two ﬁlters are shown in Figure 1.11. Note
that both ﬁlters meet the Speciﬁcations Set 2 because the order used (40) is
larger than the minimumorder required (37) by an equiripple linear phase
ﬁlter to meet such speciﬁcations. The ﬁlters differ in how they “use” the
extra number of taps to better approximate the ideal lowpass ﬁlter.
1.3.5 Sloped equiripple ﬁlters
In many cases it is desirable to minimize the energy in the stopband of
a signal being ﬁltered. One common case is in the design of decimation
ﬁlters. In this case, the energy in the stopband of a signal after being ﬁl
tered aliases into the passband region. To minimize the amount of alias
ing, we want to minimize the stopband energy. Leastsquares ﬁlters can be
used for this, however, the drawback is that the passband presents larger
ﬂuctuations than may be desirable. An alternative is to design optimal
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 29
0 0.05 0.1 0.15 0.2 0.25 0.3
−0.06
−0.04
−0.02
0
0.02
0.04
0.06
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Fixed passband ripple
Fixed transition width
Figure 1.11: Comparison of a two optimal equiripple FIR ﬁlters of 40th order. Both
ﬁlters have the same stopbandedge frequency and minimum stopband attenuation. One
is optimized to minimize the transition width while the other is optimized to minimize the
passband ripple.
equiripple ﬁlters but allowing for a slope in the stopband of the ﬁlter. The
passband remains equiripple thus minimizing the distortion of the input
signal in that region.
There are many ways of shaping the slope of the stopband. One way
[11] is to allow the stopband to decay as (1/f )
k
, that is as a power of the
inverse of frequency. This corresponds to a decay of 6k dB per octave.
Another way of shaping the slope is to allow it to decay in logarithmic
fashion so that the decay appears linear in dB scale.
Of course there is a price to pay for the sloped stopband. Since the
design provides smaller stopband energy than a regular equiripple design,
the passband ripple, although equiripple, is larger than that of a regular
equiripple design. Also, the minimum stopband attenuation measured in
dB is smaller than that of a regular equiripple design.
Example 12 Consider an equiripple design similar to that of Example 2 but with
a stopband decaying as (1/f )
2
:
Fp = 0.4  0.06/2; Fst = 0.4 + 0.06/2;
Digital Filters with MATLAB Ricardo A. Losada
30 Basic FIR Filter Design
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Least squares
Sloped equiripple
Figure 1.12: Passband details of a sloped optimal equiripple FIR design and an optimal
leastsquares FIR design. The equiripple ﬁlter has a smaller peak error or smaller transi
tion width depending on the interpretation.
Hf = fdesign.lowpass('N,Fp,Fst',42,Fp,Fst);
Hsloped = design(Hf,'equiripple','StopbandShape','1/f',...
'StopbandDecay',2);
results in a stopband energy of approximately 8.4095e05, not much larger that
the leastsquares design (6.6213e005), while having a smaller transition width
(or peak passband ripple  depending on the interpretation). The passband details
of both the leastsquares design and the sloped equiripple design are shown in
Figure 1.12 (in dB). The stopband details are shown in Figure 1.13 (also in dB).
If we constrain the ﬁlter order, the passband ripple, and the minimum
stopband attenuation, it is easy to see the tradeoff between a steeper slope
and the minimum stopband attenuation that can be achieved. Something
has to give and since everything else is constrained, the transition width
increases as the slope increases as well.
Example 13 Design two ﬁlters with the same ﬁlter order, same passband ripple,
and same stopband attenuation. The slope of the stopband decay is zero for the
ﬁrst ﬁlter and 40 for the second.
Digital Filters with MATLAB Ricardo A. Losada
1.3 Optimal FIR ﬁlter design 31
0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95
−55
−50
−45
−40
−35
−30
−25
−20
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Least squares
Sloped equiripple
Figure 1.13: Stopband details of a sloped optimal equiripple FIR design and an optimal
leastsquares FIR design. The overall error of the equiripple ﬁlter approaches that of the
leastsquares design.
Hf = fdesign.lowpass('N,Fst,Ap,Ast',30,.3,0.4,40);
Heq = design(Hf,'equiripple','StopbandShape','linear',...
'StopbandDecay',0);
Heq2 = design(Hf,'equiripple','StopbandShape','linear',...
'StopbandDecay',40);
The second ﬁlter provides better total attenuation throughout the stopband. Since
everything else is constrained, the transition width is larger as a consequence.
This is easy to see with fvtool(Heq,Heq2).
It is also possible to design minimumphase sloped equiripple ﬁlters. These
designs possess similar advantages over linearphase designs as those de
scribed for other equiripple designs when linearity of phase is not a design
requirement.
Digital Filters with MATLAB Ricardo A. Losada
32 Basic FIR Filter Design
0 5 10 15 20 25 30 35 40
−0.02
0
0.02
0.04
0.06
0.08
0.1
Samples
A
m
p
l
i
t
u
d
e
Impulse Response
Figure 1.14: Impulse response of equiripple ﬁlter showing anomalous endpoints. These
end points are the result of an equiripple response.
1.4 Further notes on equiripple designs
1.4.1 Unusual endpoints in the impulse response
In some cases the impulse response of an equiripple design appears to be
anomalous. In particular, the end points seem to be incorrect. However,
these end points are in fact a consequence of an equiripple stopband. If
we remove the anomaly by say repeating the value in the sample closest
to the end point, the stopband is no longer equiripple.
Example 14 Consider the design of this lowpass ﬁlter with band edges that are
quite close to DC:
Hf = fdesign.lowpass('N,Fp,Fst',42,0.1,0.12);
Heq = design(Hf,'equiripple');
fvtool(Heq,'Analysis','impulse')
The impulse response is show in Figure 1.14. Notice that the two end points seem
completely out of place.
Digital Filters with MATLAB Ricardo A. Losada
1.4 Further notes on equiripple designs 33
If the anomalous endpoints are a problem
∗
, it is not always feasible to
modify them by replacing their value with that of their nearest neighbor
because sometimes it is more than just the two end points that are anoma
lous. Moreover, simply using the nearest neighbor removes the equiripple
property of the stopband in an uncontrolled way. It is preferable to use a
sloped equiripple design to control the shape of the stopband and at the
same time remove the anomalies.
Example 15 Compare the magnitude response and the impulse response of these
two designs using fvtool.
Hf = fdesign.lowpass('N,Fp,Fst',800,.064,.066);
Heq = design(Hf,'equiripple','Wpass',1 ,'Wstop',10);
Heq2 = design(Hf,'equiripple','Wpass',1 ,'Wstop',10,...
'StopbandShape','linear','StopbandDecay',80);
fvtool(Heq,Heq2)
A look at the impulse response reveals that adding a sloped stopband has altered
several of the end points of the impulse response removing the discontinuity.
1.4.2 Transition region anomalies
In equiripple design, the transition band between passband and stopband
or vice versa is treated as a don’t care region for optimization purposes.
That is, the frequency response is not optimized between bands with the
hope that the response will smoothly transition between them. This is the
case for lowpass and highpass ﬁlters, but may not be the case for ﬁlters
with more than two bands when the width of the transition bands differ
[4].
A possible solution is to reduce the larger transition bands to make
them all the same width. This of course incurs in some degradation in
the performance of the ﬁlter that will depend on what constraints are im
posed. If this is not feasible, another solution would be to include the
problematic transition band in the optimization by means of a arbitrary
magnitude design.
∗
For instance, when the impulse response is very long, sometimes only a subset of it is
stored in memory and the rest of the values are computed by curve ﬁtting or some other
interpolation scheme. In such cases the anomalous points pose a problem because the
curve ﬁtting is unlikely to reproduce them accurately.
Digital Filters with MATLAB Ricardo A. Losada
34 Basic FIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 1.15: Bandpass ﬁlter with transitionband anomaly due to having different
transitionband widths.
Example 16 Consider the design of a bandpass ﬁlter with a ﬁrst transition band
0.1π rad/sample wide and a second transition band 0.2π rad/sample wide:
Hf = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',...
.2,.3,.6,.8,60,1,60);
Heq = design(Hf,'equiripple');
The magnitude response is shown in Figure 1.15. The anomalies in the second
“don’tcare” band are obvious. The design can be ﬁxed by making the second
transition band 0.1π rad/sample wide. Since this is a minimumorder design, the
price to pay for this is an increase in the ﬁlter order required to meet the modiﬁed
speciﬁcations:
Hf2 = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',...
.2,.3,.6,.7,60,1,60);
Heq2 = design(Hf,'equiripple');
cost(Heq)
cost(Heq2)
Digital Filters with MATLAB Ricardo A. Losada
1.5 Maximallyﬂat FIR ﬁlters 35
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
10th−order maximally flat FIR filter
20th−order maximally flat FIR filter
Figure 1.16: Maximallyﬂat FIR ﬁlters. The smaller transition width in one of the ﬁlters
is achieved by increasing the ﬁlter order.
1.5 Maximallyﬂat FIR ﬁlters
Maximallyﬂat ﬁlters are ﬁlters in which both the passband and stopband
are as ﬂat as possible given a speciﬁc ﬁlter order.
As we should come to expect, the ﬂatness in the bands comes at the
expense of a large transition band (which will also be maximum). There is
one less degree of freedom with these ﬁlters than with those we have look
at so far. The only way to decrease the transition band is to increase the
ﬁlter order.
Example 17 Figure 1.16 shows two maximallyﬂat FIR ﬁlters. Both ﬁlters have
a cutoff frequency of 0.3π. The ﬁlter with smaller transition width has twice the
ﬁlter order as the other.
The Maximallyﬂat stopband of the ﬁlter means that its stopband at
tenuation is very large. However, this comes at the price of a very large
transition width. These ﬁlters are seldom used in practice (in particular
with ﬁxedpoint implementations) because when the ﬁlter’s coefﬁcients
are quantized to a ﬁnite number of bits, the large stopband cannot be
Digital Filters with MATLAB Ricardo A. Losada
36 Basic FIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−200
−150
−100
−50
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Double−precision floating−point
16−bit fixed−point
Figure 1.17: A maximallyﬂat FIR ﬁlter implemented with doubleprecision ﬂoating
point arithmetic and the same ﬁlter implemented with 16bit ﬁxedpoint coefﬁcients.
achieved (and often is not required anyway) but the large transition band
is still a liability.
Example 18 Compare the stopband attenuation of a maximallyﬂat FIRﬁlter im
plemented using doubleprecision ﬂoatingpoint arithmetic with that of the same
ﬁlter implemented with 16bit ﬁxedpoint coefﬁcients. The comparison of the two
implementations is shown in Figure 1.17. The ﬁxedpoint implementation starts
to differ signiﬁcantly from the ﬂoatingpoint implementation at about 7580 dB.
Nevertheless, both ﬁlters have the same large transition width.
The maximallyﬂat passband may be desirable because it causes min
imal distortion of the signal to be ﬁltered in the frequency band that we
wish to conserve after ﬁltering. So it may seem that a maximallyﬂat pass
band and an equiripple or perhaps sloped stopband could be a thought
after combination. However, if a small amount of ripple is allowed in the
passband it is always possible to get a smaller transition band and most
applications can sustain a small amount of passband ripple.
Example 19 We can approach a maximallyﬂat passband by making the pass
band ripple of an equiripple design progressively smaller. However, for the same
Digital Filters with MATLAB Ricardo A. Losada
1.6 Summary and look ahead 37
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
1 × 10
−3
dB passband ripple
1 × 10
−8
dB passband ripple
Figure 1.18: Equiripple ﬁlters with passband approximating maximal ﬂatness. The better
the approximation, the larger the transition band.
ﬁlter order and stopband attenuation, the transition width increases as a result.
Consider the following two ﬁlter designs:
Hf = fdesign.lowpass('N,Fc,Ap,Ast',70,.3,1e3,80);
Heq = design(Hf,'equiripple');
Hf2 = fdesign.lowpass('N,Fc,Ap,Ast',70,.3,1e8,80);
Heq2 = design(Hf2,'equiripple');
The two ﬁlters are shown in Figure 1.18. It is generally best to allow some pass
band ripple as long as the application at hand supports it given that a smaller
transition band results. The passband details are shown in Figure 1.19.
1.6 Summary and look ahead
Understanding FIR ﬁlter design is a matter of understanding the trade offs
involved and the degrees of freedom available. A drawback of FIR ﬁlters
is that the tend to require a large ﬁlter order and therefore a high compu
tational cost to achieve the speciﬁcations desired. There are many ways
of addressing this. One is to use IIR ﬁlters. Another is to use multistage
Digital Filters with MATLAB Ricardo A. Losada
38 Basic FIR Filter Design
0 0.05 0.1 0.15 0.2 0.25
−6
−4
−2
0
2
4
6
x 10
−4
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
1 × 10
−3
dB passband ripple
1 × 10
−8
dB passband ripple
Figure 1.19: Passband details of equiripple ﬁlters with very small passband ripple. The
ﬂatter passband is obtained at the expense of a larger transition band, i.e. a smaller usable
passband.
and/or multirate techniques that use various FIR ﬁlters connected in cas
cade (in series) in such a way that each ﬁlter shares part of the ﬁltering
duties while having reduced complexity when compared to a singlestage
design. The idea is that for certain speciﬁcations to combined complexity
of the ﬁlters used in multistage design is lower than the complexity of a
comparable singlestage design.
We will be looking at all these approaches in the following chapters.
We will then look into implementation of ﬁlters and discuss issues that
arise when implementing a ﬁlter using ﬁxedpoint arithmetic.
Digital Filters with MATLAB Ricardo A. Losada
Chapter 2
Basic IIR Filter Design
Overview
One of the drawbacks of FIR ﬁlters is that they require a large ﬁlter order
to meet some design speciﬁcations. If the ripples are kept constant, the
ﬁlter order grows inversely proportional to the transition width. By using
feedback, it is possible to meet a set of design speciﬁcations with a far
smaller ﬁlter order than a comparable FIR ﬁlter
∗
. This is the idea behind
IIR ﬁlter design. The feedback in the ﬁlter has the effect that an impulse
applied to the ﬁlter results in a response that never decays to zero, hence
the term inﬁnite impulse response (IIR).
We will start this chapter by discussing classical IIR ﬁlter design. The
design steps consist of designing the IIR ﬁlter in the analogtime domain
where closedform solutions are well known and then using the bilinear
transformation to convert the design to the digital domain. We will see
that the degrees of freedom available are directly liked to the design al
gorithm chosen. Butterworth ﬁlters provide very little control over the
resulting design since it is basically a maximallyﬂat design. Chebyshev
designs increase the degrees of freedom by allowing ripples in the pass
band (type I Chebyshev) or the stopband (type II Chebyshev). Elliptic
ﬁlters allow for maximum degrees of freedom by allowing for ripples in
both the passband and the stopband. In fact, Chebyshev and Butterworth
designs can be seen as a special case of elliptic designs, so usually one
should only concentrate on elliptic ﬁlter design, decreasing the passband
∗
However, see Chapter 5.
40 Basic IIR Filter Design
ripples and/or increasing the stopband attenuation enough to approach
Chebyshev or Butterworth designs when so desired.
After looking at classical designs, we move on to examine design tech
niques that are based on optimization directly in the digital domain.
2.1 Why IIR ﬁlters
IIR ﬁlters are usually used when computational resources are at a pre
mium. However, stable, causal IIR ﬁlters cannot have perfectly linear
phase, so that IIR ﬁlters tend to be avoided when linearity of phase is a
requirement. Also, computational savings that are comparable to using
IIR ﬁlters can be achieved for certain design parameters by using multi
stage/multirate FIR ﬁlter designs (see Chapter 5). These designs have the
advantage of having linearphase capability, robustness to quantization,
stability, and good pipelineability.
Another important reason to use IIRﬁlters is their relatively small group
delay compared to FIR ﬁlters. This results in a shorter transient response
to input stimuli. Even if we are able to match or surpass the implemen
tation cost of an IIR ﬁlter by using multirate/multistage FIR designs, the
transient response of such FIR designs tends to be much larger than that
of a comparable IIR design. However, minimumphase FIR designs such
as those seen in Chapter 1, can have groupdelays that are comparable or
even lower than IIR ﬁlters that meet the same speciﬁcations.
2.2 Classical IIR design
We begin by discussing ﬁlters that are designed in the analogtime domain
and then transformed to the digital domain by means of the bilinear trans
formation. This methodology covers the following IIR design techniques:
Butterworth, Chebyshev type I, Chebyshev type II, and elliptic (Cauer).
We follow the methodology presented in [12][13] in which the 3dB point
is always a design speciﬁcation.
Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design 41
2.2.1 Cutoff frequency and the 3dB point
For FIR ﬁlters, we have started by designating the cutoff frequency for an
ideal ﬁlter (i.e. one with zero transitionwidth). However, depending on
the design method, the cutoff frequency may lack any meaningful value.
For windowedimpulseresponse designs, the magnitude response will
typically cross the cutoff frequency at the point where the magnitude is
equal to 0.5. In decibels, this point corresponds to 20log
10
(0.5) = −6.0206.
The reason for this is that with windowbased designs, the passband and
stopband ripples are about the same. For other designs, such as equirip
ple, the point at which the magnitude response crosses the middle of the
transition band will depend on the ratio of the passband and stopband
ripples.
By contrast, the convention for classical IIR designs is to deﬁne the
cutoff frequency as the point at which the power of an input signal is at
tenuated by onehalf. This means that the cutoff frequency in decibels cor
responds to 10log
10
(0.5) = −3.0103 which we loosely call the 3dB point
∗
.
To avoid confusion, we will call the point at which the power is re
duced by onehalf the 3dB point rather than the cutoff frequency. When
entering speciﬁcations, we use the string 'F3dB' rather than 'Fc'.
2.2.2 Butterworth ﬁlters
Butterworth ﬁlters are maximallyﬂat IIR ﬁlters. For this reason, the only
design parameters are the cutoff frequency and the ﬁlter order.
Example 20 Design a 7th order Butterworth ﬁlter with a 3 dB point of 0.3π.
Hf = fdesign.lowpass('N,F3db',7,0.3);
Hb = design(Hf,'butter');
The design is shown in Figure 2.1. The plot also includes an FIR ﬁlter designed
with a cutoff frequency of 0.3π. Notice that the attenuation at 0.3π is 3dB for
the Butterworth ﬁlter and 6dB for the FIR ﬁlter.
As with maximallyﬂat FIR ﬁlters, the ﬂatness in the passband and
stopband cause the transition band to be very wide. The only way of re
ducing the transition width is to increase the ﬁlter order.
∗
Just to be clear, the gain of the ﬁlter in decibels is 3.0103. The attenuation, i.e. the
distance between the passband gain and this point is approximately 3 dB since distance
is always positive.
Digital Filters with MATLAB Ricardo A. Losada
42 Basic IIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Normalized Frequency: 0.300415
Magnitude (dB): −6.104557
Normalized Frequency: 0.2995605
Magnitude (dB): −2.958706 Butterworth filter
FIR filter
Figure 2.1: 7th order Butterworth ﬁlter with a 3dB frequency of 0.3π. Also shown is an
FIR ﬁlter with a cutoff frequency of 0.3π.
Example 21 Compare the 7thorder Butterworth ﬁlter of the previous example,
with a 12thorder Butterworth ﬁlter designed with the same 3dB point. The
magnitudesquared responses are shown in Figure 2.2.
Hf2 = fdesign.lowpass('N,F3db',12,0.3);
Hb2 = design(Hf2,'butter');
The transitionwidth is decreased as the ﬁlter order increases. Notice that both
ﬁlters intersect at the point where the magnitudesquared of the ﬁlter is equal to
0.5, i.e., the point at which the power of the input signal is attenuated by one half.
2.2.3 Chebyshev type I ﬁlters
Chebyshev type I ﬁlters can attain a smaller transition width than a But
terworth ﬁlter of the same order by allowing for ripples in the passband
of the ﬁlter. The stopband is, as with Butterworth ﬁlters, maximally ﬂat.
For a given ﬁlter order, the tradeoff is thus between passband ripple and
transition width.
Example 22 Compare the 7thorder Butterworth ﬁlter from previous examples
with a 7thorder Chebyshev type I ﬁlter with 1 dB of peaktopeak passband ripple.
Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design 43
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
s
q
u
a
r
e
d
Magnitude Response (squared)
7th order Butterworth filter
12th order Butterworth filter
Figure 2.2: Comparison of a 7thorder and a 12thorder Butterworth ﬁlter. The ﬁlters
intersect at the 3dB point.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
s
q
u
a
r
e
d
Magnitude Response (squared)
Butterworth filter
Chebyshev type I filter
Figure 2.3: Comparison of a 7thorder Butterworth and a 7thorder Chebyshev type I
ﬁlter. Once again, the ﬁlters intersect at the 3dB point.
Hf = fdesign.lowpass('N,F3db,Ap',7,0.3,1);
Hc = design(Hf,'cheby1');
The magnitudesquared responses are shown in Figure 2.3. The passband ripple
Digital Filters with MATLAB Ricardo A. Losada
44 Basic IIR Filter Design
of the Chebyshev ﬁlter can be made arbitrarily small, until the ﬁlter becomes the
same as the Butterworth ﬁlter. That exempliﬁes the tradeoff between passband
ripple and transition width.
With IIR ﬁlters, we not only need to consider the ripple/transition
width tradeoffs, but also the degree of phase distortion. We know that
linearphase throughout the entire Nyquist interval is not possible. There
fore, we want to look at how far from linear the phase response is. A good
way to look at this is to look at the groupdelay (which ideally would be
constant) and see how ﬂat it is.
Of the classical IIR ﬁlters considered here
∗
, Butterworth ﬁlters have the
least amount of phase distortion (phase nonlinearity). Since Chebyshev
and elliptic ﬁlters can approximate Butterworth ﬁlters arbitrarily closely
by making the ripples smaller and smaller, it is clear that the amount of
ripple is related to the amount of phase distortion. Therefore, when we
refer to the tradeoff between ripples and transitionwidth, we should re
ally say that the tradeoff is between the transitionwidth and the amount
of ripple/phasedistortion. As an example, we show the groupdelay of
the Butterworth and Chebyshev type I ﬁlters of the previous example in
Figure 2.4. Notice that not only is the groupdelay of the Chebyshev ﬁl
ter less ﬂat, it is also larger for frequencies below the 3dB point (which
is the region we care about). This illustrates that although the ﬁlters have
the same order, a Chebyshev type I ﬁlter will have a larger transientdelay
than a Butterworth ﬁlter.
2.2.4 Chebyshev type II designs
Unlike FIR maximallyﬂat ﬁlters, it is possible to attain very large stop
band attenuations with Butterworth or Chebyshev type I ﬁlters even when
the ﬁlter is implemented using ﬁxedpoint arithmetic. Nevertheless, few
applications require attenuations of hundreds of decibels. With Butter
worth ﬁlters, such large attenuations come at the price of a large transition
width. With Chebyshev type I ﬁlters, a tradeoff can be made between
transitionwidth and passband ripple. However, attaining a small transi
tion width may result in unacceptably high passband ripple.
∗
Bessel ﬁlters have maximallyﬂat groupdelay responses. However, this property is
lost when the bilinear transformation is used to convert the ﬁlter from analog to digital.
It is possible to use other conversion techniques such as impulseinvariance with Bessel
ﬁlters [14].
Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design 45
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
5
10
15
20
25
30
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Butterworth
Chebyshev type I
Figure 2.4: Groupdelay responses for a 7thorder Butterworth and a 7thorder Cheby
shev type I ﬁlter. Both ﬁlters have a 3dB point of 0.3π.
In most cases a Chebyshev type II (inverse Chebyshev) ﬁlter is prefer
able to both a Chebyshev type I ﬁlter and a Butterworth ﬁlter. These ﬁlters
have maximallyﬂat passband and equiripple stopband. Since extremely
large attenuations are typically not required, we may be able to attain the
transitionwidth required by allowing for some stopband ripple.
Example 23 Design a 6th order ﬁlter with a 3dB point of 0.45π. The ﬁlter must
have an attenuation of at least 80 dB at frequencies above 0.75π and the passband
ripple must not exceed 0.8 dB.
Hf1 = fdesign.lowpass('N,F3db',6,0.45);
Hf2 = fdesign.lowpass('N,F3db,Ap',6,0.45,0.8);
Hf3 = fdesign.lowpass('N,F3db,Ast',6,0.45,80);
Hb = design(Hf1,'butter');
Hc1 = design(Hf2,'cheby1');
Hc2 = design(Hf3,'cheby2');
The three designs are shown in Figure 2.5. Only the Chebyshev type II ﬁlter
reaches the required attenuation of 80 dB by 0.75π.
The groupdelay responses for the designs of the previous example are
shown in Figure 2.6. Although the Butterworth’s groupdelay is slightly
Digital Filters with MATLAB Ricardo A. Losada
46 Basic IIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Butterworth filter
Chebyshev type I filter
Chebyshev type II filter
Figure 2.5: 6th order Butterworth, Chebyshev type I, and Chebyshev type II ﬁlters with
a 3dB point of 0.45π.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
2
4
6
8
10
12
14
16
18
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Butterworth
Chebyshev type I
Chebyshev type II
Figure 2.6: Groupdelay responses for ﬁlters from Example 23.
ﬂatter than that of the Chebyshev type II, the latter’s groupdelay is smaller
than the former’s for most of the passband.
Even though all three designs in the previous example are of 6th order,
the Chebyshev type II implementation actually requires more multipliers
as we now explain.
Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design 47
All the designs result in three secondorder sections. However, the
maximallyﬂat stopband of the Butterworth and Chebyshev type I ﬁlters is
achieved by placing multiple zeros at w = π. The result is that the numer
ators for all three sections are given by 1 +2z
−1
+ z
−2
. The corresponding
coefﬁcients, {1, 2, 1} require no actual multiplications (the multiplication
by two can be implemented with a simple shift). There are two multiplica
tions for each denominator of each section plus one more multiplier that
provides the correct passband gain (0 dB)
∗
. In other words, both the But
terworth ﬁlter and the Chebyshev type I ﬁlter can be implemented with 7
multipliers. By contrast, the Chebyshev type II design requires, at least 9
multipliers to implement.
2.2.5 Elliptic ﬁlters
Elliptic (Cauer) ﬁlters generalize Chebyshev and Butterworth ﬁlters by al
lowing for ripple in both the passband and the stopband of a ﬁlter. By
making the ripples smaller and smaller, we can approximate arbitrarily
close either Chebyshev or Butterworth ﬁlters using elliptic ﬁlters. The ap
proximation is not just of the magnitude response, but the phase response
(and consequently the groupdelay response) as well.
We have already said that most applications do not require arbitrar
ily large stopband attenuations, hence Chebyshev type II ﬁlters are gen
erally preferable to Chebyshev type I and Butterworth ﬁlters. However,
Chebyshev type II ﬁlters are maximallyﬂat in the passband and as a con
sequence have rather larger transition bands. Since most applications can
sustain some amount of passband ripple, the transition band can be re
duced by using an elliptic ﬁlter with the same amount of stopband attenu
ation as a Chebyshev type II ﬁlter (and the same ﬁlter order). The reduced
transition band is attained by allowing for some amount of passband rip
ple. As with Chebyshev type I ﬁlters, the passband ripples of elliptic ﬁl
ters cause the groupdelay to become larger and more distorted than that
of Butterworth or Chebyshev type II ﬁlters.
Example 24 Design an elliptic ﬁlter that meets the speciﬁcations of Example 23.
Hf4 = fdesign.lowpass('N,F3db,Ap,Ast',6,0.45,.8,80);
He = design(Hf4,'ellip');
∗
For ﬁxedpoint implementations, it may be preferable to breakup this scaling gain into
several gains, one per section, because of dynamic range issues.
Digital Filters with MATLAB Ricardo A. Losada
48 Basic IIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Chebyshev type II filter
Elliptic filter
Figure 2.7: Elliptic and Chebyshev type II ﬁlters with a 3dB point of 0.45π.
The resulting ﬁlter is shown in Figure 2.7 along with the Chebyshev type II ﬁlter
we had already designed. The passband ripple allows for the 80 dB attenuation to
be reached by about 0.63π rad/sample, far before the required 0.75π. If the target
application does not beneﬁt from this the passband ripple can be reduced in order
to have smaller passband distortion.
The groupdelay of the elliptic ﬁlter is similar but even less ﬂat than
that of the Chebyshev type I ﬁlter. Figure 2.8 shows the groupdelay re
sponses of the Chebyshev type I design of Example 23 and the elliptic
design of Example 24.
2.2.6 Minimumorder designs
We can use any of the design methods described above for design prob
lems with ﬁxed passband/stopband ripples and ﬁxed transitionwidths.
Naturally, elliptic ﬁlters will result in the lowest ﬁlter order due to the per
missibility of ripples in both passband and stopband. In fact, elliptic ﬁlters
are the IIR version of optimal equiripple designs.
Example 25 Design a highpass IIR ﬁlter with a maximum passband ripple of 1
dB and a minimum stopband attenuation of 60 dB. The stopband must extend to
0.45π and the passband must begin at 0.55π.
Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design 49
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
2
4
6
8
10
12
14
16
18
20
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Chebyshev type I filter
Elliptic filter
Figure 2.8: Groupdelay response of elliptic and Chebyshev type I ﬁlters with a 3dB
point of 0.45π.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Butterworth
Chebyshev type I
Chebyshev type II
Elliptic
Figure 2.9: Magnitude responses of highpass ﬁlters designed with all four classical design
methods.
Hf = fdesign.highpass('Fst,Fp,Ast,Ap',.45,.55,60,1);
Hd = design(Hf,'alliir');
The response of all four ﬁlters can be visualized using fvtool(Hd) (see Figure
2.9). Since we have designed all four ﬁlters, Hd is an array of ﬁlters. Hd(1)
Digital Filters with MATLAB Ricardo A. Losada
50 Basic IIR Filter Design
is the Butterworth ﬁlter, Hd(2) is the Chebyshev type I, Hd(3) the Chebyshev
type II, and Hd(4) the elliptic ﬁlter. By inspecting the cost of each ﬁlter (e.g.
cost(Hd(2))) we can see that the Butterworth ﬁlter takes the most multipliers
(and adders) to implement while the elliptic ﬁlter takes the least. The Chebyshev
designs are comparable.
As with Chebyshev type II ﬁlters, elliptic ﬁlters do not have trivial nu
merators of the form 1 −2z
−1
+z
−2∗
. In contrast, the actual cost of Butter
worth and Chebyshev type I ﬁlters is a little lower than what is indicated
by the cost function as long as we are able to implement the multiplica
tion by two without using an actual multiplier (the cost function does not
assume that this is the case; it is implementation agnostic).
2.2.7 Comparison to FIR ﬁlters
We have said that one reason to use IIR ﬁlters is because of their small
implementation cost when compared to FIR counterparts. We’d like to
illustrate this with an example.
Example 26 Consider the following design speciﬁcations:
Speciﬁcations Set 4
1. Cutoff frequency: 0.0625π rad/sample
2. Transition width: 0.008π rad/sample
3. Maximum passband ripple: 1 dB
4. Minimum stopband attenuation: 80 dB
Fc = 0.0625;
TW = 0.008;
Fp = FcTW/2;
Fst= Fc+TW/2;
Ap = 1;
Ast= 80;
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',Fp,Fst,Ap,Ast);
∗
Notice the negative sign for the term 2z
−1
. This is because we are designing highpass
ﬁlters rather than lowpass.
Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design 51
If we design an elliptic ﬁlter,
He = design(Hf,'ellip');
cost(He);
the cost method indicates that 20 nontrivial multipliers and 20 adders are needed
to implement the ﬁlter.
An equiripple design,
Heq = design(Hf,'equiripple');
requires a whopping 642 multipliers and 641 adders. If we use a symmetric direct
form structure to implement the ﬁlter,
Heqs = design(Hf,'equiripple','FilterStructure','dfsymfir');
the number of multipliers is halved to 321 (the number of adders remains 641).
Clearly there is not contest between the FIR and the IIR design. In the
following chapters we will see that with the use FIR multirate/multistage
techniques we will be able to achieve designs that are more efﬁcient than
the elliptic design shown here in terms not of the number of multipliers,
but of the number of multiplications per input sample (MPIS). However,
we will then go on to showthat by using efﬁcient multirate IIRﬁlters based
on allpass decompositions, we can achieve even lower MPIS. Note that for
the designs discussed so far, both the FIR and IIR cases (being singlerate),
the number of MPIS is the same as the number of multipliers.
In addition to computational cost, another common reason for using
IIR ﬁlters is their small groupdelay when compared to FIR ﬁlters. How
ever, let us compare with minimumphase FIR ﬁlters via an example.
Example 27 Consider the following bandpass ﬁlter speciﬁcations:
Speciﬁcations Set 5
1. Lower cutoff frequency: 0.35π rad/sample
2. Upper cutoff frequency: 0.55π rad/sample
3. Lower/upper transition width: 0.1π rad/sample
4. Maximum passband ripple: 0.01 dB
Digital Filters with MATLAB Ricardo A. Losada
52 Basic IIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
5
10
15
20
25
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Chebyshev type II
Linear−phase FIR
Minimum−phase FIR
Figure 2.10: Groupdelays of FIR and IIR bandpass ﬁlters.
5. Minimum stopband attenuation: 40 dB
Fc1 = 0.35;
Fc2 = 0.55;
TW = 0.1;
Fst1 = Fc1TW/2;
Fp1 = Fc1+TW/2;
Fp2 = Fc2TW/2;
Fst2 = Fc2+TW/2;
Ap = 1e2;
Ast = 40;
Hf = fdesign.bandpass(Fst1,Fp1,Fp2,Fst2,Ast,Ap,Ast);
In the passband, [0.4π, 0.5π], of all classical IIR designs, the Chebyshev type II
will have the lowest group delay. However, a minimumphase equiripple FIR ﬁlter
has an even lower groupdelay in the passband as can be seen in Figure 2.10.
2.3 IIR designs directly in the digital domain
In addition to the classical methods based on bilinear transformation on
analog designs, the Filter Design Toolbox includes design algorithms based
Digital Filters with MATLAB Ricardo A. Losada
2.3 IIR designs directly in the digital domain 53
on optimization directly in the digital domain. The advantage of these
algorithms is that they allow for independent control of the numerator
and denominator orders, providing more ﬂexibility than classical designs.
Moreover, these digitaldomain designs allowfor optimization of different
norms, from leastsquares (2norm) all the way to inﬁnitynorms (equirip
ple).
We have already stated that elliptic ﬁlters are optimal equiripple IIR ﬁl
ters. Essentially the same ﬁlters can be designed use the iirlpnorm design
algorithm if the L
∞
norm is used as the pth norm.
Example 28 The following design yields virtually the same ﬁlter as the elliptic
design of Example 24:
Hf5 = fdesign.lowpass('Nb,Na,Fp,Fst',6,6,.4425,.63);
Hd = design(Hf5,'iirlpnorm','Wpass',1,'Wstop',450);
Unlike classical IIR designs, the passband gain of the least pth norm design is not
bounded by zero dB. However, if we normalize the passband gain to 0 dB, we can
verify that this ﬁlter is virtually identical to the elliptic ﬁlter within a scale factor.
To illustrate the extra ﬂexibility afforded by independent control of the
numerator and denominator orders, consider the following example in
which have a larger order numerator than denominator.
Example 29 We want to use the iirlpnorm function to design a ﬁlter with less
than 0.8 dB passband ripple and at least 80 dB attenuation at 0.75π and be
yond. All designs we showed so far used a 6th order. The two designs that met
the speciﬁcations, elliptic and Chebyshev type II, would have failed to meet the
speciﬁcations had a 4thorder been used instead. Here, we will use a 6thorder
numerator and a 4thorder denominator and still meet the specs.
Hf5 = fdesign.lowpass('Nb,Na,Fp,Fst',6,4,.4425,.75);
Hd = design(Hf5,'iirlpnorm','Wpass',1,'Wstop',25);
The design is shown along with the Chebyshev type II ﬁlter designed previously
in Figure 2.11. The passband ripple is only about 0.043 dB. Despite using less
multipliers than the Chebyshev type II ﬁlter, the least pth norm ﬁlter has a steeper
transition width thanks to the fact that there is some passband ripple.
We should note that unlike the classical IIR designs, it is not possible
to directly control the location of the 3dB point with the least pth norm
design algorithm.
Digital Filters with MATLAB Ricardo A. Losada
54 Basic IIR Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Chebyshev type II filter
IIRLPNORM filter
Figure 2.11: Least pth norm IIR ﬁlter with a 6th order numerator and a 4th order de
nominator. Also shown is the Chebyshev type II ﬁlter design in Example 23.
2.4 Summary and look ahead
Tradeoffs and degrees of freedom in IIR ﬁlter design are essentially the
same as those in FIR ﬁlter design. This is particularly true when ripples
are allowed in the passband and/or stopband of the ﬁlter. Elliptic ﬁlters
are IIR optimal equiripple ﬁlters that use the smallest ﬁlter order possi
ble to meet a set of speciﬁcations involving ripples and transition band.
Butterworth and Chebyshev ﬁlters are special cases of elliptic ﬁlters with
zero passband and/or stopband ripples. However, most applications can
sustain some amount of ripple, making elliptic ﬁlters usually the way to
go. Further ﬂexibility can be obtained by controlling individually the nu
merator and denominators orders. Least pth norm designs allow for such
control.
IIR ﬁlters (elliptic in particular) can meet a set of speciﬁcations with
far fewer multipliers than what an FIR ﬁlter would require. However,
there is a price to pay in terms of phase distortion, implementation com
plexity, stability issues when using ﬁniteprecision arithmetic, pipeline
ability and so forth. If the design speciﬁcations are wellsuited for a mul
tirate/multistage FIR ﬁlter design, we may be able to obtain more efﬁ
cient designs without the drawbacks of IIR ﬁlters. We will study such
Digital Filters with MATLAB Ricardo A. Losada
2.4 Summary and look ahead 55
approaches in the coming chapters. However, we point out once again
that these multistage implementations tend to have large transient delays,
so that if this is a critical factor, IIR ﬁlters may be preferable (although
minimumphase FIR ﬁlters can be an interesting option as we have seen).
Digital Filters with MATLAB Ricardo A. Losada
Chapter 3
Nyquist Filters
Overview
Nyquist ﬁlters are a special class of ﬁlters which are useful for multirate
implementations. Nyquist ﬁlters also ﬁnd applications in digital commu
nications systems where they are used for pulse shaping (often simultane
ously performing multirate duties). The widely used raisedcosine ﬁlter is
a special case of Nyquist ﬁlter that is often used in communications stan
dards.
Nyquist ﬁlters are also called Lthband ﬁlters because the passband of
their magnitude response occupies roughly 1/L of the Nyquist interval.
The special case, L =2 is widely used and is referred to as Halfband ﬁlters.
Halfband ﬁlters can be very efﬁcient for interpolation/decimation by a
factor of 2.
Nyquist ﬁlters are typically designed via FIR approximations. How
ever, IIR designs are also possible. We will show FIR and IIR designs
of halfband ﬁlters. The IIR case results in extremely efﬁcient ﬁlters and
through special structures such as parallel (coupled) allpassbased struc
tures and wave digital ﬁlters can be efﬁciently implemented for multirate
applications.
Later, in Chapter 5, we will see a special property of Nyquist ﬁlters
when used in multirate applications. The cascade of Nyquist interpolators
(or decimators) results in an overall Nyquist interpolator (or decimator).
This makes Nyquist ﬁlters highly desirable for multistage designs.
Moreover, as we will see, Nyquist ﬁlters have very small passband rip
3.1 Design of Nyquist ﬁlters 57
ple even when the ﬁlter is quantized for ﬁxedpoint implementations. This
makes Nyquist ﬁlters ideally suitable for embedded applications.
3.1 Design of Nyquist ﬁlters
Although not strictly necessary, the most common design of a Nyquist ﬁl
ter is as a special case of a lowpass ﬁlter. Nonetheless, highpass and band
pass designs are also possible. When designing a Nyquist ﬁlter, the value
of the band L must be speciﬁed. Nyquist ﬁlters will reduce the bandwidth
of a signal by a factor of L.
With Nyquist ﬁlters, the passband ripple and the stopband ripple can
not be independently speciﬁed. Therefore, in all designs, only the stop
band ripple (and/or the transition width) will be given. The passband
ripple will be a result of the design. In most cases, the resulting passband
ripple is very small. This is particularly true for IIR Nyquist ﬁlters.
Example 30 Design a Kaiser window 5thband Nyquist FIR ﬁlter of 84th order
and 80 dB of stopband attenuation
∗
,
L = 5; % 5thband Nyquist filter
f = fdesign.nyquist(L,'N,Ast',84,80);
h = design(f,'kaiserwin');
Both the transitionwidth and the passband ripple of the ﬁlter are a result of the
design. The ﬁlter has a cutoff frequency given by π/L (0.2π in this case). The
passband details of the magnitude response are shown in Figure 3.1. Note that the
peak to peak ripples are indeed quite small (on the order of 2 ×10
−3
).
A characteristic of Nyquist ﬁlters is that every Lth sample of their im
pulse response is equal to zero (save for the middle sample). As we will see
when we discuss multirate ﬁlter design, this characteristic is desirable for
interpolation because it means that the input samples will pass through
the ﬁlter unchanged. Moreover, for both interpolation and decimation
purposes, it means that one of the L polyphase branches will result in a
simple delay (no multipliers/adders) reducing the implementation cost
∗
Close inspection of the stopband will show that the 80 dB attenuation is not quite
achieved. This happens sometimes with Kaiserwindow designs because the relation
between the adjustable parameter in the Kaiser window and the stopband attenuation is
derived in somewhat empirical fashion.
Digital Filters with MATLAB Ricardo A. Losada
58 Nyquist Filters
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14
−8
−6
−4
−2
0
2
4
6
8
x 10
−4
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 3.1: Passband ripple details for 5thband Nyquist FIRﬁlter designed with a Kaiser
window.
for such branch. The impulse response for the ﬁlter designed in Exam
pled 30 can be seen in Figure 3.2. Note that every 5th sample is equal to
zero except for the middle sample which is the peak value of the impulse
response.
3.1.1 Equiripple Nyquist ﬁlters
If instead of specifying the order and stopband attenuation of an FIRNyquist
ﬁlter design we specify the order and transition width or the transition
width and the stopband attenuation, equiripple designs are possible. It
must be pointed out however that it is not trivial to design equiripple FIR
Nyquist ﬁlters given the timedomain constraint (the fact that the impulse
response must be exactly zero every L samples). Equiripple designs may
have convergence issues for large order/small transition width combina
tions and may result in bogus ﬁlters. Filters with equiripple passband and
sloped stopband are also possible
∗
Although equiripple designs are possible, their advantages relative to
∗
Except in the halfband (L=2) case. In that case, symmetry characteristics of the magni
tude response about the 0.5π point result in same passband/stopband ripples. Therefore
a sloped stopband will also mean a sloped passband.
Digital Filters with MATLAB Ricardo A. Losada
3.1 Design of Nyquist ﬁlters 59
0 10 20 30 40 50 60 70 80
−0.05
0
0.05
0.1
0.15
0.2
Samples
A
m
p
l
i
t
u
d
e
Impulse Response
Figure 3.2: Impulse response of 5thband Nyquist FIR ﬁlter. Every 5th sample is equal
to zero (except at the middle).
Kaiserwindow designs are not as clear for Nyquist ﬁlters as they are for
regular ﬁlter designs. In particular, the passband ripples of Kaiserwindow
designs may be smaller than those of equiripple designs. Moreover, as we
will see in Chapter 4, the increasing attenuation in the stopband may be
desirable for interpolation and especially for decimation purposes.
Example 31 We will compare a Kaiser window design to both an equiripple de
sign with and without a sloped stopband.
f = fdesign.nyquist(4,'N,TW',72,.1); % 4thBand Nyquist filter
h = design(f,'kaiserwin');
h2 = design(f,'equiripple');
h3 = design(f,'equiripple','StopbandShape','linear','StopbandDecay',20);
While it is clear that the Kaiserwindow design has the smallest minimum stop
band attenuation, it does provide increased stopband attenuation as frequency
increases. The magnitude responses are shown in Figure 3.3.
Moreover, the Kaiser window design results in better passband ripple perfor
mance than either equiripple design (this can be veriﬁed with the measure com
mand). The passband ripple details are shown in Figure 3.4.
Digital Filters with MATLAB Ricardo A. Losada
60 Nyquist Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Kaiser window
Equiripple
Sloped equiripple
Figure 3.3: Comparison of Kaiser window, equiripple, and sloped equiripple Nyquist
ﬁlter designs of 72nd order and a transition width of 0.1π.
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
−0.015
−0.01
−0.005
0
0.005
0.01
0.015
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Kaiser window
Equiripple
Sloped equiripple
Figure 3.4: Passband ripple details for ﬁlters designed in Example 31.
Digital Filters with MATLAB Ricardo A. Losada
3.2 Halfband ﬁlters 61
3.1.2 Minimumorder Nyquist ﬁlters
It is possible to design either equiripple or Kaiserwindow FIR ﬁlters that
meet a transitionband requirement as well as a minimumstopband re
quirement with minimum order. It is important to note that while the
minimum stopband attenuation is the same for both designs. the max
imum peaktopeak passband ripple of each design will be different (of
course so to will be the resulting ﬁlter order).
What is interesting is that while equiripple designs tend to be of smaller
order, the peaktopeak passband ripple of Kaiser window designs tends
to be smaller. This coupled with the increased overall attenuation in the
stopband due to its nonequiripple nature, may make Kaiser window de
signs appealing despite the slightly larger implementation cost.
Example 32 Consider the following design examples, compare the results of the
measure command and the cost command for both Kaiser window designs and
equiripple designs.
f = fdesign.nyquist(8,'TW,Ast',0.1,60);
f2 = fdesign.nyquist(4,'TW,Ast',0.2,50);
hk = design(f,'kaiserwin');
he = design(f,'equiripple');
hk2 = design(f2,'kaiserwin');
he2 = design(f2,'equiripple');
Both cases illustrate the tradeoff between ﬁlter order and passband ripple for
Nyquist ﬁlter design choices.
3.2 Halfband ﬁlters
Halfband ﬁlter are a special case of Nyquist ﬁlters when L = 2. This ﬁl
ters reduce the bandwidth of a signal roughly by half and are suitable for
decimation/interpolation by a factor of 2 (see Chapter 4).
As previously stated, Nyquist ﬁlters are characterized by the fact that
every Lth sample of its impulse response (i.e. every Lth ﬁlter coefﬁcient)
is equal to zero. In the case of halfband ﬁlters this fact is particularly ap
pealing since it means that roughly half of its coefﬁcients are equal to zero.
This of course makes them very efﬁcient to implement. As such, halfband
Digital Filters with MATLAB Ricardo A. Losada
62 Nyquist Filters
ﬁlters are widely used in particular for multirate applications including
multistage applications (see Chapter 5).
The cutoff frequency for a halfband ﬁlter is always 0.5π. Moreover,
the passband and stopband ripples are identical, limiting the degrees of
freedom in the design. The speciﬁcations set follow the usual triangle
metaphor shown in Figure 1.2, taking into account the limitations just de
scribed. As such, three different speciﬁcations are available for halfband
designs. In each case, two of the three angles of the triangle are speciﬁed
(as just stated, the stopband ripple automatically determines the passband
ripple).
f = fdesign.halfband('N,TW',N,TW);
f2 = fdesign.halfband('N,Ast',N,Ast);
f3 = fdesign.halfband('TW,Ast',TW,Ast);
In all three cases, either Kaiser window or equiripple FIR designs are pos
sible. Moreover, in the ﬁrst case, it is also possible to design leastsquares
FIR ﬁlters.
Unlike the general case, there are usually no convergence issues with
equiripple halfband ﬁlter designs. In addition to that, the fact the pass
band ripple is the same as the stopband ripple means that regardless of
the design algorithm, the resulting peaktopeak passband ripples will be
about the same.
So for halfband ﬁlters, the advantages of optimal equiripple designs
over Kaiser window designs resurface in a more clear manner than for
other Nyquist ﬁlters. For a given set of speciﬁcations, the equiripple de
signs will have either a larger minimum stopband attenuation, a smaller
transition width, or a smaller number of coefﬁcients.
Example 33 Consider Kaiser window and equiripple designs for the following to
cases:
f = fdesign.halfband('N,TW',50,0.1);
f2 = fdesign.halfband('TW,Ast',0.1,75);
Using the measure command in the ﬁrst case shows that the resulting stopband
attenuation (and consequently the passband ripple) is better in the equiripple case.
Similarly, using the cost command in the second case shows that the same per
formance is achieved with fewer coefﬁcients in the equiripple case.
Digital Filters with MATLAB Ricardo A. Losada
3.2 Halfband ﬁlters 63
Sloped equiripple designs are also possible, but in the case of halfband
ﬁlters, they will result in similarly sloped passbands, given the symmetry
constraints on halfband ﬁlters.
3.2.1 IIR halfband ﬁlters
Nyquist ﬁlters can also be designed as IIR ﬁlters. The most interesting case
is that of halfband IIR ﬁlters [20][21]. These ﬁlters are extremely efﬁcient
especially when implemented as two allpass branches in parallel. For IIR
halfband ﬁlters, the parallel allpass decomposition (8.1) becomes
H(z) =
1
2
ˆ
A
0
(z
2
) + z
−1
ˆ
A
1
(z
2
)
(3.1)
with A
0
(z) =
ˆ
A
0
(z
2
) and A
1
(z) = z
−1
ˆ
A
1
(z
2
).
Such implementations are ideally suited for polyphase multirate ar
chitectures (see Chapter 4). In Chapter 5 we will show that using IIR
halfbandbased multirate/multistage designs result in extremely efﬁcient
ﬁlters that outperform FIR counterparts.
IIR halfband ﬁlters have similar symmetry constrains as FIR halfbands.
However, in the case of IIR ﬁlters, the symmetry is about the halfpower
point (3 dB point) rather than the halfmagnitude point (6 dB point) of
FIR halfbands. Because of this symmetry, it is not possible to design half
band Chebyshev ﬁlters. Only Butterworth and elliptic halfband ﬁlters are
possible from the classical designs. A design algorithm synthesized di
rectly in the digital domain [22] results in approximately linear phase in
the passband of the ﬁlter (at the expense of either higher order or reduced
stopband attenuation compared to elliptic halfbands).
Unlike the FIR case, it is important to point out that IIR halfbands are
not necessarily Nyquist ﬁlters. In particular, Butterworth and elliptic de
signs result in nonNyquist halfbands. As a result of this, although they
can be used for polyphase decimation/interpolation, in the interpolation
case, it will not be true that the input samples are preserved unchanged at
the output.
The reason some IIR halfbands are not Nyquist, is that
ˆ
A
0
(z
2
) and
ˆ
A
1
(z
2
) may not be equal to a delay. However, in the case of approximately
linear phase designs,
ˆ
A
0
(z
2
) = z
−D
for some integer D. Therefore, the
ﬁlter is Nyquist and when used for interpolation, the input samples are
preserved unchaged (just delayed).
Digital Filters with MATLAB Ricardo A. Losada
64 Nyquist Filters
0 0.05 0.1 0.15 0.2 0.25
−4.5
−4
−3.5
−3
−2.5
−2
−1.5
−1
−0.5
0
x 10
−7
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 3.5: Passband details of quasilinear phase IIR halfband ﬁlter with 70 dB of stop
band attenuation.
In all cases, given only moderate stopband attenuations, the resulting
passband ripples of IIR halfband ﬁlters is very small. This fact coupled
with the fact that (as previously stated) many applications do not require
hundreds of decibels of stopband attenuation, limits the appeal of Butter
worth halfband ﬁlters.
Example 34 Consider the following quasilinear phase IIR halfband design. The
fact the we specify a 70 dB minimum stopband attenuation results in a peakto
peak passband ripple of only 4 ×10
−7
dB!
f = fdesign.halfband('N,Ast',12,70);
h = design(f,'iirlinphase');
The passband details are shown in Figure 3.5.
Minimumorder designs
Minimumorder designs provide a good framework to compare imple
mentation cost of FIR halfband ﬁlters vs. IIR halfbands. Elliptic halfbands
are the most efﬁcient while quasilinear phase halfbands give up some ef
ﬁciency in the name of phase linearity. Either case is signiﬁcantly more
efﬁcient than FIR equiripple halfband.
Digital Filters with MATLAB Ricardo A. Losada
3.3 Summary and look ahead 65
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
5
10
15
20
25
30
35
40
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
iirlinphase
ellip
equiripple
Figure 3.6: Groupdelay comparison for IIR and FIR halfband ﬁlters.
Example 35 Compare the following three minimumorder designs,
f = fdesign.halfband('TW,Ast',0.1,60);
hlp = design(f,'iirlinphase');
hel = design(f,'ellip');
heq = design(f,'equiripple');
Using the cost command, we can see that the FIR equiripple design requires 35
multipliers, the quasilinear phase IIR design requires 15 multipliers, while the
elliptic design requires only 6 multipliers.
A plot of the groupdelay of all three ﬁlters shows that while the elliptic de
sign clearly has the lowest group delay, it is also the one with the most nonlinear
phase. The passband groupdelay of the quasilinear phase design is almost ﬂat as
expected (see Figure 3.6).
The passband ripple of the equiripple design is quite small, yet it is orders of
magnitude larger than the passband ripple of either IIR design.
3.3 Summary and look ahead
Nyquist ﬁlters have very useful properties that make them worth consid
ering. They tend to result in efﬁcient designs because of the fact that every
Digital Filters with MATLAB Ricardo A. Losada
66 Nyquist Filters
lth sample of their impulse response is zero. They also tend to have very
small passband ripples.
Halfband ﬁlters are particularly interesting given their high efﬁciency.
IIR halfband ﬁlters are even more efﬁcient and have extremely small pass
band ripples.
Given all their advantages, Nyquist ﬁlters (FIR or IIR) should be the
ﬁrst choice for multirate applications (see Chapter 4). The fact that their
cutoff frequency is given by π/L results in transitionband overlap in dec
imation applications. This however is not a problemgiven that no aliasing
will occur in the band of interest ((see Chapter 4 and Appendix B.)
Moreover, we will see (Chapter 5) that cascade multirate Nyquist ﬁl
ters possess an interesting property: the overall equivalent multirate ﬁl
ter is also Nyquist. For example, a decimation/interpolation ﬁlter with a
rate change of say 8 can be implemented as a cascade of three halfband
decimation/interpolation ﬁlters (each with a rate change of 2). The three
halfband ﬁlters in cascade act a single Nyquist ﬁlter (the equivalent im
pulse response of the cascade will have a value of zero every 8th sample)
but can be signiﬁcantly more efﬁcient than a singlestage design. This is
particularly true if IIR halfband designs are used.
Digital Filters with MATLAB Ricardo A. Losada
Chapter 4
Multirate Filter Design
Overview
Multirate signal processing is a key tool to use in many signal processing
implementations. The main reason to use multirate signal processing is
efﬁciency. Digital ﬁlters are a key part of multirate signal processing as
they are an enabling component for changing the sampling rate of a signal.
If multirate concepts are not fresh, it may be helpful to read through
Appendix B prior to reading through this chapter.
In this chapter we will talk about designing ﬁlters for multirate sys
tems. Whether we are increasing or decreasing the sampling rate of a sig
nal, a ﬁlter is usually required. The most common ﬁlter type used for mul
tirate applications is a lowpass ﬁlter.
∗
Nyquist ﬁlters, described in Chapter
3, are the preferred design to use for multirate applications.
We start by presenting ﬁlters in the context of reducing the sampling
rate of a signal (decimation). We want to emphasize the following: if you
reduce the bandwidth of a signal through ﬁltering, you should reduce its
sampling rate accordingly.
We will see that the above statement applies whether the bandwidth
is decreased by an integer or a fractional factor. Understanding fractional
samplingrate reduction requires understanding interpolation. We present
ﬁrst interpolation as simply ﬁnding samples lying between existing sam
ples (not necessarily increasing the sampling rate). We then use this to
∗
However, as we will see, highpass, bandpass and in general any ﬁlter that reduces the
bandwidth of a signal may be suitable for multirate applications.
68 Multirate Filter Design
show how to increase the samplingrate of a signal by an integer factor.
Finally we extend this paradigm in order to perform fractional decima
tion/interpolation.
4.1 Reducing the sampling rate of a signal
In the previous chapters we have discussed the basics of FIR and IIR ﬁl
ter design. We have concentrated mostly on lowpass ﬁlters. A lowpass
ﬁlter reduces the bandwidth of the signal being ﬁltered by some factor.
When the bandwidth of a signal is reduced, we usually want to reduce
the sampling rate in a commensurate manner. Otherwise, we are left with
redundant data, given that we are oversatisfying the Nyquist sampling
criterion. Any processing, storage, or transmission of such redundant data
will result in unnecessary use of resources.
Speciﬁcally, if the input signal x[n] has a bandwidth B
x
and the ﬁltered
signal y[n] has a bandwidth B
y
related to the input bandwidth by
B
x
B
y
= M
we should reduce the sampling frequency of y[n] by a factor of M.
4.1.1 Decimating by an integer factor
If M is an integer the procedure is straightforward. We can downsample
y[n] by keeping one of every M samples
y
down
[m] = y[nM].
The idea is depicted in Figure 4.1 and is referred to as decimation. The
ﬁlter H(z) is a lowpass ﬁlter that roughly reduces the bandwidth by a
factor of M. Once the bandwidth is reduced, the samplingrate should
be reduced accordingly. The downsampler that follows H(z) reduces the
sampling rate by keeping one out of every M of its input samples.
However, the procedure as described so far is inefﬁcient in that after
the ﬁlter processes a set of M samples, only one sample kept. All the com
putation involved in obtaining the other M−1 samples is wasted.
Digital Filters with MATLAB Ricardo A. Losada
4.1 Reducing the sampling rate of a signal 69
Figure 4.1: Reducing the sampling rate after the bandwidth of the signal is reduced.
Figure 4.2: FIR ﬁlter implemented in directform followed by a downsampler.
Efﬁcient FIR ﬁlters stemming from decimation
For FIR ﬁlters, a better paradigm is easy to implement in which we never
actually compute any of the samples that we would throw away anyway.
To illustrate the idea consider an FIR ﬁlter implemented in directform
followed by a downsampler by Mas shown in Figure 4.2. There is no point
computing all additions/multiplications indicated only to throw out the
result of most of them. Instead, we can downsample before the multipliers
so that only computations that are required are performed [3], [23], [24].
The idea is shown in Figure 4.3.
For any ﬁlter of length N + 1 (order N), even though the ﬁlter still
requires N + 1 multipliers, they are only used once every M samples.
In other words, the average number of multiplications per input sample
(MPIS) is
N+1
M
. That is of course a savings of a factor of M on average.
Unfortunately, for IIR ﬁlters, it is not straightforward to implement the
Digital Filters with MATLAB Ricardo A. Losada
70 Multirate Filter Design
Figure 4.3: Efﬁcient FIR decimation.
procedure shown due to the feedback. There is a way to implement deci
mation efﬁciently with certain IIR designs using an allpassbased decom
position as described in §8.1.2. We will discuss these efﬁcient multirate IIR
ﬁlters later.
Determining the decimation factor So far we have described a ﬁlter that
reduces the bandwidth by a factor M as if it were an ideal ﬁlter. Of course,
with practical ﬁlters we have to worry about the ﬁnite amount of atten
uation in the stopband, the distortion in the passband, and the nonzero
width transition band between passband and stopband. We’d like to ex
plore how does using a nonideal ﬁlter come into play when we decimate.
In order to answer this, consider what happens to the output signal
once it is downsampled by M (see also Appendix B). In the same way
that sampling an analog signal introduces spectral replicas of the analog
signal’s spectrum, downsampling a digital signal introduces replicas of its
spectrum. In the case of downsampling, the number of replicas introduced
Digital Filters with MATLAB Ricardo A. Losada
4.1 Reducing the sampling rate of a signal 71
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Spectral replicas after decimation
Magnitude spectrum of signal after decimation
Spectral replica
Spectral replica
Figure 4.4: Spectrum of decimated signal with ω
st
= π/M along with spectral replicas.
is equal to M−1.
We’d like to compare two different cases, one in which the cutoff fre
quency is π/M, and another in which the stopbandedge frequency is
π/M. First let’s look at the latter case.
For illustration purposes, assume M =3 and assume that the spectrum
of the signal to be ﬁltered is ﬂat and occupies the entire Nyquist interval.
This means that the spectrum of the output signal (prior to downsam
pling) will take the shape of the ﬁlter. The conclusions we will reach are
valid for any value of M and any input signal (but the aliasing will be
lower than what we show if the input signal is already somewhat attenu
ated in the stopband; we are showing the worstcase scenario). The spec
trum of the decimated signal along with the replicas are shown in Figure
4.4. Aliasing invariably occurs because of the ﬁnite amount of stopband
attenuation. However, presumably we select the amount of stopband at
tenuation so that the aliasing is tolerable. Notice the problem with using
ﬁlters with equiripple stopband when decimating. The energy in the stop
band is large and it all aliases into the spectrum of the signal we are in
terested in. Also notice that the usable bandwidth extends from zero to
the passbandedge frequency. The passbandedge frequency in this case is
given by π/M− T
w
, where T
w
is the transitionwidth.
Digital Filters with MATLAB Ricardo A. Losada
72 Multirate Filter Design
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Spectral replicas after decimation
Magnitude spectrum of signal after decimation
Spectral replica
Spectral replica
Figure 4.5: Spectrum of decimated signal with ω
c
= π/M along with spectral replicas.
Now let’s look at the case where the cutoff frequency is set to π/M.
Recall that for FIR ﬁlters the cutoff frequency is typically located at the
center of the transition band. The spectrum of the decimated signal along
with its corresponding replicas for this case are shown in Figure 4.5. Since
the cutoff frequency is in the middle of the transition band, the transition
bands alias into each other. This is not a problem since that region is dis
torted by the ﬁlter anyway so that it should not contain any information
of interest. Notice that we have used a sloped stopband to reduce the to
tal amount of aliasing that occurs. Of course this could have been done
in the previous case as well. Also, the usable passband extends now to
π/M − T
w
/2 where once again T
w
is the transition width. This means
that the usable passband is larger in this case than in the case ω
st
= π/M
by T
w
/2. In order to have the same usable passband in both cases, we
would have to make transition width of the case ω
st
= π/M half as wide
as the transition width of the case ω
c
= π/M. Given that for FIR ﬁlters
the ﬁlter order grows inversely proportional to the transition width, this
would imply having to increase the ﬁlter order by a factor of about two in
order to obtain the same usable bandwidth with ω
st
= π/M.
While both selections, ω
st
= π/M, or ω
c
= π/M are valid. There are
clear advantages to using ω
c
= π/M. In practice, we usually have some
Digital Filters with MATLAB Ricardo A. Losada
4.1 Reducing the sampling rate of a signal 73
amount of excess bandwidth in a sampled signal so that the aliasing that
occurs in the transition band does not affect the application. For instance,
consider an audio signal. The most common sampling frequency is 44.1
kHz, but the maximum frequency we are interested in is 20 kHz. That
means there is 4.1/2 kHz available at each side of the spectrum for transi
tion bands of ﬁlters. See [11] for more on this.
All this to say that usually the decimation factor M should still be se
lected as the ratio ω
c
/π even when the nonideal nature of practical FIR
ﬁlters is taken into consideration. This ﬁts in well with the use of Nyquist
ﬁlters. Since an Mthband Nyquist ﬁlter has a cutoff frequency of π/M,
it is wellsuited for applications in which we want to reduce the sampling
rate by a factor of M.
Example 36 A 4thband Nyquist ﬁlter reduces the bandwidth by a factor of 4.
We can simultaneously reduce the sampling rate by a factor of 4 by designing a
decimator Nyquist ﬁlter,
f = fdesign.decimator(4,'Nyquist',4,'TW,Ast',0.1,60);
h = design(f,'kaiserwin');
Computational savings with FIR decimators We’d like to return to the
comparison between an FIR and an IIR ﬁlter that meet the same set of
speciﬁcations. In §2.2.6 we saw that for the speciﬁcation set 4 an elliptic
IIR ﬁlter requires 20 multipliers and 20 MPIS to implement assuming a
directform II secondorder sections implementation. An optimal equirip
ple ﬁlter requires 642 multipliers if we do not take advantage of the sym
metry in the ﬁlter coefﬁcients. However, given that the cutoff frequency
is π/16, we can use the efﬁcient decimation techniques described above
to implement the FIR ﬁlter with an average of 40.125 MPIS even without
taking advantage of the symmetric coefﬁcients.
∗
M = 16; % Decimation factor
Fc = 0.0625;
TW = 0.008;
Fp = FcTW/2;
Fst = Fc+TW/2;
∗
An efﬁcient decimation structure that does take advantage of the symmetry in the co
efﬁcients is shown on page 77 of [24].
Digital Filters with MATLAB Ricardo A. Losada
74 Multirate Filter Design
Ap = 1;
Ast = 80;
Hf = fdesign.decimator(M,'lowpass','Fp,Fst,Ap,Ast',...
Fp,Fst,Ap,Ast);
Hd = design(Hf,'equiripple');
cost(Hd)
Through the use of multirate techniques, we are within a factor of two
of the number of MPIS required to implement an IIR ﬁlter that meets the
speciﬁcations. However, we still have perfect linear phase and no stability
issues to worry about.
For the case just discussed, a Kaiserwindowdesigned
∗
Nyquist ﬁl
ter would require more computations per input sample than a regular
lowpass ﬁlter. The main reason is the passband ripple. With the given
speciﬁcations, the Kaiserwindow design will have a mere 0.0015986 dB of
passband ripple. The cost to pay for this vast oversatisfying of the speci
ﬁcations is a computational cost of 73.6875 MPIS.
In Appendix C we study various approaches to ﬁlter design for these
same speciﬁcations. We will see that multistage/multirate designs and in
particular multistage Nyquist multirate designs will be the most efﬁcient
of all approaches looked at for these speciﬁcations. This is true despite the
fact that such multistage Nyquist designs also will vastly oversatisfy the
passband ripple requirements.
Decimating by a factor of 2
When reducing the bandwidth/decimating by a factor of two, if the cutoff
frequency is set to π/2 (and transitionband aliasing is tolerated), FIR or
IIR halfband ﬁlters can be used to very efﬁciently implement the ﬁlter.
In the FIR case, the halfband decimator by 2 takes full advantage of the
fact that about half the ﬁlter coefﬁcients are zero.
Example 37 Consider the following design:
f = fdesign.decimator(2,'halfband','TW,Ast',0.1,80);
h = design(f,'equiripple');
cost(h)
∗
Equiripple designs do not converge for these speciﬁcations given the Nyquist con
straint on the impulse response.
Digital Filters with MATLAB Ricardo A. Losada
4.1 Reducing the sampling rate of a signal 75
Figure 4.6: Allpassbased IIR polyphase implementation of decimation by 2.
The halfband is already efﬁcient in that for a ﬁlter of length 95, it only requires 49
multipliers. By reducing the sampling rate, a further gain factor of two is obtained
in computational cost. The number of MPIS is 24.5.
In the IIR case, efﬁcient allpassbased polyphase implementations are
possible for halfband designs. The idea is two make use of the fact that
conceptually, decimation is lowpass ﬁltering followed by downsampling.
By using (3.1) and the Noble identities, it is simple to obtain the implemen
tation shown in Figure 4.6. Note that use of the Noble identities means that
the allpass ﬁlters are now given in terms of powers of z rather than of z
2
.
Let’s look at the computational cost of using an IIR halfband ﬁlter for the
speciﬁcations from the previous example.
Example 38 For the same speciﬁcations contained in the variable f above, we
can design either an elliptic halfband decimator or a quasi linear phase halfband
decimator:
h1 = design(f,'ellip');
h2 = design(f,'iirlinphase');
cost(h1)
cost(h2)
As usual, the elliptic design is the most efﬁcient, requiring only 6 multipliers and
3 MPIS. If approximate linear phase is desired, the iirlinphase design requires
19 multipliers and 9.5 MPIS.
Digital Filters with MATLAB Ricardo A. Losada
76 Multirate Filter Design
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude spectrum of highpass−filtered signal
Figure 4.7: Spectrum of highpassﬁltered signal.
Decimating with highpass/bandpass ﬁlters
The motivation to reduce the sampling rate whenever the bandwidth of
a signal is reduced remains true regardless of the shape of the ﬁlter used
to reduce the bandwidth. If we use a highpass or a bandpass ﬁlter to re
duce the bandwidth by an integer factor M, we would still want to reduce
the sampling frequency accordingly. The resulting signal after downsam
pling is called the baseband equivalent of a bandpass signal. Any further
processing at baseband is less costly because we use fewer samples once
the sampling frequency is reduced. The bandpass signal and its baseband
equivalent contain the same information. We could for instance generate
an analog bandpass signal that corresponds to the digital bandpass signal
by starting from the baseband equivalent.
As long as the ﬁlters are FIR, we can continue to use the efﬁcient imple
mentation we showed since the directform structure can be used regard
less of the response type of the ﬁlter. If a highpass halfband ﬁlter is used,
efﬁcient polyphase IIR designs are a possibility as well.
Example 39 For example, consider using a highpass ﬁlter that reduces the band
width by a factor M = 3. If we do not downsample, and the input to the ﬁlter
has a ﬂat spectrum, the output signal will have the spectrum of the ﬁlter. Some
thing like what is shown in Figure 4.7. If we downsample the ﬁltered signal by a
Digital Filters with MATLAB Ricardo A. Losada
4.1 Reducing the sampling rate of a signal 77
−0.3 −0.2 −0.1 0 0.1 0.2 0.3
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Spectrum after decimation
Alias from spectral replicas
Magnitude spectrum of signal after decimation
Figure 4.8: Spectrum of downsampled highpassﬁltered signal.
factor of M, the resulting spectrum is moved to baseband as shown (along with
the aliasing from replicas) in Figure 4.8. The spectrum is shown relative to the
high sampling frequency, but we only show the portion of the Nyquist interval
that corresponds to the downsampled signal. For this reason, the interval plotted
is [−π/3, π/3]. Notice that in this case, some of the aliasing comes from the
replicas and some of it is “selfinﬂicted” so to speak. Nevertheless, as before, the
amount of aliasing is controlled by the stopband attenuation. In this example, no
single replica introduces more than 60 dB of aliasing in the usable passband.
Notice that the previous example amounts to removing the “white
space” that arises after highpass ﬁltering. Since the energy in the signal
is negligible in this white space, we best not waste resources by process
ing information corresponding to that band.
There are some restrictions as to where the bandpass that is retained
lies relative to the sampling rate [24]. Even if the ﬁlter were ideal, its re
sponse needs to be such that it retains a bandwidth M times smaller than
the Nyquist interval and lying in one of the intervals
kπ/M< ω < (k +1)π/M k = 0, 1, . . . , M−1.
The cases k = 0 and k = M − 1 correspond to lowpass and highpass
ﬁlters respectively. These cases are thus never a problem. However, if the
Digital Filters with MATLAB Ricardo A. Losada
78 Multirate Filter Design
−0.3 −0.2 −0.1 0 0.1 0.2 0.3
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Spectrum after decimation
Alias from spectral replicas
Magnitude spectrum of signal after decimation
Figure 4.9: Spectrum of bandpassﬁltered signal downsampled by a factor M = 3.
bandpass ﬁlter does not meet the restrictions just mentioned, we should
still try to downsample as much as possible.
Example 40 Suppose we are interested in retaining the band between 0.35π and
0.5167π. The bandwidth is reduced by a factor M = 6. However, the bandedges
are not between kπ/M and (k +1)π/M for M = 4, 5, 6. The bandedges do lie
between π/3 and 2π/3, so if we design a bandpass ﬁlter we can at least decimate
by 3.
TW = 0.1/6; % Transition width
Fc1 = 0.35;
Fc2 = 0.5167;
M = 3; % Decimation factor
Hf = fdesign.decimator(M,'bandpass','Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',...
Fc1TW/2,Fc1+TW/2,Fc2TW/2,Fc2+TW/2,60,.2,60);
Hd = design(Hf,'equiripple');
The spectrum of the bandpassﬁltered signal after downsampling is shown in Fig
ure 4.9. The frequency is relative to the high sampling rate prior to downsampling.
Since we downsampled by M = 3, the new Nyquist interval after downsampling
Digital Filters with MATLAB Ricardo A. Losada
4.1 Reducing the sampling rate of a signal 79
will be [−π/3, π/3]. Notice that we haven’t been able to remove all the white
space since we could only downsample by 3 even though the bandwidth was re
duced by 6.
Decimation when working with Hertz
So far we have used normalized frequency in all our decimation designs. If
we’d like to specify the frequency speciﬁcations in Hertz, we should sim
ply keep in mind that the sampling frequency that is used is the sampling
frequency of the input signal (prior to downsampling).
Example 41 Suppose we have a signal sampled at 30 kHz and we reduce its
bandwidth by a factor of 3. The band of interest extends from 0 Hz to 4250 Hz.
In order to remove redundancy, we reduce the samplingrate by a factor of 3 as
well. We use a 3rdband Nyquist ﬁlter, therefore the cutoff frequency is equal to
F
s
/(2M) = 5000 Hz. The transition band is set to 1500 Hz so that it extends
from 4250 Hz to 5750 Hz.
M = 3;
Band = 3;
Fs = 30e3;
Hf = fdesign.decimator(M,'Nyquist',Band,'TW,Ast',1500,65,Fs);
Hd = design(Hf,'kaiserwin');
4.1.2 Decimating by a noninteger factor
If the bandwidth reduction factor is not an integer, we would still like to re
duce the sampling frequency accordingly. A simple approximation would
be to downsample the output by the largest integer that is not greater than
the bandwidth reduction factor. This is less than optimal however and if
the bandwidth reduction factor is less than two, there would be no efﬁ
ciency improvements even if we reduce the bandwidth to almost (but not
quite) half the original bandwidth.
Abetter solution would be to reduce the sampling rate by a noninteger
factor as well. This implies computing some samples between existing
samples as shown in Figure 4.10. Computing new samples in between
existing samples amounts to interpolation. We will return to discuss frac
tional decimation in §4.4, but before we do so, we’ll look at interpolation.
Digital Filters with MATLAB Ricardo A. Losada
80 Multirate Filter Design
30 35 40 45 50 55
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time (samples)
A
m
p
l
i
t
u
d
e
Original samples
Underlying signal
Fractionally−decimated samples
Figure 4.10: Illustration of fractional decimation.
4.2 Interpolation
Roughly speaking, interpolation consists of computing new samples be
tween existing samples. In the context of signal processing, ideally we
interpolate by ﬁnding the desired points on the underlying continuous
time analog signal that corresponds to the samples we have at hand. This
is done without actually converting the signal back to continuous time.
The process is referred to as sinc interpolation since an ideal lowpass ﬁlter
(with a sincshaped impulse response) is involved (see Appendix B).
4.2.1 Fractionally advancing/delaying a signal
Usually interpolation is presented in the context of increasing the sampling
rate of a signal, but strictly speaking, this is not necessary. Consider the
situation shown in Figure 4.11. We’d like to compute the interpolated sam
ples from the existing samples. For each existing sample we compute a
new sample, therefore the sampling rate remains the same.
The interpolated samples in Figure 4.11 are found by fractionally ad
vancing the signal in time by a factor α. Equivalently, the samples can
be thought to be obtained by fractionally delaying the signal by a factor
Digital Filters with MATLAB Ricardo A. Losada
4.2 Interpolation 81
30 32 34 36 38 40 42 44 46 48 50
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
Time
A
m
p
l
i
t
u
d
e
Underlying analog signal
Sampled signal
Fractionally advanced signal
Figure 4.11: Fractional advance by a factor α = 0.4.
β = 1 −α. Both α and β are a fraction between zero and one. Thus, if x[n]
is our signal prior to interpolation, the signal consisting of interpolated
values is computed by passing the signal through a ﬁlter with transfer
function
H
frac
(z) = z
α
.
Of course advancing a signal in time is a noncausal operation. Since
the advance is less than one sample, we can make it causal by delaying
everything by one sample,
H
causal
= z
−1
z
α
= z
α−1
= z
−β
.
which shows the equivalence of a causal advance by a factor of α and a
delay (notice the negative sign) by a factor of β = 1 −α.
By taking the inverse Fourier transform, the impulse response of the
fractionaladvance ﬁlter z
α
can be easily found to be
h
frac
[n] =
sin(π(n + α))
π(n + α)
, −∞< n < ∞ (4.1)
Not surprisingly, the ideal fractional advance has an inﬁnite impulse
response that is also inﬁnitely noncausal. We will look at various FIR and
Digital Filters with MATLAB Ricardo A. Losada
82 Multirate Filter Design
Figure 4.12: Conceptual diagram for increasing the sampling rate.
IIR approximations to this ﬁlter later, but for now we will look at how a
bank of fractional advance ﬁlters can be used to increase the samplingrate
of a signal.
4.2.2 Increasing the samplingrate of a signal
In Appendix B we have already looked at what increasing the sampling
rate of a signal means in the frequency domain. In short, increasing the
samplingrate is accomplished by lowpass ﬁltering the signal with a digi
tal ﬁlter operating at the same rate we wish to increase the sampling rate
to
∗
. The key idea is to digitally produce a signal that would be exactly the
same as a signal we had obtained by sampling a bandlimited continuous
time signal at the higher sampling rate.
Conceptually, increasing the sampling rate is accomplished as depicted
in Figure 4.12. The upsampler inserts L −1 zeros between existing samples
in order to increase the sampling rate of the signal. This step in itself does
not modify the spectral content at all. All it does, is to change the Nyquist
interval to encompass a bandwidth that is now L times larger than before
upsampling. Because of this upsampling, the new Nyquist interval now
contains L −1 spectral replicas of the baseband spectrum. In order to in
terpolate between the original samples, replacing the zeros that have been
inserted with actual interpolated samples, it is necessary to lowpass ﬁlter
the upsampled signal in such a way that the L −1 unwanted spectral repli
cas are removed (see Appendix B). The ﬁlter H(z) performs such lowpass
ﬁltering.
In practice, increasing the sampling rate is never performed as shown
in Figure 4.12. The reason is that inserting all those zeros means the low
∗
Whenever we increase the sampling rate, we do not lowpass ﬁlter in order to reduce
bandwidth. On the contrary, we want to use all the information in the existing signal in
order to compute the new samples. The reason we lowpass ﬁlter is to remove spectral
replicas that are encompassed by the new Nyquist interval when the rate is increased.
See Appendix B for more on this.
Digital Filters with MATLAB Ricardo A. Losada
4.2 Interpolation 83
34 36 38 40 42 44 46
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
Time
A
m
p
l
i
t
u
d
e
Underlying analog signal
Original samples
Interpolated samples
Figure 4.13: Illustration of ideal bandlimited interpolation in the time domain.
pass ﬁlter would be performing a lot of unnecessary computations when
its input is just a zero. Instead, a socalled polyphase approach is taken in
order to efﬁciently increase the sampling rate. The polyphase approach is
easiest to understand by looking at things in the time domain.
The situation in the time domain is depicted in Figure 4.13 assuming
we want to increase the rate by a factor L = 5. We have seen that in order
to produce each sample between existing samples, we need a fractional
advance ﬁlter. Looking at Figure 4.13, we can see that we need to take
every input sample x
T
[n] and produce 5 output samples {x
T
′ [m]}, m =
5n + k, k = 0, . . . , 4 as follows (note that T = 0.5 and T
′
= T/5 = 0.1):
• x
T
′ [5n] = x
T
[n]
• x
T
′ [5n +1] = x
T
[n +
1
5
]
• x
T
′ [5n +2] = x
T
[n +
2
5
]
• x
T
′ [5n +3] = x
T
[n +
3
5
]
• x
T
′ [5n +4] = x
T
[n +
4
5
]
Digital Filters with MATLAB Ricardo A. Losada
84 Multirate Filter Design
Figure 4.14: Bank of ﬁlters used for interpolation. Each ﬁlter performs a fractional ad
vance of the input signal and has a different phase. The overall implementation is re
ferred to as a polyphase interpolation ﬁlter. For every input sample, we cycle through all
polyphase branches.
In general, the ideal interpolator consists of a bank of L ﬁlters, H
k
(z), k =
0, . . . , L − 1 which will fractionally advance the input signal by a factor
k/L, k = 0, . . . , L − 1. The outputs of the ﬁlters are then interleaved (i.e.
only one ﬁlter needs to operate per high rate output sample) to produce
the interpolated signal. This is depicted in Figure 4.14
The L ﬁlters that comprise the ﬁlter bank are the fractional advance
ﬁlters,
H
k
(z) = z
k/L
, k = 0, . . . , L −1.
Evaluating on the unit circle, we have
H
k
(e
jω
) = e
jωk/L
, k = 0, . . . , L −1
so that each ﬁlter H
k
(e
jω
) is allpass, i.e.
H
k
(e
jω
)
=1 and has linear phase,
arg{H
k
(e
jω
)} = ωk/L.
∗
∗
The term polyphase stems from this derivation. Each ﬁlter in the ﬁlter bank has a
different phase. The interpolator ﬁlter consists of L polyphase parallel branches, each
branch tasked with computing one of the L interpolated outputs. The timedomain view
of the ideal interpolation ﬁlter thus has the polyphase structure builtin.
Digital Filters with MATLAB Ricardo A. Losada
4.2 Interpolation 85
Herein lies the impossibility of designing these ﬁlters in an exact man
ner. We cannot design them as FIR ﬁlters because no FIR ﬁlter can be
allpass (except for a pure delay). We cannot design them as IIR ﬁlters, be
cause no stable IIR ﬁlter can have linear phase. However, it is clear how
we want to approximate the ideal interpolation ﬁlter bank.
FIR approximations will produce the exact linear phase, while approx
imating an allpass response as best possible. On the other hand, IIR ap
proximations will be exactly allpass, while trying to produce the required
phase.
It is enlightening
∗
to realize that the ﬁlters comprising the ﬁlter bank
are the polyphase components of the ideal interpolation ﬁlter derived in
(1.2)!
Indeed, the impulse response of each fractional advance ﬁlter in the
ﬁlter bank is given by the inverse DTFT,
h
k
[n] =
1
2π
π
−π
e
jωk/L
e
jωn
dω =
sin
π
Ln+k
L
π
Ln+k
L
this corresponds to taking the transfer function corresponding to the ideal
lowpass ﬁlter (1.1) with the cutoff frequency set to π/L and rewriting it in
the form
H
LP
(z) = . . . + h[0] + z
−L
h[L] + . . .
+ z
−1
(. . . + h[1] + z
−L
h[L +1] + . . .)
.
.
.
+ z
−(L−1)
(. . . + h[L −1] + z
−L
h[2L −1] + . . .)
which can be written as
H
LP
(z) = H
0
(z
L
) + z
−1
H
1
(z
L
) + . . . + z
−(L−1)
H
L−1
(z
L
).
The subﬁlters H
k
(z) are the polyphase components (each one is pre
ceded by a different phase, z
−k
) of the original transfer function. The im
pulse responses of each subﬁlter correspond to the L decimated sequences
of the ideal impulse response by again writing uniquely m = Ln + k, k =
0, . . . , L −1 in (1.2).
∗
The reality is that this should be expected given that we had already determined that
the ideal interpolator was an ideal lowpass ﬁlter. Yet it is nice to see that things ﬁt in
even though we have approach the derivation of the ideal interpolator fromtwo different
perspectives.
Digital Filters with MATLAB Ricardo A. Losada
86 Multirate Filter Design
4.2.3 Design of FIR interpolation ﬁlters
While interpolation ﬁlters are simply lowpass ﬁlters that can be designed
with the various techniques outlined previously, the polyphase ﬁlters that
compose the ideal interpolation ﬁlter give some insight on things to be
looking for when designing interpolation ﬁlters.
Consider an interpolation by a factor of L. The ideal L polyphase ﬁlters
will have a groupdelay given by
−
k
L
, k = 0, . . . , L −1
For simplicity, consider an FIR approximation to the ideal interpolation
ﬁlter where the order is of the form N = 2LM. Then each polyphase ﬁlter
will have order N/L = 2M.
Note that the ideal interpolation ﬁlter is inﬁnitely noncausal. After ﬁ
nite length truncation, it is possible to make the approximation causal by
delaying by half the ﬁlter order, N/2. However, because we will imple
ment in efﬁcient polyphase form, we can make each polyphase component
causal by delaying it by M samples.
The delay will mean the introduction of a phase component in the re
sponse of each polyphase component. So that instead of approximating
the ideal fractional advance e
jωk/L
the polyphase components will approx
imate e
jω(k/L−M)
. The groupdelay will consequently be of the form
−
dφ(ω)
dω
= −
dω(k/L − M)
dω
= M−k/L.
A problem that arises is that even though the FIR approximation to
the ideal interpolation ﬁlter is symmetric and thus has linear phase, the
polyphase components are not necessarily symmetric and thus will not
necessarily have exact linear phase. However, for each non symmetric
polyphase ﬁlter, there is a mirror image polyphase ﬁlter which will have
the exact same magnitude response with a mirror image groupdelay that
will compensate any phase distortion.
Example 42 We design a Nyquist ﬁlter that interpolates by a factor L = 4. The
Nyquist ﬁlter operates at the high rate (four times the input rate). It is a 4thband
ﬁlter with a cutoff frequency given by π/4. This ﬁlter will remove 3 spectral repli
cas encompassed by the augmented Nyquist interval once the signal is upsampled.
The ﬁlter is implement in efﬁcient polyphase manner.
Digital Filters with MATLAB Ricardo A. Losada
4.2 Interpolation 87
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−100
−80
−60
−40
−20
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 4.15: FIR Nyquist interpolate by 4 ﬁlter designed with a Kaiser window. The
ﬁlter removes 3 spectral replicas and operates at four times the input rate.
L = 4; % Interpolation factor
Band = 4; % Band for Nyquist design
Hf = fdesign.interpolator(L,'Nyquist',Band,'TW,Ast',0.1,80);
Hint = design(Hf,'kaiserwin');
The resulting Nyquist ﬁlter is shown in Figure 4.15.
For the design from the previous example, it is worth taking a look at
the magnitude response and groupdelay of the polyphase components of
the resulting FIR ﬁlter. The magnitude response is shown in Figure 4.16
while the groupdelay is shown in Figure 4.17. The magnitude response
reveals that only one of the polyphase ﬁlters is a perfect allpass, while
the others are approximations that fadeoff at high frequency. The magni
tude responses of the 2nd and 4th polyphase subﬁlters are identical. The
groupdelays show a fractional advance of 0, 0.25, 0.5, and 0.75 for the
four polyphase subﬁlters. This advance is relative to a nominal delay of
M = 13 samples. The ﬁlter length is 2LM +1 = 105. Note that two of the
polyphase components do not have perfectly ﬂat group delays. However,
the nonlinear shape of one compensates for the other so that overall the
interpolation ﬁlter has linear phase.
Digital Filters with MATLAB Ricardo A. Losada
88 Multirate Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−7
−6
−5
−4
−3
−2
−1
0
1
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Filter #1: Polyphase(1)
Filter #1: Polyphase(2)
Filter #1: Polyphase(3)
Filter #1: Polyphase(4)
Figure 4.16: Magnitude response of polyphase components for a Nyquist FIR interpolate
byfour ﬁlter.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
9
10
11
12
13
14
15
16
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Filter #1: Polyphase(1)
Filter #1: Polyphase(2)
Filter #1: Polyphase(3)
Filter #1: Polyphase(4)
Figure 4.17: Groupdelay of polyphase components for a Nyquist FIR interpolatebyfour
ﬁlter.
Digital Filters with MATLAB Ricardo A. Losada
4.2 Interpolation 89
Notice that the polyphase components can be obtained by taking every
Lth sample of the lowpass impulse response as stated above. For example,
it is easy to verify this for the second polyphase:
p = polyphase(Hint);
isequal(p(2,1:end1),Hint.Numerator(2:4:end)) % Returns true
In general, for all Nyquist designs, one of the polyphase components
will have perfectly ﬂat magnitude response and groupdelay. This polyphase
component is a simple delay which provides a fractional advance of zero.
The presence of this polyphase components ensures that the input sam
ples are ”passed undisturbed” to the output (they are simply delayed).
In general, a nonideal nonNyquist lowpass ﬁlter will not have a perfect
delay as one of its polyphase branches and therefore will alter somewhat
the input samples. However, this is usually not a major issue in terms of
distortion. Nevertheless, Nyquist ﬁlters are often used because of their
reduced implementation cost given that one of the polyphase branches is
simply a delay.
4.2.4 Design of IIR halfband interpolators
As with decimation, the use of halfband ﬁlters for interpolation is enticing
given their efﬁciency. In the case of interpolation by a factor L = 2, FIR
halfband ﬁlters (being Nyquist ﬁlters) will have one of their polyphase
branches given simply by a delay.
IIR ﬁlters will not necessarily have one of their branches given by a
simple delay because we do not use their impulse response directly to im
plement them. However, quasilinear phase IIR ﬁlters are implemented in
such a way that one of their polyphase branches is a pure delay. Neverthe
less, elliptic halfband interpolation ﬁlters that meet the same speciﬁcations
are still more efﬁcient even though they do not have a simple delay as one
of its polyphase branches (and therefore, as stated in Chapter 4, elliptic
halfband ﬁlters are not Nyquist and as a result, they modify the input
samples when interpolating).
The allpassbased IIR polyphase structure used to implement interpo
lation by two is shown in Figure 4.18. Note that because we have used
the Noble identities, the transfer functions of the allpass ﬁlters in (3.1) are
given as powers of z rather than powers of z
2
.
Digital Filters with MATLAB Ricardo A. Losada
90 Multirate Filter Design
Figure 4.18: Allpassbased IIR polyphase implementation of interpolation by 2.
Example 43 Design elliptic and quasi linearphase IIR halfband interpolateby
two ﬁlters for the given speciﬁcations.
Hf = fdesign.interpolator(2,'halfband','TW,Ast',0.08,55);
Hlin = design(Hf,'iirlinphase');
Hellip = design(Hf,'ellip');
cost(Hlin)
cost(Hellip)
The two polyphase branches for either design are perfect allpass ﬁlters. The ﬁlters
deviate from the ideal interpolation ﬁlter in their phase response. The groupdelay
of the polyphase branches for the quasi linearphase IIR design is shown in Figure
4.19. Note that one of the branches is a pure delay and therefore has perfectly ﬂat
groupdelay. The groupdelay of the polyphase subﬁlters for the elliptic design is
shown in Figure 4.20. Note how neither of the polyphase components has a ﬂat
groupdelay in this case.
4.2.5 Design of interpolators when working with Hertz
So far we have presented the design of interpolation ﬁlters in the context
of normalized frequency. If working with Hertz, the key point to keep in
mind is that when increasing the sampling rate we should not reduce the
bandwidth of the signal. Once again, the interpolation ﬁlter is used not to
reduce bandwidth, but to remove spectral replicas.
Example 44 Suppose we have an audio signal sampled at 48 kHz and we want
to increase the sampling frequency to 96 kHz. The band of interest extends to 20
Digital Filters with MATLAB Ricardo A. Losada
4.2 Interpolation 91
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
14
16
18
20
22
24
26
28
30
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Filter #1: Polyphase(1)
Filter #1: Polyphase(2)
Figure 4.19: Groupdelay of polyphase components for a quasi linearphase IIR halfband
interpolatebytwo ﬁlter.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
5
10
15
20
25
30
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Filter #1: Polyphase(1)
Filter #1: Polyphase(2)
Figure 4.20: Groupdelay of polyphase components for an elliptic IIR halfband
interpolatebytwo ﬁlter.
kHz. Since we want to increase the sampling frequency by a factor of 2, we can
use a (FIR or IIR) halfband ﬁlter,
Digital Filters with MATLAB Ricardo A. Losada
92 Multirate Filter Design
0 5 10 15 20 25 30 35 40 45
−100
−80
−60
−40
−20
0
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 4.21: Magnitude response of halfband ﬁlter used to increase the sampling rate by
2.
f = fdesign.interpolator(2,'halfband','TW,Ast',8000,96,96000);
H = design(f,'equiripple');
The magnitude response of the ﬁlter can be seen in Figure 4.21. Note that the
passband extends to 20 kHz as desired. The cutoff frequency for the ﬁlter is 24
kHz. The spectral replica of the original audio signal centered around 48 kHz will
be removed by the halfband ﬁlter.
4.3 Increasing the sampling rate by a fractional
factor
So far we have discussed increasing the sampling rate by an integer factor.
In some cases, we want to increase the sampling rate by a fractional factor.
This can be done trivially for rational factors.
Suppose we want to increase the rate by a factor of L/M with L > M.
A trivial way of doing this is to perform a full interpolation by a factor of
L and then discarding the samples we don’t want, that is we keep one out
of every M samples after interpolating.
Digital Filters with MATLAB Ricardo A. Losada
4.3 Increasing the sampling rate by a fractional factor 93
Figure 4.22: Conceptual conﬁguration for increasing the sampling rate of a signal by a
fractional factor. L > M.
Figure 4.22 illustrates the idea. The role of the upsampler+ﬁlter combi
nation is the same as for the case when we increase the rate by an integer
factor. Once we have increased the rate, we discard samples we don’t
need, keeping only the ones required for the new rate.
While the procedure we have just described is trivial, it is inefﬁcient
since many of the samples that have been computed via interpolation are
subsequently discarded. Instead, to implement fractional interpolation ef
ﬁciently we compute only the samples we intend to keep.
Speciﬁcally, if the polyphase ﬁlters are H
0
(z), H
1
(z), . . . , H
L−1
(z), in
stead of using H
0
(z) to compute the ﬁrst output, H
1
(z) to compute the
second output and so forth, we use H
0
(z) for the ﬁrst output, we skip
M−1 polyphase ﬁlters and use H
M
(z) for the second output and so forth.
As an example, if L = 3 and M = 2, the sequence of polyphase ﬁlters
used are H
0
(z), then skip H
1
(z), then use H
2
(z), then, for the next input,
skip H
0
(z), then use H
1
(z), then skip H
2
(z), and then start again by using
H
0
(z).
The idea in general is shown in Figure 4.23. The structure resembles
that of interpolation by an integer factor except that only the branches
that are going to produce an output we will keep are used for every input
sample.
Example 45 We will work with Hertz to illustrate the fact that when we inter
polate (by either an integer or a fractional factor) we never reduce the bandwidth
of the input signal.
Suppose we have a signal sampled at 500 Hz. The band of interest for the
signal is from 0 to 200 Hz, i.e. a transition width of 100 Hz has been allocated.
Say we want to increase the sampling rate to 1600 Hz. We choose to use a 16th
band Nyquist ﬁlter. The transition width is set to 100 Hz in order to not disturb
information contained in the band of interest.
L = 16;
M = 5;
Digital Filters with MATLAB Ricardo A. Losada
94 Multirate Filter Design
Figure 4.23: Bank of ﬁlters used for fractional interpolation. Unlike interpolation by an
integer factor, not all polyphase branches are used for each input sample.
Band = L;
Fs = 500*L; % High sampling rate
TW = 100;
Ast = 80;
Hf = fdesign.rsrc(L,M,'Nyquist',Band,'TW,Ast',TW,Ast,Fs);
Hrsrc = design(Hf,'kaiserwin');
Note that the sampling frequency we had to set for the design was that corre
sponding to full interpolation by 16, i.e. 16 ×500. This is because, as we have
explained, the ﬁlter is designed as a regular interpolateby16 ﬁlter, but is im
plemented efﬁciently so that no sample to be discarded is actually computed. The
magnitude response of the ﬁlter is shown in Figure 4.24. The passband of the ﬁlter
extends to 200 Hz so that the band of interest is left undisturbed. The resulting
sampling frequency is 1600. However, this ﬁlter removes 15 spectral replicas as
if the sampling frequency was being increased to 8000. The downsampling by 5
produces 4 spectral replicas centered around multiples of the resulting sampling
frequency, i.e. 1600.
Digital Filters with MATLAB Ricardo A. Losada
4.4 Fractional decimation 95
0 0.5 1 1.5 2 2.5 3 3.5
−100
−80
−60
−40
−20
0
20
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 4.24: Magnitude response of ﬁlter used for fractional interpolation. The passband
extends to 200 Hz so that the band of interest is left untouched.
4.4 Fractional decimation
We now return to the problem of decimating by a fractional factor. For
now, we will restrict the discussion to rational values. As we mentioned
before, in order to perform fractional decimation, it is necessary to com
pute samples lying between existing samples. We now know how to do
so by using interpolation.
It turns out that the implementation we have just described for frac
tional interpolation can be used for fractional decimation as well. The
only difference is that L < M in this case. (Conceptually, Figure 4.22 still
applies with the caveat that now L < M.)
In terms of designing the ﬁlter however, we need to be careful with
where we set the cutoff frequency since it is no longer true that we want
to keep the full spectrum of the input signal.
Indeed, fractional decimation is appropriate when the bandwidth of a
signal is being reduced by a fractional factor. We use fractional decimation
to reduce the rate by a corresponding factor.
Suppose for instance that we have a signal sampled at 1000 Hz. We
are interested in keeping the information contained from 0 to 280 Hz. We
decide to both lowpass ﬁlter the signal and reduce the bandwidth by a
Digital Filters with MATLAB Ricardo A. Losada
96 Multirate Filter Design
factor of 7/10.
L = 7;
M = 10;
Band = M;
Fs = 1000*L; % High sampling rate
TW = 140;
Ast = 80;
Hf = fdesign.rsrc(L,M,'Nyquist',Band,'TW,Ast',TW,Ast,Fs);
Hrsrc = design(Hf,'kaiserwin');
Note that once again, the sampling frequency set for the ﬁlter designed
is set as if full interpolation were to be implemented. The choice of the
band however, is made as M rather than L (compare to the previous exam
ple) so that the resulting ﬁlter reduces the bandwidth by a factor of L/M.
The transition width is chosen so that the passband of the ﬁlter extends to
the desired 280 Hz. The computation is simple, f
c
−TW/2, where f
c
is the
cutoff frequency which is given by f
s
/(2Band) = 350 Hz. Subtracting half
the transition width, i.e. 70, means the passband of the ﬁlter will extend
to 280 Hz as intended. The passband details for the ﬁlter can be seen in
Figure 4.25.
If the input signal had a ﬂat spectrum occupying the full Nyquist in
terval (worst case), after ﬁltering and fractional decimation, the spectrum
of the signal would take the shape of the ﬁlter. Its spectral replicas would
be centered around multiples of the new sampling frequency, i.e. 700 Hz.
The baseband spectrum along with the ﬁrst positive two spectral replicas
is shown in Figure 4.26. Note that as before, we have allowed for transition
band overlap, but the baseband of interest presents no signiﬁcant aliasing.
4.5 Summary and look ahead
In this chapter we have presented design considerations for multirate ﬁl
ters. In particular, it is important to understand how the cutoff frequency
for ﬁlters should be set commensurate to bandwidth reduction in the case
of decreasing the sampling rate. Also, we presented the rather obvious
fact that when increasing the sampling rate of a signal, we do not wish to
reduce its bandwidth.
Digital Filters with MATLAB Ricardo A. Losada
4.5 Summary and look ahead 97
0 0.05 0.1 0.15 0.2 0.25 0.3
16.9012
16.9014
16.9016
16.9018
16.902
16.9022
16.9024
16.9026
16.9028
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 4.25: Passband details of ﬁlter designed for fractional decimation. The passband
extends to 280 Hz so that the band of interest is left untouched.
Lowpass ﬁlters are the most common ﬁlters for multirate applications.
However, highpass and bandpass ﬁlters can also be used for both decreas
ing or increasing the sampling rate of a signal. Although we did not touch
upon the case when increasing the sampling rate, using a bandpass rather
than a lowpass for such case is simply a matter of choosing which spectral
replicas should be removed.
We have presented Nyquist ﬁlters as the preferred type of lowpass ﬁl
ters for multirate applications, however any lowpass ﬁlter in principle can
be used.
When using Nyquist ﬁlters, equiripple FIR ﬁlters are not always the
best choice. Kaiser window designs may have a smaller passband ripple
along with increasing stopband attenuation that may be desirable for re
moval of spectral replicas/aliasing attenuation.
IIR halfband ﬁlters have presented as an extremely efﬁcient way of im
plementing decimate/interpolate by two ﬁlters.
In the next chapter we will see that multirate Nyquist ﬁlters have the
interesting property that cascades of such ﬁlters remain Nyquist overall.
As such, we will see that to performefﬁcient multirate ﬁltering, multistage
designs can be a very attractive solution. In particular, cascading efﬁcient
Digital Filters with MATLAB Ricardo A. Losada
98 Multirate Filter Design
0 200 400 600 800 1000 1200 1400 1600 1800 2000
−100
−80
−60
−40
−20
0
20
Frequency (Hz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Baseband spectrum
First replica
Second replica
Figure 4.26: Baseband spectrum and two positives spectral replicas of fractionally dec
imated signal. The input signal is assumed to have a ﬂat spectrum which occupies the
entire Nyquist interval.
halfband ﬁlters may be a very desirable way of implementing changes in
sampling rate by a factor given by a power of two.
Digital Filters with MATLAB Ricardo A. Losada
Chapter 5
Multistage/Multirate Filter
Design
Overview
Generally, given a ﬁxed passband ripple/stopband attenuation, the nar
rower the transition band of a ﬁlter, the more expensive it is to implement.
A very effective way of improving the efﬁciency of ﬁlter designs is to use
several stages connected in cascade (series). The idea is that one stage
addresses the narrow transition band but manages to do so without re
quiring a high implementation cost, while subsequent stages makeup for
compromises that have to be taken in order for the ﬁrst stage to be efﬁ
cient (usually this means that subsequent stages remove remaining spec
tral replicas).
In this chapter we start by discussing the socalled interpolated FIR
(IFIR) ﬁlter design method. This methods breaks down the design into
two stages. It uses upsampling of an impulse response in order to achieve
a narrow transition band while only adding zeros to the impulse response
(therefore not increasing the complexity). The upsampling introduces spec
tral replicas that are removed by the second stage ﬁlter which is a lowpass
ﬁlter with less stringent transition bandwidth requirements.
We will showthat multirate implementations of multistage designs are
the most effective way of implementing these ﬁlters. The idea follows
upon the notion we have already discussed in Chapter 4 of reducing the
sampling rate whenever the bandwidth of a signal is reduced.
100 Multistage/Multirate Filter Design
We then extend the multistage implementation to more than two stages.
Determining the optimal number of stages (and the decimation factor of
each stage) in order to most efﬁciently implement a ﬁlter for a given set
of speciﬁcations is a hard manual task. Fortunately, we show tools which
perform these designs automatically for us.
As mentioned in Chapter 4, Nyquist ﬁlters should be the preferred de
signs used for multirate applications. The use of Nyquist ﬁlters in mul
tistage implementations will be explored. The interesting property that
Nyquist ﬁlters retain the Nyquist property when implemented in a multi
rate/multistage fashion is discussed. We will show that these designs are
very efﬁcient.
A particular case of Nyquist ﬁlters which are very efﬁcient for multi
rate/multistage applications are halfband ﬁlters. We will see how we can
obtain very efﬁcient designs using halfband ﬁlters to implement some (or
all) of the stages in a multistage design. Moreover, we can use IIR half
band multirate ﬁlters implemented in polyphase form in order to increase
the efﬁciency of designs even further.
Finally, we show that efﬁcient multistage implementations apply to in
terpolation as well as decimation. Multistage interpolation implementa
tions will typically be mirror images of multistage decimation. Whereas
with multistage decimation the simplest ﬁlter always should be the ﬁrst
stage of the cascade (operating at the highest sampling frequency), with
multistage interpolation it is the last stage that contains the simplest ﬁlter
(since in this case it is the last stage that operates at the highest sampling
frequency).
5.1 Interpolated FIR (IFIR) designs
For any given FIR design algorithm, if the peak ripple speciﬁcations re
main the same, the ﬁlter order required to meet a given speciﬁcations set
is inversely proportional to the transition width allowed.
When the transition width is small, such as in the Speciﬁcations Set 3,
the ﬁlter order required may be quite large. This is one of the primary
disadvantages of FIR ﬁlters. We have already seen that relaxing the linear
phase requirement results in a signiﬁcant savings in the number of ﬁlter
coefﬁcients.
The socalled interpolated FIR (IFIR) approach [25],[26],[27] yields lin
Digital Filters with MATLAB Ricardo A. Losada
5.1 Interpolated FIR (IFIR) designs 101
Figure 5.1: The IFIR implementation. An upsampled ﬁlter is cascaded with an image
suppressor ﬁlter to attain an overall design with a reduced computational cost.
ear phase FIR ﬁlters that can meet the given speciﬁcations with a reduced
number of multipliers.
The idea is rather simple. Since the length of the ﬁlter grows as the
transition width shrinks, we don’t design a ﬁlter for a given (small) tran
sition width. Rather, we design a ﬁlter for a multiple L of the transition
width. This ﬁlter will have a signiﬁcantly smaller length than a direct
design for the original (small) transition width. Then, we upsample the im
pulse response by a factor equal to the multiple of the transition width, L.
Upsampling will cause the designed ﬁlter to compress, meeting the origi
nal speciﬁcations without introducing extra multipliers (it only introduces
zeros, resulting in a larger delay). The price to pay is the appearance of
spectral replicas of the desired ﬁlter response within the Nyquist interval.
These replicas must be removed by a second ﬁlter (called in this context
the interpolation ﬁlter or image suppressor ﬁlter) that is cascaded with the
original to obtain the desired overall response. Although this extra ﬁlter
introduces additional multipliers, it is possible in many cases to still have
overall computational savings relative to conventional designs. The im
plementation is shown in Figure 5.1.
The idea is depicted by example in Figure 5.2 for the case of an upsam
pling factor of 3. The “relaxed” design is approximately of one third the
length of the desired design, if the latter were to be designed directly. The
upsampled design has the same transition width as the desired design.
All that is left is to remove the spectral replica introduced by upsampling.
This is the job of the image suppressor ﬁlter.
As an example of the computational cost savings, consider once again
the design Speciﬁcations Set 3. The number of multipliers required for a
single linear phase design was 263. An IFIR design can attain the same
specs with 127 multipliers when using an upsampling factor of 6:
Digital Filters with MATLAB Ricardo A. Losada
102 Multistage/Multirate Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.5
1
1.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.5
1
1.5
Relaxed design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.5
1
1.5
Upsampled design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.5
1
1.5
Resulting design
Desired design
image supressor
Figure 5.2: Illustration of the IFIR design paradigm. Two ﬁlters are used to attain strin
gent transition width speciﬁcations with reduced total multiplier count when compared
to a single ﬁlter design.
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.12,.14,.175,60);
Hifir = design(Hf,'ifir','UpsamplingFactor',6);
cost(Hifir)
The response of the upsampled ﬁlter and the image suppressor ﬁlter is
shown in Figure 5.3. The overall response, compared to a single linear
phase equiripple design is shown in Figure 5.4.
5.1.1 Further IFIR optimizations
A drawback in the IFIR design is that the passband ripples of the two ﬁl
ters are combined in a disorderly fashion. In the worst case scenario, they
Digital Filters with MATLAB Ricardo A. Losada
5.1 Interpolated FIR (IFIR) designs 103
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Image supressor filter
Upsampled filter
Figure 5.3: Magnitude response of the upsampled ﬁlter and the image suppressor ﬁlter
in an IFIR design.
can add up, requiring the design to ensure that the sum of the two peak
passband ripples does not exceed the original set of speciﬁcations. Close
inspection of the passband of the overall design in the previous example,
shown in Figure 5.5, reveals a rather chaotic behavior (but certainly within
spec.) of the ripple.
Further optimized designs, [4], [28], attain a much cleaner passband
behavior by jointly optimizing the design of the two ﬁlters to work better
together. This results in a ﬁlter that can meet the speciﬁcations set with an
even further reduction in the number of multipliers. The savings are espe
cially signiﬁcant for the image suppressor ﬁlter, which is greatly simpliﬁed
by this joint optimization.
Utilizing this joint optimization, the Speciﬁcations Set 3 can be met
with only 74 multipliers, once again for an upsampling factor of 6.
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.12,.14,.175,60);
Hifir = design(Hf,'ifir','UpsamplingFactor',6,...
'JointOptimization',true);
cost(Hifir)
The manner in which the two ﬁlters work together is best described
Digital Filters with MATLAB Ricardo A. Losada
104 Multistage/Multirate Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
IFIR design
Conventional equiripple design
Figure 5.4: Overall magnitude response of an IFIR design and a conventional equiripple
design. The IFIR implementation requires 127 multipliers vs. 263 for the conventional
implementation.
by looking at their magnitude responses, shown in Figure 5.6. By pre
compensating for a severe “droop” in the image suppressor ﬁlter, a ﬂat
passband can be achieved with dramatic savings in the number of multi
pliers required for the image suppressor ﬁlter. Out of the 74 multipliers
required, 29 are for the image suppressor ﬁlter and 45 for the upsampled
ﬁlter. By contrast, in the previous IFIR design, 78 of the 127 multipliers
correspond to the image suppressor ﬁlter, while 49 correspond to the up
sampled ﬁlter.
The passband details of the overall design show a nice equiripple be
havior, hinting at a much better optimized design. The passband details
are shown in Figure 5.7.
The reader interested in further modiﬁcations/improvements to IFIR
ﬁlters is referred to [29].
5.1.2 Multirate implementation of IFIR design
When designing an IFIR ﬁlter, the upsampling factor L used must be such
that the (normalized) stopbandedge frequency ω
s
satisﬁes Lω
s
< π. This
Digital Filters with MATLAB Ricardo A. Losada
5.1 Interpolated FIR (IFIR) designs 105
0 0.02 0.04 0.06 0.08 0.1 0.12
−0.08
−0.06
−0.04
−0.02
0
0.02
0.04
0.06
0.08
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 5.5: Passband details of an IFIR design revealing a rather chaotic behavior of the
ripple.
implies that the bandwidth of the output signal would be reduced by a
factor of L.
It is convenient from a computational cost perspective to reduce the
sampling frequency of the ﬁltered signal, since at that point the Nyquist
criterion is being unnecessarily oversatisﬁed. Subsequent processing of
the ﬁltered signal without reducing its sampling rate would incur in un
necessary (and expensive) redundant processing of information.
The idea is to downsample the ﬁltered signal by a factor of L to match
the reduction in bandwidth due to ﬁltering. If we denote by I(z) the image
suppressor ﬁlter and by U(z
L
) the upsampled ﬁlter, we would have a cas
cade of these two ﬁlters and a downsampler as shown in Figure 5.8. Using
the Noble identities, we can “commute” the downsampler and U(z
L
) to
obtain the implementation shown in Figure 5.9. The combination of I(z)
and the downsampler form a decimator which can be implemented efﬁ
ciently in polyphase form.
Example 46 Consider the same speciﬁcations as before, but now casted as a dec
imation ﬁlter design:
Hf = fdesign.decimator(6,'Lowpass',...
Digital Filters with MATLAB Ricardo A. Losada
106 Multistage/Multirate Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
10
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Image supressor filter
Upsampled filter
Figure 5.6: Magnitude response of the upsampled ﬁlter and the image suppressor ﬁlter
in an optimized IFIR design. The two ﬁlters are jointly optimized in the design to achieve
a speciﬁcations set with a reduced number of multipliers.
'Fp,Fst,Ap,Ast',.12,.14,.175,60);
Hifir = design(Hf,'ifir','UpsamplingFactor',6,...
'JointOptimization',true);
cost(Hifir)
Looking at the results from the cost function, we can see that while the num
ber of multipliers remains 74 (the same as for a singlerate design), the number
of multiplications per input sample has been reduced substantially from 74 to
12.333. The number 12.333 is computed as follows. Of the 29 multipliers used
for the image suppressor ﬁlter, because of its efﬁcient decimating implementa
tion, only 29/6 multiplications are performed on average per input sample. Be
cause of decimation, only one out of 6 input samples (to the entire cascade) ever
reaches U(z), so per input sample, the total number of multiplications on average
is 29/6 +45/6 = 12.333.
Digital Filters with MATLAB Ricardo A. Losada
5.1 Interpolated FIR (IFIR) designs 107
0 0.02 0.04 0.06 0.08 0.1 0.12
−0.1
−0.08
−0.06
−0.04
−0.02
0
0.02
0.04
0.06
0.08
0.1
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 5.7: Passband details of an optimized IFIR design. The optimized design exhibits
nice equiripple behavior.
Figure 5.8: Cascading an IFIR implementation with a downsampler.
Figure 5.9: Interchange of the downsampler and the upsampled ﬁlter using the Noble
identities.
Digital Filters with MATLAB Ricardo A. Losada
108 Multistage/Multirate Filter Design
5.2 Multistage/Multirate Designs
The procedure outlined in the previous section can be generalized to mul
tiple stages. There are a couple of ways of thinking about the philosophy
behind this. Keeping in mind that the image suppressor ﬁlter I(z) is noth
ing but a lowpass ﬁlter, as we increase the upsampling factor L, so that
the upsampled ﬁlter U(z) becomes simpler, the order required by I(z) to
remove the spectral replicas as they come closer to each other increases as
well. In other words, decreasing the complexity and computational cost
of U(z) results in an increased ﬁlter order for I(z). If the speciﬁcations
for I(z) become too stringent, the cost of implementing this ﬁlter may out
weigh the beneﬁts of the savings afforded to U(z). In such a situation, one
may consider using an IFIR approach to implement I(z) itself. After all,
the original idea behind the IFIR approach is to implement a lowpass ﬁl
ter as a cascade of two ﬁlters, U(z) and I(z). Since I(z) is a lowpass ﬁlter
itself, why not apply the IFIR approach recursively and break up I(z) into
a cascade of two ﬁlters. Of course, of these two new ﬁlters, one of them is
also a lowpass image suppressor ﬁlter which can in turn be implemented
as a cascade of two ﬁlters and so on.
In general this line of thinking leads us to implementing a ﬁlter in mul
tiple stages. The multirate implementation yields a multiratemultistage
design which lowpass ﬁlters data while decreasing the sampling rate at
each stage for maximum computational efﬁciency. Determining the op
timal number of stages, in the sense that the computational cost is mini
mized can be a difﬁcult task. Fortunately, the Filter Design Toolbox pro
vides tools to automate such designs. We will look at such tools in a mo
ment, but before that, let’s look at a different line of thought that also re
sults in multistage/multirate ﬁlter designs.
We know that the ﬁlter order is increased as the transition width of a
ﬁlter is decreased. When we talk about decreasing the transition width,
we are usually referring to the width in terms of normalized frequency.
In terms of absolute frequency, one could ask what is a narrow transition
width: 1 kHz? 100 Hz? maybe 10 Hz? The answer is: it depends. A tran
sition width is narrow relative to the sampling frequency that is involved.
For example 10 Hz is probably quite narrow relative to a sampling fre
quency in the gigahertz range, but it is not narrow relative to a sampling
frequency of say 50 Hz. One should assess whether a transition region is
narrow by considering the normalized transition width ∆f /f
s
rather than
Digital Filters with MATLAB Ricardo A. Losada
5.2 Multistage/Multirate Designs 109
the absolute transition width ∆f .
In many applications, we cannot change the transition width required
for a ﬁlter design just because it makes the ﬁlter order too large. The ap
plication sets the requirement for the transition width and this is typically
something that cannot be changed. What we can do however, is change
the sampling frequency so that the transition width is not narrow relative
to such sampling frequency. This is another way of looking at the idea
behind multistage/multirate designs. If a very narrow transition width is
required relative to the sampling frequency involved, the multistage ap
proach is to not try to achieve the narrow transition in one shot. Instead,
we lower the sampling rate in stages by using simple lowpass ﬁlters un
til we achieve a rate at which the required transition width is not large
relative to such rate. Then we design a ﬁlter that provides the required
transition.
The computational savings come from two factors. On the one hand,
the normalized transition width ∆f /f
s
will be much larger since f
s
is
smaller, resulting in a ﬁlter of lesser order. On the other hand, because the
sampling rate is lower at this point, the number of input samples that have
to be processed by the ﬁlter is much smaller than if we were handling the
original large sampling rate. Of course there are other lowpass ﬁlters we
need to implement that handle the full high sampling rate and the large
number of input samples associated with it. However, these other ﬁlter
are implemented with large transition widths, so that their order is low
thus requiring a small number of operations per input sample.
In terms of the frequency response, the simple ﬁlters operating at high
sampling rates are used to remove spectral replicas from the ﬁlters oper
ating at lower sampling rates downstream. The concepts are easily illus
trated through an example.
Example 47 Consider the design of a lowpass ﬁlter with the following speciﬁca
tions:
Speciﬁcations Set 6
1. Cutoff frequency: 550 Hz
2. Transition width: 100 Hz
3. Maximum passband ripple: 0.1 dB
Digital Filters with MATLAB Ricardo A. Losada
110 Multistage/Multirate Filter Design
4. Minimum stopband attenuation: 80 dB
5. Sampling frequency: 10 kHz
The speciﬁcations imply that the band of interest extends from 0 to 500 Hz.
Since the bandwidth is being reduced by about a factor of 8, we decide to design a
decimation ﬁlter with a decimation factor of 8 to meet the speciﬁcations and reduce
the samplingrate after ﬁltering accordingly.
If we were to design a singlestage equiripple decimator, the design would
take 343 multipliers and about 48 multiplications per input sample. In order to
design a general multistage/multirate ﬁlter and allow for the tools to determine
the optimal number of stages we use the following commands:
Hf = fdesign.decimator(8,'Lowpass',...
'Fp,Fst,Ap,Ast',500,600,.1,80,1e4);
Hmulti = design(Hf,'multistage');
cost(Hmulti)
The number of multipliers required is 114. The number of MPIS is 18.875.
By inspecting the resulting design, we can see that a 3stage ﬁlter has resulted.
In this example, each stage has a decimation factor of 2, which accounts for the
overall decimation factor of 8 we required.
∗
A plot of the magnitude response of each stage helps understand the behavior
of the design and the source for the computational savings. This is shown in Fig
ure 5.10. The simplest ﬁlter of all operates at the highest rate as should usually
be the case. This ﬁrst stage has a very wide transition band starting at 500 Hz
(therefore not affecting the band of interest) and ending at about 4450 Hz. The
second stage operates at 5 kHz given the decimation by two of the ﬁrst stage. Its
normalized transition width is also quite wide, given its sampling frequency. The
job of this ﬁlter is to eliminate spectral replicas of the third stage centered around
odd multiples of the third stage’s sampling frequency. Because the second stage
has replicas centered about multiples of 5 kHz, it cannot eliminate the spectral
replicas of the third stage centered around even multiples of the third stage’s sam
pling frequency. The ﬁrst stage takes care of those. Notice that only the last stage
has the narrow 100 Hz transition width. By that time, the sampling frequency has
∗
For this example, a jointoptimized IFIR design is more efﬁcient than a general mul
tistage design. This can happen in some cases, due to the highly optimized interaction
between the two stages as previously discussed. This jointoptimization is not carried
out for general multistage designs. This is an important thing to keep in mind.
Digital Filters with MATLAB Ricardo A. Losada
5.2 Multistage/Multirate Designs 111
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Stage one
Stage two
Stage three
Figure 5.10: Multistage design of decimation ﬁlter for Speciﬁcations Set 6.
been reduced by a factor of 4, so the normalized transition width is 4 times larger
(100/2500 vs. 100/10000) than it would have been if we had done a singlestage
design. This accounts for most of the computational savings.
The overall magnitude dB response of the threestage ﬁlter is obtained by
adding the responses of each stage. This is shown in Figure 5.11.
5.2.1 Setting the number of stages
If so desired, the number of stages can be manually controlled up to a cer
tain point. However, note that certain restrictions apply. The decimation
factor must be a number that can be factored into as many factors as the
number of stages. In some cases, it is advisable to manually try a different
number of stages than the one automatically provided by the tools since
similar computational costs may be found for different number of stages
and other things (such as implementation complexity) may factor in to the
decision of which design to use.
Example 48 We can use the Nstages option to control the number of stages in
a design. Consider the following two designs for the same design speciﬁcations:
Digital Filters with MATLAB Ricardo A. Losada
112 Multistage/Multirate Filter Design
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
−140
−120
−100
−80
−60
−40
−20
0
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 5.11: Overall magnitude response of multistage design for Speciﬁcations Set 6.
Hf = fdesign.decimator(16,'Lowpass',...
'Fp,Fst,Ap,Ast',.05,.06,.5,70);
Hmulti = design(Hf,'multistage');
Hmulti2 = design(Hf,'multistage','Nstages',3);
The number of stages that is determined automatically for Hmulti is 4. How
ever, we force Hmulti2 to have 3 stages. The computational cost of both designs
are quite comparable. However, the complexity of implementing 3 stages in hard
ware may be less than that of implementing 4 stages. This could be the deciding
factor between one design and the other.
5.3 Multistage/Multirate Nyquist ﬁlters
Multirate Nyquist ﬁlters have the interesting property that if you cascade
two or more of them together (all decimators or all interpolators) the re
sulting multistage/multirate ﬁlter is still a Nyquist ﬁlter [30]. This fact
allows us to extend the reasoning behind the use of multistage/multirate
designs to Nyquist designs.
Digital Filters with MATLAB Ricardo A. Losada
5.3 Multistage/Multirate Nyquist ﬁlters 113
We already know that Nyquist ﬁlters are wellsuited for (either deci
mation or interpolation) multirate applications. The ability to break down
a multirate Nyquist design into several multirate Nyquist stages provides
very efﬁcient designs. In many cases, halfband ﬁlters are used for the in
dividual stages that make up the multistage design. Whenever a halfband
ﬁlter is used for a stage, there is the possibility to use an extremely efﬁcient
IIR multirate halfband design as long as we allow for IIR ﬁlters as part of
the design.
Example 49 As an example, consider the design of a Nyquist ﬁlter that deci
mates by 8. We will compare singlestage a multistage design to illustrate the
computational savings that can be afforded by using multistage Nyquist ﬁlters.
Hf = fdesign.decimator(8,'nyquist',8,.016,80);
H1 = design(Hf,'kaiserwin');
H2 = design(Hf,'multistage');
H3 = design(Hf,'multistage','Nstages',2);
The computational costs of the three designs are summarized in the following
table:
NMult NAdd Nstates MPIS APIS NStages
H1 551 550 624 68.875 68.75 1
H2 93 90 174 15.625 14.75 3
H3 106 104 182 17.125 16.75 2
The equivalent overall ﬁlters for all three designs are 8band Nyquist ﬁlters.
The default multistage design, H2, is a 3stage ﬁlter with each individual stage
being a halfband ﬁlter (each halfband ﬁlter is different though). H3 is 4band
Nyquist decimator followed by a halfband Nyquist decimator.
5.3.1 Using IIR halfband ﬁlters
Whenever we have a halfband decimator (or interpolator) we may want
to consider using either an elliptic halfband ﬁlter (if phase linearity is not
an issue) or a quasi linearphase IIR halfband ﬁlter (if phase linearity is
important) to increase computational savings.
As an added bonus, all Nyquist designs tend to have a very small pass
band ripple. If we use IIR halfband ﬁlters, the passband ripple can be in
the microdB range or even smaller!
Digital Filters with MATLAB Ricardo A. Losada
114 Multistage/Multirate Filter Design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−150
−100
−50
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
3−stage FIR Nyquist
3−stage Nyquist linphase IIR
3−stage Nyquist ellip IIR
Figure 5.12: Passband phase response for multistage Nyquist FIR and IIR ﬁlters.
In the previous example, if we substitute the halfband ﬁlters of each
stage in H2 with quasi linearphase IIR ﬁlters,
H4 = design(Hf,'multistage','HalfbandDesignMethod','iirlinphase');
we can get saving close to a factor of 3 in both total number of multipliers
as well as MPIS.
If we can use elliptic halfbands,
H5 = design(Hf,'multistage','HalfbandDesignMethod','ellip');
the savings are about twice as good. The computational cost is shown
below
NMult NAdd Nstates MPIS APIS NStages
H4 35 70 75 5.625 11.25 3
H5 12 24 18 2.625 5.25 3
The magnitude response of the 3stage Nyquist FIR design along with
the two 3stage Nyquist IIR designs is shown in Figure 5.12. All three
designs behave similarly overall as expected since the speciﬁcations for
each halfband (each stage) are the same. However, although the 3stage
Digital Filters with MATLAB Ricardo A. Losada
5.4 Multistage interpolation 115
0 0.02 0.04 0.06 0.08 0.1 0.12
−1.5
−1
−0.5
0
0.5
1
1.5
x 10
−3
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
3−stage FIR Nyquist
3−stage Nyquist linphase IIR
3−stage Nyquist ellip IIR
Figure 5.13: Passband phase response for multistage Nyquist FIR and IIR ﬁlters.
FIR Nyquist design has a small passband ripple, it is nowhere near the
tiny passband ripple of the IIR designs. The passband details are shown
in Figure 5.13.
As stated before, the computational savings of the elliptic design come
at the expense of phase nonlinearity. On the other hand, the groupdelay
of the elliptic design is much lower than the other two designs. The pass
band groupdelay is shown in Figure 5.14.
We can use realizemdl(H4) or realizemdl(H5) to generate Simulink
blocks that implement these multistage decimators using halfband IIR ﬁl
ters in efﬁcient polyphase form.
5.4 Multistage interpolation
Just as with decimation, using multiple stages to perform interpolation
can result in signiﬁcant implementation savings. The reason once again
has to do with the ratio of the transition width relative to the sampling
frequency.
To see this, consider implementing a ﬁlter that interpolates by a factor
of 8, increasing the samplingrate from 1250 Hz to 10000 Hz with a cutoff
Digital Filters with MATLAB Ricardo A. Losada
116 Multistage/Multirate Filter Design
0.02 0.04 0.06 0.08 0.1 0.12
50
100
150
200
250
300
350
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
3−stage FIR Nyquist
3−stage Nyquist linphase IIR
3−stage Nyquist ellip IIR
Figure 5.14: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters.
frequency of 625 Hz and a transition width of 312.5 Hz. Let us compare
the transition width, relative to the sampling frequency of a singlestage
design vs. the ﬁrst stage of a multistage design. Suppose the ﬁrst stage
of the multistage design is a halfband ﬁlter that interpolates by a factor of
two (from 1250 Hz to 2500 Hz).
Figure 5.15 shows a comparison of the two ﬁlters. They both have the
same transition width, yet the sampling frequency ratio is 4to1. There
fore the ratio ∆f /f
s
is four times smaller for the singlestage ﬁlter than for
the ﬁrst stage of a multistage implementation. Accordingly, the number
of coefﬁcients for the singlestage design is 142 (with 135 adders), whereas
the ﬁrst stage of a multistage implementation has only 22 multipliers (and
21 adders). The fact that we have a savings of more than a factor of 4
in terms of number of multipliers is owed to the fact that we use a half
band ﬁlter for the latter design which yields further savings. Note that in
general for polyphase interpolators, the number of coefﬁcients equals the
number of multiplications per input sample (MPIS).
Of course, as is apparent from Figure 5.15, the two ﬁlters are not per
forming the same job, so the comparison is unfair. While the singlestage
design removes all spectral replicas in the new Nyquist interval (with
f
s
= 10000), the halfband ﬁlter only removes some spectral replicas. There
Digital Filters with MATLAB Ricardo A. Losada
5.4 Multistage interpolation 117
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
−120
−100
−80
−60
−40
−20
0
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
(
n
o
r
m
a
l
i
z
e
d
t
o
0
d
B
)
Magnitude Response (dB)
Single−stage design
First stage of a multistage design
Figure 5.15: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters.
is cleanup left to be done by subsequent interpolation ﬁlters operating
at higher rates (after all, we have only interpolated to 2500 Hz with the
halfband ﬁlter).
Figure 5.16 shows a full 3stage design (each stage being a halfband
interpolator) compared to a singlestage design. Both designs satisfy the
same transition width and stopband attenuation requirements. Overall
the multistage design requires 40 coefﬁcients and 72 MPIS
∗
. The code that
was used for these two designs follows:
f = fdesign.interpolator(8,'Nyquist',8,'TW,Ast',312.5,80,1e4);
h = design(f,'kaiserwin');
g = design(f,'multistage','Nstages',3);
As with multistage decimators, the use of IIR halfbands implemented
in efﬁcient allpassbased polyphase structures can improve the efﬁciency
of designs beyond what can be achieved with FIR ﬁlters. For example, for
the same speciﬁcations, this design:
∗
Since each stage produces more samples at its output than the number of samples at its
input, for multistage interpolators the number of multiplicationsperinputsample to the
overall implementation is larger then the number of coefﬁcients required for all stages.
Digital Filters with MATLAB Ricardo A. Losada
118 Multistage/Multirate Filter Design
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
−120
−100
−80
−60
−40
−20
0
20
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Single−stage design
Three−stage design
Figure 5.16: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters.
hm = design(f,'multistage','Nstages',3,...
'HalfbandDesignMethod','iirlinphase');
results in a 3stage ﬁlter with 16 coefﬁcients and 30 MPIS.
Figure 5.17 shows how subsequent stages remove spectral replicas that
remain from the ﬁrst stage. Notice how as the samplingrate increases, the
transitionwidth for each corresponding stage also increases so that the
ratio ∆f /f
s
remains large resulting in simple ﬁlters. For interpolation, the
ﬁrst stage is usually the most involved, but this is OK since the sampling
frequency is the lowest at that point. The complexity of each subsequent
stage is reduced gradually since each ﬁlter has to operate at higher and
higher sampling frequencies.
5.5 Summary and look ahead
We have shown how multistage implementation of ﬁlters can result in sig
niﬁcant computational savings. The savings are increased when multi
stage implementation are combined with multirate ﬁlters. There is an op
timal number of stages which provide maximum computational savings.
Digital Filters with MATLAB Ricardo A. Losada
5.5 Summary and look ahead 119
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
−100
−80
−60
−40
−20
0
Frequency (kHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
First stage
Second stage
Third stage
Figure 5.17: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters.
This optimal number can be determined automatically by the design tools
discussed.
Multistage Nyquist ﬁlters provide very efﬁcient implementations. This
is particularly true for halfband ﬁlters, especially IIR halfbands. These
multistage ﬁlters are equally adequate for efﬁcient decimation or interpo
lation purposes.
In the next chapter we will discuss special multirate ﬁlters that are well
suited for multistage implementations. These include hold and linear in
terpolator ﬁlters as well as CIC interpolation/decimation ﬁlters. We will
also discuss the use of Farrowﬁlters for fractional decimation/interpolation.
These ﬁlters can be used to provide fractional samplingrate changes by
an arbitrary factor (not necessarily a ratio of two integers). Moreover, they
can do so while using a small number of multipliers.
Digital Filters with MATLAB Ricardo A. Losada
Chapter 6
Special Multirate Filters
Overview
In this chapter we look at some special ﬁlters that come in handy for mul
tirate applications.
We ﬁrst look at hold interpolators which performbasic interpolation by
simply repeating input samples L times (L being the interpolation factor).
Next, we look at linear interpolators and showhowthey can be thought
of as two hold interpolators “put together”.
Both linear and hold interpolators are attractive because of their sim
plicity. We see that they are very crude approximations to an ideal lowpass
ﬁlter used for interpolation. Usually, because of their simplicity, they are
used at the last stage of a multistage implementation, operating at high
sampling rates.
We then move on to CIC interpolators and show how these are just
generalizations of hold/linear interpolators. By using multiple (more than
two) sections, CIC interpolators can obtain better attenuation than hold or
linear interpolators. The nice thing about CICinterpolators is that they can
be implemented without using multiplication. This is an attractive feature
for certain hardware such as FPGAs and ASICs because multipliers take
up quite a bit of area and are difﬁcult to make to operate at very high clock
rates.
CIC ﬁlters can also be used for decimation. Unlike the interpolation
case, in decimation, CICﬁlters are usually used at the ﬁrst stage of a multi
stage design. This is because at that stage the samplingrate is the highest,
6.1 Hold interpolators 121
0 5 10 15 20 25
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time (n)
A
m
p
l
i
t
u
d
e
Original samples
Held−interpolated samples
Figure 6.1: Interpolated samples using a hold interpolator with a factor L = 4.
making the multiplierless feature of CIC ﬁlters very attractive.
We then showhowto design CICcompensators for either interpolation
or decimation. These ﬁlters are lowpass ﬁlters whose passband is shaped
to compensate for the droop in the passband of CIC ﬁlters. Of course,
since linear and hold interpolators are special cases of CIC interpolators,
CIC compensators can be used for those linear and hold cases as well.
Finally, Farrow ﬁlters are shown both for singlerate fractionaldelay
applications as well as for changing the samplingrate of signals (by inte
ger or fractional factors). The main allure of Farrow implementations are
the low number of ﬁxed multipliers that are required and the tunability of
the fractional delay while the ﬁlter is running without having to redesign.
6.1 Hold interpolators
The simplest interpolator that one can build is the one that performs a
(zeroorder) hold of each sample, inserting as many repeated samples as
desired. For example, Figure 6.1 shows the result of a hold interpolator,
interpolating by a factor of 4.
Digital Filters with MATLAB Ricardo A. Losada
122 Special Multirate Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.5
1
1.5
2
2.5
3
3.5
4
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
Hold interpolator
Ideal interpolator
Figure 6.2: Magnitude response of a hold interpolator with a factor L = 4. The ideal
interpolator is shown for comparison.
Hold interpolators are attractive because they require no arithmetic in
order to be implemented. The hold interpolator is an FIR interpolator
whose impulse response is simply a series of L 1’s.
Hm = mfilt.holdinterp(4);
Hm.Numerator
As we know, the ideal interpolator is a lowpass ﬁlter that removes L −1
adjacent spectral replicas of the signal being interpolated. The hold inter
polator is a very crude approximation to the ideal interpolator as can be
seen with fvtool(Hm). Figure 6.2 shows the magnitude response of the
hold interpolator compared to the ideal interpolator for the case L = 4.
The hold interpolator has a very wide transition band, allows signiﬁcant
highfrequency content to pass through, and distorts the original data in
the band of interest. Note that the fact that high frequency remains after
hold interpolation is obvious from the timedomain plot shown in Figure
6.1. The fast transitions between the last interpolated sample for a given
original sample and the ﬁrst interpolated sample for the next original sam
ple are indicative of high frequency content.
Digital Filters with MATLAB Ricardo A. Losada
6.1 Hold interpolators 123
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
1
2
3
4
5
6
7
8
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
Hold interpolator
Multistage interpolator
Ideal interpolator
Figure 6.3: Hold interpolator compared with multistage interpolator for L = 8. For
reference, the ideal interpolator is shown.
For these reasons, hold interpolators are usually not used in isolation,
but rather are used as part of a cascade of interpolators (typically at the last
stage, which operates at the fastest rate and therefore beneﬁts the most of
the fact that no multiplications are required). When used in such cascade
conﬁgurations, most of the high frequency content has been removed by
previous stages. Moreover, the distortion of the signal in the band of in
terest is much less severe since the band of interest will occupy a much
smaller portion of the passband of the hold interpolator.
Example 50 Let us compare the effect of using a hold interpolator for a full in
terpolation by a factor L = 8 vs. using a hold interpolator for a factor L
3
= 2 in
conjunction with two halfband ﬁlters, each one interpolating by two.
Figure 6.3 shows a comparison of a possible multistage design including two
halfband ﬁlters followed by a hold interpolator vs. a singlestage interpolateby
8 hold interpolator design. For reference, the ideal interpolateby8 ﬁlters is also
shown. While the multistage interpolator does allow some highfrequency content
through, it is nowhere as bad as the hold interpolator acting alone. Also, assuming
the band of interest extends to 0.1π, the multistage interpolation introduces a
maximum distortion of about 0.15 dB while the hold interpolator introduces a
distortion of almost 2 dB.
Digital Filters with MATLAB Ricardo A. Losada
124 Special Multirate Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
10
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
First stage (halfband)
Second stage (halfband)
Third stage (hold interpolator)
Figure 6.4: Magnitude response of each of the three stages of the multistage design.
0 20 40 60 80 100 120
0
0.2
0.4
0.6
0.8
1
1.2
Time (n)
A
m
p
l
i
t
u
d
e
Held−interpolated samples
Multistage−interpolated samples
Figure 6.5: Comparison of interpolated data using a hold interpolator and a multistage
interpolator with L = 8.
Digital Filters with MATLAB Ricardo A. Losada
6.2 Linear interpolators 125
One thing to keep in mind that since interpolation is usually used right be
fore D/A conversion, the remnant high frequency content can be removed by an
analog (antiimage) postﬁlter. This will ensure a smooth analog waveform. As is
apparent from Figure 6.3, because of the multistage interpolation, the remaining
high frequency content will be far away from the band of interest (the passband of
the ﬁlter), making it easy for a loworder analog lowpass postﬁlter (with a wide
transition band) to remove said high frequencies.
Figure 6.4 shows the magnitude response of each of the three stages of the
multistage design. Note that because of the prior interpolation by 4 (provided by
the ﬁrst two stages) the band of interest is only a small fraction of the passband of
the hold interpolator. For this reason, the passband distortion is minimal.
Figure 6.5 shows the result of ﬁltering the same data with the hold interpola
tor compared to using the multistage interpolator. While it is obvious that some
high frequency content remains in either case, it is also obvious that overall the
multistageinterpolated data is much smoother and therefore has much less high
frequency content.
Ahold interpolator can be thought of in polyphase terms. As usual, the
polyphase components are formed by taking every Lth value from the im
pulse response. In this case, since the impulse response is a sequence of 1’s
of length L, each polyphase branch consists trivially of a single coefﬁcient
equal to one. This of course is consistent with the notion that for every
input sample, each polyphase branch computes one of the interpolated
values. In this case, each interpolated value is compute by “multiplying”
the input sample by one.
6.2 Linear interpolators
After hold interpolators, the next simplest interpolation ﬁlter is the linear
interpolator. While the hold interpolator only uses one sample in order
to compute the interpolated values (and therefore has only one coefﬁcient
per polyphase branch), in the case of linear interpolators, two adjacent
samples are used in order to compute the interpolated values. This of
course means that each polyphase branch will have two coefﬁcients as we
will soon see.
Linear interpolation is very simple to understand. Consider the plot
in Figure 6.6 which depicts the case L = 5 (it is the same idea for other
Digital Filters with MATLAB Ricardo A. Losada
126 Special Multirate Filters
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
Time (n)
A
m
p
l
i
t
u
d
e
Original samples
Linear−interpolated samples
Figure 6.6: Computing linearlyinterpolated samples for L = 5.
values of L). For every two existing samples, the interpolated values are
computed by forming a weighted average of the existing samples. The
weights are determined by the proximity of the interpolated values to each
of the existing samples. In this case, the interpolated sample closest to an
existing sample is four times closer to that existing sample than it is to the
existing sample on its other side. Therefore, when we form the weighted
average in order to compute the interpolated sample, we weight one of the
existing samples four times more than the other. This results in coefﬁcients
equal to 0.2 and 0.8 (they always add to 1) for that polyphase branch. The
coefﬁcients for other polyphase branches are similarly computed based
on the ratio of the distance between the new interpolated sample and the
existing surrounding two samples.
This means that for the case L = 5, the 5 polyphase branches can triv
ially be computed as:
L = 5;
Hl = mfilt.linearinterp(L);
p = polyphase(Hl)
Notice that the last polyphase branch is trivial (its coefﬁcients are 1 and 0).
Digital Filters with MATLAB Ricardo A. Losada
6.2 Linear interpolators 127
This allows for the existing samples to be contained unchanged within the
interpolated samples. That is, linear interpolators (and hold interpolators)
are special cases of Nyquist ﬁlters.
As usual, the overall interpolation ﬁlter is a lowpass ﬁlter whose coef
ﬁcients can be formed from the polyphase branches.
Hl.Numerator
ans =
Columns 1 through 6
0.2000 0.4000 0.6000 0.8000 1.0000 0.8000
Columns 7 through 9
0.6000 0.4000 0.2000
A linear interpolator can be thought of as the convolution of two hold
interpolators. Indeed, for the case L = 5, the coefﬁcients of the FIR hold
interpolation ﬁlter are:
Hm = mfilt.holdinterp(5);
Hm.Numerator
ans =
1 1 1 1 1
And of course
1/5*conv(Hm.Numerator,Hm.Numerator)
ans =
Columns 1 through 6
0.2000 0.4000 0.6000 0.8000 1.0000 0.8000
Columns 7 through 9
0.6000 0.4000 0.2000
is exactly equal to Hl.Numerator.
As we know, convolution in time is equal to multiplication in frequency.
Therefore, the magnitude response of a linear interpolator is given by mul
tiplying (or adding when working with dB) the magnitude response of
two hold interpolators. This can be easily veriﬁed with fvtool(Hm,Hl).
The plot comparing the magnitude response of both interpolators is shown
(in dB) in Figure 6.7 (we have normalized the passband gain to 0 dB to ease
the comparison).
Digital Filters with MATLAB Ricardo A. Losada
128 Special Multirate Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−60
−50
−40
−30
−20
−10
0
Normalized Frequency: 0.5952148
Magnitude (dB) (normalized to 0 dB): −12.09688
Normalized Frequency: 0.59375
Magnitude (dB) (normalized to 0 dB): −24.17285
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
(
n
o
r
m
a
l
i
z
e
d
t
o
0
d
B
)
Magnitude Response (dB)
Hold interpolator
Linear interpolator
Figure 6.7: Comparison of linear and hold interpolators for L = 5.
Because the magnitude response of the linear interpolator is twice that
of the hold interpolator (in dB), the linear interpolator provides more stop
band attenuation and therefore better lowpass ﬁltering than a hold inter
polator. This should be obvious to see if you think of the situation in
the time domain. While linearlyinterpolated samples still exhibit some
abrupt transitions which indicate some high frequency components re
main, it is not nearly as abrupt as taking the same samples and interpo
lating with a hold interpolator.
On the other hand, the passband distortion of the linear interpolator is
also twice that of the hold interpolator. However, as with hold interpola
tors, linear interpolators are usually used as the last stage of a multistage
interpolation scheme. Therefore, the passband distortion due to linear in
terpolation can be minimal in such conﬁgurations. Although the concept
of closeness is a relative notion, one can intuitively think that if samples
have been interpolated already so that they are very close to each other,
the error added by using linear interpolation rather than a higherorder
ﬁlter is much smaller than if we try to directly linearly interpolate samples
that are far apart in one shot.
The behavior is very similar to the comparison shown above between
Digital Filters with MATLAB Ricardo A. Losada
6.2 Linear interpolators 129
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−80
−60
−40
−20
0
20
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 6.8: Magnitude response of a multistage interpolator consisting of a halfband
ﬁlter, followed by an interpolateby2 linear interpolator followed by an interpolateby2
hold interpolator.
using a singlestage interpolateby8 hold interpolator and using a mul
tistage interpolator with a simpliﬁed (hold or linear) ﬁnal stage. In fact,
one perfectly reasonable possibility is to have a linear interpolator in the
nexttolast stage of a multistage conﬁguration and a hold interpolator in
the last stage.
Figure 6.8 shows just that conﬁguration. In this case, we have obtained
it by replacing the halfband ﬁlter in the second stage of the multistage ﬁlter
used above, with a linear interpolatebytwo ﬁlter. Once again, if the inter
polation is being done just prior to D/A conversion, it is assumed that the
analog antiimage postﬁlter will remove the remaining highfrequency
content
∗
The idea of convolving hold interpolators in order to obtain better stop
band attenuation can be generalized to more than two such interpolators.
CICinterpolation ﬁlters [31] can be seen as just that. The number of section
∗
We should note that part of the highfrequency content is attenuated by the staircase
reconstructor that is typically used in D/Aconversion in order to make the signal analog.
A postﬁlter is used after the staircase reconstructor to smoothout the analog waveform
by removing remaining highfrequency content. For more on this, see [3].
Digital Filters with MATLAB Ricardo A. Losada
130 Special Multirate Filters
of the CIC interpolators will correspond to the number of hold interpola
tors convolved. As with linear interpolators, multisection CIC interpola
tors attain better stopband attenuation at the expense of larger passband
distortion. In the next section we will take a look at CIC interpolators.
After that, we will look at the design of CIC compensators which pre
equalize the passband
∗
in order to compensate for the passband distortion
introduced by the CIC ﬁlters. Of course, if deemed necessary, this com
pensators can also be used to compensate for the distortion introduced by
linear or hold interpolators.
6.3 CIC interpolators
Let’s perform some simple math to derive the CIC ﬁlters starting from a
hold interpolator. We have seen that a hold interpolator has an impulse
response of the form
h[n] = {1, 1, 1, . . . , 1}
where the number of 1’s is equal to the interpolation factor. The transfer
function of such a ﬁlter is given simply by
H(z) = 1 + z
−1
+ z
−2
+ . . . + z
−(L−1)
(6.1)
If we multiply both sides of (6.1) by z
−1
we get
z
−1
H(z) = z
−1
+ z
−2
+ . . . + z
−L
(6.2)
Subtracting (6.2) from (6.1) we get
H(z)(1 −z
−1
) = 1 −z
−L
which means we can rewrite H(z) as
H(z) =
1 −z
−L
1 −z
−1
If we think of this as two ﬁlters in cascade, H(z) = H
1
(z)H
2
(z), with
H
1
(z) = 1 −z
−L
(the “comb” due to its magnitude response) and H
2
(z) =
∗
Postequalize in the case of decimation.
Digital Filters with MATLAB Ricardo A. Losada
6.3 CIC interpolators 131
Figure 6.9: Conceptual implementation of a CIC interpolator. As with all interpolators,
conceptually it is just an upsampler followed by a lowpass ﬁlter (the combination of the
last two ﬁlters).
Figure 6.10: Actual implementation of a CIC interpolator obtained by use of Noble iden
tities.
1/(1 −z
−1
) (the integrator), we have derived a cascaded integratorcomb
(CIC) ﬁlter.
When used for interpolation
∗
, the CIC interpolator in conceptual form
operates as the block diagram shown in Figure 6.9. Using the Noble iden
tities, we can interchange the upsampler and the comb ﬁlter to obtain the
conﬁguration shown in Figure 6.10.
Of course so far we haven’t really done much other than show a rather
complicated way of implementing a hold interpolator. In reality, if we
wanted to implement a hold interpolator, we would skip the comb and
integrator ﬁlters and simply repeat the input sample as many times as we
wish to interpolate.
The real use of CIC ﬁlters comes froma generalization of the fact we al
ready noted relating linear interpolators to hold interpolators. Recall that
we stated that a linear interpolator’s impulse response can be obtained by
convolving two impulse responses of hold interpolators. With CIC ﬁlters,
we convolve K such impulse responses. Since convolution in time equates
to multiplication in frequency, this means that the transfer function of a
CIC ﬁlter with K sections is given by elevating H(z) to the power of K,
H
CIC
(z) = (H(z))
K
=
1 −z
−L
1 −z
−1
K
If we once again use the Noble identities, we can easily verify that an
∗
Keeping in mind that interpolation conceptually consists of upsampling followed by
lowpass ﬁltering.
Digital Filters with MATLAB Ricardo A. Losada
132 Special Multirate Filters
Figure 6.11: Implementation of a multisection CIC interpolator.
Figure 6.12: Multiplierless linear interpolator.
implementation of an Ksection CIC interpolator can be done as shown in
Figure 6.11.
Note that the following commands can be used to quickly build a Simulink
model of a CIC interpolator:
L = 4; % Interpolation factor
K = 3; % Number of sections
Hm = mfilt.cicinterp(L,1,K);
realizemdl(Hm)
Of course, a multisection CIC interpolator multiplies the magnitude
response of the hold interpolator K times. Because CIC ﬁlters are mul
tiplierless, the allure of these ﬁlters is that we can obtain good stopband
attenuation by using only adders and delays if we use several sections.
For this reason, CIC ﬁlters are often implemented at the last stage of a
multistage interpolation ﬁlter, operating at the fastest rate.
The cases K =1 and K =2 are special cases of CIC interpolators that re
sult in hold and linear interpolators. In fact, the innermost combination of
comb/upsampler/integrator, can be readily replaced with a hold interpo
lator (saving a couple of adders and delays [32]. This technique allows us,
for instance, to implement a multiplierless linear interpolator using only 2
adders and 2 delays as shown in Figure 6.12.
6.3.1 Design of CIC interpolators
When designing CIC interpolators, we should think in the context of mul
tistage designs. The design basically consists of determining how many
Digital Filters with MATLAB Ricardo A. Losada
6.3 CIC interpolators 133
sections are needed in order to obtain a certain stopband attenuation. Un
like conventional lowpass ﬁlters, this stopband attenuation is not attained
for the entire stopband. Instead, the attenuation will be attained only
where needed to suppress remnant highfrequency content left behind by
previous stages of interpolation.
Example 51 As if often the case, an example is the best way to understand this.
Suppose we want to interpolate by a large factor, say 64, in order to make our life
easy when designing an analog postﬁlter for D/A conversion. The following is a
possible set of speciﬁcations for our interpolator:
f = fdesign.interpolator(64,'Nyquist',64,'TW,Ast',0.0078125,80);
These speciﬁcations state the the cutoff frequency for the interpolator is π/64 and
that the passbandedge frequency is π/64 − TW/2 = 0.0117π. The minimum
stopband attenuation for the entire stopband region is 80 dB.
First, let’s design this ﬁlter using conventional Nyquist ﬁlters and let us con
strain the design to be done in 3 stages:
Hc = design(f,'multistage','Nstages',3);
cost(Hc)
The result of this design is a interpolateby4 Nyquist ﬁlter, followed by a interpolate
by2 Nyquist (halfband) ﬁlter, followed by an interpolateby8 Nyquist ﬁlter. Over
all, the interpolation factor is 64 as desired. The cost of implementing this ﬁlter is
110 coefﬁcients and 408 MPIS.
Now, let’s try to replace the last stage with an interpolateby8 CIC ﬁlter. The
desired stopband attenuation is 80 dB. However, in order to set the passband
edge frequency, we should use the overall desired passbandedge frequency, i.e.
0.0117π:
f2 = fdesign.interpolator(8,'CIC',1,'Fp,Ast',0.0117,80);
Hcic = design(f2); % Results in 4 sections
The following commands can be used to replace the 3rd stage with a CIC and
compare the two multistage designs:
Hc2 = copy(Hc);
Hc2.stage(3) = Hcic;
fvtool(Hc,Hc2)
Digital Filters with MATLAB Ricardo A. Losada
134 Special Multirate Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−200
−180
−160
−140
−120
−100
−80
−60
−40
−20
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
(
n
o
r
m
a
l
i
z
e
d
t
o
0
d
B
)
Magnitude Response (dB)
Conventional 3−stage interpolator
3−stage interpolator that includes a CIC filter
Figure 6.13: Comparison of a conventional 3stage interpolation ﬁlter and one which
uses a CIC interpolator in its last stage.
The magnitude response of the two implementations is shown in Figure 6.13
(we have normalized the passband gain to 0 dB in order to ease the comparison).
Clearly, either ﬁlter meets the specs. However, the multistage ﬁlter that uses the
CIC in its last stage can be implemented with only 70 coefﬁcients and 88 MPIS.
Figure 6.14 shows the magnitude of each of the 3 stages comprising the ﬁlter
Hc2. The last stage is the CIC ﬁlter. Note that the CIC ﬁlter does not provide
80 dB attenuation over the entire stopband. However, it does provide 80 dB or
more attenuation where needed, i.e. at the points 2kπ/L ±0.0117π where k =
1, . . . , L −1 and L = 8.
6.3.2 Gain of CIC interpolators
In the magnitude response plots we have shown so far, we have normal
ized the passband gain of the ﬁlters to 0 dB in order to simplify visualiza
tion of the designs.
However, CIC interpolation ﬁlters have a very large gain. This goes
beyond the usual gain of L that all interpolators have. To see why, recall
ﬁrst the linear interpolator case.
We stated that a linear interpolator can be though of as two hold in
Digital Filters with MATLAB Ricardo A. Losada
6.3 CIC interpolators 135
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
(
n
o
r
m
a
l
i
z
e
d
t
o
0
d
B
)
Magnitude Response (dB)
Stage 1
Stage 2
Stage 3 (CIC)
Figure 6.14: Magnitude response of each stage of a 3stage interpolation ﬁlter using a
CIC interpolator in its last stage.
terpolators convolved. However, in order to get the impulse response of
the linear interpolator correctly scaled, when we convolved the two hold
interpolators, we had to scale the result by a factor of L as well.
For example, take the case L = 3. A hold interpolator has impulse re
sponse given by h[n] = 1, 1, 1. A plot of the magnitude response (not in
dB) shows that the gain of the ﬁlter at frequency 0, is 3. This can easily be
veriﬁed with the following commands:
Hh = mfilt.holdinterp(3);
fvtool(Hh,'MagnitudeDisplay','Magnitude')
If we convolve two such impulse responses, we get an impulse re
sponse which is 3 times larger than that of the corresponding linear in
terpolator.
conv([1 1 1],[1 1 1])
Hl = mfilt.linearinterp(3);
Hl.Numerator
However, the linear interpolator itself has a passband gain of 3:
Digital Filters with MATLAB Ricardo A. Losada
136 Special Multirate Filters
Hl = mfilt.linearinterp(3);
fvtool(Hl,'MagnitudeDisplay','Magnitude')
Therefore the convolution of two hold interpolators has a gain of L
2
=
9.
Since CIC ﬁlters are obtained by (unscaled) convolutions of hold in
terpolators, their gain is given by L
K
. If we account for the fact that we
expect any interpolator to have a gain of L, the extra gain introduced by a
CIC interpolator is L
K−1
.
∗
For example, for L = 3 and K = 4, we can easily
see that the passband gain is 81:
Hcic = mfilt.cicinterp(3,1,4);
fvtool(Hcic,'MagnitudeDisplay','Magnitude')
The extra gain, that is L
K−1
, can be computed simply by using the gain
command,
gain(Hcic)
ans =
27
6.3.3 Further details of CIC ﬁlters
Although CIC ﬁlters seem pretty nifty, it is worth noting that CIC ﬁlters
are unstable. The factor 1 − z
−1
in the denominator means that the ﬁlter
has a pole on the unit circle (at z = 1). In fact, the only way for CIC ﬁlters
to work (meaning that their output will not grow without bound) is by
using ﬁxedpoint arithmetic (with overﬂows wrapping).
Also, note that CIC ﬁlters have been constructed by adding a pole and
a zero at z = 1. This pole/zero pair should cancel, yielding the traditional
FIR transfer function. However, for implementation, we do not cancel the
pole and instead implement the ﬁlter with recursion. The ﬁlter is still FIR
even though it has feedback
†
∗
In our treatment of CIC interpolators so far, we have ignored the differential delay (we
have assumed it is one). The differential delay is the order of the delays in the differ
ence (comb) part of the ﬁlter. Typical values for the differential delay are 1 and 2. We
will assume it is always 1 here. A value different to one will also affect the passband
gain.
†
The strict deﬁnition of FIR is a ﬁlter whose minimal realization has a nilpotent
statetransition matrix in its statespace representation (see [26] Ch. 13). The CIC imple
mentation is not minimal since it allows for a pole/zero cancellation.
Digital Filters with MATLAB Ricardo A. Losada
6.4 CIC decimators 137
6.4 CIC decimators
Consider a signal with twosided bandwidth equal to f
s
and sampled at a
sampling rate f
s
. If we need to decimate by a factor M in order to reduce
the rate to a sampling frequency f
d
= f
s
/M, we need to ﬁrst reduce the
twosided bandwidth of the signal to f
d
as well.
CIC ﬁlters are attractive for decimation purposes due to their low com
putational cost given that they do not require multipliers. However, com
pared to an ideal brickwall lowpass ﬁlter, the response of CIC ﬁlter pro
vides a poor lowpass characteristic. Nevertheless, this can be compen
sated for by the use of subsequent ﬁlters that operate at reduced sampling
rates and therefore do not incur a high computational cost.
Let us illustrate typical CIC behavior for a decimation problem by a
factor M = 4. Let us examine Figure 6.15. For this example, we have
assumed f
s
= 100 MHz.
The rectangular areas shown with a dashed line illustrate how the var
ious shifted replicas would overlay had they been ﬁltered with a perfect
brickwall ﬁlter. Notice that in this case the various images would be just
adjacent to each other but there would be no overlap, i.e. no aliasing.
In contrast, the decimated version of the CIC ﬁltered signal shows sig
niﬁcant overlap between spectral replicas. Note that the aliasing is maxi
mum at the edges of the lowrate Nyquist interval, [−f
d
/2, f
d
/2]. On the
other hand, the aliasing is minimal at the center of the Nyquist interval (at
DC).
For this reason, coupled with the fact that the droop in the CIC ﬁl
ter is not as accentuated in the vicinity of DC, decimating CIC ﬁlters are
usually used when the ultimate band of interest is not the entire interval
[−f
d
/2, f
d
/2] but rather a (perhaps small) subset of it, say [−f
p
, f
p
] where
f
p
≪ f
d
/2.
It is assumed of course that the energy of the signal outside of the ﬁnal
band of interest, that is, in the band [−f
d
/2, −f
p
] ∪ [ f
p
, f
d
/2] will be re
moved with either a singlerate lowpass ﬁlter, or, more likely, with a sub
sequent lowpass decimation ﬁlter that will reduce the sampling rate to the
vicinity of 2f
p
(this can be done of course with more than one subsequent
decimation ﬁlter resulting in an overall implementation with perhaps 3 or
4 stages). This subsequent ﬁlter will typically compensate for the notable
droop in the passband of the CIC ﬁlter as well.
It is clear from Figure 6.15, that the maximum amount of aliasing in
Digital Filters with MATLAB Ricardo A. Losada
138 Special Multirate Filters
0 10 20 30 40 50 60 70 80 90 100
−150
−100
−50
0
50
Filtered magnitude spectrum after decimation
Frequency (MHz)
d
B
Baseband filtered spectrum
First shifted spectrum
Second shifted spectrum
Third shifted spectrum
Final band of interest [0,Fp]
Figure 6.15: Final band of interest of signal decimated with a CIC ﬁlter.
the ﬁnal band of interest will occur at f
p
. The actual maximum amount of
aliasing at f
p
is due to the adjacent replica. For a CIC ﬁlter, the larger the
number of sections K, the smaller the gain for the replica at such frequency,
i.e. in order to limit the amount of aliasing, we would like to have a large
number of sections. However, the more sections we have, the larger the
droop of the ﬁlter in the band of interest that we need to compensate for.
In order to design a CICﬁlter, we reverse the previous statement. Namely,
given an amount of aliasing that can be tolerated, determine the minimum
number of sections K that are required. The full design parameters are
listed next.
6.4.1 Design parameters
At this point we can enumerate the design parameters for the ﬁlter. The
design parameters are:
• the edge frequency f
p
Digital Filters with MATLAB Ricardo A. Losada
6.5 CIC compensators 139
• the amount of aliasing tolerated at f
p
: A
st
• the decimation factor M
• optionally, the sampling frequency prior to decimation f
s
As with the design of CIC interpolators, the use of stopband attenu
ation is slightly different than with conventional lowpass ﬁlters. In this
case, it is not that the ﬁlter must provide a minimum attenuation of A
st
throughout the entire stopband. Instead, A
st
is the minimum amount of
attenuation permitted for frequencies that will alias back into the band of
interest. Of course, at the end of the day, this last interpretation is the same
for any decimation ﬁlter.
Example 52 Given these parameters, a CIC decimation ﬁlter with the necessary
number of sections K such that the amount of aliasing tolerated at f = f
p
is not
exceeded can be designed as follows:
M = 8; % Decimation factor
D = 1; % Differential delay
Fp = 2e6; % 2 MHz
Ast = 80; % 80 dB
Fs = 100e6; % 100 MHz
Hf = fdesign.decimator(M,'CIC',D,'Fp,Ast',Fp,Ast,Fs);
Hcic = design(Hf);
The resulting design that meets the required attenuation consists of 6 sections.
6.5 CIC compensators
CIC compensators are singlerate or multirate ﬁlters that are used to com
pensate for the passband droop in CIC ﬁlters. In the case of CIC interpola
tion, what is usually done is to preequalize for the droop in a prior stage
of a multistage design. In the case of decimation, we postequalize in a
subsequent stage to the CIC decimator.
As we have already stated, the amount of droop will depend on the
number of sections K in the CIC ﬁlter. For the special case of linear and
hold interpolators, the number of sections is 2 and 1 respectively.
Digital Filters with MATLAB Ricardo A. Losada
140 Special Multirate Filters
0 5 10 15 20 25 30 35 40 45
−80
−60
−40
−20
0
20
40
60
80
100
120
Frequency (MHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 6.16: Overall twostage design consisting of CIC decimator and compensator.
In the case of decimation, the larger the ratio of the ﬁnal passband of
interest f
p
to the original sampling rate f
s
, the smaller the amount of droop
since only a very small portion of the passband of the CICﬁlter is involved.
In some cases, we can do without the compensation altogether, since the
small droop may not warrant equalization.
Similarly, in the case of interpolation, the larger the overall interpola
tion factor, the smaller the droop will be in the baseband spectrum. Again,
it may be so that we choose not to equalize if the overall multistage inter
polation factor is large enough.
Example 53 As an example consider a possible compensator design for the CIC
decimator design of the previous section. Suppose we want to further decimate by
a factor of 4 for an overall decimation factor of 32 for the two stages.
K = Hcic.NumberOfSections; % Determine from previous design
M2 = 4; % Decimation factor for this stage
Fst = 4.25e6; % 4.25 MHz, TW = 2.25 MHz
Ap = 1; % 1 dB peaktopeak passband ripple
Hf2 = fdesign.decimator(M2,'ciccomp',D,K,'Fp,Fst,Ap,Ast',Fp,Fst,Ap,Ast,Fs/M);
Hd = design(Hf2);
Digital Filters with MATLAB Ricardo A. Losada
6.6 Farrow Filters 141
0 5 10 15 20 25 30 35 40 45
−160
−140
−120
−100
−80
−60
−40
−20
0
Frequency (MHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
(
n
o
r
m
a
l
i
z
e
d
t
o
0
d
B
)
Magnitude Response (dB)
CIC Decimator
CIC compensator
Figure 6.17: Magnitude response of each of the two stages in the design.
We can obtain the resulting overall decimator of cascading the two ﬁlters from:
Hcas = cascade(Hcic,Hd);
fvtool(Hcas) % Show overall response
Figure 6.16 shows the resulting ﬁlter after cascading the CIC decimator and
its compensator. Figure 6.17 shows how the CIC decimator attenuates the spectral
replicas from the compensator. Figure 6.18 shows the passband of the overall two
stage decimator. Notice how the droop in the passband has been equalized. As
with CIC interpolators, CIC decimators have a large passband gain (for the same
reason). The gain can be found from gain(Hcic) and is once again given by M
K
.
In Appendix C, we will compare a multistage decimator design includ
ing a CICdecimator and a CICcompensator with various other single and
multistage designs.
6.6 Farrow Filters
We will now derive a ﬁlter that can be very effectively used for both frac
tional advances/delays and changing the sampling rate of signals by arbi
trary factors (not necessarily rational).
Digital Filters with MATLAB Ricardo A. Losada
142 Special Multirate Filters
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
107.5
108
108.5
109
109.5
110
Frequency (MHz)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Figure 6.18: Equalized passband of twostage design showing the effect of the CIC com
pensator on the droop.
Farrow ﬁlters are basically obtained by (piecewise) polynomial inter
polation (curve ﬁtting) on the input samples to the ﬁlter. Once a poly
nomial has been ﬁtted, it can be evaluated at any point. This allows for
interpolation at arbitrary locations between samples. Moreover, the im
plementation of Farrow ﬁlters is essentially done using Horner’s method
of polynomial evaluation. The advantage of doing this is that it allows
for tuning of the location at which we wish to interpolate by changing
only one parameter in the ﬁlter. All ﬁlter coefﬁcients remain constant.
Therefore, Farrow ﬁlters are suitable for instance to implement variable
fractional advance/delay ﬁlters.
Theoretically, polynomials of any order can be used to ﬁt to the existing
samples. However, since large order polynomials tend to oscillate a lot,
typically polynomials of order 1, 2, or 3 are used in practice.
The easiest way to understand the derivation of Farrow ﬁlters is to
start with linear interpolators. For the moment, consider the case where
we want to interpolate solely for the purpose of introducing a fractional
advance/delay (i.e. without changing the sampling rate of the signal).
A linearly interpolated fractional advance/delay can be implemented
with two multipliers as we have already seen (this is just what each polyphase
Digital Filters with MATLAB Ricardo A. Losada
6.6 Farrow Filters 143
Figure 6.19: Twotap ﬁlter that can be used for fractional delay by linear interpolation.
Figure 6.20: Computing a fractionally advanced/delayed interpolated sample from its
two surrounding samples via linear interpolation.
branch of a linear interpolator does). Consider the twotap ﬁlter shown in
Figure 6.19. In order to compute the interpolated values between a previ
ous sample, x[n − 1], and a current sample, x[n], we weigh each sample
relative to the distance between it and the desired interpolated value. Fig
ure 6.20 shows the resulting interpolated sample.
The ﬁlter as shown, performs a fractional delay of 1 −α (as mentioned
before, this is equivalent to a fractional advance of α if we allow for a full
sample delay for the sake of causality). The output is computed as
y[n] = (1 −α)x[n −1] + αx[n]
Now, by simply rewriting the previous expression as
y[n] = x[n −1] + α(x[n] − x[n −1])
Digital Filters with MATLAB Ricardo A. Losada
144 Special Multirate Filters
Figure 6.21: Fractional advance ﬁlter.
Figure 6.22: Fractional delay ﬁlter.
we see we can implement the ﬁlter as shown in Figure 6.21.
The advantage of this implementation is that there are no ﬁxed mul
tipliers. The desired fractional advance, α, can be thought of as a second
input to the ﬁlter. It can be tuned at any time, enabling a variable fractional
advance/delay.
It is of course trivial to rewire the ﬁlter so that the input is the fractional
delay β = 1 −α rather than the fractional advance α:
y[n] = β(x[n −1] − x[n]) + x[n]
This is shown in Figure 6.22.
6.6.1 Higherorder polynomials
As usual, better interpolation can be obtained at the expense of more com
putation. Quadratic and cubic polynomial interpolation are very common
cases. Consider the cubic case. For this case, we use two samples to the
Digital Filters with MATLAB Ricardo A. Losada
6.6 Farrow Filters 145
Figure 6.23: Fractional delay using cubic polynomials.
left and two samples to the right of where we wish to interpolate.
∗
The
situation is depicted in Figure 6.23. Once we have four samples (such as
the ﬁrst four input samples), we can interpolate, but we compute values
that lie between the two innermost samples only (between the second
and third from the left). To interpolate, we ﬁt a 3rdorder polynomial to
the four samples (the polynomial is unique) and we evaluate the polyno
mial at the point we wish to interpolate. Then we advance one sample, the
leftmost sample is discarded and the rightmost sample comes into play.
Once again, we ﬁt the unique (new) 3rdorder polynomial to these four
samples. Once we have the polynomial, we interpolate by computing the
value of the polynomial between the two innermost samples. After this,
we would advance another sample and so on.
As in the linear case, for higherorder polynomials, the Farrow struc
ture makes use of Horner’s rule so that all coefﬁcients in the ﬁlter are con
stant while the fractional delay is an input that is tunable at runtime.
∗
As always, we must allowfor sufﬁcient delay in practice in order to make things causal.
Digital Filters with MATLAB Ricardo A. Losada
146 Special Multirate Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−20
−15
−10
−5
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Linear−Lagrange Farrow Filter
Cubic−Lagrange Farrow Filter
Figure 6.24: Magnitude response of linear and cubic fractional delays designed via the
Lagrange interpolation formula.
6.6.2 Design of Farrow fractional delays
The design of variable fractional delays using the Farrow structure and
Lagrange interpolation boils down to selecting the ﬁlter order (the poly
nomial order). As we have already stated, the linear, quadratic, and cubic
cases are the most typical.
It is worth noting though, that for this structure, as the ﬁlter order N
increases, the number of coefﬁcients increases as N
2
. The fractional delay
is speciﬁed in the design as a starting point. However, as we have already
said, the value can be changed at any time while the ﬁlter is running.
Example 54 Let us compare linear and cubic fractional delays using the La
grange interpolation formula:
del = 0.5; % Desired fractional delay
Hf_lin = fdesign.fracdelay(del,1);
Hf_cub = fdesign.fracdelay(del,3);
Hlin = design(Hf_lin,'Lagrange');
Hcub = design(Hf_cub,'Lagrange');
As we know, ideal fractional delays should have an allpass magnitude re
sponse, and a ﬂat groupdelay. Figure 6.24 compares the magnitude responses.
Digital Filters with MATLAB Ricardo A. Losada
6.6 Farrow Filters 147
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0.5
0.6
0.7
0.8
0.9
1
1.1
1.2
1.3
1.4
1.5
Normalized Frequency (×π rad/sample)
G
r
o
u
p
d
e
l
a
y
(
i
n
s
a
m
p
l
e
s
)
Group Delay
Linear−Lagrange Farrow Filter
Cubic−Lagrange Farrow Filter
Figure 6.25: Group delay of linear and cubic fractional delays designed via the Lagrange
interpolation formula.
As can be seen, neither is a particularly good approximation to an allpass ﬁlter,
however, the cubic design fairs a little better. The groupdelays are plotted in Fig
ure 6.25. Both of them are ideal relative groupdelays of 0.5. In the cubic case,
there is an extra one sample delay introduced by the higher order.
Simulink models for the Farrowﬁlters resulting fromthese designs can
be obtained as usual by using the realizemdl() command (e.g. realizemdl(Hlin)
or realizemdl(Hcub) in the Example above).
6.6.3 Multirate Farrow ﬁlters
So far we have seen how to implement singlerate fractional delays with
Farrow ﬁlters. Farrow ﬁlters can be used for both increasing and decreas
ing the samplingrate of a signal (by either integer or fractional factors).
One of the key advantages of Farrow ﬁlters is that they can be used to
change the samplingrate of a signal by an irrational factor without adding
complexity in terms of number of coefﬁcients. In contrast, the previous
polyphase designs we had looked at could only change the rate by a fac
tor given by the ratio of two integers. The best that could be done for
irrational factors, was to form an approximation to a rational number of
the form L/M. In order to approximate an irrational factor adequately, it
Digital Filters with MATLAB Ricardo A. Losada
148 Special Multirate Filters
Figure 6.26: Multirate Farrow ﬁlter.
may be necessary for L and M to be very large integers. As a consequence
of this, the number of coefﬁcients required may be quite large.
Nevertheless, it is worth keeping in mind that while the number of co
efﬁcients may be kept low by using Farrow structures, the actual number
of MPIS will depend on the samplingrate conversion factor. To see this,
let’s describe how a multirate Farrow ﬁlter works.
Consider the modiﬁed diagram for the linear case of a Farrow frac
tional delay shown in Figure 6.26. The dashed line separates the ﬁlter into
a section running at the input signal’s samplingrate and a section run
ning at the output samplingrate. Note that we have relabeled the output
to be y[m] rather than y[n]. This is due to different input and output rates.
Notably, the fractional delay, now denoted β
m
will now change at every
instant an output sample occurs.
Let’s walk through a simple case to get a feel for how this operates.
Let’s say that we are increasing the samplingrate by a factor of 2. Since
for every input there are two outputs, the value held in the delay register
will be used twice. The ﬁrst time an input is used, β
m
will take on the
value 0.5 and the output will be computed as
y[m] = 0.5(x[n −1] − x[n]) + x[n] = 0.5x[n −1] +0.5x[n]
Before the input sample changes, one more output sample will be com
puted. β
m
will take the value 0 and the output will simply be
y[m +1] = x[n];
Digital Filters with MATLAB Ricardo A. Losada
6.6 Farrow Filters 149
Subsequently, the input sample will change, β
m
will be once again set
to 0.5 and so forth.
In summary, when increasing the samplingrate by a factor of two, β
m
will cycle between the values {0.5, 0} twice as fast as the input, producing
an output each time it changes.
In the general case, it is simply a matter of determining which values β
must take. The formula is simply
β
m
=
mf
s
f
′
s
mod 1
where f
s
is the input sampling rate and f
′
s
is the output sampling rate.
Example 55 Let’s say we want f
′
s
=
3f
s
5
. Then β
m
will cycle through the values
{0, 2/3, 1/3}. The following code designs such a multirate ﬁlter (for the ﬁrst
order case) and ﬁlters some random data:
% Design firstorder multirate Farrow filter
f = fdesign.polysrc(3,5);
f.PolynomialOrder = 1;
H = design(f,'lagrange');
% Filter some random data
x = randn(100,1);
y = filter(H,x);
Figure 6.27 shows partial plots of the input and output signals assuming f
s
=
1. Notice that the delay follows the values of β
m
that we have indicated.
Figure 6.28 shows partial plots for the cubic case rather than the linear case.
The improved smoothness of using a cubic polynomial is apparent from the ﬁgure.
6.6.4 Polynomial interpolation and maximally ﬂat ﬁltering
In this section we show that using polynomials as we have for piecewise
curve ﬁtting by interpolating N + 1 samples using an Nthorder polyno
mial is equivalent to “traditional” interpolation fromthe signal processing
point of view if we use a maximalyﬂat FIR ﬁlter as our lowpass ﬁlter.
To see this, consider interpolation by L = 4. Let’s ﬁrst design a cubic
polynomial Farrow ﬁlter to perform such interpolation.
Digital Filters with MATLAB Ricardo A. Losada
150 Special Multirate Filters
10 12 14 16 18 20 22 24
−1.5
−1
−0.5
0
0.5
1
1.5
2
Time (sec)
A
m
p
l
i
t
u
d
e
Input signal
Output signal
Linear interpolant
Figure 6.27: Multirate Farrow ﬁltering using a linear polynomial.
8 10 12 14 16 18 20 22
−1.5
−1
−0.5
0
0.5
1
1.5
2
Time (sec)
A
m
p
l
i
t
u
d
e
Input signal
Output signal
Cubic interpolant
Figure 6.28: Multirate Farrow ﬁltering using a cubic polynomial.
Digital Filters with MATLAB Ricardo A. Losada
6.6 Farrow Filters 151
% Design firstorder multirate Farrow filter
L = 4;
M = 1;
N = 3; % Polynomial order
f = fdesign.polysrc(L,M);
f.PolynomialOrder = N;
H = design(f,'lagrange');
To interpolate by 4, the fractional delay will take on values of {3/4, 1/2, 1/4, 0}
in a cyclic manner. If we set the fractional delay of the ﬁlter to each of those
four values and in each case compute the equivalent transfer function:
Hf = fdesign.fracdelay(0.75)
H = design(Hf,'lagrange');
[b0,a0] = tf(H)
H.FracDelay=0.5;
[b1,a1] = tf(H)
H.FracDelay=0.25;
[b2,a2] = tf(H)
H.FracDelay=0;
[b3,a3] = tf(H)
It is trivial to verify that b0,b1,b2,b3 correspond to the polyphase com
ponents of the FIR ﬁlter returned by the intfilt() command:
bint = intfilt(L,N,'lagrange');
The magnitude response of the ﬁlter bint is shown in Figure 6.29. We
also show the ideal interpolation ﬁlter for reference. As previously noted,
the maximally ﬂat characteristic has the undesirable effect of a wide transi
tion band as a result. This tells us that polynomial interpolation produces
only acceptable ﬁlters for samplingrate conversion applications (and frac
tional delays). We had already seen in this in a different form in Figure
6.24, where we noted how far from an ideal allpass the fractional delays
produced by polynomial interpolation were.
In numerical analysis, better piecewise curveﬁtting is obtained by us
ing techniques such as hermite polynomial interpolation and cubic splines.
In signal processing, typically we improve the interpolation by using ﬁl
ters with better transitionwidth than maximallyﬂat ﬁlters.
Digital Filters with MATLAB Ricardo A. Losada
152 Special Multirate Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0
0.5
1
1.5
2
2.5
3
3.5
4
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude Response
Maximally flat filter
Ideal interpolation filter
Figure 6.29: Magnitude response of a maximallyﬂat interpolateby4 ﬁlter correspond
ing to cubic polynomial interpolation.
6.6.5 Using Farrowsamplerate converters in multistage de
signs
We have seen how multistage/multirate designs can result in signiﬁcantly
reduced implementation cost when compared to singlestage cases. How
ever, multistage techniques are applicable only when the rate change fac
tor is not a prime number. However, if we need to change the rate by a
prime number, we need not be “stuck” with a singlestage design. One
possibility, is to change the rate by a nonprime number near the prime
number we are looking for, and use a Farrow ﬁlter to change the ﬁnal rate
so as to obtain the desired overall ratechange.
Example 56 Suppose we have a signal sampled at 680 kHz, but the band of inter
est extends to 17 kHz only. We may have oversampled as signal as part of analog
to digital conversion for the purpose of simplifying the antialiasing analog ﬁlter.
We wish to reduce the bandwidth and the rate by decimating. The ideal decima
tion factor would be M = 17. However, since 17 is a prime number, we can only
design a singlestage decimator such as:
Fs = 680e3; % 680 kHz
Fp = 17e3; % 17 kHz
Digital Filters with MATLAB Ricardo A. Losada
6.6 Farrow Filters 153
TW = 6e3; % 6 kHz
Ast = 80; % 80 dB
M = 17; % Decimation factor
Hf = fdesign.decimator(M,'Nyquist',M,'TW,Ast',TW,Ast,Fs);
Hd = design(Hf,'kaiserwin');
cost(Hd)
The cost of this design is of about 543 coefﬁcients and 32 MPIS.
An alternative strategy may be to design a multistage ﬁlter that decimates by
16. In fact, due to the wide transition band of the Farrow ﬁlter that follows, we
may choose to have a smaller transition band here, say half the transition width:
Hf = fdesign.decimator(16,'Nyquist',16,'TW,Ast',TW/2,Ast,Fs);
Hmult = design(Hf,'multistage')
cost(Hmult)
The result is a multistage design with 4 halfbands in cascade. The cost is of
about 92 coefﬁcients and 10 MPIS.
In order to reach the overall decimateby17 factor, we can design a cubic
polynomial Farrow ﬁlter to perform a ratechange by a factor of 16/17:
f = fdesign.polysrc(16,17);
H = design(f,'lagrange');
We can cascade this ﬁlter after the multistage decimator to achieve the goal we
want:
Hcas = cascade(Hmult,H);
Digital Filters with MATLAB Ricardo A. Losada
Part II
Filter Implementation
Chapter 7
Implementing FIR Filters
7.1 Some basics on implementing FIR ﬁlters
There are several factors that inﬂuence the selection of the ﬁlter structure
used to implement an FIR ﬁlter. If the ﬁlter length is very large, it may be
preferable to use a frequencydomain implementation based on the FFT.
If it is to be implemented in the time domain, the target hardware is an
important factor.
From a design perspective, there is an important distinction between
minimumphase and linear phase ﬁlters. Minimumphase FIR ﬁlters do
not have any symmetry in their coefﬁcients while linear phase FIR ﬁlters
have either symmetric or antisymmetric coefﬁcients. Depending on the
target hardware, it may be possible to implement a linearphase FIR ﬁlter
using less multipliers than the minimumphase ﬁlter by taking advantage
of the symmetry even if the ﬁlter length of the linearphase is larger. In
other words the implementation advantages of linearphase ﬁlters may
offset the gains of a minimumphase design making it preferable to use a
linearphase ﬁlter even when linearity of phase is not critical for the appli
cation at hand. Of course there are other reasons to use minimumphase
ﬁlters that may give a compelling reason to do so. For instance, as we have
seen, minimumphase ﬁlter introduce a minimal transient delay. This may
be important enough to stick with a minimumphase design.
156 Implementing FIR Filters
7.1.1 Directform ﬁlter structure
Consider the design of an FIR ﬁlter,
Hf = fdesign.lowpass('N,Fp,Fst',3,.3,.8);
Heq = design(Hf,'equiripple','FilterStructure','dffir');
The ﬁlter order is very low for illustration purposes. The ﬁlter struc
ture that is used to implement the ﬁlter is speciﬁed by the string 'dffir'
(which is the default) and corresponds to the socalled directform struc
ture (also called a tapped delay line). To visualize the structure we can
create a Simulink block for the resulting ﬁlter using the realizemdl com
mand,
realizemdl(Heq);
The resulting block is a subsystem. If we look inside the subsystem, we
will see the structure shown in Figure 7.1.
The number of delays is equal to the ﬁlter order and the number of co
efﬁcients (number of taps), which is one more than the number of delays,
determines the ﬁlter length.
The structure has some regularity in that a sample is read frommemory
(a delay is simply a register), multiplied with a ﬁlter coefﬁcient, and accu
mulated to form the output. DSP processors have historically been built
with this multiplyaccumulate (MAC) instruction in mind. The structure
requires a shift of the input data throughout all delays for each sample. To
minimize the amount of data copies, circular buffers are commonly used
[3].
A downside of the directform structure is that is does not take advan
tage of the symmetry (or antisymmetry) in the coefﬁcients of linearphase
ﬁlters. So the cost of using this ﬁlter structure is maximum in terms of the
number of multipliers required as can be seen using cost(Heq). Never
theless, many DSP processors have been architectured to implement this
structure efﬁciently, so that it should be used even for linearphase ﬁlters
on that hardware. Of course the structure is wellsuited for ﬁlters that
do not present symmetry in their coefﬁcients such as minimumphase FIR
ﬁlters.
Digital Filters with MATLAB Ricardo A. Losada
7.1 Some basics on implementing FIR ﬁlters 157
Figure 7.1: A 4tap FIR ﬁlter implemented in directform.
7.1.2 Symmetric directform ﬁlter structure
The design shown in the previous section was a linearphase design. Since
the number of coefﬁcients is four, there are two unique multipliers. The ﬁl
ter can be implemented using only two multipliers by using the symmetric
directform structure.
Hsym = design(Hf,'equiripple','FilterStructure','dfsymfir');
realizemdl(Hsym);
cost(Hsym)
The ﬁlter structure obtained in Simulink by using the realizemdl com
mand is shown in Figure 7.2. In general, the number of multipliers re
Digital Filters with MATLAB Ricardo A. Losada
158 Implementing FIR Filters
Figure 7.2: A 4tap symmetric FIR ﬁlter implemented using the symmetric directform
ﬁlter structure.
quired is half
∗
of the number required for the directformstructure. Notice
that even though there are only two multipliers, there are still three delays
(same as for the directformstructure) required since the number of delays
corresponds to the order of the ﬁlter.
7.1.3 Transposed directform ﬁlter structure
The directformstructure has the disadvantage that each adder has to wait
for the previous adder to ﬁnish before it can compute its result. For high
speed hardware such as FPGAs/ASICs, this introduces latency which lim
∗
Rounded up if the number of coefﬁcients is odd.
Digital Filters with MATLAB Ricardo A. Losada
7.1 Some basics on implementing FIR ﬁlters 159
Figure 7.3: A 4tap FIR ﬁlter implemented in transposed directform.
its how fast the ﬁlter can be clocked.
A solution to this is to use the transposed directform structure in
stead. With this structure, the delays between the adders can be used
for pipelining purposes and therefore all additions/multiplications can be
performed in fully parallel fashion. This allows realtime handling of data
with with very high sampling frequencies.
The transposed structure for a 4tap ﬁlter is shown in Figure 7.3. It
can be generated using the realizemdl command on a ﬁlter whose ﬁlter
structure has been selected to be transposed directform.
Htran = design(Hf,'equiripple','FilterStructure','dffirt');
realizemdl(Htran)
Digital Filters with MATLAB Ricardo A. Losada
160 Implementing FIR Filters
7.2 Fixedpoint implementation
Implementing an FIRﬁlter using ﬁxedpoint arithmetic is generally a rather
simple task. Some care must be taken when quantizing the coefﬁcients so
that we use enough bits to achieve the desired stopband attenuation of
the ﬁlter and we scale the bits in the most beneﬁcial manner (more on this
below).
Once the coefﬁcients have been quantized, and given a ﬁxedpoint in
put signal, it is easy to ﬁgure out what it would take to perform all mul
tiplications/additions within the ﬁlter in a such a way that no roundoff
error is introduced (socalled fullprecision mode).
With all arithmetic being performed with full precision, there will be bit
growth associated with ﬁltering. In most cases, the output signal cannot
have the full wordlength resulting from this bit growth. We must throw
out bits at the output, usually to match the wordlength of the input signal.
To throw away bits, we simply remove LSBs. This will introduce some
quantization error at the output as we will see below. No overﬂow will
occur by throwing out LSBs.
Appendix D provides a brief review of ﬁxedpoint concepts that may
be useful prior to reading through the rest of this Chapter.
7.2.1 Quantizing the ﬁlter’s coefﬁcients
The ﬁlter coefﬁcients have to be quantized from doubleprecision ﬂoating
point in which they are designed into ﬁxedpoint representation with usu
ally a smaller number of bits. We must make sure we make the most of the
limited number of bits we have.
The ﬁrst thing to do is check if there are enough bits available to cover
the required dynamic range. When we quantize the impulse response of
an FIR ﬁlter, we should not expect to achieve the full 6 dB/bit
∗
. This is not
surprising given the sinclike shape of most FIR impulse responses. Most
of the values of the impulse response are small, so that the average signal
strength does not cover the available range.
Example 57 Let’s compute the SNR when quantizing the impulse response of an
FIR ﬁlter using 16 bits to represent the coefﬁcients:
∗
See Appendix D.
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 161
Hf = fdesign.lowpass(0.4,0.5,0.5,80);
Hd = design(Hf,'equiripple');
himp = Hd.Numerator; % Nonquantized impulse response
Hd.Arithmetic = 'fixed'; % Uses 16bit coefficients by default
himpq = Hd.Numerator; % Quantized impulse response
SNR = 10*log10(var(himp)/var(himphimpq))
SNR =
84.3067
When we quantize the impulse response of an FIR ﬁlter, we may use
the additive noise model to get an idea of how the frequency response is
affected. If the impulse response is given by h[n], the quantized impulse
response is
h
q
[n] = h[n] + e[n]
The additive noise, e[n], will affect the frequency response of the quan
tized impulse response by adding a noiseﬂoor of intensity ε
2
/12, distort
ing both the passband and the stopband of the ﬁlter. In most cases, the
effect on the stopband is most critical, reducing the attainable stopband
attenuation of the ﬁlter.
Agood ruleofthumb is that we can expect about 5 dB/bit when quan
tizing an FIR ﬁlter, as long as we use the bits wisely. By this we mean, scale
themso that impulse response is representable with the bits we have with
out wasting any bits.
The range of values that can be represented with a given wordlength/fraction
length combination falls between a negative and a positive power of two
(for instance the intervals [0.125,0.125), [0.5,0.5), [1,1),[8,8), etc)
∗
. We
want to choose the smallest interval that contains the largest (absolute)
value of the impulse response. If we choose an interval larger than the
minimum, we are just wasting bits. If the largest value of the impulse re
sponse is positive and a power of two, then it is somewhat of a judgement
call whether or not we want to allow for a small overﬂow error for that
one coefﬁcient.
Example 58 Consider the following equiripple Nyquist design:
f = fdesign.nyquist(4,'TW,Ast',0.2,80);
h = design(f,'equiripple');
∗
Note the open interval on the right. That’s because we cannot represent exactly that
value. How close we get will depend on the number of bits available.
Digital Filters with MATLAB Ricardo A. Losada
162 Implementing FIR Filters
The ﬁlter has a minimum attenuation of 80 dB. Its largest coefﬁcient is 0.25.
Using the 5 dB/bit rule, we need at least 16 bits in order to provide the 80
dB of attenuation. Since the largest coefﬁcient is 0.25, we can choose a fractional
length of 17 to scale the bits so that all values in the interval [0.25,0.25) are
representable. In this example we choose to live with small overﬂow in the quan
tization of the largest coefﬁcient (we quantize the value to 0.25 −2
−17
). Since the
value is a power of two, depending on the hardware, another option would be not
to implement this coefﬁcient as a multiplier at all (instead simply perform a bit
shift). This is a nice property of all Nyquist ﬁlters, the largest coefﬁcient is always
a power of two.
In order to set a 16bit wordlength and a 17bit fraction length, we perform
the following steps:
h.Arithmetic = 'fixed'; % Uses 16bit wordlength by default
h.CoeffAutoScale = false;
h.NumFracLength = 17;
Note that there is automatic scaling of the coefﬁcient bits by default. It is designed
to avoid overﬂow in the quantization while minimizing the interval so that the
bits are used as best possible. As we have said, strictly speaking the quantization
of the coefﬁcient equal to 0,25 overﬂows with a fraction length of 17, so a fraction
length of 16 is used by default (which along with the wordlength, means any value
in the interval [0.5,0.5) is representable without overﬂow).
The magnitude response of the quantized ﬁlter is shown in Figure 7.4.
∗
The
16 bits are adequate in order to preserve quite faithfully the intended magnitude
response of the ﬁlter.
To emphasize the point regarding the need to use both the right num
ber of bits and use them wisely, consider what would have happened in
the previous example if instead of a fraction length of 17, we used a frac
tion length of 15. The magnitude response for this case is shown in Figure
7.5. Notice that the quantized ﬁlter no longer meets the required 80 dB
stopband attenuation (the passband also has greater error than in the pre
vious case).
∗
Note that this analysis along with most others (including the impulse response) only
takes into account the quantization of the coefﬁcients. It does not take into account the
fact that there may be roundoff/overﬂow introduced by the multiplications/additions
when actually ﬁltering data.
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 163
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Filter #1: Quantized
Filter #1: Reference
Figure 7.4: Magnitude response of equiripple Nyquist ﬁlter quantized with 16bit
wordlength and a fraction length of 17.
The reason we can no longer meet the stopband attenuation is that we
are essentially wasting two bits by using a fraction length of 15. The max
imum roundoff error (assuming we round to the nearest quantized value)
can be as a large as 2
−16
as opposed to 2
−18
if we had used a fraction
length of 17. This increase in roundoff error results in raising the quanti
zation noise ﬂoor in the frequency domain, reducing the attainable mini
mum stopband attenuation.
Redundant bits in smaller coefﬁcients
So far, we have assumed that the same number of bits are used to represent
each coefﬁcient of an FIR ﬁlter. Because usually many of the coefﬁcients
are quite smaller than the largest coefﬁcient, many of the bits used for
these small coefﬁcients are redundant and, depending on the hardware
used to implement the ﬁlter, could be removed without affecting the per
formance.
Example 59 Let’s look again at what happens when we quantize the following
ﬁlter:
Digital Filters with MATLAB Ricardo A. Losada
164 Implementing FIR Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Filter #1: Quantized
Filter #1: Reference
Figure 7.5: Magnitude response of equiripple Nyquist ﬁlter quantized with 16bit
wordlength and a fraction length of 15.
Hf = fdesign.lowpass(0.4,0.5,0.5,80);
Hd = design(Hf,'equiripple');
Hd.Arithmetic = 'fixed';
B = fi(Hd.Numerator,true,16,16);
The variable B contains the ﬁxedpoint numbers corresponding to the ﬁlter’s coef
ﬁcients. Because the largest value of the coefﬁcients is about 0.434, they have been
quantized with a fractional length of 16 (the default wordlength is in turn 16 bits
which is inline with the requirement for this ﬁlter following the 5dB/bit rule).
Now let’s look at the binary representation of say the ﬁrst three coefﬁcients:
B.bin
ans =
1111111111011100 1111111110100110 1111111111010100 ...
The repeated 1’s towards the left (the MSB) are all unnecessary in order to rep
resent the value. Indeed, we could represent the ﬁrst value simply as 1011100,
the second value as 10100110, and so forth. So in reality we need only 7 bits to
represent the ﬁrst coefﬁcient, 8 bits to represent the second coefﬁcient, etc.
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 165
Indeed, note that 1111111111011100 with a fractional length of 16 corre
sponds to the value 0.00054931640625. But this number can be represented
without loss of precision using only 7 bits:
C1 = fi(0.00054931640625,true,7,16)
C1.bin
The full 16 bits are used for the largest coefﬁcients. For instance for the middle
one (the largest one):
Hd.Numerator(30)
ans =
0.4339599609375
C30 = fi(0.4339599609375,true,16,16);
C30.bin
ans =
0110111100011000
which of course has no redundant bits.
The fact that we have redundant bits in many coefﬁcients is another
way of understanding why we cannot achieve the full 6 dBperbit when
quantizing FIR ﬁlter coefﬁcients. Effectively we don’t use all bits available
to represent most of the coefﬁcients, thus the SNR decreases.
With certain hardware, it is possible to take advantage of the fact that
many coefﬁcients have redundant bits by using smaller multipliers (in
terms of the number of bits) for these coefﬁcients.
7.2.2 Fixedpoint ﬁltering: Directform structure
Consider an FIR ﬁlter implemented in direct form. Assume the input sig
nal has been quantized already and the ﬁlter coefﬁcients have been quan
tized as well. It is possible to easily perform all additions and multipli
cations within the ﬁlter structure in such a way that no roundoff error is
introduced.
If the number of bits used to represent the output is the same as the
number of bits used for the additions (the accumulations) then no round
off error is introduced throughout the ﬁlter. This socalled full precision
mode represents the best possible result we can achieve when ﬁxedpoint
Digital Filters with MATLAB Ricardo A. Losada
166 Implementing FIR Filters
ﬁltering with an FIR ﬁlter implemented in direct form. The only quanti
zation error is due to the coefﬁcient quantization (the quantization of the
input signal is considered separately as it is not affected by what happens
within the ﬁlter itself.
No overﬂows will occur in full precision mode because we assume we
will growenough bits when adding (see below) to accommodate for signal
levels increasing.
Full precision products
In Appendix D, we saw that given two ﬁxedpoint numbers, one with
wordlength/fraclength given by {B
1
, F
1
} and the other with wordlength/fraclength
given by {B
2
, F
2
}, the product of the two numbers can be represented with
no roundoff by using a wordlength/fraclength of {B
1
+ B
2
, F
1
+ F
2
}.
For a directform FIR ﬁlter to be implemented with full precision, this
means that there will be bit growth once the input signal is multiplied with
the ﬁlter’s coefﬁcients (see Figure 7.1).
Full precision additions
In Appendix D, we saw that in order to perform a series of N additions
without introducing roundoff error, it is necessary to allowfor a bitgrowth
of ⌊log
2
(N)⌋ +1 bits. In an FIR ﬁlter implemented in direct form, there are
a series of additions that occur after multiplying the input signal with the
coefﬁcients (see Figure 7.1).
Example 60 Consider once again the following design:
Hf = fdesign.lowpass(0.4,0.5,0.5,80);
Hd = design(Hf,'equiripple');
Hd.Arithmetic = 'fixed';
The coefﬁcients are represented with 16 bits. If the input is represented with 16
bits as well, full precision multiplications would mean that the values to be added
are represented with 32 bits. Since there are 58 additions to be performed, the
number of bits we need in order to perform the additions with full precision is
⌊log
2
(58)⌋ +1 = 6
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 167
As it turns out, it is possible to performthe additions with fullprecision
by using even less bits than what it is speciﬁed by the formula ⌊log
2
(N)⌋ +
1. We will look at how to do so next.
Full precision multiplications/additions given the actual coefﬁcient val
ues
Let’s look again at the previous example to see if we actually need 32 bits
for the fullprecision multiplications. The largest coefﬁcient of the ﬁlter Hd
is 0.434. The coefﬁcients are represented with {B
1
, F
1
} = {16, 16} and the
input is assumed to be represented with {B
2
, F
2
} = {16, 15}, i.e., the input
signal is assumed to fall within the interval [−1, 1).
The fraclength for the product is given by F
1
+ F
2
=31. Since the largest
possible value that any input value multiplied by any coefﬁcient can pro
duce is about 0.434, the interval used to represent the products must be
[−0.5, 0.5). This interval is covered by making the wordlength equal to
the fraclength. Since the fraclength is 31, the wordlength needed for full
precision multiplications is also 31, not 32.
Now let’s move to fullprecision additions. Let’s take a look at the
convolution equation for a length N +1 FIR ﬁlter,
y[n] =
N
∑
m=0
h[m]x[n −m]
Given that we should know what are the maximum values that the
input can take, we want to determine what are the maximum numbers the
output can take. To do so, we use some simple math. We start by taking
the absolute value at both sides of the convolution equation,
y[n] =
N
∑
m=0
h[m]x[n −m]
Using the triangle inequality for the 1norm, we have
y[n] ≤
N
∑
m=0
h[m]x[n −m]
=
N
∑
m=0
h[m] x[n −m]
Digital Filters with MATLAB Ricardo A. Losada
168 Implementing FIR Filters
Let’s say that the input covers the range [−R/2, R/2). This means that
in the worst case,
y[n] =
R
2
N
∑
m=0
h[m] =
R
2
h[n]
1
Thus the 1norm of the impulse response provides a gain factor for the
output relative to the input. For example, if R/2 = 1, the maximum, value
the output can take is given by h[n]
1
. This tells us how many bits we
need to grow in order to perform fullprecision arithmetic throughout the
ﬁlter.
Example 61 For the 59tap ﬁlter Hd we have been using, we can compute the
1norm of its impulse response as follows:
norm(Hd,'l1')
ans =
1.9904
This means that we need to ensure the additions can represent the range [−2, 2).
Since the multiplications fall in the interval [−0.5, 0.5), it is necessary to add
two bits in order to implement a fullprecision ﬁlter. If we look at the values for
AccumWordLength and OutputWordLength when we write get(Hd), we see than
indeed these values have been set to 33 bits, i.e. two more bits than what is used
for the multiplications.
We have seen how we determine the number of bits required for full
precision implementations. As a matter a fact, this value is still somewhat
conservative because it assumes the worst possible case for the input. If
we were to actually take into account typical values we think the input
can assume, we may even be able to reduce the required number of bits
further.
7.2.3 Fixedpoint ﬁltering: Transposed directform struc
ture
In order to perform all operations with full precision, the settings for the
transposed directform structure shown in Figure 7.3 are almost identical
to the nontransposed directform case.
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 169
The only difference has to do with the wordlength necessary for the
state registers. In the directform case, the states needed to have the same
wordlength as the input signal in order to avoid roundoff. In the trans
posed structure, the states must have the same wordlength as the wordlength
used for addition. This is typically more than twice the wordlength of the
input, so that the transposed structure clearly has higher memory require
ments for a given ﬁlter.
7.2.4 Quantization of the output signal
In many cases, we need to reduce the number of bits at the output of the
ﬁlter for downstream processing. A common case is to use the same num
ber of bits for the output as we did for the input. In the example above, the
input was represented with 16 bits, but the fullprecision output required
33 bits. This means we may need to discard
∗
17 LSBs at the output of the
ﬁlter. The situation is depicted in Figure 7.6 for the directform structure.
The idea is the same for other structures. In that ﬁgure, we assumed that
the coefﬁcients are represented with the same number of bits as the input
and all multiplications/additions are performed with full precision. G is
the number of bits that need to be added for the additions to be performed
without roundoff as discussed above.
As discussed in Appendix D, the quantization can be modeled as addi
tive white noise with variance ε
2
/12 as long the number of bits discarded
is relative large (more than 3). For the directform structure, this means
we can replace the quantizer with an adder as shown in Figure 7.7.
In the example above, the fullprecision version of Hd had 33 bits at the
output and a fractional length of 31. If we discard 17 LSBs, we will have
16 bits at the output and a fractional length of 14:
Hd.FilterInternals = 'specifyPrecision';
Hd.OutputWordLength = 16; % 3316 = 17
Hd.OutputFracLength = Hd.OutputFracLength17; % 14
The variance of the quantization noise that we introduced will be given
by:
∗
Note that by discarding, we do not necessarily mean simple truncation. It is possible
that when we discard, we perform some sort of rounding such as round to nearest. This
is controlled with the RoundMode setting once the ﬁlter internals have been set to specify
the precision.
Digital Filters with MATLAB Ricardo A. Losada
170 Implementing FIR Filters
Figure 7.6: Directform FIR ﬁlter with quantization at the output.
2ˆ(14)ˆ2/12
ans =
3.1044e10
We can also ﬁnd this value by integrating the powerspectral density of
the output signal due to the noise signal e[n] by using (D.4). Note that the
transfer function between the noise input, e[n], and the output is simply
H
e
(z) = 1. The integral of the PSD gives the average power or variance:
P = noisepsd(Hd);
avgpower(P)
ans =
3.0592e10
This value is close to the theoretical value we expect from the additive
noise model as computed above.
∗
The PSD is plotted in Figure 7.8. Note
that the PSD is approximately ﬂat as it should be for white noise (the plot
can be obtained by calling the noisepsd command with no outputs).
∗
The PSD here includes a factor of 1/2π, therefore the intensity of the PSD is given by
the variance divided by 2π. When we integrate in order to compute the average power,
we should keep in mind that the variance has already been scaled by 2π.
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 171
Figure 7.7: Directform FIR ﬁlter with quantization at the output.
7.2.5 Evaluating the performance of the ﬁxedpoint ﬁlter
In order to evaluate how well the ﬁxedpoint ﬁlter compares to the ref
erence ﬂoatingpoint ﬁlter, we can ﬁlter some test data and compare the
results. In order to isolate the behavior of the ﬁlter, it is important that the
same quantized input test data is used in all cases.
We would like to distinguish between three different cases:
• What we ideally would want to compute, y
r
[n]. This is the result of us
ing the nonquantized original ﬁlter coefﬁcients and performing all
multiplications/additions with inﬁnite precision (or at least double
precision ﬂoatingpoint arithmetic).
• The best we can hope to compute, y
d
[n]. This is the result of using the
quantized coefﬁcients, but without allowing any further roundoff
noise within the ﬁlter or at its output. All multiplications/additions
are performed with fullprecision.
• What we actually compute, y[n]. This is the result we get with all ﬁnal
Digital Filters with MATLAB Ricardo A. Losada
172 Implementing FIR Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−150
−145
−140
−135
−130
−125
−120
−115
−110
−105
−100
Normalized Frequency (×π rad/sample)
P
o
w
e
r
/
f
r
e
q
u
e
n
c
y
(
d
B
/
r
a
d
/
s
a
m
p
l
e
)
Round−off Noise Power Spectrum
Computed PSD
Theoretical PSD
Figure 7.8: Power spectral density of the quantization noise at the output of an FIR ﬁlter.
ﬁxedpoint settings in our ﬁlter.
Clearly, what we actually compute can at best be the same as the best
we can hope to compute. In order to make the best we can hope to com
pute closer to what we ideally would compute, we would have to use
more bits to represent the ﬁlter coefﬁcients (and throughout the ﬁlter).
Example 62 Consider once again the following design:
Hf = fdesign.lowpass(0.4,0.5,0.5,80);
Hd = design(Hf,'equiripple');
Hd.Arithmetic = 'fixed';
As we have said, the quantized ﬁlter uses 16bits to represent the coefﬁcients by
default. A plot of the magnitude response of Hd shows that 16bits are not quite
enough in this case to get the full 80 dB attenuation throughout the stopband.
Nevertheless, if we choose to use 16 bits for the coefﬁcients, the best we can hope
to achieve can be computed for some test data as follows:
rand('state',0);
x = fi(2*(rand(1000,1).5),true,16,15);
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 173
Href = reffilter(Hd); % Compute reference filter
yr = filter(Href,x);
yd16 = filter(Hd,x); % Uses fullprecision
var(yrdouble(yd16))
ans =
4.8591e10
The ﬁlter Hd performs all multiplications/additions using full precision because
the FilterInternals property is set by default to 'FullPrecision'.
If we decide to use say 18 bits for the coefﬁcients instead of 16, we can get
closer to the result obtained with the reference ﬁlter,
Hd18 = copy(Hd);
Hd18.CoeffWordLength = 18;
yd18 = filter(Hd18,x); % Uses fullprecision
var(yrdouble(yd18))
ans =
2.4946e11
Once we have settled the number of bits for the coefﬁcients, we have
established a baseline for the best we can hope to achieve if we can’t use
fullprecision. We then measure how well our actual results compare to
the best we can hope for.
Example 63 Continuing with our previous example. Suppose we can only keep
16 bits at the output and use 16 bit coefﬁcients. In this example, this means we
need to remove 17 LSBs at the output as was shown in Figure 7.6. Once again,
this can be done as follows:
Hd.FilterInternals = 'specifyPrecision';
Hd.OutputWordLength = 16; % 3316 = 17
Hd.OutputFracLength = Hd.OutputFracLength17;
If we now ﬁlter the same data and compute the energy in the error between the
best we can hope for and what we actually compute:
y = filter(Hd,x);
var(double(y)double(yd16))
ans =
3.1004e10
We of course obtain the same result we had previously computed for the variance
of the noise, i.e., 2ˆ(14)ˆ2/12.
Digital Filters with MATLAB Ricardo A. Losada
174 Implementing FIR Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response Estimate
Full precision
16−bit output
14−bit output
12−bit output
Figure 7.9: Magnitude response estimates for various output wordlengths.
Using the magnitude response estimate to evaluate performance
Most of the analysis commands we performon ﬁxedpoint ﬁlters only take
into account the coefﬁcient quantization. This is true of the magnitude
response, impulse response, groupdelay, and pole/zero computation.
The magnitude response estimate however, computes an estimate of
the magnitude response of the ﬁlter by actually ﬁltering data through it.
The ﬁxedpoint ﬁltering means that roundoff error may be introduced
because of discarding bits at the output or other roundoff if the addi
tions/multiplications are not performed with full precision.
The closer the magnitude response estimate resembles the magnitude
response computed solely based on the quantization of the coefﬁcients,
the more the actual ﬁltering approaches the best we can hope to compute.
In this way, we can use the magnitude response estimate to evaluate the
performance of the ﬁxedpoint ﬁlter.
Example 64 Let us continue with the same design we have been using the last
several examples. If we start with full precision, the magnitude response estimate
is almost indistinguishable from the magnitude response:
Digital Filters with MATLAB Ricardo A. Losada
7.2 Fixedpoint implementation 175
0.5 0.6 0.7 0.8 0.9 1
−100
−95
−90
−85
−80
−75
−70
−65
−60
−55
−50
−45
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response Estimate
Full precision
16−bit output
14−bit output
12−bit output
Figure 7.10: Stopband details of magnitude response estimates for various output
wordlengths.
Hf = fdesign.lowpass(0.4,0.5,0.5,80);
Hd = design(Hf,'equiripple');
Hd.Arithmetic = 'fixed'; % 16bit coefficients
H = freqz(Hd);
He = freqrespest(Hd,1,'NFFT',8192);
norm(HHe)
ans =
0.0023
Now, we will compute the magnitude response estimate using always the same
16bit coefﬁcients, but in each case discarding a different number of bits at the
output. Notice that we now use a relatively large number of trials, 50, in order
to get a reliable average from the estimate (the computation takes a while). We’ll
start by discarding 17 bits,
Hd.FilterInternals = 'specifyPrecision';
Hd.OutputWordLength = 16; % 3316 = 17
Hd.OutputFracLength = Hd.OutputFracLength17;
He16 = freqrespest(Hd,50,'NFFT',8192);
Digital Filters with MATLAB Ricardo A. Losada
176 Implementing FIR Filters
We’ll repeat this for 14bit and 12bit outputs,
Hd.OutputWordLength = 14;
Hd.OutputFracLength = 12;
He14 = freqrespest(Hd,50,'NFFT',8192);
Hd.OutputWordLength = 12;
Hd.OutputFracLength = 10;
He12 = freqrespest(Hd,50,'NFFT',8192);
The plot of the various magnitude response estimates is shown in Figure 7.9. Note
the quantization at the output basically results in reduced stopband attenuation.
The stopband is shown in greater detail in Figure 7.10.
Digital Filters with MATLAB Ricardo A. Losada
Chapter 8
Implementing IIR Filters
8.1 Some basics of IIR implementation
8.1.1 The use of secondorder sections
All of the IIR designs we have discussed in Chapter 2 are performed us
ing secondorder sections by default. The full polynomials of the trans
fer function are never formed. The main reason for this has to do with
hardware implementations of IIR ﬁlters. However, even from the design
perspective it is good practice to always keep the design in secondorder
section and avoid computing the transfer function explicitly.
The reason is that forming the transfer function involves polynomial
multiplication, or equivalently convolution of the polynomial coefﬁcients.
Convolution can introduce signiﬁcant roundoff error even with double
precision ﬂoatingpoint arithmetic. This is mainly due to additions of large
numbers with small numbers (that become negligible when using ﬁnite
precision arithmetic).
Of course the effect gets worse as the ﬁlter order increases since we are
performing more and more convolutions. For loworder designs, it is not
absolutely necessary to use secondorder sections, but there still may be
good reasons to do so from an implementation perspective.
Example 65 As a rather extreme example consider the following design:
Hf = fdesign.lowpass('Fp,Fst,Ap,Ast',.47,.48,.05,120);
Hc = design(Hf,'cheby1');
[b,a] = tf(Hc);
178 Implementing IIR Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−1000
−900
−800
−700
−600
−500
−400
−300
−200
−100
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
Second−order sections
Transfer function
Figure 8.1: A Chebyshev type I ﬁlter implemented in secondorder sections and with the
transfer function.
The resulting ﬁlter order is very high (67). By forming the transfer function
using the tf command, we have completely distorted the response of the ﬁlter (see
Figure 8.1). Moreover, the ﬁlter has become unstable! The transfer function of the
polynomials is completely wrong as evidenced by the pole/zero plot (Figure 8.2).
Compare to the pole/zero plot of the secondorder sections to see what it should
look like (Figure 8.3).
The most common secondorder section structures are the directformI
and directformII. Atwosection directformI ﬁlter is shown in Figure 8.4.
The structure uses more delays than the directform II structure because
the latter shares the delays between the numerator and denominator of
each section while the former does not. However, if we do not use the
scale value between sections, we can share the delays from one section to
the next, so that the directform I structure would only require two more
delays than the directform II rather than twice as many.
8.1.2 Allpassbased implementations
Secondorder sections have been used for many years to implement IIR
ﬁlters. However, another possibility is to use allpassbased implementa
Digital Filters with MATLAB Ricardo A. Losada
8.1 Some basics of IIR implementation 179
−4 −3 −2 −1 0 1 2
−2
−1.5
−1
−0.5
0
0.5
1
1.5
2
Real Part
I
m
a
g
i
n
a
r
y
P
a
r
t
Pole/Zero Plot
Filter #1: Zero
Filter #1: Pole
Figure 8.2: Pole/zero plot of a Chebyshev type I ﬁlter implemented with the transfer
function.
−1.5 −1 −0.5 0 0.5 1 1.5
−1
−0.8
−0.6
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1
Real Part
I
m
a
g
i
n
a
r
y
P
a
r
t
67
Pole/Zero Plot
Filter #1: Zero
Filter #1: Pole
Figure 8.3: Pole/zero plot of a Chebyshev type I ﬁlter implemented with secondorder
sections.
tions. These have the advantage that they require less multipliers than
corresponding secondorder sections implementations.
The idea is to implement the ﬁlter H(z) as the sumof two allpass ﬁlters
Digital Filters with MATLAB Ricardo A. Losada
180 Implementing IIR Filters
Figure 8.4: Directform I secondorder sections structure.
A
0
(z) and A
1
(z),
H(z) =
1
2
(A
0
(z) + A
1
(z)) (8.1)
This decomposition, known as parallel allpass or coupledallpass, can
be performed under certain conditions on H(z) [15], [16], [17]. It is know
that Butterworth, Chebyshev, and elliptic ﬁlters satisfy such conditions
and therefore can be implemented in such manner.
The allpass ﬁlters themselves can be implemented in various ways.
Lattice ﬁlters are one possibility. In the Filter Design Toolbox, the all
pass ﬁlters are implemented using a minimal number of multipliers and
adders. In keeping with the good practices of not forming the full transfer
function, the allpass ﬁlters are implemented as cascades of loworder all
pass sections. The delays are shared between sections whenever possible
in order to minimize the number of them required.
Example 66 To illustrate, consider the elliptic design of Example 26. When us
ing the directform II secondorder sections implementation we found that the
number of multipliers required was 20, the number of adders was also 20 and the
number of delays was 10. If we use cascaded loworder allpass sections,
He2 = design(Hf,'ellip','FilterStructure','cascadeallpass');
we can ﬁnd through the cost function that the number of multipliers reduces to
12. The number of adders increases to 23, and the number of delays is 15.
To visualize the structure, we use the realizemdl command to gener
ate a Simulink model of the ﬁlter. Even though the number of adders is
higher than with secondorder sections, the saving in multipliers usually
more than compensates. Ultimately, this depends on the hardware used
to implement the ﬁlter. On a programmable DSP processor for instance,
an adder and a multiplier have the same cost. This is not the case with an
FPGA or an ASIC.
Digital Filters with MATLAB Ricardo A. Losada
8.2 Fixedpoint implementation 181
Example 67 For illustration purposes, we can easily get to the transfer function
∗
of the allpass ﬁlters as follows:
Hf = fdesign.lowpass('N,F3dB,Ap,Ast',5,.3,1,60);
He = design(Hf,'ellip','FilterStructure','cascadeallpass');
[b1,a1] = tf(He.stage(1).stage(1)); % A0(z)
[b2,a2] = tf(He.stage(1).stage(2)); % A1(z)
Note that He.stage(1) contains the term A
0
(z) + A
1
(z) while He.stage(2)
is simply the 1/2 factor. If we look at the numerators b1 and b2, we can see that
they are reversed versions of a1 and a2 respectively. This is an indication of their
allpass characteristic.
Lattice wave digital ﬁlters
A variation of the cascaded allpass implementation is to use lattice wave
digital ﬁlters. The term lattice in this case refers to the fact that there are
two parallel allpass branches A
0
(z) and A
1
(z). It does not refer to the
lattice structure proposed by Gray and Markel [18].
To use these structures for the elliptic design of Example 26, it is simply
a matter of specifying the appropriate ﬁlter structure,
He3 = design(Hf,'ellip','FilterStructure','cascadewdfallpass');
This implementation requires the same 12 multipliers as the cascade
allpass does. However, the number of adders increases to 34. The number
of states is only 11, but the savings in number of states may not make up
for the additional adders required.
In terms of computational cost, the cascade allpass implementation
seems to be superior. However, the lattice wave digital ﬁlters are well
scaled for ﬁxedpoint implementations, a fact that may make their use
compelling.
More about lattice wave digital ﬁlters can be found in [18] and [19] for
example.
8.2 Fixedpoint implementation
Implementing IIR ﬁlters with ﬁxedpoint arithmetic is more challenging
than the FIR case. We have already seen reasons not to use the transfer
∗
This is not needed for implementation purposes.
Digital Filters with MATLAB Ricardo A. Losada
182 Implementing IIR Filters
function of IIR ﬁlters even before thinking of ﬁxedpoint implementation.
The case to avoid the transfer function becomes much stronger once ﬁxed
point is taken into account. The following example showcases this.
Example 68 Consider the following design:
Hf = fdesign.lowpass(0.45,0.5,0.5,80);
He = design(Hf,'ellip'); % Already in SOS form
Let’s construct a directform II ﬁlter using the transfer function equivalent to the
SOS we have:
[b,a] = tf(He);
Htf = dfilt.df2(b,a);
Now let’s quantize the coefﬁcients using 16 bits and compare the resulting mag
nitude responses.
He.Arithmetic = 'fixed';
Htf.Arithmetic = 'fixed';
The magnitude responses are shown in Figure 8.5. Note that in this case, forming
the doubleprecision ﬂoatingpoint transfer function does not signiﬁcantly alter
the magnitude response (try fvtool(b,a)). The deviation that we observe for the
transfer function in Figure 8.5 has to do with the quantization.
It is worth noting that the magnitude responses shown take into ac
count only the quantization of coefﬁcients. Any other roundoff error in
troduced by the ﬁxedpoint settings is not reﬂected in the magnitude re
sponse analysis shown in fvtool.
8.2.1 Fixedpoint ﬁltering
In general, for ﬁxedpoint implementation, we want to stay away from
the transfer function because quantizing large polynomials introduces sig
niﬁcant errors when compared to quantizing secondorder polynomials.
Nevertheless, with IIR ﬁlters, it is not enough to obtain a nice magnitude
response with the quantized coefﬁcients.
Unlike FIR ﬁlters, it is not possible to implement IIR ﬁlters using full
precision arithmetic since this would result in inﬁnite bit growth due to
Digital Filters with MATLAB Ricardo A. Losada
8.2 Fixedpoint implementation 183
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response (dB)
SOS filter
TF filter
Figure 8.5: Comparison of magnitude response of the same ﬁlter quantized to 16bit
coefﬁcients. In one case, we use secondorder sections (SOS) while in the other case we
use the transfer function (TF).
the feedback. Therefore, it is necessary to introduce quantization at the
feedback points within a ﬁlter structure. This quantization will of course
introduce roundoff error. In the worst case, the quantization produces an
overﬂow condition.
Nevertheless, as with FIR ﬁlters, we can consider the following com
putations for the output:
• y
r
[n], what we ideally would want to compute. This is the result of us
ing the nonquantized original ﬁlter coefﬁcients and performing all
multiplications/additions with inﬁnite precision (or at least double
precision ﬂoatingpoint arithmetic).
• y
d
[n], the best we can hope to compute. Since fullprecision is not an op
tion with IIR ﬁlters, in order to obtain a baseline, we can use the
double() command on the ﬁlter to obtain a ﬁlter that has quan
tized coefﬁcients, but performs all multiplications/additions using
doubleprecision ﬂoatingpoint arithmetic.
∗
∗
Note that the commands refﬁlter() and double() differ in that the former uses the orig
inal ﬂoatingpoint coefﬁcients, while the later uses the quantized coefﬁcients.
Digital Filters with MATLAB Ricardo A. Losada
184 Implementing IIR Filters
• y[n], what we actually compute,. This is the result we get with all ﬁnal
ﬁxedpoint settings in our ﬁlter.
Let us consider the directform II secondorder sections structure. For
each section, the feedback part comes before the shared states. Since we
need to quantize the result from the feedback loop prior to the values en
tering the states, we want to ensure that roundoff error at this point is
minimized.
Example 69 Let us repeat the previous design with a slight change. By default,
we scale and reorder the secondorder sections in order to help obtaining good
ﬁxedpoint ﬁltering results from the start. However, for now, let’s remove the
scaling/reordering to show how a good magnitude response is necessary but not
sufﬁcient in order to obtain satisfactory results.
Hf = fdesign.lowpass(0.45,0.5,0.5,80);
He = design(Hf,'ellip','SOSScaleNorm',''); % Don't scale
He.Arithmetic = 'fixed';
We’ll compute the ideal output, y
r
[n], and compare to the best we can hope
to compute, y
d
[n]. The difference between the two is due solely to coefﬁcient
quantization.
rand('state',0);
x = fi(2*(rand(1000,1).5),true,16,15);
Hr = reffilter(He);
yr = filter(Hr,x); % Ideal output
Hd = double(He);
yd = filter(Hd,x); % This is the best we can hope for
var(yryd)
ans =
1.5734e08
Now, let’s enable min/max/overﬂow logging and ﬁlter the same data with the
ﬁxedpoint ﬁlter:
fipref('LoggingMode','on')
ye = filter(He,x);
qreport(He)
Digital Filters with MATLAB Ricardo A. Losada
8.2 Fixedpoint implementation 185
If we look at the results from qreport, we can see that the states have overﬂown
37 out of 10000 times. Because of the overﬂow, it is not worth comparing ye to
yd.
In order to avoid overﬂow, we can use scaling to control the signal
growth at critical points inside the ﬁlter. The most stringent scaling, ℓ
1

norm scaling, will ensure that no overﬂow can occur.
Example 70 Let us design the elliptic ﬁlter again, but using ℓ
1
norm scaling this
time. For now, we will disable reordering of the secondorder sections:
s = fdopts.sosscaling;
s.sosReorder = 'none';
Hl1 = design(Hf,'ellip','SOSScaleNorm','l1',...
'SOSScaleOpts',s);
Hl1.Arithmetic = 'fixed';
Now let’s ﬁlter with this scaled structure,
yl1 = filter(Hl1,x);
qreport(Hl1)
Notice from the report that we have no overﬂows. Therefore we can compare the
output to our baseline in order to evaluate performance,
var(yddouble(yl1))
ans =
1.8339e04
When doing ﬁxedpoint ﬁltering, one needs to compromise between
maximizing the SNR and minimizing the possibility of overﬂows. The
ℓ
1
norm scaling we have used is good for avoiding overﬂows, but reduces
the signal levels too much, adversely affecting the SNR. Amore commonly
used scaling (the default) is to use L
∞
normscaling. However, this scaling
may result in overﬂow as the next example shows.
Example 71 Let’s design the ﬁlter and scale using L
∞
norm scaling. For now,
we still do not reorder the sections.
HLinf = design(Hf,'ellip','SOSScaleNorm','Linf',...
'SOSScaleOpts',s);
HLinf.Arithmetic = 'fixed';
Digital Filters with MATLAB Ricardo A. Losada
186 Implementing IIR Filters
Now let’s ﬁlter and look at the report.
yLinf = filter(HLinf,x);
qreport(HLinf)
The report shows that 8 overﬂows in the states have occurred.
So far, we have not reordered the secondorder sections in the exam
ples we have explored. Reordering can help improve the SNR, and, as the
next example shows, sometimes even help avoid overﬂow.
Example 72 Let’s once again use L
∞
norm scaling, but this time use automatic
reordering of the sections.
s = fdopts.sosscaling;
s.sosReorder = 'auto';
HLinf = design(Hf,'ellip','SOSScaleNorm','Linf',...
'SOSScaleOpts',s);
HLinf.Arithmetic = 'fixed';
Once again, let’s ﬁlter the same data, and look at the report.
yLinf = filter(HLinf,x);
qreport(HLinf)
Since we did not overﬂow, it is meaningful to compare the output to our baseline
to evaluate performance.
var(yddouble(yLinf))
ans =
1.4809e05
As we can see, the result is more than an order of magnitude better than what we
got with ℓ
1
norm scaling.
Yet a less stringent scaling is to use L
2
norm scaling.
∗
Yet the chances
of overﬂowing when using that type of scaling are even larger.
It is worth noting that in some applications, it is preferable to allow
for the occasional overﬂow in order to increase the SNR overall. The as
sumption is that an overﬂow once in a while is not critical for the overall
performance of the system.
∗
This norm can be shown to be the same as ℓ
2
norm. This is Parseval’s theorem.
Digital Filters with MATLAB Ricardo A. Losada
8.2 Fixedpoint implementation 187
8.2.2 Autoscaling
The scaling we have seen so far is data agnostic. As a result sometimes
overﬂow occurs.
We can use the autoscale command in order to optimize the ﬁxed
point fractional length settings in a ﬁlter based on speciﬁc input data that
is given. Doing so, we can get even better results than if we use data
agnostic scaling.
Example 73 Let’s try once again to design the ﬁlter without dataagnostic scal
ing.
Hf = fdesign.lowpass(0.45,0.5,0.5,80);
He = design(Hf,'ellip','SOSScaleNorm',''); % Don't scale
He.Arithmetic = 'fixed';
We know that this ﬁlter will overﬂow with the input data we have. However, if
we use this input data to autoscale,
Hs = autoscale(He,x);
and we ﬁlter the same data,
ys = filter(Hs,x);
qreport(Hs)
we can see from the report that now overﬂow has been avoided. We now evaluate
the output relative to our baseline,
var(yddouble(ys))
ans =
1.4144e07
Which is of course the best result we have obtained so far.
Finally, if we combine L
∞
norm scaling, automatic reordering, and
autoscaling, we can easily verify that we can get even better results:
var(yddouble(ys2))
ans =
2.3167e08
Digital Filters with MATLAB Ricardo A. Losada
188 Implementing IIR Filters
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−100
−90
−80
−70
−60
−50
−40
−30
−20
−10
0
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response Estimate
Best we can hope for
Autoscaled, re−ordered, L
∞
Re−ordered L
∞
Non−reordered l
1
Figure 8.6: Magnitude response estimates for various scaling cases.
8.2.3 Evaluating ﬁlter performance using the magnitude re
sponse estimate
As we saw for FIR ﬁlters, one way to evaluate the performance of the
ﬁxedpoint IIR ﬁlter is to compute an estimate of the magnitude response
by ﬁltering data.
Because the ﬁltering is performed with ﬁxedpoint arithmetic, the mag
nitude response estimate takes into account not only the quantization of
the coefﬁcients, but also any roundoff error introduced within the ﬁlter.
The magnitude response estimate is particularly useful when the ﬁxed
point ﬁlter behaves in a weekly nonlinear manner.
∗
This means that it
is most useful when no overﬂow occurs given that overﬂows introduce
signiﬁcant nonlinear behavior.
As an example, Figure 8.6 shows the magnitude response estimate for
four cases corresponding to examples above. In all four cases shown, over
ﬂow is avoided. Once again, the roundoff error in the ﬁltering has a net
effect of reducing the stopband attenuation. Moreover, unlike the FIRcase,
∗
Quantization is a nonlinear operation. But a linear model that approximates the behav
ior as additive white noise is adequate in many cases as we have seen.
Digital Filters with MATLAB Ricardo A. Losada
8.2 Fixedpoint implementation 189
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45
−2
−1.5
−1
−0.5
0
0.5
1
1.5
2
Normalized Frequency (×π rad/sample)
M
a
g
n
i
t
u
d
e
(
d
B
)
Magnitude Response Estimate
Best we can hope for
Autoscaled, re−ordered, L
∞
Re−ordered L
∞
Non−reordered l
1
Figure 8.7: Passband details of magnitude response estimates for various scaling cases.
the roundoff can also affect the passband response of the ﬁlter. The pass
band details are shown in Figure 8.7.
Digital Filters with MATLAB Ricardo A. Losada
Part III
Appendices
Appendix A
Summary of relevant ﬁlter design
commands
A.1 Filter Design (fdesign)
A.1.1 Setup design speciﬁcations
Use fdesign objects to store design speciﬁcations. This will not design the
ﬁlter, only set the specs. In order to design you need to invoke the design
command (see below).
f = fdesign.lowpass('Fp,Fst,Ap,Ast',0.3,0.4,0.5,75);
To view all available frequency response designs (lowpass, highpass, etc)
type:
help fdesign/responses
To change speciﬁcation set, it can be done a step at a time,
f.Specification = 'N,Fc,Ap,Ast';
f.FilterOrder = 60;
...
but it can also be done in one shot,
setspecs(f,'N,Fc,Ap,Ast',60,0.3,0.5,75);
192 Summary of relevant ﬁlter design commands
By default, frequency speciﬁcations are assumed to be normalized with an
implied scaling by π, so for example a value of 0.3 for Fc means that the
cutoff frequency is being set to 0.3π radians/sample. In order to specify
frequencies in Hertz, the sampling frequency must be appended,
setspecs(f,'N,Fc,Ap,Ast',60,30,0.5,75,200); % Fc = 30 Hz, Fs = 200 Hz
For a list of all available speciﬁcation sets for a particular response,
set(f,'Specification')
A.1.2 Design options
To view available design methods for a particular response/speciﬁcation
combination:
designmethods(f) % List all design methods
designmethods(f,'iir') % List only IIR designs
designmethods(f,'fir') % List only FIR designs
To design with default design options
h = design(f) % Use default design method
% For the following commands, h will be an array
h = design(f,'all') % Design for all design methods
h = design(f,'fir') % Design for all FIR methods
h = design(f,'iir') % Design for all IIR methods
To view design options and defaults for a particular design method:
designoptions(f,'equiripple')
For contextsensitive (response sensitive) help type:
help(f,'equiripple') % Specific help for lowpass/equiripple combo
Digital Filters with MATLAB Ricardo A. Losada
A.2 Selecting ﬁlter structure 193
A.1.3 Design analysis/validation
To view various frequencydomain, timedomain, or polezero responses:
f = fdesign.lowpass('Fp,Fst,Ap,Ast',1.3e3,1.4e3,0.5,75);
h = design(f,'equiripple','StopbandShape','1/f','StopbandDecay',3);
fvtool(h)
In order to measure critical frequencies and/or ripple/attenuations:
measure(h)
To view a highlevel implementation cost:
f = fdesign.halfband('TW,Ast',0.01,80);
h = design(f,'equiripple');
cost(h)
ans =
Number of Multipliers : 463 % Number of nonzero and nonone coefficients
Number of Adders : 462 % Total number of additions
Number of States : 922 % Total number of states
MultPerInputSample : 463 % Nonzero/nonone multiplications per input sample
AddPerInputSample : 462 % Additions per input sample
For some general information about the design:
info(h)
A.2 Selecting ﬁlter structure
At design time, different ﬁlter structures can be speciﬁed. For FIR ﬁlters,
the default structure is directform, dffir. For symmetric ﬁlters (linear
phase), half the multipliers can be saved by using a symmetric FIR struc
ture:
f = fdesign.lowpass('N,Fp,Fst',40,0.4,0.5);
h1 = design(f,'Wpass',1,'Wstop',10,'FilterStructure','dffir'); % default
h2 = design(f,'Wpass',1,'Wstop',10,'FilterStructure','dfsymfir');
cost(h1)
cost(h2)
Digital Filters with MATLAB Ricardo A. Losada
194 Summary of relevant ﬁlter design commands
For IIR ﬁlters, the default structure is directform II. IIR ﬁlters are de
signed by default as cascaded secondorder sections (SOS). Directform I
SOS structures use more states, but may be advantageous for ﬁxedpoint
implementations,
f = fdesign.lowpass('N,F3dB,Ap,Ast',5,0.45,1,60);
h1 = design(f,'FilterStructure','df1sos');
h2 = design(f,'FilterStructure','df2sos');
cost(h1)
cost(h2)
A.3 Scaling IIR SOS structures
By default, sos IIR designs using structures such as df1sos and df2sos are
scaled. The scaling uses L
∞
norm scaling, so that the cumulative magni
tude response of the secondorder sections (ﬁrst section alone, ﬁrst and
second sections, ﬁrstsecondandthird, etc.) does not exceed one (0 dB):
f = fdesign.lowpass;
h1 = design(f,'ellip','FilterStructure','df1sos');
h2 = design(f,'ellip','FilterStructure','df2sos');
s = dspopts.sosview;
s.view='Cumulative'; % Set view to cumulative sections
fvtool(h1,'SOSViewSettings',s)
s.secondaryScaling = true; % Use secondary scaling point for df2sos
fvtool(h2,'SOSViewSettings',s)
This scaling helps avoid overﬂows when the ﬁlter is implemented with
ﬁxedpoint arithmetic, but doesn’t totally eliminate the possibility of them.
To eliminate overﬂows, the more restrictive l
1
normscaling can be used (at
the expense of reduced SNR due to subutilization of the dynamic range):
f = fdesign.lowpass;
h1 = design(f,'ellip','FilterStructure','df1sos','SOSScaleNorm','l1');
s = dspopts.sosview;
s.view = 'Cumulative';
fvtool(h1,'SOSViewSettings',s)
Digital Filters with MATLAB Ricardo A. Losada
A.4 Designing multirate ﬁlters 195
A.4 Designing multirate ﬁlters
To design multirate ﬁlters, select the multirate type, then the interpola
tion/decimation factor(s), then any fdesign singlerate response,
f = fdesign.interpolator(4,'lowpass','N,Fc,Ap,Ast',60,1/4,0.5,75); % Interp by 4
f = fdesign.decimator(2,'halfband','TW,Ast',0.1,95); % Decim by 2
f = fdesign.rsrc(3,5,'nyquist',5,'TW,Ast',0.05,80); % Up=3 Down=5
After the speciﬁcations are set, the usual commands are available: design,
designmethods, designoptions, etc.
The cost command takes into account the polyphase savings of multi
rate ﬁlters:
f1 = fdesign.interpolator(15,'lowpass','Fp,Fst,Ap,Ast',...
1/150.01,1/15+0.01,1,80);
h1 = design(f1,'multistage'); % Results in 2 stages
cost(h1) % Compare to a singlestage design: design(f1,'equiripple');
f2 = fdesign.decimator(8,'nyquist',8,'TW,Ast',0.03,80);
h2 = design(f2,'multistage'); % Result in 3 stages
cost(h2) % Compare to a singlestage design: design(f1,'kaiserwin');
% When applicable, the use of IIR halfbands results in huge implementation savings
% The implementation uses allpassbased polyphase branches
h3 = design(f2,'multistage','HalfbandDesignMethod','iirlinphase');
cost(h3) % If linear phase is not an issue, ellip halfbands would be even better
A.5 Converting to ﬁxed point
In order to convert a design to ﬁxed point, set the Arithmetic property,
h.Arithmetic = 'fixed';
or
set(h,'Arithmetic','fixed');
By default, the coefﬁcients are quantized to 16 bits with automatic scal
ing, and, for FIR ﬁlters, the ﬁlter internals (additions and multiplications)
are set in a such way that no loss of precision occurs (socalled “full pre
cision”). The input signal to the ﬁlter is assumed to be a signal quantized
Digital Filters with MATLAB Ricardo A. Losada
196 Summary of relevant ﬁlter design commands
with 16 bits and covering the range [−1, 1). The LSB is scaled by 2
−15
.
(Two’scomplement is assumed for all ﬁxedpoint quantities.)
Coefﬁcient quantization affects the frequency (and time) response of
the ﬁlter. This is reﬂected in fvtool and measure,
f = fdesign.decimator(2,'Halfband','TW,Ast',0.01,80);
h = design(f,'equiripple');
fvtool(h)
measure(h)
% Compare to
h.Arithmetic = 'fixed';
fvtool(h)
measure(h)
For FIRﬁlters, in order to change ﬁxedpoint settings for the output and/or
additions/multiplications within the ﬁlter, change the ﬁlter internals ﬁrst
∗
,
h.FilterInternals = 'SpecifyPrecision'
For example to view the effect solely due to the use of a smaller number
of bits for the output of a ﬁlter, one could write something like,
x = randn(1000,1); % Create a random input
xn = x/norm(x,inf); % Normalize to the range [1,1]
xq = fi(xn,true,16,15); % Quantize to 16 bits. Cover the range [1,1)
f = fdesign.decimator(2,'Halfband','TW,Ast',0.01,80);
h = design(f,'equiripple','StopbandShape','linear','StopbandDecay',40);
h.Arithmetic = 'fixed';
yfull = filter(h,xq); % Full precision output (33 bits)
h.FilterInternals = 'SpecifyPrecision';
h.OutputWordLength = 16;
h.OutputFracLength = 13;
y16 = filter(h,xq); % 16bit output
plot(double(yfully16)) % Plot the difference due to output quantization
∗
The LSB scaling for any ﬁxedpoint quantity can be changed by setting the appro
priate “FracLength” parameter. Note that this quantity is not really a “length” since
it can be greater than the word length or even negative. For example a word length
of 4 bits and a “FracLength” of 8 means the bits (from MSB to LSB) are scaled by
−2
−5
, 2
−6
, 2
−7
, and 2
−8
respectively. (The negative scaling of the MSB is due to the
two’scomplement representation.)
Digital Filters with MATLAB Ricardo A. Losada
A.6 Generating Simulink blocks 197
There are a couple of commands that can come in handy for analysis
when converting ﬁlters from ﬂoating point to ﬁxed point: double, and
reffilter,
f = fdesign.decimator(2,'Halfband','TW,Ast',0.01,80);
h = design(f,'equiripple');
h.Arithmetic = 'fixed';
hd = double(h); % Cast filter arithmetic to double. Use quantized coeffs
hr = reffilter(h); % Get reference doubleprecision floatingpoint filter
The difference between hd and hr lies in the ﬁlter coefﬁcients. The refer
ence ﬁlter, hr, has the original “ideal” doubleprecision coefﬁcients, while
the castedtodouble ﬁlter, hd, has a casted version of the quantized coefﬁ
cients.
These functions can be used to compare what we ideally would like to
compute, with the best we can hope to compute
∗
, and with what we can
actually compute. Continuing with the previous two examples:
yr = filter(hr,xq); % What we would ideally like to compute
yd = filter(hd,xq); % Best we can hope to compute. Same as yfull
plot(double([yryd,yry16]))
A.6 Generating Simulink blocks
There are two commands that can be used to generate blocks fromﬂoating
point or ﬁxedpoint ﬁlters: block() and realizemdl():
f = fdesign.hilbert('N,TW',122,0.1);
h = design(f);
block(h)
f = fdesign.decimator(2,'halfband','TW,Ast',0.05,75);
h = design(f,'iirlinphase','FilterStructure','cascadeallpass');
realizemdl(h)
The difference between them is that block will use the Digital Filter block
(or one of the multirate blocks) from the Signal Processing Blockset while
∗
For FIR ﬁlters with multiplications/accumulations computed with more than 53 bits,
the best one can hope to compute should be determined with fullprecision ﬁxedpoint
ﬁltering rather than casting to doubleprecision ﬂoating point.
Digital Filters with MATLAB Ricardo A. Losada
198 Summary of relevant ﬁlter design commands
realizemdl will build the ﬁlter from scratch using basic elements like
adders/multipliers.
The use of the block command will generally result in faster simula
tion speeds and better code generation. However, realizemdl provides
support for more ﬁlter structures and will permit customization of the re
sulting block diagram (say to reduce the number of bits of some of the
multipliers of a ﬁlter or to rewire the ﬁlter in some way).
A.7 Graphical User Interface
Most of the commands discussed here are available through a GUI:
filterbuilder
Note that to design multirate ﬁlters, you should ﬁrst select the response
(lowpass, halfband, etc) and then set the Filter Type to decimator, etc (if
available).
Once designed (and possibly quantized), the ﬁlter can be saved to the
workspace as an object named with the variable name speciﬁed at the top.
Digital Filters with MATLAB Ricardo A. Losada
Appendix B
Sampling, Downsampling,
Upsampling, and Analog
Reconstruction
This appendix provides a short review of both theoretical and practical is
sues related to sampling of a signal and reconstruction of an analog signal
froma sampled version of it. In general, understanding sampling and ana
log reconstruction is essential in order to understand multirate systems. In
fact, as we will see, sampling an analog signal is just the extreme case of
downsampling a digital signal thereby reducing its sampling rate. Simi
larly, analog reconstruction is just the edge case of increasing the sampling
rate of a signal.
The material presented here is standard in many textbooks
∗
, but there
are a couple of practical issues that are often overlooked and that we wish
to highlight.
First, it is wellknown that in order to avoid aliasing when sampling
it is necessary to sample at least twice as often as the highest frequency
component present. What is somewhat less wellknown is that in lieu of
ideal brickwall antialiasing and reconstructing lowpass ﬁlters, we should
always sample a bit higher than twice the maximum frequency compo
nent. As a rule of thumb, anywhere between 10 and 20 percent higher.
This is done to accommodate for the transition bands in the various ﬁl
ters involved. Moreover, if we oversample by a factor of say two or four
∗
In particular the textbooks [3] and [11] are recommended in addition to the article [35].
200Sampling, Downsampling, Upsampling, and Analog Reconstruction
to ease the burden of the analog antialiasing ﬁlter, we still leave an extra
1020 percent of room even though at this point we would be sampling
anywhere between 4 and 8 times higher than the highest frequency com
ponent.
Moreover, since we know that the information in the excess frequency
bands is of no interest for our application, we allow for aliasing to occur
in this band. This enables us to sample at a rate that, while larger than
twice the frequency of interest, does not need to be as large as twice the
stopbandedge of the antialiasing ﬁlter. Equivalently, this allows for the
transition width of the antialiasing ﬁlter to be twice as large (resulting a
simpler, lowerorder ﬁlter) than what it would be if did not permit aliasing
in the excess frequency bands.
As an example consider an audio signal. The frequency range of inter
est is 0 to 20 kHz. Ideally we would bandlimit the analog signal exactly to
20 kHz prior to sampling with an antialias analog ﬁlter. We would then
sample at 40 kHz. Subsequently, in order to reconstruct the analog signal
from the samples, we would use a perfect lowpass analog ﬁlter with a cut
off frequency of 20 kHz that removes all spectral replicas introduced by
sampling. In reality, we bandlimit the signal with an analog antialiasing
ﬁlter whose passband extends to 20 kHz but whose stopband goes be
yond 20 kHz by about 20 to 40 percent. Typical sampling rates for audio
are 44.1 kHz or 48 kHz, meaning that we have an excess bandwidth of
about 10 to 20 percent. The stopbandedge of the antialiasing ﬁlter will
be at about 24.1 kHz or 28 kHz respectively. These would also be the max
imum frequency components of the audio signal that is bandlimited with
such antialias ﬁlter. Since we don’t quite sample at twice the maximum
frequency components, aliasing occurs. However, aliasing will only occur
in the excess frequency band, 20 kHz to 22.05 kHz or 20 kHz to 24 kHz
depending on the sampling frequency.
Other sampling rates used for audio are 88.2 kHz, 96 kHz, 176.4 kHz,
and 192 kHz. These sampling rates correspond to 2x or 4x oversampling,
but the important thing is that they still include an extra 10 to 20 percent
cushion in addition to the 2x or 4x oversampling.
The second issue we wish to highlight is that when choosing the stop
band edge frequency for a decimation ﬁlter we can in many cases allow
for transitionband overlap (i.e. aliasing in the transition band). This issue
is related to the excess bandwidth resulting from the 10 to 20 percent over
sampling that we have just mentioned and it is the reason the extra 10 to
Digital Filters with MATLAB Ricardo A. Losada
B.1 Sampling an analog signal 201
20 percent is still present even if there is an oversampling of 2x or 4x.
Allowing for transitionband overlap (aliasing in the excess frequency
bands) when decimating means that the cutoff frequency (not the stopband
edge frequency) for the decimation ﬁlter can be selected as π/M where M
is the decimation factor. This in turn means that efﬁcient Nyquist ﬁlters
can be used for decimation. In particular, very efﬁcient halfband ﬁlters
can be used when decimating by a factor of two.
We will elaborate on all this in §B.5.
B.1 Sampling an analog signal
We will provide only a brief overview of sampling. For a complete treat
ment of the subject see [35]. Sampling is also covered in any signal pro
cessing textbook (see e.g. [3]).
Consider an analog signal x
a
(t) with Fourier transformX
a
( f ) also called
its spectrum or frequency response,
X
a
( f ) =
∞
−∞
x
a
(t)e
−2πj f
dt.
If we construct a sampled signal x
s
(t) from the original signal x
a
(t) in
the following way:
x
s
(t) =
∞
∑
n=−∞
x
a
(nT)δ(t −nT)
The spectrum of the sampled signal, X
s
( f ) is related to the spectrum of
the original signal by the Poisson summation formula,
X
s
( f ) =
1
T
∞
∑
k=−∞
X
a
( f −k f
s
) (B.1)
where f
s
= 1/T is the sampling frequency.
Note that the sampled signal x
s
(t) is still an analog signal in the sense
that it is a function of the continuoustime variable t. Therefore, its spec
trum is still given by the continuoustime Fourier transform,
X
s
( f ) =
∞
−∞
x
s
(t)e
−2πj f
dt.
Digital Filters with MATLAB Ricardo A. Losada
202Sampling, Downsampling, Upsampling, and Analog Reconstruction
However, if we form the discretetime sequence
x[n] = {x
a
(nT)} ∀n,
that is, we form a sequence by recording the value of the analog signal
x
a
(t) at each multiple of T, we can determine the continuoustime Fourier
transform of x
s
(t) by computing the discretetime Fourier transform of
x[n],
X
s
( f ) = X( f ) =
∞
∑
n=−∞
x[n]e
−2πj f nT
.
So even though x
s
(t) and x[n] are conceptually different, they have the
same frequency response.
Eq. (B.1) is valid for any signal x
a
(t) whether bandlimited or not [3].
The terms X
a
( f − k f
s
) are shifted versions of the spectrum of x
a
(t), and
are called spectral replicas. They are centered around multiples of f
s
. This
concept is key to understanding multirate signal processing so we’d like
to emphasize it. Any sampled signal has spectral replicas centered around
multiples of its sampling frequency. The higher the sampling frequency,
the further apart the spectral replicas will lie.
In general, when we form the sum of all the spectral replicas as in Eq.
(B.1), the replicas will interfere with each other due to frequency overlap
ping. This interference is called aliasing. However, if the signal is ban
dlimited in such a way that only one replica has a nonzero value for any
given frequency, then the replicas will not overlap and they will not inter
fere with each other when we add them as in Eq. (B.1).
Obviously if X
a
( f ) = 0 ∀f , the replicas will invariably overlap. How
ever, if x
a
(t) is bandlimited, i.e. its spectrum is equal to zero for all fre
quencies above a certain threshold and all frequencies below a certain
threshold, then by spreading the replicas enough apart from each other,
i.e. choosing a large enough value for f
s
, the replicas will not overlap
thereby avoiding aliasing.
It is easy to see that if the analog signal’s spectrum satisﬁes
X
a
( f ) = 0,  f  >
f
s
2
(B.2)
then the replicas will not overlap. Aliasing will thus be avoided if the
sampling frequency is at least equal to the twosided bandwidth.
Digital Filters with MATLAB Ricardo A. Losada
B.1 Sampling an analog signal 203
Figure B.1: Spectrum of bandlimited analog signal with maximum frequency given by
f
s
/2.
Figure B.2: Spectrum of sampled signal with maximum frequency given by f
s
/2.
Figure B.1 shows the magnitude spectrum of an example of an analog
signal that satisﬁes Eq. (B.2). This case corresponds to the best known
case, i.e. f
max
= f
s
/2 and f
min
= −f
s
/2. The twosided bandwidth, B
x
, is
simply B
x
= f
max
− f
min
= 2f
max
= f
s
.
If the analog signal is not bandlimited, we must make it so by lowpass
ﬁltering the signal with an analog ﬁlter prior to sampling. Such ﬁlter is
called an antialias ﬁlter for obvious reasons and its cutoff frequency must
be chosen such that it allows all frequencies we are interested in for a given
application to pass.
A critically sampled spectrum, i.e. one in which the sampling fre
quency is exactly equal to the twosided bandwidth is shown in Figure
B.2. The spectral replicas are adjacent to each other but do not overlap. If
we were to oversample the signal, that is if we choose f
′
s
>B
x
, the sampled
spectrum would be something like what is depicted in Figure B.3. Notice
the “whitespace” between replicas due to oversampling.
Digital Filters with MATLAB Ricardo A. Losada
204Sampling, Downsampling, Upsampling, and Analog Reconstruction
Figure B.3: Spectrum of an oversampled signal.
Figure B.4: Continuoustime signal with bandpass spectrum.
The interval [−f
s
/2, f
s
/2] is called the Nyquist interval. Since f
s
deter
mines the number of samples per second, when comparing two Nyquist
intervals of different size, it is useful not only to realize that one encom
passes a larger range of frequencies than the other, but also that it involves
a larger amount of samples. Therefore, in general, any digital processing
performed on a signal on a larger Nyquist interval requires more com
putation than comparable signal processing performed on a signal that
occupies a smaller Nyquist interval. This means that we generally want
to avoid oversampling (i.e. avoid whitespace in the spectrum). However,
oversampling can be useful in some particular cases.
The spectral replicas that appear in a sampled signal make the signal
periodic in the frequency domain. This periodicity means that any opera
tion performed on a signal within the Nyquist interval will automatically
happen in all spectral replicas as well. We can take advantage of this fact
to efﬁciently process analog bandpass signal as is explained next.
Digital Filters with MATLAB Ricardo A. Losada
B.1 Sampling an analog signal 205
Figure B.5: Spectrum of sampled bandpass signal with f
s
= 2f
c2
.
B.1.1 Bandpass sampling
Now consider the sampling of the bandpass signal depicted in Figure B.4.
If we were to sample at f
s
= f
max
− f
min
= 2f
c2
the resulting signal would
have the spectrum shown in Figure B.5. The whitespace between replicas
tells us that the signal has been oversampled. In fact, for this signal we
can sample at a much lower rate as depicted in Figure B.6 and still avoid
aliasing.
Notice that by sampling at f
s
= 2f
c1
instead of at f
s
= 2f
c2
we have
effectively moved the bandpass spectrum to baseband. The Nyquist inter
val being smaller, [−f
c1
, f
c1
] rather than [−f
c2
, f
c2
], means that if we want
to modify the signal in some way through signal processing algorithms it
will require less computation to do so than if we had sampled at f
s
= 2f
c2
.
Because of the periodicity of the spectrum, the processing we performed
at baseband is replicated in the bandpass replicas.
Notice that we have made some assumptions in order for bandpass
sampling to work. We have assumed that f
c1
= f
c2
− f
c1
so that when we
sample at f
s
= 2f
c1
, all spectral replicas align nicely without overlapping.
This will happen for any f
s
such that f
s
= 2k( f
c2
− f c1), where k is some
positive integer. Nevertheless, aliasing may occur if we choose some other
sampling frequency even if it is larger than the minimal f
s
that can be
chosen to avoid aliasing.
Digital Filters with MATLAB Ricardo A. Losada
206Sampling, Downsampling, Upsampling, and Analog Reconstruction
Figure B.6: Spectrum of sampled bandpass signal with f
s
= 2f
c1
.
B.2 Sampling a discretetime signal: downsam
pling
We have seen that sampling an analog signal results in spectral replicas
and possible aliasing if the sampling frequency is not large enough.
We now move on to explore what happens when we sample a signal
that is already sampled, i.e. a discretetime signal. More precisely, given a
sequence x[n], we downsample the sequence by a factor of M, where M is
a positive integer. In other words, we form the sequence x
d
[n] by keeping
one out of every M samples of x[n],
x
d
[n] = x[Mn].
We will see that just as sampling an analog signal results in spectral
replication, sampling a discretetime signal x[n] results in its spectrum,
X( f ), being replicated as well. The replicas of X( f ) are centered at multi
ples of the sampling frequency of the downsampled signal.
Just as with sampling, the spectral replicas that form the spectrum
of a downsampled signal will overlap in general and generate aliasing
when added together. However, once again just as with sampling, if the
twosided bandwidth is less or equal to the downsampled rate (within a
Nyquist interval), the spectral replicas do not overlap and no aliasing oc
curs.
The fact that aliasing may occur when downsampling should be ob
vious. After all, if x[n] was sampled at a frequency just high enough to
avoid aliasing, throwing out M −1 out of every M samples is equivalent
Digital Filters with MATLAB Ricardo A. Losada
B.2 Sampling a discretetime signal: downsampling 207
Figure B.7: Critically sampled signal.
Figure B.8: Three times oversampled signal.
to having sampled the analog signal at a frequency M times lower than
what is required to avoid aliasing. On the other hand, if x[n] has been
oversampled by at least a factor of M, then no aliasing should occur when
downsampling.
In order to derive the relation between the spectra, consider two sam
pled versions of x
a
(t). In one case, we sample with a sampling frequency
f
s
=1/T, x
d
[n] ={x
a
(nT)}, while in the other case we sample with a sam
pling frequency f
′
s
= Mf
s
= 1/T
′
= M/T, x[n] = {x
a
(nT
′
)}.
For illustration purposes, assume (without loss of generality) that f
s
corresponds to the critically sampled case so that all spectral replicas are
adjacent to each other. The signal x[n] is oversampled by a factor M.
As an example assume M = 3. The spectrum of x
d
[n], X
d
( f ), would be
something like that shown in Figure B.7. The spectrum of x[n], X( f ), has
the same baseband replica, but the remaining replicas are centered around
multiples of f
′
s
as shown in Figure B.8.
In order to construct X
d
( f ) from X( f ), we add X( f ) with two shifted
versions of it, X( f − f
s
) and X( f −2f
s
). The resulting spectrum is shown
in Figure B.9.
Of course we can also show this formally for any value of M through
Digital Filters with MATLAB Ricardo A. Losada
208Sampling, Downsampling, Upsampling, and Analog Reconstruction
Figure B.9: Spectrum resulting from downsampling an oversampled signal.
the use of the Poisson summation formula. We know that
X
d
( f ) =
1
T
∞
∑
k=−∞
X
a
( f −k f
s
)
and
X( f ) =
1
T
′
∞
∑
k=−∞
X
a
( f −k f
′
s
)
after some algebraic manipulation, we can arrive at the discrete version of
the Poisson summation formula,
X
d
( f ) =
1
M
M−1
∑
k=0
X( f −k f
s
). (B.3)
Note the scaling factor 1/M. When we downsample a signal, the base
band replica retains the same shape (hence the same information) as long
as no aliasing occurs. However, all replicas are scaled down by the down
sampling factor.
B.2.1 Filtering to avoid aliasing when downsampling
If the bandwidth of the signal x[n] is larger than 1/M times the Nyquist
interval, aliasing will occur if such signal is downsampled by a factor of M.
In order to avoid aliasing, a standard result in multirate signal processing
is to pass the signal x[n] through a lowpass ﬁlter prior to downsampling.
The role of this ﬁlter is akin to that of the analog antialias ﬁlter used to
bandlimit an analog signal prior to sampling. The cutoff frequency for the
ﬁlter should be π/M.
Digital Filters with MATLAB Ricardo A. Losada
B.3 Increasing the sampling rate of a signal 209
While this result is correct, reversing the thinking on this is perhaps
more useful and sometimes overlooked. By ﬁltering a signal in a way
that its bandwidth is reduced we are basically acknowledging that we no
longer are interested in part of its bandwidth (more precisely in the in
formation contained therein). Therefore, if we reduce the bandwidth of a
signal by a factor of M, we should reduce its sampling rate accordingly
in order to reduce the size of the Nyquist interval. The point is we want
to eliminate whitespace in the spectrum since we know that whitespace
is akin to an oversampled signal and the larger Nyquist interval that goes
with an oversampled signal implies extra (unnecessary) computation.
The distinction is subtle but important. We are used to thinking: “I
need to downsample therefore I should ﬁlter ﬁrst”. That’s ﬁne, but we
should also think: “I have reduced the bandwidth of a signal therefore I
should downsample”. In fact, as we will see in Chapter 4, we should do
this even if the factor by which we reduce the bandwidth is not an integer.
B.2.2 Downsampling bandpass signals
Just as with sampling, under certain conditions it is possible to downsam
ple a bandpass signal and avoid aliasing. If the signal is not bandpass
already, we can ﬁlter it with a bandpass ﬁlter that reduces the bandwidth
to 1/M times the Nyquist interval and then downsample it as long as the
passband of the resulting signal lies in one of the intervals
kπ/M< ω < (k +1)π/M k = 0, 1, . . . , M−1.
The downsampling will cause the bandpass spectrum to be moved to
baseband. This is a useful technique that allows a spectrum to be trans
lated in frequency without the need for any multiplications. Without down
sampling, it would be necessary to multiply the bandpass signal by a si
nusoid if we wanted to translate its spectrum to baseband.
B.3 Increasing the sampling rate of a signal
We have seen that sampling the same analog signal at two different rates
produces the same baseband spectrumplus replicas centered around mul
tiples of the sampling frequency. Figure B.7 shows the spectrum of a crit
Digital Filters with MATLAB Ricardo A. Losada
210Sampling, Downsampling, Upsampling, and Analog Reconstruction
ically sampled signal, while Figure B.8 shows the spectrum of the same
signal oversampled.
In those ﬁgures, the oversampling factor is 3, but the general principle
applies to any integer oversampling factor L. The question is how to in
crease the sampling rate of a signal without converting the signal back to
the analog domain and resampling at a higher rate.
Increasing the sampling rate is just a digital lowpass ﬁltering problem.
The ﬁlter must keep the baseband spectrum and all replicas of Figure B.8,
but remove all remaining replicas, i.e. for the case of 3x oversampling,
remove all replicas in Figure B.7 that are not in Figure B.8.
In order to do so, the lowpass digital ﬁlter needs to operate at the high
sampling rate so that it has replicas of its own centered around multiples
of the high sampling rate that will preserve the sampled replicas at such
frequencies.
It is wellknow that the cutoff frequency for the lowpass ﬁlter should
be π/L. However, rather than memorizing that formula it is helpful to
realize that the cutoff frequency must be selected in such a way that no in
formation is lost. This should be obvious since we are trying to reconstruct
samples from the analog signal based on the samples we have. Therefore,
the baseband spectrum must be left untouched. The lowpass ﬁlter must
remove the L −1 adjacent replicas.
The (ideal) lowpass ﬁlter speciﬁcations used to increase the sampling
rate by a factor L are thus,
H( f ) =
L if  f  ≤ f
s
/2,
0 if f
s
/2 <  f  ≤ Lf
s
/2.
(B.4)
where f
s
is the sampling rate before we increase the rate and Lf
s
is the
sampling rate that results after increasing the rate. The gain of L in the
passband of the ﬁlter is necessary since as we saw the spectrum of the
lowrate signal has a gain that is L times smaller than that of the highrate
signal.
The frequency response of the ﬁlter used to increase the sampling rate
by a factor L = 5 is shown in Figure B.10. The ﬁlter removes L −1 spec
tral replicas between the replicas centered around multiples of the high
sampling rate Lf
s
.
Digital Filters with MATLAB Ricardo A. Losada
B.4 Reconstructing an analog signal 211
Figure B.10: Frequency response of ﬁlter used to increase the sampling rate by a factor
L = 5.
B.4 Reconstructing an analog signal
Once signal processing algorithms have been performed on a sampled sig
nal in order to modify it in some desired way, it may be necessary to re
construct the analog signal corresponding to the samples at hand.
Just as with increasing the sampling rate of a signal, the mechanism to
reconstruct an analog signal is obvious if we look at the situation in the
frequencydomain. We’d like to take X( f ), the spectrum of the sampled
signal x[n], and obtain X
a
( f ), the spectrum of the bandlimited analog
signal x
a
(t). Since
X( f ) = X
s
( f ) =
1
T
∞
∑
k=−∞
X
a
( f −k f
s
).
In the most common case, we need to remove all the replicas, X
a
( f −
k f
s
), k = 0 and only retain the baseband spectrum X
a
( f ). However, if we
sampled a bandpass signal, and we wish to reconstruct it, we would want
to retain a replica for k = 0 instead.
In order to retain the baseband spectrum, we need a lowpass ﬁlter. The
lowpass ﬁlter must be analog in order for it to not have spectral replicas
of its own and thus be able to remove replicas centered at arbitrarily large
multiples of f
s
.
The role of the lowpass ﬁlter H( f ) is depicted in Figure B.11. Its speci
ﬁcations are
H( f ) =
T if  f  ≤ f
s
/2,
0 otherwise.
(B.5)
Digital Filters with MATLAB Ricardo A. Losada
212Sampling, Downsampling, Upsampling, and Analog Reconstruction
Figure B.11: Spectral characteristics of lowpass ﬁlter used for analog reconstruction.
B.5 Practical sampling and analog reconstruction
The fact that we can reconstruct a bandlimited analog signal fromits sam
ples provided we sample the signal frequently enough leads us to con
clude that no information is lost when we sample the signal in such man
ner. However, a truly bandlimited signal requires a ﬁlter with inﬁnite at
tenuation in its stopband. Moreover, the signal must be of inﬁnite length
in order to have a ﬁnite frequency spectrum, so even if could construct a
ﬁlter with inﬁnite attenuation, it would not be enough to obtain a truly
bandlimited signal. In reality there is always some degree of aliasing in
troduced when sampling.
Nevertheless, let us assume that we had a perfectly bandlimited ana
log signal that we have sampled in such a way that no aliasing occurs. In
order to reconstruct the analog signal, we would require an ideal lowpass
ﬁlter with inﬁnite attenuation and a perfect brickwall response with no
transition gap between passband and stopband.
In reality, both the antialiasing ﬁlter used to bandlimit a signal prior
to sampling and the lowpass ﬁlter used for analog reconstruction have
both a ﬁnite amount of stopband attenuation and a nonzero transition
gap between passband and stopband.
The ﬁnite attenuation can be dealt with by achieving enough attenua
tion so that the degrees of aliasing and distortion are tolerable. In many
cases, oversampling techniques are used so digital ﬁlters provide some of
the burden of attenuating the unwanted frequency components. Different
applications may require different attenuation levels.
In order to deal with the nonzero transition of the ﬁlters, excess band
width is required. In other words, in practice, instead of sampling at twice
the largest frequency of interest, we give ourselves some extra room by
Digital Filters with MATLAB Ricardo A. Losada
B.5 Practical sampling and analog reconstruction 213
Figure B.12: Practical sampling with excess bandwidth.
sampling at a slightly larger rate. The idea is illustrated in Figure B.12.
The upper graph in the Figure shows the analog spectrum X
a
( f ) after
the analog signal has been ﬁltered with an analog antialiasing preﬁlter.
The antialias ﬁlter has a passband that coincides with the band of interest.
Since the ﬁlter is nonideal, it has a transition band that extends beyond
the band of interest. The further we can push out the transition band,
the easier it is to construct the analog preﬁlter (a lower order is required,
which in turn means fewer analog components). Notice that the sampling
frequency is not selected to be twice the stopbandedge of the antialias
preﬁlter, f
max
. It is selected to be twice the frequency that lies in the mid
point between the maximum frequency of interest and f
max
. As a result,
sampling introduces aliasing in the excess frequency band. However, the
aliasing does not corrupt any of the frequencies of interest. The magnitude
spectrumof the signal sampled in the way just described, X( f ), is shown
in the lower graph of Figure B.12.
The reason we select the sampling frequency in such a way that aliasing
occurs in the excess bandwidth region is that we would like to keep the
sampling frequency as low as possible. This is because we will have a
smaller number of samples to deal with. Any signal processing algorithms
Digital Filters with MATLAB Ricardo A. Losada
214Sampling, Downsampling, Upsampling, and Analog Reconstruction
performed on the sampled signal will be less computationally intensive as
a result of having fewer samples.
Once the signal needs to be converted back to the analog domain, a
lowpass analog reconstruction ﬁlter is needed. The design of this ﬁlter also
takes advantage of the excess bandwidth available. Figure B.13 shows the
requirements for a reconstruction ﬁlter. The ﬁlter takes the sampled signal
with magnitude spectrum X( f ), and reconstructs the analog signal with
magnitude spectrum X
a
( f ) by removing all spectral replicas. As with
the antialias preﬁlter, the passband of the reconstruction ﬁlter should ex
tend up to the highest frequency of interest. The transition band require
ments will depend on how harmful the frequencies present in the excess
bandwidth are for the application at hand. If necessary, the frequencies
between the band of interest and f
s
/2 can be attenuated digitally with a
digital lowpass ﬁlter prior to analog reconstruction. This would allow a
larger transition region for the reconstruction ﬁlter, making it simpler to
build.
Although we won’t get into details, it is worth noting that the recon
struction ﬁlter is usually built in two stages. The ﬁrst stage is usually a
simple staircase reconstruction that converts the signal to analog by hold
ing each sample’s value until the next sample. This simple ﬁlter has a
poor lowpass response that allows for some highfrequency components
to remain. These high frequency components are removed by the second
stage ﬁlter. Increasing the sampling rate of the signal digitally prior to re
construction further eases the job required by the reconstruction ﬁlter. We
will discuss this next.
B.5.1 Oversampling
As we pointed out in the precious section, the further we can push out the
stopbandedge frequency of the antialias analog ﬁlter, the easier it is for
such ﬁlter to be built. The idea can be extended to 2x or 4x oversampling
(or more). In such cases, the stopbandedge can be pushed out all the way
to two times or four times the maximumfrequency of interest plus an extra
10 to 20 percent cushion.
There are two main consequences to doing this. First, since we over
sample, we have more samples to deal with than we’d like. Usually we
avoid having more samples than necessary, but in this case we purposely
Digital Filters with MATLAB Ricardo A. Losada
B.5 Practical sampling and analog reconstruction 215
Figure B.13: Practical reconstruction with excess bandwidth.
generate more samples in order to simplify the antialiasing ﬁlter. Second,
since the antialias ﬁlter has a transition band that extends all the way to
twice or more the band of interest, there is poor out of band attenuation,
i.e. many undesired frequencies are present.
In order to deal with both of these issues, we use a combination of
digital lowpass ﬁltering plus downsampling. The ﬁltering takes care of
the poor out of band attenuation and allows for the downsampling to oc
cur without aliasing corrupting the band of interest. Aliasing does occur
when downsampling, but it is limited to the transition band of the digital
ﬁlter, which overlaps with its spectral replicas. The whole idea is illus
trated for the case 2x oversampling in Figure B.14. For this 2x case, the
digital ﬁltering can be performed with a very efﬁcient halfband ﬁlter. The
magnitude spectrum X( f ) shown in the Figure corresponds to the over
sampled signal. The digitallowpassﬁltered signal’s spectrum is labeled
X
′
( f ), while the downsampled signal’s spectrum is labeled X
d
( f ). The
implementation of the digital ﬁltering and downsampling is always done
in an efﬁcient manner (polyphase or otherwise) as explained in Chapter
4. Note that the spectrum X
′
( f ) is conceptual since in practice we do
not ﬁlter ﬁrst and then downsample (that would be wasteful). It is shown
for illustration purposes. In reality we go directly from X( f ) to X
d
( f )
Digital Filters with MATLAB Ricardo A. Losada
216Sampling, Downsampling, Upsampling, and Analog Reconstruction
Figure B.14: Illustration of 2x oversampling plus decimation.
using an efﬁcient decimation ﬁlter.
As we just saw, oversampling eases the job of the antialiasing ana
log preﬁlter by placing some of the burden on the ﬁlter used for decima
tion. Similarly, increasing the sampling rate can be used to ease the job of
the analog reconstruction ﬁlter when we are performing digital to analog
conversion. The idea is completely analogous to that of oversampling in
analog to digital conversion. The burden of removing spectral replicas is
shared between the digital ﬁlter used for increasing the sampling rate and
the analog reconstruction ﬁlter.
The digital ﬁlter removes the adjacent replicas. If the sampling rate
is increased by a factor of L, the ﬁlter removes L − 1 adjacent replicas.
The analog reconstruction ﬁlter has to removed the remaining replicas that
cannot be removed by the digital ﬁlter. Nevertheless, since the adjacent
replicas have been removed, this allows for a wide transition width for the
Digital Filters with MATLAB Ricardo A. Losada
B.5 Practical sampling and analog reconstruction 217
Figure B.15: Analog reconstruction by ﬁrst increasing the samplingrate by a factor of
L = 2.
analog reconstruction ﬁlter which, once again, enables us to use a simple
loworder ﬁlter that is easy (and cheap) to build.
The situation for the case L = 2 is illustrated in Figure B.15. X
d
( f )
represents the magnitude spectrum of the digital signal we wish to con
vert to analog. This signal has been sampled (possibly downsampled as
well) in such a way that the excess bandwidth overlaps with the replicas
as previously discussed. Y( f ) represents an optional step. Depending
on the application, we may need to ﬁlter some of the components in the
band outside of the band of interest. This should be done at the lowest
rate possible so that the transition width relative to the sampling rate is
as large as possible (lowering the order required for the ﬁlter). Next, we
increase the sampling rate by two. The magnitude response of the ﬁlter
used to remove the adjacent replicas is shown by the dashed line. Note
that this ﬁlter also attenuates components out of the band of interest. It
Digital Filters with MATLAB Ricardo A. Losada
218Sampling, Downsampling, Upsampling, and Analog Reconstruction
can be designed so that it does all the work done to get Y( f ) in addi
tion to removing spectral replicas in one step. The resulting magnitude
spectrum of the upsampled signal is represented by Y
u
( f ). The remains
spectral replicas are now widely separated so that an analog reconstruc
tion ﬁlter with a wide transition band can be used for the ﬁnal digital to
analog conversion.
As mentioned before, the analog reconstruction ﬁlter is usually built
in two stages. The staircase reconstruction ﬁlter causes some distortion
in the band of interest. The more we increase the sampling rate prior to
reconstruction, the less the distortion. If necessary, the distortion can be
compensated for by preequalizing the signal digitally prior to sending it
through the staircase reconstructor. To do so, the ﬁlter used for increasing
the rate is designed in such a way that it boosts the signal over a part of
the band of interest that will be attenuated by the staircase reconstructor.
Finally, we mention that in practice noiseshaping sigmadelta quan
tizers are usually used in conjunction with the techniques outlined here in
order to reduce the number of bits required to represent the signal at high
sampling rates. The noiseshaping allows for the use of a smaller number
of bits without decreasing the signaltonoise ratio.
Digital Filters with MATLAB Ricardo A. Losada
Appendix C
Case Study: Comparison of
Various Design Approaches
Consider the following lowpass specs:
1. Cutoff frequency: 3.125 MHz
2. Transition width: 0.4 MHz
3. Maximum passband ripple: 1 dB
4. Minimum stopband attenuation: 80 dB
5. Input sampling frequency: 100 MHz
The table below compares the implementation cost of various single
rate designs. The following command is used for the speciﬁcations:
Fs = 100e6;
TW = 0.4e6;
Fp = 3.125e6  TW/2;
Fst = 3.125e6 + TW/2;
Ap = 1;
Ast = 80;
Hf = fdesign.lowpass(Fp,Fst,Ap,Ast,Fs);
220 Case Study: Comparison of Various Design Approaches
NMult NAdd Nstates MPIS APIS NStages Decim. Fact
ellip 20 20 10 20 20 1 N/A
equiripple 642 641 641 642 641 1 N/A
IFIR 138 136 759 138 136 2 N/A
IFIR JO 115 113 680 115 113 2 N/A
IFIR JO denotes that the joint optimization option is used with the IFIR
design. See Chapter 5 for more on this.
Next, we compare 3 designs that include decimation by a factor of 15.
The following command sets the specs.:
Hf = fdesign.decimator(15,'lowpass',Fp,Fst,Ap,Ast,Fs);
NMult NAdd Nstates MPIS APIS NStages Decim. Fact
equiripple 642 641 630 42.8 42.7333 1 15
IFIR JO 224 222 216 17.333 16.933 2 15
multistage 169 167 161 14.6 14.3333 2 15
Finally, we compare one CICmultistage design and 3 multistage Nyquist
designs. This line is used to set the specs for the Nyquist designs:
Hf = fdesign.decimator(16,'nyquist',16,TW,Ast,Fs);
For the CIC design, we break it down in 3 stages. The ﬁrst stage, which
is the CIC decimator, will provide a decimation of 4. The next stage, the
CIC compensator, will provide decimation of 2. The ﬁnal stage will be a
regular halfband, also providing decimation by 2.
The code is as follows:
% CIC decimator design
M1 = 4;
D = 1; % Differential delay
Hf1 = fdesign.decimator(M1,'cic',D,Fp,Ast,Fs);
Hcic = design(Hf1,'multisection');
% CIC compensator design
M2 = 2;
Nsecs = Hcic.NumberOfSections;
Hf2 = fdesign.decimator(M2,'ciccomp',D,...
Nsecs,Fp,Fs/(M1*M2)FpTW,Ap,Ast,Fs/M1);
Hcomp = design(Hf2,'equiripple');
Digital Filters with MATLAB Ricardo A. Losada
221
% Halfband design
M3 = 2;
Hf3 = fdesign.decimator(M3,'halfband',...
TW,Ast,Fs/(M1*M2));
Hhalf = design(Hf3,'equiripple');
Hcas = cascade(Hcic,Hcomp,Hhalf); % Overall design
Specifying the Nyquist band to be 16 implies that the cutoff frequency
is
π
16
which corresponds to the 0.0625π required. This value is almost al
ways set to be the same as the decimation factor.
All Nyquist designs result in a 4stage ﬁlter with halfband decimators
in each stage. Note that the Nyquist designs far exceed the passband rip
ple speciﬁcation (1 dB) even though it is not set explicitly. In the case of
IIR halfbands, the passband ripple is of the order of 10
−8
dB.
NMult NAdd Nstates MPIS APIS NStages Decim. Fact
CIC multistage 86 94 166 6.0625 12.125 3 16
FIR equirip 98 94 180 10.325 9.375 4 16
IIR ellip 14 28 22 2.3125 4.625 4 16
IIR lin phase 37 74 80 3.8125 7.625 4 16
Digital Filters with MATLAB Ricardo A. Losada
Appendix D
Overview of FixedPoint
Arithmetic
Overview
In this appendix we provide a brief overview
∗
of ﬁxedpoint arithmetic
and its implications on digital ﬁlters.
The basic tradeoff that one should understand whenever dealing with
ﬁxedpoint arithmetic is maximizing SNR vs. minimizing the possibility
of overﬂows occurring. As is so often the case, these two requirements are
in opposition to each other and a compromise needs to be reached.
The SNR in this realm refers to signal to quantization noise ratio. The
SNR can be increased in two ways: increasing the signal power by max
imizing the use of the available dynamic range or decreasing the noise
power by using more bits to represent data. Of course, using more bits
is not always an option. Hardware constraints may predetermine how
many bits are available to represent a given quantity.
The issue with increasing the utilization of the available dynamic range
is that a signal can easily overﬂow when some arithmetic is performed on
it.
∗
For a more complete coverage, Chapter 2 of [3] and Chapter 8 of [36] are recommended.
D.1 Some ﬁxedpoint basics 223
D.1 Some ﬁxedpoint basics
Consider a register used to store a ﬁxedpoint number,
b
B−1
. . .
b
2
b
1
b
0
. .. .
B−bits
The register has B bits (it has a wordlength of B), the value of the kth bit
(from right to left) is given by b
k
which can obviously be only 0 or 1. The
bits themselves are not enough to determine the value being held in the
register. For this, we need to deﬁne the scaling of the bits. Speciﬁcally, a
two’s complement ﬁxedpoint number stored in such a register has a value
given by
value = −b
B−1
2
B−1−F
+
B−2
∑
k=0
b
k
2
k−F
(D.1)
where F is a (positive or negative) integer that deﬁnes the scaling of the
bits. F is referred to as a fraction length (or FracLength) but this is some
what of a misnomer. The reason is that F is not necessarily a length (for
instance if F is negative or if F is greater than B). However, when F is
positive and F ≤ B, it will be equal to the number of bits to the right of the
binary point hence the term fraction length.
From (D.1), we can see that the value of a ﬁxedpoint number is deter
mined by assigning weights of the form 2
−m
to each bit. The rightmost bit,
b
0
has the smallest weight, 2
−F
. This bit is called the leastsigniﬁcant bit
(LSB). The leftmost bit, b
B−1
, has the largest weight, 2
B−1−F
, which is why
it is called the mostsigniﬁcant bit (MSB).
Given the bit values, b
k
, the pair {B, F} completely characterizes a ﬁxed
point number, i.e. sufﬁces in determining the value that the bits represent.
D.2 Quantization of signals and SNR
Fixedpoint representation can be used to represent data in any range.
With two’s complement representation, the most negative value that can
be represented is given by the scaling of the MSB. The most positive value
that can be represented is given by the sum of all the weights of all bits
except for the MSB.
Digital Filters with MATLAB Ricardo A. Losada
224 Overview of FixedPoint Arithmetic
Figure D.1:
For example, with 4 bits available and a fraction length of 8 (so that
the scaling of the LSB is 2
−8
and the scaling of the MSB is 2
−5
), the most
negative value that can be represented is −2
−5
and the most positive value
that can be represented is 2
−6
+ 2
−7
+ 2
−8
(which is equal to 2
−5
−2
−8
).
In total, we can represent 2
4
= 16 numbers between −2
−5
and 2
−5
−2
−8
with a resolution or increment of 2
−8
between each number and the next
consecutive one.
In general, the number of values that can be represented within those
limits is given by 2
B
. The step size or increment between the values repre
sented is given by ε =2
−F
. So for a given dynamic range to be covered, the
number of bits determines the granularity (precision) with which we can
represent numbers within that range. The more bits we use, the smaller
the quantization error when we round a value to the nearest representable
value. As the number of bits increases, the SNR increases because the
quantization noise decreases.
Speciﬁcally, consider Figure D.1. The range that is covered is denoted
by R. The quantization step is denoted ε =2
−F
. The number of values that
can be represented is given by 2
B
. There are only two degrees of freedom
in these quantities which are related by
R
2
B
= ε
If we round all values to their nearest representable value, the maxi
mum error introduced by such rounding is given by ε/2. If R is constant,
Digital Filters with MATLAB Ricardo A. Losada
D.2 Quantization of signals and SNR 225
and B increases, then ε and consequently the largest quantization error
decreases.
A simple calculation of SNR when quantizing a signal can be per
formed as follows [3]: If R is fully covered by the signal in question, the
signal strength is R. The quantization error covers the interval [−ε/2, ε/2],
i.e. it has a range of ε, so the SNR is given by
SNR =
R
ε
.
In dB, we have
SNR = 20log
10
R
ε
= 20log
10
(2
B
) = 6.02B
This result is known as the 6 dB/bit rule [3]. The result provides an up
per bound on the achievable SNR when using B bits to cover a given range
R. To achieve this upper bound, it is necessary that the signal being quan
tized can take any value within that range with equal probability. In other
words, it is necessary that the signal behaves like uniformly distributed
white noise over that range.
Example 74 Consider the following quantization of a signal which covers the
range [−1, 1) with equal probability,
x = 2*(rand(10000,1)0.5);
xq = fi(x,true,16,15);
SNR = 10*log10(var(x)/var(xdouble(xq)))
SNR =
96.3942
We use 16 bits to represent the signal and the stepsize is 2
−15
. The SNR we can
achieve is inline with the 6 dBperbit rule.
Consider what would happen if instead of uniform white noise, we
take samples froma Gaussian white noise signal and ensure they fall within
the interval [−1, 1),
x = randn(10000,1);
x = x/norm(x,inf);
xq = fi(x,true,16,15);
Digital Filters with MATLAB Ricardo A. Losada
226 Overview of FixedPoint Arithmetic
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
0
50
100
150
200
250
300
350
x
Histogram of x
Figure D.2: Histogram of a whitenoise signal normalized so that the maximum values
is ±1.
SNR = 10*log10(var(x)/var(xdouble(xq)))
SNR =
89.9794
The SNR is no longer satisfying the 6 dBperbit rule. The reason is that
the signal very rarely takes values close to the largest available range (i.e.
close to 1 or 1). This can easily be veriﬁed by looking at the histogram:
[n,c]=hist(x,100);bar(c,n)
The histogram for the whitenoise case is shown in Figure D.2. On
average the signal strength is not that large, while the quantization error
strength remains the same. In other words, the quantization error can be
equally large (on average) whether x takes a small or a large value. Since
Digital Filters with MATLAB Ricardo A. Losada
D.2 Quantization of signals and SNR 227
x takes small values more often than it take large values, this reduces the
SNR.
Indeed, if we look at the var(x) for the uniform case, it is much larger
than var(x) in the Gaussian case, while var(xdouble(xq)) is the same on
both cases.
While it may seem not so useful to consider white noise examples, it
is worth keeping in mind that many practical signals that are quantized,
such as speech and audio signals, can behave similar to white noise.
In summary, depending on the nature of the signal being quantized,
the achievable SNR will vary. In some cases, depending on whether the
application at hand permits it, it may be preferable to allow for the occa
sional overﬂow with the aim of increasing the SNR on average for a given
signal.
D.2.1 Quantizing impulse responses for FIR ﬁlters
When implementing an FIRﬁlter with ﬁxedpoint arithmetic, the ﬁrst thing
we need to do is quantize the ﬁlter’s coefﬁcients, i.e., its impulse response.
Since the impulse response of most FIRﬁlters has a fewlarge samples
∗
and
many small samples, on average we can’t expect to get the full 6 dB/bit.
In practice we can expect somewhere between 4.5 and 5.5 dB/bit when
quantizing FIR ﬁlter coefﬁcients.
Example 75 Consider the following highpass ﬁlter design:
Hf = fdesign.highpass('Fst,Fp,Ast,Ap',0.5,0.6,80,.5);
Hd = design(Hf,'equiripple');
h = Hd.Numerator; % Get the impulse response
norm(h,inf)
The impulse response is shown in Figure D.3. The largest sample has a magnitude
of 0.434. Therefore, our ﬁxedpoint settings should be such to cover the range
[−0.5, 0.5) since this is the smallest poweroftwo interval that encompasses the
values of the impulse response. This can be accomplished by setting F to be equal
to B.
Now let’s compute the SNR for various values of B and see what SNRs we
get. We will perform the following computation for different values of B:
∗
Typically, the middle sample dominates for linearphase ﬁlters.
Digital Filters with MATLAB Ricardo A. Losada
228 Overview of FixedPoint Arithmetic
0 10 20 30 40 50
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
Samples
A
m
p
l
i
t
u
d
e
Impulse Response
Figure D.3: Impulse response of highpass ﬁlter. The largest coefﬁcient has a magnitude
of 0.434.
B = 8; % change to 10, 12, 16, 18, 24
F = B;
hq = fi(h,true,B,F);
SNR = 10*log10(var(h)/var(hdouble(hq)))
If we divide the SNR by B, for the various values of B shown, we get the following
values of dB/bit: 4.7690, 4.9704, 5.1000, 5.3796, 5.3760, 5.5890.
D.3 Fixedpoint arithmetic
Let’s look at a couple of things to keep in mind when performing addi
tions/multiplications with ﬁxedpoint arithmetic.
D.3.1 Fixedpoint addition
In general, when adding two ﬁxedpoint numbers, in order to avoid round
off error it is necessary to increase the wordlength of the result by one bit.
This is to account for the possibility of a carry resulting from the addition.
Digital Filters with MATLAB Ricardo A. Losada
D.3 Fixedpoint arithmetic 229
For example suppose we want to add two 4bit numbers that fall in the
range [−1, 1), say x
1
= 0.875 and x
2
= 0.75. x
1
has the following binary
representation (with F = 3): 0111. x
2
has 0110 as its binary representation.
The sum of the two is 1.6250. We need to represent it with 5 bits so that
no roundoff error is introduced. The binary representation of the result is
01101. Note that in general because of the possibility that the LSB is equal
to 1, it is not possible to discard the LSB without introducing roundoff
error, hence the bit growth.
Many ﬁlter structures contain a series of additions, one after the other.
However, it is not necessary to increase the wordlength by one bit for ev
ery addition in the ﬁlter in order to avoid roundoff (i.e., in order to have
full precision). If N is the number of additions, it is only necessary to in
crease the wordlength by
∗
G = ⌊log
2
(N)⌋ +1. (D.2)
To see this, consider the addition of several numbers represented with
16bit wordlength and a fraction length of 15. The worst case scenario is
when the actual numbers are the largest possible representable number
for a given format. Consider the largest positive value, 0.99
†
. If we add
two of these numbers, the result will be 1.999. To avoid overﬂow, it is
necessary to cover the range [−2, 2) in order to represent the result. In
order to have no loss of precision, i.e. avoid roundoff, we need to increase
the wordlength to 17 bits (and leave the fraction length ﬁxed at 15). If we
now add 0.99 to the value 1.999 the result is 2.999. Since this value falls
outside the range [−2, 2), we need to further increase the wordlength by
one bit in order to represent the result with no loss of precision. With an
18bit wordlength and a fraction length of 15 we can represent numbers
in the range [−4, 4). If we add 0.99 to the result we had so far, 2.999, we
get 3.999 as an answer. Since this number falls within the representable
range, it is not necessary to add an additional bit in order to represent this
number. The next addition would require another bit to be aggregated,
but the following three additions would not, and so forth.
∗
The operator ⌊·⌋ denotes the largest integer smaller or equal to the value operated on
(i.e. the ﬂoor command in MATLAB).
†
A similar argument can be made by using the
largest negative value.
Digital Filters with MATLAB Ricardo A. Losada
230 Overview of FixedPoint Arithmetic
Treeadder view of multiple additions
An easy way of understanding this log
2
bit growth when adding is to look
at what would happen if we used a treelike structure to implement the
series of additions in a direct form FIR ﬁlter. Figure D.4 shows the case of
adding 4 Bbit numbers together. If we added one bit for every addition,
in order to obtain a fullprecision result, we would need to add 3 bits in
total.
However, as we can see in Figure D.4, we can get a fullprecision result
by adding only 2 rather than 3 bits overall. This takes into the account
the worst possible case, meaning that we need to add 1 bit every time two
numbers are added.
One could say the treeadder view has the log
2
bit growth builtin to
it. The idea still applies when there is not a powerof2 number of values
to be added together. Some branches will be slightly incomplete, but the
required bit growth should still be correctly determined.
Note that the (D.2) holds for the worst case scenario in which the num
bers being added are the of largest possible magnitude. In Chapter 7, we
will see that for FIR ﬁlters, we can reduce the bit growth required to avoid
roundoff by looking at the actual coefﬁcients of the ﬁlter.
D.3.2 Fixedpoint multiplication
Since multiplication is nothing but repeated addition, it should be ex
pected that bitgrowth is required if we want to multiply two numbers
without introducing loss of precision. Just as with addition, the bit growth
is independent of the fraclengths involved.
Let’s look at the worse case scenario if we multiply a number x
1
, repre
sented with B
1
bits, with a number x
2
, represented with B
2
bits. Since the
bit growth is independent of the fraclength, consider the binary digits in
volved. In the worst case, we are multiplying the bits in x
1
times −2
B
2
−1
.
That means that we add (ignore the sign) x
1
to itself 2
B
2
−1
times. Using
(D.2), the bit growth is B
2
bits.
In terms of the fraclength, if x
1
has a fraclength of F
1
and x
2
has a fr
aclengh of F
2
, the LSBs have weights of 2
−F
1
and 2
−F
2
respectively. The
product of the two will of course have a weight of 2
−(F
1
+F
2
)
.
In summary, given two ﬁxedpoint numbers, one with wordlength/fraclength
given by {B
1
, F
1
} and the other with wordlength/fraclength given by {B
2
, F
2
},
Digital Filters with MATLAB Ricardo A. Losada
D.3 Fixedpoint arithmetic 231
Figure D.4: Treeadder view of adding 4 Bbit numbers. Only B +2 bits are needed for
a full precision result.
the product of the two numbers can be represented with no roundoff by
using a wordlength/fraclength of {B
1
+ B
2
, F
1
+ F
2
}.
For example, given a number represented with 16 bits and a fraction
length of 14 and another number represented with 18 bits and a fraction
length of 10, the product of the two numbers can be represented without
loss of precision by using a wordlength of 34 bits and a fraction length of
24.
As is the case with additions, in Chapter 7 we will see that for FIR ﬁl
ters, we can reduce the bit growth required to avoid roundoff when mul
tiplying by looking at the actual coefﬁcients of the ﬁlter.
Digital Filters with MATLAB Ricardo A. Losada
232 Overview of FixedPoint Arithmetic
Figure D.5: Quantization of a signal.
Figure D.6: Statistical model for the quantization of a signal.
D.4 Quantization noise variance
In many cases, a good model for the quantization error is as additive noise
to the signal being quantized [3].
Speciﬁcally, consider the quantization of the signal x[n] as shown in
Figure D.5. The operator Q{·} takes the input signal and produces a quan
tized version of it, Q{x[n]} = x
q
[n].
Statistically, we can model the effect of Q{·} as additive noise signal as
shown in Figure D.6.
Provided that the input signal changes fast enough, the noise signal
itself, e[n], can be modeled as uniformly distributed whitenoise over the
range [−ε/2, ε/2].
∗
The variance of the quantization noise signal can easily
be found to be ε
2
/12 [3].
Reducing the number of bits used to represent a signal
The results we have presented so far apply to quantizing an analog signal
in order for it to be represented with ﬁxedpoint. This is of course impor
tant when one is considering analogtodigital conversion.
In digital ﬁlters, we don’t worry about the quantization of the input
signal since this occurs elsewhere. However, it is often the case that we
∗
Again, we assume here we are rounding to the nearest value when we quantize. If
instead we round towards −∞, i.e. we truncate, things change slightly.
Digital Filters with MATLAB Ricardo A. Losada
D.5 Quantization noise passed through a linear ﬁlter 233
need to requantize a quantized signal, i.e. reduce the number of bits used
to represent it.
Examples where this is common include throwing out bits when mov
ing data from an accumulator (all the additions in a directform FIR ﬁlter)
to the output of the ﬁlter because we need to preserve the input signal
wordlength at the output. A typical example is keeping only 16 bits for
the output from an accumulator that may have anywhere from 32 to 40
bits.
Another common case is in the feedback portion of an IIR ﬁlter since
otherwise the repeated additions would result in unbounded bit growth.
Of course the bits that we throw out when we requantize a signal are
the LSBs. This way the same range can be covered after requantization
and overﬂow is avoided. The precision is clearly reduced as we throw out
LSBs (the quantization step increases from 2
−F
to 2
−(F−Q)
; where Q is the
number of bits that are thrown away.
The variance of the quantization noise that we have just derived doesn’t
quite apply for the case of requantizing a quantized signal [36]. However,
such variance becomes a very good approximation if at least 3 or 4 bits are
thrown out. Since we are typically removing anywhere from 16 bits on
ward, the ε
2
/12 value is usually used without giving it a second thought.
The value of ε in this case corresponds of course to the quantization step
after requantizing.
D.5 Quantization noise passed through a linear
ﬁlter
When analyzing how quantization affects the output signal of a ﬁlter, the
following result will come in handy: If a random signal, x[n], with power
spectral density (PSD) given by P
xx
(e
jω
) is ﬁltered through a ﬁlter with
frequency response H(e
jω
), the output of the ﬁlter, y[n], will be a random
signal with PSD given by,
P
yy
(e
jω
) =
H(e
jω
)
2
P
xx
(e
jω
)
In particular, if the input is a whitenoise signal, such as the quantiza
tion noise, its PSD will be constant, with intensity given by the variance
Digital Filters with MATLAB Ricardo A. Losada
234 Overview of FixedPoint Arithmetic
scaled by 2π, i.e. σ
2
x
/2π. In this case, the PSD of the output will be
P
yy
(e
jω
) =
σ
2
x
2π
H(e
jω
)
2
. (D.3)
Therefore, in this case the PSD will take the spectral shape of the squared
magnituderesponse of the ﬁlter.
D.5.1 Computing the average power of the output noise
Once we have computed the PSD of the output due to the quantization
noise, we can compute the average power at the output due to such noise
by integrating the PSD,
P
AVG
=
π
−π
P
yy
(e
jω
)dω
In the case of FIR ﬁlters, when all arithmetic is performed with full
precision and therefore the only source of quantization noise is due to the
bits being discarded at the output, the transfer function between the noise
source and the ﬁlter output is trivially H(e
jω
) = 1. If the PSD intensity is
σ
2
x
/2π = ε
2
/(2π · 12), the average power is simply
P
AVG
=
π
−π
ε
2
2π · 12
H(e
jω
)
2
dω =
ε
2
12
(D.4)
D.6 Oversampling noiseshaping quantizers
A great deal of emphasis is placed throughout this document on multirate
ﬁlters. One of the primary uses of decimation ﬁlters is in easing the imple
mentation of analog to digital conversion. This process of course involves
quantization of signals.
Similarly, one of the primary uses of interpolation ﬁlters is to help with
digital to analog conversion (it is one of the few reasons to oversample).
In either the decimation or interpolation case, the use of noise shap
ing quantizers (or requantizers) in which multirate techniques are used
in conjunction with shaping the quantization noise (via highpass ﬁltering)
can reduce the number of bits required to represent a signal without de
creasing the SNR.
These schemes are widely used in practice. For more information see
[3].
Digital Filters with MATLAB Ricardo A. Losada
Bibliography
[1] R. A. Losada, “Design ﬁnite impulse response digital ﬁlters. Part I,”
Microwaves & RF, vol. 43, pp. 66–80, January 2004.
[2] R. A. Losada, “Design ﬁnite impulse response digital ﬁlters. Part II,”
Microwaves & RF, vol. 43, pp. 70–84, February 2004.
[3] S. J. Orfanidis, Introduction to Signal Processing. Upper Saddle River,
New Jersey: Prentice Hall, 1996.
[4] T. Saramaki, Handbook for Digital Signal Processing. S. K. Mitra and J. F.
Kaiser Eds., ch. 4. Finite impulse response ﬁlter design, pp. 155–278.
New York, New York: WileyInterscience, 1993.
[5] L. R. Rabiner and B. Gold, Theory and Application of Digital Signal Pro
cessing. Englewood Cliffs, New Jersey: Prentice Hall, 1975.
[6] E. W. Cheney, Introduction to Approximation Theory. Rhode Island:
American Mathematical Society, 1998.
[7] J. H. McClellan, T. W. Parks, and L. R. Rabiner, “A computer program
for designing optimum FIR linear phase digital ﬁlters,” IEEE Trans.
Audio Electroacoust., vol. AU21, pp. 506–526, 1973.
[8] O. Hermann and H. W. Sch¨ ußler, “Design of nonrecursive digital ﬁl
ters with minimum phase,” Electronic Lett., vol. 6, pp. 329–330, 1970.
[9] T. W. Parks and C. S. Burrus, Digital Filter Design. New York, New
York: WileyInterscience, 1987.
236 BIBLIOGRAPHY
[10] I. W. Selesnick and C. S. Burrus, “Exchange algorithms that comple
ment the ParksMcClellan algorithm for linearphase FIR ﬁlter de
sign,” IEEE Trans. on Circuits and Systems II, vol. CAS44, pp. 137–142,
February 1997.
[11] fred harris, Multirate Signal Processing for Communication Systems. Up
per Saddle River, New Jersey: Prentice Hall, 2004.
[12] R. A. Losada and V. Pellissier, “Designing IIR ﬁlters with a given 3dB
point,” IEEE Signal Proc. Magazine; DSP Tips & Tricks column, vol. 22,
pp. 95–98, July 2005.
[13] R. A. Losada and V. Pellissier, Streamlining Digital Signal Processing:
A Tricks of the Trade Guidebook. Edited by R. Lyons, ch. 4. Designing IIR
Filters with a Given 3dB Point, pp. 33–41. Hoboken, New Jersey:
IEEE Press; WileyInterscience, 2007.
[14] A. Antoniou, Digital Filters: Analysis, Design, and Applications. New
York, New York: McGrawHill, second ed., 1993.
[15] S. K. Mitra, Digital Signal Processing: A ComputerBased Approach. New
York, New York: McGrawHill, third ed., 2006.
[16] P. P. Vaidyanathan, Handbook for Digital Signal Processing. S. K. Mitra
and J. F. Kaiser Eds., ch. 7. Robust digital ﬁlter structures, pp. 419–490.
New York, New York: WileyInterscience, 1993.
[17] P. A. Regalia, S. K. Mitra, and P. P. Vaidyanathan, “The digital allpass
ﬁlter: a versatile signal processing buildingblock,” Proceedings of the
IEEE, vol. 76, pp. 19–37, January 1988.
[18] L. Gazsi, “Explicit formulas for wave digital ﬁlters,” IEEE Trans. on
Circuits and Systems, vol. CAS32, pp. 68–88, 1985.
[19] M. Lutovac, D. Tosic, and B. Evans, Filter Design for Signal Processing
Using MATLAB and Mathematica. Upper Saddle River, New Jersey:
Prentice Hall, 2001.
[20] H. W. Sch¨ ußler and P. Steffen, “Recursive halfbandﬁlters,” AE
¨
U In
ternational Journal of Electronics and Communications, vol. 55, pp. 377–
388, December 2001.
Digital Filters with MATLAB Ricardo A. Losada
BIBLIOGRAPHY 237
[21] H. W. Sch¨ ußler and P. Steffen, “Halfband ﬁlters and Hilbert trans
formers,” Circuits, Systems, and Signal Processing, vol. 17, pp. 137–164,
March 1998.
[22] M. Lang, “Allpass ﬁlter design and applications,” IEEE Transactions
on Signal Processing, vol. 46, pp. 2505–2514, September 1998.
[23] N. J. Fliege, Multirate Digital Signal Processing. New York, New York:
John Wiley & Sons, 1994.
[24] R. E. Crochiere and L. R. Rabiner, Multirate Digital Signal Processing.
Englewood Cliffs, New Jersey: PrenticeHall, 1983.
[25] Y. Neuvo, C.Y. Dong, and S. K. Mitra, “Interpolated ﬁnite im
pulse response ﬁlters,” IEEE Trans. on Acoust. Speech and Signal Proc.,
vol. ASSP32, pp. 563–570, June 1984.
[26] P. P. Vaidyanathan, Multirate Systems and Filter Banks. Englewood
Cliffs, New Jersey: Prentice Hall, 1993.
[27] R. Lyons, “Interpolated narrowband lowpass FIR ﬁlters,” IEEE Signal
Proc. Mag., pp. 50–57, January 2003.
[28] T. Saramaki, Y. Neuvo, and S. K. Mitra, “Design of computationally
efﬁcient interpolated FIR ﬁlters,” IEEE Trans. on Circuits and Systems,
vol. CAS35, pp. 70–88, January 1988.
[29] R. Lyons, Streamlining Digital Signal Processing: A Tricks of the Trade
Guidebook. Edited by R. Lyons, ch. 8. Turbocharging Interpolated FIR
Filters, pp. 73–84. Hoboken, New Jersey: IEEE Press; Wiley
Interscience, 2007.
[30] T. Saramaki and Y. Neuvo, “A class of ﬁr nyquist (nthband) ﬁlters
with zero intersymbol interference,” IEEE Trans. on Circuits and Sys
tems, vol. CAS34, no. 10, pp. 1182–1190, 1987.
[31] E. B. Hogenauer, “An economical class of digital ﬁlters for decima
tion and interpolation,” IEEE Trans. on Acoust. Speech and Signal Proc.,
vol. ASSP29, pp. 155–162, April 1981.
Digital Filters with MATLAB Ricardo A. Losada
238 BIBLIOGRAPHY
[32] R. A. Losada and R. Lyons, Streamlining Digital Signal Processing: A
Tricks of the Trade Guidebook. Edited by R. Lyons, ch. 6. Reducing CICFil
ter Complexity, pp. 51–58. Hoboken, New Jersey: IEEE Press; Wiley
Interscience, 2007.
[33] K. E. Atkinson, An Introduction to Numerical Analysis. New York: John
Wiley and Sons, second ed., 1989.
[34] R. L. Burden and J. D. Faires, Numerical Analysis. Paciﬁc Grove, CA:
Brooks/Cole, seventh ed., 2001.
[35] M. Unser, “Sampling—50 years after shannon,” PROCEEDINGS OF
THE IEEE, vol. 88, pp. 569–587, April 2000.
[36] D. Schlichth¨ arle, Digital Filters: Basics and Design. Berlin: Springer,
2000.
Digital Filters with MATLAB Ricardo A. Losada
Contents
I Filter Design
1 Basic FIR Filter Design 1.1 Why FIR ﬁlters? . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Lowpass ﬁlters . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 FIR lowpass ﬁlters . . . . . . . . . . . . . . . . . . . . 1.2.2 FIR ﬁlter design speciﬁcations . . . . . . . . . . . . . 1.2.3 Working with Hertz rather than normalized frequency 1.3 Optimal FIR ﬁlter design . . . . . . . . . . . . . . . . . . . . . 1.3.1 Optimal FIR designs with ﬁxed transition width and ﬁlter order . . . . . . . . . . . . . . . . . . . . . . . . . 1.3.2 Optimal equiripple designs with ﬁxed transition width and peak passband/stopband ripple . . . . . . . . . . 1.3.3 Optimal equiripple designs with ﬁxed peak ripple and ﬁlter order . . . . . . . . . . . . . . . . . . . . . . 1.3.4 Constrainedband equiripple designs . . . . . . . . . 1.3.5 Sloped equiripple ﬁlters . . . . . . . . . . . . . . . . . 1.4 Further notes on equiripple designs . . . . . . . . . . . . . . 1.4.1 Unusual endpoints in the impulse response . . . . . 1.4.2 Transition region anomalies . . . . . . . . . . . . . . . 1.5 Maximallyﬂat FIR ﬁlters . . . . . . . . . . . . . . . . . . . . . 1.6 Summary and look ahead . . . . . . . . . . . . . . . . . . . . Basic IIR Filter Design 2.1 Why IIR ﬁlters . . . . . . . . . . . . . . . . . 2.2 Classical IIR design . . . . . . . . . . . . . . 2.2.1 Cutoff frequency and the 3dB point 2.2.2 Butterworth ﬁlters . . . . . . . . . . 2.2.3 Chebyshev type I ﬁlters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
9 9 10 11 11 14 15 15 22 26 27 28 32 32 33 35 37 39 40 40 41 41 42
2
CONTENTS 2.2.4 Chebyshev type II designs . . . . . 2.2.5 Elliptic ﬁlters . . . . . . . . . . . . 2.2.6 Minimumorder designs . . . . . . 2.2.7 Comparison to FIR ﬁlters . . . . . IIR designs directly in the digital domain Summary and look ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 44 47 48 50 52 54 56 57 58 61 61 63 65 67 68 68 79 80 80 82 86 89 90 92 95 96 99 100 102 104 108 111 112 113 115
2.3 2.4
3 Nyquist Filters 3.1 Design of Nyquist ﬁlters . . . . . . . . 3.1.1 Equiripple Nyquist ﬁlters . . . 3.1.2 Minimumorder Nyquist ﬁlters 3.2 Halfband ﬁlters . . . . . . . . . . . . . 3.2.1 IIR halfband ﬁlters . . . . . . . 3.3 Summary and look ahead . . . . . . .
4 Multirate Filter Design 4.1 Reducing the sampling rate of a signal . . . . . . . . . . . 4.1.1 Decimating by an integer factor . . . . . . . . . . . 4.1.2 Decimating by a noninteger factor . . . . . . . . . 4.2 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2.1 Fractionally advancing/delaying a signal . . . . . 4.2.2 Increasing the samplingrate of a signal . . . . . . 4.2.3 Design of FIR interpolation ﬁlters . . . . . . . . . 4.2.4 Design of IIR halfband interpolators . . . . . . . . 4.2.5 Design of interpolators when working with Hertz 4.3 Increasing the sampling rate by a fractional factor . . . . 4.4 Fractional decimation . . . . . . . . . . . . . . . . . . . . . 4.5 Summary and look ahead . . . . . . . . . . . . . . . . . . 5 Multistage/Multirate Filter Design 5.1 Interpolated FIR (IFIR) designs . . . . . . . . . . 5.1.1 Further IFIR optimizations . . . . . . . . 5.1.2 Multirate implementation of IFIR design 5.2 Multistage/Multirate Designs . . . . . . . . . . . 5.2.1 Setting the number of stages . . . . . . . 5.3 Multistage/Multirate Nyquist ﬁlters . . . . . . . 5.3.1 Using IIR halfband ﬁlters . . . . . . . . . 5.4 Multistage interpolation . . . . . . . . . . . . . . Digital Filters with MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ricardo A. Losada
4 5.5 6
CONTENTS Summary and look ahead . . . . . . . . . . . . . . . . . . . . 118 120 121 125 130 132 134 136 137 138 139 141 144 146 147 149 152
Special Multirate Filters 6.1 Hold interpolators . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Linear interpolators . . . . . . . . . . . . . . . . . . . . . . . . 6.3 CIC interpolators . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.1 Design of CIC interpolators . . . . . . . . . . . . . . . 6.3.2 Gain of CIC interpolators . . . . . . . . . . . . . . . . 6.3.3 Further details of CIC ﬁlters . . . . . . . . . . . . . . . 6.4 CIC decimators . . . . . . . . . . . . . . . . . . . . . . . . . . 6.4.1 Design parameters . . . . . . . . . . . . . . . . . . . . 6.5 CIC compensators . . . . . . . . . . . . . . . . . . . . . . . . . 6.6 Farrow Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.6.1 Higherorder polynomials . . . . . . . . . . . . . . . . 6.6.2 Design of Farrow fractional delays . . . . . . . . . . . 6.6.3 Multirate Farrow ﬁlters . . . . . . . . . . . . . . . . . 6.6.4 Polynomial interpolation and maximally ﬂat ﬁltering 6.6.5 Using Farrow samplerate converters in multistage designs . . . . . . . . . . . . . . . . . . . . . . . . . . .
II Filter Implementation
7
154
Implementing FIR Filters 155 7.1 Some basics on implementing FIR ﬁlters . . . . . . . . . . . . 155 7.1.1 Directform ﬁlter structure . . . . . . . . . . . . . . . . 156 7.1.2 Symmetric directform ﬁlter structure . . . . . . . . . 157 7.1.3 Transposed directform ﬁlter structure . . . . . . . . . 158 7.2 Fixedpoint implementation . . . . . . . . . . . . . . . . . . . 160 7.2.1 Quantizing the ﬁlter’s coefﬁcients . . . . . . . . . . . 160 7.2.2 Fixedpoint ﬁltering: Directform structure . . . . . . 165 7.2.3 Fixedpoint ﬁltering: Transposed directform structure168 7.2.4 Quantization of the output signal . . . . . . . . . . . . 169 7.2.5 Evaluating the performance of the ﬁxedpoint ﬁlter . 171 Implementing IIR Filters 177 8.1 Some basics of IIR implementation . . . . . . . . . . . . . . . 177 8.1.1 The use of secondorder sections . . . . . . . . . . . . 177 Ricardo A. Losada
8
Digital Filters with MATLAB
. . . . . . . . A. . . . . . . . . . . . . .5 Converting to ﬁxed point . . . . . . . . . . . 209 B.1. . . . . . .1. . . . . . 8. . 8. . . . . . . . . . . . .2. .4 Designing multirate ﬁlters . .3 Design analysis/validation . A. . . . .1 Bandpass sampling . .2 Design options . . . . . . . . . . . . . . . . 205 B. 209 B. . . . 8. . . . . . . . .1 Filtering to avoid aliasing when downsampling . . . . .5 Practical sampling and analog reconstruction . . . . . . .3 Increasing the sampling rate of a signal . . . . . . . . . . . 223 Digital Filters with MATLAB Ricardo A. . . . . . . . . A. . . . . . . . . . .7 Graphical User Interface . . . . . . . . . . . . Losada .1 Filter Design (fdesign) . . . A. .1. . . . . . . . . . . . . . . . . . . . . and Analog Reconstruction 199 B. . . .2 Selecting ﬁlter structure . . . .1 Oversampling . . . . . A. . . . . . . . . . . .5. . . . . . . . . .2. .1 Fixedpoint ﬁltering . . 214 C Case Study: Comparison of Various Design Approaches 219 D Overview of FixedPoint Arithmetic 222 D. . . . . . . . .2. . . Downsampling. . . . 206 B. .2 Sampling a discretetime signal: downsampling . . . . . . . . . . . . . . . .CONTENTS 8. . . . . . . . . . . . . A. . .6 Generating Simulink blocks . . . Upsampling. . . . . . . . . . . . . .2. . . A. . . . . . . .1 Setup design speciﬁcations . . . . . . . . . . . . the magnitude .1 Sampling an analog signal . .2 Downsampling bandpass signals . . . . 212 B. . . . . . 5 178 181 182 187 188 8. A. . .3 Evaluating ﬁlter performance using response estimate . . . . . . . . . . . . . . .1. . . . . . . . . . . . . 211 B.1. . . . . . . . . . . . . . . . .2 Allpassbased implementations . . . . .2 III Appendices A Summary of relevant ﬁlter design commands A. . . . . .1 Some ﬁxedpoint basics . . 190 191 191 191 192 193 193 194 195 195 197 198 B Sampling. . . 208 B. . . . . . . . . 201 B. . . . . . . . . . Fixedpoint implementation . .3 Scaling IIR SOS structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Autoscaling . . . .4 Reconstructing an analog signal . .2. . . . A. . . . .
. . . . . . . .4 Quantization noise variance . .2 Fixedpoint multiplication . . . . D. . . . . . . D. . . . . . . . .3. . . .1 Fixedpoint addition . D. D. . . . D. . . . . . .5. .6 Oversampling noiseshaping quantizers . . . . . . . . . . .3 Fixedpoint arithmetic . . . . . . . . . . . . . . . . . . . . D. . . . . . .1 Quantizing impulse responses for FIR ﬁlters . . . D. .5 Quantization noise passed through a linear ﬁlter . . . .6 CONTENTS D. . . . .2 Quantization of signals and SNR . Losada . . . . .3. . . . . . . . . . . 223 227 228 228 230 232 233 234 234 Digital Filters with MATLAB Ricardo A. . . . . . . .1 Computing the average power of the output noise D. . . . . .2.
This document may be updated from time to time.Preface This document∗ constitutes a tutorial on design and implementation of digital ﬁlters in MATLAB.com/matlabcentral ∗ . It also discusses advanced design techniques such as multirate/multistage decimation/interpolation and the use of special multirate ﬁlters such as allpassbased polyphase IIR ﬁlters. and Farrow ﬁlters. The document covers the design of FIR and IIR singlerate and multirate ﬁlters. The tutorial focuses on practical aspects of ﬁlter design and implementation. CIC ﬁlters.mathworks. The tutorial is based on functionality from the Filter Design Toolbox™. The latest version can be found at www. The theory behind the design algorithms is kept to a minimal. and on the advantages and disadvantages of the different design algorithms.
Part I Filter Design .
We also mention a few caveats with equiripple ﬁlter design.1 Why FIR ﬁlters? There are many reasons why FIR ﬁlters are very attractive for digital ﬁlter design.Chapter 1 Basic FIR Filter Design Overview In this chapter we discuss the basic principles of FIR ﬁlter design. Some of them are: • Simple robust way of obtaining digital ﬁlters . 1. but most of the results apply to other response types as well. it has been expanded and includes newer syntax and features from the Filter Design Toolbox. We concentrate mostly on lowpass ﬁlters. We introduce sloped equiripple designs as a compromise to obtain equiripple passband yet nonequiripple stopband. We discuss the basic trade offs and the degrees of freedom available for FIR ﬁlter design. The material presented here is based on [1] and [2]. We then discuss optimal minimumphase designs as a way of surpassing in some sense comparable optimal linearphase designs. We motivate the use of optimal designs and introduce both optimal equiripple and optimal leastsquares designs. However. We end with an introductory discussion of different ﬁlter structures that can be used to implement an FIR ﬁlter in hardware.
there are also modern IIR design techniques that lend themselves to efﬁcient multirate implementations and are extremely computationally efﬁcient. The most important is that they can be computationally expensive to implement. In terms of the long transient response. possibly in cascaded secondorder section form. 1. Losada . the use of multistage/multirate techniques can yield FIR implementations that can compete (and even surpass) IIR implementations while retaining the nice characteristics of FIR ﬁlters such as linearphase. in many cases. ∗ Digital Filters with MATLAB Ricardo A. so depending on the requirements of the ﬁlter. and rejects all frequency components of a signal above ωc . and robustness to quantization effects. IIR designs may still be the way to go. Another is that they have a long transient response. stability. It is commonly thought that IIR ﬁlters must be used when computational power is at a premium.10 Basic FIR Filter Design • Inherently stable when implemented non recursively • Free of limit cycles when implemented non recursively • Easy to attain linear phase • Simple extensions to multirate and adaptive ﬁlters • Relatively straightforward to obtain designs to match custom magnitude responses • Some vendors and specialized hardware only support FIR • Low sensitivity to quantization effects compared to many IIR ﬁlters FIR ﬁlters have some drawbacks however. However.∗ However. This is certainly true in some cases. That being said.2 Lowpass ﬁlters The ideal lowpass ﬁlter is one that allows through all frequency components of a signal below a designated cutoff frequency ωc . We are referring here to more traditional IIR designs implemented using directform I or II structures. we will show in Chapter 2 that minimumphase FIR ﬁlters can have a shorter transient response than comparable IIR ﬁlters. these efﬁcient multistage/multirate designs tend to have very large transient responses.
The third speciﬁcation will be determined by the design algorithm utilized. Losada .2. (1. but other norms are possible. πn −∞ < n < ∞. The metaphor is used to understand the degrees of freedom available when designating design speciﬁcations. The peak ripple corresponding to the L∞ norm is the most commonly used measure. i. one must select the ﬁlter order.2 ∗ . Practical FIR designs typically consist of ﬁlters that meet certain design speciﬁcations.1 FIR lowpass ﬁlters Because the impulse response required to implement the ideal lowpass ﬁlter is inﬁnitely long.1) can easily be found to be [3] hLP [n] = sin(ωc n) .1). 0 ≤ ω ≤ ωc ωc < ω ≤ π 11 (1.2) 1.2 FIR ﬁlter design speciﬁcations Both the passband/stopband ripples and the transition width are undesirable but unavoidable deviations from the response of an ideal lowpass ﬁlter when approximating with a ﬁnite impulse response.e. 1. ∗ Digital Filters with MATLAB Ricardo A. one can at most select the values of two of the speciﬁcations. it is impossible to design an ideal FIR lowpass ﬁlter. or equivalently. Because the sum of the angles is ﬁxed. For the ripples we should more generally speak of some measure or norm of them. as well as to a nonzero transition width between the passband and stopband of the ﬁlter (see Figure 1. Finite length approximations to the ideal impulse response lead to the presence of ripples in both the passband (ω < ωc ) and the stopband (ω > ωc ) of the ﬁlter.2.2 Lowpass ﬁlters Its frequency response satisﬁes HLP (e jω ) = 1.1..1) The impulse response of the ideal lowpass ﬁlter (1. 0. In addition. the length of the truncated impulse response. that have a transition width and maximum passband/stopband ripples that do not exceed allowable values. A useful metaphor for the design speciﬁcations in FIR design is to think of each speciﬁcation as one of the angles in a triangle as in Figure 1.
as with the angles in a triangle. Example 1 As an example.4π rad/sample 2. Losada .8 0. Maximum passband/stopband ripple: 0. Transition width: 0. ωc = 0.4 Ideal lowpass filter Transition width Amplitude 0.2 0.05 The ﬁlter can easily be designed with the truncatedandwindowed impulse response algorithm (a. the “window method”) if we use a Kaiser window∗ : Notice that when specifying frequency values in MATLAB.a.4 0.6 0.3 0. Moreover.6 0.k. if we make one of the speciﬁcations larger/smaller.7 0.2 Normalized Frequency (×π rad/sample) Figure 1.4π. consider the design of an FIR ﬁlter that meets the following speciﬁcations: Speciﬁcations Set 1 1. the factor of π should be omitted.12 Zero−Phase Response 1. it will impact one or both of the other speciﬁcations.2 1 Basic FIR Filter Design Passband ripple 0.1 0.5 0.2 0 Stopband ripple 0 0.8 0.06π rad/sample 3. ∗ Digital Filters with MATLAB Ricardo A.1: Illustration of the typical deviations from the ideal lowpass ﬁlter when approximating with an FIR ﬁlter. Cutoff frequency: 0.9 1 −0.
'linear'). ∗ Digital Filters with MATLAB Ricardo A. design(Hf. Note that since we have ﬁxed the allowable transition width and peak ripples.1.05. the order is determined for us.0.Fp.2 Lowpass ﬁlters 13 Filter order Transition width peak passband/ stopband ripple Figure 1. Losada .05. ωs = 0. Similarly.Fst.4 + 0.37π.43π.'kaiserwin'). Fp = 0.0. The passbandedge frequency is the boundary between the passband and the transition band.Ast'. and at the stopbandedge frequency. the passbandedge frequency ω p is given in terms of the cutoff frequency ωc by ω p = ωc − Tw /2. Hf = fdesign.4 . Close examination at the passbandedge frequency∗ . Usually the speciﬁcations are exceeded because the order is rounded to the next integer greater than the actual value required. shows that the peak passband/stopband ripples are indeed within the allowable speciﬁcations.3. ω p = 0.lowpass('Fp. The zerophase response of the ﬁlter is shown in Figure 1.06/2.06/2.Fst. If the transition width is Tw .Ap.0.2: FIR design speciﬁcations represented as a triangle. Fst = 0. the stopbandedge frequency is given by ωs = ωc + Tw /2.
1. The corresponding normalized passband and stopband frequencies are 0.9 0. Conversion between one and the other is straightforward. and ω is normalized frequency in radians/sample. It is possible to specify design parameters directly in Hertz..2 0..3: Kaiser window design meeting prescribed speciﬁcations.6 0. Recall that normalized frequency is related to absolute frequency by ω= 2π f fs where f is absolute frequency in cycles/second.7 0.3 Working with Hertz rather than normalized frequency In many applications the speciﬁcations are given in terms of absolute frequency in Hertz rather than in terms of normalized frequency. Hf = fdesign.6π respectively.8 0.80).2 0. Suppose the speciﬁcations for a ﬁlter design problem include a passband frequency of 250 Hz. Ricardo A. Losada Digital Filters with MATLAB . it is not necessary to perform such conversion manually.Ast'.3 0.6. For example.4 0.lowpass('Fp.4 0.5 0.1.9 Normalized Frequency (×π rad/sample) Figure 1.5 0. a stopband frequency of 300 Hz.Ap.1 0 0 0.8 0. and a sampling frequency of 1 kHz.3 0.5π and 0. However.1 0.5.2.Fst.6 0. the following two ﬁlters H1 and H2 are identical.14 Zero−phase Response 1 0. f s is the sampling frequency in samples/second.7 Basic FIR Filter Design Amplitude 0.
Any of these is typically undesirable in practice.250. The most common optimal FIR design algorithms are based on ﬁxing the transition width and the order of the ﬁlter.300.lowpass('Fp.Fst. ω∈Ω where Ha (ω ) is the zerophase response of the designed ﬁlter and Ω = [0. This deviation or error can be expressed mathematically as [4] E(ω ) = Ha (ω ) − HLP (e jω ). It is still necessary to deﬁne a measure to determine “the size” of E(ω ) .the quantity we want to minimize as a result of the optimization. H2 = design(Hf2). Simply appending the sampling frequency to the other design parameters indicates that all frequencies speciﬁed are given in Hertz.Ast'.1.3 Optimal FIR ﬁlter design 15 H1 = design(Hf). Digital Filters with MATLAB Ricardo A. it is not optimal in any sense.80.Ast' (or any other speciﬁcation string) when we specify parameters in Hertz. greater transition width or greater passband/stopband ripples.leastsquares designs). 1.3 Optimal FIR ﬁlter design While the truncatedandwindowed impulse response design algorithm is very simple and reliable.Ap.Fst. π ]. The designs it produces are generally inferior to those produced by algorithms that employ some optimization criteria in that it will have greater order. Notice that we don’t add 'Fs' to the string 'Fp.1000). 1.3. therefore more sophisticated algorithms come in handy.1. ω p ] ∪ [ωs . The deviation from the ideal response is measured only by the passband/stopband ripples. The most often used measures are the L∞ norm ( E(ω ) ∞ minimax designs) and the L2 norm ( E(ω ) 2 . Hf2 = fdesign.Ap.1 Optimal FIR designs with ﬁxed transition width and ﬁlter order Optimal designs are computed by minimizing some measure of the deviation between the ﬁlter to be designed and the ideal ﬁlter. Losada .
Equiripple ﬁlters are ideally suited for applications in which a speciﬁc tolerance must be met. if it is necessary to design a ﬁlter with a given minimum stopband attenuation or a given maximum passband ripple. The design problem is to ﬁnd a ﬁlter that minimizes the energy of the error between ideal and actual ﬁlters. W (ω ) is usually introduced. The equiripple design implements an algorithm developed in [7] that computes a solution to the design problem for linearphase FIR ﬁlters in the L∞ norm case.EW (ω ) . Linearphase designs A ﬁlter with linearphase response is desirable in many applications. EW (ω ) = W (ω )[ Ha (ω ) − HLP (e jω )]. i.according to a given measure. By “best” it is meant the one which minimizes the difference between them . One of the desirable characteristics of FIR ﬁlters is that they can be designed very easily to have linear phase. For these types of ﬁlters.e. This type of design leads to socalled equiripple ﬁlters. The firls design implements an algorithm to compute solution for linearphase FIR ﬁlters in the L2 norm case. a weighting function. ﬁlters in which the peak deviations from the ideal response are all equal. notably image processing and data transmission. It is well known [5] that linearphase FIR ﬁlters will have impulse responses that are either symmetric or antisymmetric.16 Basic FIR Filter Design In order to allow for different peak ripples in the passband and stopband. For example. Equiripple ﬁlters Linearphase equiripple ﬁlters are desirable because they have the smallest maximum deviation from the ideal ﬁlter when compared to all other linearphase FIR ﬁlters of the same order. The design problem is essentially to ﬁnd a ﬁlter that minimizes the maximum error between the ideal and actual ﬁlters. Losada ω∈Ω . and the ﬁlter design problem becomes a well behaved mathematical approximation problem [6]: Determine the best approximation to a given function (the ideal lowpass ﬁlter’s frequency response) by means of a polynomial (the FIR ﬁlter) of a given order. the zerophase response can be determined analytically [5]. Digital Filters with MATLAB Ricardo A.
Example 2 The Kaiserwindow design of Example 1 was of 42nd order.lowpass('N. Fst = 0.0.Fp. In fact.99 0.1 0.05 0. since the ﬁlter is designed to minimize the maximum ripple (minimax design).4 + 0. Hf = fdesign.03 Kaiser−window design Equiripple design Amplitude 1. Heq = design(Hf. Meq = measure(Heq).Fp.4: Passband ripple for of both the Kaiserwindowdesigned FIR ﬁlter and the equirippledesigned FIR ﬁlter. Clearly the maximum deviation is smaller for the equiripple design. we are guaranteed that no other linearphase FIR ﬁlter of 42nd order will have a smaller peak ripple for the same transition width.35 Normalized Frequency (×π rad/sample) Figure 1. Losada .06 1. With this same order.'equiripple').01 1 0.4 shows the superposition of the passband details for the ﬁlters designed with the Kaiser window and with the equiripple design. Digital Filters with MATLAB Ricardo A.06/2.06/2. We can measure the passband ripple and stopband attenuation in dB units using the measure command.Fst).Fst'.96 0 0. Figure 1.3 0.2 0.3 Optimal FIR ﬁlter design 17 Zero−phase Response 1.04 1.42.25 0.15 0.97 0.1.02 1.05 1.4 .98 0. an equiripple ﬁlter (with ﬁxed transition width) can be designed that is superior to the Kaiserwindow design: Fp = 0.
'firls'). Hf. measured in terms of its energy. if we want to reduce the energy of a signal as much as possible in a certain frequency band. Digital Filters with MATLAB Ricardo A. but with a sloped stopband that can reduce the stopband energy in a manner comparable to a leastsquares design.5 that a possible compromise is to design equiripple ﬁlters in such a way that the maximum ripple in the passband is minimized. The stopband details for both equiripple design and the leastsquares design are shown in Figure 1. However.0495 dB compared to 25. although the leastsquares design minimizes the energy in the ripples in both the passband and stopband. So while the equiripple design has less peak error. as the equiripple design of Example 2. a leastsquares FIR design can be computed from Hls = design(Hf. leastsquares designs are preferable. This is a drawback of leastsquares designs. Leastsquares ﬁlters Equiripple designs may not be desirable if we want to minimize the energy of the error (between ideal and actual ﬁlter) in the passband/stopband.5214004 while the stopband energy for the leastsquares ﬁlter is 6. Consequently.5.43π H (e jω ) dω 2 where H (e jω ) is the frequency response of the ﬁlter.6213e005. the resulting peak passband ripple is always larger than that of a comparable equiripple design. (As a reference. the stopband energy for the Kaiserwindow design for this order and transition width is 1.2329e004). the stopband energy for the equiripple ﬁlter is approximately 3. We will see in Section 1. it has more “total” error. The stopband energy for this case is given by Esb = 2 2π π 0. Losada .18 Basic FIR Filter Design If we compare the measurements of the equiripple design to those of the Kaiserwindow design. In this case.3.8084 dB for the Kaiserwindow design. Example 3 For the same speciﬁcations. we can verify for instance that the equiripple design provides a minimum stopband attenuation of 29. Therefore there is a larger disturbance on the signal to be ﬁltered for a portion of the frequencies that the ﬁlter should allow to pass (ideally undisturbed).
Using weights Both equiripple and leastsquares designs can be further controlled by using weights to instruct the algorithm to provide a better approximation to the ideal ﬁlter in certain bands.05 0. This is because we implicitly were using a weight of one for each band.6.10).9 1 Normalized Frequency (×π rad/sample) Figure 1. the ﬁlter that was designed had the same ripples in the passband and in the stopband. not decibels).7 0. say δp in the passband and δs in the stopband (both in linear units. we must give a weight that is ten times larger: Heq2 = design(Hf. It would be desirable to have an analytic relation between the maximum ripples in a band and the weight in such band.1.0352379 0 −0. The equiripple ﬁlter has a smaller peak error.'Wpass'.5 0.15 19 Equiripple design 0. Unfortunately no such relation exists. If the design speciﬁcations require a speciﬁc maximum ripple amount. Losada .'equiripple'.8 0.4858398 Amplitude: 0. but larger overall error. Example 4 In Example 2 above.05 Normalized Frequency: 0.4299316 Amplitude: 0.1.'Wstop'.3 Optimal FIR ﬁlter design Zero−phase Response 0. If it is desired to have a stopband ripple that is say ten times smaller than the passband ripple.6 0. for a lowpass ﬁlter we can proceed as follows: Digital Filters with MATLAB Ricardo A.5: Comparison of an optimal equiripple FIR design and an optimal leastsquares FIR design.1 Normalized Frequency: 0.08960634 Least−squares design Amplitude 0. The result is plotted in Figure 1. This is useful if it is desired to have less ripple in one band than in another.
08 0. Set the stopband weight to δp δs .02 0 −0. the relative amplitude of the passband ripple relative to the stopband ripple will be correct.2 Normalized Frequency (× π rad/sample) 0. the relative weights control not the amplitude of the ripple but its energy relative to the bandwidth it occupies.1 0. since both the ﬁlter order and the transition width are assumed to be ﬁxed.9 1 Figure 1. 1.20 Basic FIR Filter Design Passband and Stopband Ripples 0.6: Passband and stopband ripples obtained from weighing the stopband 10 times higher than the passband.04 −0. However.1 0 0. This Digital Filters with MATLAB Ricardo A. The procedure we have just described requires trialanderror since either the ﬁlter order or the transition width may need to be adjusted many times until the desired ripples are obtained. For leastsquares designs. Instead of proceeding in such manner.1 0. Set the passband weight to one. In order to obtain a ripple of δp in the passband and δs in the stopband we need to vary either the ﬁlter order or the transition width.02 −0.7 0.3 0.06 0.04 Amplitude 0.5 0.06 −0.4 0.8 0. Losada .6 0.08 −0. later we will describe ways of designing ﬁlters for given passband/stopband ripples and either a ﬁxed transition width or a ﬁxed ﬁlter order. 2. this will not result in the desired ripples unless we are very lucky.
Digital Filters with MATLAB Ricardo A. Nevertheless. As we have already mentioned. is the ability to attain exact linear phase in a straightforward manner. If one is able to relax the linear phase constraint (i.3 Optimal FIR ﬁlter design 21 means that if we weigh the stopband ten times higher than the passband.true). 'minphase'. this symmetry of the coefﬁcients constraints the possible designs that are attainable. 2 This can easily be veriﬁed using the measure command. The minimumphase requirement restricts the resulting ﬁlter to have all ∗ π ωs H (e jω ) dω 2 ωp 0 H (e jω ) dω.. This should be obvious since for a ﬁlter with N + 1 coefﬁcients.. Losada .'equiripple'. it is possible to design minimumphase equiripple ﬁlters that are superior to optimal equiripple linearphase designs based on a technique described in [8]. For the case of lowpass ﬁlters these means that 2 Esb = π − ωs 2π (π − ωs ) will be ten times smaller than Epb 2 = ωp 2π (ω p ) Minimumphase designs One of the advantages of FIR ﬁlters.1. The remaining N/2 coefﬁcients are immediately determined by the linear phase constraint. when compared to IIR ﬁlters.'Wstop'. It is important to note that this is not a totally unconstrained design.10.. only N/2 + 1 of these coefﬁcients are freely assignable (assuming N is even). the energy in the stopband relative to the stopband bandwidth will be 10 times smaller than the energy of the ripples in the passband relative to the passband bandwidth.'Wpass'. Example 5 For the same speciﬁcation set of Example 2 the following minimumphase design has both smaller peak passband ripple and smaller peak stopband ripple∗ than the linearphase equiripple design of that example: Hmin = design(Hf. the linear phase characteristic implies a symmetry or antisymmetry property for the ﬁlter coefﬁcients.e.1. if the application at hand does not require a linear phase characteristic).
The delay introduced is equal to the group delay of the ﬁlter at that frequency. Since groupdelay is the negative of the derivative of phase with respect to frequency.7. Therefore. always the more stringent Given any linearphase FIR ﬁlter with non negative zerophase characteristic. filter(Heq. The signal to be ﬁltered is a sinusoid with frequency 0. sin(0.3.2 Optimal equiripple designs with ﬁxed transition width and peak passband/stopband ripple We have seen that the optimal equiripple designs outperform Kaiserwindow designs for the same order and transition width. The differences are even more dramatic when the passband ripple and stopband ripple speciﬁcations are different..x). the groupdelay of a linearphase ﬁlter is a constant equal to half the ﬁlter order. The plot of the groupdelays is shown in Figure 1. the design is optimal in the sense that it satisﬁes the minimumphase alternation theorem [9].'Grpdelay'). The reason is that the truncatedandwindowed impulse response methods always give a result with approximately the same passband and stopband peak ripple.'Analysis'. 1. the smallest possible transient delay) to a signal being ﬁltered. The minimumphase characteristic means that the ﬁlter introduces the lowest possible phase offset (that is.1*pi*n').1π rad/sample.x). Losada . Example 6 Compare the delay introduced by the linearphase ﬁlter of Example 2 to that introduced by the minimumphase ﬁlter designed above. filter(Hmin. minimumphase ﬁlters do not have constant groupdelay since their phase response is not linear. The output from both ﬁlters are plotted overlaid in Figure 1. This means that all frequencies are delayed by the same amount.22 Basic FIR Filter Design its zeros on or inside the unit circle. n x yeq ymin = = = = 0:500. The groupdelays of both ﬁlters can be visualized using fvtool(Heq. ∗ Digital Filters with MATLAB Ricardo A. On the other hand.Hmin.∗ However. Having smaller ripples for the same ﬁlter order and transition width is not the only reason to use a minimumphase design.8. it is possible to extract the minimumphase spectral factor using the ﬁrminphase function.
Digital Filters with MATLAB Ricardo A.5 0.6 0.1 0.8 −1 0 10 20 30 40 50 60 70 80 90 100 Sample index (n) Figure 1.3 Optimal FIR ﬁlter design 23 1 0.4 −0.7: Sinusoid ﬁltered with a linearphase ﬁlter and a minimumphase ﬁlter of the same order. Losada .2 0.8: Groupdelay of a linearphase ﬁlter and a minimumphase ﬁlter of the same order.6 −0.8 0.7 0.3 0.9 Normalized Frequency (×π rad/sample) Figure 1.6 0.2 −0.1.4 0.2 0 −0.4 Linear−phase filtered sinusoid Minimum−phase filtered sinusoid Amplitude 0.8 0. Group Delay 20 Group delay (in samples) Linear−phase filter Minimum−phase filter 15 10 5 0 0 0.
In this case.15/2. Minimumphase designs with ﬁxed transition width and peak passband/stopband ripple The same procedure to design minimumphase ﬁlters with ﬁxed ﬁlter order and ﬁxed transition width can be used to design minimumphase ﬁlters with ﬁxed transition width and peak passband/stopband ripple.0. Maximum passband ripple: 0.13 dB 4. Hf = fdesign. cost(Heq) results in a ﬁlter of 37th order (38 taps) as indicated by the cost command.375 . Heq = design(Hf. By comparison.lowpass('Fp. a Kaiserwindow design requires a 49th order ﬁlter (50 taps) to meet the same speciﬁcations. Example 7 Consider the following speciﬁcations: Speciﬁcations Set 2 1.9.2. Fp = 0.60).Ap.Fst. Digital Filters with MATLAB Ricardo A.24 Basic FIR Filter Design peak ripple constraint is satisﬁed. Transition width: 0.Fp. rather than obtaining smaller ripples. Referring back to the triangle in Figure 1.Ast'. Fst = 0.'equiripple').Fst. resulting in exceeding (possibly significantly) all other ripple constraints at the expense of unnecessarily large ﬁlter order. To illustrate this. Minimum stopband attenuation: 60 dB An equiripple design of this ﬁlter. The passband details can be seen in Figure 1. Losada .15π rad/sample 3. Cutoff frequency: 0. this means the resulting ﬁlter order will come from the design algorithm.13.375 + 0.15/2.375π rad/sample 2. we turn to a different equiripple design in which both the peak ripples and the transition width are ﬁxed.0. It is evident that the Kaiserwindow design oversatisﬁes the requirements signiﬁcantly. the beneﬁt is meeting the same transition width and peak passband/stopband ripples with a reduced ﬁlter order.
The Kaiserwindow design oversatisﬁes the requirement at the expense of increase number of taps. Example 8 Consider the following speciﬁcations: Speciﬁcations Set 3 1.994 0. Minimum stopband attenuation: 60 dB The minimum order needed to meet such speciﬁcations with a linearphase FIR ﬁlter is 262.true).006 25 Kaiser window design 1.14.004 Equiripple design Magnitude 1.15 0.60). Hmin = design(Hf.992 0 0.3 Normalized Frequency (×π rad/sample) Figure 1. Maximum passband ripple: 0.3 Optimal FIR ﬁlter design Magnitude Response 1.1.lowpass('Fp.25 0. the equiripple design (based on the algorithm proposed in [8]) results in a minimumphase FIR ﬁlter of 216th order that meets the speciﬁcations: Hf = fdesign.'equiripple'.2 0.Fst. If we relax the linearphase constraint however. Transition width: 0.002 1 0.175 dB 4.02π rad/sample 3. Cutoff frequency: 0... Losada .175..Ast'.Ap.05 0.9: Passband ripple details for both the Kaiserwindowdesigned FIR ﬁlter and the equirippledesigned FIR ﬁlter. This ﬁlter must be the result of an optimal equiripple design.'minphase'.12. cost(Hmin) Digital Filters with MATLAB Ricardo A.13π rad/sample 2.998 0.008 1.996 0.1 0.
Ap.13. while ﬁxing the transition width and peak ripple values results in a ﬁlter with less number of taps.3.0.49. In fact this is true in general we had previously seen that a ﬁlter with the same transition width and ﬁlter order with minimumphase has a smaller delay than a corresponding linearphase ﬁlter. Moreover.0. the order of the linearphase ﬁlter would have to increased until the ripples are the same as those of the minimumphase design. Naturally. Losada . the minimumphase ﬁlter has smaller ripples so that the two ﬁlters are not really comparable. In order to compare apples to apples. ﬁxing the transition width and ﬁlter order results in an optimal equiripple design with smaller peak ripple values. The ﬁlter order is set to be the same as that needed for a Kaiserwindow design to meet the ripple speciﬁcations Hf = fdesign.Ast'. This gives maximum ﬂexibility in utilizing the degrees of freedom available to design an FIR ﬁlter.10. This increase in ﬁlter order would of course further increase the delay of the ﬁlter. The comparison of this new design with the Kaiserwindow design is shown in Figure 1. Example 9 Consider the following design of an equiripple with the same cutoff frequency as in Example 7.Fc. 1. The transition width has been reduced from 0. Digital Filters with MATLAB Ricardo A.26 Basic FIR Filter Design Note that for these designs minimumphase ﬁlters will have a much smaller transient delay not only because of their minimumphase property but also because their ﬁlter order is lower than that of a comparable linearphase ﬁlter.60).'equiripple').15π to approximately 0. when compared to Kaiserwindow designs. ﬁxing the ﬁlter order and the peak ripple values should result in a smaller transition width. We have seen that.3 Optimal equiripple designs with ﬁxed peak ripple and ﬁlter order So far we have illustrated equiripple designs with ﬁxed transition width and ﬁxed order and designs with ﬁxed transition width and ﬁxed peak ripple values.lowpass('N.11π.375. Heq = design(Hf. The Filter Design Toolbox also provides algorithms for designs with ﬁxed peak ripple values and ﬁxed ﬁlter order [10].
2 0. Digital Filters with MATLAB Ricardo A. The equiripple design results in a reduced transitionwidth.3 Optimal FIR ﬁlter design Zero−phase Response 1 0.38 0.4 Constrainedband equiripple designs Sometimes when designing lowpass ﬁlters (for instance for decimation purposes) it is necessary to guarantee that the stopband of the ﬁlter begins at a speciﬁc frequency value and that the ﬁlter provides a given minimum stopband attenuation.36 0.34 0. if linearphase is not a requirement. Losada .42 0.3.6 0. In this case. a minimumphase design results in a smaller transition width than a linearphase design. Minimumphase designs with ﬁxed peak ripple and ﬁlter order Once again. for the same ﬁlter order and peak ripple value.9 0.7 27 Kaiser−window design Equiripple design Amplitude 0.1 0 0.10: Comparison of a Kaiserwindowdesigned FIR ﬁlter and an optimal equiripple FIR ﬁlter of the same order and peak ripple values.8 0.4 0.44 Normalized Frequency (×π rad/sample) Figure 1.'minphase'.32 0.1.4 0.3 0. 1.true). the following design has a noticeably smaller transition width: Hmin = design(Hf.5 0.'equiripple'. Example 10 Compared to the 50th order linearphase design Heq. a minimumphase ﬁlter can be designed that is a superior in some sense to a comparable linearphase ﬁlter.
Heq = design(Hf. however.Ast'.'equiripple')..28 Basic FIR Filter Design If the ﬁlter order is ﬁxed .there are two alternatives available in the Filter Design Toolbox for optimal equiripple designs.60). Example 11 For example.13. One way to design this ﬁlter is to provide the same maximum passband ripple of 0.'equiripple'). the design speciﬁcations of Example 7 call for a stopband that extends from 0.3. an equiripple design will result in a ﬁlter with the smallest possible passband ripple for any linearphase FIR ﬁlter of that order that meets the given speciﬁcations.for instance when using specialized hardware .60).3.. To minimize the amount of aliasing. One possibility is to ﬁx the transition width.5 Sloped equiripple ﬁlters In many cases it is desirable to minimize the energy in the stopband of a signal being ﬁltered. The result will be a ﬁlter with the smallest possible transition width for any linearphase FIR ﬁlter of that order that meets the given speciﬁcations.Ast'. Losada . The passband details of the two ﬁlters are shown in Figure 1. the energy in the stopband of a signal after being ﬁltered aliases into the passband region. Leastsquares ﬁlters can be used for this.13 dB but to give up control of the transition width..Fst. Instead of a minimumorder design. we want to minimize the stopband energy.0.45. the other is to ﬁx the passband ripple.11.Ap. Hf = fdesign.lowpass('N. Hf = fdesign.45.Fst. Heq = design(Hf.40. If instead we want to ﬁx the transition width but not constrain the passband ripple.40.Fp.45π to π and provide a minimum stopband attenuation of 60 dB.lowpass('N. One common case is in the design of decimation ﬁlters. The ﬁlters differ in how they “use” the extra number of taps to better approximate the ideal lowpass ﬁlter. the drawback is that the passband presents larger ﬂuctuations than may be desirable. 1. suppose the ﬁlter order available is 40 (41 taps). Note that both ﬁlters meet the Speciﬁcations Set 2 because the order used (40) is larger than the minimum order required (37) by an equiripple linear phase ﬁlter to meet such speciﬁcations. In this case. An alternative is to design optimal Digital Filters with MATLAB Ricardo A.
05 0. There are many ways of shaping the slope of the stopband. Fst = 0. The passband remains equiripple thus minimizing the distortion of the input signal in that region.4 + 0.4 .15 0. although equiripple.1.11: Comparison of a two optimal equiripple FIR ﬁlters of 40th order. Ricardo A.06 0.02 0 −0.06/2.25 0. the passband ripple. Since the design provides smaller stopband energy than a regular equiripple design. One is optimized to minimize the transition width while the other is optimized to minimize the passband ripple. that is as a power of the inverse of frequency. Another way of shaping the slope is to allow it to decay in logarithmic fashion so that the decay appears linear in dB scale. This corresponds to a decay of 6k dB per octave.3 Optimal FIR ﬁlter design Magnitude Response (dB) Fixed passband ripple Fixed transition width 29 0.0. Example 12 Consider an equiripple design similar to that of Example 2 but with a stopband decaying as (1/ f )2 : Fp = 0. Of course there is a price to pay for the sloped stopband. the minimum stopband attenuation measured in dB is smaller than that of a regular equiripple design.2 0.02 −0. is larger than that of a regular equiripple design. Losada Digital Filters with MATLAB . One way [11] is to allow the stopband to decay as (1/ f )k .06/2. Also.1 0.3 Normalized Frequency (×π rad/sample) Figure 1.06 0 0.04 −0. equiripple ﬁlters but allowing for a slope in the stopband of the ﬁlter. Both ﬁlters have the same stopbandedge frequency and minimum stopband attenuation.04 Magnitude (dB) 0.
Hf = fdesign. If we constrain the ﬁlter order. results in a stopband energy of approximately 8. same passband ripple.'1/f'.12: Passband details of a sloped optimal equiripple FIR design and an optimal leastsquares FIR design.4 −0.5 0 0.4095e05. and the minimum stopband attenuation.35 0. the transition width increases as the slope increases as well. 'StopbandDecay'.1 0.2).15 0.Fp.5 0.3 −0. The passband details of both the leastsquares design and the sloped equiripple design are shown in Figure 1.1 −0.Fp. The equiripple ﬁlter has a smaller peak error or smaller transition width depending on the interpretation. Losada .12 (in dB).05 0.1 0 −0.2 0. Example 13 Design two ﬁlters with the same ﬁlter order. Something has to give and since everything else is constrained.depending on the interpretation). the passband ripple.30 Magnitude Response (dB) 0. Hsloped = design(Hf.25 0.2 −0.'equiripple'.13 (also in dB).Fst'.. Digital Filters with MATLAB Ricardo A.3 0.2 0.6213e005).4 Normalized Frequency (×π rad/sample) Figure 1.Fst). The stopband details are shown in Figure 1. and same stopband attenuation..4 0. not much larger that the leastsquares design (6.3 Basic FIR Filter Design Least squares Sloped equiripple Magnitude (dB) 0.'StopbandShape'. it is easy to see the tradeoff between a steeper slope and the minimum stopband attenuation that can be achieved.lowpass('N.42.. The slope of the stopband decay is zero for the ﬁrst ﬁlter and 40 for the second. while having a smaller transition width (or peak passband ripple .
.30.3 Optimal FIR ﬁlter design Magnitude Response (dB) −20 −25 −30 −35 −40 −45 −50 −55 0.Heq2).3.85 0. Losada .5 0..Ap.. 'StopbandDecay'..6 0.9 0. This is easy to see with fvtool(Heq.0).'equiripple'. = design(Hf..75 0. The second ﬁlter provides better total attenuation throughout the stopband.Ast'. Since everything else is constrained.'linear'.'StopbandShape'.7 0.lowpass('N.45 0.8 0.Fst. 'StopbandDecay'.. The overall error of the equiripple ﬁlter approaches that of the leastsquares design. It is also possible to design minimumphase sloped equiripple ﬁlters.13: Stopband details of a sloped optimal equiripple FIR design and an optimal leastsquares FIR design.65 0.. Digital Filters with MATLAB Ricardo A.'linear'. the transition width is larger as a consequence. These designs possess similar advantages over linearphase designs as those described for other equiripple designs when linearity of phase is not a design requirement.55 0. Hf Heq = fdesign.40). Heq2 = design(Hf.0.95 31 Least squares Sloped equiripple Magnitude (dB) Normalized Frequency (×π rad/sample) Figure 1.1.40).4.'StopbandShape'.'equiripple'.
'impulse') The impulse response is show in Figure 1. Notice that the two end points seem completely out of place.4.04 0. fvtool(Heq.0. 1.02 0 −0. In particular.06 Basic FIR Filter Design Amplitude 0.42.1. Heq = design(Hf. the end points seem to be incorrect.'equiripple').08 0. However. the stopband is no longer equiripple.1 0.32 Impulse Response 0. These end points are the result of an equiripple response.4 Further notes on equiripple designs 1. Digital Filters with MATLAB Ricardo A. Example 14 Consider the design of this lowpass ﬁlter with band edges that are quite close to DC: Hf = fdesign.14.Fp.Fst'.12).lowpass('N.1 Unusual endpoints in the impulse response In some cases the impulse response of an equiripple design appears to be anomalous.'Analysis'.14: Impulse response of equiripple ﬁlter showing anomalous endpoints. these end points are in fact a consequence of an equiripple stopband. Losada .0.02 0 5 10 15 20 25 30 35 40 Samples Figure 1. If we remove the anomaly by say repeating the value in the sample closest to the end point.
Heq = design(Hf. ∗ Digital Filters with MATLAB Ricardo A.1 .. Losada ...'equiripple'.Fst'.10.Fp. simply using the nearest neighbor removes the equiripple property of the stopband in an uncontrolled way.800. the frequency response is not optimized between bands with the hope that the response will smoothly transition between them. This is the case for lowpass and highpass ﬁlters. It is preferable to use a sloped equiripple design to control the shape of the stopband and at the same time remove the anomalies. 'StopbandShape'. but may not be the case for ﬁlters with more than two bands when the width of the transition bands differ [4]. another solution would be to include the problematic transition band in the optimization by means of a arbitrary magnitude design.10).1.064. Heq2 = design(Hf. fvtool(Heq..80).'equiripple'. This of course incurs in some degradation in the performance of the ﬁlter that will depend on what constraints are imposed. 1. it is not always feasible to modify them by replacing their value with that of their nearest neighbor because sometimes it is more than just the two end points that are anomalous.4. For instance. sometimes only a subset of it is stored in memory and the rest of the values are computed by curve ﬁtting or some other interpolation scheme.2 Transition region anomalies In equiripple design.Heq2) A look at the impulse response reveals that adding a sloped stopband has altered several of the end points of the impulse response removing the discontinuity.lowpass('N.4 Further notes on equiripple designs 33 If the anomalous endpoints are a problem∗ .'Wstop'.066). A possible solution is to reduce the larger transition bands to make them all the same width. Hf = fdesign.'linear'. when the impulse response is very long. If this is not feasible.'Wpass'. the transition band between passband and stopband or vice versa is treated as a don’t care region for optimization purposes. In such cases the anomalous points pose a problem because the curve ﬁtting is unlikely to reproduce them accurately.1 .'Wstop'.'StopbandDecay'.. Moreover. Example 15 Compare the magnitude response and the impulse response of these two designs using fvtool. That is.'Wpass'.
8.Fp2.3.Fst2..Fp1..4 0.. The anomalies in the second “don’tcare” band are obvious.. the price to pay for this is an increase in the ﬁlter order required to meet the modiﬁed speciﬁcations: = fdesign.1. Example 16 Consider the design of a bandpass ﬁlter with a ﬁrst transition band 0..3 0. Heq = design(Hf..Ast1.2.60). .Fp1.bandpass('Fst1.60.9 Normalized Frequency (×π rad/sample) Figure 1.Ap.1π rad/sample wide and a second transition band 0.. cost(Heq) cost(Heq2) Hf2 Digital Filters with MATLAB Ricardo A.15: Bandpass ﬁlter with transitionband anomaly due to having different transitionband widths.Ast1..3.8 0..1 0.2π rad/sample wide: Hf = fdesign.60. The design can be ﬁxed by making the second transition band 0.2 0.15.Fp2.60).'equiripple')..Fst2.7 0.6.5 0.'equiripple'). Losada .Ast2'.6.bandpass('Fst1.1π rad/sample wide.1. Heq2 = design(Hf.6 0.2.Ap..Ast2'. The magnitude response is shown in Figure 1. Since this is a minimumorder design. .34 Magnitude Response (dB) 0 −10 Basic FIR Filter Design Magnitude (dB) −20 −30 −40 −50 −60 −70 0 0.7..
3π.4 0. The smaller transition width in one of the ﬁlters is achieved by increasing the ﬁlter order. The Maximallyﬂat stopband of the ﬁlter means that its stopband attenuation is very large. Losada .16: Maximallyﬂat FIR ﬁlters.7 10th−order maximally flat FIR filter 20th−order maximally flat FIR filter Magnitude 0.5 0. However. 1.5 Maximallyﬂat FIR ﬁlters Maximallyﬂat ﬁlters are ﬁlters in which both the passband and stopband are as ﬂat as possible given a speciﬁc ﬁlter order. These ﬁlters are seldom used in practice (in particular with ﬁxedpoint implementations) because when the ﬁlter’s coefﬁcients are quantized to a ﬁnite number of bits. As we should come to expect. the ﬂatness in the bands comes at the expense of a large transition band (which will also be maximum). The ﬁlter with smaller transition width has twice the ﬁlter order as the other.4 0.2 0.1 0. the large stopband cannot be Digital Filters with MATLAB Ricardo A.16 shows two maximallyﬂat FIR ﬁlters.5 Maximallyﬂat FIR ﬁlters 35 Magnitude Response 1 0.7 0.1.6 0.1 0 0 0. Example 17 Figure 1.5 0.9 0. There is one less degree of freedom with these ﬁlters than with those we have look at so far.6 0.2 0.3 0.8 0. Both ﬁlters have a cutoff frequency of 0.9 Normalized Frequency (×π rad/sample) Figure 1. this comes at the price of a very large transition width.3 0.8 0. The only way to decrease the transition band is to increase the ﬁlter order.
5 0.6 0. for the same Digital Filters with MATLAB Ricardo A. The comparison of the two implementations is shown in Figure 1.3 0.9 Normalized Frequency (×π rad/sample) Figure 1. if a small amount of ripple is allowed in the passband it is always possible to get a smaller transition band and most applications can sustain a small amount of passband ripple.17: A maximallyﬂat FIR ﬁlter implemented with doubleprecision ﬂoatingpoint arithmetic and the same ﬁlter implemented with 16bit ﬁxedpoint coefﬁcients. The ﬁxedpoint implementation starts to differ signiﬁcantly from the ﬂoatingpoint implementation at about 7580 dB. Example 18 Compare the stopband attenuation of a maximallyﬂat FIR ﬁlter implemented using doubleprecision ﬂoatingpoint arithmetic with that of the same ﬁlter implemented with 16bit ﬁxedpoint coefﬁcients. Example 19 We can approach a maximallyﬂat passband by making the passband ripple of an equiripple design progressively smaller. So it may seem that a maximallyﬂat passband and an equiripple or perhaps sloped stopband could be a thoughtafter combination.17.4 0.1 0. However. Losada . Nevertheless.36 Basic FIR Filter Design Magnitude Response (dB) 0 Double−precision floating−point 16−bit fixed−point −50 Magnitude (dB) −100 −150 −200 0 0. However. achieved (and often is not required anyway) but the large transition band is still a liability.8 0.7 0.2 0. The maximallyﬂat passband may be desirable because it causes minimal distortion of the signal to be ﬁltered in the frequency band that we wish to conserve after ﬁltering. both ﬁlters have the same large transition width.
the larger the transition band. fdesign.9 Normalized Frequency (×π rad/sample) Figure 1.'equiripple'). The better the approximation.Ap. 1.Ast'. Consider the following two ﬁlter designs: Hf Heq Hf2 Heq2 = = = = fdesign.70. The passband details are shown in Figure 1. design(Hf2. Another is to use multistage Digital Filters with MATLAB Ricardo A.Fc.18: Equiripple ﬁlters with passband approximating maximal ﬂatness.Fc. One is to use IIR ﬁlters.2 0.lowpass('N.lowpass('N.3. Losada .'equiripple'). It is generally best to allow some passband ripple as long as the application at hand supports it given that a smaller transition band results. the transition width increases as a result.6 Summary and look ahead 37 Magnitude Response (dB) 0 −10 −20 1 × 10 −3 dB passband ripple 1 × 10−8 dB passband ripple Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 0 0.Ast'.6 Summary and look ahead Understanding FIR ﬁlter design is a matter of understanding the trade offs involved and the degrees of freedom available.70.3.1 0.1e8.. A drawback of FIR ﬁlters is that the tend to require a large ﬁlter order and therefore a high computational cost to achieve the speciﬁcations desired.8 0.6 0. design(Hf.19.7 0.Ap.4 0.18. ﬁlter order and stopband attenuation.80).80).3 0.5 0.1. There are many ways of addressing this. The two ﬁlters are shown in Figure 1..1e3.
e. We will then look into implementation of ﬁlters and discuss issues that arise when implementing a ﬁlter using ﬁxedpoint arithmetic. i.2 0. Digital Filters with MATLAB Ricardo A.38 Magnitude Response (dB) Basic FIR Filter Design x 10 6 −4 1 × 10−3 dB passband ripple 4 1 × 10−8 dB passband ripple Magnitude (dB) 2 0 −2 −4 −6 0 0.19: Passband details of equiripple ﬁlters with very small passband ripple. and/or multirate techniques that use various FIR ﬁlters connected in cascade (in series) in such a way that each ﬁlter shares part of the ﬁltering duties while having reduced complexity when compared to a singlestage design. We will be looking at all these approaches in the following chapters.1 0.25 Normalized Frequency (×π rad/sample) Figure 1. The idea is that for certain speciﬁcations to combined complexity of the ﬁlters used in multistage design is lower than the complexity of a comparable singlestage design.05 0.15 0. a smaller usable passband. The ﬂatter passband is obtained at the expense of a larger transition band. Losada .
see Chapter 5. This is the idea behind IIR ﬁlter design. Butterworth ﬁlters provide very little control over the resulting design since it is basically a maximallyﬂat design. hence the term inﬁnite impulse response (IIR). In fact. the ﬁlter order grows inversely proportional to the transition width. The feedback in the ﬁlter has the effect that an impulse applied to the ﬁlter results in a response that never decays to zero. By using feedback. Elliptic ﬁlters allow for maximum degrees of freedom by allowing for ripples in both the passband and the stopband. so usually one should only concentrate on elliptic ﬁlter design. decreasing the passband ∗ However.Chapter 2 Basic IIR Filter Design Overview One of the drawbacks of FIR ﬁlters is that they require a large ﬁlter order to meet some design speciﬁcations. If the ripples are kept constant. . Chebyshev designs increase the degrees of freedom by allowing ripples in the passband (type I Chebyshev) or the stopband (type II Chebyshev). it is possible to meet a set of design speciﬁcations with a far smaller ﬁlter order than a comparable FIR ﬁlter∗ . We will start this chapter by discussing classical IIR ﬁlter design. The design steps consist of designing the IIR ﬁlter in the analogtime domain where closedform solutions are well known and then using the bilinear transformation to convert the design to the digital domain. We will see that the degrees of freedom available are directly liked to the design algorithm chosen. Chebyshev and Butterworth designs can be seen as a special case of elliptic designs.
40
Basic IIR Filter Design
ripples and/or increasing the stopband attenuation enough to approach Chebyshev or Butterworth designs when so desired. After looking at classical designs, we move on to examine design techniques that are based on optimization directly in the digital domain.
2.1
Why IIR ﬁlters
IIR ﬁlters are usually used when computational resources are at a premium. However, stable, causal IIR ﬁlters cannot have perfectly linear phase, so that IIR ﬁlters tend to be avoided when linearity of phase is a requirement. Also, computational savings that are comparable to using IIR ﬁlters can be achieved for certain design parameters by using multistage/multirate FIR ﬁlter designs (see Chapter 5). These designs have the advantage of having linearphase capability, robustness to quantization, stability, and good pipelineability. Another important reason to use IIR ﬁlters is their relatively small group delay compared to FIR ﬁlters. This results in a shorter transient response to input stimuli. Even if we are able to match or surpass the implementation cost of an IIR ﬁlter by using multirate/multistage FIR designs, the transient response of such FIR designs tends to be much larger than that of a comparable IIR design. However, minimumphase FIR designs such as those seen in Chapter 1, can have groupdelays that are comparable or even lower than IIR ﬁlters that meet the same speciﬁcations.
2.2
Classical IIR design
We begin by discussing ﬁlters that are designed in the analogtime domain and then transformed to the digital domain by means of the bilinear transformation. This methodology covers the following IIR design techniques: Butterworth, Chebyshev type I, Chebyshev type II, and elliptic (Cauer). We follow the methodology presented in [12][13] in which the 3dB point is always a design speciﬁcation. Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design
41
2.2.1 Cutoff frequency and the 3dB point
For FIR ﬁlters, we have started by designating the cutoff frequency for an ideal ﬁlter (i.e. one with zero transitionwidth). However, depending on the design method, the cutoff frequency may lack any meaningful value. For windowedimpulseresponse designs, the magnitude response will typically cross the cutoff frequency at the point where the magnitude is equal to 0.5. In decibels, this point corresponds to 20 log10 (0.5) = −6.0206. The reason for this is that with windowbased designs, the passband and stopband ripples are about the same. For other designs, such as equiripple, the point at which the magnitude response crosses the middle of the transition band will depend on the ratio of the passband and stopband ripples. By contrast, the convention for classical IIR designs is to deﬁne the cutoff frequency as the point at which the power of an input signal is attenuated by onehalf. This means that the cutoff frequency in decibels corresponds to 10 log10 (0.5) = −3.0103 which we loosely call the 3dB point∗ . To avoid confusion, we will call the point at which the power is reduced by onehalf the 3dB point rather than the cutoff frequency. When entering speciﬁcations, we use the string 'F3dB' rather than 'Fc'.
2.2.2 Butterworth ﬁlters
Butterworth ﬁlters are maximallyﬂat IIR ﬁlters. For this reason, the only design parameters are the cutoff frequency and the ﬁlter order. Example 20 Design a 7th order Butterworth ﬁlter with a 3 dB point of 0.3π. Hf = fdesign.lowpass('N,F3db',7,0.3); Hb = design(Hf,'butter'); The design is shown in Figure 2.1. The plot also includes an FIR ﬁlter designed with a cutoff frequency of 0.3π. Notice that the attenuation at 0.3π is 3dB for the Butterworth ﬁlter and 6dB for the FIR ﬁlter. As with maximallyﬂat FIR ﬁlters, the ﬂatness in the passband and stopband cause the transition band to be very wide. The only way of reducing the transition width is to increase the ﬁlter order.
Just to be clear, the gain of the ﬁlter in decibels is 3.0103. The attenuation, i.e. the distance between the passband gain and this point is approximately 3 dB since distance is always positive.
∗
Digital Filters with MATLAB
Ricardo A. Losada
42
Basic IIR Filter Design
Magnitude Response (dB)
0
Normalized Frequency: 0.2995605 Magnitude (dB): −2.958706 Frequency: 0.300415 Magnitude (dB): −6.104557
−10 Normalized
Butterworth filter FIR filter
−20
Magnitude (dB)
−30
−40
−50
−60
−70
−80
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Normalized Frequency (×π rad/sample)
Figure 2.1: 7th order Butterworth ﬁlter with a 3dB frequency of 0.3π. Also shown is an FIR ﬁlter with a cutoff frequency of 0.3π.
Example 21 Compare the 7thorder Butterworth ﬁlter of the previous example, with a 12thorder Butterworth ﬁlter designed with the same 3dB point. The magnitudesquared responses are shown in Figure 2.2. Hf2 = fdesign.lowpass('N,F3db',12,0.3); Hb2 = design(Hf2,'butter'); The transitionwidth is decreased as the ﬁlter order increases. Notice that both ﬁlters intersect at the point where the magnitudesquared of the ﬁlter is equal to 0.5, i.e., the point at which the power of the input signal is attenuated by one half.
2.2.3 Chebyshev type I ﬁlters
Chebyshev type I ﬁlters can attain a smaller transition width than a Butterworth ﬁlter of the same order by allowing for ripples in the passband of the ﬁlter. The stopband is, as with Butterworth ﬁlters, maximally ﬂat. For a given ﬁlter order, the tradeoff is thus between passband ripple and transition width. Example 22 Compare the 7thorder Butterworth ﬁlter from previous examples with a 7thorder Chebyshev type I ﬁlter with 1 dB of peaktopeak passband ripple. Digital Filters with MATLAB Ricardo A. Losada
2.2 Classical IIR design
43
Magnitude Response (squared)
1 0.9 0.8
7th order Butterworth filter 12th order Butterworth filter
Magnitude squared
0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Figure 2.2: Comparison of a 7thorder and a 12thorder Butterworth ﬁlter. The ﬁlters intersect at the 3dB point.
Magnitude Response (squared)
1 0.9 0.8
Butterworth filter Chebyshev type I filter
Magnitude squared
0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Figure 2.3: Comparison of a 7thorder Butterworth and a 7thorder Chebyshev type I ﬁlter. Once again, the ﬁlters intersect at the 3dB point.
Hf = fdesign.lowpass('N,F3db,Ap',7,0.3,1); Hc = design(Hf,'cheby1'); The magnitudesquared responses are shown in Figure 2.3. The passband ripple Digital Filters with MATLAB Ricardo A. Losada
However. attaining a small transition width may result in unacceptably high passband ripple. We know that linearphase throughout the entire Nyquist interval is not possible. As an example. it is also larger for frequencies below the 3dB point (which is the region we care about). until the ﬁlter becomes the same as the Butterworth ﬁlter. It is possible to use other conversion techniques such as impulseinvariance with Bessel ﬁlters [14].4 Chebyshev type II designs Unlike FIR maximallyﬂat ﬁlters. Notice that not only is the groupdelay of the Chebyshev ﬁlter less ﬂat. Since Chebyshev and elliptic ﬁlters can approximate Butterworth ﬁlters arbitrarily closely by making the ripples smaller and smaller. 2. With Butterworth ﬁlters.2. a tradeoff can be made between transitionwidth and passband ripple. ∗ Digital Filters with MATLAB Ricardo A. With Chebyshev type I ﬁlters. we want to look at how far from linear the phase response is. Of the classical IIR ﬁlters considered here∗ .4. it is clear that the amount of ripple is related to the amount of phase distortion. few applications require attenuations of hundreds of decibels. such large attenuations come at the price of a large transition width. we should really say that the tradeoff is between the transitionwidth and the amount of ripple/phasedistortion. With IIR ﬁlters. Butterworth ﬁlters have the least amount of phase distortion (phase nonlinearity). Therefore. Therefore.44 Basic IIR Filter Design of the Chebyshev ﬁlter can be made arbitrarily small. That exempliﬁes the tradeoff between passband ripple and transition width. but also the degree of phase distortion. it is possible to attain very large stopband attenuations with Butterworth or Chebyshev type I ﬁlters even when the ﬁlter is implemented using ﬁxedpoint arithmetic. this property is lost when the bilinear transformation is used to convert the ﬁlter from analog to digital. Bessel ﬁlters have maximallyﬂat groupdelay responses. Nevertheless. Losada . This illustrates that although the ﬁlters have the same order. A good way to look at this is to look at the groupdelay (which ideally would be constant) and see how ﬂat it is. a Chebyshev type I ﬁlter will have a larger transientdelay than a Butterworth ﬁlter. we show the groupdelay of the Butterworth and Chebyshev type I ﬁlters of the previous example in Figure 2. However. we not only need to consider the ripple/transitionwidth tradeoffs. when we refer to the tradeoff between ripples and transitionwidth.
4: Groupdelay responses for a 7thorder Butterworth and a 7thorder Chebyshev type I ﬁlter. Since extremely large attenuations are typically not required. Both ﬁlters have a 3dB point of 0.2 Classical IIR design Group Delay 30 45 Butterworth Chebyshev type I Group delay (in samples) 25 20 15 10 5 0 0 0. Although the Butterworth’s groupdelay is slightly Digital Filters with MATLAB Ricardo A.Ap'.2 0.0. design(Hf2.lowpass('N.F3db. The ﬁlter must have an attenuation of at least 80 dB at frequencies above 0. design(Hf1.F3db'.1 0. fdesign.6.8).3 0. Example 23 Design a 6th order ﬁlter with a 3dB point of 0.80).'cheby2').45). Hf1 Hf2 Hf3 Hb Hc1 Hc2 = = = = = = fdesign.75π and the passband ripple must not exceed 0.5 0.7 0. The groupdelay responses for the designs of the previous example are shown in Figure 2. Losada .2.6.9 Normalized Frequency (×π rad/sample) Figure 2. Only the Chebyshev type II ﬁlter reaches the required attenuation of 80 dB by 0.'cheby1').lowpass('N.3π. we may be able to attain the transitionwidth required by allowing for some stopband ripple. fdesign.6.F3db. These ﬁlters have maximallyﬂat passband and equiripple stopband.6. design(Hf3.5.0. The three designs are shown in Figure 2.45.0.45π.'butter').8 0.4 0.75π.6 0.8 dB.0.Ast'. In most cases a Chebyshev type II (inverse Chebyshev) ﬁlter is preferable to both a Chebyshev type I ﬁlter and a Butterworth ﬁlter.lowpass('N.45.
46 Magnitude Response (dB) 0 −10 −20 Basic IIR Filter Design Butterworth filter Chebyshev type I filter Chebyshev type II filter Magnitude (dB) −30 −40 −50 −60 −70 −80 0 0.5 0.9 1 Normalized Frequency (×π rad/sample) Figure 2.3 0.1 0. Losada .4 0. ﬂatter than that of the Chebyshev type II. and Chebyshev type II ﬁlters with a 3dB point of 0.7 0.2 0. the Chebyshev type II implementation actually requires more multipliers as we now explain.45π.9 Normalized Frequency (×π rad/sample) Figure 2. Digital Filters with MATLAB Ricardo A.5 0. the latter’s groupdelay is smaller than the former’s for most of the passband.4 0.5: 6th order Butterworth.3 0.7 0.8 0. Even though all three designs in the previous example are of 6th order.8 0. Group Delay 18 16 Group delay (in samples) Butterworth Chebyshev type I Chebyshev type II 14 12 10 8 6 4 2 0 0 0.6: Groupdelay responses for ﬁlters from Example 23.2 0.1 0.6 0.6 0. Chebyshev type I.
it may be preferable to breakup this scaling gain into several gains.8.'ellip'). 1} require no actual multiplications (the multiplication by two can be implemented with a simple shift). Hf4 = fdesign. at least 9 multipliers to implement. we can approximate arbitrarily close either Chebyshev or Butterworth ﬁlters using elliptic ﬁlters. the passband ripples of elliptic ﬁlters cause the groupdelay to become larger and more distorted than that of Butterworth or Chebyshev type II ﬁlters.. ∗ Digital Filters with MATLAB Ricardo A. As with Chebyshev type I ﬁlters. However.2.80). one per section. {1. The reduced transition band is attained by allowing for some amount of passband ripple.Ap. The result is that the numerators for all three sections are given by 1 + 2z−1 + z−2 . both the Butterworth ﬁlter and the Chebyshev type I ﬁlter can be implemented with 7 multipliers.5 Elliptic ﬁlters Elliptic (Cauer) ﬁlters generalize Chebyshev and Butterworth ﬁlters by allowing for ripple in both the passband and the stopband of a ﬁlter.Ast'. Since most applications can sustain some amount of passband ripple. 2. Example 24 Design an elliptic ﬁlter that meets the speciﬁcations of Example 23. By contrast. the Chebyshev type II design requires.45. In other words. because of dynamic range issues. He = design(Hf4. Chebyshev type II ﬁlters are maximallyﬂat in the passband and as a consequence have rather larger transition bands.2 Classical IIR design 47 All the designs result in three secondorder sections. There are two multiplications for each denominator of each section plus one more multiplier that provides the correct passband gain (0 dB)∗ . but the phase response (and consequently the groupdelay response) as well. The approximation is not just of the magnitude response.F3db. hence Chebyshev type II ﬁlters are generally preferable to Chebyshev type I and Butterworth ﬁlters. the transition band can be reduced by using an elliptic ﬁlter with the same amount of stopband attenuation as a Chebyshev type II ﬁlter (and the same ﬁlter order).0.2. For ﬁxedpoint implementations. However. We have already said that most applications do not require arbitrarily large stopband attenuations. Losada . By making the ripples smaller and smaller.6. the maximallyﬂat stopband of the Butterworth and Chebyshev type I ﬁlters is achieved by placing multiple zeros at w = π.lowpass('N. 2. The corresponding coefﬁcients.
If the target application does not beneﬁt from this the passband ripple can be reduced in order to have smaller passband distortion. Naturally.5 0. The groupdelay of the elliptic ﬁlter is similar but even less ﬂat than that of the Chebyshev type I ﬁlter.48 Magnitude Response (dB) 0 −10 −20 Basic IIR Filter Design Chebyshev type II filter Elliptic filter Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 −100 0 0. elliptic ﬁlters are the IIR version of optimal equiripple designs.2 0.9 Normalized Frequency (×π rad/sample) Figure 2. elliptic ﬁlters will result in the lowest ﬁlter order due to the permissibility of ripples in both passband and stopband.7 0.8 shows the groupdelay responses of the Chebyshev type I design of Example 23 and the elliptic design of Example 24. The resulting ﬁlter is shown in Figure 2.6 0.55π.63π rad/sample.1 0.2. far before the required 0. 2.45π and the passband must begin at 0. Example 25 Design a highpass IIR ﬁlter with a maximum passband ripple of 1 dB and a minimum stopband attenuation of 60 dB. The passband ripple allows for the 80 dB attenuation to be reached by about 0.4 0.45π.7 along with the Chebyshev type II ﬁlter we had already designed.8 0.7: Elliptic and Chebyshev type II ﬁlters with a 3dB point of 0. Digital Filters with MATLAB Ricardo A. In fact.6 Minimumorder designs We can use any of the design methods described above for design problems with ﬁxed passband/stopband ripples and ﬁxed transitionwidths.3 0. The stopband must extend to 0. Figure 2. Losada .75π.
The response of all four ﬁlters can be visualized using fvtool(Hd) (see Figure 2.2 0.1 0.45.4 0.60.7 0. Hf = fdesign. Hd(1) Digital Filters with MATLAB Ricardo A.3 0.6 0..8: Groupdelay response of elliptic and Chebyshev type I ﬁlters with a 3dB point of 0.45π.Ast.4 0.6 0. Hd = design(Hf. Hd is an array of ﬁlters.9 Normalized Frequency (×π rad/sample) Figure 2.9: Magnitude responses of highpass ﬁlters designed with all four classical design methods.1 0.2.3 0.Fp.8 0.2 Classical IIR design Group Delay 20 18 49 Chebyshev type I filter Elliptic filter Group delay (in samples) 16 14 12 10 8 6 4 2 0 0 0.highpass('Fst.1).2 0.Ap'. Losada .55.5 0.5 0.9).7 0.8 0.'alliir'). Magnitude Response (dB) 0 Butterworth Chebyshev type I Chebyshev type II Elliptic −10 Magnitude (dB) −20 −30 −40 −50 −60 0 0. Since we have designed all four ﬁlters.9 1 Normalized Frequency (×π rad/sample) Figure 2..
and Hd(4) the elliptic ﬁlter.50 Basic IIR Filter Design is the Butterworth ﬁlter. Maximum passband ripple: 1 dB 4. Losada . FcTW/2. This is because we are designing highpass ﬁlters rather than lowpass. the actual cost of Butterworth and Chebyshev type I ﬁlters is a little lower than what is indicated by the cost function as long as we are able to implement the multiplication by two without using an actual multiplier (the cost function does not assume that this is the case. Hd(2) is the Chebyshev type I. 80. Fc+TW/2.Ap.lowpass('Fp. elliptic ﬁlters do not have trivial numerators of the form 1 − 2z−1 + z−2 ∗ . Minimum stopband attenuation: 80 dB Fc = TW = Fp = Fst= Ap = Ast= Hf = ∗ 0.Ap.Ast'. We’d like to illustrate this with an example.0625π rad/sample 2. As with Chebyshev type II ﬁlters. cost(Hd(2))) we can see that the Butterworth ﬁlter takes the most multipliers (and adders) to implement while the elliptic ﬁlter takes the least. Cutoff frequency: 0. 1. 0. Digital Filters with MATLAB Ricardo A.2. Transition width: 0.7 Comparison to FIR ﬁlters We have said that one reason to use IIR ﬁlters is because of their small implementation cost when compared to FIR counterparts. 2.Fst. it is implementation agnostic). By inspecting the cost of each ﬁlter (e.Fst.g.008π rad/sample 3.008. fdesign.Ast). The Chebyshev designs are comparable. Notice the negative sign for the term 2z−1 .0625. Example 26 Consider the following design speciﬁcations: Speciﬁcations Set 4 1. Hd(3) the Chebyshev type II.Fp. In contrast.
the number of MPIS is the same as the number of multipliers. but of the number of multiplications per input sample (MPIS). the number of multipliers is halved to 321 (the number of adders remains 641).35π rad/sample 2. Lower/upper transition width: 0. Note that for the designs discussed so far.1π rad/sample 4. Upper cutoff frequency: 0. 51 the cost method indicates that 20 nontrivial multipliers and 20 adders are needed to implement the ﬁlter.2 Classical IIR design If we design an elliptic ﬁlter.'dfsymfir'). we will then go on to show that by using efﬁcient multirate IIR ﬁlters based on allpass decompositions. Maximum passband ripple: 0. cost(He). If we use a symmetric directform structure to implement the ﬁlter. In the following chapters we will see that with the use FIR multirate/multistage techniques we will be able to achieve designs that are more efﬁcient than the elliptic design shown here in terms not of the number of multipliers.'equiripple').'equiripple'. both the FIR and IIR cases (being singlerate). In addition to computational cost.'FilterStructure'.55π rad/sample 3. Heqs = design(Hf.2. However. let us compare with minimumphase FIR ﬁlters via an example. Lower cutoff frequency: 0. Example 27 Consider the following bandpass ﬁlter speciﬁcations: Speciﬁcations Set 5 1. An equiripple design. we can achieve even lower MPIS.'ellip'). requires a whopping 642 multipliers and 641 adders. Clearly there is not contest between the FIR and the IIR design. He = design(Hf. Losada .01 dB Digital Filters with MATLAB Ricardo A. Heq = design(Hf. another common reason for using IIR ﬁlters is their small groupdelay when compared to FIR ﬁlters. However.
3 0. = Fc2TW/2. In the passband. 5.Fst2. 0.9 Normalized Frequency (×π rad/sample) Figure 2.4 0. Losada . the Filter Design Toolbox includes design algorithms based Digital Filters with MATLAB Ricardo A. = Fc1+TW/2.Fp2. = 40.1 0. 2.55.6 0. = 0.8 0.5 0. [0.4π. Minimum stopband attenuation: 40 dB Fc1 Fc2 TW Fst1 Fp1 Fp2 Fst2 Ap Ast Hf = = 0.52 Group Delay Basic IIR Filter Design 25 Chebyshev type II Linear−phase FIR Minimum−phase FIR Group delay (in samples) 20 15 10 5 0 0 0. However.1.2 0.7 0. = 0. = Fc2+TW/2. fdesign.Ast).Ap. = Fc1TW/2. = 1e2.10: Groupdelays of FIR and IIR bandpass ﬁlters.10.3 IIR designs directly in the digital domain In addition to the classical methods based on bilinear transformation on analog designs.Ast. of all classical IIR designs.bandpass(Fst1. the Chebyshev type II will have the lowest group delay.Fp1.35. a minimumphase equiripple FIR ﬁlter has an even lower groupdelay in the passband as can be seen in Figure 2.5π ].
providing more ﬂexibility than classical designs.Fp.4. Example 28 The following design yields virtually the same ﬁlter as the elliptic design of Example 24: Hf5 = fdesign.Fp.75π and beyond.'iirlpnorm'. To illustrate the extra ﬂexibility afforded by independent control of the numerator and denominator orders.25).Fst'. Unlike classical IIR designs.. Moreover. the passband gain of the least pth norm design is not bounded by zero dB. we will use a 6thorder numerator and a 4thorder denominator and still meet the specs.'iirlpnorm'. Here.3 IIR designs directly in the digital domain 53 on optimization directly in the digital domain. we can verify that this ﬁlter is virtually identical to the elliptic ﬁlter within a scale factor. All designs we showed so far used a 6th order.4425. elliptic and Chebyshev type II...Na.lowpass('Nb.Na.4425.043 dB.'Wstop'. The design is shown along with the Chebyshev type II ﬁlter designed previously in Figure 2.2. the least pth norm ﬁlter has a steeper transition width thanks to the fact that there is some passband ripple. from leastsquares (2norm) all the way to inﬁnitynorms (equiripple).450). it is not possible to directly control the location of the 3dB point with the least pth norm design algorithm. consider the following example in which have a larger order numerator than denominator.6. The two designs that met the speciﬁcations. We have already stated that elliptic ﬁlters are optimal equiripple IIR ﬁlters. Hd = design(Hf5. would have failed to meet the speciﬁcations had a 4thorder been used instead.lowpass('Nb.'Wpass'.Fst'. The passband ripple is only about 0.. Digital Filters with MATLAB Ricardo A.75). Losada .1.63).8 dB passband ripple and at least 80 dB attenuation at 0.'Wstop'. Despite using less multipliers than the Chebyshev type II ﬁlter. Essentially the same ﬁlters can be designed use the iirlpnorm design algorithm if the L∞ norm is used as the pth norm.1. We should note that unlike the classical IIR designs. Hd = design(Hf5. However.11. Example 29 We want to use the iirlpnorm function to design a ﬁlter with less than 0. Hf5 = fdesign. these digitaldomain designs allow for optimization of different norms.'Wpass'. The advantage of these algorithms is that they allow for independent control of the numerator and denominator orders.6.6. if we normalize the passband gain to 0 dB.
making elliptic ﬁlters usually the way to go. Also shown is the Chebyshev type II ﬁlter design in Example 23. Further ﬂexibility can be obtained by controlling individually the numerator and denominators orders.3 0. stability issues when using ﬁniteprecision arithmetic. implementation complexity.9 Normalized Frequency (×π rad/sample) Figure 2. pipelineability and so forth. we may be able to obtain more efﬁcient designs without the drawbacks of IIR ﬁlters.11: Least pth norm IIR ﬁlter with a 6th order numerator and a 4th order denominator. However.1 0.2 0. Losada . 2.7 0. Elliptic ﬁlters are IIR optimal equiripple ﬁlters that use the smallest ﬁlter order possible to meet a set of speciﬁcations involving ripples and transition band.6 0.54 Magnitude Response (dB) 0 −10 −20 Basic IIR Filter Design Chebyshev type II filter IIRLPNORM filter Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 0 0. We will study such Digital Filters with MATLAB Ricardo A. However.8 0. Butterworth and Chebyshev ﬁlters are special cases of elliptic ﬁlters with zero passband and/or stopband ripples. IIR ﬁlters (elliptic in particular) can meet a set of speciﬁcations with far fewer multipliers than what an FIR ﬁlter would require.4 0. Least pth norm designs allow for such control. This is particularly true when ripples are allowed in the passband and/or stopband of the ﬁlter.4 Summary and look ahead Tradeoffs and degrees of freedom in IIR ﬁlter design are essentially the same as those in FIR ﬁlter design.5 0. If the design speciﬁcations are wellsuited for a multirate/multistage FIR ﬁlter design. most applications can sustain some amount of ripple. there is a price to pay in terms of phase distortion.
Losada . IIR ﬁlters may be preferable (although minimumphase FIR ﬁlters can be an interesting option as we have seen). we point out once again that these multistage implementations tend to have large transient delays. so that if this is a critical factor.4 Summary and look ahead 55 approaches in the coming chapters. However. Digital Filters with MATLAB Ricardo A.2.
L = 2 is widely used and is referred to as Halfband ﬁlters. as we will see. Nyquist ﬁlters are typically designed via FIR approximations. The special case. IIR designs are also possible. we will see a special property of Nyquist ﬁlters when used in multirate applications. Halfband ﬁlters can be very efﬁcient for interpolation/decimation by a factor of 2.Chapter 3 Nyquist Filters Overview Nyquist ﬁlters are a special class of ﬁlters which are useful for multirate implementations. Nyquist ﬁlters are also called Lthband ﬁlters because the passband of their magnitude response occupies roughly 1/L of the Nyquist interval. This makes Nyquist ﬁlters highly desirable for multistage designs. Nyquist ﬁlters have very small passband rip . Later. The widely used raisedcosine ﬁlter is a special case of Nyquist ﬁlter that is often used in communications standards. The IIR case results in extremely efﬁcient ﬁlters and through special structures such as parallel (coupled) allpassbased structures and wave digital ﬁlters can be efﬁciently implemented for multirate applications. We will show FIR and IIR designs of halfband ﬁlters. However. The cascade of Nyquist interpolators (or decimators) results in an overall Nyquist interpolator (or decimator). Nyquist ﬁlters also ﬁnd applications in digital communications systems where they are used for pulse shaping (often simultaneously performing multirate duties). Moreover. in Chapter 5.
Losada . 3. Nonetheless. the most common design of a Nyquist ﬁlter is as a special case of a lowpass ﬁlter. When designing a Nyquist ﬁlter.84. This is particularly true for IIR Nyquist ﬁlters. A characteristic of Nyquist ﬁlters is that every Lth sample of their impulse response is equal to zero (save for the middle sample). for both interpolation and decimation purposes. In most cases. This happens sometimes with Kaiserwindow designs because the relation between the adjustable parameter in the Kaiser window and the stopband attenuation is derived in somewhat empirical fashion. it means that one of the L polyphase branches will result in a simple delay (no multipliers/adders) reducing the implementation cost Close inspection of the stopband will show that the 80 dB attenuation is not quite achieved. Note that the peak to peak ripples are indeed quite small (on the order of 2 × 10−3 ). the passband ripple and the stopband ripple cannot be independently speciﬁed.1.'kaiserwin'). This makes Nyquist ﬁlters ideally suitable for embedded applications.3. Moreover. Therefore.1 Design of Nyquist ﬁlters Although not strictly necessary. With Nyquist ﬁlters. this characteristic is desirable for interpolation because it means that the input samples will pass through the ﬁlter unchanged.1 Design of Nyquist ﬁlters 57 ple even when the ﬁlter is quantized for ﬁxedpoint implementations.'N. only the stopband ripple (and/or the transition width) will be given. Both the transitionwidth and the passband ripple of the ﬁlter are a result of the design.2π in this case). The passband details of the magnitude response are shown in Figure 3.80).nyquist(L. % 5thband Nyquist filter f = fdesign. The ﬁlter has a cutoff frequency given by π/L (0. As we will see when we discuss multirate ﬁlter design. L = 5. the resulting passband ripple is very small. h = design(f. highpass and bandpass designs are also possible. in all designs. the value of the band L must be speciﬁed. Nyquist ﬁlters will reduce the bandwidth of a signal by a factor of L.Ast'. Example 30 Design a Kaiser window 5thband Nyquist FIR ﬁlter of 84th order and 80 dB of stopband attenuation∗ . The passband ripple will be a result of the design. ∗ Digital Filters with MATLAB Ricardo A.
58 Magnitude Response (dB) Nyquist Filters x 10 8 6 4 −4 Magnitude (dB) 2 0 −2 −4 −6 −8 0 0.2. In that case. The impulse response for the ﬁlter designed in Exampled 30 can be seen in Figure 3.1: Passband ripple details for 5thband Nyquist FIR ﬁlter designed with a Kaiser window. equiripple designs are possible. Equiripple designs may have convergence issues for large order/small transition width combinations and may result in bogus ﬁlters.1.06 0. ∗ Digital Filters with MATLAB Ricardo A.1 Equiripple Nyquist ﬁlters If instead of specifying the order and stopband attenuation of an FIR Nyquist ﬁlter design we specify the order and transition width or the transition width and the stopband attenuation.04 0.08 0.1 0. symmetry characteristics of the magnitude response about the 0. It must be pointed out however that it is not trivial to design equiripple FIR Nyquist ﬁlters given the timedomain constraint (the fact that the impulse response must be exactly zero every L samples). Losada .5π point result in same passband/stopband ripples. 3. Filters with equiripple passband and sloped stopband are also possible∗ Although equiripple designs are possible.02 0. Note that every 5th sample is equal to zero except for the middle sample which is the peak value of the impulse response.14 Normalized Frequency (×π rad/sample) Figure 3. their advantages relative to Except in the halfband (L=2) case. Therefore a sloped stopband will also mean a sloped passband. for such branch.12 0.
3. design(f. In particular.20). f h h2 h3 = = = = fdesign.1 0.3.1).15 Amplitude 0.'StopbandShape'. The passband ripple details are shown in Figure 3. Moreover. While it is clear that the Kaiserwindow design has the smallest minimum stopband attenuation.05 0 10 20 30 40 50 60 70 80 Samples Figure 3.'kaiserwin').'linear'.2 59 0.1 Design of Nyquist ﬁlters Impulse Response 0. Every 5th sample is equal to zero (except at the middle).'StopbandDecay'. Kaiserwindow designs are not as clear for Nyquist ﬁlters as they are for regular ﬁlter designs.nyquist(4. the passband ripples of Kaiserwindow designs may be smaller than those of equiripple designs. as we will see in Chapter 4.72..'equiripple').'N. design(f. Example 31 We will compare a Kaiser window design to both an equiripple design with and without a sloped stopband. The magnitude responses are shown in Figure 3.'equiripple'.2: Impulse response of 5thband Nyquist FIR ﬁlter. % 4thBand Nyquist filter design(f.TW'. the increasing attenuation in the stopband may be desirable for interpolation and especially for decimation purposes.4. the Kaiser window design results in better passband ripple performance than either equiripple design (this can be veriﬁed with the measure command). Losada . Moreover. it does provide increased stopband attenuation as frequency increases. Digital Filters with MATLAB Ricardo A.05 0 −0.
1 0.1π. equiripple.2 0.01 Magnitude (dB) 0.3: Comparison of Kaiser window.06 0.08 0.7 0.015 0 0. and sloped equiripple Nyquist ﬁlter designs of 72nd order and a transition width of 0.2 Normalized Frequency (×π rad/sample) Figure 3.5 0.6 0. Magnitude Response (dB) 0.015 Kaiser window Equiripple Sloped equiripple 0.14 0.60 Magnitude Response (dB) 0 −10 −20 Nyquist Filters Kaiser window Equiripple Sloped equiripple Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 0 0.04 0.1 0.8 0.4: Passband ripple details for ﬁlters designed in Example 31.12 0.18 0.005 −0.02 0.4 0.3 0.01 −0. Losada .005 0 −0.9 Normalized Frequency (×π rad/sample) Figure 3. Digital Filters with MATLAB Ricardo A.16 0.
fdesign.'kaiserwin'). the maximum peaktopeak passband ripple of each design will be different (of course so to will be the resulting ﬁlter order).'equiripple'). design(f.Ast'. 3. As such.e. Example 32 Consider the following design examples. It is important to note that while the minimum stopband attenuation is the same for both designs. As previously stated.60). f f2 hk he hk2 he2 = = = = = = fdesign. This of course makes them very efﬁcient to implement.0.'TW. the peaktopeak passband ripple of Kaiser window designs tends to be smaller.50). Both cases illustrate the tradeoff between ﬁlter order and passband ripple for Nyquist ﬁlter design choices. In the case of halfband ﬁlters this fact is particularly appealing since it means that roughly half of its coefﬁcients are equal to zero. Losada . compare the results of the measure command and the cost command for both Kaiser window designs and equiripple designs.0.'kaiserwin').Ast'.'equiripple').'TW. This ﬁlters reduce the bandwidth of a signal roughly by half and are suitable for decimation/interpolation by a factor of 2 (see Chapter 4).2 Halfband ﬁlters Halfband ﬁlter are a special case of Nyquist ﬁlters when L = 2.1. design(f. may make Kaiser window designs appealing despite the slightly larger implementation cost.1.3.2 Halfband ﬁlters 61 3. What is interesting is that while equiripple designs tend to be of smaller order. halfband Digital Filters with MATLAB Ricardo A. design(f2.2 Minimumorder Nyquist ﬁlters It is possible to design either equiripple or Kaiserwindow FIR ﬁlters that meet a transitionband requirement as well as a minimumstopband requirement with minimum order. This coupled with the increased overall attenuation in the stopband due to its nonequiripple nature.2.nyquist(8. every Lth ﬁlter coefﬁcient) is equal to zero.nyquist(4. design(f2. Nyquist ﬁlters are characterized by the fact that every Lth sample of its impulse response (i.
Ast'.N. the equiripple designs will have either a larger minimum stopband attenuation.1).Ast).0.2. The speciﬁcations set follow the usual triangle metaphor shown in Figure 1.75). In addition to that. Losada . For a given set of speciﬁcations. Similarly. In each case. there are usually no convergence issues with equiripple halfband ﬁlter designs.1. f3 = fdesign. the stopband ripple automatically determines the passband ripple). Moreover.0.N. a smaller transition width.5π. the advantages of optimal equiripple designs over Kaiser window designs resurface in a more clear manner than for other Nyquist ﬁlters. the passband and stopband ripples are identical. f2 = fdesign.Ast'.halfband('N.50.Ast'. either Kaiser window or equiripple FIR designs are possible. f = fdesign. Unlike the general case.halfband('TW. Example 33 Consider Kaiser window and equiripple designs for the following to cases: f = fdesign. or a smaller number of coefﬁcients. using the cost command in the second case shows that the same performance is achieved with fewer coefﬁcients in the equiripple case.62 Nyquist Filters ﬁlters are widely used in particular for multirate applications including multistage applications (see Chapter 5). Moreover. In all three cases. taking into account the limitations just described. As such. Digital Filters with MATLAB Ricardo A.halfband('TW. it is also possible to design leastsquares FIR ﬁlters.TW'. in the ﬁrst case. the resulting peaktopeak passband ripples will be about the same.TW). the fact the passband ripple is the same as the stopband ripple means that regardless of the design algorithm.TW'. Using the measure command in the ﬁrst case shows that the resulting stopband attenuation (and consequently the passband ripple) is better in the equiripple case.halfband('N. three different speciﬁcations are available for halfband designs.halfband('N.Ast). The cutoff frequency for a halfband ﬁlter is always 0. two of the three angles of the triangle are speciﬁed (as just stated. limiting the degrees of freedom in the design. So for halfband ﬁlters. f2 = fdesign.TW.
3. in the case of IIR ﬁlters.1) 2 ˆ ˆ with A0 (z) = A0 (z2 ) and A1 (z) = z−1 A1 (z2 ). These ﬁlters are extremely efﬁcient especially when implemented as two allpass branches in parallel. the input samples are preserved unchaged (just delayed). Therefore. Losada . In Chapter 5 we will show that using IIR halfbandbased multirate/multistage designs result in extremely efﬁcient ﬁlters that outperform FIR counterparts. In particular. However. ˆ The reason some IIR halfbands are not Nyquist.2 Halfband ﬁlters 63 Sloped equiripple designs are also possible. As a result of this. Such implementations are ideally suited for polyphase multirate architectures (see Chapter 4). Butterworth and elliptic designs result in nonNyquist halfbands. For IIR halfband ﬁlters. A0 (z2 ) = z− D for some integer D. although they can be used for polyphase decimation/interpolation.1 IIR halfband ﬁlters Nyquist ﬁlters can also be designed as IIR ﬁlters. However. it is not possible to design halfband Chebyshev ﬁlters. it is important to point out that IIR halfbands are not necessarily Nyquist ﬁlters.3. Unlike the FIR case. they will result in similarly sloped passbands. given the symmetry constraints on halfband ﬁlters. A design algorithm synthesized directly in the digital domain [22] results in approximately linear phase in the passband of the ﬁlter (at the expense of either higher order or reduced stopband attenuation compared to elliptic halfbands). it will not be true that the input samples are preserved unchanged at the output. the parallel allpass decomposition (8. in the case of approximately ˆ A1 ( z ˆ linear phase designs.2. the symmetry is about the halfpower point (3 dB point) rather than the halfmagnitude point (6 dB point) of FIR halfbands. The most interesting case is that of halfband IIR ﬁlters [20][21].1) becomes 1 ˆ 2 ˆ A 0 ( z ) + z −1 A 1 ( z 2 ) (3. in the interpolation case. Because of this symmetry. but in the case of halfband ﬁlters. H (z) = Digital Filters with MATLAB Ricardo A. is that A0 (z2 ) and 2 ) may not be equal to a delay. Only Butterworth and elliptic halfband ﬁlters are possible from the classical designs. the ﬁlter is Nyquist and when used for interpolation. IIR halfband ﬁlters have similar symmetry constrains as FIR halfbands.
5 −1 −7 Magnitude (dB) −1. The fact the we specify a 70 dB minimum stopband attenuation results in a peaktopeak passband ripple of only 4 × 10−7 dB! f = fdesign. Either case is signiﬁcantly more efﬁcient than FIR equiripple halfband.'iirlinphase').2 0.5 0 0. limits the appeal of Butterworth halfband ﬁlters. In all cases. the resulting passband ripples of IIR halfband ﬁlters is very small. Elliptic halfbands are the most efﬁcient while quasilinear phase halfbands give up some efﬁciency in the name of phase linearity.halfband('N. This fact coupled with the fact that (as previously stated) many applications do not require hundreds of decibels of stopband attenuation.12.70).25 Normalized Frequency (×π rad/sample) Figure 3. Minimumorder designs Minimumorder designs provide a good framework to compare implementation cost of FIR halfband ﬁlters vs. The passband details are shown in Figure 3. Losada .5 −4 −4. h = design(f. IIR halfbands.5: Passband details of quasilinear phase IIR halfband ﬁlter with 70 dB of stopband attenuation. Example 34 Consider the following quasilinear phase IIR halfband design. given only moderate stopband attenuations.64 Magnitude Response (dB) Nyquist Filters x 10 0 −0.5 −3 −3.Ast'.5 −2 −2. Digital Filters with MATLAB Ricardo A.1 0.15 0.05 0.5.
f = hlp hel heq fdesign. it is also the one with the most nonlinear phase.6 0.'ellip'). the quasilinear phase IIR design requires 15 multipliers.'equiripple'). while the elliptic design requires only 6 multipliers. we can see that the FIR equiripple design requires 35 multipliers.'iirlinphase').1 0. = design(f. They tend to result in efﬁcient designs because of the fact that every Digital Filters with MATLAB Ricardo A. Losada .3 0.60). The passband groupdelay of the quasilinear phase design is almost ﬂat as expected (see Figure 3.Ast'. = design(f. Using the cost command. A plot of the groupdelay of all three ﬁlters shows that while the elliptic design clearly has the lowest group delay. Example 35 Compare the following three minimumorder designs. yet it is orders of magnitude larger than the passband ripple of either IIR design.4 0.3 Summary and look ahead Nyquist ﬁlters have very useful properties that make them worth considering.3.halfband('TW. = design(f.8 0.3 Summary and look ahead Group Delay iirlinphase 40 65 ellip equiripple Group delay (in samples) 35 30 25 20 15 10 5 0 0.9 Normalized Frequency (×π rad/sample) Figure 3. 3.6: Groupdelay comparison for IIR and FIR halfband ﬁlters.6).7 0.5 0.1.2 0. The passband ripple of the equiripple design is quite small.0.
The three halfband ﬁlters in cascade act a single Nyquist ﬁlter (the equivalent impulse response of the cascade will have a value of zero every 8th sample) but can be signiﬁcantly more efﬁcient than a singlestage design. Losada . Nyquist ﬁlters (FIR or IIR) should be the ﬁrst choice for multirate applications (see Chapter 4). The fact that their cutoff frequency is given by π/L results in transitionband overlap in decimation applications. For example. Given all their advantages. Digital Filters with MATLAB Ricardo A. Halfband ﬁlters are particularly interesting given their high efﬁciency. a decimation/interpolation ﬁlter with a rate change of say 8 can be implemented as a cascade of three halfband decimation/interpolation ﬁlters (each with a rate change of 2). This is particularly true if IIR halfband designs are used. IIR halfband ﬁlters are even more efﬁcient and have extremely small passband ripples. we will see (Chapter 5) that cascade multirate Nyquist ﬁlters possess an interesting property: the overall equivalent multirate ﬁlter is also Nyquist. They also tend to have very small passband ripples.66 Nyquist Filters lth sample of their impulse response is zero. This however is not a problem given that no aliasing will occur in the band of interest ((see Chapter 4 and Appendix B.) Moreover.
We will see that the above statement applies whether the bandwidth is decreased by an integer or a fractional factor. We want to emphasize the following: if you reduce the bandwidth of a signal through ﬁltering. a ﬁlter is usually required. you should reduce its sampling rate accordingly. described in Chapter 3. We then use this to However. Whether we are increasing or decreasing the sampling rate of a signal. We present ﬁrst interpolation as simply ﬁnding samples lying between existing samples (not necessarily increasing the sampling rate).∗ Nyquist ﬁlters. Digital ﬁlters are a key part of multirate signal processing as they are an enabling component for changing the sampling rate of a signal. as we will see. The main reason to use multirate signal processing is efﬁciency. are the preferred design to use for multirate applications.Chapter 4 Multirate Filter Design Overview Multirate signal processing is a key tool to use in many signal processing implementations. highpass. The most common ﬁlter type used for multirate applications is a lowpass ﬁlter. If multirate concepts are not fresh. ∗ . bandpass and in general any ﬁlter that reduces the bandwidth of a signal may be suitable for multirate applications. Understanding fractional samplingrate reduction requires understanding interpolation. it may be helpful to read through Appendix B prior to reading through this chapter. In this chapter we will talk about designing ﬁlters for multirate systems. We start by presenting ﬁlters in the context of reducing the sampling rate of a signal (decimation).
Speciﬁcally. The idea is depicted in Figure 4. Finally we extend this paradigm in order to perform fractional decimation/interpolation. When the bandwidth of a signal is reduced. Otherwise. or transmission of such redundant data will result in unnecessary use of resources. The ﬁlter H (z) is a lowpass ﬁlter that roughly reduces the bandwidth by a factor of M. given that we are oversatisfying the Nyquist sampling criterion. We have concentrated mostly on lowpass ﬁlters. we are left with redundant data. Digital Filters with MATLAB Ricardo A.1 Reducing the sampling rate of a signal In the previous chapters we have discussed the basics of FIR and IIR ﬁlter design. A lowpass ﬁlter reduces the bandwidth of the signal being ﬁltered by some factor. we usually want to reduce the sampling rate in a commensurate manner. Any processing. 4. We can downsample y[n] by keeping one of every M samples ydown [m] = y[nM ]. Once the bandwidth is reduced. However.1 Decimating by an integer factor If M is an integer the procedure is straightforward. 4. All the computation involved in obtaining the other M − 1 samples is wasted. if the input signal x [n] has a bandwidth Bx and the ﬁltered signal y[n] has a bandwidth By related to the input bandwidth by Bx =M By we should reduce the sampling frequency of y[n] by a factor of M. only one sample kept.1.68 Multirate Filter Design show how to increase the samplingrate of a signal by an integer factor. the samplingrate should be reduced accordingly. The downsampler that follows H (z) reduces the sampling rate by keeping one out of every M of its input samples. the procedure as described so far is inefﬁcient in that after the ﬁlter processes a set of M samples. Losada .1 and is referred to as decimation. storage.
[23].2. the average number of multiplications per input sample + (MPIS) is NM 1 .4.2: FIR ﬁlter implemented in directform followed by a downsampler.1 Reducing the sampling rate of a signal 69 Figure 4. Figure 4.1: Reducing the sampling rate after the bandwidth of the signal is reduced. There is no point computing all additions/multiplications indicated only to throw out the result of most of them. To illustrate the idea consider an FIR ﬁlter implemented in directform followed by a downsampler by M as shown in Figure 4. it is not straightforward to implement the Digital Filters with MATLAB Ricardo A. for IIR ﬁlters. even though the ﬁlter still requires N + 1 multipliers.3. Instead. In other words. That is of course a savings of a factor of M on average. Efﬁcient FIR ﬁlters stemming from decimation For FIR ﬁlters. For any ﬁlter of length N + 1 (order N). they are only used once every M samples. a better paradigm is easy to implement in which we never actually compute any of the samples that we would throw away anyway. Unfortunately. Losada . The idea is shown in Figure 4. we can downsample before the multipliers so that only computations that are required are performed [3]. [24].
Of course. In order to answer this. In the same way that sampling an analog signal introduces spectral replicas of the analog signal’s spectrum. There is a way to implement decimation efﬁciently with certain IIR designs using an allpassbased decomposition as described in §8.2. the distortion in the passband. consider what happens to the output signal once it is downsampled by M (see also Appendix B). Losada . In the case of downsampling. We will discuss these efﬁcient multirate IIR ﬁlters later. We’d like to explore how does using a nonideal ﬁlter come into play when we decimate.3: Efﬁcient FIR decimation. and the nonzero width transition band between passband and stopband. downsampling a digital signal introduces replicas of its spectrum. the number of replicas introduced Digital Filters with MATLAB Ricardo A. with practical ﬁlters we have to worry about the ﬁnite amount of attenuation in the stopband. Determining the decimation factor So far we have described a ﬁlter that reduces the bandwidth by a factor M as if it were an ideal ﬁlter. procedure shown due to the feedback.70 Multirate Filter Design Figure 4.1.
Aliasing invariably occurs because of the ﬁnite amount of stopband attenuation.2 0. The energy in the stopband is large and it all aliases into the spectrum of the signal we are interested in.1 Reducing the sampling rate of a signal 71 Spectral replicas after decimation 0 −10 −20 Magnitude spectrum of signal after decimation Spectral replica Spectral replica Magnitude (dB) −30 −40 −50 −60 −70 −80 −1 −0.8 −0.4.4: Spectrum of decimated signal with ωst = π/M along with spectral replicas. Also notice that the usable bandwidth extends from zero to the passbandedge frequency.6 −0. The passbandedge frequency in this case is given by π/M − Tw .6 0. Digital Filters with MATLAB Ricardo A. For illustration purposes. we are showing the worstcase scenario). However.4.4 −0. Notice the problem with using ﬁlters with equiripple stopband when decimating. is equal to M − 1. presumably we select the amount of stopband attenuation so that the aliasing is tolerable. The spectrum of the decimated signal along with the replicas are shown in Figure 4. First let’s look at the latter case. We’d like to compare two different cases. assume M = 3 and assume that the spectrum of the signal to be ﬁltered is ﬂat and occupies the entire Nyquist interval. and another in which the stopbandedge frequency is π/M. where Tw is the transitionwidth. This means that the spectrum of the output signal (prior to downsampling) will take the shape of the ﬁlter.8 1 Normalized Frequency (×π rad/sample) Figure 4. Losada . The conclusions we will reach are valid for any value of M and any input signal (but the aliasing will be lower than what we show if the input signal is already somewhat attenuated in the stopband. one in which the cutoff frequency is π/M.2 0 0.4 0.
ωst = π/M. Notice that we have used a sloped stopband to reduce the total amount of aliasing that occurs. Losada . In practice. Now let’s look at the case where the cutoff frequency is set to π/M. or ωc = π/M are valid. the usable passband extends now to π/M − Tw /2 where once again Tw is the transition width.5: Spectrum of decimated signal with ωc = π/M along with spectral replicas.4 −0. While both selections. Of course this could have been done in the previous case as well.2 0. Given that for FIR ﬁlters the ﬁlter order grows inversely proportional to the transition width. This is not a problem since that region is distorted by the ﬁlter anyway so that it should not contain any information of interest. we would have to make transition width of the case ωst = π/M half as wide as the transition width of the case ωc = π/M. The spectrum of the decimated signal along with its corresponding replicas for this case are shown in Figure 4. this would imply having to increase the ﬁlter order by a factor of about two in order to obtain the same usable bandwidth with ωst = π/M.6 −0.5. There are clear advantages to using ωc = π/M.8 −0. we usually have some Digital Filters with MATLAB Ricardo A. the transition bands alias into each other.2 0 0.4 0. Recall that for FIR ﬁlters the cutoff frequency is typically located at the center of the transition band.8 1 Normalized Frequency (×π rad/sample) Figure 4. This means that the usable passband is larger in this case than in the case ωst = π/M by Tw /2. Since the cutoff frequency is in the middle of the transition band. In order to have the same usable passband in both cases.6 0.72 Multirate Filter Design Spectral replicas after decimation 0 −10 −20 Magnitude spectrum of signal after decimation Spectral replica Spectral replica Magnitude (dB) −30 −40 −50 −60 −70 −80 −1 −0. Also.
In §2. An optimal equiripple ﬁlter requires 642 multipliers if we do not take advantage of the symmetry in the ﬁlter coefﬁcients.'Nyquist'.'kaiserwin').4.008. Since an Mthband Nyquist ﬁlter has a cutoff frequency of π/M.decimator(4. consider an audio signal. we can use the efﬁcient decimation techniques described above to implement the FIR ﬁlter with an average of 40. Digital Filters with MATLAB Ricardo A. All this to say that usually the decimation factor M should still be selected as the ratio ωc /π even when the nonideal nature of practical FIR ﬁlters is taken into consideration. For instance. 0. it is wellsuited for applications in which we want to reduce the sampling rate by a factor of M.∗ M Fc TW Fp Fst ∗ = = = = = 16.1. That means there is 4. given that the cutoff frequency is π/16.0. We can simultaneously reduce the sampling rate by a factor of 4 by designing a decimator Nyquist ﬁlter. Losada .'TW. h = design(f.6 we saw that for the speciﬁcation set 4 an elliptic IIR ﬁlter requires 20 multipliers and 20 MPIS to implement assuming a directform II secondorder sections implementation. This ﬁts in well with the use of Nyquist ﬁlters. FcTW/2.1 kHz.1 Reducing the sampling rate of a signal 73 amount of excess bandwidth in a sampled signal so that the aliasing that occurs in the transition band does not affect the application. See [11] for more on this.125 MPIS even without taking advantage of the symmetric coefﬁcients.1/2 kHz available at each side of the spectrum for transition bands of ﬁlters. Example 36 A 4thband Nyquist ﬁlter reduces the bandwidth by a factor of 4. f = fdesign.2. An efﬁcient decimation structure that does take advantage of the symmetry in the coefﬁcients is shown on page 77 of [24]. Fc+TW/2.60). but the maximum frequency we are interested in is 20 kHz.4. Computational savings with FIR decimators We’d like to return to the comparison between an FIR and an IIR ﬁlter that meet the same set of speciﬁcations. However. % Decimation factor 0. The most common sampling frequency is 44.Ast'.0625.
Hd = design(Hf. ∗ Digital Filters with MATLAB Ricardo A. h = design(f.decimator(2. Ast = 80. cost(Hd) Through the use of multirate techniques.0.'lowpass'.decimator(M.'halfband'. FIR or IIR halfband ﬁlters can be used to very efﬁciently implement the ﬁlter. We will see that multistage/multirate designs and in particular multistage Nyquist multirate designs will be the most efﬁcient of all approaches looked at for these speciﬁcations. In Appendix C we study various approaches to ﬁlter design for these same speciﬁcations. cost(h) Equiripple designs do not converge for these speciﬁcations given the Nyquist constraint on the impulse response. This is true despite the fact that such multistage Nyquist designs also will vastly oversatisfy the passband ripple requirements..Ast). a Kaiserwindowdesigned∗ Nyquist ﬁlter would require more computations per input sample than a regular lowpass ﬁlter. In the FIR case.Ast'. the Kaiserwindow design will have a mere 0.'TW.74 Multirate Filter Design Ap = 1.'Fp. Example 37 Consider the following design: f = fdesign.Fst.Fst. With the given speciﬁcations.. we still have perfect linear phase and no stability issues to worry about. we are within a factor of two of the number of MPIS required to implement an IIR ﬁlter that meets the speciﬁcations. The cost to pay for this vast oversatisfying of the speciﬁcations is a computational cost of 73..Ap.Ap. Fp.'equiripple'). The main reason is the passband ripple. if the cutoff frequency is set to π/2 (and transitionband aliasing is tolerated).1. Losada .80). However.6875 MPIS. For the case just discussed.'equiripple'). Decimating by a factor of 2 When reducing the bandwidth/decimating by a factor of two.Ast'.0015986 dB of passband ripple. Hf = fdesign. the halfband decimator by 2 takes full advantage of the fact that about half the ﬁlter coefﬁcients are zero.
4.1 Reducing the sampling rate of a signal 75 Figure 4. the elliptic design is the most efﬁcient. The idea is two make use of the fact that conceptually. In the IIR case.6: Allpassbased IIR polyphase implementation of decimation by 2. a further gain factor of two is obtained in computational cost. it is simple to obtain the implementation shown in Figure 4. By reducing the sampling rate.1) and the Noble identities. The number of MPIS is 24. Digital Filters with MATLAB Ricardo A. it only requires 49 multipliers. Let’s look at the computational cost of using an IIR halfband ﬁlter for the speciﬁcations from the previous example.5.'iirlinphase'). Example 38 For the same speciﬁcations contained in the variable f above. h2 = design(f. decimation is lowpass ﬁltering followed by downsampling.6.'ellip'). requiring only 6 multipliers and 3 MPIS. The halfband is already efﬁcient in that for a ﬁlter of length 95. efﬁcient allpassbased polyphase implementations are possible for halfband designs. the iirlinphase design requires 19 multipliers and 9.5 MPIS. If approximate linear phase is desired. we can design either an elliptic halfband decimator or a quasi linear phase halfband decimator: h1 = design(f. Note that use of the Noble identities means that the allpass ﬁlters are now given in terms of powers of z rather than of z2 . cost(h1) cost(h2) As usual. By using (3. Losada .
Example 39 For example.8 Normalized Frequency (×π rad/sample) Figure 4. we can continue to use the efﬁcient implementation we showed since the directform structure can be used regardless of the response type of the ﬁlter.6 0. If a highpass halfband ﬁlter is used. If we downsample the ﬁltered signal by a Digital Filters with MATLAB Ricardo A. the output signal will have the spectrum of the ﬁlter.2 0.8 −0. consider using a highpass ﬁlter that reduces the bandwidth by a factor M = 3. and the input to the ﬁlter has a ﬂat spectrum. Losada . The bandpass signal and its baseband equivalent contain the same information. The resulting signal after downsampling is called the baseband equivalent of a bandpass signal. If we use a highpass or a bandpass ﬁlter to reduce the bandwidth by an integer factor M.7.76 Multirate Filter Design Magnitude spectrum of highpass−filtered signal 0 −10 Magnitude (dB) −20 −30 −40 −50 −60 −70 −1 −0. As long as the ﬁlters are FIR. Something like what is shown in Figure 4.2 0 0. We could for instance generate an analog bandpass signal that corresponds to the digital bandpass signal by starting from the baseband equivalent.4 0. we would still want to reduce the sampling frequency accordingly.4 −0. efﬁcient polyphase IIR designs are a possibility as well.7: Spectrum of highpassﬁltered signal. Any further processing at baseband is less costly because we use fewer samples once the sampling frequency is reduced.6 −0. Decimating with highpass/bandpass ﬁlters The motivation to reduce the sampling rate whenever the bandwidth of a signal is reduced remains true regardless of the shape of the ﬁlter used to reduce the bandwidth. If we do not downsample.
Notice that in this case. Notice that the previous example amounts to removing the “white space” that arises after highpass ﬁltering. factor of M. Even if the ﬁlter were ideal. In this example.3 −0. However. The cases k = 0 and k = M − 1 correspond to lowpass and highpass ﬁlters respectively. These cases are thus never a problem. its response needs to be such that it retains a bandwidth M times smaller than the Nyquist interval and lying in one of the intervals kπ/M < ω  < (k + 1)π/M k = 0.1 0 0. . 1. Nevertheless. but we only show the portion of the Nyquist interval that corresponds to the downsampled signal. . π/3]. M − 1.3 Normalized Frequency (×π rad/sample) Figure 4. . we best not waste resources by processing information corresponding to that band.2 0. . The spectrum is shown relative to the high sampling frequency. There are some restrictions as to where the bandpass that is retained lies relative to the sampling rate [24]. Losada .2 −0. the resulting spectrum is moved to baseband as shown (along with the aliasing from replicas) in Figure 4.1 Reducing the sampling rate of a signal 77 Spectrum after decimation 0 −10 −20 Alias from spectral replicas Magnitude spectrum of signal after decimation Magnitude (dB) −30 −40 −50 −60 −70 −80 −0. Since the energy in the signal is negligible in this white space. For this reason. the amount of aliasing is controlled by the stopband attenuation. as before.8: Spectrum of downsampled highpassﬁltered signal.8. the interval plotted is [−π/3. some of the aliasing comes from the replicas and some of it is “selfinﬂicted” so to speak. if the Digital Filters with MATLAB Ricardo A.1 0. no single replica introduces more than 60 dB of aliasing in the usable passband.4.
'equiripple'). 3. we should still try to downsample as much as possible. 0.Ast1. The bandedges do lie between π/3 and 2π/3.60).3 −0.decimator(M.'Fst1.1 0 0.5167. The frequency is relative to the high sampling rate prior to downsampling. 6. % Transition width 0. bandpass ﬁlter does not meet the restrictions just mentioned. Since we downsampled by M = 3. the bandedges are not between kπ/M and (k + 1)π/M for M = 4.5167π. % Decimation factor fdesign. TW Fc1 Fc2 M Hf Hd = = = = = 0.'bandpass'.Fp2.Fc1+TW/2.Fc2+TW/2.. Fc1TW/2.Fp1.2 0.78 Multirate Filter Design Spectrum after decimation 0 −10 −20 Alias from spectral replicas Magnitude spectrum of signal after decimation Magnitude (dB) −30 −40 −50 −60 −70 −80 −0.9: Spectrum of bandpassﬁltered signal downsampled by a factor M = 3.35π and 0.35.60.Fc2TW/2.2 −0.. = design(Hf.Ap.9.Ast2'. The bandwidth is reduced by a factor M = 6.1/6. Losada . 5. the new Nyquist interval after downsampling Digital Filters with MATLAB Ricardo A. The spectrum of the bandpassﬁltered signal after downsampling is shown in Figure 4.3 Normalized Frequency (×π rad/sample) Figure 4.1 0. Example 40 Suppose we are interested in retaining the band between 0.. However. so if we design a bandpass ﬁlter we can at least decimate by 3.2.Fst2..
Decimation when working with Hertz So far we have used normalized frequency in all our decimation designs. Computing new samples in between existing samples amounts to interpolation. we would still like to reduce the sampling frequency accordingly. Losada .10. M Band Fs Hf Hd = = = = = 3.1 Reducing the sampling rate of a signal 79 will be [−π/3. This is less than optimal however and if the bandwidth reduction factor is less than two. We will return to discuss fractional decimation in §4.4. we should simply keep in mind that the sampling frequency that is used is the sampling frequency of the input signal (prior to downsampling).1.4. Notice that we haven’t been able to remove all the white space since we could only downsample by 3 even though the bandwidth was reduced by 6. A simple approximation would be to downsample the output by the largest integer that is not greater than the bandwidth reduction factor. design(Hf. we’ll look at interpolation. 4. This implies computing some samples between existing samples as shown in Figure 4. Example 41 Suppose we have a signal sampled at 30 kHz and we reduce its bandwidth by a factor of 3. In order to remove redundancy. If we’d like to specify the frequency speciﬁcations in Hertz. therefore the cutoff frequency is equal to Fs /(2M ) = 5000 Hz.'kaiserwin').'Nyquist'.1500. A better solution would be to reduce the sampling rate by a noninteger factor as well. The transition band is set to 1500 Hz so that it extends from 4250 Hz to 5750 Hz. Digital Filters with MATLAB Ricardo A.65. π/3].Fs).Band.2 Decimating by a noninteger factor If the bandwidth reduction factor is not an integer. we reduce the samplingrate by a factor of 3 as well. there would be no efﬁciency improvements even if we reduce the bandwidth to almost (but not quite) half the original bandwidth. We use a 3rdband Nyquist ﬁlter. The band of interest extends from 0 Hz to 4250 Hz. 30e3.'TW. 3. fdesign. but before we do so.decimator(M.Ast'.
1 Fractionally advancing/delaying a signal Usually interpolation is presented in the context of increasing the samplingrate of a signal.1 0 30 35 40 45 50 55 Time (samples) Figure 4.11 are found by fractionally advancing the signal in time by a factor α.3 0. but strictly speaking. The process is referred to as sinc interpolation since an ideal lowpass ﬁlter (with a sincshaped impulse response) is involved (see Appendix B). Consider the situation shown in Figure 4. This is done without actually converting the signal back to continuous time.6 0.8 0.2 Interpolation Roughly speaking.9 0.10: Illustration of fractional decimation. interpolation consists of computing new samples between existing samples. ideally we interpolate by ﬁnding the desired points on the underlying continuoustime analog signal that corresponds to the samples we have at hand. 4.4 0.5 0.2 0. the samples can be thought to be obtained by fractionally delaying the signal by a factor Digital Filters with MATLAB Ricardo A.2. In the context of signal processing. We’d like to compute the interpolated samples from the existing samples. therefore the sampling rate remains the same. Equivalently. The interpolated samples in Figure 4.80 Multirate Filter Design 1 Original samples 0. 4. this is not necessary.11. For each existing sample we compute a new sample. Losada .7 Underlying signal Fractionally−decimated samples Amplitude 0.
2 Interpolation 81 0. Losada . Of course advancing a signal in time is a noncausal operation. π (n + α) −∞ < n < ∞ (4. the ideal fractional advance has an inﬁnite impulse response that is also inﬁnitely noncausal.1 −0.4.2 Sampled signal Fractionally advanced signal Amplitude 0. β = 1 − α. Thus.3 0. if x [n] is our signal prior to interpolation.5 30 32 34 36 38 40 42 44 46 48 50 Time Figure 4.2 −0.4.4 −0.1 0 −0.4 0. By taking the inverse Fourier transform.11: Fractional advance by a factor α = 0. the impulse response of the fractionaladvance ﬁlter zα can be easily found to be hfrac [n] = sin(π (n + α)) . Both α and β are a fraction between zero and one. We will look at various FIR and Digital Filters with MATLAB Ricardo A.3 −0. we can make it causal by delaying everything by one sample. the signal consisting of interpolated values is computed by passing the signal through a ﬁlter with transfer function Hfrac (z) = zα .5 Underlying analog signal 0. Since the advance is less than one sample. which shows the equivalence of a causal advance by a factor of α and a delay (notice the negative sign) by a factor of β = 1 − α.1) Not surprisingly. Hcausal = z−1 zα = zα−1 = z− β .
∗ Digital Filters with MATLAB Ricardo A.82 Multirate Filter Design Figure 4. it is necessary to lowpass ﬁlter the upsampled signal in such a way that the L − 1 unwanted spectral replicas are removed (see Appendix B). The upsampler inserts L − 1 zeros between existing samples in order to increase the sampling rate of the signal. See Appendix B for more on this. In order to interpolate between the original samples. The ﬁlter H (z) performs such lowpass ﬁltering.2. IIR approximations to this ﬁlter later. Conceptually. increasing the sampling rate is never performed as shown in Figure 4.12: Conceptual diagram for increasing the sampling rate.12. This step in itself does not modify the spectral content at all. In practice. Losada .12. All it does. we want to use all the information in the existing signal in order to compute the new samples. Because of this upsampling. is to change the Nyquist interval to encompass a bandwidth that is now L times larger than before upsampling. 4.2 Increasing the samplingrate of a signal In Appendix B we have already looked at what increasing the samplingrate of a signal means in the frequency domain. The reason is that inserting all those zeros means the lowWhenever we increase the sampling rate. The reason we lowpass ﬁlter is to remove spectral replicas that are encompassed by the new Nyquist interval when the rate is increased. the new Nyquist interval now contains L − 1 spectral replicas of the baseband spectrum. In short. increasing the samplingrate is accomplished by lowpass ﬁltering the signal with a digital ﬁlter operating at the same rate we wish to increase the sampling rate to∗ . replacing the zeros that have been inserted with actual interpolated samples. but for now we will look at how a bank of fractional advance ﬁlters can be used to increase the samplingrate of a signal. The key idea is to digitally produce a signal that would be exactly the same as a signal we had obtained by sampling a bandlimited continuous time signal at the higher sampling rate. On the contrary. increasing the sampling rate is accomplished as depicted in Figure 4. we do not lowpass ﬁlter in order to reduce bandwidth.
1 −0.4 −0. pass ﬁlter would be performing a lot of unnecessary computations when its input is just a zero.4.5 and T ′ = T/5 = 0. Instead.5 0.4 0. The situation in the time domain is depicted in Figure 4.13. Losada . .13: Illustration of ideal bandlimited interpolation in the time domain.1): • x T ′ [5n] = x T [n] 1 • x T ′ [5n + 1] = x T [n + 5 ] 2 • x T ′ [5n + 2] = x T [n + 5 ] 3 • x T ′ [5n + 3] = x T [n + 5 ] 4 • x T ′ [5n + 4] = x T [n + 5 ] Digital Filters with MATLAB Ricardo A. . The polyphase approach is easiest to understand by looking at things in the time domain. k = 0.2 −0.13 assuming we want to increase the rate by a factor L = 5. .5 34 36 38 40 42 44 46 Time Figure 4. we can see that we need to take every input sample x T [n] and produce 5 output samples { x T ′ [m]}. 4 as follows (note that T = 0.3 0.3 −0. we need a fractional advance ﬁlter. Looking at Figure 4. We have seen that in order to produce each sample between existing samples. m = 5n + k. a socalled polyphase approach is taken in order to efﬁciently increase the sampling rate. .2 Underlying analog signal Original samples Interpolated samples Amplitude 0.1 0 −0.2 Interpolation 83 0.
we cycle through all polyphase branches. This is depicted in Figure 4.84 Multirate Filter Design Figure 4. . k = 0. . . . we have Hk (e jω ) = e jωk/L . Losada . Hk (z). the ideal interpolator consists of a bank of L ﬁlters. . Hk (e jω ) = 1 and has linear phase. . For every input sample. . Hk (z) = zk/L . Each ﬁlter performs a fractional advance of the input signal and has a different phase. . The overall implementation is referred to as a polyphase interpolation ﬁlter. i. . . Evaluating on the unit circle. L − 1 so that each ﬁlter Hk (e jω ) is allpass. each branch tasked with computing one of the L interpolated outputs.e. The timedomain view of the ideal interpolation ﬁlter thus has the polyphase structure builtin. . ∗ The term polyphase stems from this derivation. . ∗ Digital Filters with MATLAB Ricardo A. . In general. The outputs of the ﬁlters are then interleaved (i. . k = 0. only one ﬁlter needs to operate per high rate output sample) to produce the interpolated signal. . arg{ Hk (e jω )} = ωk/L. L − 1.14: Bank of ﬁlters used for interpolation. The interpolator ﬁlter consists of L polyphase parallel branches.e. Each ﬁlter in the ﬁlter bank has a different phase. k = 0. . L − 1. k = 0.14 The L ﬁlters that comprise the ﬁlter bank are the fractional advance ﬁlters. L − 1 which will fractionally advance the input signal by a factor k/L.
. ∗ Digital Filters with MATLAB Ricardo A. hk [n] = 1 2π π −π e jωk/L e jωn dω = + sin π LnL k + π LnL k this corresponds to taking the transfer function corresponding to the ideal lowpass ﬁlter (1. Yet it is nice to see that things ﬁt in even though we have approach the derivation of the ideal interpolator from two different perspectives. . the impulse response of each fractional advance ﬁlter in the ﬁlter bank is given by the inverse DTFT. + h[0] + z− L h[ L] + . . . We cannot design them as FIR ﬁlters because no FIR ﬁlter can be allpass (except for a pure delay). . Losada . + h[ L − 1] + z− L h[2L − 1] + . . it is clear how we want to approximate the ideal interpolation ﬁlter bank. . . IIR approximations will be exactly allpass.) which can be written as HLP (z) = H0 (z L ) + z−1 H1 (z L ) + . because no stable IIR ﬁlter can have linear phase. We cannot design them as IIR ﬁlters. .1) with the cutoff frequency set to π/L and rewriting it in the form HLP (z) = . + z −1 ( . k = 0. The impulse responses of each subﬁlter correspond to the L decimated sequences of the ideal impulse response by again writing uniquely m = Ln + k. while approximating an allpass response as best possible. . . ) .2). + h [ 1 ] + z − L h [ L + 1 ] + . FIR approximations will produce the exact linear phase. . z−k ) of the original transfer function. It is enlightening∗ to realize that the ﬁlters comprising the ﬁlter bank are the polyphase components of the ideal interpolation ﬁlter derived in (1. + z−( L−1) (. . .2 Interpolation 85 Herein lies the impossibility of designing these ﬁlters in an exact manner. The reality is that this should be expected given that we had already determined that the ideal interpolator was an ideal lowpass ﬁlter. .2)! Indeed. However.4. L − 1 in (1. . . + z−( L−1) HL−1 (z L ). The subﬁlters Hk (z) are the polyphase components (each one is preceded by a different phase. . . On the other hand. while trying to produce the required phase. .
it is possible to make the approximation causal by delaying by half the ﬁlter order. However. for each non symmetric polyphase ﬁlter. However. Digital Filters with MATLAB Ricardo A. Note that the ideal interpolation ﬁlter is inﬁnitely noncausal. because we will implement in efﬁcient polyphase form. The Nyquist ﬁlter operates at the high rate (four times the input rate). the polyphase ﬁlters that compose the ideal interpolation ﬁlter give some insight on things to be looking for when designing interpolation ﬁlters. So that instead of approximating the ideal fractional advance e jωk/L the polyphase components will approximate e jω (k/L− M) . The delay will mean the introduction of a phase component in the response of each polyphase component. The groupdelay will consequently be of the form − dφ(ω ) dω (k/L − M ) =− = M − k/L.3 Design of FIR interpolation ﬁlters While interpolation ﬁlters are simply lowpass ﬁlters that can be designed with the various techniques outlined previously. The ideal L polyphase ﬁlters will have a groupdelay given by k − L. Consider an interpolation by a factor of L. . we can make each polyphase component causal by delaying it by M samples. dω dω A problem that arises is that even though the FIR approximation to the ideal interpolation ﬁlter is symmetric and thus has linear phase.86 Multirate Filter Design 4. consider an FIR approximation to the ideal interpolation ﬁlter where the order is of the form N = 2LM. The ﬁlter is implement in efﬁcient polyphase manner. After ﬁnite length truncation. L − 1 For simplicity.2. there is a mirror image polyphase ﬁlter which will have the exact same magnitude response with a mirror image groupdelay that will compensate any phase distortion. . Example 42 We design a Nyquist ﬁlter that interpolates by a factor L = 4. It is a 4thband ﬁlter with a cutoff frequency given by π/4. . Losada . the polyphase components are not necessarily symmetric and thus will not necessarily have exact linear phase. N/2. Then each polyphase ﬁlter will have order N/L = 2M. k = 0. . This ﬁlter will remove 3 spectral replicas encompassed by the augmented Nyquist interval once the signal is upsampled.
'Nyquist'.1 0. design(Hf. Note that two of the polyphase components do not have perfectly ﬂat group delays. For the design from the previous example.7 0. The magnitude responses of the 2nd and 4th polyphase subﬁlters are identical.8 0.3 0.1.'TW.6 0.4. The groupdelays show a fractional advance of 0.9 Normalized Frequency (×π rad/sample) Figure 4. while the others are approximations that fadeoff at high frequency.15: FIR Nyquist interpolate by 4 ﬁlter designed with a Kaiser window. Losada . The resulting Nyquist ﬁlter is shown in Figure 4. the nonlinear shape of one compensates for the other so that overall the interpolation ﬁlter has linear phase. 0. The ﬁlter length is 2LM + 1 = 105. L Band Hf Hint = = = = 4.0.Band.80). % Interpolation factor 4.2 Interpolation Magnitude Response (dB) 87 0 −20 Magnitude (dB) −40 −60 −80 −100 0 0. The magnitude response is shown in Figure 4. % Band for Nyquist design fdesign.75 for the four polyphase subﬁlters.'kaiserwin').25. it is worth taking a look at the magnitude response and groupdelay of the polyphase components of the resulting FIR ﬁlter.interpolator(L. This advance is relative to a nominal delay of M = 13 samples. Digital Filters with MATLAB Ricardo A.15.5 0.Ast'. The ﬁlter removes 3 spectral replicas and operates at four times the input rate.5.2 0.17. 0. and 0.4 0.16 while the groupdelay is shown in Figure 4. However. The magnitude response reveals that only one of the polyphase ﬁlters is a perfect allpass.
Group Delay 16 15 14 13 12 11 10 9 0 0.1 0.1 0.88 Magnitude Response (dB) 1 0 −1 −2 −3 −4 −5 −6 −7 0 0.16: Magnitude response of polyphase components for a Nyquist FIR interpolatebyfour ﬁlter.3 0.2 0.2 0.9 Normalized Frequency (×π rad/sample) Figure 4. Losada .7 0.4 0. Digital Filters with MATLAB Ricardo A.7 Multirate Filter Design Magnitude (dB) Filter #1: Polyphase(1) Filter #1: Polyphase(2) Filter #1: Polyphase(3) Filter #1: Polyphase(4) 0.3 0.6 0.17: Groupdelay of polyphase components for a Nyquist FIR interpolatebyfour ﬁlter.8 0.4 0.8 0.6 0.5 0.5 0.9 Filter #1: Polyphase(1) Filter #1: Polyphase(2) Filter #1: Polyphase(3) Filter #1: Polyphase(4) Group delay (in samples) Normalized Frequency (×π rad/sample) Figure 4.
1) are given as powers of z rather than powers of z2 . FIR halfband ﬁlters (being Nyquist ﬁlters) will have one of their polyphase branches given simply by a delay.4 Design of IIR halfband interpolators As with decimation. The presence of this polyphase components ensures that the input samples are ”passed undisturbed” to the output (they are simply delayed). a nonideal nonNyquist lowpass ﬁlter will not have a perfect delay as one of its polyphase branches and therefore will alter somewhat the input samples. The allpassbased IIR polyphase structure used to implement interpolation by two is shown in Figure 4. elliptic halfband ﬁlters are not Nyquist and as a result. one of the polyphase components will have perfectly ﬂat magnitude response and groupdelay. it is easy to verify this for the second polyphase: p = polyphase(Hint). Nyquist ﬁlters are often used because of their reduced implementation cost given that one of the polyphase branches is simply a delay. In general.Hint. Nevertheless. This polyphase component is a simple delay which provides a fractional advance of zero. Losada .1:end1). However. Digital Filters with MATLAB Ricardo A. 4. For example.Numerator(2:4:end)) % Returns true In general.4. quasilinear phase IIR ﬁlters are implemented in such a way that one of their polyphase branches is a pure delay. this is usually not a major issue in terms of distortion.18. In the case of interpolation by a factor L = 2. isequal(p(2. the transfer functions of the allpass ﬁlters in (3. IIR ﬁlters will not necessarily have one of their branches given by a simple delay because we do not use their impulse response directly to implement them. elliptic halfband interpolation ﬁlters that meet the same speciﬁcations are still more efﬁcient even though they do not have a simple delay as one of its polyphase branches (and therefore.2. they modify the input samples when interpolating). Note that because we have used the Noble identities. as stated in Chapter 4. the use of halfband ﬁlters for interpolation is enticing given their efﬁciency. However. for all Nyquist designs.2 Interpolation 89 Notice that the polyphase components can be obtained by taking every Lth sample of the lowpass impulse response as stated above. Nevertheless.
Hellip = design(Hf.19. Hlin = design(Hf. Example 43 Design elliptic and quasi linearphase IIR halfband interpolatebytwo ﬁlters for the given speciﬁcations. The ﬁlters deviate from the ideal interpolation ﬁlter in their phase response. Note that one of the branches is a pure delay and therefore has perfectly ﬂat groupdelay.interpolator(2. Once again. The band of interest extends to 20 Digital Filters with MATLAB Ricardo A. Example 44 Suppose we have an audio signal sampled at 48 kHz and we want to increase the sampling frequency to 96 kHz.'halfband'. the key point to keep in mind is that when increasing the sampling rate we should not reduce the bandwidth of the signal.55). Note how neither of the polyphase components has a ﬂat groupdelay in this case. but to remove spectral replicas.5 Design of interpolators when working with Hertz So far we have presented the design of interpolation ﬁlters in the context of normalized frequency.90 Multirate Filter Design Figure 4. Losada . the interpolation ﬁlter is used not to reduce bandwidth.'TW. The groupdelay of the polyphase branches for the quasi linearphase IIR design is shown in Figure 4.'ellip'). Hf = fdesign. The groupdelay of the polyphase subﬁlters for the elliptic design is shown in Figure 4. cost(Hlin) cost(Hellip) The two polyphase branches for either design are perfect allpass ﬁlters.Ast'. 4.20.0.08.'iirlinphase').18: Allpassbased IIR polyphase implementation of interpolation by 2.2. If working with Hertz.
20: Groupdelay of polyphase components for an elliptic IIR halfband interpolatebytwo ﬁlter.8 0.1 0.4 0.7 0.2 Interpolation Group Delay 30 91 Filter #1: Polyphase(1) 28 Filter #1: Polyphase(2) Group delay (in samples) 26 24 22 20 18 16 14 0 0.3 0.8 0. we can use a (FIR or IIR) halfband ﬁlter.4 0.2 0.9 Normalized Frequency (×π rad/sample) Figure 4.3 0.5 0. kHz. Losada . Since we want to increase the sampling frequency by a factor of 2. Digital Filters with MATLAB Ricardo A.6 0.4. Group Delay 30 Filter #1: Polyphase(1) Group delay (in samples) 25 Filter #1: Polyphase(2) 20 15 10 5 0 0 0.5 0.2 0.19: Groupdelay of polyphase components for a quasi linearphase IIR halfband interpolatebytwo ﬁlter.9 Normalized Frequency (×π rad/sample) Figure 4.6 0.7 0.1 0.
Digital Filters with MATLAB Ricardo A. Suppose we want to increase the rate by a factor of L/M with L > M. The spectral replica of the original audio signal centered around 48 kHz will be removed by the halfband ﬁlter.96000). This can be done trivially for rational factors.interpolator(2.96.'equiripple'). H = design(f.8000. Note that the passband extends to 20 kHz as desired.92 Magnitude Response (dB) 0 Multirate Filter Design −20 Magnitude (dB) −40 −60 −80 −100 0 5 10 15 20 25 30 35 40 45 Frequency (kHz) Figure 4.21: Magnitude response of halfband ﬁlter used to increase the sampling rate by 2. that is we keep one out of every M samples after interpolating.'TW. we want to increase the sampling rate by a fractional factor.'halfband'. The cutoff frequency for the ﬁlter is 24 kHz. In some cases.21. Losada . 4. The magnitude response of the ﬁlter can be seen in Figure 4. f = fdesign. A trivial way of doing this is to perform a full interpolation by a factor of L and then discarding the samples we don’t want.3 Increasing the sampling rate by a fractional factor So far we have discussed increasing the sampling rate by an integer factor.Ast'.
Figure 4. Instead. The band of interest for the signal is from 0 to 200 Hz. The transition width is set to 100 Hz in order to not disturb information contained in the band of interest. L M = 16. L > M. HL−1 (z). if the polyphase ﬁlters are H0 (z). Example 45 We will work with Hertz to illustrate the fact that when we interpolate (by either an integer or a fractional factor) we never reduce the bandwidth of the input signal. We choose to use a 16thband Nyquist ﬁlter. instead of using H0 (z) to compute the ﬁrst output. The structure resembles that of interpolation by an integer factor except that only the branches that are going to produce an output we will keep are used for every input sample. then. While the procedure we have just described is trivial. we discard samples we don’t need. H1 (z) to compute the second output and so forth. for the next input. = 5.e. i. Say we want to increase the sampling rate to 1600 Hz. if L = 3 and M = 2. Suppose we have a signal sampled at 500 Hz. H1 (z). . The idea in general is shown in Figure 4. to implement fractional interpolation efﬁciently we compute only the samples we intend to keep. then skip H2 (z).22 illustrates the idea. then use H2 (z). Speciﬁcally.4. Once we have increased the rate. skip H0 (z). a transition width of 100 Hz has been allocated. and then start again by using H0 (z). it is inefﬁcient since many of the samples that have been computed via interpolation are subsequently discarded. keeping only the ones required for the new rate. the sequence of polyphase ﬁlters used are H0 (z). then skip H1 (z).22: Conceptual conﬁguration for increasing the sampling rate of a signal by a fractional factor. .3 Increasing the sampling rate by a fractional factor 93 Figure 4. . we use H0 (z) for the ﬁrst output. As an example.23. The role of the upsampler+ﬁlter combination is the same as for the case when we increase the rate by an integer factor. Ricardo A. . we skip M − 1 polyphase ﬁlters and use H M (z) for the second output and so forth. then use H1 (z). Losada Digital Filters with MATLAB .
design(Hf.'TW.23: Bank of ﬁlters used for fractional interpolation. i.'kaiserwin'). The downsampling by 5 produces 4 spectral replicas centered around multiples of the resulting sampling frequency.rsrc(L. % High sampling rate 100. However.Fs). the ﬁlter is designed as a regular interpolateby16 ﬁlter.M. Unlike interpolation by an integer factor. this ﬁlter removes 15 spectral replicas as if the sampling frequency was being increased to 8000. 1600. The magnitude response of the ﬁlter is shown in Figure 4. Digital Filters with MATLAB Ricardo A. not all polyphase branches are used for each input sample. 16 × 500.e. The resulting sampling frequency is 1600.94 Multirate Filter Design Figure 4. Note that the sampling frequency we had to set for the design was that corresponding to full interpolation by 16. This is because. fdesign.e.Band.24. 80. Band Fs TW Ast Hf Hrsrc = = = = = = L. Losada .'Nyquist'. but is implemented efﬁciently so that no sample to be discarded is actually computed.Ast'. as we have explained.Ast. 500*L. The passband of the ﬁlter extends to 200 Hz so that the band of interest is left undisturbed.TW. i.
in order to perform fractional decimation. we need to be careful with where we set the cutoff frequency since it is no longer true that we want to keep the full spectrum of the input signal. For now. Losada . Suppose for instance that we have a signal sampled at 1000 Hz.5 Frequency (kHz) Figure 4. As we mentioned before. it is necessary to compute samples lying between existing samples. fractional decimation is appropriate when the bandwidth of a signal is being reduced by a fractional factor. We use fractional decimation to reduce the rate by a corresponding factor.4 Fractional decimation We now return to the problem of decimating by a fractional factor.) In terms of designing the ﬁlter however.4 Fractional decimation Magnitude Response (dB) 20 0 95 Magnitude (dB) −20 −40 −60 −80 −100 0 0. (Conceptually. We are interested in keeping the information contained from 0 to 280 Hz.4. The only difference is that L < M in this case.22 still applies with the caveat that now L < M. It turns out that the implementation we have just described for fractional interpolation can be used for fractional decimation as well. 4.24: Magnitude response of ﬁlter used for fractional interpolation.5 2 2. We now know how to do so by using interpolation. The passband extends to 200 Hz so that the band of interest is left untouched.5 1 1. Figure 4. we will restrict the discussion to rational values. We decide to both lowpass ﬁlter the signal and reduce the bandwidth by a Digital Filters with MATLAB Ricardo A. Indeed.5 3 3.
Subtracting half the transition width. i.'TW. The transition width is chosen so that the passband of the ﬁlter extends to the desired 280 Hz. The choice of the band however. but the baseband of interest presents no signiﬁcant aliasing. L M Band Fs TW Ast Hf Hrsrc = = = = = = = = Multirate Filter Design 7.M. If the input signal had a ﬂat spectrum occupying the full Nyquist interval (worst case).'Nyquist'.Band. 700 Hz. Its spectral replicas would be centered around multiples of the new sampling frequency.Fs). fdesign. 80. is made as M rather than L (compare to the previous example) so that the resulting ﬁlter reduces the bandwidth by a factor of L/M. we do not wish to reduce its bandwidth. where f c is the cutoff frequency which is given by f s /(2Band) = 350 Hz. after ﬁltering and fractional decimation. 1000*L. Also. f c − TW/2. The passband details for the ﬁlter can be seen in Figure 4. Digital Filters with MATLAB Ricardo A.96 factor of 7/10.25. 70.Ast'. The computation is simple. it is important to understand how the cutoff frequency for ﬁlters should be set commensurate to bandwidth reduction in the case of decreasing the sampling rate. the sampling frequency set for the ﬁlter designed is set as if full interpolation were to be implemented. we presented the rather obvious fact that when increasing the sampling rate of a signal.e.26. the spectrum of the signal would take the shape of the ﬁlter. Note that once again.rsrc(L.5 Summary and look ahead In this chapter we have presented design considerations for multirate ﬁlters. 4.'kaiserwin'). 10. In particular. Losada . means the passband of the ﬁlter will extend to 280 Hz as intended.Ast.TW. M. Note that as before. The baseband spectrum along with the ﬁrst positive two spectral replicas is shown in Figure 4. i. design(Hf. we have allowed for transition band overlap.e. % High sampling rate 140.
3 Frequency (kHz) Figure 4. Lowpass ﬁlters are the most common ﬁlters for multirate applications.05 0. using a bandpass rather than a lowpass for such case is simply a matter of choosing which spectral replicas should be removed. In particular. equiripple FIR ﬁlters are not always the best choice.25 0. however any lowpass ﬁlter in principle can be used. highpass and bandpass ﬁlters can also be used for both decreasing or increasing the sampling rate of a signal.9014 16.9012 0 0.1 0. In the next chapter we will see that multirate Nyquist ﬁlters have the interesting property that cascades of such ﬁlters remain Nyquist overall. We have presented Nyquist ﬁlters as the preferred type of lowpass ﬁlters for multirate applications.25: Passband details of ﬁlter designed for fractional decimation. When using Nyquist ﬁlters. As such.2 0.9016 16. Although we did not touch upon the case when increasing the sampling rate.9024 97 Magnitude (dB) 16.5 Summary and look ahead Magnitude Response (dB) 16.9018 16.9026 16.4.9022 16. we will see that to perform efﬁcient multirate ﬁltering. multistage designs can be a very attractive solution.902 16.15 0. Kaiser window designs may have a smaller passband ripple along with increasing stopband attenuation that may be desirable for removal of spectral replicas/aliasing attenuation. cascading efﬁcient Digital Filters with MATLAB Ricardo A. Losada . However. IIR halfband ﬁlters have presented as an extremely efﬁcient way of implementing decimate/interpolate by two ﬁlters.9028 16. The passband extends to 280 Hz so that the band of interest is left untouched.
The input signal is assumed to have a ﬂat spectrum which occupies the entire Nyquist interval.98 Multirate Filter Design 20 0 Baseband spectrum First replica Second replica Magnitude (dB) −20 −40 −60 −80 −100 0 200 400 600 800 1000 1200 1400 1600 1800 2000 Frequency (Hz) Figure 4. Losada . halfband ﬁlters may be a very desirable way of implementing changes in sampling rate by a factor given by a power of two.26: Baseband spectrum and two positives spectral replicas of fractionally decimated signal. Digital Filters with MATLAB Ricardo A.
while subsequent stages makeup for compromises that have to be taken in order for the ﬁrst stage to be efﬁcient (usually this means that subsequent stages remove remaining spectral replicas).Chapter 5 Multistage/Multirate Filter Design Overview Generally. The idea is that one stage addresses the narrow transition band but manages to do so without requiring a high implementation cost. . The idea follows upon the notion we have already discussed in Chapter 4 of reducing the sampling rate whenever the bandwidth of a signal is reduced. It uses upsampling of an impulse response in order to achieve a narrow transition band while only adding zeros to the impulse response (therefore not increasing the complexity). In this chapter we start by discussing the socalled interpolated FIR (IFIR) ﬁlter design method. This methods breaks down the design into two stages. the more expensive it is to implement. A very effective way of improving the efﬁciency of ﬁlter designs is to use several stages connected in cascade (series). We will show that multirate implementations of multistage designs are the most effective way of implementing these ﬁlters. the narrower the transition band of a ﬁlter. The upsampling introduces spectral replicas that are removed by the second stage ﬁlter which is a lowpass ﬁlter with less stringent transition bandwidth requirements. given a ﬁxed passband ripple/stopband attenuation.
Nyquist ﬁlters should be the preferred designs used for multirate applications. As mentioned in Chapter 4. When the transition width is small. we can use IIR halfband multirate ﬁlters implemented in polyphase form in order to increase the efﬁciency of designs even further. The socalled interpolated FIR (IFIR) approach [25]. Finally. The interesting property that Nyquist ﬁlters retain the Nyquist property when implemented in a multirate/multistage fashion is discussed. Losada . we show that efﬁcient multistage implementations apply to interpolation as well as decimation. Whereas with multistage decimation the simplest ﬁlter always should be the ﬁrst stage of the cascade (operating at the highest sampling frequency). 5.1 Interpolated FIR (IFIR) designs For any given FIR design algorithm. A particular case of Nyquist ﬁlters which are very efﬁcient for multirate/multistage applications are halfband ﬁlters. We will see how we can obtain very efﬁcient designs using halfband ﬁlters to implement some (or all) of the stages in a multistage design. we show tools which perform these designs automatically for us. We have already seen that relaxing the linear phase requirement results in a signiﬁcant savings in the number of ﬁlter coefﬁcients.[26]. This is one of the primary disadvantages of FIR ﬁlters. the ﬁlter order required to meet a given speciﬁcations set is inversely proportional to the transition width allowed.[27] yields linDigital Filters with MATLAB Ricardo A. the ﬁlter order required may be quite large. if the peak ripple speciﬁcations remain the same. such as in the Speciﬁcations Set 3. Fortunately. Multistage interpolation implementations will typically be mirror images of multistage decimation. We will show that these designs are very efﬁcient. Determining the optimal number of stages (and the decimation factor of each stage) in order to most efﬁciently implement a ﬁlter for a given set of speciﬁcations is a hard manual task. with multistage interpolation it is the last stage that contains the simplest ﬁlter (since in this case it is the last stage that operates at the highest sampling frequency). Moreover. The use of Nyquist ﬁlters in multistage implementations will be explored.100 Multistage/Multirate Filter Design We then extend the multistage implementation to more than two stages.
An upsampled ﬁlter is cascaded with an image suppressor ﬁlter to attain an overall design with a reduced computational cost. meeting the original speciﬁcations without introducing extra multipliers (it only introduces zeros. The upsampled design has the same transition width as the desired design. we upsample the impulse response by a factor equal to the multiple of the transition width. All that is left is to remove the spectral replica introduced by upsampling. Losada . Although this extra ﬁlter introduces additional multipliers. An IFIR design can attain the same specs with 127 multipliers when using an upsampling factor of 6: Digital Filters with MATLAB Ricardo A. consider once again the design Speciﬁcations Set 3.1 Interpolated FIR (IFIR) designs 101 Figure 5. Since the length of the ﬁlter grows as the transition width shrinks.5. The idea is depicted by example in Figure 5. Upsampling will cause the designed ﬁlter to compress. The price to pay is the appearance of spectral replicas of the desired ﬁlter response within the Nyquist interval. Then. Rather. These replicas must be removed by a second ﬁlter (called in this context the interpolation ﬁlter or image suppressor ﬁlter) that is cascaded with the original to obtain the desired overall response. resulting in a larger delay). As an example of the computational cost savings. we don’t design a ﬁlter for a given (small) transition width. This is the job of the image suppressor ﬁlter. The implementation is shown in Figure 5. The idea is rather simple. This ﬁlter will have a signiﬁcantly smaller length than a direct design for the original (small) transition width. The number of multipliers required for a single linear phase design was 263. L. The “relaxed” design is approximately of one third the length of the desired design. if the latter were to be designed directly. it is possible in many cases to still have overall computational savings relative to conventional designs.1: The IFIR implementation.1.2 for the case of an upsampling factor of 3. ear phase FIR ﬁlters that can meet the given speciﬁcations with a reduced number of multipliers. we design a ﬁlter for a multiple L of the transition width.
The overall response. cost(Hifir) The response of the upsampled ﬁlter and the image suppressor ﬁlter is shown in Figure 5.9 1 Relaxed design 0 0.6 0. Hf = fdesign.6 0.12.6 0.8 0.2 0.9 1 Resulting design 0 0.7 0. 5.5 0.5 0 1.60).5 1 0. Losada ..8 0.Fst.14.3 0.4 0.Ast'.2 0.5 0.1 0.lowpass('Fp.5 1 0.9 1 Desired design Figure 5.5 0 1. In the worst case scenario.3 0.3 0.6).2 0.4 0.5 0.9 1 image supressor Upsampled design 0 0.4 0.5 0 0 0.8 0.6 0.1.2: Illustration of the IFIR design paradigm.3 0.5 1 0.1 0.. Two ﬁlters are used to attain stringent transition width speciﬁcations with reduced total multiplier count when compared to a single ﬁlter design.7 0. they Digital Filters with MATLAB Ricardo A.8 0. Hifir = design(Hf.7 0..2 0. compared to a single linear phase equiripple design is shown in Figure 5.3.175.5 0 1.4.1 0.102 Multistage/Multirate Filter Design 1.5 1 0.4 0.7 0.Ap.1 Further IFIR optimizations A drawback in the IFIR design is that the passband ripples of the two ﬁlters are combined in a disorderly fashion.5 0.'UpsamplingFactor'.1 0.'ifir'.
1 0.6.5. shown in Figure 5..5.Ast'. 'JointOptimization'. [28].lowpass('Fp..3: Magnitude response of the upsampled ﬁlter and the image suppressor ﬁlter in an IFIR design.. Hf = fdesign.) of the ripple. attain a much cleaner passband behavior by jointly optimizing the design of the two ﬁlters to work better together. which is greatly simpliﬁed by this joint optimization.Ap.9 103 Image supressor filter Upsampled filter Magnitude (dB) Normalized Frequency (×π rad/sample) Figure 5. reveals a rather chaotic behavior (but certainly within spec.3 0. cost(Hifir) The manner in which the two ﬁlters work together is best described Digital Filters with MATLAB Ricardo A..175.14.'ifir'.. requiring the design to ensure that the sum of the two peak passband ripples does not exceed the original set of speciﬁcations.. Further optimized designs. Utilizing this joint optimization. This results in a ﬁlter that can meet the speciﬁcations set with an even further reduction in the number of multipliers.6 0. [4]. The savings are especially signiﬁcant for the image suppressor ﬁlter. the Speciﬁcations Set 3 can be met with only 74 multipliers.'UpsamplingFactor'. once again for an upsampling factor of 6. Hifir = design(Hf.7 0.8 0.4 0. Losada .Fst. can add up.5 0. Close inspection of the passband of the overall design in the previous example.60).2 0.12.true).1 Interpolated FIR (IFIR) designs Magnitude Response (dB) 0 −10 −20 −30 −40 −50 −60 −70 0 0.
4: Overall magnitude response of an IFIR design and a conventional equiripple design.6. shown in Figure 5. 29 are for the image suppressor ﬁlter and 45 for the upsampled ﬁlter. 263 for the conventional implementation.1.2 Multirate implementation of IFIR design When designing an IFIR ﬁlter. hinting at a much better optimized design. 5. Losada . 78 of the 127 multipliers correspond to the image suppressor ﬁlter. by looking at their magnitude responses.8 0.6 0.7 0. a ﬂat passband can be achieved with dramatic savings in the number of multipliers required for the image suppressor ﬁlter.9 Normalized Frequency (×π rad/sample) Figure 5. This Digital Filters with MATLAB Ricardo A.2 0.5 0. The passband details of the overall design show a nice equiripple behavior.3 0.7.1 0. the upsampling factor L used must be such that the (normalized) stopbandedge frequency ωs satisﬁes Lωs < π. The reader interested in further modiﬁcations/improvements to IFIR ﬁlters is referred to [29]. By contrast. in the previous IFIR design.104 Multistage/Multirate Filter Design Magnitude Response (dB) 0 −10 −20 IFIR design Conventional equiripple design Magnitude (dB) −30 −40 −50 −60 −70 −80 0 0. Out of the 74 multipliers required.4 0. while 49 correspond to the upsampled ﬁlter. The IFIR implementation requires 127 multipliers vs. The passband details are shown in Figure 5. By precompensating for a severe “droop” in the image suppressor ﬁlter.
. since at that point the Nyquist criterion is being unnecessarily oversatisﬁed.1 0. If we denote by I (z) the image suppressor ﬁlter and by U (z L ) the upsampled ﬁlter..08 0. Subsequent processing of the ﬁltered signal without reducing its sampling rate would incur in unnecessary (and expensive) redundant processing of information.5: Passband details of an IFIR design revealing a rather chaotic behavior of the ripple.06 0. implies that the bandwidth of the output signal would be reduced by a factor of L. we would have a cascade of these two ﬁlters and a downsampler as shown in Figure 5.8.04 105 Magnitude (dB) 0. Using the Noble identities.1 Interpolated FIR (IFIR) designs Magnitude Response (dB) 0. Losada Digital Filters with MATLAB . The idea is to downsample the ﬁltered signal by a factor of L to match the reduction in bandwidth due to ﬁltering. It is convenient from a computational cost perspective to reduce the sampling frequency of the ﬁltered signal. Example 46 Consider the same speciﬁcations as before.06 0..04 0.'Lowpass'.5.06 −0.08 0 0.08 0. we can “commute” the downsampler and U (z L ) to obtain the implementation shown in Figure 5.04 −0.decimator(6. but now casted as a decimation ﬁlter design: Hf = fdesign.12 Normalized Frequency (×π rad/sample) Figure 5.02 0. The combination of I (z) and the downsampler form a decimator which can be implemented efﬁciently in polyphase form.02 −0.02 0 −0. Ricardo A.9.
Digital Filters with MATLAB Ricardo A.7 0.333. only one out of 6 input samples (to the entire cascade) ever reaches U (z). Hifir = design(Hf.Ap. The two ﬁlters are jointly optimized in the design to achieve a speciﬁcations set with a reduced number of multipliers. because of its efﬁcient decimating implementation.6: Magnitude response of the upsampled ﬁlter and the image suppressor ﬁlter in an optimized IFIR design.. Of the 29 multipliers used for the image suppressor ﬁlter.6..Fst.9 Normalized Frequency (×π rad/sample) Figure 5.Ast'.5 0..true).3 0...333 is computed as follows. only 29/6 multiplications are performed on average per input sample. so per input sample.8 0.1 0. cost(Hifir) Looking at the results from the cost function.. Losada . the total number of multiplications on average is 29/6 + 45/6 = 12.106 Multistage/Multirate Filter Design Magnitude Response (dB) 10 0 −10 Image supressor filter Upsampled filter Magnitude (dB) −20 −30 −40 −50 −60 −70 −80 −90 0 0.12.2 0. we can see that while the number of multipliers remains 74 (the same as for a singlerate design). 'JointOptimization'.'UpsamplingFactor'. The number 12.6 0.175. the number of multiplications per input sample has been reduced substantially from 74 to 12. Because of decimation.'ifir'.60).14.4 0.333. 'Fp.
5. The optimized design exhibits nice equiripple behavior.02 0.08 −0.1 Interpolated FIR (IFIR) designs Magnitude Response (dB) 0.08 0.9: Interchange of the downsampler and the upsampled ﬁlter using the Noble identities.8: Cascading an IFIR implementation with a downsampler.1 0.08 0.7: Passband details of an optimized IFIR design. Losada .1 0. Figure 5.04 0.1 0 0. Figure 5.06 0.04 −0.12 Normalized Frequency (×π rad/sample) Figure 5.06 −0.04 0.06 107 Magnitude (dB) 0.02 −0. Digital Filters with MATLAB Ricardo A.02 0 −0.
Keeping in mind that the image suppressor ﬁlter I (z) is nothing but a lowpass ﬁlter. Determining the optimal number of stages. U (z) and I (z). let’s look at a different line of thought that also results in multistage/multirate ﬁlter designs. In other words. why not apply the IFIR approach recursively and break up I (z) into a cascade of two ﬁlters. We will look at such tools in a moment. Since I (z) is a lowpass ﬁlter itself. The multirate implementation yields a multiratemultistage design which lowpass ﬁlters data while decreasing the sampling rate at each stage for maximum computational efﬁciency. in the sense that the computational cost is minimized can be a difﬁcult task. the order required by I (z) to remove the spectral replicas as they come closer to each other increases as well. as we increase the upsampling factor L. After all. the original idea behind the IFIR approach is to implement a lowpass ﬁlter as a cascade of two ﬁlters. decreasing the complexity and computational cost of U (z) results in an increased ﬁlter order for I (z). the Filter Design Toolbox provides tools to automate such designs. of these two new ﬁlters. Fortunately. When we talk about decreasing the transition width.2 Multistage/Multirate Designs The procedure outlined in the previous section can be generalized to multiple stages. but it is not narrow relative to a sampling frequency of say 50 Hz. If the speciﬁcations for I (z) become too stringent. One should assess whether a transition region is narrow by considering the normalized transition width ∆ f / f s rather than Digital Filters with MATLAB Ricardo A. the cost of implementing this ﬁlter may outweigh the beneﬁts of the savings afforded to U (z). we are usually referring to the width in terms of normalized frequency. so that the upsampled ﬁlter U (z) becomes simpler. A transition width is narrow relative to the sampling frequency that is involved. We know that the ﬁlter order is increased as the transition width of a ﬁlter is decreased. Of course. In terms of absolute frequency.108 Multistage/Multirate Filter Design 5. Losada . one may consider using an IFIR approach to implement I (z) itself. In general this line of thinking leads us to implementing a ﬁlter in multiple stages. but before that. For example 10 Hz is probably quite narrow relative to a sampling frequency in the gigahertz range. In such a situation. one of them is also a lowpass image suppressor ﬁlter which can in turn be implemented as a cascade of two ﬁlters and so on. There are a couple of ways of thinking about the philosophy behind this. one could ask what is a narrow transition width: 1 kHz? 100 Hz? maybe 10 Hz? The answer is: it depends.
Instead. The computational savings come from two factors. is change the sampling frequency so that the transition width is not narrow relative to such sampling frequency. However. Then we design a ﬁlter that provides the required transition. the multistage approach is to not try to achieve the narrow transition in one shot. the number of input samples that have to be processed by the ﬁlter is much smaller than if we were handling the original large sampling rate. In many applications. Losada . so that their order is low thus requiring a small number of operations per input sample. we cannot change the transition width required for a ﬁlter design just because it makes the ﬁlter order too large. This is another way of looking at the idea behind multistage/multirate designs. The application sets the requirement for the transition width and this is typically something that cannot be changed. Of course there are other lowpass ﬁlters we need to implement that handle the full high sampling rate and the large number of input samples associated with it.1 dB Digital Filters with MATLAB Ricardo A.5. resulting in a ﬁlter of lesser order. The concepts are easily illustrated through an example.2 Multistage/Multirate Designs 109 the absolute transition width ∆ f . because the sampling rate is lower at this point. the simple ﬁlters operating at high sampling rates are used to remove spectral replicas from the ﬁlters operating at lower sampling rates downstream. On the other hand. In terms of the frequency response. If a very narrow transition width is required relative to the sampling frequency involved. Transition width: 100 Hz 3. Maximum passband ripple: 0. What we can do however. On the one hand. Example 47 Consider the design of a lowpass ﬁlter with the following speciﬁcations: Speciﬁcations Set 6 1. these other ﬁlter are implemented with large transition widths. Cutoff frequency: 550 Hz 2. we lower the sampling rate in stages by using simple lowpass ﬁlters until we achieve a rate at which the required transition width is not large relative to such rate. the normalized transition width ∆ f / f s will be much larger since f s is smaller.
Fst.10. cost(Hmulti) The number of multipliers required is 114. If we were to design a singlestage equiripple decimator.Ast'.500. This can happen in some cases. Losada . Its normalized transition width is also quite wide. Because the second stage has replicas centered about multiples of 5 kHz. Notice that only the last stage has the narrow 100 Hz transition width. due to the highly optimized interaction between the two stages as previously discussed.'Lowpass'. The simplest ﬁlter of all operates at the highest rate as should usually be the case.Ap.. By that time.875. a jointoptimized IFIR design is more efﬁcient than a general multistage design.1. In this example.'multistage'). the sampling frequency has For this example. This is shown in Figure 5.80. 'Fp. Since the bandwidth is being reduced by about a factor of 8. This is an important thing to keep in mind. This jointoptimization is not carried out for general multistage designs. By inspecting the resulting design.600. ∗ Hf Digital Filters with MATLAB Ricardo A.1e4).∗ A plot of the magnitude response of each stage helps understand the behavior of the design and the source for the computational savings. The ﬁrst stage takes care of those. Sampling frequency: 10 kHz The speciﬁcations imply that the band of interest extends from 0 to 500 Hz. the design would take 343 multipliers and about 48 multiplications per input sample. which accounts for the overall decimation factor of 8 we required. This ﬁrst stage has a very wide transition band starting at 500 Hz (therefore not affecting the band of interest) and ending at about 4450 Hz.. each stage has a decimation factor of 2.decimator(8.110 Multistage/Multirate Filter Design 4.. given its sampling frequency.. we decide to design a decimation ﬁlter with a decimation factor of 8 to meet the speciﬁcations and reduce the samplingrate after ﬁltering accordingly. The number of MPIS is 18. we can see that a 3stage ﬁlter has resulted. The second stage operates at 5 kHz given the decimation by two of the ﬁrst stage. In order to design a general multistage/multirate ﬁlter and allow for the tools to determine the optimal number of stages we use the following commands: = fdesign. The job of this ﬁlter is to eliminate spectral replicas of the third stage centered around odd multiples of the third stage’s sampling frequency. Hmulti = design(Hf. it cannot eliminate the spectral replicas of the third stage centered around even multiples of the third stage’s sampling frequency. Minimum stopband attenuation: 80 dB 5.
been reduced by a factor of 4.5 3 3. note that certain restrictions apply. it is advisable to manually try a different number of stages than the one automatically provided by the tools since similar computational costs may be found for different number of stages and other things (such as implementation complexity) may factor in to the decision of which design to use.10: Multistage design of decimation ﬁlter for Speciﬁcations Set 6.11. 5. However. The overall magnitude dB response of the threestage ﬁlter is obtained by adding the responses of each stage.5 4 4. so the normalized transition width is 4 times larger (100/2500 vs.5.5 2 2. Consider the following two designs for the same design speciﬁcations: Digital Filters with MATLAB Ricardo A.5 Frequency (kHz) Figure 5.1 Setting the number of stages If so desired. This is shown in Figure 5. Losada . This accounts for most of the computational savings. the number of stages can be manually controlled up to a certain point. 100/10000) than it would have been if we had done a singlestage design.2. In some cases. The decimation factor must be a number that can be factored into as many factors as the number of stages.2 Multistage/Multirate Designs Magnitude Response (dB) 0 −10 −20 111 Stage one Stage two Stage three Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 −100 0 0. Example 48 We can use the Nstages option to control the number of stages in a design.5 1 1.
This fact allows us to extend the reasoning behind the use of multistage/multirate designs to Nyquist designs. 'Fp.5 4 4. The number of stages that is determined automatically for Hmulti is 4.3 Multistage/Multirate Nyquist ﬁlters Multirate Nyquist ﬁlters have the interesting property that if you cascade two or more of them together (all decimators or all interpolators) the resulting multistage/multirate ﬁlter is still a Nyquist ﬁlter [30].... Hf = fdesign.'multistage'. Digital Filters with MATLAB Ricardo A. The computational cost of both designs are quite comparable. This could be the deciding factor between one design and the other.11: Overall magnitude response of multistage design for Speciﬁcations Set 6.5. Hmulti2 = design(Hf.'Nstages'. However.06.'Lowpass'. Losada ..5 3 3.. Hmulti = design(Hf.Fst. However.70).decimator(16. we force Hmulti2 to have 3 stages. the complexity of implementing 3 stages in hardware may be less than that of implementing 4 stages. 5.5 1 1.3).Ast'.'multistage').5 2 2..112 Multistage/Multirate Filter Design Magnitude Response (dB) 0 −20 −40 Magnitude (dB) −60 −80 −100 −120 −140 0 0.5 Frequency (kHz) Figure 5.Ap.05.
80). We will compare singlestage a multistage design to illustrate the computational savings that can be afforded by using multistage Nyquist ﬁlters. In many cases.875 15.75 16.1 Using IIR halfband ﬁlters Whenever we have a halfband decimator (or interpolator) we may want to consider using either an elliptic halfband ﬁlter (if phase linearity is not an issue) or a quasi linearphase IIR halfband ﬁlter (if phase linearity is important) to increase computational savings.3 Multistage/Multirate Nyquist ﬁlters 113 We already know that Nyquist ﬁlters are wellsuited for (either decimation or interpolation) multirate applications.75 14.'multistage'). The default multistage design.decimator(8. halfband ﬁlters are used for the individual stages that make up the multistage design.'nyquist'.'kaiserwin'). Hf H1 H2 H3 = = = = fdesign.. the passband ripple can be in the microdB range or even smaller! Digital Filters with MATLAB Ricardo A.125 APIS 68.75 NStages 1 3 2 The equivalent overall ﬁlters for all three designs are 8band Nyquist ﬁlters. there is the possibility to use an extremely efﬁcient IIR multirate halfband design as long as we allow for IIR ﬁlters as part of the design. H3 is 4band Nyquist decimator followed by a halfband Nyquist decimator. is a 3stage ﬁlter with each individual stage being a halfband ﬁlter (each halfband ﬁlter is different though).5. design(Hf. H2.'multistage'. As an added bonus.8. design(Hf. design(Hf.3. consider the design of a Nyquist ﬁlter that decimates by 8. If we use IIR halfband ﬁlters.625 17. Example 49 As an example.016.2). The ability to break down a multirate Nyquist design into several multirate Nyquist stages provides very efﬁcient designs. Whenever a halfband ﬁlter is used for a stage. 5.'Nstages'. all Nyquist designs tend to have a very small passband ripple. Losada . The computational costs of the three designs are summarized in the following table: H1 H2 H3 NMult 551 93 106 NAdd 550 90 104 Nstates 624 174 182 MPIS 68.
3 0. we can get saving close to a factor of 3 in both total number of multipliers as well as MPIS.7 0. H5 = design(Hf. However.2 0.'ellip').'HalfbandDesignMethod'. In the previous example. Losada .12.114 Multistage/Multirate Filter Design Magnitude Response (dB) 0 3−stage FIR Nyquist 3−stage Nyquist linphase IIR 3−stage Nyquist ellip IIR Magnitude (dB) −50 −100 −150 0 0.'iirlinphase'). H4 = design(Hf.8 0.625 5.12: Passband phase response for multistage Nyquist FIR and IIR ﬁlters.'multistage'.9 Normalized Frequency (×π rad/sample) Figure 5.25 NStages 3 3 The magnitude response of the 3stage Nyquist FIR design along with the two 3stage Nyquist IIR designs is shown in Figure 5.6 0.5 0.25 2. the savings are about twice as good.1 0. All three designs behave similarly overall as expected since the speciﬁcations for each halfband (each stage) are the same. If we can use elliptic halfbands.'HalfbandDesignMethod'.625 11.'multistage'. The computational cost is shown below H4 H5 NMult NAdd 35 70 12 24 Nstates 75 18 MPIS APIS 5.4 0. if we substitute the halfband ﬁlters of each stage in H2 with quasi linearphase IIR ﬁlters. although the 3stage Digital Filters with MATLAB Ricardo A.
5.4 Multistage interpolation
Magnitude Response (dB) 3−stage FIR Nyquist 3−stage Nyquist linphase IIR 3−stage Nyquist ellip IIR
115
x 10 1.5 1
−3
Magnitude (dB)
0.5 0 −0.5 −1 −1.5 0 0.02 0.04 0.06 0.08 0.1 0.12
Normalized Frequency (×π rad/sample)
Figure 5.13: Passband phase response for multistage Nyquist FIR and IIR ﬁlters.
FIR Nyquist design has a small passband ripple, it is nowhere near the tiny passband ripple of the IIR designs. The passband details are shown in Figure 5.13. As stated before, the computational savings of the elliptic design come at the expense of phase nonlinearity. On the other hand, the groupdelay of the elliptic design is much lower than the other two designs. The passband groupdelay is shown in Figure 5.14. We can use realizemdl(H4) or realizemdl(H5) to generate Simulink blocks that implement these multistage decimators using halfband IIR ﬁlters in efﬁcient polyphase form.
5.4
Multistage interpolation
Just as with decimation, using multiple stages to perform interpolation can result in signiﬁcant implementation savings. The reason once again has to do with the ratio of the transition width relative to the sampling frequency. To see this, consider implementing a ﬁlter that interpolates by a factor of 8, increasing the samplingrate from 1250 Hz to 10000 Hz with a cutoff Digital Filters with MATLAB Ricardo A. Losada
116
Multistage/Multirate Filter Design
Group Delay
350
300
Group delay (in samples)
250
200
3−stage FIR Nyquist 3−stage Nyquist linphase IIR 3−stage Nyquist ellip IIR
150
100
50 0.02 0.04 0.06 0.08 0.1 0.12
Normalized Frequency (×π rad/sample)
Figure 5.14: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters.
frequency of 625 Hz and a transition width of 312.5 Hz. Let us compare the transition width, relative to the sampling frequency of a singlestage design vs. the ﬁrst stage of a multistage design. Suppose the ﬁrst stage of the multistage design is a halfband ﬁlter that interpolates by a factor of two (from 1250 Hz to 2500 Hz). Figure 5.15 shows a comparison of the two ﬁlters. They both have the same transition width, yet the sampling frequency ratio is 4to1. Therefore the ratio ∆ f / f s is four times smaller for the singlestage ﬁlter than for the ﬁrst stage of a multistage implementation. Accordingly, the number of coefﬁcients for the singlestage design is 142 (with 135 adders), whereas the ﬁrst stage of a multistage implementation has only 22 multipliers (and 21 adders). The fact that we have a savings of more than a factor of 4 in terms of number of multipliers is owed to the fact that we use a halfband ﬁlter for the latter design which yields further savings. Note that in general for polyphase interpolators, the number of coefﬁcients equals the number of multiplications per input sample (MPIS). Of course, as is apparent from Figure 5.15, the two ﬁlters are not performing the same job, so the comparison is unfair. While the singlestage design removes all spectral replicas in the new Nyquist interval (with f s = 10000), the halfband ﬁlter only removes some spectral replicas. There Digital Filters with MATLAB Ricardo A. Losada
5.4 Multistage interpolation
117
Magnitude Response (dB)
0
Magnitude (dB) (normalized to 0 dB)
−20
Single−stage design First stage of a multistage design
−40
−60
−80
−100
−120 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Frequency (kHz)
Figure 5.15: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters.
is cleanup left to be done by subsequent interpolation ﬁlters operating at higher rates (after all, we have only interpolated to 2500 Hz with the halfband ﬁlter). Figure 5.16 shows a full 3stage design (each stage being a halfband interpolator) compared to a singlestage design. Both designs satisfy the same transition width and stopband attenuation requirements. Overall the multistage design requires 40 coefﬁcients and 72 MPIS ∗ . The code that was used for these two designs follows: f = fdesign.interpolator(8,'Nyquist',8,'TW,Ast',312.5,80,1e4); h = design(f,'kaiserwin'); g = design(f,'multistage','Nstages',3); As with multistage decimators, the use of IIR halfbands implemented in efﬁcient allpassbased polyphase structures can improve the efﬁciency of designs beyond what can be achieved with FIR ﬁlters. For example, for the same speciﬁcations, this design:
Since each stage produces more samples at its output than the number of samples at its input, for multistage interpolators the number of multiplicationsperinputsample to the overall implementation is larger then the number of coefﬁcients required for all stages.
∗
Digital Filters with MATLAB
Ricardo A. Losada
118
Multistage/Multirate Filter Design
Magnitude Response (dB)
20
Single−stage design Three−stage design
0
−20
Magnitude (dB)
−40
−60
−80
−100
−120 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Frequency (kHz)
Figure 5.16: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters.
hm = design(f,'multistage','Nstages',3,... 'HalfbandDesignMethod','iirlinphase'); results in a 3stage ﬁlter with 16 coefﬁcients and 30 MPIS. Figure 5.17 shows how subsequent stages remove spectral replicas that remain from the ﬁrst stage. Notice how as the samplingrate increases, the transitionwidth for each corresponding stage also increases so that the ratio ∆ f / f s remains large resulting in simple ﬁlters. For interpolation, the ﬁrst stage is usually the most involved, but this is OK since the sampling frequency is the lowest at that point. The complexity of each subsequent stage is reduced gradually since each ﬁlter has to operate at higher and higher sampling frequencies.
5.5
Summary and look ahead
We have shown how multistage implementation of ﬁlters can result in signiﬁcant computational savings. The savings are increased when multistage implementation are combined with multirate ﬁlters. There is an optimal number of stages which provide maximum computational savings. Digital Filters with MATLAB Ricardo A. Losada
This optimal number can be determined automatically by the design tools discussed.5 3 3.5 2 2.5 4 4. Digital Filters with MATLAB Ricardo A.5 Frequency (kHz) Figure 5.5. These include hold and linear interpolator ﬁlters as well as CIC interpolation/decimation ﬁlters. they can do so while using a small number of multipliers. We will also discuss the use of Farrow ﬁlters for fractional decimation/interpolation. Moreover. Multistage Nyquist ﬁlters provide very efﬁcient implementations. In the next chapter we will discuss special multirate ﬁlters that are wellsuited for multistage implementations.17: Passband groupdelay for multistage Nyquist FIR and IIR ﬁlters. especially IIR halfbands. This is particularly true for halfband ﬁlters.5 Summary and look ahead 119 Magnitude Response (dB) 0 −20 First stage Second stage Third stage Magnitude (dB) −40 −60 −80 −100 0 0. Losada .5 1 1. These ﬁlters can be used to provide fractional samplingrate changes by an arbitrary factor (not necessarily a ratio of two integers). These multistage ﬁlters are equally adequate for efﬁcient decimation or interpolation purposes.
CIC ﬁlters can also be used for decimation. . This is because at that stage the samplingrate is the highest. in decimation. Usually. we look at linear interpolators and show how they can be thought of as two hold interpolators “put together”. operating at high sampling rates. We then move on to CIC interpolators and show how these are just generalizations of hold/linear interpolators. By using multiple (more than two) sections. because of their simplicity. Both linear and hold interpolators are attractive because of their simplicity. CIC ﬁlters are usually used at the ﬁrst stage of a multistage design. Next. The nice thing about CIC interpolators is that they can be implemented without using multiplication. Unlike the interpolation case. This is an attractive feature for certain hardware such as FPGAs and ASICs because multipliers take up quite a bit of area and are difﬁcult to make to operate at very high clock rates. CIC interpolators can obtain better attenuation than hold or linear interpolators. We see that they are very crude approximations to an ideal lowpass ﬁlter used for interpolation. We ﬁrst look at hold interpolators which perform basic interpolation by simply repeating input samples L times (L being the interpolation factor). they are used at the last stage of a multistage implementation.Chapter 6 Special Multirate Filters Overview In this chapter we look at some special ﬁlters that come in handy for multirate applications.
6. For example. The main allure of Farrow implementations are the low number of ﬁxed multipliers that are required and the tunability of the fractional delay while the ﬁlter is running without having to redesign. interpolating by a factor of 4.7 0.1 0 0 5 10 15 20 25 Time (n) Figure 6. Finally.9 Original samples 0.1 shows the result of a hold interpolator. since linear and hold interpolators are special cases of CIC interpolators.6. Of course.1 Hold interpolators The simplest interpolator that one can build is the one that performs a (zeroorder) hold of each sample. Digital Filters with MATLAB Ricardo A.5 0.2 0.4 0.6 Amplitude 0. Figure 6. making the multiplierless feature of CIC ﬁlters very attractive. These ﬁlters are lowpass ﬁlters whose passband is shaped to compensate for the droop in the passband of CIC ﬁlters. Losada .8 Held−interpolated samples 0. CIC compensators can be used for those linear and hold cases as well.3 0.1 Hold interpolators 121 1 0. We then show how to design CIC compensators for either interpolation or decimation.1: Interpolated samples using a hold interpolator with a factor L = 4. inserting as many repeated samples as desired. Farrow ﬁlters are shown both for singlerate fractionaldelay applications as well as for changing the samplingrate of signals (by integer or fractional factors).
5 1 0.5 3 2. Figure 6. Hm = mfilt. Losada .3 0.holdinterp(4).6 0.1 0.4 0.5 Magnitude 2 1.5 0 0 0.5 0.122 Special Multirate Filters Magnitude Response 4 Hold interpolator Ideal interpolator 3. the ideal interpolator is a lowpass ﬁlter that removes L − 1 adjacent spectral replicas of the signal being interpolated. The hold interpolator has a very wide transition band. allows signiﬁcant highfrequency content to pass through. The ideal interpolator is shown for comparison.2 0. and distorts the original data in the band of interest.1.9 Normalized Frequency (×π rad/sample) Figure 6. The fast transitions between the last interpolated sample for a given original sample and the ﬁrst interpolated sample for the next original sample are indicative of high frequency content.Numerator As we know.8 0.2 shows the magnitude response of the hold interpolator compared to the ideal interpolator for the case L = 4. Note that the fact that high frequency remains after hold interpolation is obvious from the timedomain plot shown in Figure 6. The hold interpolator is an FIR interpolator whose impulse response is simply a series of L 1’s.7 0. The hold interpolator is a very crude approximation to the ideal interpolator as can be seen with fvtool(Hm). Hold interpolators are attractive because they require no arithmetic in order to be implemented. Hm. Digital Filters with MATLAB Ricardo A.2: Magnitude response of a hold interpolator with a factor L = 4.
Figure 6.3 0. which operates at the fastest rate and therefore beneﬁts the most of the fact that no multiplications are required). the multistage interpolation introduces a maximum distortion of about 0. hold interpolators are usually not used in isolation.8 0. the distortion of the signal in the band of interest is much less severe since the band of interest will occupy a much smaller portion of the passband of the hold interpolator. the ideal interpolator is shown. but rather are used as part of a cascade of interpolators (typically at the last stage. each one interpolating by two.15 dB while the hold interpolator introduces a distortion of almost 2 dB.3: Hold interpolator compared with multistage interpolator for L = 8. the ideal interpolateby8 ﬁlters is also shown. For reference. When used in such cascade conﬁgurations.5 0.9 Normalized Frequency (×π rad/sample) Figure 6.1 Hold interpolators 123 Magnitude Response 8 7 Hold interpolator Multistage interpolator Ideal interpolator 6 5 Magnitude 4 3 2 1 0 0 0. Example 50 Let us compare the effect of using a hold interpolator for a full interpolation by a factor L = 8 vs.6. a singlestage interpolateby8 hold interpolator design. Moreover. Losada . assuming the band of interest extends to 0.4 0. it is nowhere as bad as the hold interpolator acting alone.6 0. For reference.1π. While the multistage interpolator does allow some highfrequency content through.1 0. For these reasons.7 0. Digital Filters with MATLAB Ricardo A. using a hold interpolator for a factor L3 = 2 in conjunction with two halfband ﬁlters. most of the high frequency content has been removed by previous stages. Also.3 shows a comparison of a possible multistage design including two halfband ﬁlters followed by a hold interpolator vs.2 0.
1.2 0.2 Held−interpolated samples Multistage−interpolated samples 1 0.8 0.9 Normalized Frequency (×π rad/sample) Figure 6.4 0.6 0. Digital Filters with MATLAB Ricardo A.124 Special Multirate Filters Magnitude Response (dB) 10 0 −10 −20 First stage (halfband) Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 Second stage (halfband) Third stage (hold interpolator) 0 0.8 Amplitude 0.4 0.4: Magnitude response of each of the three stages of the multistage design.5: Comparison of interpolated data using a hold interpolator and a multistage interpolator with L = 8.5 0. Losada .7 0.3 0.1 0.2 0 0 20 40 60 80 100 120 Time (n) Figure 6.6 0.
the remnant high frequency content can be removed by an analog (antiimage) postﬁlter. While it is obvious that some high frequency content remains in either case. This of course is consistent with the notion that for every input sample. This of course means that each polyphase branch will have two coefﬁcients as we will soon see. Losada .4 shows the magnitude response of each of the three stages of the multistage design. Note that because of the prior interpolation by 4 (provided by the ﬁrst two stages) the band of interest is only a small fraction of the passband of the hold interpolator. the remaining high frequency content will be far away from the band of interest (the passband of the ﬁlter). each polyphase branch computes one of the interpolated values. A hold interpolator can be thought of in polyphase terms. it is also obvious that overall the multistageinterpolated data is much smoother and therefore has much less highfrequency content. the passband distortion is minimal. because of the multistage interpolation. Linear interpolation is very simple to understand.2 Linear interpolators After hold interpolators. Consider the plot in Figure 6. in the case of linear interpolators. each polyphase branch consists trivially of a single coefﬁcient equal to one. making it easy for a loworder analog lowpass postﬁlter (with a wide transition band) to remove said high frequencies.5 shows the result of ﬁltering the same data with the hold interpolator compared to using the multistage interpolator. two adjacent samples are used in order to compute the interpolated values. Figure 6. the next simplest interpolation ﬁlter is the linear interpolator. As is apparent from Figure 6. For this reason. While the hold interpolator only uses one sample in order to compute the interpolated values (and therefore has only one coefﬁcient per polyphase branch).6 which depicts the case L = 5 (it is the same idea for other Digital Filters with MATLAB Ricardo A.2 Linear interpolators 125 One thing to keep in mind that since interpolation is usually used right before D/A conversion.3. As usual. each interpolated value is compute by “multiplying” the input sample by one. since the impulse response is a sequence of 1’s of length L.6. This will ensure a smooth analog waveform. In this case. 6. the polyphase components are formed by taking every Lth value from the impulse response. Figure 6. In this case.
linearinterp(L).8 0. Digital Filters with MATLAB Ricardo A.8 (they always add to 1) for that polyphase branch. we weight one of the existing samples four times more than the other.126 Special Multirate Filters 2 Original samples 1. Losada .4 0. For every two existing samples.6 0. The coefﬁcients for other polyphase branches are similarly computed based on the ratio of the distance between the new interpolated sample and the existing surrounding two samples. This means that for the case L = 5.8 Linear−interpolated samples 1.2 0 0 1 2 3 4 5 6 7 8 9 10 Time (n) Figure 6.2 Amplitude 1 0.4 1. This results in coefﬁcients equal to 0. The weights are determined by the proximity of the interpolated values to each of the existing samples. Hl = mfilt. the 5 polyphase branches can trivially be computed as: L = 5. Therefore.2 and 0. the interpolated sample closest to an existing sample is four times closer to that existing sample than it is to the existing sample on its other side. In this case. p = polyphase(Hl) Notice that the last polyphase branch is trivial (its coefﬁcients are 1 and 0).6 1. when we form the weighted average in order to compute the interpolated sample.6: Computing linearlyinterpolated samples for L = 5. the interpolated values are computed by forming a weighted average of the existing samples. values of L).
6000 0.holdinterp(5). the magnitude response of a linear interpolator is given by multiplying (or adding when working with dB) the magnitude response of two hold interpolators.7 (we have normalized the passband gain to 0 dB to ease the comparison).6000 0. for the case L = 5. The plot comparing the magnitude response of both interpolators is shown (in dB) in Figure 6. Therefore. This can be easily veriﬁed with fvtool(Hm.6000 0.Numerator) ans = Columns 1 through 6 0.Hm. Hm. linear interpolators (and hold interpolators) are special cases of Nyquist ﬁlters.2000 0. Digital Filters with MATLAB Ricardo A.8000 Columns 7 through 9 0.8000 is exactly equal to Hl.Numerator.Numerator ans = Columns 1 through 6 0.2 Linear interpolators 127 This allows for the existing samples to be contained unchanged within the interpolated samples.Hl).4000 0.6000 0. the coefﬁcients of the FIR hold interpolation ﬁlter are: Hm = mfilt. As we know.Numerator ans = 1 1 1 1 And of course 1/5*conv(Hm. convolution in time is equal to multiplication in frequency.4000 0. Hl. Losada .0000 0.4000 0.2000 1 1.8000 A linear interpolator can be thought of as the convolution of two hold interpolators.4000 Columns 7 through 9 0.8000 1.Numerator. As usual. the overall interpolation ﬁlter is a lowpass ﬁlter whose coefﬁcients can be formed from the polyphase branches.2000 0. Indeed.6.2000 0.0000 0. That is.
However. While linearlyinterpolated samples still exhibit some abrupt transitions which indicate some high frequency components remain.7: Comparison of linear and hold interpolators for L = 5. as with hold interpolators. Losada .6 Normalized Frequency (×π rad/sample) 0. the linear interpolator provides more stopband attenuation and therefore better lowpass ﬁltering than a hold interpolator.2 0. Therefore.9 Figure 6.17285 −30 −40 −50 −60 0 0. The behavior is very similar to the comparison shown above between Digital Filters with MATLAB Ricardo A.4 0. This should be obvious to see if you think of the situation in the time domain.3 0.5 0. the error added by using linear interpolation rather than a higherorder ﬁlter is much smaller than if we try to directly linearly interpolate samples that are far apart in one shot. Because the magnitude response of the linear interpolator is twice that of the hold interpolator (in dB). linear interpolators are usually used as the last stage of a multistage interpolation scheme. the passband distortion due to linear interpolation can be minimal in such conﬁgurations.09688 −10 Magnitude (dB) (normalized to 0 dB) −20 Normalized Frequency: 0. On the other hand.7 0. the passband distortion of the linear interpolator is also twice that of the hold interpolator. it is not nearly as abrupt as taking the same samples and interpolating with a hold interpolator. Although the concept of closeness is a relative notion.59375 Magnitude (dB) (normalized to 0 dB): −24.8 0.128 Special Multirate Filters Magnitude Response (dB) 0 Hold interpolator Linear interpolator Normalized Frequency: 0.1 0. one can intuitively think that if samples have been interpolated already so that they are very close to each other.5952148 Magnitude (dB) (normalized to 0 dB): −12.
For more on this. Losada . if the interpolation is being done just prior to D/A conversion. we have obtained it by replacing the halfband ﬁlter in the second stage of the multistage ﬁlter used above. ∗ Digital Filters with MATLAB Ricardo A. CIC interpolation ﬁlters [31] can be seen as just that.7 0. followed by an interpolateby2 linear interpolator followed by an interpolateby2 hold interpolator.3 0. The number of section We should note that part of the highfrequency content is attenuated by the staircase reconstructor that is typically used in D/A conversion in order to make the signal analog.8: Magnitude response of a multistage interpolator consisting of a halfband ﬁlter. it is assumed that the analog antiimage postﬁlter will remove the remaining highfrequency content∗ The idea of convolving hold interpolators in order to obtain better stopband attenuation can be generalized to more than two such interpolators.6 0. A postﬁlter is used after the staircase reconstructor to smoothout the analog waveform by removing remaining highfrequency content. using a singlestage interpolateby8 hold interpolator and using a multistage interpolator with a simpliﬁed (hold or linear) ﬁnal stage.5 0. see [3]. one perfectly reasonable possibility is to have a linear interpolator in the nexttolast stage of a multistage conﬁguration and a hold interpolator in the last stage.2 0. In this case.1 0. Figure 6. In fact. with a linear interpolatebytwo ﬁlter.6.4 0.9 Normalized Frequency (×π rad/sample) Figure 6.8 shows just that conﬁguration.2 Linear interpolators 129 Magnitude Response (dB) 20 0 Magnitude (dB) −20 −40 −60 −80 0 0.8 0. Once again.
with H1 (z) = 1 − z− L (the “comb” due to its magnitude response) and H2 (z) = ∗ Postequalize in the case of decimation. . Of course. Digital Filters with MATLAB Ricardo A. 1. if deemed necessary. 1.130 Special Multirate Filters of the CIC interpolators will correspond to the number of hold interpolators convolved.1) by z−1 we get z −1 H ( z ) = z −1 + z −2 + .1) If we think of this as two ﬁlters in cascade. + z−( L−1) If we multiply both sides of (6. Losada . this compensators can also be used to compensate for the distortion introduced by linear or hold interpolators. In the next section we will take a look at CIC interpolators. . The transfer function of such a ﬁlter is given simply by H (z) = 1 + z−1 + z−2 + . H (z) = H1 (z) H2 (z). . After that. . . we will look at the design of CIC compensators which preequalize the passband∗ in order to compensate for the passband distortion introduced by the CIC ﬁlters. multisection CIC interpolators attain better stopband attenuation at the expense of larger passband distortion.2) (6. 6. 1} where the number of 1’s is equal to the interpolation factor. . + z − L Subtracting (6. .2) from (6.3 CIC interpolators Let’s perform some simple math to derive the CIC ﬁlters starting from a hold interpolator. . We have seen that a hold interpolator has an impulse response of the form h[n] = {1. As with linear interpolators.1) we get H (z)(1 − z−1 ) = 1 − z− L which means we can rewrite H (z) as H (z) = 1 − z− L 1 − z −1 (6.
we would skip the comb and integrator ﬁlters and simply repeat the input sample as many times as we wish to interpolate. we convolve K such impulse responses. HCIC (z) = ( H (z)) = K 1 − z− L 1 − z −1 K If we once again use the Noble identities. With CIC ﬁlters. we have derived a cascaded integratorcomb (CIC) ﬁlter. conceptually it is just an upsampler followed by a lowpass ﬁlter (the combination of the last two ﬁlters). Of course so far we haven’t really done much other than show a rather complicated way of implementing a hold interpolator. the CIC interpolator in conceptual form operates as the block diagram shown in Figure 6. if we wanted to implement a hold interpolator.3 CIC interpolators 131 Figure 6. The real use of CIC ﬁlters comes from a generalization of the fact we already noted relating linear interpolators to hold interpolators. this means that the transfer function of a CIC ﬁlter with K sections is given by elevating H (z) to the power of K. Since convolution in time equates to multiplication in frequency.9: Conceptual implementation of a CIC interpolator.10. As with all interpolators. Figure 6. Losada . ∗ Digital Filters with MATLAB Ricardo A.10: Actual implementation of a CIC interpolator obtained by use of Noble identities. When used for interpolation∗ .6. we can interchange the upsampler and the comb ﬁlter to obtain the conﬁguration shown in Figure 6. 1/(1 − z−1 ) (the integrator).9. Using the Noble identities. we can easily verify that an Keeping in mind that interpolation conceptually consists of upsampling followed by lowpass ﬁltering. In reality. Recall that we stated that a linear interpolator’s impulse response can be obtained by convolving two impulse responses of hold interpolators.
6. Note that the following commands can be used to quickly build a Simulink model of a CIC interpolator: L = 4. The cases K = 1 and K = 2 are special cases of CIC interpolators that result in hold and linear interpolators.12. % Interpolation factor K = 3.3. a multisection CIC interpolator multiplies the magnitude response of the hold interpolator K times. realizemdl(Hm) Of course. Because CIC ﬁlters are multiplierless.1.12: Multiplierless linear interpolator. the allure of these ﬁlters is that we can obtain good stopband attenuation by using only adders and delays if we use several sections. For this reason. % Number of sections Hm = mfilt.11: Implementation of a multisection CIC interpolator.cicinterp(L. CIC ﬁlters are often implemented at the last stage of a multistage interpolation ﬁlter. Figure 6. Losada .132 Special Multirate Filters Figure 6. This technique allows us. to implement a multiplierless linear interpolator using only 2 adders and 2 delays as shown in Figure 6.K).11.1 Design of CIC interpolators When designing CIC interpolators. The design basically consists of determining how many Digital Filters with MATLAB Ricardo A. the innermost combination of comb/upsampler/integrator. implementation of an Ksection CIC interpolator can be done as shown in Figure 6. for instance. In fact. can be readily replaced with a hold interpolator (saving a couple of adders and delays [32]. operating at the fastest rate. we should think in the context of multistage designs.
the interpolation factor is 64 as desired.3). followed by a interpolateby2 Nyquist (halfband) ﬁlter.0078125. in order to set the passbandedge frequency. However. The following is a possible set of speciﬁcations for our interpolator: f = fdesign.e. The cost of implementing this ﬁlter is 110 coefﬁcients and 408 MPIS.interpolator(8.80). The desired stopband attenuation is 80 dB.'CIC'. Instead.Hc2) Digital Filters with MATLAB Ricardo A.3 CIC interpolators 133 sections are needed in order to obtain a certain stopband attenuation.'Nyquist'. let’s try to replace the last stage with an interpolateby8 CIC ﬁlter.Ast'. Hcic = design(f2). Hc2.0117. Example 51 As if often the case. cost(Hc) The result of this design is a interpolateby4 Nyquist ﬁlter. Now. fvtool(Hc. % Results in 4 sections The following commands can be used to replace the 3rd stage with a CIC and compare the two multistage designs: Hc2 = copy(Hc).0.0117π: f2 = fdesign. this stopband attenuation is not attained for the entire stopband. Losada . Overall. The minimum stopband attenuation for the entire stopband region is 80 dB. we should use the overall desired passbandedge frequency.64. i. First. followed by an interpolateby8 Nyquist ﬁlter.'TW. Unlike conventional lowpass ﬁlters. These speciﬁcations state the the cutoff frequency for the interpolator is π/64 and that the passbandedge frequency is π/64 − TW/2 = 0. in order to make our life easy when designing an analog postﬁlter for D/A conversion.stage(3) = Hcic.'multistage'.Ast'.'Fp. say 64.0.0117π.'Nstages'. the attenuation will be attained only where needed to suppress remnant highfrequency content left behind by previous stages of interpolation. let’s design this ﬁlter using conventional Nyquist ﬁlters and let us constrain the design to be done in 3 stages: Hc = design(f.interpolator(64.80). an example is the best way to understand this. Suppose we want to interpolate by a large factor. 0.6.1.
4 0. the multistage ﬁlter that uses the CIC in its last stage can be implemented with only 70 coefﬁcients and 88 MPIS.3.13 (we have normalized the passband gain to 0 dB in order to ease the comparison). However. . either ﬁlter meets the specs. . We stated that a linear interpolator can be though of as two hold inDigital Filters with MATLAB Ricardo A.8 0.9 Normalized Frequency (×π rad/sample) Figure 6. Losada . The last stage is the CIC ﬁlter.0117π where k = 1.2 0. at the points 2kπ/L ± 0. 6. However.2 Gain of CIC interpolators In the magnitude response plots we have shown so far. CIC interpolation ﬁlters have a very large gain. Figure 6. The magnitude response of the two implementations is shown in Figure 6. recall ﬁrst the linear interpolator case. L − 1 and L = 8. .e.5 0.3 0.13: Comparison of a conventional 3stage interpolation ﬁlter and one which uses a CIC interpolator in its last stage. Clearly.6 0. it does provide 80 dB or more attenuation where needed.1 0. This goes beyond the usual gain of L that all interpolators have.134 Special Multirate Filters Magnitude Response (dB) 0 −20 Conventional 3−stage interpolator 3−stage interpolator that includes a CIC filter Magnitude (dB) (normalized to 0 dB) −40 −60 −80 −100 −120 −140 −160 −180 −200 0 0.14 shows the magnitude of each of the 3 stages comprising the ﬁlter Hc2. we have normalized the passband gain of the ﬁlters to 0 dB in order to simplify visualization of the designs. Note that the CIC ﬁlter does not provide 80 dB attenuation over the entire stopband. To see why. However. . i.7 0.
6.6 0.3 CIC interpolators 135 Magnitude Response (dB) 0 −10 Magnitude (dB) (normalized to 0 dB) −20 −30 −40 −50 −60 −70 −80 −90 −100 Stage 1 Stage 2 Stage 3 (CIC) 0 0.'Magnitude') If we convolve two such impulse responses. we had to scale the result by a factor of L as well. A hold interpolator has impulse response given by h[n] = 1. terpolators convolved. 1. This can easily be veriﬁed with the following commands: Hh = mfilt. the linear interpolator itself has a passband gain of 3: Digital Filters with MATLAB Ricardo A.14: Magnitude response of each stage of a 3stage interpolation ﬁlter using a CIC interpolator in its last stage. when we convolved the two hold interpolators.holdinterp(3). However.7 0. 1.1 0. Losada .2 0. For example.4 0. is 3.[1 1 1]) Hl = mfilt. Hl. in order to get the impulse response of the linear interpolator correctly scaled. conv([1 1 1].3 0. A plot of the magnitude response (not in dB) shows that the gain of the ﬁlter at frequency 0.'MagnitudeDisplay'. fvtool(Hh.5 0. we get an impulse response which is 3 times larger than that of the corresponding linear interpolator.linearinterp(3).8 0.Numerator However.9 1 Normalized Frequency (×π rad/sample) Figure 6. take the case L = 3.
4).'Magnitude') The extra gain. that is LK −1 .3 Further details of CIC ﬁlters Although CIC ﬁlters seem pretty nifty. can be computed simply by using the gain command.1. The factor 1 − z−1 in the denominator means that the ﬁlter has a pole on the unit circle (at z = 1). In fact. Also. we can easily see that the passband gain is 81: Hcic = mfilt. their gain is given by LK . The CIC implementation is not minimal since it allows for a pole/zero cancellation. 13). The ﬁlter is still FIR even though it has feedback† In our treatment of CIC interpolators so far. we have ignored the differential delay (we have assumed it is one). This pole/zero pair should cancel. Typical values for the differential delay are 1 and 2. If we account for the fact that we expect any interpolator to have a gain of L. we do not cancel the pole and instead implement the ﬁlter with recursion. However. gain(Hcic) ans = 27 6.∗ For example. The differential delay is the order of the delays in the difference (comb) part of the ﬁlter.'MagnitudeDisplay'. † The strict deﬁnition of FIR is a ﬁlter whose minimal realization has a nilpotent statetransition matrix in its statespace representation (see [26] Ch. for implementation. Since CIC ﬁlters are obtained by (unscaled) convolutions of hold interpolators. fvtool(Hl. ∗ Digital Filters with MATLAB Ricardo A. A value different to one will also affect the passband gain.'Magnitude') Therefore the convolution of two hold interpolators has a gain of L2 = 9. it is worth noting that CIC ﬁlters are unstable.'MagnitudeDisplay'.3. yielding the traditional FIR transfer function. for L = 3 and K = 4. fvtool(Hcic.linearinterp(3). We will assume it is always 1 here.136 Special Multirate Filters Hl = mfilt.cicinterp(3. the only way for CIC ﬁlters to work (meaning that their output will not grow without bound) is by using ﬁxedpoint arithmetic (with overﬂows wrapping). Losada . note that CIC ﬁlters have been constructed by adding a pole and a zero at z = 1. the extra gain introduced by a CIC interpolator is LK −1 .
more likely.6. Nevertheless. the response of CIC ﬁlter provides a poor lowpass characteristic. f d /2] but rather a (perhaps small) subset of it. − f p ] ∪ [ f p . This subsequent ﬁlter will typically compensate for the notable droop in the passband of the CIC ﬁlter as well. say [− f p . we need to ﬁrst reduce the twosided bandwidth of the signal to f d as well. For this reason. no aliasing. in the band [− f d /2. with a subsequent lowpass decimation ﬁlter that will reduce the sampling rate to the vicinity of 2 f p (this can be done of course with more than one subsequent decimation ﬁlter resulting in an overall implementation with perhaps 3 or 4 stages). f p ] where f p ≪ f d /2.e. CIC ﬁlters are attractive for decimation purposes due to their low computational cost given that they do not require multipliers. However. Notice that in this case the various images would be just adjacent to each other but there would be no overlap. this can be compensated for by the use of subsequent ﬁlters that operate at reduced sampling rates and therefore do not incur a high computational cost. [− f d /2. f d /2] will be removed with either a singlerate lowpass ﬁlter. Losada . For this example. i.15. that is. It is assumed of course that the energy of the signal outside of the ﬁnal band of interest. Let us illustrate typical CIC behavior for a decimation problem by a factor M = 4. the aliasing is minimal at the center of the Nyquist interval (at DC).4 CIC decimators Consider a signal with twosided bandwidth equal to f s and sampled at a sampling rate f s . decimating CIC ﬁlters are usually used when the ultimate band of interest is not the entire interval [− f d /2. we have assumed f s = 100 MHz. coupled with the fact that the droop in the CIC ﬁlter is not as accentuated in the vicinity of DC. that the maximum amount of aliasing in Digital Filters with MATLAB Ricardo A. Note that the aliasing is maximum at the edges of the lowrate Nyquist interval. the decimated version of the CIC ﬁltered signal shows signiﬁcant overlap between spectral replicas. compared to an ideal brickwall lowpass ﬁlter.15. f d /2]. Let us examine Figure 6. or. The rectangular areas shown with a dashed line illustrate how the various shifted replicas would overlay had they been ﬁltered with a perfect brickwall ﬁlter. It is clear from Figure 6. In contrast. On the other hand.4 CIC decimators 137 6. If we need to decimate by a factor M in order to reduce the rate to a sampling frequency f d = f s /M.
we reverse the previous statement. 6. The full design parameters are listed next. Losada . the larger the droop of the ﬁlter in the band of interest that we need to compensate for. The actual maximum amount of aliasing at f p is due to the adjacent replica. The design parameters are: • the edge frequency f p Digital Filters with MATLAB Ricardo A. Namely. the smaller the gain for the replica at such frequency.4. we would like to have a large number of sections. For a CIC ﬁlter.e. the larger the number of sections K. the more sections we have. However.138 Special Multirate Filters Filtered magnitude spectrum after decimation 50 Final band of interest [0.1 Design parameters At this point we can enumerate the design parameters for the ﬁlter.Fp] Baseband filtered spectrum First shifted spectrum Second shifted spectrum Third shifted spectrum 0 dB −50 −100 −150 0 10 20 30 40 50 60 70 80 90 100 Frequency (MHz) Figure 6. determine the minimum number of sections K that are required. In order to design a CIC ﬁlter. given an amount of aliasing that can be tolerated. i. the ﬁnal band of interest will occur at f p . in order to limit the amount of aliasing.15: Final band of interest of signal decimated with a CIC ﬁlter.
it is not that the ﬁlter must provide a minimum attenuation of Ast throughout the entire stopband.Fs).decimator(M. what is usually done is to preequalize for the droop in a prior stage of a multistage design. Losada . In the case of decimation. a CIC decimation ﬁlter with the necessary number of sections K such that the amount of aliasing tolerated at f = f p is not exceeded can be designed as follows: M D Fp Ast Fs Hf Hcic = = = = = = = 8. the use of stopband attenuation is slightly different than with conventional lowpass ﬁlters.Ast.6. the sampling frequency prior to decimation f s 139 As with the design of CIC interpolators. In this case.Fp. The resulting design that meets the required attenuation consists of 6 sections. % 100 MHz fdesign. For the special case of linear and hold interpolators. we postequalize in a subsequent stage to the CIC decimator. % 80 dB 100e6. Instead.5 CIC compensators CIC compensators are singlerate or multirate ﬁlters that are used to compensate for the passband droop in CIC ﬁlters. at the end of the day. the amount of droop will depend on the number of sections K in the CIC ﬁlter.D. % Differential delay 2e6. Example 52 Given these parameters. Digital Filters with MATLAB Ricardo A. % Decimation factor 1. In the case of CIC interpolation. Of course. Ast is the minimum amount of attenuation permitted for frequencies that will alias back into the band of interest. % 2 MHz 80.'Fp.5 CIC compensators • the amount of aliasing tolerated at f p : Ast • the decimation factor M • optionally. 6.Ast'. design(Hf). this last interpretation is the same for any decimation ﬁlter. the number of sections is 2 and 1 respectively. As we have already stated.'CIC'.
since the small droop may not warrant equalization.Fp. the larger the ratio of the ﬁnal passband of interest f p to the original sampling rate f s .Fst. % Determine from previous design 4.140 Special Multirate Filters Magnitude Response (dB) 120 100 80 60 Magnitude (dB) 40 20 0 −20 −40 −60 −80 0 5 10 15 20 25 30 35 40 45 Frequency (MHz) Figure 6. In some cases. % 4. TW = 2.D. % Decimation factor for this stage 4.25 MHz 1.decimator(M2.K. Losada Digital Filters with MATLAB . Suppose we want to further decimate by a factor of 4 for an overall decimation factor of 32 for the two stages.Ast.Ast'.25 MHz.NumberOfSections. we can do without the compensation altogether. Example 53 As an example consider a possible compensator design for the CIC decimator design of the previous section. it may be so that we choose not to equalize if the overall multistage interpolation factor is large enough.16: Overall twostage design consisting of CIC decimator and compensator.Ap. Similarly.Fs/M). % 1 dB peaktopeak passband ripple fdesign. in the case of interpolation. design(Hf2). the smaller the amount of droop since only a very small portion of the passband of the CIC ﬁlter is involved. In the case of decimation.'Fp.Ap. Again.'ciccomp'. K M2 Fst Ap Hf2 Hd = = = = = = Hcic. Ricardo A.Fst.25e6. the larger the overall interpolation factor. the smaller the droop will be in the baseband spectrum.
18 shows the passband of the overall twostage decimator. Notice how the droop in the passband has been equalized. We can obtain the resulting overall decimator of cascading the two ﬁlters from: Hcas = cascade(Hcic. As with CIC interpolators.6 Farrow Filters 141 Magnitude Response (dB) 0 Magnitude (dB) (normalized to 0 dB) −20 −40 −60 −80 −100 −120 −140 −160 0 5 10 15 20 25 30 35 CIC Decimator CIC compensator 40 45 Frequency (MHz) Figure 6. we will compare a multistage decimator design including a CIC decimator and a CIC compensator with various other single. Figure 6. The gain can be found from gain(Hcic) and is once again given by MK .Hd). Losada .17: Magnitude response of each of the two stages in the design.17 shows how the CIC decimator attenuates the spectral replicas from the compensator.6. In Appendix C. fvtool(Hcas) % Show overall response Figure 6. Figure 6. 6.6 Farrow Filters We will now derive a ﬁlter that can be very effectively used for both fractional advances/delays and changing the sampling rate of signals by arbitrary factors (not necessarily rational).and multistage designs. CIC decimators have a large passband gain (for the same reason). Digital Filters with MATLAB Ricardo A.16 shows the resulting ﬁlter after cascading the CIC decimator and its compensator.
Losada .2 1.4 0.5 0. polynomials of any order can be used to ﬁt to the existing samples. All ﬁlter coefﬁcients remain constant. However. For the moment.2 0.5 Magnitude (dB) 109 108. or 3 are used in practice. without changing the sampling rate of the signal). it can be evaluated at any point. 2.5 108 107. since large order polynomials tend to oscillate a lot.18: Equalized passband of twostage design showing the effect of the CIC compensator on the droop. Farrow ﬁlters are basically obtained by (piecewise) polynomial interpolation (curve ﬁtting) on the input samples to the ﬁlter.6 0. consider the case where we want to interpolate solely for the purpose of introducing a fractional advance/delay (i. Therefore. the implementation of Farrow ﬁlters is essentially done using Horner’s method of polynomial evaluation.8 1 1. Farrow ﬁlters are suitable for instance to implement variable fractional advance/delay ﬁlters. The advantage of doing this is that it allows for tuning of the location at which we wish to interpolate by changing only one parameter in the ﬁlter.6 1.8 2 Frequency (MHz) Figure 6.e. A linearly interpolated fractional advance/delay can be implemented with two multipliers as we have already seen (this is just what each polyphase Digital Filters with MATLAB Ricardo A. This allows for interpolation at arbitrary locations between samples. Theoretically. Moreover.4 1.142 Special Multirate Filters Magnitude Response (dB) 110 109. typically polynomials of order 1. Once a polynomial has been ﬁtted. The easiest way to understand the derivation of Farrow ﬁlters is to start with linear interpolators.
Consider the twotap ﬁlter shown in Figure 6.19: Twotap ﬁlter that can be used for fractional delay by linear interpolation. Figure 6. we weigh each sample relative to the distance between it and the desired interpolated value. The ﬁlter as shown. by simply rewriting the previous expression as y[n] = x [n − 1] + α( x [n] − x [n − 1]) Digital Filters with MATLAB Ricardo A.6 Farrow Filters 143 Figure 6. branch of a linear interpolator does). performs a fractional delay of 1 − α (as mentioned before. The output is computed as y[n] = (1 − α) x [n − 1] + αx [n] Now. In order to compute the interpolated values between a previous sample.19. Figure 6.20 shows the resulting interpolated sample. x [n − 1].6.20: Computing a fractionally advanced/delayed interpolated sample from its two surrounding samples via linear interpolation. this is equivalent to a fractional advance of α if we allow for a full sample delay for the sake of causality). and a current sample. Losada . x [n].
Quadratic and cubic polynomial interpolation are very common cases. Figure 6. It is of course trivial to rewire the ﬁlter so that the input is the fractional delay β = 1 − α rather than the fractional advance α: y[n] = β( x [n − 1] − x [n]) + x [n] This is shown in Figure 6. α.1 Higherorder polynomials As usual. can be thought of as a second input to the ﬁlter. It can be tuned at any time.21. enabling a variable fractional advance/delay. we see we can implement the ﬁlter as shown in Figure 6. For this case. The advantage of this implementation is that there are no ﬁxed multipliers.22.144 Special Multirate Filters Figure 6.21: Fractional advance ﬁlter.6. we use two samples to the Digital Filters with MATLAB Ricardo A. better interpolation can be obtained at the expense of more computation.22: Fractional delay ﬁlter. Losada . The desired fractional advance. 6. Consider the cubic case.
Once we have four samples (such as the ﬁrst four input samples). To interpolate. left and two samples to the right of where we wish to interpolate. As in the linear case.6.23. we ﬁt a 3rdorder polynomial to the four samples (the polynomial is unique) and we evaluate the polynomial at the point we wish to interpolate.23: Fractional delay using cubic polynomials. we must allow for sufﬁcient delay in practice in order to make things causal. Then we advance one sample. Digital Filters with MATLAB Ricardo A. the leftmost sample is discarded and the rightmost sample comes into play. we interpolate by computing the value of the polynomial between the two innermost samples. ∗ As always. the Farrow structure makes use of Horner’s rule so that all coefﬁcients in the ﬁlter are constant while the fractional delay is an input that is tunable at runtime. Losada . but we compute values that lie between the two innermost samples only (between the second and third from the left). we ﬁt the unique (new) 3rdorder polynomial to these four samples. Once again. Once we have the polynomial. After this.∗ The situation is depicted in Figure 6. we would advance another sample and so on. for higherorder polynomials. we can interpolate.6 Farrow Filters 145 Figure 6.
1 0.2 0. However.1).6.146 Special Multirate Filters Magnitude Response (dB) 0 Linear−Lagrange Farrow Filter Cubic−Lagrange Farrow Filter −5 Magnitude (dB) −10 −15 −20 0 0.5.7 0.5 0. the linear. The fractional delay is speciﬁed in the design as a starting point.8 0. 6. As we know.4 0.3).3 0. Figure 6. Hf_cub = fdesign. As we have already stated. that for this structure. % Desired fractional delay Hf_lin = fdesign. Hlin = design(Hf_lin. as we have already said. and a ﬂat groupdelay. ideal fractional delays should have an allpass magnitude response.fracdelay(del.24 compares the magnitude responses. as the ﬁlter order N increases.2 Design of Farrow fractional delays The design of variable fractional delays using the Farrow structure and Lagrange interpolation boils down to selecting the ﬁlter order (the polynomial order).'Lagrange'). quadratic. Digital Filters with MATLAB Ricardo A. Losada . Example 54 Let us compare linear and cubic fractional delays using the Lagrange interpolation formula: del = 0.6 0.24: Magnitude response of linear and cubic fractional delays designed via the Lagrange interpolation formula. and cubic cases are the most typical.fracdelay(del. the number of coefﬁcients increases as N 2 . It is worth noting though. the value can be changed at any time while the ﬁlter is running.9 Normalized Frequency (×π rad/sample) Figure 6. Hcub = design(Hf_cub.'Lagrange').
6. however. In contrast.8 0.g. there is an extra one sample delay introduced by the higher order.2 1. the previous polyphase designs we had looked at could only change the rate by a factor given by the ratio of two integers. was to form an approximation to a rational number of the form L/M. the cubic design fairs a little better. Both of them are ideal relative groupdelays of 0.25: Group delay of linear and cubic fractional delays designed via the Lagrange interpolation formula. Losada .2 0. The groupdelays are plotted in Figure 6. In order to approximate an irrational factor adequately.3 0. neither is a particularly good approximation to an allpass ﬁlter.25.8 0. The best that could be done for irrational factors.9 0.9 Normalized Frequency (×π rad/sample) Figure 6. realizemdl(Hlin) or realizemdl(Hcub) in the Example above).5.4 1.1 1 0.5 0.5 0 0. As can be seen.5 1.3 Linear−Lagrange Farrow Filter Cubic−Lagrange Farrow Filter Group delay (in samples) 1. In the cubic case. Farrow ﬁlters can be used for both increasing and decreasing the samplingrate of a signal (by either integer or fractional factors).6 Farrow Filters 147 Group Delay 1.6.6 0.4 0. Simulink models for the Farrow ﬁlters resulting from these designs can be obtained as usual by using the realizemdl() command (e.6 0.6.3 Multirate Farrow ﬁlters So far we have seen how to implement singlerate fractional delays with Farrow ﬁlters.7 0.1 0. it Digital Filters with MATLAB Ricardo A. One of the key advantages of Farrow ﬁlters is that they can be used to change the samplingrate of a signal by an irrational factor without adding complexity in terms of number of coefﬁcients.7 0.
the fractional delay.5 and the output will be computed as y[m] = 0. Consider the modiﬁed diagram for the linear case of a Farrow fractional delay shown in Figure 6.26: Multirate Farrow ﬁlter.26. The dashed line separates the ﬁlter into a section running at the input signal’s samplingrate and a section running at the output samplingrate. Let’s say that we are increasing the samplingrate by a factor of 2. Digital Filters with MATLAB Ricardo A.148 Special Multirate Filters Figure 6.5( x [n − 1] − x [n]) + x [n] = 0. Notably. Let’s walk through a simple case to get a feel for how this operates.5x [n − 1] + 0. may be necessary for L and M to be very large integers. β m will take on the value 0. the actual number of MPIS will depend on the samplingrate conversion factor. one more output sample will be computed. now denoted β m will now change at every instant an output sample occurs. Nevertheless. the value held in the delay register will be used twice.5x [n] Before the input sample changes. As a consequence of this. β m will take the value 0 and the output will simply be y [ m + 1] = x [ n ]. the number of coefﬁcients required may be quite large. let’s describe how a multirate Farrow ﬁlter works. it is worth keeping in mind that while the number of coefﬁcients may be kept low by using Farrow structures. The ﬁrst time an input is used. Note that we have relabeled the output to be y[m] rather than y[n]. This is due to different input and output rates. Losada . To see this. Since for every input there are two outputs.
Then β m will cycle through the values {0. The formula is simply βm = m fs f s′ mod 1 where f s is the input sampling rate and f s′ is the output sampling rate. when increasing the samplingrate by a factor of two.5 and so forth.PolynomialOrder = 1. β m will cycle between the values {0. it is simply a matter of determining which values β must take.6 Farrow Filters 149 Subsequently. 3f 6. producing an output each time it changes. Notice that the delay follows the values of β m that we have indicated. 0} twice as fast as the input. The following code designs such a multirate ﬁlter (for the ﬁrstorder case) and ﬁlters some random data: % Design firstorder multirate Farrow filter f = fdesign. 1/3}. f. 2/3.1).28 shows partial plots for the cubic case rather than the linear case.'lagrange').27 shows partial plots of the input and output signals assuming f s = 1.6. β m will be once again set to 0. Let’s ﬁrst design a cubicpolynomial Farrow ﬁlter to perform such interpolation. Figure 6.5). y = filter(H.polysrc(3. Example 55 Let’s say we want f s′ = 5 s . In the general case. Digital Filters with MATLAB Ricardo A. In summary. % Filter some random data x = randn(100. Figure 6. the input sample will change.5. H = design(f.4 Polynomial interpolation and maximally ﬂat ﬁltering In this section we show that using polynomials as we have for piecewise curve ﬁtting by interpolating N + 1 samples using an Nthorder polynomial is equivalent to “traditional” interpolation from the signal processing point of view if we use a maximalyﬂat FIR ﬁlter as our lowpass ﬁlter. Losada .x). The improved smoothness of using a cubic polynomial is apparent from the ﬁgure. To see this. consider interpolation by L = 4.6.
5 −1 −1.5 Input signal Output signal Cubic interpolant 1 Amplitude 0.5 1 Amplitude 0. Losada .5 8 10 12 14 16 18 20 22 Time (sec) Figure 6.150 Special Multirate Filters 2 Input signal Output signal Linear interpolant 1.5 10 12 14 16 18 20 22 24 Time (sec) Figure 6.5 0 −0.27: Multirate Farrow ﬁltering using a linear polynomial.5 0 −0.5 −1 −1. Digital Filters with MATLAB Ricardo A.28: Multirate Farrow ﬁltering using a cubic polynomial. 2 1.
FracDelay=0.fracdelay(0.b2.M). We also show the ideal interpolation ﬁlter for reference.a1] = tf(H) H.polysrc(L.24. 1/4.b3 correspond to the polyphase components of the FIR ﬁlter returned by the intfilt() command: bint = intfilt(L.a3] = tf(H) It is trivial to verify that b0. [b2.25.a2] = tf(H) H. N = 3. M = 1.'lagrange'). In numerical analysis.N. Losada . where we noted how far from an ideal allpass the fractional delays produced by polynomial interpolation were. [b1.a0] = tf(H) H. We had already seen in this in a different form in Figure 6. better piecewise curveﬁtting is obtained by using techniques such as hermite polynomial interpolation and cubic splines.b1. H = design(f.75) H = design(Hf. As previously noted. [b0. To interpolate by 4. Digital Filters with MATLAB Ricardo A. 1/2.5.'lagrange'). % Polynomial order f = fdesign. the maximally ﬂat characteristic has the undesirable effect of a wide transition band as a result.PolynomialOrder = N.FracDelay=0.FracDelay=0.6 Farrow Filters 151 % Design firstorder multirate Farrow filter L = 4.'lagrange'). f. the fractional delay will take on values of {3/4. typically we improve the interpolation by using ﬁlters with better transitionwidth than maximallyﬂat ﬁlters. 0} in a cyclic manner. This tells us that polynomial interpolation produces only acceptable ﬁlters for samplingrate conversion applications (and fractional delays). In signal processing. The magnitude response of the ﬁlter bint is shown in Figure 6.29. [b3.6. If we set the fractional delay of the ﬁlter to each of those four values and in each case compute the equivalent transfer function: Hf = fdesign.
The ideal decimation factor would be M = 17. However.6. 6.5 0.9 Normalized Frequency (×π rad/sample) Figure 6. Losada Digital Filters with MATLAB . We wish to reduce the bandwidth and the rate by decimating. multistage techniques are applicable only when the rate change factor is not a prime number.4 0.2 0. is to change the rate by a nonprime number near the prime number we are looking for.5 Magnitude 2 1. We may have oversampled as signal as part of analog to digital conversion for the purpose of simplifying the antialiasing analog ﬁlter.6 0. % 17 kHz Ricardo A.29: Magnitude response of a maximallyﬂat interpolateby4 ﬁlter corresponding to cubic polynomial interpolation. we need not be “stuck” with a singlestage design.152 Special Multirate Filters Magnitude Response 4 Maximally flat filter Ideal interpolation filter 3. and use a Farrow ﬁlter to change the ﬁnal rate so as to obtain the desired overall ratechange.3 0.7 0.5 3 2. since 17 is a prime number. One possibility. we can only design a singlestage decimator such as: Fs Fp = 680e3.5 Using Farrow samplerate converters in multistage designs We have seen how multistage/multirate designs can result in signiﬁcantly reduced implementation cost when compared to singlestage cases. Example 56 Suppose we have a signal sampled at 680 kHz. % 680 kHz = 17e3. if we need to change the rate by a prime number.5 0 0 0. However.1 0. but the band of interest extends to 17 kHz only.5 1 0.8 0. However.
decimator(M.'kaiserwin').TW/2. We can cascade this ﬁlter after the multistage decimator to achieve the goal we want: Hcas = cascade(Hmult.16.'multistage') cost(Hmult) The result is a multistage design with 4 halfbands in cascade.17). % Decimation factor Hf = fdesign. Hd = design(Hf.'TW.Ast'. Hmult = design(Hf.'lagrange').'Nyquist'.6 Farrow Filters 153 TW = 6e3. due to the wide transition band of the Farrow ﬁlter that follows.M.polysrc(16. The cost is of about 92 coefﬁcients and 10 MPIS. Digital Filters with MATLAB Ricardo A. In order to reach the overall decimateby17 factor.Fs). we may choose to have a smaller transition band here.H). say half the transition width: Hf = fdesign. An alternative strategy may be to design a multistage ﬁlter that decimates by 16. we can design a cubicpolynomial Farrow ﬁlter to perform a ratechange by a factor of 16/17: f = fdesign. % 6 kHz Ast = 80.'Nyquist'.Ast. In fact.Fs). cost(Hd) The cost of this design is of about 543 coefﬁcients and 32 MPIS. Losada .6.Ast.TW. % 80 dB M = 17.decimator(16.'TW. H = design(f.Ast'.
Part II Filter Implementation .
Minimumphase FIR ﬁlters do not have any symmetry in their coefﬁcients while linear phase FIR ﬁlters have either symmetric or antisymmetric coefﬁcients.1 Some basics on implementing FIR ﬁlters There are several factors that inﬂuence the selection of the ﬁlter structure used to implement an FIR ﬁlter. it may be possible to implement a linearphase FIR ﬁlter using less multipliers than the minimumphase ﬁlter by taking advantage of the symmetry even if the ﬁlter length of the linearphase is larger. If the ﬁlter length is very large. This may be important enough to stick with a minimumphase design. it may be preferable to use a frequencydomain implementation based on the FFT. For instance. as we have seen. . minimumphase ﬁlter introduce a minimal transient delay. In other words the implementation advantages of linearphase ﬁlters may offset the gains of a minimumphase design making it preferable to use a linearphase ﬁlter even when linearity of phase is not critical for the application at hand. there is an important distinction between minimumphase and linear phase ﬁlters. Of course there are other reasons to use minimumphase ﬁlters that may give a compelling reason to do so. the target hardware is an important factor. If it is to be implemented in the time domain.Chapter 7 Implementing FIR Filters 7. From a design perspective. Depending on the target hardware.
To visualize the structure we can create a Simulink block for the resulting ﬁlter using the realizemdl command.lowpass('N. many DSP processors have been architectured to implement this structure efﬁciently. So the cost of using this ﬁlter structure is maximum in terms of the number of multipliers required as can be seen using cost(Heq). multiplied with a ﬁlter coefﬁcient. The number of delays is equal to the ﬁlter order and the number of coefﬁcients (number of taps). and accumulated to form the output. Hf = fdesign.1. Heq = design(Hf. The ﬁlter structure that is used to implement the ﬁlter is speciﬁed by the string 'dffir' (which is the default) and corresponds to the socalled directform structure (also called a tapped delay line).. Digital Filters with MATLAB Ricardo A. The structure has some regularity in that a sample is read from memory (a delay is simply a register).3.'FilterStructure'. If we look inside the subsystem.1. To minimize the amount of data copies. determines the ﬁlter length.Fst'.'dffir'). so that it should be used even for linearphase ﬁlters on that hardware. DSP processors have historically been built with this multiplyaccumulate (MAC) instruction in mind. A downside of the directform structure is that is does not take advantage of the symmetry (or antisymmetry) in the coefﬁcients of linearphase ﬁlters.. The resulting block is a subsystem.1 Directform ﬁlter structure Consider the design of an FIR ﬁlter.3. Nevertheless. which is one more than the number of delays. Losada . The ﬁlter order is very low for illustration purposes.Fp. realizemdl(Heq). The structure requires a shift of the input data throughout all delays for each sample. circular buffers are commonly used [3].156 Implementing FIR Filters 7.8). Of course the structure is wellsuited for ﬁlters that do not present symmetry in their coefﬁcients such as minimumphase FIR ﬁlters. we will see the structure shown in Figure 7.'equiripple'.
'dfsymfir'). In general.1: A 4tap FIR ﬁlter implemented in directform. Hsym = design(Hf. The ﬁlter can be implemented using only two multipliers by using the symmetric directform structure. the number of multipliers reDigital Filters with MATLAB Ricardo A. cost(Hsym) The ﬁlter structure obtained in Simulink by using the realizemdl command is shown in Figure 7. Losada .2 Symmetric directform ﬁlter structure The design shown in the previous section was a linearphase design.7. 7.1 Some basics on implementing FIR ﬁlters 157 Figure 7. there are two unique multipliers.'FilterStructure'.2.1.'equiripple'. Since the number of coefﬁcients is four. realizemdl(Hsym).
2: A 4tap symmetric FIR ﬁlter implemented using the symmetric directform ﬁlter structure. 7.3 Transposed directform ﬁlter structure The directform structure has the disadvantage that each adder has to wait for the previous adder to ﬁnish before it can compute its result. Digital Filters with MATLAB Ricardo A.1. quired is half∗ of the number required for the directform structure. this introduces latency which lim∗ Rounded up if the number of coefﬁcients is odd. Losada .158 Implementing FIR Filters Figure 7. For highspeed hardware such as FPGAs/ASICs. Notice that even though there are only two multipliers. there are still three delays (same as for the directform structure) required since the number of delays corresponds to the order of the ﬁlter.
It can be generated using the realizemdl command on a ﬁlter whose ﬁlter structure has been selected to be transposed directform. This allows realtime handling of data with with very high sampling frequencies. realizemdl(Htran) Digital Filters with MATLAB Ricardo A. Htran = design(Hf.'FilterStructure'.3: A 4tap FIR ﬁlter implemented in transposed directform. Losada . its how fast the ﬁlter can be clocked.'equiripple'. A solution to this is to use the transposed directform structure instead. The transposed structure for a 4tap ﬁlter is shown in Figure 7.'dffirt'). the delays between the adders can be used for pipelining purposes and therefore all additions/multiplications can be performed in fully parallel fashion.7.1 Some basics on implementing FIR ﬁlters 159 Figure 7. With this structure.3.
Most of the values of the impulse response are small. the output signal cannot have the full wordlength resulting from this bit growth. When we quantize the impulse response of an FIR ﬁlter. This will introduce some quantization error at the output as we will see below. Digital Filters with MATLAB Ricardo A. We must throw out bits at the output. we simply remove LSBs. usually to match the wordlength of the input signal. With all arithmetic being performed with full precision. No overﬂow will occur by throwing out LSBs. In most cases. Example 57 Let’s compute the SNR when quantizing the impulse response of an FIR ﬁlter using 16 bits to represent the coefﬁcients: ∗ See Appendix D. there will be bit growth associated with ﬁltering.1 Quantizing the ﬁlter’s coefﬁcients The ﬁlter coefﬁcients have to be quantized from doubleprecision ﬂoating point in which they are designed into ﬁxedpoint representation with usually a smaller number of bits. so that the average signal strength does not cover the available range.160 Implementing FIR Filters 7. Appendix D provides a brief review of ﬁxedpoint concepts that may be useful prior to reading through the rest of this Chapter. To throw away bits.2. Some care must be taken when quantizing the coefﬁcients so that we use enough bits to achieve the desired stopband attenuation of the ﬁlter and we scale the bits in the most beneﬁcial manner (more on this below). and given a ﬁxedpoint input signal. we should not expect to achieve the full 6 dB/bit∗ . Losada . it is easy to ﬁgure out what it would take to perform all multiplications/additions within the ﬁlter in a such a way that no roundoff error is introduced (socalled fullprecision mode). We must make sure we make the most of the limited number of bits we have. The ﬁrst thing to do is check if there are enough bits available to cover the required dynamic range. Once the coefﬁcients have been quantized. 7. This is not surprising given the sinclike shape of most FIR impulse responses.2 Fixedpoint implementation Implementing an FIR ﬁlter using ﬁxedpoint arithmetic is generally a rather simple task.
'equiripple'). we may use the additive noise model to get an idea of how the frequency response is affected. A good ruleofthumb is that we can expect about 5 dB/bit when quantizing an FIR ﬁlter.0. h = design(f.'equiripple'). That’s because we cannot represent exactly that value. etc)∗ .125). will affect the frequency response of the quantized impulse response by adding a noiseﬂoor of intensity ε2 /12. the quantized impulse response is hq [n] = h[n] + e[n] The additive noise. If the largest value of the impulse response is positive and a power of two.0. If we choose an interval larger than the minimum.3067 When we quantize the impulse response of an FIR ﬁlter.0. e[n].80).2. ∗ Digital Filters with MATLAB Ricardo A.8). [1. If the impulse response is given by h[n].[8. % Nonquantized impulse response Hd.5.80).125. Losada . reducing the attainable stopband attenuation of the ﬁlter. We want to choose the smallest interval that contains the largest (absolute) value of the impulse response.5).nyquist(4.Numerator.'TW. % Uses 16bit coefficients by default himpq = Hd.Numerator. Hd = design(Hf. the effect on the stopband is most critical.Ast'. then it is somewhat of a judgement call whether or not we want to allow for a small overﬂow error for that one coefﬁcient. Note the open interval on the right.Arithmetic = 'fixed'.4.lowpass(0. In most cases.1). we are just wasting bits.0.7. By this we mean. % Quantized impulse response SNR = 10*log10(var(himp)/var(himphimpq)) SNR = 84.2 Fixedpoint implementation 161 Hf = fdesign.5. The range of values that can be represented with a given wordlength/fraction length combination falls between a negative and a positive power of two (for instance the intervals [0. distorting both the passband and the stopband of the ﬁlter.5. Example 58 Consider the following equiripple Nyquist design: f = fdesign. [0. How close we get will depend on the number of bits available. scale them so that impulse response is representable with the bits we have without wasting any bits. as long as we use the bits wisely. himp = Hd.0.
This is a nice property of all Nyquist ﬁlters. The magnitude response of the quantized ﬁlter is shown in Figure 7. h.25. we used a fraction length of 15.5. In this example we choose to live with small overﬂow in the quantization of the largest coefﬁcient (we quantize the value to 0. Note that this analysis along with most others (including the impulse response) only takes into account the quantization of the coefﬁcients.25. It does not take into account the fact that there may be roundoff/overﬂow introduced by the multiplications/additions when actually ﬁltering data. we perform the following steps: h. Using the 5 dB/bit rule. The magnitude response for this case is shown in Figure 7. Losada . Since the largest coefﬁcient is 0.5. another option would be not to implement this coefﬁcient as a multiplier at all (instead simply perform a bit shift).162 Implementing FIR Filters The ﬁlter has a minimum attenuation of 80 dB. we can choose a fractional length of 17 to scale the bits so that all values in the interval [0. Notice that the quantized ﬁlter no longer meets the required 80 dB stopband attenuation (the passband also has greater error than in the previous case). % Uses 16bit wordlength by default h. As we have said. depending on the hardware. To emphasize the point regarding the need to use both the right number of bits and use them wisely.5) is representable without overﬂow).25 − 2−17 ). consider what would have happened in the previous example if instead of a fraction length of 17.0.25.25 overﬂows with a fraction length of 17.25) are representable. ∗ The 16 bits are adequate in order to preserve quite faithfully the intended magnitude response of the ﬁlter. so a fraction length of 16 is used by default (which along with the wordlength. Note that there is automatic scaling of the coefﬁcient bits by default.0. Its largest coefﬁcient is 0. In order to set a 16bit wordlength and a 17bit fraction length. the largest coefﬁcient is always a power of two. It is designed to avoid overﬂow in the quantization while minimizing the interval so that the bits are used as best possible. means any value in the interval [0. strictly speaking the quantization of the coefﬁcient equal to 0.Arithmetic = 'fixed'.CoeffAutoScale = false. Since the value is a power of two. we need at least 16 bits in order to provide the 80 dB of attenuation. ∗ Digital Filters with MATLAB Ricardo A.NumFracLength = 17.4.
4 0.7 0. This increase in roundoff error results in raising the quantization noise ﬂoor in the frequency domain.5 0. The maximum roundoff error (assuming we round to the nearest quantized value) can be as a large as 2−16 as opposed to 2−18 if we had used a fraction length of 17. depending on the hardware used to implement the ﬁlter. reducing the attainable minimum stopband attenuation. Losada . The reason we can no longer meet the stopband attenuation is that we are essentially wasting two bits by using a fraction length of 15.3 0.7.4: Magnitude response of equiripple Nyquist ﬁlter quantized with 16bit wordlength and a fraction length of 17. we have assumed that the same number of bits are used to represent each coefﬁcient of an FIR ﬁlter.2 Fixedpoint implementation Magnitude Response (dB) 0 −10 −20 163 Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 0 0.6 Filter #1: Quantized Filter #1: Reference 0.9 Normalized Frequency (×π rad/sample) Figure 7.8 0.1 0. could be removed without affecting the performance. Redundant bits in smaller coefﬁcients So far. Example 59 Let’s look again at what happens when we quantize the following ﬁlter: Digital Filters with MATLAB Ricardo A. Because usually many of the coefﬁcients are quite smaller than the largest coefﬁcient. many of the bits used for these small coefﬁcients are redundant and.2 0.
Arithmetic = 'fixed'.true.4.9 Normalized Frequency (×π rad/sample) Figure 7. Hf = fdesign. 8 bits to represent the second coefﬁcient.434. The repeated 1’s towards the left (the MSB) are all unnecessary in order to represent the value.5. Hd.7 0. B = fi(Hd.2 0. etc.bin ans = 1111111111011100 1111111110100110 1111111111010100 ...16). Because the largest value of the coefﬁcients is about 0.164 Magnitude Response (dB) 0 −10 −20 Implementing FIR Filters Magnitude (dB) −30 −40 −50 −60 −70 −80 −90 0 0.6 Filter #1: Quantized Filter #1: Reference 0. and so forth.0.0.5: Magnitude response of equiripple Nyquist ﬁlter quantized with 16bit wordlength and a fraction length of 15. Hd = design(Hf. Losada .5 0. Now let’s look at the binary representation of say the ﬁrst three coefﬁcients: B.'equiripple').5. the second value as 10100110.lowpass(0. they have been quantized with a fractional length of 16 (the default wordlength is in turn 16 bits which is inline with the requirement for this ﬁlter following the 5dB/bit rule).4 0. Digital Filters with MATLAB Ricardo A.16. The variable B contains the ﬁxedpoint numbers corresponding to the ﬁlter’s coefﬁcients.80). Indeed.3 0.1 0. we could represent the ﬁrst value simply as 1011100.8 0. So in reality we need only 7 bits to represent the ﬁrst coefﬁcient.Numerator.
Assume the input signal has been quantized already and the ﬁlter coefﬁcients have been quantized as well.bin The full 16 bits are used for the largest coefﬁcients. The fact that we have redundant bits in many coefﬁcients is another way of understanding why we cannot achieve the full 6 dBperbit when quantizing FIR ﬁlter coefﬁcients.2 Fixedpoint implementation 165 Indeed.00054931640625. Losada . This socalled full precision mode represents the best possible result we can achieve when ﬁxedpoint Digital Filters with MATLAB Ricardo A. note that 1111111111011100 with a fractional length of 16 corresponds to the value 0. For instance for the middle one (the largest one): Hd. it is possible to take advantage of the fact that many coefﬁcients have redundant bits by using smaller multipliers (in terms of the number of bits) for these coefﬁcients. thus the SNR decreases.true.16). It is possible to easily perform all additions and multiplications within the ﬁlter structure in such a way that no roundoff error is introduced. C30.4339599609375. Effectively we don’t use all bits available to represent most of the coefﬁcients.Numerator(30) ans = 0. If the number of bits used to represent the output is the same as the number of bits used for the additions (the accumulations) then no roundoff error is introduced throughout the ﬁlter.4339599609375 C30 = fi(0.true.7.bin ans = 0110111100011000 which of course has no redundant bits.2.16.2 Fixedpoint ﬁltering: Directform structure Consider an FIR ﬁlter implemented in direct form. 7.7.16) C1. With certain hardware. But this number can be represented without loss of precision using only 7 bits: C1 = fi(0.00054931640625.
the number of bits we need in order to perform the additions with full precision is ⌊log2 (58)⌋ + 1 = 6 Digital Filters with MATLAB Ricardo A. Example 60 Consider once again the following design: Hf = fdesign.166 Implementing FIR Filters ﬁltering with an FIR ﬁlter implemented in direct form.1). F2 }. If the input is represented with 16 bits as well.1). this means that there will be bit growth once the input signal is multiplied with the ﬁlter’s coefﬁcients (see Figure 7.5. the product of the two numbers can be represented with no roundoff by using a wordlength/fraclength of { B1 + B2 .5.Arithmetic = 'fixed'.80). For a directform FIR ﬁlter to be implemented with full precision.'equiripple').lowpass(0. In an FIR ﬁlter implemented in direct form. Since there are 58 additions to be performed.4. Hd = design(Hf. F1 + F2 }.0. we saw that given two ﬁxedpoint numbers. Hd. The only quantization error is due to the coefﬁcient quantization (the quantization of the input signal is considered separately as it is not affected by what happens within the ﬁlter itself. No overﬂows will occur in full precision mode because we assume we will grow enough bits when adding (see below) to accommodate for signal levels increasing. full precision multiplications would mean that the values to be added are represented with 32 bits. F1 } and the other with wordlength/fraclength given by { B2 . Full precision products In Appendix D. one with wordlength/fraclength given by { B1 .0. it is necessary to allow for a bitgrowth of ⌊log2 ( N )⌋ + 1 bits. there are a series of additions that occur after multiplying the input signal with the coefﬁcients (see Figure 7. Full precision additions In Appendix D. we saw that in order to perform a series of N additions without introducing roundoff error. The coefﬁcients are represented with 16 bits. Losada .
434.5). y[n] = ∑ h[m] x [n − m] m =0 N Using the triangle inequality for the 1norm. Full precision multiplications/additions given the actual coefﬁcient values Let’s look again at the previous example to see if we actually need 32 bits for the fullprecision multiplications. Losada m =0 Digital Filters with MATLAB . F2 } = {16. The coefﬁcients are represented with { B1 .e. the input signal is assumed to fall within the interval [−1. the interval used to represent the products must be [−0. The fraclength for the product is given by F1 + F2 = 31. 16} and the input is assumed to be represented with { B2 . Now let’s move to fullprecision additions.7. The largest coefﬁcient of the ﬁlter Hd is 0. Since the largest possible value that any input value multiplied by any coefﬁcient can produce is about 0. This interval is covered by making the wordlength equal to the fraclength. i. it is possible to perform the additions with fullprecision by using even less bits than what it is speciﬁed by the formula ⌊log2 ( N )⌋ + 1. we use some simple math. 0.2 Fixedpoint implementation 167 As it turns out. 1). Since the fraclength is 31.434. Let’s take a look at the convolution equation for a length N + 1 FIR ﬁlter.5. the wordlength needed for fullprecision multiplications is also 31. F1 } = {16. We start by taking the absolute value at both sides of the convolution equation. We will look at how to do so next. not 32. 15}. we have y[n] ≤ = ∑ h[m] x[n − m] m =0 N N ∑ h[m] x[n − m] Ricardo A.. To do so. y[n] = ∑ h[m] x [n − m] m =0 N Given that we should know what are the maximum values that the input can take. we want to determine what are the maximum numbers the output can take.
If we look at the values for AccumWordLength and OutputWordLength when we write get(Hd). we see than indeed these values have been set to 33 bits. the settings for the transposed directform structure shown in Figure 7. we may even be able to reduce the required number of bits further. if R/2 = 1.168 Implementing FIR Filters Let’s say that the input covers the range [− R/2. 7. We have seen how we determine the number of bits required for fullprecision implementations.'l1') ans = 1. R/2). it is necessary to add two bits in order to implement a fullprecision ﬁlter. 2).5. For example. the maximum. value the output can take is given by h[n] 1 . This tells us how many bits we need to grow in order to perform fullprecision arithmetic throughout the ﬁlter. Digital Filters with MATLAB Ricardo A. i. 0.e. R R N h[n] y[n] = ∑ h[m] = 2 m =0 2 1 Thus the 1norm of the impulse response provides a gain factor for the output relative to the input. This means that in the worst case. we can compute the 1norm of its impulse response as follows: norm(Hd. Losada . Since the multiplications fall in the interval [−0. two more bits than what is used for the multiplications.9904 This means that we need to ensure the additions can represent the range [−2. If we were to actually take into account typical values we think the input can assume.5).3 Fixedpoint ﬁltering: Transposed directform structure In order to perform all operations with full precision. Example 61 For the 59tap ﬁlter Hd we have been using.2. this value is still somewhat conservative because it assumes the worst possible case for the input.3 are almost identical to the nontransposed directform case. As a matter a fact.
the fullprecision version of Hd had 33 bits at the output and a fractional length of 31. Hd. The situation is depicted in Figure 7. 7. In the transposed structure. the states must have the same wordlength as the wordlength used for addition. we do not necessarily mean simple truncation. ∗ Digital Filters with MATLAB Ricardo A.2. Losada .FilterInternals = 'specifyPrecision'. This means we may need to discard∗ 17 LSBs at the output of the ﬁlter. This is typically more than twice the wordlength of the input. As discussed in Appendix D. % 3316 = 17 Hd. In the directform case. G is the number of bits that need to be added for the additions to be performed without roundoff as discussed above. we assumed that the coefﬁcients are represented with the same number of bits as the input and all multiplications/additions are performed with full precision.4 Quantization of the output signal In many cases. this means we can replace the quantizer with an adder as shown in Figure 7.OutputFracLength = Hd.2 Fixedpoint implementation 169 The only difference has to do with the wordlength necessary for the state registers. It is possible that when we discard. so that the transposed structure clearly has higher memory requirements for a given ﬁlter. If we discard 17 LSBs. The idea is the same for other structures. the states needed to have the same wordlength as the input signal in order to avoid roundoff. we need to reduce the number of bits at the output of the ﬁlter for downstream processing.6 for the directform structure. the input was represented with 16 bits.OutputFracLength17.OutputWordLength = 16. In the example above.7. we will have 16 bits at the output and a fractional length of 14: Hd. but the fullprecision output required 33 bits. A common case is to use the same number of bits for the output as we did for the input. In the example above.7. In that ﬁgure. we perform some sort of rounding such as round to nearest. For the directform structure. the quantization can be modeled as additive white noise with variance ε2 /12 as long the number of bits discarded is relative large (more than 3). % 14 The variance of the quantization noise that we introduced will be given by: Note that by discarding. This is controlled with the RoundMode setting once the ﬁlter internals have been set to specify the precision.
avgpower(P) ans = 3.6: Directform FIR ﬁlter with quantization at the output.8.4). Losada . and the output is simply He (z) = 1. we should keep in mind that the variance has already been scaled by 2π. Note that the PSD is approximately ﬂat as it should be for white noise (the plot can be obtained by calling the noisepsd command with no outputs). When we integrate in order to compute the average power. The PSD here includes a factor of 1/2π.1044e10 We can also ﬁnd this value by integrating the powerspectral density of the output signal due to the noise signal e[n] by using (D.∗ The PSD is plotted in Figure 7.0592e10 This value is close to the theoretical value we expect from the additive noise model as computed above. therefore the intensity of the PSD is given by the variance divided by 2π. The integral of the PSD gives the average power or variance: P = noisepsd(Hd). 2ˆ(14)ˆ2/12 ans = 3. Note that the transfer function between the noise input. e[n].170 Implementing FIR Filters Figure 7. ∗ Digital Filters with MATLAB Ricardo A.
yr [n]. We would like to distinguish between three different cases: • What we ideally would want to compute.7.5 Evaluating the performance of the ﬁxedpoint ﬁlter In order to evaluate how well the ﬁxedpoint ﬁlter compares to the reference ﬂoatingpoint ﬁlter. but without allowing any further roundoff noise within the ﬁlter or at its output. we can ﬁlter some test data and compare the results. • What we actually compute. Losada . • The best we can hope to compute. This is the result we get with all ﬁnal Digital Filters with MATLAB Ricardo A. y[n]. This is the result of using the nonquantized original ﬁlter coefﬁcients and performing all multiplications/additions with inﬁnite precision (or at least doubleprecision ﬂoatingpoint arithmetic).2 Fixedpoint implementation 171 Figure 7. In order to isolate the behavior of the ﬁlter. This is the result of using the quantized coefﬁcients. 7. All multiplications/additions are performed with fullprecision.2.7: Directform FIR ﬁlter with quantization at the output. it is important that the same quantized input test data is used in all cases. yd [n].
80). x = fi(2*(rand(1000.0. Nevertheless.1 0. Hd.0).9 1 Normalized Frequency (×π rad/sample) Figure 7.4 0.4. Clearly. we would have to use more bits to represent the ﬁlter coefﬁcients (and throughout the ﬁlter). Losada .5.'equiripple'). Example 62 Consider once again the following design: Hf = fdesign.7 0.5). if we choose to use 16 bits for the coefﬁcients. A plot of the magnitude response of Hd shows that 16bits are not quite enough in this case to get the full 80 dB attenuation throughout the stopband. the quantized ﬁlter uses 16bits to represent the coefﬁcients by default.8: Power spectral density of the quantization noise at the output of an FIR ﬁlter.2 0. Digital Filters with MATLAB Ricardo A.172 Implementing FIR Filters Round−off Noise Power Spectrum −100 −105 −110 Power/frequency (dB/rad/sample) −115 −120 −125 −130 −135 −140 −145 −150 Computed PSD Theoretical PSD 0 0.8 0. In order to make the best we can hope to compute closer to what we ideally would compute.16.3 0.15). Hd = design(Hf. the best we can hope to achieve can be computed for some test data as follows: rand('state'.lowpass(0.6 0.true.Arithmetic = 'fixed'.5 0. what we actually compute can at best be the same as the best we can hope to compute.1). As we have said. ﬁxedpoint settings in our ﬁlter.5.0.
Hd. this can be done as follows: Hd.OutputWordLength = 16. Example 63 Continuing with our previous example. % Uses fullprecision var(yrdouble(yd16)) ans = 4. Once again. % 3316 = 17 Hd. var(double(y)double(yd16)) ans = 3. % Compute reference filter yr = filter(Href. If we now ﬁlter the same data and compute the energy in the error between the best we can hope for and what we actually compute: y = filter(Hd.e. Losada .8591e10 The ﬁlter Hd performs all multiplications/additions using full precision because the FilterInternals property is set by default to 'FullPrecision'. Suppose we can only keep 16 bits at the output and use 16 bit coefﬁcients. i.OutputFracLength17. yd18 = filter(Hd18.x). this means we need to remove 17 LSBs at the output as was shown in Figure 7.7. In this example. yd16 = filter(Hd.CoeffWordLength = 18. If we decide to use say 18 bits for the coefﬁcients instead of 16.1004e10 We of course obtain the same result we had previously computed for the variance of the noise. Hd18. we can get closer to the result obtained with the reference ﬁlter. 2ˆ(14)ˆ2/12.x). % Uses fullprecision var(yrdouble(yd18)) ans = 2.x).. Digital Filters with MATLAB Ricardo A.x).4946e11 Once we have settled the number of bits for the coefﬁcients.2 Fixedpoint implementation 173 Href = reffilter(Hd). Hd18 = copy(Hd).OutputFracLength = Hd. We then measure how well our actual results compare to the best we can hope for.FilterInternals = 'specifyPrecision'. we have established a baseline for the best we can hope to achieve if we can’t use fullprecision.6.
and pole/zero computation. The closer the magnitude response estimate resembles the magnitude response computed solely based on the quantization of the coefﬁcients. If we start with full precision.2 0. computes an estimate of the magnitude response of the ﬁlter by actually ﬁltering data through it. Losada . Example 64 Let us continue with the same design we have been using the last several examples. The ﬁxedpoint ﬁltering means that roundoff error may be introduced because of discarding bits at the output or other roundoff if the additions/multiplications are not performed with full precision. groupdelay.3 0. This is true of the magnitude response.8 0.1 0. the magnitude response estimate is almost indistinguishable from the magnitude response: Digital Filters with MATLAB Ricardo A.6 0. we can use the magnitude response estimate to evaluate the performance of the ﬁxedpoint ﬁlter.9: Magnitude response estimates for various output wordlengths. the more the actual ﬁltering approaches the best we can hope to compute. impulse response.7 0. Using the magnitude response estimate to evaluate performance Most of the analysis commands we perform on ﬁxedpoint ﬁlters only take into account the coefﬁcient quantization. The magnitude response estimate however.5 0. In this way.9 1 Normalized Frequency (×π rad/sample) Figure 7.174 Implementing FIR Filters Magnitude Response Estimate 0 −10 −20 −30 Full precision 16−bit output 14−bit output 12−bit output Magnitude (dB) −40 −50 −60 −70 −80 −90 −100 0 0.4 0.
Losada . We’ll start by discarding 17 bits.7 0. % 3316 = 17 Hd.4. He = freqrespest(Hd.8192).2 Fixedpoint implementation 175 Magnitude Response Estimate −45 −50 −55 −60 −65 −70 −75 −80 −85 −90 −95 −100 Full precision 16−bit output 14−bit output 12−bit output Magnitude (dB) 0.OutputFracLength17. He16 = freqrespest(Hd. Hf = fdesign.OutputWordLength = 16.FilterInternals = 'specifyPrecision'.lowpass(0.5. Hd.80).0023 Now.5 0.8 0.0. 50. we will compute the magnitude response estimate using always the same 16bit coefﬁcients.8192). % 16bit coefficients H = freqz(Hd).'NFFT'.5. Hd = design(Hf. Hd.50. norm(HHe) ans = 0. Hd.Arithmetic = 'fixed'.6 0. Digital Filters with MATLAB Ricardo A. but in each case discarding a different number of bits at the output.1.'equiripple').0.7. in order to get a reliable average from the estimate (the computation takes a while).10: Stopband details of magnitude response estimates for various output wordlengths.9 1 Normalized Frequency (×π rad/sample) Figure 7.'NFFT'. Notice that we now use a relatively large number of trials.OutputFracLength = Hd.
8192).OutputFracLength = 10. Losada .OutputFracLength = 12.'NFFT'. Hd. Digital Filters with MATLAB Ricardo A.'NFFT'.9.50. Hd. He14 = freqrespest(Hd. He12 = freqrespest(Hd.8192). Hd. Implementing FIR Filters The plot of the various magnitude response estimates is shown in Figure 7.176 We’ll repeat this for 14bit and 12bit outputs.OutputWordLength = 14. Hd.50.OutputWordLength = 12.10. Note the quantization at the output basically results in reduced stopband attenuation. The stopband is shown in greater detail in Figure 7.
or equivalently convolution of the polynomial coefﬁcients.Ast'. it is not absolutely necessary to use secondorder sections..47.Chapter 8 Implementing IIR Filters 8. For loworder designs. However.Ap.. Hc = design(Hf. The reason is that forming the transfer function involves polynomial multiplication.120).1. .1 Some basics of IIR implementation 8.a] = tf(Hc). Of course the effect gets worse as the ﬁlter order increases since we are performing more and more convolutions. This is mainly due to additions of large numbers with small numbers (that become negligible when using ﬁnite precision arithmetic). Example 65 As a rather extreme example consider the following design: Hf = fdesign. The full polynomials of the transfer function are never formed. Convolution can introduce signiﬁcant roundoff error even with doubleprecision ﬂoatingpoint arithmetic. but there still may be good reasons to do so from an implementation perspective. The main reason for this has to do with hardware implementations of IIR ﬁlters.1 The use of secondorder sections All of the IIR designs we have discussed in Chapter 2 are performed using secondorder sections by default.Fst.'cheby1').05.48. [b. even from the design perspective it is good practice to always keep the design in secondorder section and avoid computing the transfer function explicitly..lowpass('Fp.
The most common secondorder section structures are the directform I and directform II.4 0. However. we can share the delays from one section to the next.4.1).3).1: A Chebyshev type I ﬁlter implemented in secondorder sections and with the transfer function. The resulting ﬁlter order is very high (67). the ﬁlter has become unstable! The transfer function of the polynomials is completely wrong as evidenced by the pole/zero plot (Figure 8. so that the directform I structure would only require two more delays than the directform II rather than twice as many.7 0. The structure uses more delays than the directform II structure because the latter shares the delays between the numerator and denominator of each section while the former does not. 8.8 0.1.5 0. Compare to the pole/zero plot of the secondorder sections to see what it should look like (Figure 8.2 0. A twosection directform I ﬁlter is shown in Figure 8. Losada .2 Allpassbased implementations Secondorder sections have been used for many years to implement IIR ﬁlters. we have completely distorted the response of the ﬁlter (see Figure 8.6 0.178 Magnitude Response (dB) 0 −100 −200 −300 −400 −500 −600 −700 −800 −900 −1000 Implementing IIR Filters Second−order sections Transfer function Magnitude (dB) 0 0. However.3 0. By forming the transfer function using the tf command. Moreover.9 1 Normalized Frequency (×π rad/sample) Figure 8. if we do not use the scale value between sections.2).1 0. another possibility is to use allpassbased implementaDigital Filters with MATLAB Ricardo A.
Pole/Zero Plot 1 0.5 67 Real Part Figure 8.4 −0. These have the advantage that they require less multipliers than corresponding secondorder sections implementations.6 Filter #1: Zero Filter #1: Pole Imaginary Part 0.5 1 179 Filter #1: Zero Filter #1: Pole Imaginary Part 0.6 −0.5 1 1.1 Some basics of IIR implementation Pole/Zero Plot 2 1.8 −1 −1.5 −2 −4 −3 −2 −1 0 1 2 Real Part Figure 8.4 0.5 −1 −0. tions.5 −1 −1. The idea is to implement the ﬁlter H (z) as the sum of two allpass ﬁlters Digital Filters with MATLAB Ricardo A.8 0.2: Pole/zero plot of a Chebyshev type I ﬁlter implemented with the transfer function.2 0 −0.8.2 −0. Losada .5 0 0.3: Pole/zero plot of a Chebyshev type I ﬁlter implemented with secondorder sections.5 0 −0.
1) 2 This decomposition. the allpass ﬁlters are implemented using a minimal number of multipliers and adders. [16]. Digital Filters with MATLAB Ricardo A. 1 H (z) = ( A0 (z) + A1 (z)) (8. Losada A0 (z) and A1 (z). He2 = design(Hf. When using the directform II secondorder sections implementation we found that the number of multipliers required was 20. On a programmable DSP processor for instance.'cascadeallpass').'FilterStructure'. the allpass ﬁlters are implemented as cascades of loworder allpass sections. we use the realizemdl command to generate a Simulink model of the ﬁlter. [17]. we can ﬁnd through the cost function that the number of multipliers reduces to 12. The delays are shared between sections whenever possible in order to minimize the number of them required. It is know that Butterworth.'ellip'. To visualize the structure. known as parallel allpass or coupledallpass. and the number of delays is 15. Ultimately.4: Directform I secondorder sections structure. The number of adders increases to 23. the saving in multipliers usually more than compensates. The allpass ﬁlters themselves can be implemented in various ways. consider the elliptic design of Example 26. can be performed under certain conditions on H (z) [15]. In the Filter Design Toolbox. the number of adders was also 20 and the number of delays was 10. and elliptic ﬁlters satisfy such conditions and therefore can be implemented in such manner. Even though the number of adders is higher than with secondorder sections. If we use cascaded loworder allpass sections. In keeping with the good practices of not forming the full transfer function. an adder and a multiplier have the same cost. Lattice ﬁlters are one possibility. Example 66 To illustrate. this depends on the hardware used to implement the ﬁlter.180 Implementing IIR Filters Figure 8. Chebyshev. . This is not the case with an FPGA or an ASIC.
the number of adders increases to 34. % A0(z) [b2.2 Fixedpoint implementation 181 Example 67 For illustration purposes.5. He = design(Hf. He3 = design(Hf. a fact that may make their use compelling. the lattice wave digital ﬁlters are wellscaled for ﬁxedpoint implementations. The term lattice in this case refers to the fact that there are two parallel allpass branches A0 (z) and A1 (z).8.3. This implementation requires the same 12 multipliers as the cascade allpass does.a1] = tf(He.'cascadewdfallpass'). Lattice wave digital ﬁlters A variation of the cascaded allpass implementation is to use lattice wave digital ﬁlters. The number of states is only 11.stage(2)). Digital Filters with MATLAB Ricardo A.stage(1) contains the term A0 (z) + A1 (z) while He. If we look at the numerators b1 and b2. it is simply a matter of specifying the appropriate ﬁlter structure. the cascade allpass implementation seems to be superior.60).2 Fixedpoint implementation Implementing IIR ﬁlters with ﬁxedpoint arithmetic is more challenging than the FIR case.Ast'.stage(1).F3dB. We have already seen reasons not to use the transfer ∗ This is not needed for implementation purposes.'FilterStructure'.Ap. 8.'cascadeallpass').stage(1)). It does not refer to the lattice structure proposed by Gray and Markel [18]. we can easily get to the transfer function∗ of the allpass ﬁlters as follows: Hf = fdesign.a2] = tf(He.'ellip'. but the savings in number of states may not make up for the additional adders required.lowpass('N. However.'FilterStructure'. Losada . In terms of computational cost. This is an indication of their allpass characteristic.stage(1).stage(2) is simply the 1/2 factor. To use these structures for the elliptic design of Example 26. More about lattice wave digital ﬁlters can be found in [18] and [19] for example. [b1. we can see that they are reversed versions of a1 and a2 respectively.. However.'ellip'. % A1(z) Note that He.1.
a)). Note that in this case.45. Htf = dfilt. it is not enough to obtain a nice magnitude response with the quantized coefﬁcients.0. Unlike FIR ﬁlters. He = design(Hf. Htf.a). Losada . forming the doubleprecision ﬂoatingpoint transfer function does not signiﬁcantly alter the magnitude response (try fvtool(b. The case to avoid the transfer function becomes much stronger once ﬁxedpoint is taken into account. we want to stay away from the transfer function because quantizing large polynomials introduces signiﬁcant errors when compared to quantizing secondorder polynomials. Nevertheless.Arithmetic = 'fixed'. The following example showcases this. % Already in SOS form Let’s construct a directform II ﬁlter using the transfer function equivalent to the SOS we have: [b. He.2. it is not possible to implement IIR ﬁlters using fullprecision arithmetic since this would result in inﬁnite bit growth due to Digital Filters with MATLAB Ricardo A. with IIR ﬁlters.Arithmetic = 'fixed'.1 Fixedpoint ﬁltering In general. Any other roundoff error introduced by the ﬁxedpoint settings is not reﬂected in the magnitude response analysis shown in fvtool. The magnitude responses are shown in Figure 8. It is worth noting that the magnitude responses shown take into account only the quantization of coefﬁcients.a] = tf(He). Now let’s quantize the coefﬁcients using 16 bits and compare the resulting magnitude responses.'ellip').lowpass(0.df2(b.182 Implementing IIR Filters function of IIR ﬁlters even before thinking of ﬁxedpoint implementation. for ﬁxedpoint implementation. 8.80).5.5.5. The deviation that we observe for the transfer function in Figure 8.5 has to do with the quantization. Example 68 Consider the following design: Hf = fdesign.0.
7 0. we can use the double() command on the ﬁlter to obtain a ﬁlter that has quantized coefﬁcients. but performs all multiplications/additions using doubleprecision ﬂoatingpoint arithmetic.2 Fixedpoint implementation 183 Magnitude Response (dB) 0 −10 −20 −30 SOS filter TF filter Magnitude (dB) −40 −50 −60 −70 −80 −90 −100 0 0. In one case.8.2 0. In the worst case.5 0.1 0. This quantization will of course introduce roundoff error.4 0. the feedback. while the later uses the quantized coefﬁcients.8 0. Nevertheless.5: Comparison of magnitude response of the same ﬁlter quantized to 16bit coefﬁcients.6 0. This is the result of using the nonquantized original ﬁlter coefﬁcients and performing all multiplications/additions with inﬁnite precision (or at least doubleprecision ﬂoatingpoint arithmetic). what we ideally would want to compute. we can consider the following computations for the output: • yr [n]. the quantization produces an overﬂow condition. it is necessary to introduce quantization at the feedback points within a ﬁlter structure. in order to obtain a baseline. Losada . we use secondorder sections (SOS) while in the other case we use the transfer function (TF). the best we can hope to compute.3 0.9 Normalized Frequency (×π rad/sample) Figure 8. ∗ Digital Filters with MATLAB Ricardo A. Therefore. Since fullprecision is not an option with IIR ﬁlters. ∗ Note that the commands refﬁlter() and double() differ in that the former uses the original ﬂoatingpoint coefﬁcients. • yd [n]. as with FIR ﬁlters.
let’s enable min/max/overﬂow logging and ﬁlter the same data with the ﬁxedpoint ﬁlter: fipref('LoggingMode'.0. % Ideal output Hd = double(He). what we actually compute.Arithmetic = 'fixed'.lowpass(0. This is the result we get with all ﬁnal ﬁxedpoint settings in our ﬁlter. Hf = fdesign.16. He = design(Hf.'ellip'. For each section. we want to ensure that roundoff error at this point is minimized. Example 69 Let us repeat the previous design with a slight change.x). and compare to the best we can hope to compute. % This is the best we can hope for var(yryd) ans = 1. Hr = reffilter(He). rand('state'. The difference between the two is due solely to coefﬁcient quantization.15). By default.5).'on') ye = filter(He. Let us consider the directform II secondorder sections structure.0). However.5. yr = filter(Hr.'SOSScaleNorm'.''). x = fi(2*(rand(1000. Losada . % Don't scale He.true. let’s remove the scaling/reordering to show how a good magnitude response is necessary but not sufﬁcient in order to obtain satisfactory results.5734e08 Now. we scale and reorder the secondorder sections in order to help obtaining good ﬁxedpoint ﬁltering results from the start. yr [n].184 Implementing IIR Filters • y[n].0. yd = filter(Hd.. We’ll compute the ideal output. Since we need to quantize the result from the feedback loop prior to the values entering the states.x).45.x).1).5. for now. yd [n]. the feedback part comes before the shared states. qreport(He) Digital Filters with MATLAB Ricardo A.80).
'ellip'.'ellip'.s). Therefore we can compare the output to our baseline in order to evaluate performance. HLinf. HLinf = design(Hf. we can use scaling to control the signal growth at critical points inside the ﬁlter. 'SOSScaleOpts'. but using ℓ1 norm scaling this time.8339e04 When doing ﬁxedpoint ﬁltering.. For now. In order to avoid overﬂow. will ensure that no overﬂow can occur..Arithmetic = 'fixed'. but reduces the signal levels too much. this scaling may result in overﬂow as the next example shows. adversely affecting the SNR.sosReorder = 'none'.'l1'. ℓ1 norm scaling..8. Now let’s ﬁlter with this scaled structure.'SOSScaleNorm'. it is not worth comparing ye to yd. However.2 Fixedpoint implementation 185 If we look at the results from qreport. Hl1 = design(Hf.sosscaling. The ℓ1 norm scaling we have used is good for avoiding overﬂows.. var(yddouble(yl1)) ans = 1. Hl1.x). we can see that the states have overﬂown 37 out of 10000 times.'SOSScaleNorm'. Digital Filters with MATLAB Ricardo A.s).. The most stringent scaling. For now. A more commonly used scaling (the default) is to use L∞ norm scaling. Because of the overﬂow. yl1 = filter(Hl1. 'SOSScaleOpts'. one needs to compromise between maximizing the SNR and minimizing the possibility of overﬂows.. qreport(Hl1) Notice from the report that we have no overﬂows. Example 71 Let’s design the ﬁlter and scale using L∞ norm scaling.'Linf'. we will disable reordering of the secondorder sections: s = fdopts. s.Arithmetic = 'fixed'. we still do not reorder the sections. Losada . Example 70 Let us design the elliptic ﬁlter again.
Once again.'ellip'.sosReorder = 'auto'.'SOSScaleNorm'.sosscaling. HLinf. yLinf = filter(HLinf. it is preferable to allow for the occasional overﬂow in order to increase the SNR overall. 'SOSScaleOpts'. and.'Linf'.186 Now let’s ﬁlter and look at the report.. s. and look at the report.. it is meaningful to compare the output to our baseline to evaluate performance. sometimes even help avoid overﬂow. we have not reordered the secondorder sections in the examples we have explored. ∗ This norm can be shown to be the same as ℓ2 norm. yLinf = filter(HLinf.s). s = fdopts.4809e05 As we can see. Digital Filters with MATLAB Ricardo A.Arithmetic = 'fixed'. HLinf = design(Hf. qreport(HLinf) Implementing IIR Filters The report shows that 8 overﬂows in the states have occurred. var(yddouble(yLinf)) ans = 1.x).. the result is more than an order of magnitude better than what we got with ℓ1 norm scaling. So far. Yet a less stringent scaling is to use L2 norm scaling.x). It is worth noting that in some applications. This is Parseval’s theorem. let’s ﬁlter the same data. qreport(HLinf) Since we did not overﬂow. Example 72 Let’s once again use L∞ norm scaling. Reordering can help improve the SNR. but this time use automatic reordering of the sections. The assumption is that an overﬂow once in a while is not critical for the overall performance of the system.∗ Yet the chances of overﬂowing when using that type of scaling are even larger. as the next example shows. Losada .
Hs = autoscale(He. var(yddouble(ys)) ans = 1. and autoscaling. We can use the autoscale command in order to optimize the ﬁxedpoint fractional length settings in a ﬁlter based on speciﬁc input data that is given. Hf = fdesign. However.x).'SOSScaleNorm'. We know that this ﬁlter will overﬂow with the input data we have. and we ﬁlter the same data. Losada .x).2 Fixedpoint implementation 187 8.3167e08 Digital Filters with MATLAB Ricardo A.5. Doing so.2.'ellip'. ys = filter(Hs. He = design(Hf.8.45. if we combine L∞ norm scaling. we can get even better results than if we use dataagnostic scaling. We now evaluate the output relative to our baseline.Arithmetic = 'fixed'. Finally.lowpass(0. we can easily verify that we can get even better results: var(yddouble(ys2)) ans = 2. if we use this input data to autoscale. qreport(Hs) we can see from the report that now overﬂow has been avoided. As a result sometimes overﬂow occurs.2 Autoscaling The scaling we have seen so far is data agnostic.'').5.80).0. automatic reordering.4144e07 Which is of course the best result we have obtained so far.0. % Don't scale He. Example 73 Let’s try once again to design the ﬁlter without dataagnostic scaling.
∗ Digital Filters with MATLAB Ricardo A.5 0. As an example. L Re−ordered L ∞ 1 ∞ Non−reordered l Magnitude (dB) 0 0. In all four cases shown. Losada .188 Implementing IIR Filters Magnitude Response Estimate 0 −10 −20 −30 −40 −50 −60 −70 −80 −90 −100 Best we can hope for Autoscaled.1 0.3 Evaluating ﬁlter performance using the magnitude response estimate As we saw for FIR ﬁlters.2. Figure 8. But a linear model that approximates the behavior as additive white noise is adequate in many cases as we have seen.6 shows the magnitude response estimate for four cases corresponding to examples above.9 1 Normalized Frequency (×π rad/sample) Figure 8. overﬂow is avoided. re−ordered.∗ This means that it is most useful when no overﬂow occurs given that overﬂows introduce signiﬁcant nonlinear behavior. unlike the FIR case.2 0.6 0. 8. Moreover.8 0.7 0. Because the ﬁltering is performed with ﬁxedpoint arithmetic. one way to evaluate the performance of the ﬁxedpoint IIR ﬁlter is to compute an estimate of the magnitude response by ﬁltering data. the roundoff error in the ﬁltering has a net effect of reducing the stopband attenuation.4 0. the magnitude response estimate takes into account not only the quantization of the coefﬁcients.3 0. Quantization is a nonlinear operation. Once again.6: Magnitude response estimates for various scaling cases. but also any roundoff error introduced within the ﬁlter. The magnitude response estimate is particularly useful when the ﬁxedpoint ﬁlter behaves in a weekly nonlinear manner.
45 Normalized Frequency (×π rad/sample) Figure 8.35 0. Losada . The passband details are shown in Figure 8.15 0.7: Passband details of magnitude response estimates for various scaling cases. re−ordered. Digital Filters with MATLAB Ricardo A.5 −2 0 0.5 0 −0. the roundoff can also affect the passband response of the ﬁlter.3 0.2 Fixedpoint implementation 189 Magnitude Response Estimate 2 1. L Re−ordered L ∞ 1 ∞ 1 Non−reordered l Magnitude (dB) 0.5 Best we can hope for Autoscaled.5 −1 −1.1 0.7.4 0.2 0.8.05 0.25 0.
Part III Appendices .
3.1 Filter Design (fdesign) A.. f = fdesign.Fc.1.Ast'.Ap. etc) type: help fdesign/responses To change speciﬁcation set.0.5. To view all available frequency response designs (lowpass. setspecs(f.75).Ast'.FilterOrder = 60. f.lowpass('Fp. only set the specs.60. .Fc.0.Appendix A Summary of relevant ﬁlter design commands A.0. f.Ast'.0.5. highpass.75).Fst.Ap. . it can be done a step at a time.'N..3. In order to design you need to invoke the design command (see below).Specification = 'N.0.Ap. but it can also be done in one shot.1 Setup design speciﬁcations Use fdesign objects to store design speciﬁcations. This will not design the ﬁlter.4.
5.'N. In order to specify frequencies in Hertz.'fir') = design(f. set(f.30. so for example a value of 0.'fir') % List only FIR designs To design with default design options h % h h h = design(f) % Use For the following = design(f.'Specification') A.'equiripple') For contextsensitive (response sensitive) help type: help(f.'iir') default design method commands. Fs = 200 Hz For a list of all available speciﬁcation sets for a particular response.60.2 Design options To view available design methods for a particular response/speciﬁcation combination: designmethods(f) % List all design methods designmethods(f.3π radians/sample. the sampling frequency must be appended.200).192 Summary of relevant ﬁlter design commands By default.1.Ap.Fc.Ast'. setspecs(f.3 for Fc means that the cutoff frequency is being set to 0.'all') = design(f. Losada . % Fc = 30 Hz. h will be an array % Design for all design methods % Design for all FIR methods % Design for all IIR methods To view design options and defaults for a particular design method: designoptions(f.'iir') % List only IIR designs designmethods(f.'equiripple') % Specific help for lowpass/equiripple combo Digital Filters with MATLAB Ricardo A.0. frequency speciﬁcations are assumed to be normalized with an implied scaling by π.75.
A.2 Selecting ﬁlter structure
193
A.1.3 Design analysis/validation
To view various frequencydomain, timedomain, or polezero responses: f = fdesign.lowpass('Fp,Fst,Ap,Ast',1.3e3,1.4e3,0.5,75); h = design(f,'equiripple','StopbandShape','1/f','StopbandDecay',3); fvtool(h) In order to measure critical frequencies and/or ripple/attenuations: measure(h) To view a highlevel implementation cost: f = fdesign.halfband('TW,Ast',0.01,80); h = design(f,'equiripple'); cost(h) ans = Number of Multipliers : 463 % Number of nonzero and nonone coefficients Number of Adders : 462 % Total number of additions Number of States : 922 % Total number of states MultPerInputSample : 463 % Nonzero/nonone multiplications per input sample AddPerInputSample : 462 % Additions per input sample For some general information about the design: info(h)
A.2 Selecting ﬁlter structure
At design time, different ﬁlter structures can be speciﬁed. For FIR ﬁlters, the default structure is directform, dffir. For symmetric ﬁlters (linear phase), half the multipliers can be saved by using a symmetric FIR structure: f = fdesign.lowpass('N,Fp,Fst',40,0.4,0.5); h1 = design(f,'Wpass',1,'Wstop',10,'FilterStructure','dffir'); % default h2 = design(f,'Wpass',1,'Wstop',10,'FilterStructure','dfsymfir'); cost(h1) cost(h2) Digital Filters with MATLAB Ricardo A. Losada
194
Summary of relevant ﬁlter design commands
For IIR ﬁlters, the default structure is directform II. IIR ﬁlters are designed by default as cascaded secondorder sections (SOS). Directform I SOS structures use more states, but may be advantageous for ﬁxedpoint implementations, f = fdesign.lowpass('N,F3dB,Ap,Ast',5,0.45,1,60); h1 = design(f,'FilterStructure','df1sos'); h2 = design(f,'FilterStructure','df2sos'); cost(h1) cost(h2)
A.3
Scaling IIR SOS structures
By default, sos IIR designs using structures such as df1sos and df2sos are scaled. The scaling uses L∞ norm scaling, so that the cumulative magnitude response of the secondorder sections (ﬁrst section alone, ﬁrst and second sections, ﬁrstsecondandthird, etc.) does not exceed one (0 dB): f = fdesign.lowpass; h1 = design(f,'ellip','FilterStructure','df1sos'); h2 = design(f,'ellip','FilterStructure','df2sos'); s = dspopts.sosview; s.view='Cumulative'; % Set view to cumulative sections fvtool(h1,'SOSViewSettings',s) s.secondaryScaling = true; % Use secondary scaling point for df2sos fvtool(h2,'SOSViewSettings',s) This scaling helps avoid overﬂows when the ﬁlter is implemented with ﬁxedpoint arithmetic, but doesn’t totally eliminate the possibility of them. To eliminate overﬂows, the more restrictive l1 norm scaling can be used (at the expense of reduced SNR due to subutilization of the dynamic range): f = fdesign.lowpass; h1 = design(f,'ellip','FilterStructure','df1sos','SOSScaleNorm','l1'); s = dspopts.sosview; s.view = 'Cumulative'; fvtool(h1,'SOSViewSettings',s) Digital Filters with MATLAB Ricardo A. Losada
A.4 Designing multirate ﬁlters
195
A.4 Designing multirate ﬁlters
To design multirate ﬁlters, select the multirate type, then the interpolation/decimation factor(s), then any fdesign singlerate response, f = fdesign.interpolator(4,'lowpass','N,Fc,Ap,Ast',60,1/4,0.5,75); % Interp by 4 f = fdesign.decimator(2,'halfband','TW,Ast',0.1,95); % Decim by 2 f = fdesign.rsrc(3,5,'nyquist',5,'TW,Ast',0.05,80); % Up=3 Down=5 After the speciﬁcations are set, the usual commands are available: design, designmethods, designoptions, etc. The cost command takes into account the polyphase savings of multirate ﬁlters: f1 = fdesign.interpolator(15,'lowpass','Fp,Fst,Ap,Ast',... 1/150.01,1/15+0.01,1,80); h1 = design(f1,'multistage'); % Results in 2 stages cost(h1) % Compare to a singlestage design: design(f1,'equiripple'); f2 = fdesign.decimator(8,'nyquist',8,'TW,Ast',0.03,80); h2 = design(f2,'multistage'); % Result in 3 stages cost(h2) % Compare to a singlestage design: design(f1,'kaiserwin'); % When applicable, the use of IIR halfbands results in huge implementation savings % The implementation uses allpassbased polyphase branches h3 = design(f2,'multistage','HalfbandDesignMethod','iirlinphase'); cost(h3) % If linear phase is not an issue, ellip halfbands would be even better
A.5 Converting to ﬁxed point
In order to convert a design to ﬁxed point, set the Arithmetic property, h.Arithmetic = 'fixed'; or set(h,'Arithmetic','fixed'); By default, the coefﬁcients are quantized to 16 bits with automatic scaling, and, for FIR ﬁlters, the ﬁlter internals (additions and multiplications) are set in a such way that no loss of precision occurs (socalled “full precision”). The input signal to the ﬁlter is assumed to be a signal quantized Digital Filters with MATLAB Ricardo A. Losada
196
Summary of relevant ﬁlter design commands
with 16 bits and covering the range [−1, 1). The LSB is scaled by 2−15 . (Two’scomplement is assumed for all ﬁxedpoint quantities.) Coefﬁcient quantization affects the frequency (and time) response of the ﬁlter. This is reﬂected in fvtool and measure, f = fdesign.decimator(2,'Halfband','TW,Ast',0.01,80); h = design(f,'equiripple'); fvtool(h) measure(h) % Compare to h.Arithmetic = 'fixed'; fvtool(h) measure(h) For FIR ﬁlters, in order to change ﬁxedpoint settings for the output and/or additions/multiplications within the ﬁlter, change the ﬁlter internals ﬁrst∗ , h.FilterInternals = 'SpecifyPrecision' For example to view the effect solely due to the use of a smaller number of bits for the output of a ﬁlter, one could write something like, x = randn(1000,1); % Create a random input xn = x/norm(x,inf); % Normalize to the range [1,1] xq = fi(xn,true,16,15); % Quantize to 16 bits. Cover the range [1,1) f = fdesign.decimator(2,'Halfband','TW,Ast',0.01,80); h = design(f,'equiripple','StopbandShape','linear','StopbandDecay',40); h.Arithmetic = 'fixed'; yfull = filter(h,xq); % Full precision output (33 bits) h.FilterInternals = 'SpecifyPrecision'; h.OutputWordLength = 16; h.OutputFracLength = 13; y16 = filter(h,xq); % 16bit output plot(double(yfully16)) % Plot the difference due to output quantization
The LSB scaling for any ﬁxedpoint quantity can be changed by setting the appropriate “FracLength” parameter. Note that this quantity is not really a “length” since it can be greater than the word length or even negative. For example a word length of 4 bits and a “FracLength” of 8 means the bits (from MSB to LSB) are scaled by −2−5 , 2−6 , 2−7 , and 2−8 respectively. (The negative scaling of the MSB is due to the two’scomplement representation.)
∗
Digital Filters with MATLAB
Ricardo A. Losada
hd. f = fdesign. block(h) f = fdesign. Same as yfull plot(double([yryd. has the original “ideal” doubleprecision coefﬁcients.'TW.A.0. % Cast filter arithmetic to double. and reffilter.'halfband'. ∗ Digital Filters with MATLAB Ricardo A.Arithmetic = 'fixed'.'cascadeallpass').01.yry16])) A.1). and with what we can actually compute. Continuing with the previous two examples: yr = filter(hr.75). while the castedtodouble ﬁlter. % Best we can hope to compute.TW'.Ast'.decimator(2. Losada .'FilterStructure'. These functions can be used to compare what we ideally would like to compute. % Get reference doubleprecision floatingpoint filter The difference between hd and hr lies in the ﬁlter coefﬁcients.decimator(2. hd = double(h).0. h = design(f. the best one can hope to compute should be determined with fullprecision ﬁxedpoint ﬁltering rather than casting to doubleprecision ﬂoating point. realizemdl(h) The difference between them is that block will use the Digital Filter block (or one of the multirate blocks) from the Signal Processing Blockset while For FIR ﬁlters with multiplications/accumulations computed with more than 53 bits. % What we would ideally like to compute yd = filter(hd.'equiripple'). h = design(f. h = design(f). The reference ﬁlter.122.0.hilbert('N.xq). has a casted version of the quantized coefﬁcients.xq).05.'TW.'iirlinphase'. with the best we can hope to compute∗ .'Halfband'.80).6 Generating Simulink blocks 197 There are a couple of commands that can come in handy for analysis when converting ﬁlters from ﬂoating point to ﬁxed point: double. hr.6 Generating Simulink blocks There are two commands that can be used to generate blocks from ﬂoatingpoint or ﬁxedpoint ﬁlters: block() and realizemdl(): f = fdesign.Ast'. Use quantized coeffs hr = reffilter(h). h.
you should ﬁrst select the response (lowpass. However. Digital Filters with MATLAB Ricardo A.198 Summary of relevant ﬁlter design commands realizemdl will build the ﬁlter from scratch using basic elements like adders/multipliers.7 Graphical User Interface Most of the commands discussed here are available through a GUI: filterbuilder Note that to design multirate ﬁlters. Once designed (and possibly quantized). the ﬁlter can be saved to the workspace as an object named with the variable name speciﬁed at the top. halfband. The use of the block command will generally result in faster simulation speeds and better code generation. etc) and then set the Filter Type to decimator. A. Losada . etc (if available). realizemdl provides support for more ﬁlter structures and will permit customization of the resulting block diagram (say to reduce the number of bits of some of the multipliers of a ﬁlter or to rewire the ﬁlter in some way).
and Analog Reconstruction This appendix provides a short review of both theoretical and practical issues related to sampling of a signal and reconstruction of an analog signal from a sampled version of it. but there are a couple of practical issues that are often overlooked and that we wish to highlight. Moreover. it is wellknown that in order to avoid aliasing when sampling it is necessary to sample at least twice as often as the highest frequency component present. This is done to accommodate for the transition bands in the various ﬁlters involved. Similarly. Upsampling. analog reconstruction is just the edge case of increasing the sampling rate of a signal. sampling an analog signal is just the extreme case of downsampling a digital signal thereby reducing its sampling rate. What is somewhat less wellknown is that in lieu of ideal brickwall antialiasing and reconstructing lowpass ﬁlters. In fact. we should always sample a bit higher than twice the maximum frequency component. if we oversample by a factor of say two or four ∗ In particular the textbooks [3] and [11] are recommended in addition to the article [35]. First. understanding sampling and analog reconstruction is essential in order to understand multirate systems. The material presented here is standard in many textbooks∗ . Downsampling. In general. As a rule of thumb. anywhere between 10 and 20 percent higher. . as we will see.Appendix B Sampling.
Other sampling rates used for audio are 88. but the important thing is that they still include an extra 10 to 20 percent cushion in addition to the 2x or 4x oversampling. These would also be the maximum frequency components of the audio signal that is bandlimited with such antialias ﬁlter. The frequency range of interest is 0 to 20 kHz. The second issue we wish to highlight is that when choosing the stopband edge frequency for a decimation ﬁlter we can in many cases allow for transitionband overlap (i. Downsampling.05 kHz or 20 kHz to 24 kHz depending on the sampling frequency. and 192 kHz.1 kHz or 28 kHz respectively. Moreover. Equivalently. this allows for the transition width of the antialiasing ﬁlter to be twice as large (resulting a simpler. This enables us to sample at a rate that. and Analog Reconstruction to ease the burden of the analog antialiasing ﬁlter.200Sampling.4 kHz. 20 kHz to 22. does not need to be as large as twice the stopbandedge of the antialiasing ﬁlter. These sampling rates correspond to 2x or 4x oversampling. we allow for aliasing to occur in this band. Typical sampling rates for audio are 44.e. Losada . 96 kHz. meaning that we have an excess bandwidth of about 10 to 20 percent. we would use a perfect lowpass analog ﬁlter with a cutoff frequency of 20 kHz that removes all spectral replicas introduced by sampling. lowerorder ﬁlter) than what it would be if did not permit aliasing in the excess frequency bands.1 kHz or 48 kHz. Ideally we would bandlimit the analog signal exactly to 20 kHz prior to sampling with an antialias analog ﬁlter. In reality. we still leave an extra 1020 percent of room even though at this point we would be sampling anywhere between 4 and 8 times higher than the highest frequency component. We would then sample at 40 kHz. aliasing occurs. The stopbandedge of the antialiasing ﬁlter will be at about 24. However. Upsampling. while larger than twice the frequency of interest. in order to reconstruct the analog signal from the samples. since we know that the information in the excess frequency bands is of no interest for our application. aliasing in the transition band). Subsequently. Since we don’t quite sample at twice the maximum frequency components. As an example consider an audio signal. 176. we bandlimit the signal with an analog antialiasing ﬁlter whose passband extends to 20 kHz but whose stopband goes beyond 20 kHz by about 20 to 40 percent.2 kHz. aliasing will only occur in the excess frequency band. This issue is related to the excess bandwidth resulting from the 10 to 20 percent oversampling that we have just mentioned and it is the reason the extra 10 to Digital Filters with MATLAB Ricardo A.
Losada . very efﬁcient halfband ﬁlters can be used when decimating by a factor of two.g. In particular. 1 ∞ Xs ( f ) = ∑ Xa ( f − k f s ) T k=−∞ (B.1 Sampling an analog signal 201 20 percent is still present even if there is an oversampling of 2x or 4x. Consider an analog signal x a (t) with Fourier transform Xa ( f ) also called its spectrum or frequency response.1) where f s = 1/T is the sampling frequency. ∞ Xa ( f ) = −∞ x a (t)e−2πj f dt. ∞ Xs ( f ) = Digital Filters with MATLAB −∞ xs (t)e−2πj f dt.1 Sampling an analog signal We will provide only a brief overview of sampling. For a complete treatment of the subject see [35]. its spectrum is still given by the continuoustime Fourier transform. B.5. Ricardo A. Allowing for transitionband overlap (aliasing in the excess frequency bands) when decimating means that the cutoff frequency (not the stopbandedge frequency) for the decimation ﬁlter can be selected as π/M where M is the decimation factor. Note that the sampled signal xs (t) is still an analog signal in the sense that it is a function of the continuoustime variable t. If we construct a sampled signal xs (t) from the original signal x a (t) in the following way: ∞ xs (t) = ∑ n=−∞ x a (nT )δ(t − nT ) The spectrum of the sampled signal. Therefore. [3]). We will elaborate on all this in §B.B. Xs ( f ) is related to the spectrum of the original signal by the Poisson summation formula. This in turn means that efﬁcient Nyquist ﬁlters can be used for decimation. Sampling is also covered in any signal processing textbook (see e.
They are centered around multiples of f s . and Analog Reconstruction However. The terms Xa ( f − k f s ) are shifted versions of the spectrum of x a (t). f > fs 2 (B. In general. we can determine the continuoustime Fourier transform of xs (t) by computing the discretetime Fourier transform of x [ n ]. Digital Filters with MATLAB Ricardo A. (B. the further apart the spectral replicas will lie. if we form the discretetime sequence x [n] = { x a (nT )} ∀n. (B. This concept is key to understanding multirate signal processing so we’d like to emphasize it. So even though xs (t) and x [n] are conceptually different. However. (B.1). The higher the sampling frequency. they have the same frequency response. Any sampled signal has spectral replicas centered around multiples of its sampling frequency. the replicas will invariably overlap. if x a (t) is bandlimited. then by spreading the replicas enough apart from each other. if the signal is bandlimited in such a way that only one replica has a nonzero value for any given frequency. This interference is called aliasing.202Sampling. choosing a large enough value for f s . Losada . Downsampling. ∞ Xs ( f ) = X ( f ) = ∑ n=−∞ x [n]e−2πj f nT . i. Upsampling. and are called spectral replicas. we form a sequence by recording the value of the analog signal x a (t) at each multiple of T.1) is valid for any signal x a (t) whether bandlimited or not [3]. then the replicas will not overlap and they will not interfere with each other when we add them as in Eq. However. that is. its spectrum is equal to zero for all frequencies above a certain threshold and all frequencies below a certain threshold. Obviously if Xa ( f ) = 0 ∀ f .2) then the replicas will not overlap.e. Eq. Aliasing will thus be avoided if the sampling frequency is at least equal to the twosided bandwidth. It is easy to see that if the analog signal’s spectrum satisﬁes Xa ( f ) = 0.1). the replicas will interfere with each other due to frequency overlapping. when we form the sum of all the spectral replicas as in Eq.e. the replicas will not overlap thereby avoiding aliasing. i.
is simply Bx = f max − f min = 2 f max = f s .1 shows the magnitude spectrum of an example of an analog signal that satisﬁes Eq.B. one in which the sampling frequency is exactly equal to the twosided bandwidth is shown in Figure B. If the analog signal is not bandlimited. the sampled spectrum would be something like what is depicted in Figure B. Figure B. Losada .e. Digital Filters with MATLAB Ricardo A. Such ﬁlter is called an antialias ﬁlter for obvious reasons and its cutoff frequency must be chosen such that it allows all frequencies we are interested in for a given application to pass.e. The spectral replicas are adjacent to each other but do not overlap.3. A critically sampled spectrum. If we were to oversample the signal. Notice the “whitespace” between replicas due to oversampling. i.1: Spectrum of bandlimited analog signal with maximum frequency given by f s /2. we must make it so by lowpass ﬁltering the signal with an analog ﬁlter prior to sampling. The twosided bandwidth.2).2. Figure B. (B. This case corresponds to the best known case. Bx . that is if we choose f s′ > Bx . i.2: Spectrum of sampled signal with maximum frequency given by f s /2.1 Sampling an analog signal 203 Figure B. f max = f s /2 and f min = − f s /2.
e. Figure B. in general. Upsampling. when comparing two Nyquist intervals of different size. Losada . any digital processing performed on a signal on a larger Nyquist interval requires more computation than comparable signal processing performed on a signal that occupies a smaller Nyquist interval.4: Continuoustime signal with bandpass spectrum. Therefore. The interval [− f s /2.204Sampling. However. Downsampling.3: Spectrum of an oversampled signal. The spectral replicas that appear in a sampled signal make the signal periodic in the frequency domain. f s /2] is called the Nyquist interval. and Analog Reconstruction Figure B. avoid whitespace in the spectrum). This means that we generally want to avoid oversampling (i. This periodicity means that any operation performed on a signal within the Nyquist interval will automatically happen in all spectral replicas as well. We can take advantage of this fact to efﬁciently process analog bandpass signal as is explained next. Digital Filters with MATLAB Ricardo A. Since f s determines the number of samples per second. it is useful not only to realize that one encompasses a larger range of frequencies than the other. oversampling can be useful in some particular cases. but also that it involves a larger amount of samples.
The whitespace between replicas tells us that the signal has been oversampled.B. This will happen for any f s such that f s = 2k ( f c2 − f c1). We have assumed that f c1 = f c2 − f c1 so that when we sample at f s = 2 f c1 . Notice that by sampling at f s = 2 f c1 instead of at f s = 2 f c2 we have effectively moved the bandpass spectrum to baseband.5: Spectrum of sampled bandpass signal with f s = 2 f c2 . If we were to sample at f s = f max − f min = 2 f c2 the resulting signal would have the spectrum shown in Figure B. Because of the periodicity of the spectrum.1.1 Bandpass sampling Now consider the sampling of the bandpass signal depicted in Figure B. Digital Filters with MATLAB Ricardo A. all spectral replicas align nicely without overlapping. B. where k is some positive integer. Notice that we have made some assumptions in order for bandpass sampling to work.5. f c2 ]. for this signal we can sample at a much lower rate as depicted in Figure B. The Nyquist interval being smaller. Nevertheless. Losada . In fact. f c1 ] rather than [− f c2 . the processing we performed at baseband is replicated in the bandpass replicas.1 Sampling an analog signal 205 Figure B. means that if we want to modify the signal in some way through signal processing algorithms it will require less computation to do so than if we had sampled at f s = 2 f c2 . [− f c1 .6 and still avoid aliasing.4. aliasing may occur if we choose some other sampling frequency even if it is larger than the minimal f s that can be chosen to avoid aliasing.
We will see that just as sampling an analog signal results in spectral replication. Just as with sampling. and Analog Reconstruction Figure B. once again just as with sampling. being replicated as well. X ( f ). xd [n] = x [ Mn].2 Sampling a discretetime signal: downsampling We have seen that sampling an analog signal results in spectral replicas and possible aliasing if the sampling frequency is not large enough. However. i. More precisely. we form the sequence xd [n] by keeping one out of every M samples of x [n]. where M is a positive integer. given a sequence x [n]. the spectral replicas do not overlap and no aliasing occurs.e. the spectral replicas that form the spectrum of a downsampled signal will overlap in general and generate aliasing when added together. The fact that aliasing may occur when downsampling should be obvious.6: Spectrum of sampled bandpass signal with f s = 2 f c1 . B.206Sampling. if the twosided bandwidth is less or equal to the downsampled rate (within a Nyquist interval). throwing out M − 1 out of every M samples is equivalent Digital Filters with MATLAB Ricardo A. We now move on to explore what happens when we sample a signal that is already sampled. The replicas of X ( f ) are centered at multiples of the sampling frequency of the downsampled signal. a discretetime signal. Losada . we downsample the sequence by a factor of M. In other words. sampling a discretetime signal x [n] results in its spectrum. if x [n] was sampled at a frequency just high enough to avoid aliasing. Upsampling. After all. Downsampling.
B.2 Sampling a discretetime signal: downsampling
207
Figure B.7: Critically sampled signal.
Figure B.8: Three times oversampled signal.
to having sampled the analog signal at a frequency M times lower than what is required to avoid aliasing. On the other hand, if x [n] has been oversampled by at least a factor of M, then no aliasing should occur when downsampling. In order to derive the relation between the spectra, consider two sampled versions of x a (t). In one case, we sample with a sampling frequency f s = 1/T, xd [n] = { x a (nT )}, while in the other case we sample with a sampling frequency f s′ = M f s = 1/T ′ = M/T, x [n] = { x a (nT ′ )}. For illustration purposes, assume (without loss of generality) that f s corresponds to the critically sampled case so that all spectral replicas are adjacent to each other. The signal x [n] is oversampled by a factor M. As an example assume M = 3. The spectrum of xd [n], Xd ( f ), would be something like that shown in Figure B.7. The spectrum of x [n], X ( f ), has the same baseband replica, but the remaining replicas are centered around multiples of f s′ as shown in Figure B.8. In order to construct Xd ( f ) from X ( f ), we add X ( f ) with two shifted versions of it, X ( f − f s ) and X ( f − 2 f s ). The resulting spectrum is shown in Figure B.9. Of course we can also show this formally for any value of M through Digital Filters with MATLAB Ricardo A. Losada
208Sampling, Downsampling, Upsampling, and Analog Reconstruction
Figure B.9: Spectrum resulting from downsampling an oversampled signal.
the use of the Poisson summation formula. We know that Xd ( f ) = and X( f ) = 1 ∞ ∑ Xa ( f − k f s ) T k=−∞ 1 ∞ ∑ Xa ( f − k f s′ ) T ′ k=−∞
after some algebraic manipulation, we can arrive at the discrete version of the Poisson summation formula, Xd ( f ) = 1 M −1 ∑ X ( f − k f s ). M k =0 (B.3)
Note the scaling factor 1/M. When we downsample a signal, the baseband replica retains the same shape (hence the same information) as long as no aliasing occurs. However, all replicas are scaled down by the downsampling factor.
B.2.1 Filtering to avoid aliasing when downsampling
If the bandwidth of the signal x [n] is larger than 1/M times the Nyquist interval, aliasing will occur if such signal is downsampled by a factor of M. In order to avoid aliasing, a standard result in multirate signal processing is to pass the signal x [n] through a lowpass ﬁlter prior to downsampling. The role of this ﬁlter is akin to that of the analog antialias ﬁlter used to bandlimit an analog signal prior to sampling. The cutoff frequency for the ﬁlter should be π/M. Digital Filters with MATLAB Ricardo A. Losada
B.3 Increasing the sampling rate of a signal
209
While this result is correct, reversing the thinking on this is perhaps more useful and sometimes overlooked. By ﬁltering a signal in a way that its bandwidth is reduced we are basically acknowledging that we no longer are interested in part of its bandwidth (more precisely in the information contained therein). Therefore, if we reduce the bandwidth of a signal by a factor of M, we should reduce its sampling rate accordingly in order to reduce the size of the Nyquist interval. The point is we want to eliminate whitespace in the spectrum since we know that whitespace is akin to an oversampled signal and the larger Nyquist interval that goes with an oversampled signal implies extra (unnecessary) computation. The distinction is subtle but important. We are used to thinking: “I need to downsample therefore I should ﬁlter ﬁrst”. That’s ﬁne, but we should also think: “I have reduced the bandwidth of a signal therefore I should downsample”. In fact, as we will see in Chapter 4, we should do this even if the factor by which we reduce the bandwidth is not an integer.
B.2.2 Downsampling bandpass signals
Just as with sampling, under certain conditions it is possible to downsample a bandpass signal and avoid aliasing. If the signal is not bandpass already, we can ﬁlter it with a bandpass ﬁlter that reduces the bandwidth to 1/M times the Nyquist interval and then downsample it as long as the passband of the resulting signal lies in one of the intervals kπ/M < ω  < (k + 1)π/M k = 0, 1, . . . , M − 1.
The downsampling will cause the bandpass spectrum to be moved to baseband. This is a useful technique that allows a spectrum to be translated in frequency without the need for any multiplications. Without downsampling, it would be necessary to multiply the bandpass signal by a sinusoid if we wanted to translate its spectrum to baseband.
B.3 Increasing the sampling rate of a signal
We have seen that sampling the same analog signal at two different rates produces the same baseband spectrum plus replicas centered around multiples of the sampling frequency. Figure B.7 shows the spectrum of a critDigital Filters with MATLAB Ricardo A. Losada
210Sampling, Downsampling, Upsampling, and Analog Reconstruction ically sampled signal, while Figure B.8 shows the spectrum of the same signal oversampled. In those ﬁgures, the oversampling factor is 3, but the general principle applies to any integer oversampling factor L. The question is how to increase the sampling rate of a signal without converting the signal back to the analog domain and resampling at a higher rate. Increasing the sampling rate is just a digital lowpass ﬁltering problem. The ﬁlter must keep the baseband spectrum and all replicas of Figure B.8, but remove all remaining replicas, i.e. for the case of 3x oversampling, remove all replicas in Figure B.7 that are not in Figure B.8. In order to do so, the lowpass digital ﬁlter needs to operate at the high sampling rate so that it has replicas of its own centered around multiples of the high sampling rate that will preserve the sampled replicas at such frequencies. It is wellknow that the cutoff frequency for the lowpass ﬁlter should be π/L. However, rather than memorizing that formula it is helpful to realize that the cutoff frequency must be selected in such a way that no information is lost. This should be obvious since we are trying to reconstruct samples from the analog signal based on the samples we have. Therefore, the baseband spectrum must be left untouched. The lowpass ﬁlter must remove the L − 1 adjacent replicas. The (ideal) lowpass ﬁlter speciﬁcations used to increase the sampling rate by a factor L are thus, L 0 if  f  ≤ f s /2, if f s /2 <  f  ≤ L f s /2.
H( f ) =
(B.4)
where f s is the sampling rate before we increase the rate and L f s is the sampling rate that results after increasing the rate. The gain of L in the passband of the ﬁlter is necessary since as we saw the spectrum of the lowrate signal has a gain that is L times smaller than that of the highrate signal. The frequency response of the ﬁlter used to increase the sampling rate by a factor L = 5 is shown in Figure B.10. The ﬁlter removes L − 1 spectral replicas between the replicas centered around multiples of the high sampling rate L f s . Digital Filters with MATLAB Ricardo A. Losada
Since 1 ∞ X ( f ) = Xs ( f ) = ∑ X a ( f − k f s ).B. Losada . Digital Filters with MATLAB Ricardo A.11. and obtain Xa ( f ). T k=−∞ In the most common case. Just as with increasing the sampling rate of a signal. we would want to retain a replica for k = 0 instead. we need a lowpass ﬁlter.4 Reconstructing an analog signal 211 Figure B. the spectrum of the sampled signal x [n]. The role of the lowpass ﬁlter H ( f ) is depicted in Figure B. B. Its speciﬁcations are T if  f  ≤ f s /2.5) 0 otherwise. k = 0 and only retain the baseband spectrum Xa ( f ).4 Reconstructing an analog signal Once signal processing algorithms have been performed on a sampled signal in order to modify it in some desired way. and we wish to reconstruct it. the mechanism to reconstruct an analog signal is obvious if we look at the situation in the frequencydomain. we need to remove all the replicas. the spectrum of the bandlimited analog signal x a (t). We’d like to take X ( f ). The lowpass ﬁlter must be analog in order for it to not have spectral replicas of its own and thus be able to remove replicas centered at arbitrarily large multiples of f s . In order to retain the baseband spectrum. H( f ) = (B. Xa ( f − k f s ). if we sampled a bandpass signal. However.10: Frequency response of ﬁlter used to increase the sampling rate by a factor L = 5. it may be necessary to reconstruct the analog signal corresponding to the samples at hand.
oversampling techniques are used so digital ﬁlters provide some of the burden of attenuating the unwanted frequency components. it would not be enough to obtain a truly bandlimited signal. B. let us assume that we had a perfectly bandlimited analog signal that we have sampled in such a way that no aliasing occurs. we give ourselves some extra room by Digital Filters with MATLAB Ricardo A. Moreover. In order to reconstruct the analog signal. excess bandwidth is required. In order to deal with the nonzero transition of the ﬁlters. the signal must be of inﬁnite length in order to have a ﬁnite frequency spectrum. In reality there is always some degree of aliasing introduced when sampling. and Analog Reconstruction Figure B. we would require an ideal lowpass ﬁlter with inﬁnite attenuation and a perfect brickwall response with no transition gap between passband and stopband. both the antialiasing ﬁlter used to bandlimit a signal prior to sampling and the lowpass ﬁlter used for analog reconstruction have both a ﬁnite amount of stopband attenuation and a nonzero transition gap between passband and stopband. a truly bandlimited signal requires a ﬁlter with inﬁnite attenuation in its stopband. In many cases. in practice.212Sampling. so even if could construct a ﬁlter with inﬁnite attenuation. Downsampling. In reality. The ﬁnite attenuation can be dealt with by achieving enough attenuation so that the degrees of aliasing and distortion are tolerable. In other words. Losada . However.5 Practical sampling and analog reconstruction The fact that we can reconstruct a bandlimited analog signal from its samples provided we sample the signal frequently enough leads us to conclude that no information is lost when we sample the signal in such manner. instead of sampling at twice the largest frequency of interest. Upsampling.11: Spectral characteristics of lowpass ﬁlter used for analog reconstruction. Nevertheless. Different applications may require different attenuation levels.
 X ( f ). Losada .12. f max .12: Practical sampling with excess bandwidth. The upper graph in the Figure shows the analog spectrum  Xa ( f ) after the analog signal has been ﬁltered with an analog antialiasing preﬁlter. which in turn means fewer analog components). Any signal processing algorithms Digital Filters with MATLAB Ricardo A. As a result.5 Practical sampling and analog reconstruction 213 Figure B. The further we can push out the transition band. The magnitude spectrum of the signal sampled in the way just described. is shown in the lower graph of Figure B. This is because we will have a smaller number of samples to deal with. However. It is selected to be twice the frequency that lies in the midpoint between the maximum frequency of interest and f max .12. Since the ﬁlter is nonideal. the aliasing does not corrupt any of the frequencies of interest. sampling introduces aliasing in the excess frequency band. The antialias ﬁlter has a passband that coincides with the band of interest. The idea is illustrated in Figure B.B. it has a transition band that extends beyond the band of interest. the easier it is to construct the analog preﬁlter (a lower order is required. The reason we select the sampling frequency in such a way that aliasing occurs in the excess bandwidth region is that we would like to keep the sampling frequency as low as possible. sampling at a slightly larger rate. Notice that the sampling frequency is not selected to be twice the stopbandedge of the antialias preﬁlter.
but in this case we purposely Digital Filters with MATLAB Ricardo A. the further we can push out the stopbandedge frequency of the antialias analog ﬁlter. The idea can be extended to 2x or 4x oversampling (or more). There are two main consequences to doing this. a lowpass analog reconstruction ﬁlter is needed. it is worth noting that the reconstruction ﬁlter is usually built in two stages. If necessary. In such cases. B. Usually we avoid having more samples than necessary. First. Downsampling. We will discuss this next.214Sampling. the stopbandedge can be pushed out all the way to two times or four times the maximum frequency of interest plus an extra 10 to 20 percent cushion. making it simpler to build. As with the antialias preﬁlter.13 shows the requirements for a reconstruction ﬁlter. since we oversample. and reconstructs the analog signal with magnitude spectrum  Xa ( f ) by removing all spectral replicas. This simple ﬁlter has a poor lowpass response that allows for some highfrequency components to remain. These high frequency components are removed by the second stage ﬁlter. the frequencies between the band of interest and f s /2 can be attenuated digitally with a digital lowpass ﬁlter prior to analog reconstruction. This would allow a larger transition region for the reconstruction ﬁlter. Figure B. Increasing the sampling rate of the signal digitally prior to reconstruction further eases the job required by the reconstruction ﬁlter. the easier it is for such ﬁlter to be built. Although we won’t get into details. The transition band requirements will depend on how harmful the frequencies present in the excess bandwidth are for the application at hand. Once the signal needs to be converted back to the analog domain. we have more samples to deal with than we’d like. the passband of the reconstruction ﬁlter should extend up to the highest frequency of interest. The design of this ﬁlter also takes advantage of the excess bandwidth available.5.1 Oversampling As we pointed out in the precious section. Upsampling. The ﬁlter takes the sampled signal with magnitude spectrum  X ( f ). Losada . and Analog Reconstruction performed on the sampled signal will be less computationally intensive as a result of having fewer samples. The ﬁrst stage is usually a simple staircase reconstruction that converts the signal to analog by holding each sample’s value until the next sample.
generate more samples in order to simplify the antialiasing ﬁlter.e. Second. The magnitude spectrum  X ( f ) shown in the Figure corresponds to the oversampled signal. The implementation of the digital ﬁltering and downsampling is always done in an efﬁcient manner (polyphase or otherwise) as explained in Chapter 4. It is shown for illustration purposes. i. The ﬁltering takes care of the poor out of band attenuation and allows for the downsampling to occur without aliasing corrupting the band of interest.B. while the downsampled signal’s spectrum is labeled  Xd ( f ). Aliasing does occur when downsampling. In order to deal with both of these issues. Losada . there is poor out of band attenuation.5 Practical sampling and analog reconstruction 215 Figure B.13: Practical reconstruction with excess bandwidth. For this 2x case. which overlaps with its spectral replicas. many undesired frequencies are present. In reality we go directly from  X ( f ) to  Xd ( f ) Digital Filters with MATLAB Ricardo A. we use a combination of digital lowpass ﬁltering plus downsampling. but it is limited to the transition band of the digital ﬁlter. The whole idea is illustrated for the case 2x oversampling in Figure B. The digitallowpassﬁltered signal’s spectrum is labeled  X ′ ( f ).14. the digital ﬁltering can be performed with a very efﬁcient halfband ﬁlter. Note that the spectrum  X ′ ( f ) is conceptual since in practice we do not ﬁlter ﬁrst and then downsample (that would be wasteful). since the antialias ﬁlter has a transition band that extends all the way to twice or more the band of interest.
The burden of removing spectral replicas is shared between the digital ﬁlter used for increasing the sampling rate and the analog reconstruction ﬁlter. this allows for a wide transition width for the Digital Filters with MATLAB Ricardo A.216Sampling. If the sampling rate is increased by a factor of L. As we just saw. using an efﬁcient decimation ﬁlter. The analog reconstruction ﬁlter has to removed the remaining replicas that cannot be removed by the digital ﬁlter. The idea is completely analogous to that of oversampling in analog to digital conversion. Upsampling. and Analog Reconstruction Figure B. Similarly. oversampling eases the job of the antialiasing analog preﬁlter by placing some of the burden on the ﬁlter used for decimation. Downsampling. increasing the sampling rate can be used to ease the job of the analog reconstruction ﬁlter when we are performing digital to analog conversion. the ﬁlter removes L − 1 adjacent replicas. The digital ﬁlter removes the adjacent replicas. Nevertheless. Losada . since the adjacent replicas have been removed.14: Illustration of 2x oversampling plus decimation.
15.15: Analog reconstruction by ﬁrst increasing the samplingrate by a factor of L = 2. once again.B. The situation for the case L = 2 is illustrated in Figure B. This signal has been sampled (possibly downsampled as well) in such a way that the excess bandwidth overlaps with the replicas as previously discussed. This should be done at the lowest rate possible so that the transition width relative to the sampling rate is as large as possible (lowering the order required for the ﬁlter). enables us to use a simple loworder ﬁlter that is easy (and cheap) to build.5 Practical sampling and analog reconstruction 217 Figure B. The magnitude response of the ﬁlter used to remove the adjacent replicas is shown by the dashed line. Note that this ﬁlter also attenuates components out of the band of interest. Y ( f ) represents an optional step. Losada . Next. Depending on the application. we may need to ﬁlter some of the components in the band outside of the band of interest. It Digital Filters with MATLAB Ricardo A. we increase the sampling rate by two.  Xd ( f ) represents the magnitude spectrum of the digital signal we wish to convert to analog. analog reconstruction ﬁlter which.
As mentioned before. the distortion can be compensated for by preequalizing the signal digitally prior to sending it through the staircase reconstructor. Losada . To do so. the analog reconstruction ﬁlter is usually built in two stages. The more we increase the sampling rate prior to reconstruction. The remains spectral replicas are now widely separated so that an analog reconstruction ﬁlter with a wide transition band can be used for the ﬁnal digital to analog conversion. The noiseshaping allows for the use of a smaller number of bits without decreasing the signaltonoise ratio. Downsampling. The staircase reconstruction ﬁlter causes some distortion in the band of interest.218Sampling. Upsampling. Digital Filters with MATLAB Ricardo A. The resulting magnitude spectrum of the upsampled signal is represented by Yu ( f ). we mention that in practice noiseshaping sigmadelta quantizers are usually used in conjunction with the techniques outlined here in order to reduce the number of bits required to represent the signal at high sampling rates. and Analog Reconstruction can be designed so that it does all the work done to get Y ( f ) in addition to removing spectral replicas in one step. If necessary. the ﬁlter used for increasing the rate is designed in such a way that it boosts the signal over a part of the band of interest that will be attenuated by the staircase reconstructor. Finally. the less the distortion.
Input sampling frequency: 100 MHz The table below compares the implementation cost of various singlerate designs. Transition width: 0.Fst.Ast. Minimum stopband attenuation: 80 dB 5.125e6 + TW/2. The following command is used for the speciﬁcations: Fs = 100e6. Ap = 1. Maximum passband ripple: 1 dB 4.Appendix C Case Study: Comparison of Various Design Approaches Consider the following lowpass specs: 1. Ast = 80.Ap. Cutoff frequency: 3. Hf = fdesign.125e6 . Fst = 3.125 MHz 2. Fp = 3. TW = 0. .4 MHz 3.Fs).TW/2.4e6.lowpass(Fp.
NumberOfSections. Next.'cic'. % CIC compensator design M2 = 2.Fs). For the CIC design. The ﬁnal stage will be a regular halfband. Fact 15 15 15 Finally. Hf2 = fdesign.7333 16.Fp.decimator(15. we compare 3 designs that include decimation by a factor of 15.Ast.Ast.Ap. The code is as follows: % CIC decimator design M1 = 4. D = 1.Fst. Nsecs = Hcic. will provide decimation of 2.Ast.Fs).Fs/M1). Losada . This line is used to set the specs for the Nyquist designs: Hf = fdesign. The next stage.933 14. The ﬁrst stage.: Hf = fdesign.Ap. we compare one CIC multistage design and 3 multistage Nyquist designs.decimator(M1.TW.'lowpass'..3333 NStages 1 2 2 Decim.6 APIS 42. NMult NAdd equiripple 642 641 IFIR JO 224 222 multistage 169 167 Nstates 630 216 161 MPIS 42. Fact N/A N/A N/A N/A IFIR JO denotes that the joint optimization option is used with the IFIR design.'nyquist'. See Chapter 5 for more on this. will provide a decimation of 4. Nsecs.8 17. % Differential delay Hf1 = fdesign.Fp.Ast.'ciccomp'. the CIC compensator.decimator(M2.. also providing decimation by 2.decimator(16.'equiripple').Fp..16. Hcomp = design(Hf2.Fs/(M1*M2)FpTW.D. Hcic = design(Hf1. we break it down in 3 stages.220 Case Study: Comparison of Various Design Approaches NMult NAdd ellip 20 20 equiripple 642 641 IFIR 138 136 IFIR JO 115 113 Nstates 10 641 759 680 MPIS 20 642 138 115 APIS 20 641 136 113 NStages 1 1 2 2 Decim. Digital Filters with MATLAB Ricardo A.'multisection').D.Fs). The following command sets the specs.333 14. which is the CIC decimator.
'equiripple'). NMult NAdd CIC multistage 86 94 FIR equirip 98 94 IIR ellip 14 28 IIR lin phase 37 74 Nstates 166 180 22 80 MPIS 6. Note that the Nyquist designs far exceed the passband ripple speciﬁcation (1 dB) even though it is not set explicitly.221 % Halfband design M3 = 2.. Hhalf = design(Hf3. Losada . the passband ripple is of the order of 10−8 dB. % Overall design Specifying the Nyquist band to be 16 implies that the cutoff frequency π is 16 which corresponds to the 0.375 4.decimator(M3. This value is almost always set to be the same as the decimation factor. Hcas = cascade(Hcic.625 7. In the case of IIR halfbands.Hcomp.Fs/(M1*M2)).325 2.0625 10.0625π required. TW. All Nyquist designs result in a 4stage ﬁlter with halfband decimators in each stage.625 NStages 3 4 4 4 Decim. Hf3 = fdesign.Hhalf).. Fact 16 16 16 16 Digital Filters with MATLAB Ricardo A.'halfband'..125 9.8125 APIS 12.3125 3.Ast.
The basic tradeoff that one should understand whenever dealing with ﬁxedpoint arithmetic is maximizing SNR vs. Of course. Chapter 2 of [3] and Chapter 8 of [36] are recommended. minimizing the possibility of overﬂows occurring. using more bits is not always an option.Appendix D Overview of FixedPoint Arithmetic Overview In this appendix we provide a brief overview∗ of ﬁxedpoint arithmetic and its implications on digital ﬁlters. Hardware constraints may predetermine how many bits are available to represent a given quantity. The SNR can be increased in two ways: increasing the signal power by maximizing the use of the available dynamic range or decreasing the noise power by using more bits to represent data. The issue with increasing the utilization of the available dynamic range is that a signal can easily overﬂow when some arithmetic is performed on it. The SNR in this realm refers to signal to quantization noise ratio. these two requirements are in opposition to each other and a compromise needs to be reached. . ∗ For a more complete coverage. As is so often the case.
2B−1− F . From (D.1 Some ﬁxedpoint basics 223 D. D. we can see that the value of a ﬁxedpoint number is determined by assigning weights of the form 2−m to each bit. Given the bit values. For this. B−bits The register has B bits (it has a wordlength of B).2 Quantization of signals and SNR Fixedpoint representation can be used to represent data in any range. F } completely characterizes a ﬁxedpoint number. the pair { B. i. a two’s complement ﬁxedpoint number stored in such a register has a value given by value = −bB−1 2B−1− F + B −2 k =0 ∑ bk 2 k − F (D.D.1) where F is a (positive or negative) integer that deﬁnes the scaling of the bits. The reason is that F is not necessarily a length (for instance if F is negative or if F is greater than B). .1 Some ﬁxedpoint basics b B −1 b2 b1 b0 Consider a register used to store a ﬁxedpoint number.1). has the largest weight. we need to deﬁne the scaling of the bits. The leftmost bit.. This bit is called the leastsigniﬁcant bit (LSB). However. bB−1 . sufﬁces in determining the value that the bits represent. 2− F . The bits themselves are not enough to determine the value being held in the register. F is referred to as a fraction length (or FracLength) but this is somewhat of a misnomer. The most positive value that can be represented is given by the sum of all the weights of all bits except for the MSB. when F is positive and F ≤ B.e. Losada . Speciﬁcally. it will be equal to the number of bits to the right of the binary point hence the term fraction length. the most negative value that can be represented is given by the scaling of the MSB.. With two’s complement representation. which is why it is called the mostsigniﬁcant bit (MSB). Digital Filters with MATLAB Ricardo A. bk . the value of the kth bit (from right to left) is given by bk which can obviously be only 0 or 1. The rightmost bit. b0 has the smallest weight.
with 4 bits available and a fraction length of 8 (so that the scaling of the LSB is 2−8 and the scaling of the MSB is 2−5 ). So for a given dynamic range to be covered. In general. the most negative value that can be represented is −2−5 and the most positive value that can be represented is 2−6 + 2−7 + 2−8 (which is equal to 2−5 − 2−8 ). the smaller the quantization error when we round a value to the nearest representable value. The number of values that can be represented is given by 2B . As the number of bits increases. consider Figure D.1. the number of values that can be represented within those limits is given by 2B . The step size or increment between the values represented is given by ε = 2− F . Losada . we can represent 24 = 16 numbers between −2−5 and 2−5 − 2−8 with a resolution or increment of 2−8 between each number and the next consecutive one. the number of bits determines the granularity (precision) with which we can represent numbers within that range. The range that is covered is denoted by R. The quantization step is denoted ε = 2− F . In total. the SNR increases because the quantization noise decreases.224 Overview of FixedPoint Arithmetic Figure D. If R is constant. Digital Filters with MATLAB Ricardo A. Speciﬁcally. The more bits we use.1: For example. There are only two degrees of freedom in these quantities which are related by R =ε 2B If we round all values to their nearest representable value. the maximum error introduced by such rounding is given by ε/2.
= fi(x.15). it is necessary that the signal being quantized can take any value within that range with equal probability. 1) with equal probability. i.2 Quantization of signals and SNR 225 and B increases. it has a range of ε.5). ε/2].15).inf). Consider what would happen if instead of uniform white noise. then ε and consequently the largest quantization error decreases.e. x x xq = randn(10000. ε = 20 log10 (2B ) = 6. The quantization error covers the interval [−ε/2. x = 2*(rand(10000.true. the signal strength is R. To achieve this upper bound. Losada Digital Filters with MATLAB .3942 We use 16 bits to represent the signal and the stepsize is 2−15 . A simple calculation of SNR when quantizing a signal can be performed as follows [3]: If R is fully covered by the signal in question.02B This result is known as the 6 dB/bit rule [3]. The result provides an upper bound on the achievable SNR when using B bits to cover a given range R. Ricardo A.16.16. xq = fi(x.true. we take samples from a Gaussian white noise signal and ensure they fall within the interval [−1. it is necessary that the signal behaves like uniformly distributed white noise over that range. we have SNR = 20 log10 R ε R . The SNR we can achieve is inline with the 6 dBperbit rule. so the SNR is given by SNR = In dB. SNR = 10*log10(var(x)/var(xdouble(xq))) SNR = 96.1). = x/norm(x.D.1)0. In other words. Example 74 Consider the following quantization of a signal which covers the range [−1. 1).
e. On average the signal strength is not that large. while the quantization error strength remains the same.bar(c.2: Histogram of a whitenoise signal normalized so that the maximum values is ±1.n) The histogram for the whitenoise case is shown in Figure D. the quantization error can be equally large (on average) whether x takes a small or a large value.8 1 x Figure D. Since Digital Filters with MATLAB Ricardo A. SNR = 10*log10(var(x)/var(xdouble(xq))) SNR = 89.226 Overview of FixedPoint Arithmetic Histogram of x 350 300 250 200 150 100 50 0 −1 −0.9794 The SNR is no longer satisfying the 6 dBperbit rule.4 0. In other words.4 −0.6 0.2 0.c]=hist(x. Losada .100). The reason is that the signal very rarely takes values close to the largest available range (i. This can easily be veriﬁed by looking at the histogram: [n.2.6 −0.2 0 0.8 −0. close to 1 or 1).
5. h = Hd. In some cases. while var(xdouble(xq)) is the same on both cases.Fp.2.highpass('Fst. Digital Filters with MATLAB Ricardo A. depending on whether the application at hand permits it. While it may seem not so useful to consider white noise examples. 0. the ﬁrst thing we need to do is quantize the ﬁlter’s coefﬁcients. We will perform the following computation for different values of B: ∗ Typically.D.5 dB/bit when quantizing FIR ﬁlter coefﬁcients.Numerator.Ap'. Losada .5).1 Quantizing impulse responses for FIR ﬁlters When implementing an FIR ﬁlter with ﬁxedpoint arithmetic. In practice we can expect somewhere between 4. if we look at the var(x) for the uniform case. on average we can’t expect to get the full 6 dB/bit.2 Quantization of signals and SNR 227 x takes small values more often than it take large values. In summary. the middle sample dominates for linearphase ﬁlters. Now let’s compute the SNR for various values of B and see what SNRs we get.e. Example 75 Consider the following highpass ﬁlter design: Hf = fdesign. our ﬁxedpoint settings should be such to cover the range [−0. can behave similar to white noise.inf) The impulse response is shown in Figure D. Since the impulse response of most FIR ﬁlters has a few large samples∗ and many small samples.5 and 5. it is much larger than var(x) in the Gaussian case. depending on the nature of the signal being quantized.5.5) since this is the smallest poweroftwo interval that encompasses the values of the impulse response. Therefore.3. Hd = design(Hf. it is worth keeping in mind that many practical signals that are quantized. The largest sample has a magnitude of 0.80.Ast. this reduces the SNR.434. i.'equiripple'). D. Indeed.0. This can be accomplished by setting F to be equal to B.. its impulse response. the achievable SNR will vary.6.. such as speech and audio signals.0. it may be preferable to allow for the occasional overﬂow with the aim of increasing the SNR on average for a given signal. % Get the impulse response norm(h.
228 Overview of FixedPoint Arithmetic Impulse Response 0.2 0. 5.4 −0.3 −0. when adding two ﬁxedpoint numbers. 16.1 0 −0. 12.5 0. The largest coefﬁcient has a magnitude of 0.3.B.434.9704. fi(h. B F hq SNR = = = = 8. 24 B. 10*log10(var(h)/var(hdouble(hq))) If we divide the SNR by B.3: Impulse response of highpass ﬁlter. % change to 10. 4. Digital Filters with MATLAB Ricardo A.3796.1 Fixedpoint addition In general.4 0.3 0. we get the following values of dB/bit: 4. Losada . D.3760.7690. 5.2 −0.true.1000. 5. 5. 18.3 Fixedpoint arithmetic Let’s look at a couple of things to keep in mind when performing additions/multiplications with ﬁxedpoint arithmetic. for the various values of B shown. in order to avoid roundoff error it is necessary to increase the wordlength of the result by one bit. D.F).1 −0.5890. This is to account for the possibility of a carry resulting from the addition.5 0 10 20 30 40 50 Amplitude Samples Figure D.
in order to have full precision). If we now add 0.e. If we add 0. If we add two of these numbers. the result will be 1. 2). † A similar argument can be made by using the largest negative value. avoid roundoff. Losada . If N is the number of additions.D. The worst case scenario is when the actual numbers are the largest possible representable number for a given format. With an 18bit wordlength and a fraction length of 15 we can represent numbers in the range [−4. but the following three additions would not. we get 3.e.999 the result is 2. 0.e. Many ﬁlter structures contain a series of additions. 1). ∗ Digital Filters with MATLAB Ricardo A. it is not necessary to increase the wordlength by one bit for every addition in the ﬁlter in order to avoid roundoff (i. x2 has 0110 as its binary representation.999 as an answer. we need to further increase the wordlength by one bit in order to represent the result with no loss of precision.99 to the value 1. To avoid overﬂow.. Note that in general because of the possibility that the LSB is equal to 1. Since this number falls within the representable range. it is only necessary to increase the wordlength by ∗ G = ⌊log2 ( N )⌋ + 1.875 and x2 = 0. it is not necessary to add an additional bit in order to represent this number.999. The sum of the two is 1. i. Since this value falls outside the range [−2. hence the bit growth. we need to increase the wordlength to 17 bits (and leave the fraction length ﬁxed at 15). The binary representation of the result is 01101. However. say x1 = 0. In order to have no loss of precision. Consider the largest positive value.2) To see this. it is necessary to cover the range [−2.3 Fixedpoint arithmetic 229 For example suppose we want to add two 4bit numbers that fall in the range [−1.99† .999. (D. consider the addition of several numbers represented with 16bit wordlength and a fraction length of 15. the ﬂoor command in MATLAB). The operator ⌊·⌋ denotes the largest integer smaller or equal to the value operated on (i. We need to represent it with 5 bits so that no roundoff error is introduced. 2) in order to represent the result.6250. it is not possible to discard the LSB without introducing roundoff error. 4). The next addition would require another bit to be aggregated. 2. x1 has the following binary representation (with F = 3): 0111.99 to the result we had so far.999.75. and so forth. one after the other.
4. meaning that we need to add 1 bit every time two numbers are added. In Chapter 7. In the worst case. we can get a fullprecision result by adding only 2 rather than 3 bits overall. we would need to add 3 bits in total. in order to obtain a fullprecision result. In summary. Some branches will be slightly incomplete. we will see that for FIR ﬁlters. Note that the (D.3. Let’s look at the worse case scenario if we multiply a number x1 . it should be expected that bitgrowth is required if we want to multiply two numbers without introducing loss of precision. but the required bit growth should still be correctly determined.4 shows the case of adding 4 Bbit numbers together.230 Overview of FixedPoint Arithmetic Treeadder view of multiple additions An easy way of understanding this log2 bit growth when adding is to look at what would happen if we used a treelike structure to implement the series of additions in a direct form FIR ﬁlter. the bit growth is independent of the fraclengths involved. the bit growth is B2 bits. F2 }. This takes into the account the worst possible case. Using (D. the LSBs have weights of 2− F1 and 2− F2 respectively. represented with B1 bits. The idea still applies when there is not a powerof2 number of values to be added together. Losada . D. F1 } and the other with wordlength/fraclength given by { B2 . In terms of the fraclength.2). One could say the treeadder view has the log2 bit growth builtin to it. represented with B2 bits.2) holds for the worst case scenario in which the numbers being added are the of largest possible magnitude. The product of the two will of course have a weight of 2−( F1 + F2 ) . we can reduce the bit growth required to avoid roundoff by looking at the actual coefﬁcients of the ﬁlter. we are multiplying the bits in x1 times −2B2 −1 . Since the bit growth is independent of the fraclength. Digital Filters with MATLAB Ricardo A. Figure D. If we added one bit for every addition. That means that we add (ignore the sign) x1 to itself 2B2 −1 times. Just as with addition. given two ﬁxedpoint numbers. with a number x2 . as we can see in Figure D. if x1 has a fraclength of F1 and x2 has a fraclengh of F2 .2 Fixedpoint multiplication Since multiplication is nothing but repeated addition. consider the binary digits involved. However. one with wordlength/fraclength given by { B1 .
Losada . Digital Filters with MATLAB Ricardo A. F1 + F2 }.D. As is the case with additions.4: Treeadder view of adding 4 Bbit numbers. we can reduce the bit growth required to avoid roundoff when multiplying by looking at the actual coefﬁcients of the ﬁlter. For example. in Chapter 7 we will see that for FIR ﬁlters. the product of the two numbers can be represented without loss of precision by using a wordlength of 34 bits and a fraction length of 24. Only B + 2 bits are needed for a full precision result. the product of the two numbers can be represented with no roundoff by using a wordlength/fraclength of { B1 + B2 .3 Fixedpoint arithmetic 231 Figure D. given a number represented with 16 bits and a fraction length of 14 and another number represented with 18 bits and a fraction length of 10.
However.5: Quantization of a signal. we assume here we are rounding to the nearest value when we quantize. Statistically. Q{ x [n]} = xq [n].∗ The variance of the quantization noise signal can easily be found to be ε2 /12 [3]. can be modeled as uniformly distributed whitenoise over the range [−ε/2. Speciﬁcally. a good model for the quantization error is as additive noise to the signal being quantized [3]. This is of course important when one is considering analogtodigital conversion. D. ∗ Digital Filters with MATLAB Ricardo A.232 Overview of FixedPoint Arithmetic Figure D. we don’t worry about the quantization of the input signal since this occurs elsewhere. The operator Q{·} takes the input signal and produces a quantized version of it. the noise signal itself. Reducing the number of bits used to represent a signal The results we have presented so far apply to quantizing an analog signal in order for it to be represented with ﬁxedpoint. Figure D. i. In digital ﬁlters. Losada .e. we truncate.6.4 Quantization noise variance In many cases. Provided that the input signal changes fast enough. we can model the effect of Q{·} as additive noise signal as shown in Figure D. ε/2]. things change slightly. If instead we round towards −∞.5. consider the quantization of the signal x [n] as shown in Figure D.6: Statistical model for the quantization of a signal. it is often the case that we Again. e[n].
However. will be a random signal with PSD given by. Pyy (e jω ) = H (e jω ) P xx (e jω ) In particular. its PSD will be constant. The variance of the quantization noise that we have just derived doesn’t quite apply for the case of requantizing a quantized signal [36]. such variance becomes a very good approximation if at least 3 or 4 bits are thrown out. the output of the ﬁlter. y[n]. Another common case is in the feedback portion of an IIR ﬁlter since otherwise the repeated additions would result in unbounded bit growth. This way the same range can be covered after requantization and overﬂow is avoided. A typical example is keeping only 16 bits for the output from an accumulator that may have anywhere from 32 to 40 bits.5 Quantization noise passed through a linear ﬁlter When analyzing how quantization affects the output signal of a ﬁlter. the ε2 /12 value is usually used without giving it a second thought. D.e. Examples where this is common include throwing out bits when moving data from an accumulator (all the additions in a directform FIR ﬁlter) to the output of the ﬁlter because we need to preserve the input signal wordlength at the output. reduce the number of bits used to represent it. Losada 2 . with power spectral density (PSD) given by P xx (e jω ) is ﬁltered through a ﬁlter with frequency response H (e jω ). The precision is clearly reduced as we throw out LSBs (the quantization step increases from 2− F to 2−( F−Q) . i. where Q is the number of bits that are thrown away. Since we are typically removing anywhere from 16 bits onward. with intensity given by the variance Digital Filters with MATLAB Ricardo A. The value of ε in this case corresponds of course to the quantization step after requantizing. Of course the bits that we throw out when we requantize a signal are the LSBs. such as the quantization noise. if the input is a whitenoise signal. the following result will come in handy: If a random signal.5 Quantization noise passed through a linear ﬁlter 233 need to requantize a quantized signal.D. x [n].
In this case. These schemes are widely used in practice.234 Overview of FixedPoint Arithmetic 2 scaled by 2π. One of the primary uses of decimation ﬁlters is in easing the implementation of analog to digital conversion. the average power is simply PAVG = 2 ε2 ε2 H (e jω ) dω = 12 −π 2π · 12 π (D. 2π Therefore. For more information see [3]. Losada . Pyy (e jω ) = D.1 Computing the average power of the output noise Once we have computed the PSD of the output due to the quantization noise. the PSD of the output will be 2 2 σx (D.5. we can compute the average power at the output due to such noise by integrating the PSD. σx /2π. the transfer function between the noise source and the ﬁlter output is trivially H (e jω ) = 1. PAVG = π −π Pyy (e jω )dω In the case of FIR ﬁlters.e.3) H (e jω ) .6 Oversampling noiseshaping quantizers A great deal of emphasis is placed throughout this document on multirate ﬁlters. one of the primary uses of interpolation ﬁlters is to help with digital to analog conversion (it is one of the few reasons to oversample). In either the decimation or interpolation case.4) D. the use of noise shaping quantizers (or requantizers) in which multirate techniques are used in conjunction with shaping the quantization noise (via highpass ﬁltering) can reduce the number of bits required to represent a signal without decreasing the SNR. If the PSD intensity is 2 σx /2π = ε2 /(2π · 12). i. in this case the PSD will take the spectral shape of the squared magnituderesponse of the ﬁlter. Digital Filters with MATLAB Ricardo A. Similarly. This process of course involves quantization of signals. when all arithmetic is performed with full precision and therefore the only source of quantization noise is due to the bits being discarded at the output.
Burrus. J. [2] R. Parks and C. Part I. Digital Filter Design. Upper Saddle River. “Design ﬁnite impulse response digital ﬁlters. Parks. Rabiner. Introduction to Approximation Theory. pp. W. 1987. 6. Finite impulse response ﬁlter design. 1993. 1996. [7] J. Orfanidis. 4. 506–526. R. F. vol. Introduction to Signal Processing. W. pp. Handbook for Digital Signal Processing. S. 1973. New York: WileyInterscience. [4] T. [3] S. Kaiser Eds. Rhode Island: American Mathematical Society. New York. [9] T. January 2004.” Microwaves & RF. New York. Schußler. S. ch.” Electronic Lett. and L. Englewood Cliffs.. 70–84. K. Rabiner and B. . 155–278. Hermann and H. New Jersey: Prentice Hall. R. [5] L. AU21.” IEEE Trans. McClellan. February 2004. New Jersey: Prentice Hall. vol. W. New York: WileyInterscience. “A computer program for designing optimum FIR linear phase digital ﬁlters. W.Bibliography [1] R. 66–80.. A. pp. “Design ﬁnite impulse response digital ﬁlters. 43. Part II. “Design of nonrecursive digital ﬁlters with minimum phase. A. Gold. vol. Cheney. pp. vol. Saramaki. Audio Electroacoust. H. 1970. 1975. ¨ [8] O. pp. 1998. Mitra and J. Losada.. 329–330. T. Losada. [6] E.” Microwaves & RF. 43. Theory and Application of Digital Signal Processing.
pp. July 2005. New Jersey: Prentice Hall. 137–142. Gazsi. S. P. 55. New York. 33–41. Digital Filters with MATLAB Ricardo A. 377– 388.. CAS44. New York. K. Losada and V. [15] S. vol. Upper Saddle River. A. [11] fred harris. pp. Designing IIR Filters with a Given 3dB Point. “Designing IIR ﬁlters with a given 3dB point. 68–88. Regalia. pp. Pellissier. A. New York: McGrawHill. ch. ch. Edited by R. Losada and V. [18] L. New York: WileyInterscience.” IEEE Signal Proc. “The digital allpass ﬁlter: a versatile signal processing buildingblock. Magazine. 1993. K.236 BIBLIOGRAPHY [10] I. pp. “Exchange algorithms that complement the ParksMcClellan algorithm for linearphase FIR ﬁlter design. Hoboken. 76. WileyInterscience. second ed. Pellissier. Mitra. vol. pp. 419–490. [13] R. Robust digital ﬁlter structures. January 1988. Selesnick and C. third ed. December 2001. and B. Mitra. 7. Vaidyanathan. New Jersey: Prentice Hall. Vaidyanathan. DSP Tips & Tricks column. New Jersey: IEEE Press. 22. 1985. P. vol. W. Mitra and J. Antoniou. 95–98. pp.” AEU International Journal of Electronics and Communications. vol. Digital Signal Processing: A ComputerBased Approach.. [17] P. Filter Design for Signal Processing Using MATLAB and Mathematica. 1993. and Applications. Steffen. W. S.” IEEE Trans. [19] M. Upper Saddle River. and P. Tosic. New York. Evans. 2007. 4. on Circuits and Systems II. “Recursive halfbandﬁlters.” Proceedings of the IEEE. on Circuits and Systems. [12] R. 19–37.. Design. 2004. Burrus. Lyons. Schußler and P. K. “Explicit formulas for wave digital ﬁlters. F. S. Losada . Lutovac. pp. Kaiser Eds. Handbook for Digital Signal Processing. CAS32. February 1997. 2001. 2006. A. D. [14] A. Streamlining Digital Signal Processing: A Tricks of the Trade Guidebook. Multirate Signal Processing for Communication Systems.” IEEE Trans. New York: McGrawHill. Digital Filters: Analysis. vol. ¨ ¨ [20] H. [16] P.
[22] M. Fliege. ASSP29. on Acoust. Losada . Digital Filters with MATLAB Ricardo A.Y. “Allpass ﬁlter design and applications. Hoboken. 70–88. 1983. Hogenauer. Streamlining Digital Signal Processing: A Tricks of the Trade Guidebook. “Design of computationally efﬁcient interpolated FIR ﬁlters.BIBLIOGRAPHY 237 ¨ [21] H. Vaidyanathan. pp. Turbocharging Interpolated FIR Filters. Rabiner. Edited by R.” IEEE Trans. Mitra. on Circuits and Systems. Mag. 155–162. Saramaki. March 1998. 73–84. New York. [23] N. [28] T. 137–164. 17.” IEEE Trans. Crochiere and L. Lyons. vol. [24] R. New Jersey: Prentice Hall. P. ch. 563–570. New Jersey: IEEE Press.” IEEE Trans. Englewood Cliffs. Speech and Signal Proc. 8. no. January 1988. 1993. 1987. pp.. K. R. 1994. 10. June 1984. on Acoust. pp. Multirate Digital Signal Processing. pp. Speech and Signal Proc. Multirate Digital Signal Processing. [26] P. “Interpolated narrowband lowpass FIR ﬁlters. [25] Y.” IEEE Signal Proc.” Circuits. on Circuits and Systems. Lyons. April 1981. [27] R. CAS34. September 1998. pp. New York: John Wiley & Sons. vol. 2505–2514. J. 1182–1190. “An economical class of digital ﬁlters for decimation and interpolation. Englewood Cliffs. W. [31] E. New Jersey: PrenticeHall. Y. vol. “Interpolated ﬁnite impulse response ﬁlters. Lyons. pp. pp. E. Neuvo. pp. Multirate Systems and Filter Banks. vol. Saramaki and Y. Lang. [30] T. Neuvo. Schußler and P. K. and S. [29] R. vol. 46. Neuvo. vol. Mitra. and S. “Halfband ﬁlters and Hilbert transformers.. 50–57. Steffen. C. Systems. ASSP32. and Signal Processing..” IEEE Transactions on Signal Processing. CAS35. Dong.” IEEE Trans. January 2003. “A class of ﬁr nyquist (nthband) ﬁlters with zero intersymbol interference. WileyInterscience. B. 2007.
a 2000. [34] R. 2001. Digital Filters with MATLAB Ricardo A. Numerical Analysis.. Digital Filters: Basics and Design. A. 88. pp. Hoboken. pp. Reducing CIC Filter Complexity. L. Streamlining Digital Signal Processing: A Tricks of the Trade Guidebook.238 BIBLIOGRAPHY [32] R.. “Sampling—50 years after shannon. Paciﬁc Grove. 6. New Jersey: IEEE Press. CA: Brooks/Cole. Berlin: Springer. Burden and J. Edited by R.” PROCEEDINGS OF THE IEEE. 51–58. 569–587. D. Schlichth¨ rle. New York: John Wiley and Sons. An Introduction to Numerical Analysis. Unser. ch. Losada . second ed. [36] D. seventh ed. Losada and R. Lyons. 2007. 1989. [33] K. Faires. Atkinson. E. WileyInterscience. April 2000. [35] M. Lyons. vol.
This action might not be possible to undo. Are you sure you want to continue?
Use one of your book credits to continue reading from where you left off, or restart the preview.