INTRODUCTION TO
Signal Processing
INTRODUCTION TO
Signal Processing Sophocles J. Orfanidis Rutgers University
To my lifelong friend George Lazos
Copyright © 2010 by Sophocles J. Orfanidis This book was previously published by Pearson Education, Inc. Copyright © 1996–2009 by Prentice Hall, Inc. Previous ISBN 0132091720.
All rights reserved. No parts of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the author.
R MATLAB is a registered trademark of The MathWorks, Inc.
Web page:
www.ece.rutgers.edu/~orfanidi/i2sp
Contents
Preface xiii 1
Sampling and Reconstruction 1 1.1 1.2 1.3
1.4
1.5
1.6
1.7 1.8
2
Quantization 61 2.1 2.2 2.3 2.4 2.5 2.6
3
Introduction, 1 Review of Analog Signals, 1 Sampling Theorem, 4 1.3.1 Sampling Theorem, 6 1.3.2 Antialiasing Prefilters, 7 1.3.3 Hardware Limits, 8 Sampling of Sinusoids, 9 1.4.1 Analog Reconstruction and Aliasing, 10 1.4.2 Rotational Motion, 27 1.4.3 DSP Frequency Units, 29 Spectra of Sampled Signals∗ , 29 1.5.1 DiscreteTime Fourier Transform, 31 1.5.2 Spectrum Replication, 33 1.5.3 Practical Antialiasing Prefilters, 38 Analog Reconstructors∗ , 42 1.6.1 Ideal Reconstructors, 43 1.6.2 Staircase Reconstructors, 45 1.6.3 AntiImage Postfilters, 46 Basic Components of DSP Systems, 53 Problems, 55
Quantization Process, 61 Oversampling and Noise Shaping∗ , 65 D/A Converters, 71 A/D Converters, 75 Analog and Digital Dither∗ , 83 Problems, 90
DiscreteTime Systems 95 3.1 3.2 3.3
Input/Output Rules, 96 Linearity and Time Invariance, 100 Impulse Response, 103
vii
viii
CONTENTS 3.4 3.5 3.6
4
FIR Filtering and Convolution 121 4.1
4.2
4.3
5
Block Processing Methods, 122 4.1.1 Convolution, 122 4.1.2 Direct Form, 123 4.1.3 Convolution Table, 126 4.1.4 LTI Form, 127 4.1.5 Matrix Form, 129 4.1.6 FlipandSlide Form, 131 4.1.7 Transient and SteadyState Behavior, 132 4.1.8 Convolution of Infinite Sequences, 134 4.1.9 Programming Considerations, 139 4.1.10 OverlapAdd Block Convolution Method, 143 Sample Processing Methods, 146 4.2.1 Pure Delays, 146 4.2.2 FIR Filtering in Direct Form, 152 4.2.3 Programming Considerations, 160 4.2.4 Hardware Realizations and Circular Buffers, 162 Problems, 178
zTransforms 183 5.1 5.2 5.3 5.4 5.5 5.6
6
FIR and IIR Filters, 105 Causality and Stability, 112 Problems, 117
Basic Properties, 183 Region of Convergence, 186 Causality and Stability, 193 Frequency Spectrum, 196 Inverse zTransforms, 202 Problems, 210
Transfer Functions 214 6.1 6.2 6.3
6.4
6.5 6.6
Equivalent Descriptions of Digital Filters, 214 Transfer Functions, 215 Sinusoidal Response, 229 6.3.1 SteadyState Response, 229 6.3.2 Transient Response, 232 Pole/Zero Designs, 242 6.4.1 FirstOrder Filters, 242 6.4.2 Parametric Resonators and Equalizers, 244 6.4.3 Notch and Comb Filters, 249 Deconvolution, Inverse Filters, and Stability, 254 Problems, 259
CONTENTS
7
Digital Filter Realizations 265 7.1 7.2 7.3 7.4 7.5 7.6 7.7
8
Signal Processing Applications 316 8.1
8.2
8.3
8.4
9
Direct Form, 265 Canonical Form, 271 Cascade Form, 277 Cascade to Canonical, 284 Hardware Realizations and Circular Buffers, 293 Quantization Effects in Digital Filters, 305 Problems, 306
Digital Waveform Generators, 316 8.1.1 Sinusoidal Generators, 316 8.1.2 Periodic Waveform Generators, 321 8.1.3 Wavetable Generators, 330 Digital Audio Effects, 349 8.2.1 Delays, Echoes, and Comb Filters, 350 8.2.2 Flanging, Chorusing, and Phasing, 355 8.2.3 Digital Reverberation, 362 8.2.4 Multitap Delays, 374 8.2.5 Compressors, Limiters, Expanders, and Gates, 378 Noise Reduction and Signal Enhancement, 382 8.3.1 Noise Reduction Filters, 382 8.3.2 Notch and Comb Filters, 398 8.3.3 Line and Frame Combs for Digital TV, 409 8.3.4 Signal Averaging, 421 8.3.5 SavitzkyGolay Smoothing Filters∗ , 427 Problems, 453
DFT/FFT Algorithms 464 9.1 9.2
Frequency Resolution and Windowing, 464 DTFT Computation, 475 9.2.1 DTFT at a Single Frequency, 475 9.2.2 DTFT over Frequency Range, 478 9.2.3 DFT, 479 9.2.4 Zero Padding, 481 9.3 Physical versus Computational Resolution, 482 9.4 Matrix Form of DFT, 486 9.5 ModuloN Reduction, 489 9.6 Inverse DFT, 496 9.7 Sampling of Periodic Signals and the DFT, 499 9.8 FFT, 504 9.9 Fast Convolution, 515 9.9.1 Circular Convolution, 515 9.9.2 OverlapAdd and OverlapSave Methods, 520 9.10 Problems, 523
ix
x
CONTENTS
10 FIR Digital Filter Design 532 10.1 Window Method, 532 10.1.1 Ideal Filters, 532 10.1.2 Rectangular Window, 535 10.1.3 Hamming Window, 540 10.2 Kaiser Window, 541 10.2.1 Kaiser Window for Filter Design, 541 10.2.2 Kaiser Window for Spectral Analysis, 555 10.3 Frequency Sampling Method, 558 10.4 Other FIR Design Methods, 558 10.5 Problems, 559
11 IIR Digital Filter Design 563 11.1 11.2 11.3 11.4 11.5 11.6
Bilinear Transformation, 563 FirstOrder Lowpass and Highpass Filters, 566 SecondOrder Peaking and Notching Filters, 573 Parametric Equalizer Filters, 581 Comb Filters, 590 HigherOrder Filters, 592 11.6.1 Analog Lowpass Butterworth Filters, 594 11.6.2 Digital Lowpass Filters, 599 11.6.3 Digital Highpass Filters, 603 11.6.4 Digital Bandpass Filters, 606 11.6.5 Digital Bandstop Filters, 611 11.6.6 Chebyshev Filter Design∗ , 615 11.7 Problems, 628
12 Interpolation, Decimation, and Oversampling 632 12.1 Interpolation and Oversampling, 632 12.2 Interpolation Filter Design∗ , 638 12.2.1 Direct Form, 638 12.2.2 Polyphase Form, 640 12.2.3 Frequency Domain Characteristics, 645 12.2.4 Kaiser Window Designs, 647 12.2.5 Multistage Designs, 649 12.3 Linear and Hold Interpolators∗ , 657 12.4 Design Examples∗ , 661 12.4.1 4fold Interpolators, 661 12.4.2 Multistage 4fold Interpolators, 667 12.4.3 DAC Equalization, 671 12.4.4 Postfilter Design and Equalization, 674 12.4.5 Multistage Equalization, 678 12.5 Decimation and Oversampling∗ , 686 12.6 Sampling Rate Converters∗ , 691 12.7 Noise Shaping Quantizers∗ , 698 12.8 Problems, 705
CONTENTS
13 Appendices 713 A
B
C D
Random Signals∗ , 713 A.1 Autocorrelation Functions and Power Spectra, 713 A.2 Filtering of Random Signals, 717 Random Number Generators, 719 B.1 Uniform and Gaussian Generators, 719 B.2 LowFrequency Noise Generators∗ , 724 B.3 1/f Noise Generators∗ , 729 B.4 Problems, 733 Complex Arithmetic in C, 736 MATLAB Functions, 739
References 758 Index 775
xi
Preface
This book provides an applicationsoriented introduction to digital signal processing written primarily for electrical engineering undergraduates. Practicing engineers and graduate students may also find it useful as a first text on the subject. Digital signal processing is everywhere. Today’s college students hear “DSP” all the time in their everyday life—from their CD players, to their electronic music synthesizers, to the sound cards in their PCs. They hear all about “DSP chips”, “oversampling digital filters”, “1bit A/D and D/A converters”, “wavetable sound synthesis”, “audio effects processors”, “alldigital audio studios”. By the time they reach their junior year, they are already very eager to learn more about DSP.
Approach The learning of DSP can be made into a rewarding, interesting, and fun experience for the student by weaving into the material several applications, such as the above, that serve as vehicles for teaching the basic DSP concepts, while generating and maintaining student interest. This has been the guiding philosophy and objective in writing this text. As a result, the book’s emphasis is more on signal processing than discretetime system theory, although the basic principles of the latter are adequately covered. The book teaches by example and takes a handson practical approach that emphasizes the algorithmic, computational, and programming aspects of DSP. It contains a large number of worked examples, computer simulations and applications, and several C and MATLAB functions for implementing various DSP operations. The practical slant of the book makes the concepts more concrete.
Use The book may be used at the junior or senior level. It is based on a juniorlevel DSP course that I have taught at Rutgers since 1988. The assumed background is only a first course on linear systems. Sections marked with an asterisk (∗ ) are more appropriate for a second or senior elective course on DSP. The rest can be covered at the junior level. The included computer experiments can form the basis of an accompanying DSP lab course, as is done at Rutgers. A solutions manual, which also contains the results of the computer experiments, is available from the publisher. The C and MATLAB functions may be obtained via anonymous FTP from the Internet site ece.rutgers.edu in the directory /pub/sjo or
xiii
xiv
PREFACE
by pointing a Web browser to the book’s WWW home page at the URL: http://www.ece.rutgers.edu/~orfanidi/intro2sp
Contents and Highlights Chapters 1 and 2 contain a discussion of the two key DSP concepts of sampling and quantization. The first part of Chapter 1 covers the basic issues of sampling, aliasing, and analog reconstruction at a level appropriate for juniors. The second part is more advanced and discusses the practical issues of choosing and defining specifications for antialiasing prefilters and antiimage postfilters. Chapter 2 discusses the quantization process and some practical implementations of A/D and D/A converters, such as the conversion algorithm for bipolar two’s complement successive approximation converters. The standard model of quantization noise is presented, as well as the techniques of oversampling, noise shaping, and dithering. The tradeoff between oversampling ratio and savings in bits is derived. This material is continued in Section 12.7 where the implementation and operation of deltasigma noise shaping quantizers is considered. Chapter 3 serves as a review of basic discretetime systems concepts, such as linearity, timeinvariance, impulse response, convolution, FIR and IIR filters, causality, and stability. It can be covered quickly as most of this material is assumed known from a prerequisite linear systems course. Chapter 4 focuses on FIR filters and its purpose is to introduce two basic signal processing methods: blockbyblock processing and samplebysample processing. In the block processing part, we discuss various approaches to convolution, transient and steadystate behavior of filters, and realtime processing on a blockbyblock basis using the overlapadd method and its software implementation. This is further discussed in Section 9.9 using the FFT. In the sample processing part, we introduce the basic building blocks of filters: adders, multipliers, and delays. We discuss block diagrams for FIR filters and their timedomain operation on a samplebysample basis. We put a lot of emphasis on the concept of sample processing algorithm, which is the repetitive series of computations that must be carried out on each input sample. We discuss the concept of circular buffers and their use in implementing delays and FIR filters. We present a systematic treatment of the subject and carry it on to the remainder of the book. The use of circular delayline buffers is old, dating back at least 25 years with its application to computer music. However, it has not been treated systematically in DSP texts. It has acquired a new relevance because all modern DSP chips use it to minimize the number of hardware instructions. Chapter 5 covers the basics of ztransforms. We emphasize the zdomain view of causality, stability, and frequency spectrum. Much of this material may be known from an earlier linear system course. Chapter 6 shows the equivalence of various ways of characterizing a linear filter and illustrates their use by example. It also discusses topics such as sinusoidal and steadystate responses, time constants of filters, simple pole/zero designs of first and secondorder filters as well as comb and notch filters. The issues of inverse filtering and causality are also considered.
PREFACE
xv
Chapter 7 develops the standard filter realizations of canonical, direct, and cascade forms, and their implementation with linear and circular buffers. Quantization effects are briefly discussed. Chapter 8 presents three DSP application areas. The first is on digital waveform generation, with particular emphasis on wavetable generators. The second is on digital audio effects, such as flanging, chorusing, reverberation, multitap delays, and dynamics processors, such as compressors, limiters, expanders, and gates. These areas were chosen for their appeal to undergraduates and because they provide concrete illustrations of the use of delays, circular buffers, and filtering concepts in the context of audio signal processing. The third area is on noise reduction/signal enhancement, which is one of the most important applications of DSP and is of interest to practicing engineers and scientists who remove noise from data on a routine basis. Here, we develop the basic principles for designing noise reduction and signal enhancement filters both in the frequency and time domains. We discuss the design and circular buffer implementation of notch and comb filters for removing periodic interference, enhancing periodic signals, signal averaging, and separating the luminance and chrominance components in digital color TV systems. We also discuss SavitzkyGolay filters for data smoothing and differentiation. Chapter 9 covers DFT/FFT algorithms. The first part emphasizes the issues of spectral analysis, frequency resolution, windowing, and leakage. The second part discusses the computational aspects of the DFT and some of its pitfalls, the difference between physical and computational frequency resolution, the FFT, and fast convolution. Chapter 10 covers FIR filter design using the window method, with particular emphasis on the Kaiser window. We also discuss the use of the Kaiser window in spectral analysis. Chapter 11 discusses IIR filter design using the bilinear transformation based on Butterworth and Chebyshev filters. By way of introducing the bilinear transformation, we show how to design practical secondorder digital audio parametric equalizer filters having prescribed widths, center frequencies, and gains. We also discuss the design of periodic notch and comb filters with prescribed widths. In the two filter design chapters, we have chosen to present only a few design methods that are simple enough for our intended level of presentation and effective enough to be of practical use. Chapter 12 discusses interpolation, decimation, oversampling DSP systems, sample rate converters, and deltasigma quantizers. We discuss the use of oversampling for alleviating the need for high quality analog prefilters and postfilters. We present several practical design examples of interpolation filters, including polyphase and multistage designs. We consider the design of sample rate converters and study the operation of oversampled deltasigma quantizers by simulation. This material is too advanced for juniors but not seniors. All undergraduates, however, have a strong interest in it because of its use in digital audio systems such as CD and DAT players. The Appendix has four parts: (a) a review section on random signals; (b) a discussion of random number generators, including uniform, Gaussian, low frequency, and 1/f noise generators; (c) C functions for performing the complex arithmetic in the DFT routines; (d) listings of MATLAB functions.
xvi
PREFACE
Paths Several course paths are possible through the text depending on the desired level of presentation. For example, in the 14week junior course at Rutgers we cover Sections 1.1–1.4, 2.1–2.4, Chapters 3–7, Sections 8.1–8.2, Chapter 9, and Sections 10.1–10.2 and 11.1–11.4. One may omit certain of these sections and/or add others depending on the available time and student interest and background. In a second DSP course at the senior year, one may add Sections 1.5–1.7, 2.5, 8.3, 11.5–11.6, and Chapter 12. In a graduate course, the entire text can be covered comfortably in one semester.
Acknowledgments I am indebted to the many generations of students who tried earlier versions of the book and helped me refine it. In particular, I would like to thank Mr. Cem Saraydar for his thorough proofreading of the manuscript. I would like to thank my colleagues Drs. Zoran Gajic, Mark Kahrs, James Kaiser, Dino Lelic, Tom Marshall, Peter Meer, and Nader Moayeri for their feedback and encouragement. I am especially indebted to Dr. James Kaiser for enriching my classes over the past eight years with his inspiring yearly lectures on the Kaiser window. I would like to thank the book’s reviewers Drs. A. V. Oppenheim, J. A. Fleming, YC. Jenq, W. B. Mikhael, S. J. Reeves, A. Sekey, and J. Weitzen, whose comments helped improve the book. And I would like to thank Rutgers for providing me with a sabbatical leave to finish up the project. I welcome any feedback from readers—it may be sent to
[email protected] Finally, I would like to thank my wife Monica and son John for their love, patience, encouragement, and support.
Sophocles J. Orfanidis
1 Sampling and Reconstruction
1.1 Introduction Digital processing of analog signals proceeds in three stages: 1. The analog signal is digitized, that is, it is sampled and each sample quantized to a finite number of bits. This process is called A/D conversion. 2. The digitized samples are processed by a digital signal processor. 3. The resulting output samples may be converted back into analog form by an analog reconstructor (D/A conversion). A typical digital signal processing system is shown below.
analog input
sampler and quantizer
100111011 0110 . . .
digital input
digital signal processor
110010100 1101 . . .
digital output
analog reconstructor
analog output
The digital signal processor can be programmed to perform a variety of signal processing operations, such as filtering, spectrum estimation, and other DSP algorithms. Depending on the speed and computational requirements of the application, the digital signal processor may be realized by a general purpose computer, minicomputer, special purpose DSP chip, or other digital hardware dedicated to performing a particular signal processing task. The design and implementation of DSP algorithms will be considered in the rest of this text. In the first two chapters we discuss the two key concepts of sampling and quantization, which are prerequisites to every DSP operation.
1.2 Review of Analog Signals We begin by reviewing some pertinent topics from analog system theory. An analog signal is described by a function of time, say, x(t). The Fourier transform X(Ω) of x(t) is the frequency spectrum of the signal: 1
2
1. SAMPLING AND RECONSTRUCTION
∞
X(Ω)=
−∞
x(t)e−jΩt dt
(1.2.1)
where Ω is the radian frequency† in [radians/second]. The ordinary frequency f in [Hertz] or [cycles/sec] is related to Ω by
Ω = 2πf
(1.2.2)
The physical meaning of X(Ω) is brought out by the inverse Fourier transform, which expresses the arbitrary signal x(t) as a linear superposition of sinusoids of different frequencies:
x(t)=
∞
X(Ω)ejΩt
−∞
dΩ 2π
(1.2.3)
The relative importance of each sinusoidal component is given by the quantity X(Ω). The Laplace transform is defined by
X(s)=
∞
−∞
x(t)e−st dt
It reduces to the Fourier transform, Eq. (1.2.1), under the substitution s = jΩ. The splane pole/zero properties of transforms provide additional insight into the nature of signals. For example, a typical exponentially decaying sinusoid of the form
x(t)= e−α1 t ejΩ1 t u(t)= es1 t u(t)
t
where s1 = −α1 + jΩ1 , has Laplace transform
Im s X(s)=
s  plane
s1
1
s − s1
α1
jΩ1 0
Re s
with a pole at s = s1 , which lies in the lefthand splane. Next, consider the response of a linear system to an input signal x(t):
x(t) input
linear system h(t)
y(t) output
† We use the notation Ω to denote the physical frequency in units of [radians/sec], and reserve the notation ω to denote digital frequency in [radians/sample].
3
1.2. REVIEW OF ANALOG SIGNALS
The system is characterized completely by the impulse response function h(t). The output y(t) is obtained in the time domain by convolution:
y(t)=
∞
−∞
h(t − t )x(t ) dt
or, in the frequency domain by multiplication:
Y(Ω)= H(Ω)X(Ω)
(1.2.4)
where H(Ω) is the frequency response of the system, defined as the Fourier transform of the impulse response h(t):
H(Ω)=
∞
−∞
h(t)e−jΩt dt
(1.2.5)
The steadystate sinusoidal response of the filter, defined as its response to sinusoidal inputs, is summarized below:
x(t) = e
jΩt
linear system H(Ω)
sinusoid in
y(t) = H(Ω) e
jΩt
sinusoid out
This figure illustrates the filtering action of linear filters, that is, a given frequency component Ω is attenuated (or, magnified) by an amount H(Ω) by the filter. More precisely, an input sinusoid of frequency Ω will reappear at the output modified in magnitude by a factor H(Ω) and shifted in phase by an amount arg H(Ω):
x(t)= ejΩt
⇒
y(t)= H(Ω)ejΩt = H(Ω)ejΩt + jarg H(Ω)
By linear superposition, if the input consists of the sum of two sinusoids of frequencies Ω1 and Ω2 and relative amplitudes A1 and A2 ,
x(t)= A1 ejΩ1 t + A2 ejΩ2 t then, after filtering, the steadystate output will be
y(t)= A1 H(Ω1 )ejΩ1 t + A2 H(Ω2 )ejΩ2 t Notice how the filter changes the relative amplitudes of the sinusoids, but not their frequencies. The filtering effect may also be seen in the frequency domain using Eq. (1.2.4), as shown below:
X(Ω)
Y(Ω) A1
A2 A1 H(Ω1)
H(Ω)
Ω1
Ω2
A2 H(Ω2) Ω
Ω1
Ω2
Ω
4
1. SAMPLING AND RECONSTRUCTION
The input spectrum X(Ω) consists of two sharp spectral lines at frequencies Ω1 and Ω2 , as can be seen by taking the Fourier transform of x(t):
X(Ω)= 2πA1 δ(Ω − Ω1 )+2πA2 δ(Ω − Ω2 ) The corresponding output spectrum Y(Ω) is obtained from Eq. (1.2.4):
Y(Ω) = H(Ω)X(Ω)= H(Ω) 2πA1 δ(Ω − Ω1 )+2πA2 δ(Ω − Ω2 ) = 2πA1 H(Ω1 )δ(Ω − Ω1 )+2πA2 H(Ω2 )δ(Ω − Ω2 )
What makes the subject of linear filtering useful is that the designer has complete control over the shape of the frequency response H(Ω) of the filter. For example, if the sinusoidal component Ω1 represents a desired signal and Ω2 an unwanted interference, then a filter may be designed that lets Ω1 pass through, while at the same time it filters out the Ω2 component. Such a filter must have H(Ω1 )= 1 and H(Ω2 )= 0.
1.3 Sampling Theorem Next, we study the sampling process, illustrated in Fig. 1.3.1, where the analog signal x(t) is periodically measured every T seconds. Thus, time is discretized in units of the sampling interval T:
t = nT,
n = 0, 1, 2, . . .
Considering the resulting stream of samples as an analog signal, we observe that the sampling process represents a very drastic chopping operation on the original signal x(t), and therefore, it will introduce a lot of spurious highfrequency components into the frequency spectrum. Thus, for system design purposes, two questions must be answered: 1. What is the effect of sampling on the original frequency spectrum? 2. How should one choose the sampling interval T? We will try to answer these questions intuitively, and then more formally using Fourier transforms. We will see that although the sampling process generates high frequency components, these components appear in a very regular fashion, that is, every frequency component of the original signal is periodically replicated over the entire frequency axis, with period given by the sampling rate:
fs =
1
T
(1.3.1)
This replication property will be justified first for simple sinusoidal signals and then for arbitrary signals. Consider, for example, a single sinusoid x(t)= e2πjf t of frequency f . Before sampling, its spectrum consists of a single sharp spectral line at f . But after sampling, the spectrum of the sampled sinusoid x(nT)= e2πjf nT will be the periodic replication of the original spectral line at intervals of fs , as shown in Fig. 1.3.2.
5
1.3. SAMPLING THEOREM
ideal sampler analog signal
x(t)
x(nT)
sampled signal
T x(t)
x(nT) T
t
0 T 2T . . . nT
t
Fig. 1.3.1 Ideal sampler.
frequency f . . .
. . . f3fs
f2fs
ffs
f
f+fs
f+2fs
f+3fs
Fig. 1.3.2 Spectrum replication caused by sampling.
Note also that starting with the replicated spectrum of the sampled signal, one cannot tell uniquely what the original frequency was. It could be any one of the replicated frequencies, namely, f = f + mfs , m = 0, ±1, ±2, . . . . That is so because any one of them has the same periodic replication when sampled. This potential confusion of the original frequency with another is known as aliasing and can be avoided if one satisfies the conditions of the sampling theorem. The sampling theorem provides a quantitative answer to the question of how to choose the sampling time interval T. Clearly, T must be small enough so that signal variations that occur between samples are not lost. But how small is small enough? It would be very impractical to choose T too small because then there would be too many samples to be processed. This is illustrated in Fig. 1.3.3, where T is small enough to resolve the details of signal 1, but is unnecessarily small for signal 2.
signal 1 signal 2 T
t Fig. 1.3.3 Signal 2 is oversampled.
Another way to say the same thing is in terms of the sampling rate fs , which is
6
1. SAMPLING AND RECONSTRUCTION
measured in units of [samples/sec] or [Hertz] and represents the “density” of samples per unit time. Thus, a rapidly varying signal must be sampled at a high sampling rate fs , whereas a slowly varying signal may be sampled at a lower rate.
1.3.1 Sampling Theorem A more quantitative criterion is provided by the sampling theorem which states that for accurate representation of a signal x(t) by its time samples x(nT), two conditions must be met: 1. The signal x(t) must be bandlimited, that is, its frequency spectrum must be limited to contain frequencies up to some maximum frequency, say fmax , and no frequencies beyond that. A typical bandlimited spectrum is shown in Fig. 1.3.4. 2. The sampling rate fs must be chosen to be at least twice the maximum frequency fmax , that is,
fs ≥ 2fmax or, in terms of the sampling time interval: T ≤
(1.3.2) 1 . 2fmax
X(f)
fmax
0
f fmax
Fig. 1.3.4 Typical bandlimited spectrum.
The minimum sampling rate allowed by the sampling theorem, that is, fs = 2fmax , is called the Nyquist rate. For arbitrary values of fs , the quantity fs /2 is called the Nyquist frequency or folding frequency. It defines the endpoints of the Nyquist frequency interval:
fs fs − , = Nyquist Interval 2
2
The Nyquist frequency fs /2 also defines the cutoff frequencies of the lowpass analog prefilters and postfilters that are required in DSP operations. The values of fmax and fs depend on the application. Typical sampling rates for some common DSP applications are shown in the following table.
7
1.3. SAMPLING THEOREM
application
fmax
fs
geophysical biomedical mechanical speech audio video
500 Hz 1 kHz 2 kHz 4 kHz 20 kHz 4 MHz
1 kHz 2 kHz 4 kHz 8 kHz 40 kHz 8 MHz
1.3.2 Antialiasing Prefilters The practical implications of the sampling theorem are quite important. Since most signals are not bandlimited, they must be made so by lowpass filtering before sampling. In order to sample a signal at a desired rate fs and satisfy the conditions of the sampling theorem, the signal must be prefiltered by a lowpass analog filter, known as an antialiasing prefilter. The cutoff frequency of the prefilter, fmax , must be taken to be at most equal to the Nyquist frequency fs /2, that is, fmax ≤ fs /2. This operation is shown in Fig. 1.3.5. The output of the analog prefilter will then be bandlimited to maximum frequency fmax and may be sampled properly at the desired rate fs . The spectrum replication caused by the sampling process can also be seen in Fig. 1.3.5. It will be discussed in detail in Section 1.5. input spectrum
prefiltered spectrum
replicated spectrum
prefilter
f
f
xin(t) analog signal
f
fs /2 0 fs /2
0
analog lowpass prefilter cutoff fmax = fs /2
x(t) bandlimited signal
fs sampler and quantizer
0
x(nT) digital signal
fs to DSP
rate fs
Fig. 1.3.5 Antialiasing prefilter.
It should be emphasized that the rate fs must be chosen to be high enough so that, after the prefiltering operation, the surviving signal spectrum within the Nyquist interval [−fs /2, fs /2] contains all the significant frequency components for the application at hand. Example 1.3.1: In a hifi digital audio application, we wish to digitize a music piece using a sampling rate of 40 kHz. Thus, the piece must be prefiltered to contain frequencies up to 20 kHz. After the prefiltering operation, the resulting spectrum of frequencies is more than adequate for this application because the human ear can hear frequencies only up to 20 kHz.
8
1. SAMPLING AND RECONSTRUCTION
Example 1.3.2: Similarly, the spectrum of speech prefiltered to about 4 kHz results in very intelligible speech. Therefore, in digital speech applications it is adequate to use sampling rates of about 8 kHz and prefilter the speech waveform to about 4 kHz.
What happens if we do not sample in accordance with the sampling theorem? If we undersample, we may be missing important time variations between sampling instants and may arrive at the erroneous conclusion that the samples represent a signal which is smoother than it actually is. In other words, we will be confusing the true frequency content of the signal with a lower frequency content. Such confusion of signals is called aliasing and is depicted in Fig. 1.3.6. true signal
aliased signal
T 0
T 2T 3T 4T 5T 6T 7T 8T 9T 10T
t
Fig. 1.3.6 Aliasing in the time domain.
1.3.3 Hardware Limits Next, we consider the restrictions imposed on the choice of the sampling rate fs by the hardware. The sampling theorem provides a lower bound on the allowed values of fs . The hardware used in the application imposes an upper bound. In realtime applications, each input sample must be acquired, quantized, and processed by the DSP, and the output sample converted back into analog format. Many of these operations can be pipelined to reduce the total processing time. For example, as the DSP is processing the present sample, the D/A may be converting the previous output sample, while the A/D may be acquiring the next input sample. In any case, there is a total processing or computation time, say Tproc seconds, required for each sample. The time interval T between input samples must be greater than Tproc ; otherwise, the processor would not be able to keep up with the incoming samples. Thus,
T ≥ Tproc or, expressed in terms of the computation or processing rate, fproc = 1/Tproc , we obtain the upper bound fs ≤ fproc , which combined with Eq. (1.3.2) restricts the choice of fs to the range: 2fmax ≤ fs ≤ fproc In succeeding sections we will discuss the phenomenon of aliasing in more detail, provide a quantitative proof of the sampling theorem, discuss the spectrum replication
9
1.4. SAMPLING OF SINUSOIDS
property, and consider the issues of practical sampling and reconstruction and their effect on the overall quality of a digital signal processing system. Quantization will be considered later on.
1.4 Sampling of Sinusoids The two conditions of the sampling theorem, namely, that x(t) be bandlimited and the requirement fs ≥ 2fmax , can be derived intuitively by considering the sampling of sinusoidal signals only. Figure 1.4.1 shows a sinusoid of frequency f ,
x(t)= cos(2πf t) that has been sampled at the three rates: fs = 8f , fs = 4f , and fs = 2f . These rates correspond to taking 8, 4, and 2 samples in each cycle of the sinusoid.
fs = 8f
fs = 4f
fs = 2f
Fig. 1.4.1 Sinusoid sampled at rates fs = 8f , 4f , 2f .
Simple inspection of these figures leads to the conclusion that the minimum acceptable number of samples per cycle is two. The representation of a sinusoid by two samples per cycle is hardly adequate,† but at least it does incorporate the basic updown nature of the sinusoid. The number of samples per cycle is given by the quantity fs /f :
fs samples/sec samples = = f cycles/sec cycle Thus, to sample a single sinusoid properly, we must require
fs ≥ 2 samples/cycle f
⇒
fs ≥ 2f
(1.4.1)
Next, consider the case of an arbitrary signal x(t). According to the inverse Fourier transform of Eq. (1.2.3), x(t) can be expressed as a linear combination of sinusoids. Proper sampling of x(t) will be achieved only if every sinusoidal component of x(t) is properly sampled. This requires that the signal x(t) be bandlimited. Otherwise, it would contain sinusoidal components of arbitrarily high frequency f , and to sample those accurately, we would need, by Eq. (1.4.1), arbitrarily high rates fs . If the signal is bandlimited to † It also depends on the phase of the sinusoid. For example, sampling at the zero crossings instead of at the peaks, would result in zero values for the samples.
10
1. SAMPLING AND RECONSTRUCTION
some maximum frequency fmax , then by choosing fs ≥ 2fmax , we are accurately sampling the fastestvarying component of x(t), and thus a fortiori, all the slower ones. As an example, consider the special case:
x(t)= A1 cos(2πf1 t)+A2 cos(2πf2 t)+ · · · + Amax cos(2πfmax t) where fi are listed in increasing order. Then, the conditions 2f1 ≤ 2f2 ≤ · · · ≤ 2fmax ≤ fs imply that every component of x(t), and hence x(t) itself, is properly sampled.
1.4.1 Analog Reconstruction and Aliasing Next, we discuss the aliasing effects that result if one violates the sampling theorem conditions (1.3.2) or (1.4.1). Consider the complex version of a sinusoid:
x(t)= ejΩt = e2πjf t and its sampled version obtained by setting t = nT,
x(nT)= ejΩTn = e2πjf Tn Define also the following family of sinusoids, for m = 0, ±1, ±2, . . . ,
xm (t)= e2πj(f + mfs )t and their sampled versions,
xm (nT)= e2πj(f + mfs )Tn Using the property fs T = 1 and the trigonometric identity,
e2πjmfs Tn = e2πjmn = 1 we find that, although the signals xm (t) are different from each other, their sampled values are the same; indeed,
xm (nT)= e2πj(f + mfs )Tn = e2πjf Tn e2πjmfs Tn = e2πjf Tn = x(nT) In terms of their sampled values, the signals xm (t) are indistinguishable, or aliased. Knowledge of the sample values x(nT)= xm (nT) is not enough to determine which among them was the original signal that was sampled. It could have been any one of the xm (t). In other words, the set of frequencies,
f , f ± fs , f ± 2fs , . . . , f ± mfs , . . .
(1.4.2)
are equivalent to each other. The effect of sampling was to replace the original frequency f with the replicated set (1.4.2). This is the intuitive explanation of the spectrum
11
1.4. SAMPLING OF SINUSOIDS
ideal sampler x(t)
T
ideal reconstructor xa(t)
x(nT) f
analog signal
sampled signal rate fs
fs /2 0 fs /2
analog signal
lowpass filter cutoff = fs /2
Fig. 1.4.2 Ideal reconstructor as a lowpass filter.
replication property depicted in Fig. 1.3.2. A more mathematical explanation will be given later using Fourier transforms. Given that the sample values x(nT) do not uniquely determine the analog signal they came from, the question arises: What analog signal would result if these samples were fed into an analog reconstructor, as shown in Fig. 1.4.2? We will see later that an ideal analog reconstructor extracts from a sampled signal all the frequency components that lie within the Nyquist interval [−fs /2, fs /2] and removes all frequencies outside that interval. In other words, an ideal reconstructor acts as a lowpass filter with cutoff frequency equal to the Nyquist frequency fs /2. Among the frequencies in the replicated set (1.4.2), there is a unique one that lies within the Nyquist interval.† It is obtained by reducing the original f modulofs , that is, adding to or subtracting from f enough multiples of fs until it lies within the symmetric Nyquist interval [−fs /2, fs /2]. We denote this operation by‡
fa = f mod(fs )
(1.4.3)
This is the frequency, in the replicated set (1.4.2), that will be extracted by the analog reconstructor. Therefore, the reconstructed sinusoid will be:
xa (t)= e2πjfa t It is easy to see that fa = f only if f lies within the Nyquist interval, that is, only if f  ≤ fs /2, which is equivalent to the sampling theorem requirement. If f lies outside the Nyquist interval, that is, f  > fs /2, violating the sampling theorem condition, then the “aliased” frequency fa will be different from f and the reconstructed analog signal xa (t) will be different from x(t), even though the two agree at the sampling times, xa (nT)= x(nT). It is instructive also to plot in Fig. 1.4.3 the aliased frequency fa = f mod(fs ) versus the true frequency f . Observe how the straight line ftrue = f is brought down in segments by parallel translation of the Nyquist periods by multiples of fs . In summary, potential aliasing effects that can arise at the reconstruction phase of DSP operations can be avoided if one makes sure that all frequency components of the signal to be sampled satisfy the sampling theorem condition, f  ≤ fs /2, that is, all † The
only exception is when it falls exactly on the left or right edge of the interval, f = ±fs /2. differs slightly from a true modulo operation; the latter would bring f into the rightsided Nyquist interval [0, fs ]. ‡ This
12
1. SAMPLING AND RECONSTRUCTION
ft
ru e
=
f
fa = f mod( fs)
fs /2 fs fs /2
0
fs /2 fs
2fs
f
fs /2
Fig. 1.4.3 f mod(fs ) versus f .
frequency components lie within the Nyquist interval. This is ensured by the lowpass antialiasing prefilter, which removes all frequencies beyond the Nyquist frequency fs /2, as shown in Fig. 1.3.5. Example 1.4.1: Consider a sinusoid of frequency f = 10 Hz sampled at a rate of fs = 12 Hz. The sampled signal will contain all the replicated frequencies 10 + m12 Hz, m = 0, ±1, ±2, . . . , or,
. . . , −26, −14, −2, 10, 22, 34, 46, . . . and among these only fa = 10 mod(12)= 10 − 12 = −2 Hz lies within the Nyquist interval [−6, 6] Hz. This sinusoid will appear at the output of a reconstructor as a −2 Hz sinusoid instead of a 10 Hz one.
On the other hand, had we sampled at a proper rate, that is, greater than 2f = 20 Hz, say at fs = 22 Hz, then no aliasing would result because the given frequency of 10 Hz already lies within the corresponding Nyquist interval of [−11, 11] Hz.
Example 1.4.2: Suppose a music piece is sampled at rate of 40 kHz without using a prefilter with cutoff of 20 kHz. Then, inaudible components having frequencies greater than 20 kHz can be aliased into the Nyquist interval [−20, 20] distorting the true frequency components in that interval. For example, all components in the inaudible frequency range 20 ≤ f ≤ 60 kHz will be aliased with −20 = 20 − 40 ≤ f − fs ≤ 60 − 40 = 20 kHz, which are audible.
Example 1.4.3: The following five signals, where t is in seconds, are sampled at a rate of 4 Hz: − sin(14πt),
− sin(6πt),
sin(2πt),
sin(10πt),
sin(18πt)
Show that they are all aliased with each other in the sense that their sampled values are the same.
13
1.4. SAMPLING OF SINUSOIDS Solution: The frequencies of the five sinusoids are: −7,
−3,
1,
5,
9
Hz
They differ from each other by multiples of fs = 4 Hz. Their sampled spectra will be indistinguishable from each other because each of these frequencies has the same periodic replication in multiples of 4 Hz. Writing the five frequencies compactly:
fm = 1 + 4m,
m = −2, −1, 0, 1, 2
we can express the five sinusoids as:
xm (t)= sin(2πfm t)= sin(2π(1 + 4m)t),
m = −2, −1, 0, 1, 2
Replacing t = nT = n/fs = n/4 sec, we obtain the sampled signals:
xm (nT) = sin(2π(1 + 4m)nT)= sin(2π(1 + 4m)n/4) = sin(2πn/4 + 2πmn)= sin(2πn/4) which are the same, independently of m. The following figure shows the five sinusoids over the interval 0 ≤ t ≤ 1 sec.
t 1
0
They all intersect at the sampling time instants t = nT = n/4 sec. We will reconsider this example in terms of rotating wheels in Section 1.4.2.
Example 1.4.4: Let x(t) be the sum of sinusoidal signals x(t)= 4 + 3 cos(πt)+2 cos(2πt)+ cos(3πt) where t is in milliseconds. Determine the minimum sampling rate that will not cause any aliasing effects, that is, the Nyquist rate. To observe such aliasing effects, suppose this signal is sampled at half its Nyquist rate. Determine the signal xa (t) that would be aliased with x(t).
Solution: The frequencies of the four terms are: f1 = 0, f2 = 0.5 kHz, f3 = 1 kHz, and f4 = 1.5 kHz (they are in kHz because t is in msec). Thus, fmax = f4 = 1.5 kHz and the Nyquist rate will be 2fmax = 3 kHz. If x(t) is now sampled at half this rate, that is, at fs = 1.5 kHz, then aliasing will occur. The corresponding Nyquist interval is [−0.75, 0.75] kHz. The frequencies f1 and f2 are already in it, and hence they are not aliased, in the sense that f1a = f1 and f2a = f2 . But f3 and f4 lie outside the Nyquist interval and they will be aliased with
14
1. SAMPLING AND RECONSTRUCTION
f3a = f3 mod(fs )= 1 mod(1.5)= 1 − 1.5 = −0.5 kHz f4a = f4 mod(fs )= 1.5 mod(1.5)= 1.5 − 1.5 = 0 kHz The aliased signal xa (t) is obtained from x(t) by replacing f1 , f2 , f3 , f4 by f1a , f2a , f3a , f4a . Thus, the signal
x(t)= 4 cos(2πf1 t)+3 cos(2πf2 t)+2 cos(2πf3 t)+ cos(2πf4 t) will be aliased with
xa (t) = 4 cos(2πf1a t)+3 cos(2πf2a t)+2 cos(2πf3a t)+ cos(2πf4a t) = 4 + 3 cos(πt)+2 cos(−πt)+ cos(0) = 5 + 5 cos(πt) The signals x(t) and xa (t) are shown below. Note that they agree only at their sampled values, that is, xa (nT)= x(nT). The aliased signal xa (t) is smoother, that is, it has lower frequency content than x(t) because its spectrum lies entirely within the Nyquist interval, as shown below:
x(t)
0
T
xa(t)
2T 3T 4T 5T
6T
7T
8T 9T
t
The form of xa (t) can also be derived in the frequency domain by replicating the spectrum of x(t) at intervals of fs = 1.5 kHz, and then extracting whatever part of the spectrum lies within the Nyquist interval. The following figure shows this procedure.
ideal reconstructor
4 3/2 2/2
2/2
1/2
1.5
3/2 2/2 1/2
1
0.75
0.5
2/2 1/2
1/2
0 Nyquist Interval
f 0.5
0.75
1
1.5 kHz
Each spectral line of x(t) is replicated in the fashion of Fig. 1.3.2. The two spectral lines of strength 1/2 at f4 = ±1.5 kHz replicate onto f = 0 and the amplitudes add up to give a total amplitude of (4 + 1/2 + 1/2)= 5. Similarly, the two spectral lines of strength 2/2 at
15
1.4. SAMPLING OF SINUSOIDS
f3 = ±1 kHz replicate onto f = ∓0.5 kHz and the amplitudes add to give (3/2 + 2/2)= 2.5 at f = ±0.5 kHz. Thus, the ideal reconstructor will extract f1 = 0 of strength 5 and f2 = ±0.5 of equal strengths 2.5, which recombine to give: 5 + 2.5e2πj0.5t + 2.5e−2πj0.5t = 5 + 5 cos(πt) This example shows how aliasing can distort irreversibly the amplitudes of the original frequency components within the Nyquist interval.
Example 1.4.5: The signal x(t)= sin(πt)+4 sin(3πt)cos(2πt) where t is in msec, is sampled at a rate of 3 kHz. Determine the signal xa (t) aliased with x(t). Then, determine two other signals x1 (t) and x2 (t) that are aliased with the same xa (t), that is, such that x1 (nT)= x2 (nT)= xa (nT).
Solution: To determine the frequency content of x(t), we must express it as a sum of sinusoids. Using the trigonometric identity 2 sin a cos b = sin(a + b)+ sin(a − b), we find: x(t)= sin(πt)+2 sin(3πt + 2πt)+ sin(3πt − 2πt) = 3 sin(πt)+2 sin(5πt)
Thus, the frequencies present in x(t) are f1 = 0.5 kHz and f2 = 2.5 kHz. The first already lies in the Nyquist interval [−1.5, 1, 5] kHz so that f1a = f1 . The second lies outside and can be reduced mod fs to give f2a = f2 mod(fs )= 2.5 mod(3)= 2.5 − 3 = −0.5. Thus, the given signal will “appear” as:
xa (t) = 3 sin(2πf1a t)+2 sin(2πf2a t) = 3 sin(πt)+2 sin(−πt)= 3 sin(πt)−2 sin(πt) = sin(πt) To find two other signals that are aliased with xa (t), we may shift the original frequencies f1 , f2 by multiples of fs . For example,
x1 (t) = 3 sin(7πt)+2 sin(5πt) x2 (t) = 3 sin(13πt)+2 sin(11πt) where we replaced {f1 , f2 } by {f1 + fs , f2 } = {3.5, 2.5} for x1 (t), and by {f1 + 2fs , f2 + fs } =
{6.5, 5.5} for x2 (t).
Example 1.4.6: Consider a periodic square wave with period T0 = 1 sec, defined within its basic period 0 ≤ t ≤ 1 by
x(t)=
1, −1, 0,
for 0 < t < 0.5 for 0.5 < t < 1 for t = 0, 0.5, 1
1
t 0.5
0
1
1
where t is in seconds. The square wave is sampled at rate fs and the resulting samples are reconstructed by an ideal reconstructor as in Fig. 1.4.2. Determine the signal xa (t) that will appear at the output of the reconstructor for the two cases fs = 4 Hz and fs = 8 Hz. Verify that xa (t) and x(t) agree at the sampling times t = nT.
16
1. SAMPLING AND RECONSTRUCTION
Solution: The Fourier series expansion of the square wave contains odd harmonics at frequencies fm = m/T0 = m Hz, m = 1, 3, 5, 7, . . . . It is given by x(t) =
bm sin(2πmt)=
m=1,3,5,...
(1.4.4)
= b1 sin(2πt)+b3 sin(6πt)+b5 sin(10πt)+ · · · where bm = 4/(πm), m = 1, 3, 5, . . . . Because of the presence of an infinite number of harmonics, the square wave is not bandlimited and, thus, cannot be sampled properly at any rate. For the rate fs = 4 Hz, only the f1 = 1 harmonic lies within the Nyquist interval [−2, 2] Hz. For the rate fs = 8 Hz, only f1 = 1 and f3 = 3 Hz lie in [−4, 4] Hz. The following table shows the true frequencies and the corresponding aliased frequencies in the two cases:
fs
f
1
3
5
7
9
11
13
15
···
4 Hz
f mod(4) f mod(8)
1
−1
1
−1 −1
1
−1
1
−1 −1
··· ···
8 Hz
1
3
−3
1
3
−3
Note the repeated patterns of aliased frequencies in the two cases. If a harmonic is aliased with ±f1 = ±1, then the corresponding term in Eq. (1.4.4) will appear (at the output of the reconstructor) as sin(±2πf1 t)= ± sin(2πt). And, if it is aliased with ±f3 = ±3, the term will appear as sin(±2πf3 t)= ± sin(6πt). Thus, for fs = 4, the aliased signal will be
xa (t) = b1 sin(2πt)−b3 sin(2πt)+b5 sin(2πt)−b7 sin(2πt)+ · · · = (b1 − b3 + b5 − b7 + b9 − b11 + · · · )sin(2πt) = A sin(2πt) where
A=
∞ ∞ 4 1 1 − b1+4k − b3+4k = π 1 + 4 k 3 + 4 k k=0 k=0
(1.4.5)
Similarly, for fs = 8, grouping together the 1 and 3 Hz terms, we find the aliased signal
xa (t) = (b1 − b7 + b9 − b15 + · · · )sin(2πt)+ + (b3 − b5 + b11 − b13 + · · · )sin(6πt) = B sin(2πt)+C sin(6πt) where
B=
∞ ∞ 1 4 1 − b1+8k − b7+8k = π k=0 1 + 8k 7 + 8k k=0
∞ ∞ 1 1 4 C= − b3+8k − b5+8k = π k=0 3 + 8k 5 + 8k k=0
(1.4.6)
17
1.4. SAMPLING OF SINUSOIDS
There are two ways to determine the aliased coefficients A, B, C. One is to demand that the sampled signals xa (nT) and x(nT) agree. For example, in the first case we have T = 1/fs = 1/4, and therefore, xa (nT)= A sin(2πn/4)= A sin(πn/2). The condition xa (nT)= x(nT) evaluated at n = 1 implies A = 1. The following figure shows x(t), xa (t), and their samples:
t 1/4
0
1/2
1
Similarly, in the second case we have T = 1/fs = 1/8, resulting in the sampled aliased signal xa (nT)= B sin(πn/4)+C sin(3πn/4). Demanding the condition xa (nT)= x(nT) at n = 1, 2 gives the two equations
B+C=
B sin(π/4)+C sin(3π/4)= 1 ⇒
B sin(π/2)+C sin(3π/2)= 1 √
√
2
B−C=1 √
which can be solved to give B = ( 2 + 1)/2 and C = ( 2 − 1)/2. The following figure shows x(t), xa (t), and their samples:
t 0
1/8
1/2
1
The second way of determining A, B, C is by evaluating the infinite sums of Eqs. (1.4.5) and (1.4.6). All three are special cases of the more general sum:
b(m, M)≡
∞ 4
π
k=0
1
m + Mk
−
1
M − m + Mk
with M > m > 0. It can be computed as follows. Write 1
m + Mk
−
1
M − m + Mk
=
∞ 0
e−mx − e−(M−m)x e−Mkx dx
then, interchange summation and integration and use the geometric series sum (for x > 0) ∞
k=0
to get
e−Mkx =
1 1 − e−Mx
18
1. SAMPLING AND RECONSTRUCTION
b(m, M)=
∞
4
π
0
e−mx − e−(M−m)x dx 1 − e−Mx
Looking this integral up in a table of integrals [30], we find:
b(m, M)=
4
M
cot
mπ M
The desired coefficients A, B, C are then:
A = b(1, 4)= cot B = b(1, 8)= C = b(3, 8)=
π
=1
4
π 1 cot = 2 8
√
3π 1 cot = 2 8
2+1 2
√
2−1 2
The above results generalize to any sampling rate fs = M Hz, where M is a multiple of 4. For example, if fs = 12, we obtain
xa (t)= b(1, 12)sin(2πt)+b(3, 12)sin(6πt)+b(5, 12)sin(10πt) and more generally
xa (t)=
b(m, M)sin(2πmt)
m=1,3,...,(M/2)−1
The coefficients b(m, M) tend to the original Fourier series coefficients bm in the continuoustime limit, M → ∞. Indeed, using the approximation cot(x)≈ 1/x, valid for small x, we obtain the limit lim b(m, M)=
M→∞
4
M
·
1
πm/M
=
4
πm
= bm
The table below shows the successive improvement of the values of the aliased harmonic coefficients as the sampling rate increases: coefficients
4 Hz
8 Hz
12 Hz
16 Hz
∞
b1 b3 b5 b7
1
1.207
1.244
1.257
1.273
–
0.207
0.333
0.374
0.424
–
–
0.089
0.167
0.255
–
–
–
0.050
0.182
In this example, the sampling rates of 4 and 8 Hz, and any multiple of 4, were chosen so that all the harmonics outside the Nyquist intervals got aliased onto harmonics within the intervals. For other values of fs , such as fs = 13 Hz, it is possible for the aliased harmonics to fall on nonharmonic frequencies within the Nyquist interval; thus, changing not only the relative balance of the Nyquist interval harmonics, but also the frequency values.
19
1.4. SAMPLING OF SINUSOIDS
When we develop DFT algorithms, we will see that the aliased Fourier series coefficients for the above type of problem can be obtained by performing a DFT, provided that the periodic analog signal remains a periodic discretetime signal after sampling. This requires that the sampling frequency fs be an integral multiple of the fundamental harmonic of the given signal, that is, fs = Nf1 . In such a case, the aliased coefficients can be obtained by an Npoint DFT of the first N time samples x(nT), n = 0, 1, . . . , N− 1 of the analog signal. See Section 9.7. Example 1.4.7: A sound wave has the form: x(t) = 2A cos(10πt)+2B cos(30πt) + 2C cos(50πt)+2D cos(60πt)+2E cos(90πt)+2F cos(125πt) where t is in milliseconds. What is the frequency content of this signal? Which parts of it are audible and why? This signal is prefiltered by an analog prefilter H(f ). Then, the output y(t) of the prefilter is sampled at a rate of 40 kHz and immediately reconstructed by an ideal analog reconstructor, resulting into the final analog output ya (t), as shown below:
x(t) analog
prefilter
H(f)
y(t) analog
40 kHz sampler
y(nT) digital
analog reconstructor
ya(t) analog
Determine the output signals y(t) and ya (t) in the following cases: (a) When there is no prefilter, that is, H(f )= 1 for all f . (b) When H(f ) is the ideal prefilter with cutoff fs /2 = 20 kHz. (c) When H(f ) is a practical prefilter with specifications as shown below:
H(f)
Analog Prefilter
1
(0 dB)
60 dB/octave (60 dB)
f 0
20
40
60
80
kHz
That is, it has a flat passband over the 20 kHz audio range and drops monotonically at a rate of 60 dB per octave beyond 20 kHz. Thus, at 40 kHz, which is an octave away, the filter’s response will be down by 60 dB. For the purposes of this problem, the filter’s phase response may be ignored in determining the output y(t). Does this filter help in removing the aliased components? What happens if the filter’s attenuation rate is reduced to 30 dB/octave?
Solution: The six terms of x(t) have frequencies:
20
1. SAMPLING AND RECONSTRUCTION
fA = 5 kHz
fC = 25 kHz
fE = 45 kHz
fB = 15 kHz
fD = 30 kHz
fF = 62.5 kHz
Only fA and fB are audible; the rest are inaudible. Our ears filter out all frequencies beyond 20 kHz, and we hear x(t) as though it were the signal:
x1 (t)= 2A cos(10πt)+2B cos(30πt) Each term of x(t) is represented in the frequency domain by two peaks at positive and negative frequencies, for example, the Aterm has spectrum: 2A cos(2πfA t)= A e2πjfA t + A e−2πjfA t
−→
A δ(f − fA )+A δ(f + fA )
Therefore, the spectrum of the input x(t) will be as shown below:
ideal prefilter F
E
DC
B
A
A
B
CD
E
F
f 70 60 50 40 30 20 10
0
10
20 30 40 50 60 70 kHz
Nyquist interval The sampling process will replicate each of these peaks at multiples of fs = 40 kHz. The four terms C, D, E, F lie outside the [−20, 20] kHz Nyquist interval and therefore will be aliased with the following frequencies inside the interval:
fC = 25
⇒
fC, a = fC mod (fs )= fC − fs = 25 − 40 = −15
fD = 30
⇒
fD, a = fD mod (fs )= fD − fs = 30 − 40 = −10
fE = 45
⇒
fE, a = fE mod (fs )= fE − fs = 45 − 40 = 5
fF = 62.5
⇒
fF, a = fF mod (fs )= fF − 2fs = 62.5 − 2 × 40 = −17.5
In case (a), if we do not use any prefilter at all, we will have y(t)= x(t) and the reconstructed signal will be:
ya (t) = 2A cos(10πt)+2B cos(30πt) + 2C cos(−2π15t)+2D cos(−2π10t) + 2E cos(2π5t)+2F cos(−2π17.5t) = 2(A + E)cos(10πt)+2(B + C)cos(30πt) + 2D cos(20πt)+2F cos(35πt)
21
1.4. SAMPLING OF SINUSOIDS where we replaced each outofband frequency with its aliased self, for example, 2C cos(2πfC t)→ 2C cos(2πfC,a t)
The relative amplitudes of the 5 and 15 kHz audible components have changed and, in addition, two new audible components at 10 and 17.5 kHz have been introduced. Thus, ya (t) will sound very different from x(t). In case (b), if an ideal prefilter with cutoff fs /2 = 20 kHz is used, then its output will be the same as the audible part of x(t), that is, y(t)= x1 (t). The filter’s effect on the input spectrum is to remove completely all components beyond the 20 kHz Nyquist frequency, as shown below:
ideal prefilter B
F
E
A
A
B
DC
CD
70 60 50 40 30 20 10
0
10
E
F
f
20 30 40 50 60 70 kHz
Nyquist interval Because the prefilter’s output contains no frequencies beyond the Nyquist frequency, there will be no aliasing and after reconstruction the output would sound the same as the input, ya (t)= y(t)= x1 (t). In case (c), if the practical prefilter H(f ) is used, then its output y(t) will be:
y(t) = 2AH(fA ) cos(10πt)+2BH(fB ) cos(30πt) + 2CH(fC ) cos(50πt)+2DH(fD ) cos(60πt)
(1.4.7)
+ 2EH(fE ) cos(90πt)+2FH(fF ) cos(125πt) This follows from the steadystate sinusoidal response of a filter applied to the individual sinusoidal terms of x(t), for example, the effect of H(f ) on A is: H
2A cos(2πfA t)−→ 2AH(fA ) cos 2πfA t + θ(fA )
where in Eq. (1.4.7) we ignored the phase response θ(fA )= arg H(fA ). The basic conclusions of this example are not affected by this simplification. Note that Eq. (1.4.7) applies also to cases (a) and (b). In case (a), we can replace:
H(fA ) = H(fB ) = H(fC ) = H(fD ) = H(fE ) = H(fF ) = 1 and in case (b):
H(fA ) = H(fB ) = 1,
H(fC ) = H(fD ) = H(fE ) = H(fF ) = 0
22
1. SAMPLING AND RECONSTRUCTION In case (c), because fA and fB are in the filter’s passband, we still have
H(fA ) = H(fB ) = 1 To determine H(fC ), H(fD ), H(fE ), H(fF ), we must find how many octaves† away the frequencies fC , fD , fE , fF are from the fs /2 = 20 kHz edge of the passband. These are given by:
log2
log2
log2
log2
fC fs /2
= log2
25 20
fD fs /2
= 0.322
= log2
30 20
fE fs /2
= 0.585
= log2
45 20
fF fs /2
= 1.170
= log2
62.5 20
= 1.644
and therefore, the corresponding filter attenuations will be: at fC :
60 dB/octave × 0.322 octaves = 19.3 dB
at fD :
60 dB/octave × 0.585 octaves = 35.1 dB
at fE :
60 dB/octave × 1.170 octaves = 70.1 dB
at fF :
60 dB/octave × 1.644 octaves = 98.6 dB
By definition, an amount of A dB attenuation corresponds to reducing H(f ) by a factor 10−A/20 . For example, the relative drop of H(f ) with respect to the edge of the passband H(fs /2) is A dB if:
H(f ) = 10−A/20 H(fs /2) Assuming that the passband has 0 dB normalization, H(fs /2) = 1, we find the following values for the filter responses:
H(fC ) = 10−19.3/20 =
1 9
H(fD ) = 10−35.1/20 =
1 57
H(fE ) = 10−70.1/20 =
1 3234
H(fF ) = 10−98.6/20 =
1 85114
It follows from Eq. (1.4.7) that the output y(t) of the prefilter will be: † The
number of octaves is the number of powers of two, that is, if f2 = 2ν f1 ⇒ ν = log2 (f2 /f1 ).
23
1.4. SAMPLING OF SINUSOIDS
y(t) = 2A cos(10πt)+2B cos(30πt) +
2C 2D cos(50πt)+ cos(60πt) 9 57
+
2F 2E cos(90πt)+ cos(125πt) 3234 85114
(1.4.8)
Its spectrum is shown below:
DC
A
B
A
B
E F
(19 dB) (35 dB) (70 dB) CD (98 dB) E F
f
70 60 50 40 30 20 10
0
10
20 30 40 50 60 70 kHz
Nyquist interval Notice how the inaudible outofband components have been attenuated by the prefilter, so that when they get aliased back into the Nyquist interval because of sampling, their distorting effect will be much less. The wrapping of frequencies into the Nyquist interval is the same as in case (a). Therefore, after sampling and reconstruction we will get:
ya (t) = 2 A + +
E 3234
cos(10πt)+2 B +
C 9
cos(30πt)
2F 2D cos(20πt)+ cos(35πt) 57 85114
Now, all aliased components have been reduced in magnitude. The component closest to the Nyquist frequency, namely fC , causes the most distortion because it does not get attenuated much by the filter. We will see in Section 1.5.3 that the prefilter’s rate of attenuation in dB/octave is related to the filter’s order N by α = 6N so that α = 60 dB/octave corresponds to 60 = 6N or N = 10. Therefore, the given filter is already a fairly complex analog filter. Decreasing the filter’s complexity to α = 30 dB/octave, corresponding to filter order N = 5, would reduce all the attenuations by half, that is, at fC :
30 dB/octave × 0.322 octaves = 9.7 dB
at fD :
30 dB/octave × 0.585 octaves = 17.6 dB
at fE :
30 dB/octave × 1.170 octaves = 35.1 dB
at fF :
30 dB/octave × 1.644 octaves = 49.3 dB
and, in absolute units:
24
1. SAMPLING AND RECONSTRUCTION
H(fC ) = 10−9.7/20 =
1 3
H(fD ) = 10−17.6/20 =
1 7 .5
H(fE ) = 10−35.1/20 =
1 57
H(fF ) = 10−49.3/20 =
1 292
Therefore, the resulting signal after reconstruction would be:
C E cos(10πt)+2 B + cos(30πt) ya (t) = 2 A + 57
3
2F 2D cos(35πt) + cos(20πt)+ 7.5 292
(1.4.9)
Now the C and D terms are not as small and aliasing would still be significant. The situation can be remedied by oversampling, as discussed in the next example.
Example 1.4.8: Oversampling can be used to reduce the attenuation requirements of the prefilter, and thus its order. Oversampling increases the gap between spectral replicas reducing aliasing and allowing less sharp cutoffs for the prefilter. For the previous example, if we oversample by a factor of 2, fs = 2 × 40 = 80 kHz, the new Nyquist interval will be [−40, 40] kHz. Only the fE = 45 kHz and fF = 62.5 kHz components lie outside this interval, and they will be aliased with
fE,a = fE − fs = 45 − 80 = −35 kHz fF,a = fF − fs = 62.5 − 80 = −17.5 kHz Only fF,a lies in the audio band and will cause distortions, unless we attenuate fF using a prefilter before it gets wrapped into the audio band. Without a prefilter, the reconstructed signal will be:
ya (t) = 2A cos(10πt)+2B cos(30πt) + 2C cos(50πt)+2D cos(60πt) + 2E cos(−2π35t)+2F cos(−2π17.5t) = 2A cos(10πt)+2B cos(30πt) + 2C cos(50πt)+2D cos(60πt)+2E cos(70πt)+2F cos(35πt) The audible components in ya (t) are:
y1 (t)= 2A cos(10πt)+2B cos(30πt)+2F cos(35πt) Thus, oversampling eliminated almost all the aliasing from the desired audio band. Note that two types of aliasing took place here, namely, the aliasing of the E component which
25
1.4. SAMPLING OF SINUSOIDS
remained outside the relevant audio band, and the aliasing of the F component which does represent distortion in the audio band. Of course, one would not want to feed the signal ya (t) into an amplifier/speaker system because the high frequencies beyond the audio band might damage the system or cause nonlinearities. (But even if they were filtered out, the F component would still be there.)
Example 1.4.9: Oversampling and Decimation. Example 1.4.8 assumed that sampling at 80 kHz could be maintained throughout the digital processing stages up to reconstruction. There are applications however, where the sampling rate must eventually be dropped down to its original value. This is the case, for example, in digital audio, where the rate must be reduced eventually to the standardized value of 44.1 kHz (for CDs) or 48 kHz (for DATs). When the sampling rate is dropped, one must make sure that aliasing will not be reintroduced. In our example, if the rate is reduced back to 40 kHz, the C and D components, which were inside the [−40, 40] kHz Nyquist interval with respect to the 80 kHz rate, would find themselves outside the [−20, 20] kHz Nyquist interval with respect to the 40 kHz rate, and therefore would be aliased inside that interval, as in Example 1.4.7. To prevent C and D, as well as E, from getting aliased into the audio band, one must remove them by a lowpass digital filter before the sampling rate is dropped to 40 kHz. Such a filter is called a digital decimation filter. The overall system is shown below.
x(t)
prefilter
y(t) 80 kHz sampler
H(f)
analog
80 kHz
80 kHz
digital filter
downsampler
40 kHz
ya(t)
reconstructor
analog
The downsampler in this diagram reduces the sampling rate from 80 down to 40 kHz by throwing away every other sample, thus, keeping only half the samples. This is equivalent to sampling at a 40 kHz rate. The input to the digital filter is the sampled spectrum of y(t), which is replicated at multiples of 80 kHz as shown below.
digital lowpass filter prefilter A
B
C D
F
DC EE
B F
A
A
B
C D
F
B
DC EE
A
F
f 0
10
20 30 40 50 60 70 80 90 100
120
140
160 kHz
We have also assumed that the 30 dB/octave prefilter is present. The output of the digital filter will have spectrum as shown below.
26
1. SAMPLING AND RECONSTRUCTION
digital lowpass filter A
B
B
F 0
10
(49 dB) C DE
EDC
F
A
A
B F
B
C DE
20 30 40 50 60 70 80 90 100
E DC
120
A
F
140
f 160 kHz
The digital filter operates at the oversampled rate of 80 kHz and acts as a lowpass filter within the [−40, 40] kHz Nyquist interval, with a cutoff of 20 kHz. Thus, it will remove the C, D, and E components, as well as any other component that lies between 20 ≤ f  ≤ 60 kHz. However, because the digital filter is periodic in f with period fs = 80 kHz, it cannot remove any components from the interval 60 ≤ f ≤ 100. Any components of the analog input y(t) that lie in that interval would be aliased into the interval 60 − 80 ≤ f − fs ≤ 100 − 80, which is the desired audio band −20 ≤ f − fs ≤ 20. This is what happened to the F component, as can be seen in the above figure. The frequency components of y(t) in 60 ≤ f  ≤ 100 can be removed only by a prefilter, prior to sampling and replicating the spectrum. For example, our lowcomplexity 30 dB/octave prefilter would provide 47.6 dB attenuation at 60 kHz. Indeed, the number of octaves from 20 to 60 kHz is log2 (60/20)= 1.585 and the attenuation there will be 30 dB/octave × 1.584 octaves = 47.6 dB. The prefilter, being monotonic beyond 60 kHz, would suppress all potential aliased components beyond 60 kHz by more than 47.6 dB. At 100 kHz, it would provide 30×log2 (100/20)= 69.7 dB attenuation. At fF = 62.5 kHz, it provides 49.3 dB suppression, as was calculated in Example 1.4.7, that is, H(fF ) = 10−49.3/20 = 1/292. Therefore, assuming that the digital filter has already removed the C, D, and E components, and that the aliased F component has been sufficiently attenuated by the prefilter, we can now drop the sampling rate down to 40 kHz. At the reduced 40 kHz rate, if we use an ideal reconstructor, it would extract only the components within the [−20, 20] kHz band and the resulting reconstructed output will be:
ya (t)= 2A cos(10πt)+2B cos(30πt)+
2F cos(35πt) 292
which has a much attenuated aliased component F. This is to be compared with Eq. (1.4.9), which used the same prefilter but no oversampling. Oversampling in conjunction with digital decimation helped eliminate the most severe aliased components, C and D. In summary, with oversampling, the complexity of the analog prefilter can be reduced and traded off for the complexity of a digital filter which is much easier to design and cheaper to implement with programmable DSPs. As we will see in Chapter 2, another benefit of oversampling is to reduce the number of bits representing each quantized sample. The connection between sampling rate and the savings in bits is discussed in Section 2.2. The subject of oversampling, decimation, interpolation, and the design and implementation of digital decimation and interpolation filters will be discussed in detail in Chapter 12.
27
1.4. SAMPLING OF SINUSOIDS
1.4.2 Rotational Motion A more intuitive way to understand the sampling properties of sinusoids is to consider a representation of the complex sinusoid x(t)= e2πjf t as a wheel rotating with a frequency of f revolutions per second. The wheel is seen in a dark room by means of a strobe light flashing at a rate of fs flashes per second. The rotational frequency in [radians/sec] is Ω = 2πf . During the time interval T between flashes, the wheel turns by an angle:
ω = ΩT = 2πf T =
2πf
(1.4.10)
fs
This quantity is called the digital frequency and is measured in units of [radians/sample]. It represents a convenient normalization of the physical frequency f . In terms of ω, the sampled sinusoid reads simply
x(nT)= e2πjf Tn = ejωn In units of ω, the Nyquist frequency f = fs /2 becomes ω = π and the Nyquist interval becomes [−π, π]. The replicated set f + mfs becomes 2π(f + mfs )
fs
=
2πf
fs
+ 2πm = ω + 2πm
Because the frequency f = fs corresponds to ω = 2π, the aliased frequency given in Eq. (1.4.3) becomes in units of ω:
ωa = ω mod(2π) The quantity f /fs = f T is also called the digital frequency and is measured in units of [cycles/sample]. It represents another convenient normalization of the physical frequency axis, with the Nyquist interval corresponding to [−0.5, 0.5]. In terms of the rotating wheel, f T represents the number of revolutions turned during the flashing interval T. If the wheel were actually turning at the higher frequency f + mfs , then during time T it would turn by (f + mfs )T = f T + mfs T = f T + m revolutions, that is, it would cover m whole additional revolutions. An observer would miss these extra m revolutions completely. The perceived rotational speed for an observer is always given by fa = f mod(fs ). The next two examples illustrate these remarks. Example 1.4.10: Consider two wheels turning clockwise, one at f1 = 1 Hz and the other at f2 = 5 Hz, as shown below. Both are sampled with a strobe light flashing at fs = 4 Hz. Note that the second one is turning at f2 = f1 + fs .
n=0
n=0
f=1
ωa=π/2
ω=π/2
n=1
n=3
n=1
n=3 ω=5π/2
n=2
f=5
n=2
28
1. SAMPLING AND RECONSTRUCTION The first wheel covers f1 T = f1 /fs = 1/4 of a revolution during T = 1/4 second. Its angle of rotation during that time interval is ω1 = 2πf1 /fs = 2π/4 = π/2 radians. During the sampled motion, an observer would observe the sequence of points n = 0, 1, 2, 3, . . . and would conclude that the wheel is turning at a speed of 1/4 of a revolution in 1/4 second, or, 1/4 cycles = 1 Hz 1/4 sec Thus, the observer would perceive the correct speed and sense of rotation. The second wheel, on the other hand, is actually turning by f2 T = f2 /fs = 5/4 revolutions in 1/4 second, with an angle of rotation ω2 = 5π/2. Thus, it covers one whole extra revolution compared to the first one. However, the observer would still observe the same sequence of points n = 0, 1, 2, 3, . . . , and would conclude again that the wheel is turning at 1/4 revolution in 1/4 second, or, 1 Hz. This result can be obtained quickly using Eq. (1.4.3):
f2a = f2 mod(fs )= 5 mod(4)= 5 − 4 = 1 Thus, in this case the perceived speed is wrong, but the sense of rotation is still correct. In the next figure, we see two more wheels, one turning clockwise at f3 = 9 Hz and the other counterclockwise at f4 = −3 Hz.
n=0
n=0
f=9
ωa=π/2
ωa= π/2
n=1
n=3 ω=9π/2
n=2
f=−3
n=1
n=3 ω = −3π/ 2
n=2
The negative sign signifies here the sense of rotation. During T = 1/4 sec, the third wheel covers f3 T = 9/4 revolutions, that is, two whole extra revolutions over the f1 wheel. An observer would again see the sequence of points n = 0, 1, 2, 3, . . . , and would conclude that f3 is turning at 1 Hz. Again, we can quickly compute, f3a = f3 mod(fs )= 9 mod(4)= 9 − 2 · 4 = 1 Hz. The fourth wheel is more interesting. It covers f4 T = −3/4 of a revolution in the counterclockwise direction. An observer captures the motion every 3/4 of a counterclockwise revolution. Thus, she will see the sequence of points n = 0, 1, 2, 3, . . . , arriving at the conclusion that the wheel is turning at 1 Hz in the clockwise direction. In this case, both the perceived speed and sense of rotation are wrong. Again, the same conclusion can be reached quickly using f4a = f4 mod(fs )= (−3) mod(4)= −3 + 4 = 1 Hz. Here, we added one fs in order to bring f4 within the Nyquist interval [−2, 2].
Example 1.4.11: The following figure shows four wheels rotating clockwise at f = 1.5, 2, 2.5, 4 Hz and sampled at fs = 4 Hz by a strobe light.
1.5. SPECTRA OF SAMPLED SIGNALS∗ n =0
29 n=0
n=0 2 4 6 3
5 ω
2
6
ωa
ω
6
1
7 4 f=1.5
n=0 1 2 3 4 5 5
3 ωa
7
1 13 57 f=2
ω
2
ω 4 f=2.5
f=4
This example is meant to show that if a wheel is turning by less than half of a revolution between sampling instants, that is, f T < 1/2 or ω = 2πf T < π, then the motion is perceived correctly and there is no aliasing. The conditions f T < 1/2 or ω < π are equivalent to the sampling theorem condition fs > 2f . But if the wheel is turning by more than half of a revolution, it will be perceived as turning in the opposite direction and aliasing will occur. The first wheel turns by f T = 3/8 of a revolution every T seconds. Thus, an observer would see the sequence of points n = 0, 1, 2, 3, . . . and perceive the right motion. The second wheel is turning by exactly half of a revolution f T = 1/2 or angle ω = 2πf T = π radians. An observer would perceive an updown motion and lose sense of direction, not being able to tell which way the wheel is turning. The third wheel turns by more than half of a revolution, f T = 5/8. An observer would see the sequence of points n = 0, 1, 2, 3, . . . , corresponding to successive rotations by ω = 5π/4 radians. An observer always perceives the motion in terms of the lesser angle of rotation, and therefore will think that the wheel is turning the other way by an angle ωa = ω mod(2π)= (5π/4)mod(2π)= 5π/4 − 2π = −3π/4 or frequency fa = −(3/8 cycle)/(1/4 sec)= −1.5 Hz. The fourth wheel will appear to be stationary because f = fs = 4 and the motion is sampled once every revolution, ω = 2π. The perceived frequency will be fa = f mod(fs )= 4 mod(4)= 4 − 4 = 0.
1.4.3 DSP Frequency Units Figure 1.4.4 compares the various frequency scales that are commonly used in DSP, and the corresponding Nyquist intervals. A sampled sinusoid takes the form in these units:
e2πjf Tn = e2πj(f /fs )n = ejΩTn = ejωn being expressed more simply in terms of ω. Sometimes f is normalized with respect to the Nyquist frequency fN = fs /2, that is, in units of f /fN . In this case, the Nyquist interval becomes [−1, 1]. In multirate applications, where successive digital processing stages operate at different sampling rates, the most convenient set of units is simply in terms of f . In fixedrate applications, the units of ω or f /fs are the most convenient.
1.5 Spectra of Sampled Signals∗ Next, we discuss the effects of sampling using Fourier transforms. Figure 1.3.1 shows an ideal sampler that instantaneously measures the analog signal x(t) at the sampling
30
1. SAMPLING AND RECONSTRUCTION
fs /2
0
fs /2
1/2
0
1/2
π
0
π
πfs
0
πfs
f
[Hz] = [cycles/sec]
f /fs
[cycles/sample]
ω = 2πf /fs
[radians/sample]
Ω = 2πf
[radians/sec]
Nyquist Interval Fig. 1.4.4 Commonly used frequency units.
instants t = nT. The output of the sampler can be considered to be an analog signal consisting of the linear superposition of impulses occurring at the sampling times, with each impulse weighted by the corresponding sample value. Thus, the sampled signal is ˆ(t)= x
∞
n=−∞
x(nT)δ(t − nT)
(1.5.1)
In practical sampling, each sample must be held constant for a short period of time, say τ seconds, in order for the A/D converter to accurately convert the sample to digital format. This holding operation may be achieved by a sample/hold circuit. In this case, the sampled signal will be:
xflat (t)=
∞
n=−∞
x(nT)p(t − nT)
(1.5.2)
where p(t) is a flattop pulse of duration of τ seconds such that τ T. Ideal sampling corresponds to the limit τ → 0. Figure 1.5.1 illustrates the ideal and practical cases.
x(nT)p(t −nT)
x(nT)δ(tnT) ^ x(t)
xflat(t) T
0
T
T
2T . . . nT
t
τ 0
T
2T . . . nT
t
Fig. 1.5.1 Ideal and practical sampling.
We will consider only the ideal case, Eq. (1.5.1), because it captures all the essential features of the sampling process. Our objective is to determine the spectrum of ˆ(t) and compare it with the spectrum of the original signal x(t). the sampled signal x Problem 1.21 explores practical sampling.
1.5. SPECTRA OF SAMPLED SIGNALS∗
31
ˆ(t) in two ways. The first relates Our main result will be to express the spectrum of x the sampled spectrum to the discretetime samples x(nT) and leads to the discretetime Fourier transform. The second relates it to the original spectrum and implies the spectrum replication property that was mentioned earlier.
1.5.1 DiscreteTime Fourier Transform ˆ(t) is the Fourier transform: The spectrum of the sampled signal x
)= X(f
∞
−∞
ˆ(t)e−2πjf t dt x
(1.5.3)
Inserting Eq. (1.5.1) into Eq. (1.5.3) and interchanging integration and summation, we obtain:
)= X(f =
∞
∞
−∞ n=−∞ ∞
n=−∞
x(nT)δ(t − nT)e−2πjf t dt
∞ x(nT) δ(t − nT)e−2πjf t dt
or,
−∞
)= X(f
∞
x(nT)e−2πjf Tn
(1.5.4)
n=−∞
). Several remarks are in order: This is the first way of expressing X(f
1. DTFT. Eq. (1.5.4) is known as the DiscreteTime Fourier Transform (DTFT)† of the ) is computable only from the knowledge of the sequence of samples x(nT). X(f sample values x(nT).
) is a periodic function of f with period fs , hence, X(f +fs )= X(f ). 2. Periodicity. X(f This follows from the fact that e−2πjf Tn is periodic in f . Because of this periodicity, one may restrict the frequency interval to just one period, namely, the Nyquist interval, [−fs /2, fs /2]. ) will extend over the entire frequency axis, The periodicity in f implies that X(f in accordance with our expectation that the sampling process introduces high frequencies into the original spectrum. Although not obvious yet, the periodicity in f is related to the periodic replication of the original spectrum. 3. Fourier Series. Mathematically, Eq. (1.5.4) may be thought of as the Fourier series ), with the samples x(nT) being the corexpansion of the periodic function X(f ) responding Fourier series coefficients. Thus, x(nT) may be recovered from X(f by the inverse Fourier series:
x(nT)= † Not
1
fs
fs /2
−fs /2
)e2πjf Tn df = X(f
π
−π
jωn X(ω)e
dω 2π
(1.5.5)
to be confused with the Discrete Fourier Transform (DFT), which is a special case of the DTFT.
32
1. SAMPLING AND RECONSTRUCTION where in the second equation we changed variables from f to ω = 2πf /fs .‡ Eq. (1.5.5) is the inverse DTFT and expresses the discretetime signal x(nT) as a superposition of discretetime sinusoids ejωn . 4. Numerical Approximation. Eq. (1.5.4) may be thought of as a numerical approximation to the frequency spectrum of the original analog signal x(t). Indeed, using the definition of integrals, we may write approximately,
X(f )=
∞
−∞
x(t)e−2πjf t dt
∞
n=−∞
x(nT)e−2πjf nT · T
or,
) X(f ) TX(f
(1.5.6)
) X(f )= lim TX(f
(1.5.7)
This approximation becomes exact in the continuoustime limit:
T→0
It is precisely this limiting result and the approximation of Eq. (1.5.6) that justify the use of discrete Fourier transforms to compute actual spectra of analog signals. 5. Practical Approximations. In an actual spectrum computation, two additional approximations must be made before anything can be computed: (a) We must keep only a finite number of time samples x(nT), say L samples, n = 0, 1, 2, . . . , L − 1, so that Eq. (1.5.4) is computed approximately by the truncated sum:
) X L (f )= X(f
L− 1
x(nT)e−2πjf Tn
(1.5.8)
n=0
This approximation leads to the concept of a time window and the related effects of smearing and leakage of the spectrum. These concepts are central in the area of spectral analysis and will be discussed in Chapter 9.
). (b) We must decide on a finite set of frequencies f at which to evaluate X(f Proper choice of this set allows the development of various efficient computational algorithms for the DFT, such as the Fast Fourier Transform (FFT), presented also in Chapter 9. 6. ztransform. Finally, we note that Eq. (1.5.4) leads to the concept of the ztransform, much like the ordinary Fourier transform leads to the Laplace transform. Setting z = ejω = e2πjf T , we may write Eq. (1.5.4) as the ztransform† ∞
x(nT)z−n
n=−∞
). the notation slightly, we wrote X(ω) for X(f ). abusing the notation, we wrote X(z) for X(f
‡ Abusing † Again,
X(z)=
1.5. SPECTRA OF SAMPLED SIGNALS∗
33
1.5.2 Spectrum Replication Next, we show the spectrum replication property by deriving the precise relationship ) of the sampled signal x ˆ(t) and the original spectrum X(f ) between the spectrum X(f of the analog signal x(t). The nth term x(nT)δ(t − nT) in Eq. (1.5.1) may be replaced by x(t)δ(t − nT) because the term is nonzero only at t = nT. Then, x(t) can be factored out of the sum in Eq. (1.5.1) as a common factor: ˆ(t)= x(t) x
∞
n=−∞
δ(t − nT)≡ x(t)s(t)
(1.5.9)
Thinking of this as the modulation of the “carrier” s(t) by the “baseband” signal x(t), we expect to get frequency translations of the original spectrum, much like the AM modulation of a sinusoidal carrier. The frequency translation effect may be seen by expanding the (periodic in time) sampling function s(t) into its Fourier series representation as a linear combination of harmonics. It is easily shown that
s(t)=
∞
n=−∞
δ(t − nT)=
1
T
∞
e2πjmfs t
(1.5.10)
m=−∞
which expresses the sampling function s(t) as a linear combination of sinusoidal carriers, each causing its own frequency shift. Writing Eq. (1.5.9) as ˆ(t)= x(t)s(t)= x
1
T
∞
x(t)e2πjmfs t
m=−∞
and using the modulation property of Fourier transforms, which states that if X(f ) is the transform of x(t) then X(f − fc ) is the transform of x(t)e2πjfc t , we obtain by taking Fourier transforms of both sides,
)= X(f
1
T
∞
m=−∞
X(f − mfs )
(1.5.11)
This represents the periodic replication of the original spectrum X(f ) at intervals ) as the sum of the periodic replicas of of the sampling rate fs . Fig. 1.5.2 shows TX(f X(f ). ˆ(t) is the product of x(t) Another way to prove Eq. (1.5.11) is as follows. Because x and s(t), its Fourier transform will be the convolution of the corresponding transforms, that is,
)= X(f
∞
−∞
X(f − f )S(f ) df
(1.5.12)
On the other hand, it follows from Eq. (1.5.10) that the Fourier transform of s(t) will be the sum of the transforms of the individual harmonics:
S(f )=
1
T
∞
m=−∞
δ(f − mfs )
(1.5.13)
34
1. SAMPLING AND RECONSTRUCTION
spectral replicas
spectral replicas
^ TX(f) original spectrum
. . .
X(f+2fs)
X(f+fs)
2fs
fs
X(ffs)
X(f)
fs /2 fs / 2 fmax 0 fmax
fs
Nyquist Interval
X(f2fs) . . .
2fs δ δ = fs −2 fmax
f
Fig. 1.5.2 Spectrum replication caused by sampling.
Inserting this into Eq. (1.5.12) and interchanging the summation over m with the integration over f , we obtain
)= X(f
1
T
∞ ∞
m=−∞
−∞
X(f − f )δ(f − mfs ) df =
1
T
∞
m=−∞
X(f − mfs )
Combining Eqs. (1.5.4) and (1.5.11), we obtain the two alternative expressions for ) the spectrum X(f
)= X(f
∞
n=−∞
x(nT)e−2πjf Tn =
1
T
∞
m=−∞
X(f − mfs )
(1.5.14)
This is known as the Poisson summation formula. We also see from Fig. 1.5.2 that as we let T → 0, or equivalently, fs → ∞, the replicas move out to infinity leaving behind only the original spectrum X(f ). Therefore, Eq. (1.5.7) follows. We emphasize that Eq. (1.5.14) holds for arbitrary signals x(t), not necessarily bandlimited ones. In the special case when x(t) is bandlimited to some maximum frequency fmax , as suggested by Fig. 1.5.2, we immediately obtain the sampling theorem condition, Eq. (1.3.2). It is seen in Fig. 1.5.2 that the replicas are separated from each other by a distance δ = fs − 2fmax , known as the guard band. It follows that the replicas will not overlap if δ ≥ 0, or equivalently, fs ≥ 2fmax . But they will overlap if fs < 2fmax or δ < 0 and aliasing of frequencies will take place as the tails of the replicas enter into the Nyquist interval and add to the original spectrum, distorting it. This case is shown in Fig. 1.5.3. It is evident by inspecting Fig. 1.5.2 that if the signal is bandlimited and fs is large enough so that the replicas do not overlap, then the portion of the sampled signal spec ) that lies within the Nyquist interval [−fs /2, fs /2] will be identical to the trum X(f original spectrum X(f ), that is,
)= X(f ), TX(f
for
−
fs 2
≤f ≤
fs 2
(1.5.15)
This is an important result for DSP. Not only does it make possible the analog reconstruction of the sampled signal, but it also guarantees that any subsequent digital
1.5. SPECTRA OF SAMPLED SIGNALS∗
35
^ TX(f) . . .
. . . 2fs
fs
fs/2 0
f fs /2
2fs
fs
Nyquist Interval Fig. 1.5.3 Aliasing caused by overlapping spectral replicas.
processing of the sampled signal will be applied to the original spectrum X(f ) and not to some aliased and distorted version thereof. For example, a subsequent digital filtering operation will transform the input samples x(nT) into a sequence of output samples y(nT). Just like analog filtering, digital filtering is equivalent to spectral shaping in the frequency domain. If the digital filter has ) of the input sequence will be reshaped frequency response HDSP (f ), the spectrum X(f into the output spectrum
)= HDSP (f )X(f ) Y(f
If Eq. (1.5.15) holds, then the digital filter will reshape the original spectrum X(f ). Note that because all digital filters have periodic frequency responses, the periodicity of the sampled spectrum is preserved by the digital filtering operation. Therefore, the output samples could be recovered from Eq. (1.5.5)
y(nT)=
π
−π
jωn Y(ω)e
dω = 2π
π
−π
jωn HDSP (ω)X(ω)e
dω 2π
If the spectrum X(f ) is not bandlimited, or, if it is bandlimited but the sampling rate fs is so low that the replicas overlap, then Eq. (1.5.15) does not hold. Any subsequent filtering will reshape the wrong spectrum. Therefore, it is essential to use a lowpass antialiasing prefilter, as shown in Fig. 1.3.5, to bandlimit the input spectrum to within the Nyquist interval, so that the resulting replicas after sampling will not overlap. Example 1.5.1: Consider a pure sinusoid of frequency f0 , x(t)= e2πjf0 t . Its Fourier transform is the spectral line X(f )= δ(f − f0 ). It follows from Eq. (1.5.11) that the sampled sinusoid ˆ(t)= x
∞
n=−∞
x(nT)δ(t − nT)=
∞
n=−∞
e2πjf0 Tn δ(t − nT)
will have Fourier spectrum
)= X(f
1
T
∞
m=−∞
δ(f − f0 − mfs )
Thus, the spectrum of the sampled sinusoid consists of all the frequencies in the replicated set {f0 + mfs , m = 0, ±1, ±2, . . . } in accordance with Fig. 1.3.2 and our remarks in Sections 1.4 and 1.3.
36
1. SAMPLING AND RECONSTRUCTION
Example 1.5.2: This example illustrates the effect of sampling on a nonbandlimited signal ) within the Nyquist interval and the degree to which the portion of the spectrum X(f approximates the original spectrum X(f ). Consider the exponentially decaying signal and its spectrum:
x(t) x(t) = e X(f ) =
−at
u(t)
x(nT)
1
a + 2πjf
T t
nT
ˆ(t) may be obtained in two ways. Using The frequency spectrum of the sampled signal x Eq. (1.5.4) ∞
)= X(f
n=−∞
x(nT)e−2πjf Tn =
∞
e−aTn e−2πjf Tn
n=0
and summing the geometric series, we get
Its magnitude square is
)= X(f
1 1 = 1 − e−aT e−2πjf T 1 − e−aT e−jω
)2 = X(f
1 1 − 2e−aT cos(2πf T)+e−2aT
The periodicity in f is evident because the dependence on f comes through the periodic cosine function. Alternatively, we may use Eq. (1.5.11) and sum the replicas of the original spectrum to get
)= X(f
1
T
∞
m=−∞
X(f − mfs )=
1
T
∞
m=−∞
1
a + 2πj(f − mfs )
), we obtain the notsoobvious identity in the paCombining the two expression for X(f rameters a, f , T: 1
T
∞
m=−∞
1
a + 2πj(f − mfs )
=
1 1 − e−aT e−2πjf T
)2 with the original The left graph in Fig. 1.5.4 compares the periodic spectrum TX(f analog spectrum X(f )2 = 1/ a2 + (2πf )2 . The spectra are shown in decibels, that is, 20 log10 X(f ). The parameter a was a = 0.2 sec−1 . Two values of the sampling rate fs = 1/T are shown, fs = 1 Hz and fs = 2 Hz. The two Nyquist intervals are [−0.5, 0.5] Hz and [−1, 1] Hz, respectively. Outside these intervals, the sampled spectra repeat periodically. Notice that even with the scale factor T taken into account, the two spectra X(f ) and ) are very different from each other. However, within the central Nyquist interval TX(f
1.5. SPECTRA OF SAMPLED SIGNALS∗
37
Fig. 1.5.4 Spectra of analog, sampled, and windowed signals.
[−fs /2, fs /2], they agree approximately, especially at low frequencies. This approximation gets better as fs increases. The limit as T → 0 or fs → ∞ can be seen explicitly in this example. Using the approximation e−x 1 − x, valid for small x, or L’Hospital’s rule, we obtain
)= lim lim TX(f
T→0
T→0
T 1 − e−aT e−2πjf T
=
1
a + 2πjf
= X(f )
In the right graph of Fig. 1.5.4, we show the effect of using a lengthL time window and approximating the spectrum by Eq. (1.5.8). The parameter values were a = 0.2, fs = 2, and L = 10 samples.
That figure compares what we would like to compute, that is, X(f )2 , with what we can )2 , and with what we can at best hope to compute based on our sampled signal, TX(f L (f )2 . actually compute based on a finite record of samples, TX
L (f )2 can be improved by taking longer L and using a nonThe windowed spectrum TX rectangular window, such as a Hamming window. At best, however, it will approach the )2 and not X(f )2 . The approximation of X(f ) by TX(f ) can sampled spectrum TX(f be improved only by increasing the sampling rate fs .
L (f ) can be computed by sending the L samples x(nT)= e−anT , n = The quantity X L (f ) can also be 0, 1, . . . , L − 1 into a general DFT routine. In this particular example, X computed in closed form. Using the finite geometric series: L− 1
n=0
xn =
1 − xL 1−x
we obtain:
L (f )= X
L− 1
n=0
e−aTn e−2πjf Tn =
L (f )→ X(f ) as L → ∞. It is evident that X
1 − e−aTL e−2πjf TL 1 − e−aT e−2πjf T
38
1. SAMPLING AND RECONSTRUCTION
1.5.3 Practical Antialiasing Prefilters An ideal analog prefilter is shown in Fig. 1.5.5. It acts as an ideal lowpass filter removing all frequency components of the analog input signal that lie beyond the Nyquist frequency fs /2. prefiltered spectrum
input spectrum
replicated spectrum
prefilter
f
f
Xin( f ) analog input
f
fs /2 0 fs /2
0
X( f )
ideal prefilter
sampled spectrum
ideal sampler
cutoff fmax = fs /2
fs
^ X( f)
T
bandlimited spectrum
H( f )
0
fs
rate fs
Fig. 1.5.5 Ideal antialiasing prefilter.
The antialiasing prefilters used in practice are not ideal and do not completely remove all the frequency components outside the Nyquist interval. Thus, some aliasing will take place. However, by proper design the prefilters may be made as good as desired and the amount of aliasing reduced to tolerable levels. A practical antialiasing lowpass filter is shown in Fig. 1.5.6. Its passband [−fpass , fpass ] is usually taken to be the frequency range of interest for the application at hand and must lie entirely within the Nyquist interval.
H(f)
ideal prefilter
transition region
Astop fs /2
fs /2
fstop
fpass
0 passband
stopband
fpass
fstop
f stopband
Fig. 1.5.6 Practical antialiasing lowpass prefilter.
The prefilter must be essentially flat over this passband in order not to distort the frequencies of interest. Even if it is not completely flat over the passband, it can be “equalized” digitally at a subsequent processing stage by a digital filter, say HEQ (f ), whose frequency response is the inverse of the response of the prefilter over the passband range:
HEQ (f )=
1
H(f )
,
for
− fpass ≤ f ≤ fpass
1.5. SPECTRA OF SAMPLED SIGNALS∗
39
The digital filter HEQ (f ), being periodic with period fs , cannot be the inverse of the prefilter over the entire frequency axis, but it can be the inverse over the passband. The stopband frequency fstop of the prefilter and the minimum stopband attenuation Astop in dB must be chosen appropriately to minimize aliasing effects. It will become evident from the examples below that fstop must be chosen as
fstop = fs − fpass
(1.5.16)
or, equivalently,
fs = fpass + fstop This places the Nyquist frequency fs /2 exactly in the middle of the transition region of the prefilter, as shown in Fig. 1.5.6. The attenuation of the filter in decibels is defined in terms of its magnitude response by:
H(f ) A(f )= −20 log10 H(f0 )
(attenuation in dB)
where f0 is a convenient reference frequency, typically taken to be at DC for a lowpass filter. Therefore, the stopband specification of the filter, depicted in this figure, is A(f )≥ Astop , for f  ≥ fstop . Transfer functions of analog filters typically drop like a power H(s)∼ 1/sN for large s, where N is the filter order. Thus, their magnitude response drops like H(f ) ∼ 1/f N for large f , and their attenuation will be, up to an additive constant,
A(f )= −20 log10 1/f N = α10 log10 f ,
(for large f )
(1.5.17)
where α10 is the attenuation in dB per decade defined by:
α10 = 20N
(dB per decade)
It represents the increase in attenuation when f is changed by a factor of ten, that is, A(10f )−A(f )= α10 . Engineers also like to measure attenuation in dB per octave, that is, the amount of change per doubling of f . This is obtained by using logs in base two, that is, writing Eq. (1.5.17) in the form:
A(f )= α2 log2 f = α10 log10 f where α2 is in dB/octave and is related to α10 by:
α2 = α10 log10 2 = 6N
(dB per octave)
Figure 1.5.5 shows the effect on the input spectrum Xin (f ) of an ideal prefilter with a sharp cutoff. For a practical prefilter, the output spectrum is given by:
X(f )= H(f )Xin (f ) or, in terms of attenuations in dB:
40
1. SAMPLING AND RECONSTRUCTION
AX (f )= A(f )+AXin (f )
(1.5.18)
where AX (f )= −20 log10 X(f )/X(f0 ) and similarly for AXin (f ). Thus, attenuations are additive. The spectrum X(f ) will be replicated by the subsequent sampling operation and therefore, the amount of attenuation in AX (f ) will determine the degree of overlapping of the spectral replicas, that is, the degree of aliasing. The specifications of the prefilter can be adjusted so that its attenuation A(f ), in combination with the attenuation AXin (f ) of the input spectrum, will result in sufficient attenuation of X(f ) to reduce the amount of aliasing within the desired frequency band. The next few examples illustrate these remarks. Example 1.5.3: The frequency range of interest of an analog signal extends to 4 kHz. Beyond 4 kHz, the spectrum attenuates at a rate of 15 dB per octave. Ideally, we would sample at a rate of 8 kHz provided the sampling operation is preceded by a perfect lowpass antialiasing prefilter with cutoff of 4 kHz. As a practical alternative to designing a perfect prefilter, we decide to sample at the higher rate of 12 kHz. (a) If we do not use any prefilter at all, determine the amount of aliasing that will be introduced by the sampling process into the frequency range of interest, that is, into the 4 kHz range. (b) We wish to suppress the aliased components within the frequency range of interest by more than 50 dB. Determine the least stringent specifications of the lowpass antialiasing prefilter that must be used.
Solution: Both parts are answered with the help of the figure below, which shows the original spectrum and its first replicas centered at ±fs = ±12 kHz.
X(f) 1st replica
1st replica
0th replica
y
x 16
12
8
4
0 desired range
4
8
12
16
f (kHz)
By the even symmetry of the spectra, it follows that the left tail of the 1st replica will be the same as the right tail of the 0th replica. Thus, the indicated attenuations x and y at frequencies 4 and 8 kHz will be equal, x = y. If we do not use any prefilter, the attenuation at 8 kHz will be y = 15 dB because the 0th replica attenuates by 15 dB per octave starting at 4 kHz. The aliased components within the desired 4 kHz range correspond to the shaded portion of the left side of the 1st replica that has entered into the 4 kHz interval. They are suppressed by more than x dB. Thus, x = y = 15 dB. This probably represents too much aliasing to be tolerable. If we use a prefilter, its passband must extend over the desired 4 kHz range. Therefore,
fpass = 4 kHz and fstop = fs − fpass = 12 − 4 = 8 kHz. Because attenuations are additive in dB, the total attenuation y at 8 kHz will now be the sum of the attenuation due to the
1.5. SPECTRA OF SAMPLED SIGNALS∗
41
signal, that is, 15 dB, and the attenuation due to the prefilter, say Astop dB. The equality
y = x and the requirement that x ≥ 50 dB lead to y = 15 + Astop = x ≥ 50
⇒
Astop ≥ 50 − 15 = 35 dB
Thus, the specifications of the prefilter are a fairly flat passband over the ±4 kHz range and a stopband starting at 8 kHz with minimum attenuation of 35 dB.
Example 1.5.4: The significant frequency range of a signal extends to fmax . Beyond fmax , the spectrum attenuates by α dB/octave. We have available an offtheshelf antialiasing prefilter that has a flat passband up to fmax and attenuates by β dB/octave beyond that. It is required that within the fmax range of interest, the aliased components due to sampling be suppressed by more than A dB. Show that the minimum sampling rate that we should use is given by
fs = fmax + 2A/γ fmax where γ = α + β.
Solution: We refer to the following figure, which shows the 0th and ±1st replicas.
γ dB/octave
X(f) 1st replica
1st replica
0th replica
x
A f
fs
0
fmax
fmax
fs  fmax
desired range
fs
The passband edge is at fpass = fmax and the stopband edge at fstop = fs − fmax . Beyond the desired fmax range, the total attenuation (in dB) of the 0th replica will be the sum of the attenuations of the signal and the prefilter. In the notation of Eq. (1.5.18), it will be given as function of frequency by
AX (f )= α log2
f fmax
+ β log2
f fmax
= γ log2
f fmax
where we have normalized the attenuation to 0 dB at f = fmax . This is the mathematical expression of the statement that the total attenuation will be γ dB per octave. By the even symmetry of the spectra, we have x = AX (fstop )= AX (fs − fmax ). Thus, the requirement that x ≥ A gives the condition
AX (fs − fmax )≥ A
⇒
γ log2
fs − fmax fmax
≥A
Solving this as an equality gives the minimum acceptable rate fs . If α and β had been given in dB/decade instead of dB/octave, the above condition would be valid with log10 instead of log2 resulting in fs = fmax + 10A/γ fmax . Note that the previous example corresponds to the case A = γ giving fs = fmax + 2fmax = 3fmax .
42
1. SAMPLING AND RECONSTRUCTION
The above examples show that to accommodate practical specifications for antialiasing prefilters, the sampling rates must be somewhat higher than the minimum Nyquist rate. The higher the rate, the less complex the prefilter. This idea is carried further in the method of oversampling, whereby the input is sampled at rates that are many times higher than the Nyquist rate. The replicas become very far separated, allowing the use of low quality, inexpensive analog prefilters. Oversampling methods will be discussed in Chapter 12.
1.6 Analog Reconstructors∗ We saw in Section 1.4.1 that an ideal reconstructor is an ideal lowpass filter with cutoff the Nyquist frequency fs /2. Here, we derive this result and also consider practical reconstructors. Analog reconstruction represents some sort of lowpass filtering of the sampled signal. This can be seen in Fig. 1.6.1, where practical reconstruction has been accomplished by filling the gaps between samples by holding the current sample value constant till the next sample. This is the staircase or sample/hold reconstructor. ^ y(t)
^ y(t) T
D/A staircase reconstructor
ya (t)
ya (t) T
t
t
sampled signal
reconstructed signal Fig. 1.6.1 Staircase reconstructor.
It must be clear from this figure that any reasonable way of filling the gaps between samples will result in some sort of reconstruction. Filling the gaps results in a smoother signal than the sampled signal. In frequencydomain language, the higher frequencies in the sampled signal are removed, that is, the sampled signal is lowpass filtered. Thus, any reconstructor may be viewed as an analog lowpass filter, as shown in Fig. 1.6.2. ^ y(t)
analog reconstructor
sampled input
h(t)
ya (t) reconstructed analog output
Fig. 1.6.2 Analog reconstructor as a lowpass filter.
We will determine the form of the impulse response h(t) of the reconstructor both for ideal and practical reconstruction. The relationship of the reconstructed output ya (t) to the input samples y(nT) can be found by inserting the sampled input signal ˆ(t)= y
∞
n=−∞
y(nT)δ(t − nT)
1.6. ANALOG RECONSTRUCTORS∗
43
into the convolutional equation of the reconstructor
ya (t)=
∞
ya (t)=
∞
−∞
ˆ(t ) dt h(t − t )y
It then follows that:
n=−∞
y(nT)h(t − nT)
(1.6.1)
It states that the way to fill the gaps between samples is to start at the current sample y(nT) and interpolate from it following the shape of h(t) until the next sample. More precisely, a copy of h(t) must be attached at each sample y(nT), and all such contributions must be summed over—the resulting curve being the reconstructed analog signal. In the frequency domain, Eq. (1.6.1) becomes
) Ya (f )= H(f )Y(f
(1.6.2)
) is the replicated spectrum given by Eq. (1.5.11) where Y(f )= Y(f
1
T
∞
m=−∞
Y(f − mfs )
1.6.1 Ideal Reconstructors For perfect or ideal reconstruction one must require that Ya (f ) be identical to the original analog spectrum Y(f ). If the spectrum Y(f ) is bandlimited and its replicas do not ) will agree with Y(f ) in accordance with overlap, then within the Nyquist interval, TY(f Eq. (1.5.15), that is,
)= Y(f
1
T
Y(f ) ,
for
−
fs 2
≤f ≤
fs
(1.6.3)
2
The ideal reconstruction filter H(f ) is an ideal lowpass filter with cutoff fs /2, defined as follows:
H(f )=
H( f )
T T, 0,
if f  ≤ fs /2 otherwise
f −fs /2
0
fs /2
The value T for the passband gain is justified below. As shown in Fig. 1.6.3, such a filter will extract the central replica and remove all other replicas. Using Eq. (1.6.3), we have within the Nyquist interval:
)= T · Ya (f )= H(f )Y(f
1
T
Y(f )= Y(f )
where the filter’s gain factor T canceled the 1/T factor in the spectrum.
44
1. SAMPLING AND RECONSTRUCTION
^ TY(f) . . .
Y(f+2fs)
Y(f+fs)
2fs
fs
ideal reconstructor
Y(ffs)
Y(f)
0
fs /2
fs /2
Y(f2fs) . . .
f
2fs
fs
Nyquist Interval Fig. 1.6.3 Ideal reconstructor in frequency domain.
The same relationship also holds trivially (0 ≡ 0) outside the Nyquist interval. Thus, we have Ya (f )= Y(f ), for all f , which implies that the reconstructed analog signal ya (t) will be identical to the original signal that was sampled, ya (t)= y(t). Combining this with Eq. (1.6.1), we obtain the Shannon sampling theorem [35–39] expressing the bandlimited signal y(t) in terms of its samples y(nT):
y(t)=
∞
n=−∞
y(nT)h(t − nT)
(1.6.4)
The impulse response of the ideal reconstructor can be obtained from the inverse Fourier transform of H(f ):
h(t)=
∞
−∞
h(t)=
H(f )e2πjf t df =
sin(πt/T)
πt/T
=
fs /2
Te2πjf t df ,
or,
−fs /2
sin(πfs t)
(ideal reconstructor)
πfs t
(1.6.5)
It is shown in Fig. 1.6.4. Unfortunately, the ideal reconstructor is not realizable. Its impulse response is not causal, having an infinite anticausal part. Therefore, alternative reconstructors, such as the staircase one, are used in practice.
ideal reconstructor
3T
2T
1
T
0
staircase reconstructor
h(t)
T
2T
3T
t
Fig. 1.6.4 Impulse response of ideal reconstructor.
An approximation to the ideal reconstructor, obtained by truncating it to finite length, is used in the design of digital FIR interpolation filters for oversampling and sample rate conversion applications. We will discuss it in Chapter 12.
1.6. ANALOG RECONSTRUCTORS∗
45
1.6.2 Staircase Reconstructors The staircase reconstructor shown in Fig. 1.6.1 is the simplest and most widely used reconstructor in practice. It generates a staircase approximation to the original signal. Note the similarity of this operation to practical sampling, where h(t) is a sampling pulse p(t) having a very narrow width τ T. By contrast, the impulse response of the staircase reconstructor must have duration of T seconds in order to fill the entire gap between samples. Thus, h(t) is given by:
h(t) h(t)= u(t)−u(t − T)=
1
if 0 ≤ t ≤ T otherwise
1, 0,
t 0
T
where u(t) is the unit step. The staircase output, although smoother than the sampled input, still contains spurious highfrequency components arising from the sudden jumps in the staircase levels from sample to sample. This spurious frequency content may be seen by computing the frequency response of the reconstructor. The Laplace transform of h(t)= u(t)−u(t − T) is
H(s)=
1
s
−
1
s
e−sT
from which we obtain the Fourier transform by setting s = 2πjf :
H(f )=
sin(πf T) −πjf T 1 e 1 − e−2πjf T = T 2πjf πf T
(1.6.6)
It is shown in Fig. 1.6.5 in comparison to the ideal reconstructor. Notice that it vanishes at integral multiples of fs — exactly where the replicas caused by sampling are centered. The spurious high frequencies mentioned above are those beyond the Nyquist frequency fs /2.
ideal reconstructor
 H(f) 
T
4 dB
f 2fs
fs
fs /2
0
fs /2
fs
2fs
Fig. 1.6.5 Frequency response of staircase reconstructor.
Thus, the reconstructor does not completely eliminate the replicated spectral images as the ideal reconstructor does. Figure 1.6.6 compares the spectra before and after the ). staircase reconstructor, that is, the effect of the multiplication Ya (f )= H(f )Y(f
46
1. SAMPLING AND RECONSTRUCTION
ideal reconstructor
2fs
fs
staircase reconstructor
fs /2
0
fs /2
partially attenuated central replica
2fs
fs
fs /2
fs
f
2fs
surviving replicas
0
fs /2
fs
f
2fs
Fig. 1.6.6 Frequency response of staircase reconstructor.
1.6.3 AntiImage Postfilters The surviving spectral replicas may be removed by an additional lowpass postfilter, called an antiimage postfilter, whose cutoff is the Nyquist frequency fs /2. This operation is shown in Fig. 1.6.7.
t digital signal
t staircase reconstructor
analog signal
antiimage lowpass postfilter
cutoff fs /2 ideal reconstructor
t analog signal
Fig. 1.6.7 Analog antiimage postfilter.
In the time domain, the postfilter has the effect of rounding off the corners of the staircase output making it smoother. In the frequency domain, the combined effect of the staircase reconstructor followed by the antiimage postfilter is to remove the spectral replicas as much as possible, that is, to emulate the ideal reconstructor. The final reconstructed spectrum at the output of the postfilter is shown in Fig. 1.6.8. The reason for using this twostage reconstruction procedure is the simplicity of implementation of the staircase reconstruction part. A typical D/A converter will act as such a reconstructor. The digital code for each sample is applied to the DAC for T seconds generating an analog output that remains constant during T. The specifications of the postfilter are similar to those of an antialiasing prefilter, namely, a flat passband and cutoff frequency equal to the Nyquist frequency fs /2. Highquality DSP applications, such as digital audio, require the use of postfilters (and prefilters) with very stringent specifications. In deciding the specifications of a postfilter, one must take into account the effect of the staircase D/A which does part of the recon
1.6. ANALOG RECONSTRUCTORS∗
47
antiimage lowpass postfilter
stopband attenuation
sharp cutoff
APOST
2fs
fs
fs /2
0
fs /2
f
2fs
fs
Fig. 1.6.8 Spectrum after postfilter.
struction. The main function of the postfilter is to remove the remnants of the spectral images that survived the staircase D/A reconstructor. It can also be used to equalize the rolloff of the staircase response within the Nyquist interval. As shown in Fig. 1.6.5, the staircase reconstructor is not flat within the Nyquist interval, tending to attenuate more near the Nyquist frequency fs /2. The maximum attenuation suffered at fs /2 is about 4 dB. This can be seen as follows:
H(fs /2) sin(π/2) −20 log10 H(0) = −20 log10 π/2 = 3.9 dB
This attenuation can be compensated by proper design of the passband of the antiimage postfilter. But more conveniently, it can be compensated digitally before analog reconstruction, by designing an equalizing digital filter whose response matches the inverse of H(f ) over the Nyquist interval. Similar techniques were mentioned in Section 1.5.3 for equalizing the imperfect passband of the antialiasing prefilter. The use of highquality digital filters to perform these equalizations improves the overall quality of the digital processing system. By contrast, analog compensation techniques would be more cumbersome and expensive. The combined equalizer, DAC, and postfilter are shown in Fig. 1.6.9. The frequency response of the equalizer is defined as the inverse of the DAC, as given by Eq. (1.6.6):
HEQ (f )=
πf T T = eπjf T , H(f ) sin(πf T)
for
−
fs 2
≤f ≤
fs
(1.6.7)
2
It is shown in Fig. 1.6.10. As a digital filter, HEQ (f ) is periodic outside the Nyquist interval with period fs . We will design such inverse filters later using the frequency sampling design method of Section 10.3. Some designs are presented in Chapter 12.
y(nT) digital signal
digital filter equalizer HEQ(f)
yEQ(nT) digital signal
staircase reconstructor H(f)
ya(t) analog signal
antiimage postfilter HPOST(f)
yPOST(t) analog signal
Fig. 1.6.9 Digital equalization filter for D/A conversion.
The equalizer filter transforms the sequence y(nT) into the “equalized” sequence yEQ (nT), which is then fed into the DAC and postfilter. The frequency spectrum of
48
1. SAMPLING AND RECONSTRUCTION
 HEQ(f) 4 dB
1 H(f)  T
f fs
0
fs /2
fs /2
fs
Fig. 1.6.10 Frequency response of DAC equalizer.
EQ (f )= HEQ (f )Y(f ). The spectrum of the staircase output of the DAC will yEQ (nT) is Y EQ (f ). Therefore, the final reconstructed spectrum at the output of be Ya (f )= H(f )Y the postfilter will be
YPOST (f ) = HPOST (f ) Ya (f ) EQ (f ) = HPOST (f ) H(f ) Y
) = HPOST (f ) H(f ) HEQ (f ) Y(f
Within the Nyquist interval, using Eqs. (1.6.7) and (1.5.15) and assuming a flat postfilter there, HPOST (f ) 1, we have
)= 1 · T · YPOST (f )= HPOST (f ) H(f ) HEQ (f ) Y(f
1
T
Y(f )= Y(f )
Outside the Nyquist interval, assuming HPOST (f ) 0, we have YPOST (f )= 0. Thus, the combination of equalizer, DAC, and postfilter acts like an ideal reconstructor. Example 1.6.1: The signal of Example 1.5.3 that was sampled at fs = 12 kHz is filtered by a digital filter designed to act as an ideal lowpass filter with cutoff frequency of fc = 2 kHz. The filtered digital signal is then fed into a staircase D/A and then into a lowpass antiimage postfilter. The overall reconstructor is required to suppress the spectral images caused by sampling by more than A = 80 dB. Determine the least stringent specifications for the analog postfilter that will satisfy this requirement.
Solution: The digital lowpass filter is, by construction, periodic in f with period fs . Thus, the spectrum of the signal after the digital filter will look as follows:
^ ideal lowpass Y(f) digital filter
2fs
fs
fs /2
0
fs /2 fs fc fsfc
2fs
f
The spectral images are separated now by a distance fs − 2fc = 12 − 2 · 2 = 8 kHz. After passing through the staircase reconstructor, the spectrum will be as shown below:
1.6. ANALOG RECONSTRUCTORS∗
49
postfilter passband
Ya (f)
transition region
ADAC 2fs
fs
fs /2
0
fs /2 fc
APOST
fs
2fs
f
fsfc = stopband
The postfilter must have a flat passband over [−fc , fc ]. Its stopband must begin at fstop = fs − fc = 12 − 2 = 10 kHz because the first replica is largest there. The wide transition region between fc and fs − fc allows the use of a less stringent postfilter. The required stopband attenuation of the postfilter can be determined as follows. The total attenuation caused by the cascade of the DAC and postfilter is the sum of the corresponding attenuations:
A(f )= ADAC (f )+APOST (f ) where
sin(πf /f ) H(f ) s = −20 log ADAC (f )= −20 log10 10 H(0) πf /fs
At f = fstop = fs − fc , the total attenuation must be greater than A
ADAC + APOST ≥ A
⇒
APOST ≥ A − ADAC
Numerically, we find at fstop = 10 kHz
sin(π10/12) ADAC = −20 log10 π10/12 = 14.4
resulting in APOST ≥ 80 − 14.4 = 65.6 dB.
The key idea in this example was to use the separation between spectral replicas as the transition region of the postfilter. The wider this separation, the less stringent the postfilter. Oversampling and digital interpolation techniques exploit this idea to its fullest and can be used to alleviate the need for expensive highquality analog postfilters. Such oversampling systems are routinely used in CD and DAT players. They will be discussed in Chapter 12. Example 1.6.2: A sinusoid of frequency f0 is sampled at a rate fs , such that f0  ≤ fs /2. The resulting sampled sinusoid is then reconstructed by an arbitrary reconstructor H(f ). Determine the analog signal at the output of the reconstructor when H(f ) is: (a) the ideal reconstructor, (b) the staircase reconstructor, (c) the staircase reconstructor followed by a very good antiimage postfilter, and (d) a staircase reconstructor equalized by the digital filter defined in Eq. (1.6.7).
50
1. SAMPLING AND RECONSTRUCTION
Solution: Let y(t)= e2πjf0 t . Its spectrum is Y(f )= δ(f − f0 ) and the spectrum of the sampled sinusoid will be the replication of Y(f ), as in Example 1.5.1: ∞
1
)= Y(f
T
m=−∞
δ(f − f0 − mfs )
The spectrum of the reconstructed signal will be: 1
)= Ya (f )= H(f )Y(f
T
=
T
∞
H(f )δ(f − f0 − mfs )
∞
H(f0 + mfs )δ(f − f0 − mfs )
m=−∞
1
m=−∞
Taking inverse Fourier transforms, we obtain:
ya (t)=
1
T
∞
H(fm )e2πjfm t
(1.6.8)
m=−∞
where fm = f0 + mfs . If H(f ) is the ideal reconstructor, then H(fm ) will be zero if fm does not lie in the Nyquist interval. Because f0 was assumed to lie in the interval, only the m = 0 term will survive the sum giving:
ya (t)=
1
T
H(f0 )e2πjf0 t =
1
T
· T e2πjf0 t = e2πjf0 t
thus, the sinusoid is reconstructed perfectly. If f0 lies outside the interval, f0  > fs /2, then there exists a unique integer m0 such that f0 + m0 fs  < fs /2, where m0 is negative if f0 > 0. In this case, only the m = m0 term will survive the sum giving:
ya (t)=
1
T
H(fm0 )e2πjfm0 t = e2πjfm0 t
where fm0 = f0 + m0 fs = f0 mod(fs ). The sinusoid f0 will be confused with the sinusoid fm0 , as we discussed qualitatively in Section 1.4.1. For the staircase reconstructor of Eq. (1.6.6), the reconstructed signal will be given by Eq. (1.6.8), which should sum up to generate the staircase approximation to the sinusoid. This is demonstrated in Example 1.6.3. In case (c), a good postfilter will remove all frequencies outside the Nyquist interval, that is, only the m = 0 term will survive in Eq. (1.6.8), giving:
ya (t)=
1
T
H(f0 )e2πjf0 t
where we assumed that the postfilter has unity gain over the Nyquist interval. Using Eq. (1.6.6) evaluated at f = f0 , we get:
ya (t)=
sin(πf0 T)
πf0 T
e−πjf0 T e2πjf0 t
1.6. ANALOG RECONSTRUCTORS∗
51
Thus, there is amplitude attenuation and phase shift, which both become worse as f0 increases towards the Nyquist frequency fs /2. A digital filter that equalizes the staircase response, would anticipate this attenuation and phase shift and undo them. Indeed, in case (d), the effective reconstructor is HEQ (f )H(f ). Therefore, Eq. (1.6.8) becomes:
ya (t)=
1
T
∞
HEQ (fm )H(fm )e2πjfm t
m=−∞
But because of the periodicity of HEQ (f ), we can replace HEQ (fm )= HEQ (f0 )= T/H(f0 ), giving:
ya (t)=
∞ H(fm ) 2πjfm t e m=−∞ H(f0 )
(1.6.9)
A good postfilter, extracting the m = 0 term, would result in the final reconstructed output
ypost (t)=
H(f0 ) 2πjf0 t e = e2πjf0 t . H(f0 )
Example 1.6.3: The cosinusoid y(t)= cos(2πf0 t) is sampled at a rate fs and the samples are reconstructed by a staircase reconstructor H(f ). The reconstructed signal will be:
ya (t)=
∞
m=−∞
G(fm )cos 2πfm t + φ(fm )
(1.6.10)
where G(f ) and φ(f ) are defined as
G(f )=
sin(πf T)
πf T
,
φ(f )= −πf T
⇒
H(f )= TG(f )ejφ(f )
Note that TG(f ) and φ(f ) are not quite the magnitude and phase responses of H(f ); those are H(f ) = TG(f ) and arg H(f ) = φ(f )+π (1 − sign G(f ))/2. Eq. (1.6.10) is obtained by substituting H(f )= TG(f )ejφ(f ) into Eq. (1.6.8) and taking real parts. A computable approximation of Eq. (1.6.10) is obtained by truncating the sum to 2M + 1 terms, that is, keeping the terms −M ≤ m ≤ M:
ya (t)=
M
m=−M
w(m)G(fm )cos 2πfm t + φ(fm )
(1.6.11)
where we have also introduced appropriate weights w(m) to reduce the Gibbs ripples resulting from the truncation of the sum. For example, the Hamming weights are:
πm , w(m)= 0.54 + 0.46 cos M
−M ≤ m ≤ M
whereas the rectangular weights are w(m)= 1. For the numerical values f0 = 0.125 kHz, fs = 1 kHz, M = 15, we have computed the original analog signal y(t) and the reconstructed signal ya (t) as given by the approximation of Eq. (1.6.11), over the time interval 0 ≤ t ≤ 16 msec, that is, over 16 sampling instants. If the signal ya (t) were postfiltered by a good postfilter, only the m = 0 term would survive the sum, and the resulting signal would be the original f0 sinusoid with some attenuation and phase shift:
52
1. SAMPLING AND RECONSTRUCTION
ypost (t)= G(f0 )cos 2πf0 t + φ(f0 ) The following figure compares the three signals y(t), ya (t), and ypost (t) in the two cases of using rectangular weights and Hamming weights w(m).
Notice how the postfilter output ypost (t) is essentially an averaged or smoothed version of the staircase output ya (t). To see the dependence on the value of f0 of the attenuation and phase shift of ypost (t), the next two graphs show the cases f0 = 0.25 and f0 = 0.5 kHz.
The case f0 = 0.5 kHz corresponds to the Nyquist frequency fs /2, having the maximum amplitude and phase distortion. In all cases, however, ypost (t) is a smoothed version of the staircase output. If the staircase reconstructor is preceded by an equalizer filter, as shown in Fig. 1.6.9, then the staircase output will be given by the real part of Eq. (1.6.9). We have: sin(πfm T) πf0 T H(fm ) e−jπ(fm −f0 ) = H(f0 ) πfm T sin(πf0 T)
=
sin(πf0 T + πm) f0 −jπm e sin(πf0 T) fm
=
(−1)m sin(πf0 T) f0 f0 (−1)m = sin(πf0 T) fm fm
where we used the property cos(x + πm)= (−1)m cos x. Thus,
53
1.7. BASIC COMPONENTS OF DSP SYSTEMS
ya (t)=
M
m=−M
w(m)
f0 cos(2πfm t) fm
(1.6.12)
This signal is shown below for the case f0 = 0.125 kHz.
It is superimposed on the original sinusoid, corresponding to the m = 0 term, which is what would be extracted by a good postfilter. Notice again the smoothing effect of the postfilter. In order to remove completely all the m = 0 terms, the postfilter must be a highquality lowpass filter with sharp cutoff at the Nyquist frequency. To illustrate the beneficial effect of oversampling on such a reconstructor, we have also plotted the digitally equalized staircase output in the case of 4times oversampling, as given by Eq. (1.6.12) with fs = 4 kHz. Now there are four times as many staircase levels. They follow the original sinusoid more closely and can be smoothed more easily. Therefore, a lower quality, less expensive lowpass postfilter would be sufficient in this case.
1.7 Basic Components of DSP Systems It follows from the discussion in Sections 1.5 and 1.6 that the minimum number of necessary components in a typical digital signal processing system must be: 1. A lowpass analog antialiasing prefilter that bandlimits the signal to be sampled to within the Nyquist interval. 2. An A/D converter (sampler and quantizer). 3. A digital signal processor. 4. A D/A converter (staircase reconstructor), possibly preceded by an equalizing digital filter. 5. A lowpass analog antiimage postfilter to complete the job of the staircase reconstructor and further remove the spectral images introduced by the sampling process. These are shown in Fig. 1.7.1. Here, we review briefly the function of each stage and its impact on the quality of the overall digital processing system. With the exception
54
1. SAMPLING AND RECONSTRUCTION
of the sampling stage, every stage in this system may be thought of as a filtering operation by an appropriate transfer function. The sampling stage, through its spectrum replication, is a spectrum expansion operation. The function of the antialiasing prefilter HPRE (f ) is to bandlimit the overall analog input signal xa (t) to within the Nyquist interval [−fs /2, fs /2]. The output of the prefilter is now a bandlimited signal x(t) and may be sampled at a rate of fs samples per second. By design, the spectral replicas generated by the sampling process will not overlap. The sampling rate must be high enough so that the surviving input spectrum after the prefiltering operation, that is, the spectrum of x(t), contains all the frequencies of interest for the application at hand. The quality of the prefilter affects critically the quality of the overall system, that is, the degree of overlap of the spectral replicas depends on the rolloff characteristics of the prefilter. ˆ(t) or x(nT) is then processed by a digital The sampled (and quantized) signal x signal processor whose effect is to reshape the spectrum by means of a transfer function, )= HDSP (f )X(f ). say HDSP (f ), so that Y(f ˆ(t) or y(nT) are then reconstructed by the DAC into The resulting output samples y the staircase analog signal y(t). Finally, the signal y(t) is smoothed further by the postfilter, resulting in the overall analog output signal ya (t). Separating in Eq. (1.5.11) the central replica from the other replicas, we write
)= X(f
1
T
∞
m=−∞
1
X(f − mfs )=
T
X(f )+replicas
and following backwards all the transfer function relationships, we find for the spectrum of ya (t):
) Ya (f ) = HPOST (f ) Y(f )= HPOST (f ) HDAC (f ) Y(f ) = HPOST (f ) HDAC (f ) HDSP (f ) X(f
xa(t) analog in
T
= HPOST (f ) HDAC (f ) HDSP (f )
T
analog prefilter HPRE(f)
x(t) sampler & A/D fs clock
Xa (f)
X(f)
f 0
1
= HPOST (f ) HDAC (f ) HDSP (f )
^ x(t)
DSP HDSP(f)
^
1
^ staircase y(t) y(t) D/A HDAC(f)
Y(f)
fs
analog postfilter HPOST(f)
f 0
fs
ya (t) analog out Ya(f)
Y(f)
f 0
HPRE (f )Xa (f )+replicas
^
X(f)
f 0
X(f )+replicas
f 0
Fig. 1.7.1 Components of typical DSP system.
fs
f 0
fs
55
1.8. PROBLEMS
In a welldesigned system, the product of the staircase DAC and the postfilter transfer functions should be effectively equal to the ideal reconstructor. Therefore, for frequencies outside the Nyquist interval the output spectrum will vanish, that is, the spectral images will be removed. But for frequencies within the Nyquist interval, that product should be equal to the gain T canceling the 1/T factor. Furthermore, because the prefilter HPRE (f ) ensures that the replicas do not overlap, the terms labeled “replicas” will vanish for all frequencies within the Nyquist interval. Finally, because the prefilter approximates an ideal lowpass filter, its passband gain will be approximately one. The upshot of all this is that within the Nyquist interval one has approximately
HPOST (f ) HDAC (f ) T replicas 0
HPRE (f ) 1 To the extent that these approximations are good—and this determines the quality of the overall system—we finally find
Ya (f )= T · HDSP (f )
1 1 · Xa (f )+0 ,
T
Ya (f )= HDSP (f )Xa (f ) ,
for
f  ≤
or,
fs 2
(1.7.1)
Thus, the above arrangement works exactly as expected, that is, it is equivalent to linear filtering of the analog input, with an effective transfer function HDSP (f ) defined by the digital signal processor. This is, of course, the ultimate goal of the DSP system. The primary reasons for using digital signal processing are the programmability, reliability, accuracy, availability, and cost of the digital hardware.
1.8 Problems 1.1 A wheel, rotating at 6 Hz, is seen in a dark room by means of a strobe light flashing at a rate of 8 Hz. Determine the apparent rotational speed and sense of rotation of the wheel. Repeat the question if the flashes occur at 12 Hz, 16 Hz, or 24 Hz. 1.2 The analog signal x(t)= 10 sin(2πt)+10 sin(8πt)+5 sin(12πt), where t is in seconds, is sampled at a rate of fs = 5 Hz. Determine the signal xa (t) aliased with x(t). Show that the two signals have the same sample values, that is, show that x(nT)= xa (nT). Repeat the above questions if the sampling rate is fs = 10 Hz. 1.3 The signal x(t)= cos(5πt)+ 4 sin(2πt)sin(3πt), where t is in milliseconds, is sampled at a rate of 3 kHz. Determine the signal xa (t) aliased with x(t). Determine two other signals x1 (t) and x2 (t) that are different from each other and from x(t), yet they are aliased with the same xa (t) that you found. 1.4 Let x(t)= cos(8πt)+ 2 cos(4πt)cos(6πt), where t is in seconds. Determine the signal xa (t) aliased with x(t), if the sampling rate is 5 Hz. Repeat for a sampling rate of 9 Hz.
56
1. SAMPLING AND RECONSTRUCTION
1.5 The analog signal x(t)= sin(6πt) 1 + 2 cos(4πt) , where t is in milliseconds, is sampled at a rate of 4 kHz. The resulting samples are immediately reconstructed by an ideal reconstructor. Determine the analog signal xa (t) at the output of the reconstructor. 1.6 The analog signal x(t)= 4 cos(2πt)cos(8πt)cos(12πt), where t is in seconds, is sampled at a rate of fs = 10 Hz. Determine the signal xa (t) aliased with x(t). Show that the two signals have the same sample values, that is, show that x(nT)= xa (nT). Repeat the above questions if the sampling rate is fs = 12 Hz. [Hint: Express x(t) as a sum of sines and cosines.] 1.7 Consider the periodic triangular waveform with period T0 = 1 sec shown in Fig. 1.8.1. The waveform is sampled at rate fs = 8 Hz and the resulting samples are reconstructed by an ideal reconstructor. Show that the signal xrec (t) that will appear at the output of the reconstructor will have the form:
xrec (t)= A sin(2πf1 t)+B sin(2πf2 t) and determine the numerical values of the frequencies f1 , f2 and amplitudes A, B.
x(t) 1
0
0.5
1
t (sec)
Fig. 1.8.1 Triangular waveform of Problem 1.7. 1.8 Computer Experiment: Aliasing. Consider an analog signal x(t) consisting of three sinusoids of frequencies f1 = 1 kHz, f2 = 4 kHz, and f3 = 6 kHz, where t is in milliseconds:
x(t)= 2 sin(2πf1 t)+2 sin(2πf2 t)+ sin(2πf3 t) a. The signal is sampled at a rate of 5 kHz. Determine the signal xa (t) that would be aliased with x(t). On the same graph, plot the two signals x(t) and xa (t) versus t in the range 0 ≤ t ≤ 2 msec. Show both analytically and graphically that the two signals have the same sampled values, which occur at intervals of T = 1/fs = 0.2 msec. b. Repeat with a sampling rate of fs = 10 kHz. c. On the same graph, plot the signals x(t) and xa (t) of Problem 1.7, over the range 0 ≤ t ≤ 2 sec, and verify that they intersect at the sampling instants at multiples of T = 1/fs = 0.125 sec. In plotting, x(t), you need to define it as a triangular function of t. Repeat this part, but with sampling rate fs = 4 Hz. What is xa (t) now? 1.9 Consider the following sound wave, where t is in milliseconds:
x(t)= sin(10πt)+ sin(20πt)+ sin(60πt)+ sin(90πt) This signal is prefiltered by an analog antialiasing prefilter H(f ) and then sampled at an audio rate of 40 kHz. The resulting samples are immediately reconstructed using an ideal reconstructor. Determine the output ya (t) of the reconstructor in the following cases and compare it with the audible part of x(t):
57
1.8. PROBLEMS a. When there is no prefilter, that is, H(f )≡ 1. b. When H(f ) is an ideal prefilter with cutoff of 20 kHz.
c. When H(f ) is a practical prefilter that has a flat passband up to 20 kHz and attenuates at a rate of 48 dB/octave beyond 20 kHz. (You may ignore the effects of the phase response of the filter.) 1.10 Prove the Fourier series expansion of the ideal sampling function s(t) given in Eq. (1.5.10). Then, prove its Fourier transform expression (1.5.13). 1.11 Given Eq. (1.5.4), prove the inverse DTFT property (1.5.5), that is,
)= X(f
∞
x(nT)e−2πjf Tn
⇒
n=−∞
x(nT)=
1
fs
fs /2
−fs /2
)e2πjf Tn df X(f
1.12 Consider a pure sinusoid of frequency f0 , x(t)= cos(2πf0 t). Show that the spectrum of the sampled sinusoid x(nT) is:
)= X(f
1 2T
∞
m=−∞
δ(f − f0 − mfs )+δ(f + f0 + mfs )
1.13 Computer Experiment: Sampling of NonBandlimited Signals. Consider the exponentially decaying sinusoid x(t)= e−at cos(2πf0 t) sampled at a rate fs = 1/T. For convenience, replace it by its complexvalued version: x(t)= e−at e2πjf0 t . Let x(nT)= e−aTn e2πjf0 Tn be its samples, and let xL (nT)= x(nT), n = 0, 1, . . . , L − 1 be its windowed version to length L. Show that the magnitude spectra of the analog, sampled, and windowed signals are given by:
X(f )2 = )2 = X(f
Show the limits:
L (f )2 = X
1
2 a2 + 2π(f − f0 )
1 1 − 2e−aT cos 2π(f − f0 )T + e−2aT
1 − 2e−aTL cos 2π(f − f0 )LT + e−2aTL 1 − 2e−aT cos 2π(f − f0 )T + e−2aT
L (f )= X(f ), lim X
L→∞
)= X(f ) lim TX(f
fs →∞
For the numerical values a = 0.2 sec−1 , f0 = 0.5 Hz, and the two rates fs = 1 Hz and fs = 2 Hz, plot on the same graph the analog spectrum X(f )2 and the sampled spectrum )2 , over the frequency range 0 ≤ f ≤ 3 Hz. TX(f
)2 , TX L (f )2 , over the For fs = 2, plot on another graph, the three spectra X(f )2 , TX(f range 0 ≤ f ≤ 3 Hz. What conclusions do you draw from these graphs? What are the implications of the above limits? What are the essential differences if we work with the realvalued signal?
1.14 The frequency range of interest of a signal extends to fmax . Beyond fmax , the spectrum attenuates by α dB per decade. We have available an offtheshelf antialiasing prefilter that has a flat passband up to fmax and attenuates by β dB per decade beyond that. It is required that within the fmax range of interest, the aliased components due to sampling be suppressed by more than A dB. Show that the minimum sampling rate that we should use is given by
fs = fmax + 10A/γ fmax ,
where γ = α + β
58
1. SAMPLING AND RECONSTRUCTION
1.15 An analog input signal to a DSP system has spectrum:
Xin (f ) =
1 1 + (0.1f )8
where f is in kHz. The highest frequency of interest is 20 kHz. The signal is to be sampled at a rate fs . It is required that the aliased spectral components within the frequency range of interest be suppressed by more than 60 dB relative to the signal components, that is, they must be at least 60 dB below the value of the signal components throughout the 20 kHz range of interest. a. Determine the minimum sampling rate fs , if no antialiasing prefilter is used. b. Suppose a simple thirdorder Butterworth antialiasing prefilter is used having magnitude response
H(f ) =
1 1 + (f /f0 )6
It is required that the prefilter’s attenuation within the 20 kHz band of interest remain less than 1 dB. What is the value of the normalization frequency f0 in this case? What is the minimum value of fs that may be used? Compare your exact calculation of fs with the approximate one using the method of Problem 1.14. 1.16 For the above example, suppose we are constrained to use a particular sampling rate, which is less than the minimum we determined above (and greater than 2fmax ), such as fs = 70 kHz. In order to achieve the required 60 dB suppression of the aliased replicas, we must now use a more complex prefilter—one that has a steeper transition width, such as a higherorder Butterworth. An Nth order Butterworth filter has magnitude response
H(f )2 =
1 1 + (f /f0 )2N
Given fs , determine the minimum filter order N in order for the filter to attenuate less than Apass = 1 dB in the passband and the total suppression of the spectral images to be greater than A = 60 dB. 1.17 Computer Experiment: Butterworth Prefilter Design. Using the methods of the previous problem, derive a “design curve” for the prefilter, that is, an expression for the Butterworth filter order N as a function of the sampling rate fs and stopband attenuation A. Assume fmax = 20 kHz and Apass = 1 dB for the passband attenuation. For each of the attenuation values A = 40, 50, 60, 70, 80 dB, plot the filter order N versus fs in the range 50 ≤ fs ≤ 120 kHz. Identify on these graphs the design points of the Problems 1.15 and 1.16.
1.18 The significant frequency range of an analog signal extends to 10 kHz. Beyond 10 kHz, the signal spectrum attenuates at a rate of 80 dB per decade. The signal is to be sampled at a rate of 30 kHz. The aliased frequency components introduced into the 10 kHz range of interest must be kept below 60 dB, as compared to the signal components. Suppose we use an antialiasing prefilter whose passband is flat over the 10 kHz interval. Beyond 10 kHz, it attenuates at a certain rate that must be steep enough to satisfy the above sampling requirements. What is this attenuation rate in dB per decade? Explain your reasoning. What is the minimum filter order that we must use? What is the prefilter’s attenuation rate if we increase the sampling rate to 50 kHz? What is the filter order in this case?
59
1.8. PROBLEMS 1.19 An analog input signal to a DSP system has spectrum:
Xin (f ) =
1
1 + f /fa
2Na
where fa and Na are given. The highest frequency of interest is fmax = 2fa . The signal is to be sampled at a rate fs . It is required that the aliased spectral components within the frequency range of interest be suppressed by more than A dB relative to the signal components, that is, they must be at least A dB below the value of the signal components throughout the 0 ≤ f ≤ fmax range of interest. a. Assuming that no antialiasing prefilter is used, set up and solve an equation for the minimum sampling rate fs , in terms of the quantities fa , Na , A. b. Next, suppose that an Nth order Butterworth analog prefilter is to be used to aid the sampling process. Let f0 be the filter’s 3dB normalization frequency. It is required that the prefilter’s attenuation within the 0 ≤ f ≤ fmax band of interest remain less than B dB. Set up an equation for f0 that would guarantee this condition. Then, set up an equation for the minimum fs that would guarantee the desired A dB suppression of the spectral images. c. Show that fs is given approximately by
fs = fmax 1 + 10A/20(N+Na ) When is this approximation valid? Show that this expression also covers part (a) if you set N = 0. Discuss the meaning of the limit N → ∞ in terms of the sampling theorem. 1.20 In Problem 1.19, we implicitly assumed that the prefilter’s order N was given, and we determined f0 and fs . Here, we assume that fs is given and is equal to some value above 2fmax . Show that the minimum prefilter order that must be used to guarantee A dB suppression of the spectral images is approximately linearly related to A via an equation of the form:
N = aA + b Determine expressions for a and b in terms of the given quantities. 1.21 The operation of flattop practical sampling depicted in Fig. 1.5.1 may be thought of as filterˆ(t) through an analog linear filter whose impulse response ing the ideally sampled signal x is the sampling pulse p(t), as shown in Fig. 1.8.2. Show that Eq. (1.5.2) can be written as the I/O convolutional equation of such a filter:
xflat (t)=
∞
−∞
ˆ(t ) dt = p(t − t )x
∞
n=−∞
x(nT)p(t − nT)
ˆ(t) is given by Eq. (1.5.1). In the frequency domain, this translates to Xflat (f )= where x ), where P(f ) is the spectrum of sampling pulse p(t). P(f )X(f
Determine P(f ) for a flat pulse p(t) of duration τ seconds. For the case τ = T/5, make a sketch of Xflat (f ) over the range −6fs ≤ f ≤ 6fs .
60
1. SAMPLING AND RECONSTRUCTION
x(nT) δ(tnT)
p(t)
^ x(t)
t nT
x(nT) p(t −nT)
linear system
ideally sampled signal
t
τ
0
xflat(t) flattop sampled signal
t nT
Fig. 1.8.2 Flattop sampling as filtering.
1.22 After having been properly prefiltered by an antialiasing filter, an analog signal is sampled at a rate of 6 kHz. The digital signal is then filtered by a digital filter designed to act as an ideal lowpass filter with cutoff frequency of 1 kHz. The filtered digital signal is then fed into a staircase D/A reconstructor and then into a lowpass antiimage postfilter. The overall reconstructor is required to suppress the spectral images caused by sampling by more than A = 40 dB. Determine the least stringent specifications for the analog postfilter that will satisfy this requirement. 1.23 Consider an arbitrary D/A reconstructing filter with impulse response h(t) and corresponding frequency response H(f ). The analog signal at the output of the reconstructor is related to the incoming time samples x(nT) by
xa (t)=
n
x(nT)h(t − nT)
Show this result in two ways: a. Using convolution in the time domain.
) and taking inverse Fourier transforms. b. Starting with Xa (f )= H(f )X(f
1.24 The sinusoidal signal x(t)= sin(2πf0 t) is sampled at a rate fs and the resulting samples are then reconstructed by an arbitrary analog reconstructing filter H(f ). Show that the analog signal at the output of the reconstructor will have the form:
xrec (t)=
∞
m=−∞
Am sin(2πfm t + θm )
What are the frequencies fm ? How are the quantities Am and θm related to the frequency response H(f )? Determine the quantities Am and θm for the two cases of a staircase reconstructor and an ideal reconstructor. 1.25 The sum of sinusoids
y(t)= A1 e2πjf1 t + A2 e2πjf2 t is sampled at a rate fs such that fs > 2f1  and fs > 2f2 . The resulting samples are then filtered digitally by a staircaseequalizing digital filter and then reconstructed by a staircase reconstructor, as shown in Fig. 1.6.9. If a final postfilter is not used, show that the resulting analog signal at the output of the reconstructor will be
ya (t)=
∞
m=−∞
A1m e2πjf1m t + A2m e2πjf2m t
where A1m = A1 f1 /f1m , A2m = A2 f2 /f2m , and f1m = f1 + mfs , f2m = f2 + mfs . What would a final postfilter do to each of these terms?
2 Quantization
2.1 Quantization Process Sampling and quantization are the necessary prerequisites for any digital signal processing operation on analog signals. A sampler and quantizer are shown in Fig. 2.1.1 [40–45]. The hold capacitor in the sampler holds each measured sample x(nT) for at most T seconds during which time the A/D converter must convert it to a quantized sample, xQ (nT), which is representable by a finite number of bits, say B bits. The Bbit word is then shipped over to the digital signal processor.
sampler & quantizer x(t) analog signal
sample & hold T
x(nT)
quantized signal xQ(nT)
A/D converter
sampled signal
to DSP B bits/sample
Fig. 2.1.1 Analog to digital conversion.
After digital processing, the resulting Bbit word is applied to a D/A converter which converts it back to analog format generating a staircase output. In practice, the sample/hold and ADC may be separate modules or may reside on board the same chip. The quantized sample xQ (nT), being represented by B bits, can take only one of 2B possible values. An A/D converter is characterized by a fullscale range R, which is divided equally (for a uniform quantizer) into 2B quantization levels, as shown in Fig. 2.1.2. The spacing between levels, called the quantization width or the quantizer resolution, is given by:
Q=
R 2B
This equation can also be written in the form:
61
(2.1.1)
62
2. QUANTIZATION
x(t) R/2 3Q
x(nT) quantization levels
2Q
xQ(nT)
Q
R
0 Q 2Q 3Q R/2
Q t
nT Fig. 2.1.2 Signal quantization.
R = 2B Q
(2.1.2)
which gives the number of quantization levels. Typical values of R in practice are between 1–10 volts. Figure 2.1.2 shows the case of B = 3 or 2B = 8 levels, and assumes a bipolar ADC for which the possible quantized values lie within the symmetric range:
−
R 2
≤ xQ (nT)
= 0; i) dac = 0.5 * (dac + b[i]);
H¨ orner’s rule
dac = R * (dac  0.5);
shift and scale
b[0] = 1  b[0];
restore MSB
return dac; }
Its usage is:
bits are dimensioned as b[0], b[1], . . . , b[B − 1]
75
2.4. A/D CONVERTERS xQ = dac(b, B, R);
Because of the default indexing of arrays in C, the Bdimensional bit vector b[i] is indexed for i = 0, 1, . . . , B− 1. The declaration and dimensioning of b[i] should be done in the main program. For example, if B = 4, the main program must include a line: int b[4];
The array b[i] can also be allocated dynamically for any desired value of B using calloc. The main program must include the lines: int *b; B = 4; b = (int *) calloc(B, sizeof(int));
b is a pointer to int B can also be read from stdin allocates B int slots
The internal forloop in dac.c implements a variant of H¨ orner’s rule for evaluating a polynomial. The result is the binary sum b1 2−1 + b2 2−2 + · · · + bB 2−B which is then shifted by 0.5 and scaled by R. We leave the details of H¨ orner’s algorithm for Problems 2.10–2.13. This algorithm will be used again later for the evaluation of ztransforms and DTFTs. (See the MATLAB function dtft.m in Appendix D.) The routine dac may be modified easily to implement the natural binary and offset binary converter types, given by Eqs. (2.3.1) and (2.3.3).
2.4 A/D Converters A/D converters quantize an analog value x so that it is represented by B bits [b1 , b2 , . . . , bB ], as shown in Fig. 2.4.1. ADCs come in many varieties, depending on how the conversion process is implemented. One of the most popular ones is the successive approximation A/D converter whose main building block is a D/A converter in a feedback loop. It is shown in Fig. 2.4.2. MSB
x ADC analog input
. . .
R
LSB
b1 b2 b3
B output bits
. . .
bB
Fig. 2.4.1 Bbit A/D converter.
The conversion algorithm is as follows. Initially all B bits are cleared to zero, b = [0, 0, . . . , 0], in the successive approximation register (SAR). Then, starting with the MSB b1 , each bit is turned on in sequence and a test is performed to determine whether that bit should be left on or turned off. The control logic puts the correct value of that bit in the right slot in the SAR register. Then, leaving all the tested bits set at their correct values, the next bit is turned on in
76
2. QUANTIZATION

b1
C = 1/0
SAR b2 b3
bB
MSB
. . .
. . .
xQ
ADC
comparator +
. . .
analog input
x
. . .
x
LSB
b1 b2 b3 DAC
. . .
xQ
bB
B output bits
Fig. 2.4.2 Successive approximation A/D converter.
the SAR and the process repeated. After B tests, the SAR will hold the correct bit vector b = [b1 , b2 , . . . , bB ], which can be sent to the output. At each test, the SAR bit vector b is applied to the DAC which produces the analog quantized value xQ . When a given bit is turned on, the output xQ of the DAC is compared with the analog input x to the ADC. If x ≥ xQ , that bit is kept on; else, it is turned off. The output C of the comparator is the correct value of the bit being tested. The algorithm is summarized below: for each x to be converted, do: initialize b = [0, 0, . . . , 0] for i = 1, 2, . . . , B do: bi = 1 xQ = dac(b, B, R) if (x ≥ xQ ) C=1 else C=0
bi = C
Therefore, C becomes a serial representation of the bit vector b. The algorithm imitates the operations shown in Fig. 2.4.2. It can be written more compactly as follows: for each x to be converted, do: initialize b = [0, 0, . . . , 0] for i = 1, 2, . . . , B do: bi = 1 xQ = dac(b, B, R)
bi = u(x − xQ )
where u(x) is the unitstep function, defined by:
u(x)=
1 0
if x ≥ 0 if x < 0
As stated above, the algorithm applies to the natural and offset binary cases (with corresponding versions of dac). It implements truncation of x to the quantization level just below, instead of rounding to the nearest level.
77
2.4. A/D CONVERTERS
The algorithm converges to the right quantization level by performing a binary search through the quantization levels. This can be seen with the help of the first column of Table 2.3.2. The test b1 = 1 or 0 determines whether x lies in the upper or lower half of the levels. Then, the test b2 = 1/0 determines whether x lies in the upper/lower half of the first half, and so on. Some examples will make this clear. Example 2.4.1: Convert the analog values x = 3.5 and x = −1.5 volts to their offset binary representation, assuming B = 4 bits and R = 10 volts, as in Table 2.3.2. Solution: The following table shows the successive tests of the bits, the corresponding DAC output xQ at each test, and the comparator output C = u(x − xQ ). test
b1 b2 b3 b4
b1 b2 b3 b4
xQ
0 0 0 1
0.000 2.500 3.750 3.125
1101
3.125
1 1 1 1
0 1 1 1
0 0 1 0
C = u(x − xQ ) 1 1 0 1
For each bit pattern, the DAC inputs/outputs were looked up in the first/fifth columns of Table 2.3.2, instead of computing them via Eq. (2.3.3). When b1 is tested, the DAC output is xQ = 0 which is less than x; therefore, b1 passes the test. Similarly, b2 passes the test and stays on. On the other hand bit b3 fails the test because x < xQ = 3.75; thus, b3 is turned off. Finally, b4 passes. The last row gives the final content of the SAR register and the corresponding quantized value xQ = 3.125. Even though x = 3.5 lies in the upper half between the two levels xQ = 3.75 and xQ = 3.125, it gets truncated down to the lower level. The C column is a serial representation of the final answer. Note also the binary searching taking place: b1 = 1 selects the upper half of the levels, b2 = 1 selects the upper half of the upper half, and of these, b3 = 0 selects the lower half, and of those, b4 = 1 selects the upper half. For the case x = −1.5 we have the testing table test
b1 b2 b3 b4
xQ
C = u(x − xQ )
0 0 0 1
0.000 −2.500 −1.250 −1.875
0 1 0 1
0101
−1.875
b1 b2 b3 b4 1 0 0 0
0 1 1 1
0 0 1 0
Bit b1 fails the test because x < xQ = 0, and therefore, b1 = 0, and so on. Again, the final quantized value xQ = −1.875 is that obtained by truncating x = −1.5 to the level below it, even though x lies nearer the level above it.
In order to quantize by rounding to the nearest level, we must shift x by half the spacing between levels, that is, use:
y =x+
1 Q 2
78
2. QUANTIZATION
in place of x and perform truncation on y. If x is already in the upper half between two levels, then y will be brought above the upper level and will be truncated down to that level. The conversion algorithm for rounding is: for each x to be converted, do: y = x + Q/2 initialize b = [0, 0, . . . , 0] for i = 1, 2, . . . , B do: bi = 1 xQ = dac(b, B, R)
bi = u(y − xQ )
Example 2.4.2: To quantize the value x = 3.5 by rounding, we shift it to y = x + Q/2 = 3.5 + 0.625/2 = 3.8125. The corresponding test table will be test
b1 b2 b3 b4
b1 b2 b3 b4
xQ
0 0 0 1
0.000 2.500 3.750 4.375
1110
3.750
1 1 1 1
0 1 1 1
0 0 1 1
C = u(y − xQ ) 1 1 1 0
Only b4 fails the test because with it on, the DAC output xQ = 4.375 exceeds y. The final value xQ = 3.750 is the rounded up version of x = 3.5. For the case x = −1.5, we have y = −1.5 + 0.625/2 = −1.1875. The corresponding test table is test
b1 b2 b3 b4
xQ
C = u(y − xQ )
0 0 0 1
0.000 −2.500 −1.250 −0.625
0 1 1 0
0110
−1.250
b1 b2 b3 b4 1 0 0 0
0 1 1 1
0 0 1 1
The value xQ = −1.250 is the rounded up version of x = −1.5.
The successive approximation algorithm for the two’s complement case is slightly different. Because the MSB is complemented, it must be treated separately from the other bits. As seen in the last column of Table 2.3.2, the bit b1 determines whether the number x is positive or negative. If x ≥ 0 then, we must have b1 = 0; else b1 = 1. We can express this result by b1 = 1 − u(x), or, b1 = 1 − u(y) if we are quantizing by rounding. The remaining bits, {b2 , b3 , . . . , bB }, are tested in the usual manner. This leads to the following two’s complement conversion algorithm with rounding:
79
2.4. A/D CONVERTERS
for each x to be converted, do: y = x + Q/2 initialize b = [0, 0, . . . , 0] b1 = 1 − u(y) for i = 2, 3, . . . , B do: bi = 1 xQ = dac(b, B, R)
bi = u(y − xQ )
Example 2.4.3: The two’s complement rounded 4bit representations of x = 3.5 and x = −1.5 are:
x = 3.5 x = −1.5
⇒ ⇒
xQ = 3.750 xQ = −1.250
⇒ ⇒
b = [0, 1, 1, 0] b = [1, 1, 1, 0]
They are obtained from the offset binary by complementing the MSB. The quantized values xQ are the same as in the offset binary case — only the binary codes change.
Example 2.4.4: Consider the sampled sinusoid x(n)= A cos(2πf n), where A = 3 volts and f = 0.04 cycles/sample. The sinusoid is evaluated at the ten sampling times n = 0, 1, . . . , 9 and x(n) is quantized using a 4bit successive approximation ADC with fullscale range R = 10 volts. The following table shows the sampled and quantized values xQ (n) and the offset binary and two’s complement binary codes representing them.
n
x(n)
xQ (n)
2’s C
offset
0 1 2 3 4 5 6 7 8 9
3.000 2.906 2.629 2.187 1.607 0.927 0.188 −0.562 −1.277 −1.912
3.125 3.125 2.500 1.875 1.875 0.625 0.000 −0.625 −1.250 −1.875
0101 0101 0100 0011 0011 0001 0000 1111 1110 1101
1101 1101 1100 1011 1011 1001 1000 0111 0110 0101
The 2’s complement and offset binary codes differ only in their MSB. The quantized values they represent are the same.
The following routine adc.c simulates the operation of a bipolar two’s complement successive approximation ADC. It makes successive calls to dac.c to determine each bit. /* adc.c  successive approximation A/D converter */ #include <math.h> double dac(); int u();
80
2. QUANTIZATION
void adc(x, b, B, R) double x, R; int *b, B; { int i; double y, xQ, Q; Q = R / pow(2, B); y = x + Q/2;
quantization width Q = R/2B
for (i = 0; i < B; i++) b[i] = 0;
initialize bit vector
b[0] = 1  u(y);
determine MSB
for (i = 1; b[i] xQ = b[i] }
loop starts with i = 1
i < B; i++) { = 1; dac(b, B, R); = u(yxQ);
rounding
turn ith bit ON
compute DAC output test and correct bit
}
The inputs to the routine are the analog value x to be converted and the fullscale range R. The outputs are the B bits b = [b1 , b2 , . . . , bB ] representing x in the two’s complement representation. The unitstep function u(x) is implemented by the routine: /* u.c  unit step function */ int u(x) double x; { if (x >= 0) return 1; else return 0; }
Example 2.4.5: This example illustrates the usage of the routines adc and dac. Consider L = 50 samples of a sinusoid x(n)= A cos(2πf n) of digital frequency f = 0.02 cycles/sample and amplitude A = 4. The signal x(n) is quantized using a successive approximation two’s
complement converter with rounding, as implemented by the routine adc. The following forloop was used in the main program for calculating xQ (n): for (n=0; n 1:
X(z)= 1 − z−2 + z−4 − z−6 + z−8 − · · · Derive a rational expression for X(z) in two ways: (a) by summing the above series, and (b) by showing that it satisfies the equation X(z)= 1 − z−2 X(z).
Derive also the inverse ztransform x(n) for all n.
5.16 Without using partial fractions, determine the causal inverse ztransforms of: 1 1 + z −4 1 b. X(z)= 1 − z −4 1 c. X(z)= 1 + z −8 1 d. X(z)= 1 − z −8 a. X(z)=
5.17 Using partial fraction expansions, determine the inverse ztransforms of Problem 5.16. Verify that you get the same answers as in that problem. 5.18 Consider a transfer function H(z)= N(z)/D(z), where the numerator and denominator polynomials have realvalued coefficients and degrees L and M in z−1 , and assume L > M. Show that H(z) can be written in the form:
H(z)= Q(z)+
K
i=1
bi0 + z−1 bi1 1 + ai1 z−1 + ai2 z−2
where Q(z) is a polynomial of degree L − M in z−1 and the secondorder sections have real coefficients. The number of sections K is related to M by K = M/2 if M is even and K = (M − 1)/2 if M is odd. This result forms the basis of the parallel realization form of H(z). 5.19 Determine the factorization into firstorder zeros of: 1 − z−D =
D− +1
(1 − zk z−1 )
1 + z−D =
D− +1
(1 − zk z−1 )
k=0
k=0
where D is an integer. What are the zeros zk in the two cases? For D = 4 and D = 8, place these zeros on the zplane with respect to the unit circle. 5.20 Given a > 0 and integer D, repeat the previous problem for: 1 − az−D =
D− +1
(1 − zk z−1 )
1 + az−D =
D− +1
(1 − zk z−1 )
k=0
k=0
213
5.6. PROBLEMS 5.21 Prove the “modulation” property of ztransforms: Z
x(n)−→ X(z)
⇒
Z
an x(n)−→ X(z/a)
For a = ejω0 , show that in the frequency domain this property becomes:
x(n)−→ X(ω)
⇒
ejω0 n x(n)−→ X(ω − ω0 )
5.22 Given the DTFT equation (5.4.1), prove the inverse DTFT, Eq. (5.4.6). 5.23 Prove the Parseval equation (5.4.7). 5.24 For realvalued signals, prove the hermitian properties (5.4.8) and (5.4.9). What are the hermitian properties satisfied by the real and imaginary parts of the DTFT spectrum?
6 Transfer Functions
6.1 Equivalent Descriptions of Digital Filters In this chapter, with the aid of ztransforms, we develop several mathematically equivalent ways to describe and characterize FIR and IIR filters, namely, in terms of their:
• • • • • • •
Transfer function H(z) Frequency response H(ω) Block diagram realization and sample processing algorithm I/O difference equation Pole/zero pattern Impulse response h(n) I/O convolutional equation
The most important one is the transfer function description because from it we can easily obtain all the others. Figure 6.1.1 shows the relationships among these descriptions. The need for such multiple descriptions is that each provides a different insight into the nature of the filter and each serves a different purpose.
impulse response h(n)
I/O difference equation(s)
I/O convolutional equation
transfer function H(z)
block processing
pole/zero pattern
filter design method filter design specifications
frequency response H(ω)
blockdiagram realization
Fig. 6.1.1 Equivalent descriptions of digital filters.
214
sample processing
215
6.2. TRANSFER FUNCTIONS
In practice, a typical usage of these descriptions is to start by specifying a set of desired frequency response specifications, that is, the desired shape of H(ω) (lower left corner in Fig. 6.1.1). Then, through a filter design method, obtain a transfer function H(z) that satisfies the given specifications. From H(z) one can then derive a block diagram realization and the corresponding samplebysample processing algorithm that tells how to operate the designed filter in real time (lower right corner of Fig. 6.1.1). For an FIR filter, one can alternatively obtain the impulse response h(n) and then use one of the convolutionbased block processing methods to implement the operation of the filter (upper right corner of Fig. 6.1.1).
6.2 Transfer Functions Here, we illustrate the central role played by the transfer function H(z) of a filter by showing how to pass back and forth from one description to another. Given a transfer function H(z) one can obtain: (a) the impulse response h(n), (b) the difference equation satisfied by the impulse response, (c) the I/O difference equation relating the output y(n) to the input x(n), (d) the block diagram realization of the filter, (e) the samplebysample processing algorithm, (f) the pole/zero pattern, (g) the frequency response H(ω). Conversely, given any of (a)–(g) as the starting point, one can obtain H(z) and from it the rest of (a)–(g). As an example, consider the transfer function:
H(z)=
5 + 2z−1 1 − 0.8z−1
(6.2.1)
To obtain the impulse response, we use partial fraction expansion to write it in the form:
H(z)=
5 + 2z−1 A1 7.5 = A0 + = −2.5 + 1 − 0.8z−1 1 − 0.8z−1 1 − 0.8z−1
where A0 and A1 are obtained by:
5z + 2 2 5 + 2z−1 = = = −2.5 A0 = H(z)z=0 = 1 − 0.8z−1 z=0 z − 0.8 z=0 −0.8 A1 = (1 − 0.8z−1 )H(z)z=0.8 = (5 + 2z−1 )z=0.8 = 5 + 2/0.8 = 7.5
Assuming the filter is causal, we find:
h(n)= −2.5δ(n)+7.5(0.8)n u(n)
(6.2.2)
The difference equation satisfied by h(n) can be obtained from H(z). The standard approach is to eliminate the denominator polynomial of H(z) and then transfer back to the time domain. Starting with Eq. (6.2.1) and multiplying both sides by the denominator, we find
(1 − 0.8z−1 )H(z)= 5 + 2z−1
⇒
H(z)= 0.8z−1 H(z)+5 + 2z−1
216
6. TRANSFER FUNCTIONS
Taking inverse ztransforms of both sides and using the linearity and delay properties, we obtain the difference equation for h(n):
h(n)= 0.8h(n − 1)+5δ(n)+2δ(n − 1)
(6.2.3)
It is easily verified that Eq. (6.2.2) is the causal solution, that is, the solution with the causal initial condition h(−1)= 0. Given the impulse response h(n), we can obtain the general I/O convolutional equation for the filter, that is,
yn = h0 xn + h1 xn−1 + h2 xn−2 + h3 xn−3 + · · · = 5xn + 7.5 (0.8)xn−1 + (0.8)2 xn−2 + (0.8)3 xn−3 + · · ·
It can be rearranged into a difference equation for y(n) using the timedomain techniques of Chapter 3, as in Example 3.4.7. This difference equation can be determined very quickly using ztransforms with the aid of the zdomain equivalent of convolution:
Y(z)= H(z)X(z) Again, the standard procedure is to eliminate denominators and go back to the time domain. For this example, we have:
Y(z)= H(z)X(z)=
5 + 2z−1 X(z) ⇒ 1 − 0.8z−1
(1 − 0.8z−1 )Y(z)= (5 + 2z−1 )X(z)
which can be written as
Y(z)−0.8z−1 Y(z)= 5X(z)+2z−1 X(z) Taking inverse ztransforms of both sides, we have
y(n)−0.8y(n − 1)= 5x(n)+2x(n − 1) Therefore, the I/O difference equation is:
y(n)= 0.8y(n − 1)+5x(n)+2x(n − 1)
(6.2.4)
Note that Eq. (6.2.3) is a special case of this, with x(n)= δ(n) and y(n)= h(n). If the difference equation (6.2.4) was the starting point, we could obtain H(z) by reversing all of the above steps, that is, taking ztransforms of both sides
Y(z)= 0.8z−1 Y(z)+5X(z)+2z−1 X(z) ⇒ (1 − 0.8z−1 )Y(z)= (5 + 2z−1 )X(z) and solving for the ratio
H(z)=
Y(z) 5 + 2z−1 = X(z) 1 − 0.8z−1
Once the I/O difference equation is determined, one can mechanize it by a block diagram. For example, Eq. (6.2.4) can be implemented as shown in Fig. 6.2.1. This is
217
6.2. TRANSFER FUNCTIONS
x(n)
y(n)
5
z1 w1(n)=y(n1)
z1 v1(n)=x(n1) 2
0.8
Fig. 6.2.1 Direct form realization of H(z).
referred to as the direct form realization because it realizes directly the various terms in the righthand side of Eq. (6.2.4). As in the FIR case, the sample processing algorithm can be obtained by assigning internal state variables to all the delays that are present in the block diagram. That is, we may define
v1 (n)= x(n − 1) ⇒
v1 (n + 1)= x(n)
where v1 (n) is the content of the xdelay at time n. Similarly, we define:
w1 (n)= y(n − 1) ⇒
w1 (n + 1)= y(n)
so that w1 (n) is the content of the ydelay at time n. In terms of these definitions, we can replace Eq. (6.2.4) by the system of equations: (compute output) (update states)
y(n)= 0.8w1 (n)+5x(n)+2v1 (n) v1 (n + 1)= x(n) w1 (n + 1)= y(n)
It may be written as the repetitive sample processing algorithm: for each input sample x do: y = 0.8w1 + 5x + 2v1
v1 = x w1 = y
(direct form)
(6.2.5)
The frequency response of this particular filter can be obtained by replacing z by ejω into H(z). This substitution is valid here because the filter is stable and therefore its ROC, z > 0.8, contains the unit circle. We find:
H(z)=
5(1 + 0.4z−1 ) 1 − 0.8z−1
⇒
H(ω)=
5(1 + 0.4e−jω ) 1 − 0.8e−jω
Using the identity
1 − ae−jω  = 1 − 2a cos ω + a2
which is valid for any realvalued a, we obtain an expression for the magnitude response:
218
6. TRANSFER FUNCTIONS
√ 5 1 + 0.8 cos ω + 0.16 H(ω) = √ 1 − 1.6 cos ω + 0.64 This quantity may be plotted with the help of the pole/zero geometric pattern. The filter has a zero at z = −0.4 and a pole at z = 0.8. Fig. 6.2.2 shows the pole/zero locations relative to the unit circle.
= zeros = poles
zplane
e jω
0.4
35
H(ω)
ω
35/21
0.8 unit circle
0
π
ω
Fig. 6.2.2 Pole/zero pattern and magnitude response.
A quick sketch of the magnitude response H(ω) can be obtained by letting the point ejω trace the unit circle and drawing peaks when passing near poles and dips when passing near zeros. The moving point ejω is nearest to the pole z = 0.8 when ω = 0 and therefore there must be a peak there. Similarly, at ω = π there must be a dip because ejω is closest to the zero z = −0.4. In particular, setting z = 1 or ω = 0, and z = −1 or ω = π, we can calculate the actual frequency response values at the endpoints of the Nyquist interval:
5+2 = 35 H(ω)ω=0 = H(z)z=1 = 1 − 0.8 5−2 5 35 H(ω)ω=π = H(z)z=−1 = = = 1 + 0.8 3 21
This filter acts like a lowpass filter because it emphasizes low frequencies and attenuates high frequencies. The highest frequency is attenuated by a factor of 21 relative to the lowest one: 1 H(π) = H(0) 21 or, in decibels:
H(π) 1 = 20 log = −26.4 dB 10 H(0) 21
20 log10
The block diagram realization of a transfer function is not unique. Different but mathematically equivalent forms of the transfer function may lead to a different set of I/O difference equations which are implemented by a different block diagram and corresponding sample processing algorithm. For our example, the partial fraction expansion form of Eq. (6.2.1)
219
6.2. TRANSFER FUNCTIONS
H(z)=
5 + 2z−1 7.5 = −2.5 + 1 − 0.8z−1 1 − 0.8z−1
may be thought of as a parallel implementation, that is, the sum of two transfer functions
H(z)= H1 (z)+H2 (z) where H1 (z)= −2.5 and H2 (z)= 7.5/(1 − 0.8z−1 ). Fig. 6.2.3 shows a block diagram implementation of this form. At first glance, it may not be obvious that the transfer function of this block diagram is the above H(z).
2.5
w(n)
x(n)
y(n) w0
7.5
z1 w(n1) w
1
0.8 Fig. 6.2.3 Parallel form realization of H(z).
To verify it, we follow the standard procedure of assigning labels, that is, names to all the signal lines that do not already have a label. The output adder has two inputs, one due to the direct connection of the input to the output through the multiplier −2.5, that is, the term −2.5x(n). The other input is assigned a temporary name w(n). Thus, the output adder equation becomes
y(n)= w(n)−2.5x(n)
(6.2.6)
The quantity w(n) is recognized as the output of the filter H2 (z) with input x(n). The I/O difference equation of H2 (z) is
w(n)= 0.8w(n − 1)+7.5x(n)
(6.2.7)
The two equations (6.2.6) and (6.2.7) together describe the operation of the block diagram in the time domain. Transforming both equations to the zdomain, we obtain
Y(z) = W(z)−2.5X(z) W(z) = 0.8z−1 W(z)+7.5X(z) ⇒
W(z)=
7.5X(z) 1 − 0.8z−1
and therefore,
Y(z)= W(z)−2.5X(z)=
7.5X(z) − 2.5X(z) 1 − 0.8z−1
220
6. TRANSFER FUNCTIONS
Solving for the ratio Y(z)/X(z) gives the corresponding transfer function:
H(z)=
7.5 Y(z) = − 2.5 X(z) 1 − 0.8z−1
The sample processing algorithm corresponding to this block diagram is obtained by introducing an internal state holding the content of the delay. That is, we define
w0 (n) = w(n) w1 (n) = w(n − 1)
⇒
w1 (n + 1)= w0 (n)
Then, Eqs. (6.2.6) and (6.2.7) can be replaced by the system:
w0 (n)= 0.8w1 (n)+7.5x(n) y(n)= w0 (n)−2.5x(n) w1 (n + 1)= w0 (n) which can be written in the algorithmic form: for each input sample x do: w0 = 0.8w1 + 7.5x y = w0 − 2.5x
(parallel form)
(6.2.8)
w1 = w0
Other block diagram realizations can be derived by rearranging the I/O computations differently. A third realization is the socalled canonical form realization and is depicted in Fig. 6.2.4. It can be justified as follows. Starting with the zdomain filtering equation
x(n)
w(n) w0 z1 w(n1) w1 0.8
5
y(n)
2
Fig. 6.2.4 Canonical form realization of H(z).
Y(z)= H(z)X(z)=
5 + 2z−1 X(z) 1 − 0.8z−1
we separate out the effect of the filter’s denominator by defining the temporary quantity
W(z)=
1 X(z) 1 − 0.8z−1
then, the output ztransform can be computed by
Y(z)= (5 + 2z−1 )W(z)
221
6.2. TRANSFER FUNCTIONS Writing these equations in the time domain, we obtain
W(z)=
1 X(z) ⇒ 1 − 0.8z−1
W(z)= 0.8z−1 W(z)+X(z)
or,
w(n)= 0.8w(n − 1)+x(n) Similarly,
Y(z)= 5W(z)+2z−1 W(z) ⇒
y(n)= 5w(n)+2w(n − 1)
Thus, we obtain the system of I/O equations
w(n) = 0.8w(n − 1)+x(n) y(n) = 5w(n)+2w(n − 1) which are mechanized in the block diagram of Fig. 6.2.4. Introducing internal states
w0 (n) = w(n) w1 (n) = w(n − 1)
⇒
w1 (n + 1)= w0 (n)
we rewrite the above system as:
w0 (n)= 0.8w1 (n)+x(n) y(n)= 5w0 (n)+2w1 (n) w1 (n + 1)= w0 (n) which can be written in the algorithmic form: for each input sample x do: w0 = 0.8w1 + x y = 5w0 + 2w1
(canonical form)
(6.2.9)
w1 = w0
A fourth block diagram realization can be obtained by transposing the canonical realization following the transposition rules of replacing adders by nodes, nodes by adders, reversing all flows, and exchanging input with output. The resulting transposed realization is depicted in Fig. 6.2.5. Again, we have assigned an internal state variable w1 (n) to hold the contents of the delay register. The input to the delay is the sum 2x(n)+0.8y(n) which gets delayed and becomes w1 (n). Thus,
w1 (n)= 2x(n − 1)+0.8y(n − 1) The complete I/O description of this realization is then given by the system:
222
6. TRANSFER FUNCTIONS
5
y(n)
x(n) w1(n) z1
2
0.8
Fig. 6.2.5 Transposed realization of H(z).
y(n)= w1 (n)+5x(n) w1 (n + 1)= 2x(n)+0.8y(n) which translates to the following sample processing algorithm: for each input sample x do: y = w1 + 5x w1 = 2x + 0.8y
(transposed form)
(6.2.10)
To verify that this realization describes the same transfer function, we transform the I/O equations to the zdomain:
Y(z)= W1 (z)+5X(z) zW1 (z)= 2X(z)+0.8Y(z) Then, solve the second for W1 (z), insert it in the first, and solve for the ratio
Y(z)/X(z). We have: W1 (z)= 0.8z−1 Y(z)+2z−1 X(z) and
Y(z)= W1 (z)+5X(z)= 0.8z−1 Y(z)+2z−1 X(z)+5X(z) which gives
H(z)=
5 + 2z−1 Y(z) = X(z) 1 − 0.8z−1
Given a particular block diagram implementation, one can easily translate the corresponding sample processing algorithm into a software or hardware routine. For example, the canonical form of Eq. (6.2.9) can be implemented by the following C routine filter.c:
223
6.2. TRANSFER FUNCTIONS /* filter.c  IIR example routine */ double filter(x, w) double x, *w; { double y;
usage: y = filter(x, w);
w[0] = 0.8 * w[1] + x; y = 5 * w[0] + 2 * w[1];
compute output
w[1] = w[0];
update internal state
return y; }
The array w must be declared to be a twodimensional array in the main program. The following program segment illustrates the usage of this routine for processing N input samples: w = (double *) calloc(2, sizeof(double)); for (n=0; n ejω0  = 1. Assume a filter of the form:
H(z)=
N(z) N(z) = D(z) (1 − p1 z−1 )(1 − p2 z−1 )· · · (1 − pM z−1 )
233
6.3. SINUSOIDAL RESPONSE
cos(ω0n) n
0
cos(ω0n)u(n) n
0
Fig. 6.3.3 Doublesided and onesided sinewaves.
with M poles that lie strictly within the unit circle, so that the filter is stable and causal. The output ztransform will be:
Y(z)= H(z)X(z)=
N(z) (1 − ejω0 z−1 )(1 − p1 z−1 )(1 − p2 z−1 )· · · (1 − pM z−1 )
Assuming that the degree of the numerator polynomial N(z) is strictly less than the degree M+1 of the denominator,† we can write the PF expansion:
Y(z)=
C 1 − ejω0 z−1
+
B1 1 − p1 z−1
+
B2 1 − p2 z−1
+ ··· +
BM 1 − pM z−1
The PF expansion coefficients are obtained in the usual fashion, via Eq. (5.5.2). In particular, the coefficient of the first term will be:
C = (1 − ejω0 z−1 )Y(z)z=ejω0 = (1 − ejω0 z−1 )
H(z) 1 − ejω0 z−1
z=ejω0
Canceling the (1 − ejω0 z−1 ) factors, we find that C is none other than the frequency response H(ω) evaluated at ω = ω0 , that is,
C = H(z)z=ejω0 = H(ω0 )
(6.3.10)
Therefore, the PF expansion will read:
Y(z)=
H(ω0 ) 1 − ejω0 z−1
+
B1 1 − p1 z−1
+
B2 1 − p2 z−1
+ ··· +
BM 1 − pM z−1
Taking the causal inverse ztransform (with ROC z > 1), we find for n ≥ 0:
y(n)= H(ω0 )ejω0 n + B1 pn1 + B2 pn2 + · · · + BM pnM
(6.3.11)
Because the filter was assumed to have all its poles inside the unit circle, namely,
pi  < 1, it follows that in the limit of large n, the pni terms will drop to zero exponentially giving the steadystate output: † This
assumption is not critical. The same conclusions can be drawn otherwise.
234
6. TRANSFER FUNCTIONS
y(n)→ H(ω0 )ejω0 n
as n → ∞
For smaller values of n, Eq. (6.3.11) gives the transient response of the filter. Example 6.3.1: Determine the full transient response of the filter H(z)=
5 + 2z−1 1 − 0.8z−1
for a causal complex sinusoidal input of frequency ω0 .
Solution: We have the partial fraction expansion for the output ztransform Y(z)= H(z)X(z): Y(z)=
B1 5 + 2z−1 H(ω0 ) + = (1 − ejω0 z−1 )(1 − 0.8z−1 ) 1 − ejω0 z−1 1 − 0.8z−1
where the coefficient B1 is found by
B1 = (1 − 0.8z−1 )Y(z)z=0.8 =
!
5 + 2z−1
1 − ejω0 z−1
"
z=0.8
=
7.5 1 − 1.25ejω0
The causal inverse ztransform will be:
y(n)= H(ω0 )ejω0 n + B1 (0.8)n ,
n≥0
For large n, the term (0.8)n drops to zero and the output settles into its steadystate sinusoidal response
y(n)→ H(ω0 )ejω0 n where H(ω0 )=
5 + 2e−jω0 . 1 − 0.8e−jω0
There are four straightforward conclusions that can be drawn from Eq. (6.3.11). First, it shows clearly the requirement of stability for the filter. If any of the filter poles, say p1 , were outside the unit circle, such that p1  > 1, the term pn 1 would be unstable, diverging as n → ∞. This term would dominate completely the rest of terms of Eq. (6.3.11) and there would be no steadystate response. (Of course, we know that in this case the series definition, Eq. (5.4.3), of the frequency response H(ω) does not converge because the unit circle does not lie in the causal region of convergence z > p1  > 1.) Second, assuming the filter is strictly stable, all the transient terms pn i will drop to zero exponentially. But some of them will drop to zero faster than others. The effective time constant to reach the sinusoidal steady state is dictated by the slowest converging pole term, that is, the term with the largest magnitude, namely, max pi . Equivalently, this is the pole that lies closest to the unit circle (from the inside). Denoting the maximum pole magnitude by
ρ = max pi  i
235
6.3. SINUSOIDAL RESPONSE
we may define the effective time constant to be the time neff at which the quantity ρn has dropped below a certain small value, for example, when it drops below 1% its initial value. We can make this definition more quantitative by defining neff such that:
ρneff = where is the desired level of smallness, for example, = 1% = 0.01. It follows that:
neff =
ln ln(1/) = ln ρ ln(1/ρ)
(time constant)
(6.3.12)
Because both and ρ are less than one, their logs are negative, but the ratio is positive. In the last expression, we have the ratio of two positive numbers. The effective time constant neff becomes larger if the slowest pole is pushed closer to the unit circle, that is, increasing ρ toward one, and also if we require a smaller threshold . The value = 1% corresponds to the amplitude of the filter’s output falling by a factor of 10−2 or 40 dB. The time constant in seconds, τ = neff T, is referred to as the 40dB time constant. In the study of reverberation properties of concert halls, the 60dB time constants are used, which correspond to = 0.1% = 10−3 . In conclusion, the speed of response of a stable and causal IIR filter is controlled by the poles nearest to the unit circle. The filter is slow reaching steady state if its poles are near the unit circle, and fast if they are further away (toward the center). Example 6.3.2: A sinusoid of frequency ω0 = 0.1π and duration of 300 samples, that is, x(n)= sin(ω0 n), 0 ≤ n < 300, is input to a (causal) filter with transfer function H(z)=
b 1 − az−1
where a = 0.97. Determine the 1% time constant of this filter. Adjust the scale factor b such that the filter’s gain at ω0 is unity. Determine and plot the output of the filter y(n) over the interval 0 ≤ n < 450, by iterating the difference equation of the filter.
Solution: The 1% time constant of this filter is computed from Eq. (6.3.12), neff =
ln(0.01) ln = = 151.2 samples ln a ln(0.97)
The frequency and magnitude responses are
H(ω)=
b
⇒
1 − ae−jω
H(ω) = √
b
1 − 2a cos ω + a2
The requirement that H(ω0 ) = 1 leads to the condition on b:
H(ω0 ) =
b 1 − 2a cos ω0 +
a2
=1
⇒
b = 1 − 2a cos ω0 + a2 = 0.3096
The value of the frequency response at ω0 becomes then,
H(ω0 )=
b 1 − ae−jω0
= 0.2502 − 0.9682j = 1 · e−j1.3179
236
6. TRANSFER FUNCTIONS so that its phase response will be arg H(ω0 )= −1.3179 radians. The resulting output y(n), shown in Fig. 6.3.4, was computed by the following program segment, which implements the difference equation y(n)= ay(n − 1)+bx(n) and sample processing algorithm of this filter:
for (y1=0, n=0; n N, it is more efficient to first wrap the signal modN and then take its DFT.
N
L N
X =
=
A
~ A
N ~ A
~ A
~ A
x0 =
~ A
~ x
x1 x x2 x3 Fig. 9.5.3 Npoint DFTs of the full and wrapped signals are equal.
Example 9.5.2: Compute the 4point DFT of the length8 signal of Example 9.5.1 in two ways: (a) working with the full unwrapped vector x and (b) computing the DFT of its mod4 reduction.
493
9.5. MODULON REDUCTION Solution: The 4×8 DFT matrix was worked out above. The corresponding DFT is:
1
1
1
−j −1 j
1 X = Ax = 1
1 −1 1 −1
1
1 1 1 1
j −1 −j
1
−j −1 j
1 −1 1 −1
1
2 −2 6 3 8 + 4j = 4 −2 −2 8 − 4j −1
1
j −1 −j
1
# acting on the wrapped signal x The same DFT can be computed by the DFT matrix A #, determined in Example 9.5.1:
1
1
1
−j −1 j
1 #x = # = A# X 1
1 −1 1 −1
1
5
j 0 − 1 −3 −j 4
6
8 + 4j = −2 8 − 4j
The two methods give identical results.
Example 9.5.3: The length L of the signal x can be infinite, as long as the signal is stable, so that the sum (9.5.4) converges. To illustrate the theorem (9.5.6) or (9.5.11), consider the causal signal x(n)= an u(n), where a < 1. To compute its Npoint DFT, we determine its ztransform and evaluate it at the Nth root of unity points zk = ejωk = e2πjk/N . This gives:
X(z)=
1 1 − az−1
⇒
Xk = X(zk )=
1 1 − azk−1
,
k = 0, 1, . . . , N − 1
Next, we compute its modN reduction by the sum (9.5.4):
#(n)= x
∞
m=0
x(mN + n)=
∞
m=0
amN an =
an , 1 − aN
n = 0, 1, . . . , N − 1
where we used the geometric series sum. Computing its ztransform, we find:
# X(z)=
N− 1 n=0
#(n)z−n = x
N− 1 1 − aN z−N 1 an z−n = 1 − aN n=0 (1 − aN )(1 − az−1 )
Evaluating it at z = zk and using the property that zN k = 1, we find
# k = X(z # k )= X
1 − aN z−N k
1 (1 − aN )(1 − az− k )
=
1 − aN 1 = = Xk (1 − aN )(1 − azk−1 ) 1 − azk−1
#(n) are different and have different ztransforms and DTFTs, Thus, even though x(n) and x their Npoint DFTs are the same.
494
9. DFT/FFT ALGORITHMS
The following C routine modwrap.c implements the moduloN reduction operation. If L < N, it pads N − L zeros at the end of x so that x # will have length N. If L > N, it determines how many lengthN blocks fit into L, and adds them up, also taking into account the few excess points at the end. /* modwrap.c  moduloN wrapping of lengthL signal */ void modwrap(L, x, N, xtilde) int L, N; double *x, *xtilde; { int n, r, m, M; r = L % N; M = (Lr) / N;
usage: modwrap(L, x, N, xtilde);
x is Ldimensional xtilde is Ndimensional
remainder r = 0, 1, . . . , N − 1 quotient of division L/N
for (n=0; n=0; m) xtilde[n] += x[m*N+n]; }
nonzero part of last block if L < N, this is the only block if L < N, pad N − L zeros at end remaining blocks if L < N, this loop is skipped
}
Using this routine, we may compute the Npoint DFT of a lengthL signal by first wrapping it moduloN and then computing the Npoint DFT of the wrapped signal: modwrap(L, x, N, xtilde); dft(N, xtilde, N, X);
wrap input moduloN DFT(x #) = DFT(x)
Assuming L is a multiple of N, L = MN, the computational cost of the routine modwrap is N(M − 1) MN MACs, whereas that of the above dft is N2 MACS. Thus, the total cost of computing the DFT is N2 + MN MACs. This is to be compared to LN = MN2 MACs for the routine dft acting on the full lengthL input. Replacing the above DFT by an FFT routine gives an even more efficient implementation, requiring N log2 (N)/2 + MN operations. Example 9.5.4: Compare the cost of computing the 128point DFT of a length1024 signal, using a direct DFT, a prewrapped DFT, and a prewrapped FFT. The number of lengthN segments is M = L/N = 1024/128 = 8. The cost of wrapping the signal to length 128 is N(M − 1)= 896. The cost of the three methods will be: (direct DFT)
LN = 1024 · 128 = 131,072
(wrapped DFT)
N2 + N(M − 1)= 1282 + 128 · (8 − 1)= 17,280
(wrapped FFT)
1 1 N log2 (N)+N(M − 1)= · 128 · 7 + 128 · (8 − 1)= 1,344 2 2
where we assumed that all the MAC operations are complexvalued. We may also compare the above with the cost of a direct 1024point FFT on the 1024point input:
495
9.5. MODULON REDUCTION
(1024point FFT)
1 1 L log2 (L)= · 1024 · 10 = 5,120 2 2
The DFT frequencies of the desired 128point DFT are a subset of the DFT frequencies of the 1024point DFT; indeed, we have:
ωk =
2πk 2π(8k) = , 128 1024
k = 0, 1, . . . , 127
Thus, the 128point DFT can be extracted from the 1024point FFT by taking every eighth
entry, that is, X128 (k)= X1024 (8k).
The two signals x and x # are not the only ones that have a common DFT. Any other signal that has the same modN reduction as x will have the same DFT as x. To see this, consider a lengthL signal y such that y #=x #; then its Npoint DFT can be obtained by applying Eq. (9.5.11):
# y = A# # x = Ax = X Y = Ay = A#
For example, the following length8 signals all have the same 4point DFT,
x0 x1 x2 x3 x4 x5 x6 x7
,
x0 + x4 x1 x2 x3 0
x5 x6 x7
,
x0 + x4 x1 + x5 x2 x3 0 0 x6 x7
,
x0 + x4 x1 + x5 x2 + x6 x3 0 0 0 x7
,
x0 + x4 x1 + x5 x2 + x6 x +x 3 7 0 0 0 0
because all have the same mod4 reduction:
x0 + x4 x +x 1 5 x #= x2 + x6 x3 + x7
The above signals have a bottom half that becomes progressively zero, until the last vector which is recognized as the x #, viewed as a length8 vector. In fact, the modN wrapped signal x # is unique in the above class of signals in the sense that it is shortest signal, that is, of length N, that has the same DFT as the signal x. An equivalent characterization of the class of signals that have a common DFT can be given in the zdomain. Suppose the lengthL signals y and x have equal modN reductions, y #=x # and, therefore, equal DFTs Xk = Yk . We form the difference of their ztransforms:
F(z)= X(z)−Y(z)=
L− 1
n=0
x(n)z−n −
L− 1
n=0
y(n)z−n
496
9. DFT/FFT ALGORITHMS
Evaluating F(z) at the Nth roots of unity and using the equality of their Npoint DFTs, we find:
F(zk )= X(zk )−Y(zk )= Xk − Yk = 0,
k = 0, 1, . . . , N − 1
Thus, the N complex numbers zk are roots of the difference polynomial F(z). Therefore, F(z) will be divisible by the Nth order product polynomial: 1 − z−N =
N− +1 k=0
(1 − zk z−1 )
which represents the factorization of 1 −z−N into its Nth rootofunity zeros. Therefore, we can write:
X(z)−Y(z)= F(z)= 1 − z−N Q(z) or, X(z)= Y(z)+ 1 − z−N Q(z)
(9.5.13)
Because X(z) and Y(z) have degree L − 1, it follows that Q(z) is an arbitrary polynomial of degree L − 1 − N. Denoting the coefficients of Q(z) by q(n), 0 ≤ n ≤ L − 1 − N, we may write Eq. (9.5.13) in the time domain:
x(n)= y(n)+q(n)−q(n − N) ,
n = 0, 1, . . . , L − 1
(9.5.14)
Thus, any two sequences x(n) and y(n) related by Eq. (9.5.14) will have the same # Npoint DFT. The modN reduction x # and its ztransform X(z) are also related by Eq. (9.5.13):
# X(z)= 1 − z−N Q(z)+X(z)
(9.5.15)
# has degree N− 1, Eq. (9.5.15) represents the division of the polynomial Because X(z) # X(z) by the DFT polynomial 1 − z−N , with X(z) being the remainder polynomial and # Q(z) the quotient polynomial. The remainder X(z) is the unique polynomial satisfying Eq. (9.5.15) that has minimal degree N − 1.
9.6 Inverse DFT The problem of inverting an Npoint DFT is the problem of recovering the original lengthL signal x from its Npoint DFT X, that is, inverting the relationship:
#x X = Ax = A#
(9.6.1)
When L > N, the matrix A is not invertible. As we saw, there are in this case several possible solutions x, all satisfying Eq. (9.6.1) and having the same modN reduction x #. Among these solutions, the only one that is uniquely obtainable from the knowledge # is an N×N square invertible of the DFT vector X is x #. The corresponding DFT matrix A matrix. Thus, we define the inverse DFT by
497
9.6. INVERSE DFT
or, componentwise,
# −1 X x # = IDFT(X)= A #n = x
N− 1 k=0
# −1 )nk Xk , (A
(inverse DFT)
(9.6.2)
n = 0, 1, . . . , N − 1
(9.6.3)
# −1 can be obtained without having to perform a matrix inversion by The inverse A #: using the following unitarity property of the DFT matrix A 1
N
#A # ∗ = IN A
(9.6.4)
# ∗ is the complex conjugate of A #, where IN is the Ndimensional identity matrix and A # obtained by conjugating every matrix element of A. For example, for N = 4, we can verify easily:
1
1
1
−j −1 j
1 1 #A #∗ = 1 A 4 4 1
1 −1 1 −1
1
1
j 1 −1 1 −j 1
1
j −1 −j
1 −1 1 −1
1
1
−j 0 = −1 0 j 0
0 1 0 0
0 0 1 0
# −1 , we obtain for the matrix inverse: Multiplying both sides of Eq. (9.6.4) by A #∗ # −1 = 1 A A N
0 0 0 1
(9.6.5)
Thus, the IDFT (9.6.2) can be written in the form: x # = IDFT(X)=
1
N
#∗ X A
(inverse DFT)
(9.6.6)
We note also that the IDFT can be thought of as a DFT in the following sense. Introducing a second conjugation instruction, we have:
# ∗ X = (A # X∗ )∗ = DFT(X∗ ) ∗ A
# acting on the conjugated vector X∗ is the DFT of that vector. Dividing where the matrix A by N, we have: IDFT(X)=
1
N
∗
(9.6.7)
∗
(9.6.8)
DFT(X∗ )
Replacing DFT by FFT, we get a convenient inverse FFT formula, which uses an FFT to perform the IFFT. It is used in most FFT routines. IFFT(X)=
1
N
FFT(X∗ )
498
9. DFT/FFT ALGORITHMS
Example 9.6.1: To illustrate Eqs. (9.6.6) and (9.6.7), we calculate the IDFT of the 4point DFT of Example 9.5.2. We have:
1
1 1 ∗ # X= 1 x # = IDFT(X)= A N 4 1 1
1
1 −1 1 −1
j −1 −j
1
6
−j 8 + 4j −1 −2 j 8 − 4j
5
0 = −3 4
and using Eq. (9.6.7), we conjugate X and transform it:
# X ∗ )∗ = 1 (A N 4 1
1
1
1
−1
1
−j −1 j
1 1
1 −1
1
6
j 8 − 4j −1 −2 −j 8 + 4j
5
0 = −3 4
where the final overall conjugation was omitted because x # is real.
# −1 are: Using Eq. (9.4.3) the matrix elements of A 1
# −1 )nk = (A
N
1 −nk nk ∗ # ∗ = 1 (WN A ) = WN nk N N
∗ −1 where we used the property WN = e2πj/N = WN . Then, Eq. (9.6.3) can be written in the form:
#n = x
(IDFT)
N−1 1
N
−nk WN Xk ,
k=0
n = 0, 1, . . . , N − 1
(9.6.9)
In terms of the DFT frequencies ωk , we have Xk = X(ωk ) and −nk = e2πjkn/N = ejωk n WN
Therefore, the inverse DFT can be written in the alternative form:
(IDFT)
#(n)= x
N−1 1
N
X(ωk )ejωk n ,
k=0
n = 0, 1, . . . , N − 1
(9.6.10)
#(n) as a sum of N complex sinusoids of frequencies ωk , It expresses the signal x whose relative amplitudes and phases are given by the DFT values X(ωk ). The forward DFT of Eq. (9.2.8) is sometimes called an analysis transform, analyzing a signal x(n) into N Fourier components. The inverse DFT (9.6.10) is called a synthesis #(n) from those Fourier components. The forward transform, resynthesizing the signal x and inverse Npoint DFTs are akin to the more general forward and inverse DTFTs that use all frequencies, not just the N DFT frequencies: X(ω)=
L− 1
n=0
x(n)e−jωn ,
x(n)=
2π 0
X(ω)ejωn
dω 2π
(9.6.11)
499
9.7. SAMPLING OF PERIODIC SIGNALS AND THE DFT
The difference between this inverse DTFT and (9.6.10) is that (9.6.11) reconstructs #(n). the full original signal x(n), whereas (9.6.10) reconstructs only the wrapped signal x Eq. (9.6.10) can be thought of as a numerical approximation of the integral in (9.6.11), obtained by dividing the integration range into N equal bins:
2π
X(ω)ejωn
0
N− 1 dω ∆ωbin X(ωk )ejωk n 2π 2π k=0
where from the definition (9.2.9), we have ∆ωbin /2π = 1/N. In summary, the inverse of an Npoint DFT reconstructs only the wrapped version of the original signal that was transformed. This property is shown in Fig. 9.6.1.
x
L
X
modN reduction
N
DFT
N
DFT
~x
IDFT
Fig. 9.6.1 Forward and inverse Npoint DFTs.
In order for the IDFT to generate the original unwrapped signal x, it is necessary to have x # = x. This happens only if the DFT length N is at least L, so that there will be only one lengthN subblock in x and there will be nothing to wrap around. Thus, we have the condition: x # = x only if
N≥L
(9.6.12)
If N = L, then Eq. (9.6.12) is exact. If N > L, then we must pad N −L zeros at the end of x so that the two sides of Eq. (9.6.12) have compatible lengths. If N < L, the wrapped and original signals will be different because there will be several lengthN subblocks in x that get wrapped around. Thus, we also have the condition: x # = x if
N> B) > 0 ) B++;
B = number of bits
B;
N = 2B
for (n = 0; n < N; n++) { r = bitrev(n, B); if (r < n) continue; swap(X+n, X+r); }
bitreversed version of n swap only half of the ns swap by addresses
}
/* swap.c  swap two complex numbers (by their addresses) */ #include void swap(a,b) complex *a, *b; { complex t; t = *a; *a = *b; *b = t; }
/* bitrev.c  bit reverse of a Bbit integer n */ #define two(x)
(1 =0; m) if ((n >> m) == 1) { r += two(B1m); n = two(m); }
if 2m term is present, then add 2B−1−m to r , and subtract 2m from n
return(r); }
A Bbit number n and its reverse can be expressed in terms of their bits as:
513
9.8. FFT
n= r=
B− 1
bm 2m
B− 1
bm 2B−1−m
m=0
m=0
The routine bitrev builds r by determining if the mth bit bm is one and adding the corresponding power 2B−1−m to r . The DFT merging operation is given by the routine dftmerge.c. It is basically a loop that runs over the successive merging stages of dimensions M = 2, 4, . . . , N. /* dftmerge.c  DFT merging for radix 2 decimationintime FFT */ #include void dftmerge(N, XF) complex *XF; int N; { double pi = 4. * atan(1.0); int k, i, p, q, M; complex A, B, V, W; M = 2; while (M W = V = for
M, the remaining output points will be correct.
522
9. DFT/FFT ALGORITHMS
Fig. 9.9.1 Overlapsave method of fast convolution.
N+M y=
N
M
M ~ y= M
NM N
Fig. 9.9.2 ModN reduction of output block ruins first M output samples.
As shown in Fig. 9.9.1, because the input blocks overlap by M points, when the wrapped output blocks are aligned according to their absolute timings, the first M points of each block can be ignored because the correct outputs have already been computed from the previous block. There is only one exception, that is, the very first M points of the output sequence are not computed correctly. This can be corrected by delaying the input by M time units before commencing the filtering operation. The computational cost of the method is essentially the same as that of the overlapadd method, with the relative performance over conventional convolution given by Eq. (9.9.15). Example 9.9.5: Using the overlapsave method of fast convolution, implemented in the time domain by mod8 circular convolutions, compute the linear convolution of the “long” input: x = [1, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1]
523
9.10. PROBLEMS with the “short” filter: h = [1, −1, −1, 1]
Solution: For comparison, we compute the linear convolution using the convolution table: y = [1, 0, −1, 0, 2, 0, −2, 0, −2, 0, 2, 1, 0, −1, 0, −1, 0, 1, 0, −1, 0, 1] For the overlapsave method, we divide the input into length8 blocks which overlap by M = 3 points. These blocks are:
x = [1, 1, 1, 1, 3, 3, 3, 3], 1, 1, [1, 2, 2 , 2, 2, 1, 1, 1], 1, 0, 0, 0, 0 Convolving these blocks with h gives: y0 = h ∗ [1, 1, 1, 1, 3, 3, 3, 3]= [1, 0, −1, 0, 2, 0, −2, 0, −3, 0, 3] y1 = h ∗ [3, 3, 3, 1, 1, 1, 2, 2]= [3, 0, −3, −2, 0, 2, 1, 0, −3, 0, 2]
y2 = h ∗ [1, 2, 2, 2, 2, 1, 1, 1]= [1, 1, −1, −1, 0, −1, 0, 1, −1, 0, 1] y3 = h ∗ [1, 1, 1, 1, 0, 0, 0, 0]= [1, 0, −1, 0, −1, 0, 1, 0, 0, 0, 0] Reducing these modulo8 and ignoring the first M = 3 points (indicated by ∗), we obtain: y # 0 = [∗, ∗, ∗, 0, 2, 0, −2, 0]
y # 1 = [∗, ∗, ∗, −2, 0, 2, 1, 0]
y # 2 = [∗, ∗, ∗, −1, 0, −1, 0, 1]
y # 3 = [∗, ∗, ∗, 0, −1, 0, 1, 0]
These would be the outputs computed via the FFT method. Putting them together, we obtain the overall output signal: y = [∗, ∗, ∗, 0, 2, 0, −2, 0][−2, 0, 2, 1, 0][−1, 0, −1, 0, 1][0, −1, 0, 1, 0] With the exception of the first 3 points, the answer is correct.
9.10 Problems 9.1 A 128millisecond portion of an analog signal is sampled at a rate of 8 kHz and the resulting L samples are saved for further processing. What is L? The 256point DFT of these samples is computed. What is the frequency spacing in Hz of the computed DFT values? What is the total number of required multiplications: (a) if the computations are done directly using the definition of the DFT, (b) if the L samples are first wrapped modulo 256 and then the 256point DFT is computed, and (c) if a 256point FFT is computed of the wrapped signal? 9.2 A 10 kHz sinusoidal signal is sampled at 80 kHz and 64 samples are collected and used to compute the 64point DFT of this signal. At what DFT indices k = 0, 1, . . . , 63 would you expect to see any peaks in the DFT?
524
9. DFT/FFT ALGORITHMS
9.3 A 5 kHz sinusoidal signal is sampled at 40 kHz and 16 periods of the signal are collected. What is the length N of the collected samples? Suppose an Npoint DFT is performed. Then, at what DFT indices, k = 0, 1, . . . , N − 1, do you expect to see any peaks in the DFT spectrum? In general, how is the number of periods contained in the N samples related to the DFT index at which you get a peak?
9.4 An 18 kHz sinusoid is sampled at a rate of 8 kHz and a 16point DFT of a finite portion of the signal is computed. At what DFT indices in the range 0 ≤ k ≤ 15 do you expect to see any peaks in the DFT spectrum? Would it matter if first we folded the 18 kHz frequency to lie within the Nyquist interval and then computed the DFT? Explain. 9.5 It is known that the frequency spectrum of a narrowband signal has a peak of width of 20 Hz but it is not known where this peak is located. To find out, an FFT must be computed and plotted versus frequency. If the signal is sampled at a rate of 8 kHz, what would be the minimum number of samples L that must be collected in order for the peak to be resolvable by the lengthL data window? What is the duration in seconds of this data segment? What would be the minimum size N of the FFT in order for the N FFT spectral values to represent the L time samples accurately? 9.6 Computer Experiment: Rectangular and Hamming Windows. Using the routine dtftr.c, reproduce the results and graphs of Example 9.1.3. 9.7 Computer Experiment: Frequency Resolution and Windowing. Reproduce the results and graphs of Example 9.1.4. The spectra of the windowed signals must be computed by first windowing them using a lengthL window and then padding 256 − L zeros at their ends to make them of length256, and finally calling a 256point FFT routine. 9.8 Computer Experiment: Physical versus Computational Resolution. Reproduce the results of Figs. 9.3.1 and 9.3.2. The theoretical DTFTs may be computed by 256point FFTs. The 32point and 64point DFTs may be extracted from the 256point FFTs by keeping every 8th point (256/32 = 8) and every 4th point (256/64 = 4.) 9.9 A dualtone multifrequency (DTMF) transmitter (touchtone phone) encodes each keypress as a sum of two sinusoidal tones, with one frequency taken from group A and one from group B, where: group A = 697, 770, 852, 941 Hz group B = 1209, 1336, 1477 Hz A digital DTMF receiver computes the spectrum of the received dualtone signal and determines the two frequencies that are present, and thus, the key that was pressed. What is the smallest number of time samples L that we should collect at a sampling rate of 8 kHz, in order for the groupA frequencies to be resolvable from the groupB frequencies? What is L if a Hamming window is used prior to computing the spectrum? 9.10 Suppose we collect 256 samples of the above DTMF signal and compute a 256point FFT. Explain why each keypress generates substantial signal energy in 2 out of 7 possible DFT frequency bins (and their negatives). What are the indices k for these 7 bins? [Hint: Round k to its nearest integer. Do not ignore negative frequencies.] Note that in practice, it may be more economical to just compute the value of X(k) at those 14 k’s instead of computing a full 256point FFT. 9.11 Computer Experiment: DTMF Sinusoids. Consider the following artificial signal consisting of the sum of all seven DTMF sinusoids:
525
9.10. PROBLEMS
x(t)=
4
a=1
sin(2πfa t)+
3
sin(2πfb t)
b=1
where fa and fb are the group A and B frequencies given in Problem 9.9 and t is in seconds. (In practice, of course, only one fa term and one fb term will be present.) The signal x(t) is sampled at a rate of 8 kHz and 256 samples are collected, say, x(n), n = 0, 1, . . . , 255. The spectrum of this signal should consist of seven peaks clustered in two clearly separable groups (and, seven more negativefrequency peaks). a. Plot the signal x(n) versus n. b. Compute the 256point DFT or FFT of the signal x(n) and plot the corresponding magnitude spectrum X(f ) only over the frequency range 0 ≤ f ≤ 4 kHz. c. Window the signal x(n) by a length256 Hamming window w(n), that is, xham (n)= w(n)x(n), and plot it versus n. Then, compute its 256point DFT and plot the magnitude spectrum Xham (f ) over 0 ≤ f ≤ 4 kHz. 9.12 Let x = [1, 2, 2, 1, 2, 1, 1, 2]. Compute the 4point DFT of x using the definition in matrix form. Recompute it by first reducing x modulo 4 and then computing the 4DFT of the result. Finally, compute the 4point IDFT of the result and verify that you recover the mod4 wrapped version of x. 9.13 Compute the 8point FFT of the length8 signal x = [5, −1, −3, −1, 5, −1, −3, −1]. Noting that these samples are the first 8 samples of x(n)= 4 cos(πn/2)+ cos(πn), discuss whether the 8 computed FFT values accurately represent the expected spectrum of x(n). What FFT indices correspond to the two frequencies of the cosinusoids? 9.14 The 8point DFT X of an 8point sequence x is given by X = [0, 4, −4j, 4, 0, 4, 4j, 4] Using the FFT algorithm, compute the inverse DFT: x = IFFT(X). Using the given FFT X, express x as a sum of realvalued (co)sinusoidal signals. 9.15 When a very large FFT of a very large data set is required (e.g., of size 216 or larger), it may be computed in stages by partially decimating the time data down to several data sets of manageable dimension, computing their FFTs, and then rebuilding the desired FFT from the smaller ones. See [241–244,303] for a variety of approaches. In this context, suppose you want to compute a (4N)point FFT but your FFT hardware can only accommodate Npoint FFTs. Explain how you might use this hardware to compute that FFT. Discuss how you must partition the time data, what FFTs must be computed, how they must be combined, and how the partial results must be shipped back and forth from secondary storage to the FFT processor in groups of no more than N samples. What is the total number of complex multiplications with your method? Compare this total to the cost of performing the (4N)point FFT in a single pass? Do you observe anything interesting? 9.16 Compute the length4 circular convolution of the two signals h = [1, 2, 1, 2, 1], x = [1, 1, 1, 1, 1] in two ways: (a) by computing their linear convolution and then reducing the result mod4, (b) by first reducing h and x mod4, computing the linear convolution of the reduced signals, and reducing the result mod4.
526
9. DFT/FFT ALGORITHMS
9.17 Compute the 8point FFT of x = [4, 2, 4, −6, 4, 2, 4, −6]. Without performing any additional computations, determine the 4point DFT and the 2point DFT of the above signal. Explain your reasoning. Using the computed DFT and the inverse DFT formula, express the sequence x(n), n = 0, 1, . . . , 7 as a linear combination of realvalued sinusoidal signals. Does your x(n) agree with the given sequence? 9.18 Let x = [1, 2, 3, 4, 5]. (a) Determine a length6 signal that has the same 5point DFT as x. (b) Determine a length7 signal that has the same 5point DFT as x. Your answers should be nontrivial, that is, do not increase the length of x by padding zeros at its end. 9.19 Show the property: 1 (N−1)k 3k k 2k 1 + WN + WN = δ(k), + WN + · · · + WN
k = 0, 1, . . . , N − 1
N
9.20 Show the following properties: p
a. WN = W22N = W33N = · · · = WpN b. XN (k)= XpN (pk),
k = 0, 1, . . . , N − 1
where WpN is the twiddle factor of order pN, p is any integer, XN (k) denotes the Npoint DFT, and XpN (k) the (pN)point DFT of a common signal x(n) of length L. 9.21 Consider a 16point signal xn , 0 ≤ n ≤ 15, with 16point DFT Xk , 0 ≤ k ≤ 15, namely,
X0 , X1 , X2 , X3 , X4 , X5 , X6 , X7 , X8 , X9 , X10 , X11 , X12 , X13 , X14 , X15
Show that the 8point DFT of the given 16point signal is:
X0 , X2 , X4 , X6 , X8 , X10 , X12 , X14
9.22 The following analog signal x(t), where t is in msec, is sampled at a rate of 8 kHz:
x(t)= cos(24πt)+2 sin(12πt)cos(8πt) a. Determine the signal xa (t) that is aliased with x(t). b. Eight consecutive samples of x(t) are collected. Without performing any DFT or FFT operations, determine the 8point DFT of these 8 samples. 9.23 Consider the following 8point signal, defined for n = 0, 1, . . . , 7:
x(n)= 1 + 2 sin(
πn 4
)−2 sin(
πn 2
)+2 sin(
3πn )+3(−1)n 4
Without performing any DFT or FFT computations, determine the 8point DFT of this signal. 9.24 Let x(n)= cos(πn/2)+2 cos(πn/8), n = 0, 1, . . . , 15. Without performing any actual DFT/FFT computations, determine the 16point DFT of this 16point signal. [Hint: Compare x(n) with the 16point inverse DFT formula.] 9.25 Let x(n)= cos(πn/2)+2 cos(πn/8), n = 0, 1, . . . , 31. Without performing any actual DFT/FFT computations, determine the 32point DFT of this 32point signal. 9.26 Consider the following length16 signal:
x(n)= 0.5 + 2 sin(0.5πn)+1.5 cos(πn),
n = 0, 1, . . . , 15
527
9.10. PROBLEMS
a. Determine the DTFT X(ω) of this finite sequence, and sketch it roughly versus ω in the range 0 ≤ ω ≤ 2π. [Hint: Remember that each spectral line gets replaced by the rectangular window’s frequency response.] b. Without performing any DFT or FFT computations, determine the 16point DFT of this sequence. Then, determine the 8point DFT of the same sequence. c. Place the 16point DFT values on the graph of X(ω) of part (a). 9.27 Let X = Ax be the Npoint DFT of the lengthN signal x expressed in matrix form, where A kn is the N × N DFT matrix defined by its matrix elements Akn = WN , k, n = 0, 1, . . . , N − 1. Show that the inverse of this matrix can be obtained essentially by conjugating A, that is, 1
A−1 =
N
A∗
Therefore the IDFT can be expressed by x = A−1 X = A∗ X/N. Explain how this result justifies the rule: IFFT(X)=
∗ 1 FFT(X∗ )
N
9.28 Let X(k) be the Npoint DFT of a lengthN (complexvalued) signal x(n). Use the results of Problem 9.27 to show the Parseval relation: N− 1 n=0
x(n)2 =
N−1 1
N
k=0
X(k)2
9.29 Compute the mod4, mod5, mod6, mod7, and mod8 circular convolutions of the signals x = [2, 1, 1, 2] and h = [1, −1, −1, 1]. For what value of N does the modN circular convolution agree with the ordinary linear convolution? 9.30 Compute the modulo8 circular convolution of the two signals h = [2, 1, 1, 1, 2, 1, 1, 1],
x = [2, 1, 2, −3, 2, 1, 2, −3]
in two ways: a. Working exclusively in the time domain. b. Using the formula:
y # = IFFT FFT(h)·FFT(x)
implemented via 8point FFTs. All the computational details of the required FFTs must be shown explicitly. 9.31
a. Compute the 8point FFT of the 8point signal x = [6, 1, 0, 1, 6, 1, 0, 1]. b. Using the inverse DFT formula, express x as a linear combination of realvalued sinusoids. c. Find two other signals, one of length9 and one of length10, that have the same 8point DFT as x. These signals must not begin or end with zeros. d. Compute the 4point FFT of x by carrying out a single 4point FFT.
528
9. DFT/FFT ALGORITHMS
9.32 Let A(k) be the Npoint DFT of a realvalued signal a(n), n = 0, 1, . . . , N − 1. Prove the symmetry property:
A(k)∗ = A(N − k),
k = 0, 1, . . . , N − 1
If we think of A(k) as an Ndimensional array, then how can we state the above relationship at k = 0? 9.33 Two RealValued Signals at a Time. Let x(n)= a(n)+jb(n) be a lengthN complexvalued signal and let X(k) be its Npoint DFT. Let A(k) and B(k) denote the Npoint DFTs of the real and imaginary parts a(n) and b(n) of x(n). Show that they can be recovered from X(k) by
A(k)=
1 X(k)+X(N − k)∗ , 2
B(k)=
1 X(k)−X(N − k)∗ 2j
for k = 0, 1, . . . , N − 1. If we think of X(k) as an Ndimensional array, then how can we state the above relationships at k = 0?
Thus, the DFTs of realvalued signals can be computed two at a time by computing the DFT of a single complexvalued signal. 9.34 FFT of RealValued Signal. Using the results of Problem 9.33, show that the Npoint FFT X(k) of an Npoint realvalued signal x(n), n = 0, 1, . . . , N − 1 can be computed efficiently as follows: First, pack the even and odd parts of x(n) into a complexvalued signal of length N/2, that is, define
y(n)= x(2n)+jx(2n + 1)≡ g(n)+jh(n),
n = 0, 1, . . . ,
N 2
−1
Then, compute the N/2point FFT of y(n), say, Y(k), k = 0, 1, . . . , N/2 − 1, and extract the N/2point FFTs of g(n) and h(n) by
G(k)=
1 N Y(k)+Y( − k)∗ , 2 2
H(k)=
1 N Y(k)−Y( − k)∗ 2j 2
for k = 0, 1, . . . , N/2 − 1. And finally, construct the desired Npoint FFT by k X(k)= G(k)+WN H(k),
X(k +
N 2
k )= G(k)−WN H(k)
for k = 0, 1, . . . , N/2 − 1. What happens at k = 0?
Determine the relative computational savings of this method versus performing the Npoint FFT of x(n) directly. 9.35 Computer Experiment: FFT of RealValued Signal. Write a C routine fftreal.c that implements the method of Problem 9.34. The routine must have inputs/output declarations: void fftreal(N, x, X) int N; double *x; complex *X;
must be a power of 2 realvalued Ndimensional time data complex Ndimensional FFT array
The routine must invoke the routine fft.c once on the timedecimated, complexified, input. In rebuilding the final DFT X(k), special care must be exercised at k = 0.
Write a small main program to test the routine by comparing its output to the output of fft called on the full input array as usual.
529
9.10. PROBLEMS 9.36 Consider the following Npoint signal and its reverse: x = [x0 , x1 , . . . , xN−1 ] xR = [xN−1 , . . . , x1 , x0 ]
Show that the ztransform and Npoint DFT of the reversed signal can be expressed as:
XR (z) = z−(N−1) X(z−1 ) −k XR (k) = WN X(N − k),
k = 0, 1, . . . , N − 1
Show that in the time domain the reversal process is equivalent to a twostep process of first reflecting the signal around the origin n = 0, and then delaying it by N − 1 units. 9.37 Discrete Cosine Transform (DCT). Consider a lengthN realvalued signal x and its reverse as defined in Problem 9.36. Construct the concatenated signal of length 2N: y = [x, xR ]= [x0 , x1 , . . . , xN−1 , xN−1 , . . . , x1 , x0 ] a. Show that its ztransform can be expressed in terms of the ztransform of x:
Y(z)= X(z)+z−N XR (z)= X(z)+z−(2N−1) X(z−1 ) b. Let Yk be the (2N)point DFT of y. Show that it can be expressed in the form:
Yk = 2ejωk /2 Ck ,
k = 0, 1, . . . , 2N − 1
where ωk = 2πk/(2N)= πk/N is the kth frequency for the (2N)point DFT and Ck is one form of the discrete cosine transform of xn given by:
Ck =
N− 1 n=0
xn cos ωk (n + 1/2)
(9.10.1)
[Hint: Evaluate part (a) at the (2N)th roots of unity and multiply by z−1/2 .] c. Using the results of Problem 9.32, show that Ck satisfies the symmetry property:
C2N−k = −Ck ,
k = 0, 1, . . . , 2N − 1
In particular, show CN = 0. d. Applying the inverse DFT equation on Yk , show the inverse DCT:
xn =
2N−1 1
N
Ck ejωk (n+1/2) ,
n = 0, 1, . . . , N − 1
k=0
Using the symmetry property of part (c), show the alternative inverse DCT, which uses only the first N DCT coefficients Ck , k = 0, 1, . . . , N − 1:
xn =
N− 1 1 C0 + 2 Ck cos ωk (n + 1/2) ,
N
k=1
n = 0, 1, . . . , N − 1
(9.10.2)
Together, Eqs. (9.10.1) and (9.10.2) form a forward/inverse DCT pair. The relationship to the doubled signal y allows an efficient calculation using (2N)point FFTs [238–240].
530 9.38
9. DFT/FFT ALGORITHMS a. Let XN (k) denote the Npoint DFT of a lengthL sequence x(n), n = 0, 1, . . . , L − 1. Show the relationships:
k = 0, 1, . . . , N − 1
XN (k)= X2N (2k),
b. In particular, we have X4 (k)= X8 (2k), for k = 0, 1, 2, 3. That is, the 4point DFT of a sequence can be obtained by keeping every other entry of the 8point DFT of that sequence. 9.39 Consider a length5 sequence and its “circular shifts” x0 = [x0 , x1 , x2 , x3 , x4 ] x1 = [x4 , x0 , x1 , x2 , x3 ] x2 = [x3 , x4 , x0 , x1 , x2 ] x3 = [x2 , x3 , x4 , x0 , x1 ] x4 = [x1 , x2 , x3 , x4 , x0 ] Show that the 5point DFT Xi (k) of xi is related to the 5point DFT X0 (k) of x0 by
Xi (k)= W5ik X0 (k),
for
i = 1, 2, 3, 4
Explain this result in terms of ordinary “linear” shifts of the original sequence x0 . 9.40 Show that the following, successively shorter, signals all have the same 4point DFT:
x0 x1 x2 x3 x4 x5 x6 x7
,
x0 x1 x2 x3 + x7 x4 x5 x6 0
,
x0 x1 x2 + x6 x3 + x7 x4 x5 0 0
,
x0 x1 + x5 x2 + x6 x3 + x7 x4 0 0 0
,
x0 + x4 x1 + x5 x2 + x6 x3 + x7 0 0 0 0
9.41 Using the overlapsave method of fast convolution implemented in the time domain using length8 circular convolutions, compute the ordinary convolution of the “long” signal x = [1, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1] with the “short” filter h = [1, −1, −1, 1] and explain any discrepancies from the correct answer. Repeat using the overlapadd method. 9.42 A periodic triangular waveform of period T0 = 1 sec is defined over one period 0 ≤ t ≤ 1 sec as follows (see also Fig. 1.8.1):
t, 0.5 − t, x(t)= t − 1,
if 0 ≤ t ≤ 0.25 if 0.25 ≤ t ≤ 0.75 if 0.75 ≤ t ≤ 1
531
9.10. PROBLEMS
The signal x(t) is sampled at a rate of 8 Hz and the sampled signal x(nT) is immediately reconstructed into analog form using an ideal reconstructor. Because x(t) is not bandlimited, aliasing effects will cause the reconstructed signal to be different from x(t). Show that the aliased reconstructed signal will have the form:
xal (t)= A sin(2πf1 t)+B sin(2πf2 t) What are the frequencies f1 and f2 ? Determine the amplitudes A and B by performing an appropriate 8point FFT by hand. Explain how the negative frequencies in xal (t) are represented in this FFT. 9.43 A lengthL input signal is to be filtered by an orderM FIR filter using the overlapsave method of fast convolution, implemented via Npoint FFTs. Assume that L N and N > M. a. Derive an expression for the total number of multiplications required to compute the output, in terms of L, N, and M. b. Repeat part (a) if the overlapadd method is used. 9.44 Computer Experiment: OverlapSave Method. Write a standalone C or MATLAB program, say ovsave.c, that implements the overlapsave method of fast convolution. The program must have usage: ovsave h.dat N < x.dat > y.dat
Like the program firfilt.c of Problem 4.10, it must read dynamically the impulse response coefficients from a file h.dat. It must keep reading the input samples in blocks of length N (overlapped by M points), processing each block, and writing the output block. The processing of each block must be implemented by Npoint FFTs, that is,
y # = IFFT H · FFT(x)
where the FFT of the filter H = FFT(h) may be computed once and used in processing all the input blocks. Care must be exercised in handling the first M inputs, where M zeros must be padded to the beginning of the input. When the endoffile of the input is detected, the program must calculate correctly the inputoff output transients. (The output of this program and that of firfilt.c must be identical, up to perhaps some last zeros.)
10 FIR Digital Filter Design
The filter design problem is the problem of constructing the transfer function of a filter that meets prescribed frequency response specifications. The input to any filter design method is the set of desired specifications and the output is the finite impulse response coefficient vector h = [h0 , h1 , . . . , hN−1 ] in the case of FIR filters, or the numerator and denominator coefficient vectors b = [b0 , b1 , . . . , bM ], a = [1, a1 , . . . , aM ] in the case of IIR filters. The subject of FIR and IIR digital filter design is very extensive [2–8]. In this and the next chapter, we present only a small cross section of available design methods—our objective being to give the flavor of the subject, while at the same time presenting some practical methods. The two main advantages of FIR filters are their linear phase property and their guaranteed stability because of the absence of poles. Their potential disadvantage is that the requirement of sharp filter specifications can lead to long filter lengths N, consequently increasing their computational cost. Recall from Chapter 4 that modern DSP chips require N MACs per output point computed. The main advantages of IIR filters are their low computational cost and their efficient implementation in cascade of secondorder sections. Their main disadvantage is the potential for instabilities introduced when the quantization of the coefficients pushes the poles outside the unit circle. For IIR filters, linear phase cannot be achieved exactly over the entire Nyquist interval, but it can be achieved approximately over the relevant passband of the filter, for example, using Bessel filter designs.
10.1 Window Method 10.1.1 Ideal Filters The window method is one of the simplest methods of designing FIR digital filters. It is well suited for designing filters with simple frequency response shapes, such as ideal lowpass filters. Some typical filter shapes that can be designed are shown in Figs. 10.1.1 and 10.1.2. For arbitrary shapes, a variant of the method, known as frequency sampling method, may be used; it will be discussed in Section 10.3.
532
533
10.1. WINDOW METHOD
lowpass
highpass
D(ω) 1
D(ω) 1
ω −π
−ωc
ωc
0
bandpass
ω
π
−π
−ωc
bandstop
D(ω)
ωc
0
D(ω)
1
1
π
ω −π −ωb −ωa
ωa
0
ωb
ω
π
−π
−ωb −ωa
ωa
0
ωb
π
Fig. 10.1.1 Ideal lowpass, highpass, bandpass, and bandstop filters.
D(ω)/j
D(ω)/j 1
differentiator −π
ω 0
ω −π
π
0
Hilbert transformer
π
−1
Fig. 10.1.2 Ideal differentiator and Hilbert transformer filters.
A given desired ideal frequency response, say D(ω), being periodic in ω with period 2π, need only be specified over one complete Nyquist interval −π ≤ ω ≤ π. The corresponding impulse response, say d(k), is related to D(ω) by the DTFT and inverse DTFT relationships:
D(ω)=
∞
d(k)e−jωk
d(k)=
π
D(ω)ejωk
−π
k=−∞
dω 2π
(10.1.1)
In general, the impulse response d(k) will be doublesided and infinite. For many ideal filter shapes, the ωintegration in Eq. (10.1.1) can be done in closed form. For example, for the lowpass filter shown in Fig. 10.1.1, the quantity D(ω) is defined over the Nyquist interval by
D(ω)=
1, 0,
if −ωc ≤ ω ≤ ωc if −π ≤ ω < −ωc , or ωc < ω ≤ π
Therefore, Eq. (10.1.1) gives:
d(k) = =
π
D(ω)ejωk
−π
!
ejωk 2πjk
"ωc
−ωc
=
dω = 2π
ωc
−ωc
1 · ejωk
ejωc k − e−jωc k 2πjk
dω 2π
534
10. FIR DIGITAL FILTER DESIGN
which can be rewritten as (lowpass filter)
d(k)=
sin(ωc k)
πk
−∞ < k < ∞
,
(10.1.2)
For computational purposes, the case k = 0 must be handled separately. Taking the limit k → 0, we find from Eq. (10.1.2):
d(0)=
ωc π
(10.1.3)
Similarly, we find for the highpass, bandpass, and bandstop filters of Fig. 10.1.1, defined over −∞ < k < ∞ (highpass filter)
d(k)= δ(k)−
sin(ωc k)
πk
sin(ωb k)− sin(ωa k)
(bandpass filter)
d(k)=
(bandstop filter)
d(k)= δ(k)−
(10.1.4)
πk sin(ωb k)− sin(ωa k)
πk
Note that for the same values of the cutoff frequencies ωc , ωa , ωb , the lowpass/highpass and bandpass/bandstop filters are complementary, that is, their impulse responses add up to a unit impulse δ(k) and their frequency responses add up to unity (as can also be seen by inspecting Fig. 10.1.1):
dLP (k)+dHP (k)= δ(k)
DLP (ω)+DHP (ω)= 1
dBP (k)+dBS (k)= δ(k)
DBP (ω)+DBS (ω)= 1
(10.1.5) As we see below, such complementarity properties can be exploited to simplify the implementation of loudspeaker crossover networks and graphic equalizers. The ideal differentiator filter of Fig. 10.1.2 has frequency response D(ω)= jω, defined over the Nyquist interval. The ideal Hilbert transformer response can be expressed compactly as D(ω)= −jsign(ω), where sign(ω) is the signum function which is equal to ±1 depending on the algebraic sign of its argument. The ωintegrations in Eq. (10.1.1) give the impulse responses: (differentiator)
d(k)=
(Hilbert transformer)
d(k)=
cos(πk)
k
−
sin(πk)
1 − cos(πk)
πk2
(10.1.6)
πk
Both filters have d(0)= 0, as can be verified by carefully taking the limit k → 0. Both impulse responses d(k) are realvalued and odd (antisymmetric) functions of k. By contrast, the filters of Fig. 10.1.1 all have impulse responses that are real and even (symmetric) in k. We will refer to the two classes of filters of Figs. 10.1.1 and 10.1.2 as the symmetric and antisymmetric classes. In the frequency domain, the symmetric types are characterized by a frequency response D(ω) which is real and even in ω; the antisymmetric ones have D(ω) which is imaginary and odd in ω. One of the main consequences of these frequency properties is the linear phase property of the window designs.
535
10.1. WINDOW METHOD
10.1.2 Rectangular Window The window method consists of truncating, or rectangularly windowing, the doublesided d(k) to a finite length. For example, we may keep only the coefficients:
d(k)=
π
D(ω)ejωk
−π
dω , 2π
−M ≤ k ≤ M
(10.1.7)
Because the coefficients are taken equally for positive and negative k’s, the total number of coefficients will be odd, that is, N = 2M + 1 (even values of N are also possible, but not discussed in this text). The resulting Ndimensional coefficient vector is the FIR impulse response approximating the infinite ideal response: d = [d−M , . . . , d−2 , d−1 , d0 , d1 , d2 , . . . , dM ]
(10.1.8)
The time origin k = 0 is at the middle d0 of this vector. To make the filter causal we may shift the time origin to the left of the vector and reindex the entries accordingly: h = d = [h0 , . . . , hM−2 , hM−1 , hM , hM+1 , hM+2 , . . . , h2M ]
(10.1.9)
where we defined h0 = d−M , h1 = d−M+1 , . . . , hM = d0 , . . . , h2M = dM . Thus, the vectors d and h are the same, with the understanding that d’s origin is in its middle and h’s at its left. The definition of h may be thought of as timedelaying the doublesided sequence d(k), −M ≤ k ≤ M, by M time units to make it causal:
h(n)= d(n − M),
n = 0, 1, . . . , N − 1
(10.1.10)
The operations of windowing and delaying are shown in Fig. 10.1.3. To summarize, the steps of the rectangular window method are simply: 1. Pick an odd length N = 2M + 1, and let M = (N − 1)/2. 2. Calculate the N coefficients d(k) from Eq. (10.1.7), and 3. Make them causal by the delay (10.1.10).
rectangular window
d(k)
h(n)
... 5 4 3 2 1 0 1 2 3 4 5 ... k
rectangular window w(n)
2 1 0 1 2 3 4 5 6 7 8 9 ... n
Fig. 10.1.3 Rectangularly windowed impulse response, with N = 9, M = 4.
For example, the Ndimensional approximation to the ideal lowpass filter of Eq. (10.1.2) will be:
h(n)= d(n − M)=
sin ωc (n − M)
π(n − M)
, n = 0, . . . , M, . . . , N − 1
(10.1.11)
536
10. FIR DIGITAL FILTER DESIGN
where we must calculate separately h(M)= d(0)= ωc /π. For other ideal filter shapes, we can use the functions d(k) of Eqs. (10.1.4) or (10.1.6). Once the impulse response coefficients are calculated, the filter may be implemented by its FIR filtering equation, using the routines fir or cfir of Chapter 4: N− 1
yn =
hm xn−m
(10.1.12)
m=0
Example 10.1.1: Determine the length11, rectangularly windowed impulse response that approximates (a) an ideal lowpass filter of cutoff frequency ωc = π/4, (b) the ideal differentiator filter, and (c) the ideal Hilbert transformer filter.
Solution: With N = 11, we have M = (N − 1)/2 = 5. For the lowpass filter, we evaluate Eq. (10.1.2), that is,
d(k)=
sin(πk/4)
πk
,
for −5 ≤ k ≤ 5
We find the numerical values: h=d=
!
−
√
√
√
√
√
√
2 2 1 2 1 2 1 2 2 , 0, , , , , , , , 0, − 10π 6π 2π 2π 4 2π 2π 6π 10π
"
For the differentiator filter, the second term, sin(πk)/πk2 , vanishes for all values k = 0. Therefore, we find: h=d=
1 1 1 1 1 1 1 1 , − , , − , 1, 0, −1, , − , , − 5 4 3 2 2 3 4 5
And, for the Hilbert transformer:
h=d= −
2 2 2 2 2 2 , 0, , 0, − , 0, − , 0, , 0, π 3π 5π 5π 3π π
Note that the lowpass filter’s impulse response is symmetric about its middle, whereas the differentiator’s and Hilbert transformer’s are antisymmetric. Note also that because of the presence of the factor 1 − cos(πk), every other entry of the Hilbert transformer vanishes. This property can be exploited to reduce by half the total number of multiplications required in the convolutional equation Eq. (10.1.12).
In the frequency domain, the FIR approximation to D(ω) is equivalent to truncating the DTFT Fourier series expansion (10.1.1) to the finite sum:
D(ω)=
M
d(k)e−jωk
(10.1.13)
k=−M
Replacing z = ejω , we may also write it as the doublesided ztransform:
D(z)=
M
k=−M
d(k)z−k
(10.1.14)
537
10.1. WINDOW METHOD The final lengthN filter obtained by Eq. (10.1.10) will have transfer function:
z−M H(z)= z−M D(z)=
M
d(k)z−k
(10.1.15)
k=−M
and frequency response:
e−jωM H(ω)= e−jωM D(ω)=
M
d(k)e−jωk
(10.1.16)
k=−M
Example 10.1.2: To illustrate the definition of H(z), consider a case with N = 7 and M = (N − 1)/2 = 3. Let the FIR filter weights be d = [d−3 , d−2 , d−1 , d0 , d1 , d2 , d3 ] with truncated ztransform: D(z)= d−3 z3 + d−2 z2 + d−1 z + d0 + d1 z−1 + d2 z−2 + d3 z−3
Delaying it by M = 3, we get the causal transfer function:
= z−3 d−3 z3 + d−2 z2 + d−1 z + d0 + d1 z−1 + d2 z−2 + d3 z−3 H(z)= z−3 D(z) = d−3 + d−2 z−1 + d−1 z−2 + d0 z−3 + d1 z−4 + d2 z−5 + d3 z−6
= h0 + h1 z−1 + h2 z−2 + h3 z−3 + h4 z−4 + h5 z−5 + h6 z−6 where we defined h(n)= d(n − 3), n = 0, 1, 2, 3, 4, 5, 6.
The linear phase property of the window design is a direct consequence of Eq. (10.1.16). The truncated D(ω) has the same symmetry/antisymmetry properties as D(ω). Thus, in the symmetric case, D(ω) will be real and even in ω. It follows from Eq. (10.1.16) that the designed FIR filter will have linear phase, arising essentially from the delay fac tor e−jωM . More precisely, we may write the real factor D(ω) in terms of its positive magnitude and its sign:
D(ω)= sign D(ω) D(ω) = ejπβ(ω) D(ω)
where β(ω)= 1 − sign D(ω) /2, which is zero or one depending on the sign of D(ω) . It follows that H(ω) will be: H(ω)= e−jωM D(ω)= e−jωM+jπβ(ω) D(ω)
Thus, its magnitude and phase responses will be:
H(ω) = D(ω) ,
arg H(ω)= −ωM + π β(ω) o
(10.1.17)
making the phase response piecewise linear in ω with 180 jumps at those ω where D(ω) changes sign. For the antisymmetric case, D(ω) will be pure imaginary, that is, of the form D(ω)= jA(ω). The factor j may be made into a phase by writing it as j = ejπ/2 . Thus, we have
538
10. FIR DIGITAL FILTER DESIGN
e−jωM ejπ/2 A(ω)= e−jωM ejπ/2 ejπα(ω) A(ω) H(ω)= e−jωM D(ω)=
where α(ω)= sponses:
/2, which gives for the magnitude and phase re
1 − sign A(ω)
H(ω) = A(ω) ,
arg H(ω)= −ωM +
π 2
+ π α(ω)
(10.1.18)
How good is the rectangular window design? How well does the truncated D(ω) represent the desired response D(ω)? In other words, how good is the approximation D(ω) D(ω)? Intuitively one would expect that D(ω)→ D(ω) as N increases. This is true for any ω which is a point of continuity of D(ω), but it fails at points of discontinuity, such as at the transition edges from passband to stopband. Around these edges one encounters the celebrated Gibbs phenomenon of Fourier series, which causes the approximation to be bad regardless of how large N is. To illustrate the nature of the approximation D(ω) D(ω), we consider the design of an ideal lowpass filter of cutoff frequency ωc = 0.3π, approximated by a rectangularly windowed response of length N = 41 and then by another one of length N = 121. For the case N = 41, we have M = (N − 1)/2 = 20. The designed impulse response is given by Eq. (10.1.10): h(n)= d(n − 20)=
sin 0.3π(n − 20) , π(n − 20)
n = 0, 1, . . . , 40
and in particular, h(20)= d(0)= ωc /π = 0.3. The second design has N = 121 and M = 60. Its impulse response is, with h(60)= d(0)= 0.3: sin 0.3π(n − 60) , n = 0, 1, . . . , 120 h(n)= d(n − 60)= π(n − 60) The two impulse responses are plotted in Fig. 10.1.4. Note that the portion of the second response extending ±20 samples around the central peak at n = 60 coincides numerically with the first response. The corresponding magnitude responses are shown in Fig. 10.1.5. An intermediate case having N = 81 is shown in Figs. 10.1.6 and 10.1.7. In Fig. 10.1.5, the magnitude responses were computed by evaluating:
H(ω)=
N− 1
h(n)e−jωn
(10.1.19)
n=0
The lengthN impulse response h(n) defined in Eq. (10.1.10) may be thought of formally as the rectangularly windowed doublesided sequence defined by
h(n)= w(n)d(n − M) ,
−∞ < n < ∞
(10.1.20)
where w(n) is the lengthN rectangular window. In the frequency domain, this translates to the convolution of the corresponding spectra, as in Eq. (9.1.8):
539
10.1. WINDOW METHOD
Fig. 10.1.4 Rectangularly windowed impulse responses for N = 41 and N = 121.
Fig. 10.1.5 Rectangularly windowed magnitude responses for N = 41 and N = 121.
H(ω)=
π
−π
W(ω − ω )e−jω M D(ω )
dω 2π
(10.1.21)
where the e−jω M arises from the delay in d(n − M). The spectrum W(ω) of the rectangular window was given in Eq. (9.1.9) (with L = N). Thus, the designed filter H(ω) will be a smeared version of the desired shape D(ω). In particular, for the ideal lowpass case, because D(ω ) is nonzero and unity only over the subinterval −ωc ≤ ω ≤ ωc , the frequency convolution integral becomes:
H(ω)=
ωc
−ωc
W(ω − ω )e−jω M
dω 2π
(10.1.22)
The ripples in the frequency response H(ω), observed in Fig. 10.1.5, arise from the (integrated) ripples of the rectangular window spectrum W(ω). As N increases, we observe three effects in Fig. 10.1.5: 1. For ω’s that lie well within the passband or stopband (i.e., points of continuity), the ripple size decreases as N increases, resulting in flatter passband and stopband. For such ω, we have D(ω)→ D(ω) as N → ∞.
540
10. FIR DIGITAL FILTER DESIGN
2. The transition width decreases with increasing N. Note also that for any N, the windowed response H(ω) is always equal to 0.5 at the cutoff frequency ω = ωc . (This is a standard property of Fourier series.) 3. The largest ripples tend to cluster near the passbandtostopband discontinuity (from both sides) and do not get smaller with N. Instead, their size remains approximately constant, about 8.9 percent, independent of N. Eventually, as N → ∞, these ripples get squeezed onto the discontinuity at ω = ωc , occupying a set of measure zero. This behavior is the Gibbs phenomenon.
10.1.3 Hamming Window To eliminate the 8.9% passband and stopband ripples, we may replace the rectangular window w(n) in Eq. (10.1.20) by a nonrectangular one, which tapers off gradually at its endpoints, thus reducing the ripple effect. There exist dozens of windows [219–222] and among these the Hamming window is a popular choice; it is defined by:
w(n)= 0.54 − 0.46 cos
2πn N−1
,
n = 0, 1, . . . , N − 1
(10.1.23)
In particular, the Hamming windowed impulse response for a lengthN lowpass filter will be, where N = 2M + 1 and n = 0, 1, . . . , N − 1:
2πn sin ωc (n − M) h(n)= w(n)d(n − M)= 0.54 − 0.46 cos · N−1 π(n − M)
(10.1.24)
As an example, consider the design of a length N = 81 lowpass filter with cutoff frequency ωc = 0.3π. Fig. 10.1.6 shows the rectangularly and Hamming windowed impulse responses. Note how the Hamming impulse response tapers off to zero more gradually. It was computed by Eq. (10.1.24) with N = 81 and M = 40. Fig. 10.1.7 shows the corresponding magnitude responses.
Fig. 10.1.6 Rectangular and Hamming windowed impulse responses for N = 81.
541
10.2. KAISER WINDOW
Fig. 10.1.7 Rectangular and Hamming windowed magnitude responses for N = 81.
The passband/stopband ripples of the rectangular window design are virtually eliminated from the Hamming window design. Actually, there are small ripples with maximum overshoot of about 0.2%, but they are not visible in the scale of Fig. 10.1.7. The price for eliminating the ripples is loss of resolution, which is reflected into a wider transition width.
10.2 Kaiser Window 10.2.1 Kaiser Window for Filter Design The rectangular and Hamming window designs are very simple, but do not provide good control over the filter design specifications. With these windows, the amount of overshoot is always fixed to 8.9% or 0.2% and cannot be changed to a smaller value if so desired. A flexible set of specifications is shown in Fig. 10.2.1 in which the designer can arbitrarily specify the amount of passband and stopband overshoot δpass , δstop , as well as the transition width ∆f . The passband/stopband frequencies {fpass , fstop } are related to the ideal cutoff frequency fc and transition width ∆f by
fc =
1 (fpass + fstop ) , 2
∆f = fstop − fpass
(10.2.1)
Thus, fc is chosen to lie exactly in the middle between fpass and fstop . Eqs. (10.2.1) can be inverted to give:
fpass = fc −
1 ∆f , 2
fstop = fc +
1 ∆f 2
(10.2.2)
The normalized versions of the frequencies are the digital frequencies:
ωpass =
2πfpass
fs
,
ωstop =
2πfstop
fs
,
ωc =
2πfc
fs
,
∆ω =
2π∆f
fs
542
10. FIR DIGITAL FILTER DESIGN
In practice, the passband and stopband overshoots are usually expressed in dB:
Apass = 20 log10
1 + δpass
1 − δpass
Astop = −20 log10 δstop
,
(10.2.3)
A simplified version of the passband equation can be obtained by expanding it to first order in δpass , giving:
Apass = 17.372δpass
(10.2.4)
which is valid for small values of δpass . Eqs. (10.2.3) can be inverted to give:
δpass =
10Apass /20 − 1 , 10Apass /20 + 1
δstop = 10−Astop /20
(10.2.5)
Thus, one can pass back and forth between the specification sets:
{fpass , fstop , Apass , Astop }
designed filter H( f )
desired ideal filter D( f )
1+δpass 1−δpass
{fc , ∆f , δpass , δstop }
Apass
1
Astop
∆f = transition width
1/2
f
δstop 0
fs /2
fstop
fpass
passband
stopband
fc
Fig. 10.2.1 Magnitude response specifications for a lowpass filter.
Although δpass and δstop can be specified independently of each other, it is a property of all window designs that the final designed filter will have equal passband and stopband ripples. Therefore, we must design the filter on the basis of the smaller of the two ripples, that is,
δ = min(δpass , δstop )
(10.2.6)
The designed filter will have passband and stopband ripple equal to δ. The value of
δ can also be expressed in dB: A = −20 log10 δ ,
δ = 10−A/20
(10.2.7)
543
10.2. KAISER WINDOW
In practice, the design is usually based on the stopband ripple δstop . This is so because any reasonably good choices for the passband and stopband attenuations (e.g., Apass = 0.1 dB and Astop = 60 dB) will almost always result into δstop < δpass , and therefore, δ = δstop , and in dB, A = Astop . Thus, it is useful to think of A as the stopband attenuation. The main limitation of most windows is that they have a fixed value of δ, which depends on the particular window shape. Such windows limit the achievable passband and stopband attenuations {Apass , Astop } to only certain specific values. For example, Table 10.2.1 shows the attenuations achievable by the rectangular and Hamming windows, calculated from Eq. (10.2.3) with the values δ = δpass = δstop = 0.089 and δ = δpass = δstop = 0.002, respectively. The table also shows the corresponding value of the transition width parameter D of Eq. (10.2.11). The only windows that do not suffer from the above limitation are the Kaiser window [245–247], the DolphChebyshev window [248–253], and the Saram¨ aki windows [254]. These windows have an adjustable shape parameter that allows the window to achieve any desired value of ripple δ or attenuation A. Window
δ
Astop
Apass
D
Rectangular Hamming Kaiser
8.9% 0.2% variable δ
−21 dB −54 dB
1.55 dB 0.03 dB 17.372δ
0.92 3.21 (A − 7.95)/14.36
−20 log10 δ
Table 10.2.1 Specifications for rectangular, Hamming, and Kaiser windows.
The Kaiser window is unique in the above class in that it has nearoptimum performance (in the sense of minimizing the sidelobe energy of the window), as well as having the simplest implementation. It depends on two parameters: its length N and the shape parameter α. Assuming odd length N = 2M + 1, the window is defined, for n = 0, 1, . . . , N − 1, as follows: (Kaiser window)
w(n)=
I0 α 1 − (n − M)2 /M2 I0 (α)
(10.2.8)
where I0 (x) is the modified Bessel function of the first kind and 0th order. This function and its evaluation by the routine I0.c are discussed at the end of this section. The numerator in Eq. (10.2.8) can be rewritten in the following form, which is more convenient for numerical evaluation:
w(n)=
I0 α n(2M − n)/M , I0 (α)
n = 0, 1, . . . , N − 1
(10.2.9)
Like all window functions, the Kaiser window is symmetric about its middle, n = M, and has the value w(M)= 1 there. At the endpoints, n = 0 and n = N − 1, it has the value 1/I0 (α) because I0 (0)= 1. Figure 10.2.2 compares a Hamming window of length N = 51 to the Kaiser windows of the same length and shape parameters α = 7 and α = 5. For α = 5 the Kaiser and
544
10. FIR DIGITAL FILTER DESIGN
Hamming windows agree closely, except near their endpoints. For α = 0 the Kaiser window reduces to the rectangular one.
Fig. 10.2.2 Kaiser and Hamming windows for N = 51 and α = 5, 7.
The window parameters {N, α} are computable in terms of the filter specifications, namely, the ripple δ and transition width ∆f . The design equations developed by Kaiser [245–247] are as follows. The shape parameter α is calculated from:
0.1102(A − 8.7), 0.5842(A − 21)0.4 +0.07886(A − 21), α= 0,
if A ≥ 50 if 21 < A < 50 if A ≤ 21
(10.2.10)
where A is the ripple in dB, given by Eq. (10.2.7). The filter length N is inversely related to the transition width:
∆f =
Dfs N−1
N−1=
Dfs ∆f
(10.2.11)
where the factor D is computed also in terms of A by
A − 7.95 , D= 14.36 0.922,
to:
if A > 21
(10.2.12)
if A ≤ 21
The most practical range of these formulas is for A ≥ 50 dB, for which they simplify
α = 0.1102(A − 8.7) ,
D=
A − 7.95 14.36
(for A ≥ 50 dB)
(10.2.13)
To summarize, the steps for designing a lowpass filter are as follows. Given the specifications {fpass , fstop , Apass , Astop }: 1. Calculate fc and ∆f from Eq. (10.2.1). Then, calculate ωc = 2πfc /fs .
545
10.2. KAISER WINDOW 2. Calculate δpass and δstop from Eq. (10.2.5). 3. Calculate δ = min(δpass , δstop ) and A = −20 log10 δ in dB. 4. Calculate α and D from Eqs. (10.2.10) and (10.2.12).
5. Calculate the filter length N from Eq. (10.2.11) and round it up to the next odd integer, N = 2M + 1, and set M = (N − 1)/2. 6. Calculate the window function w(n), n = 0, 1, . . . , N − 1 from Eq. (10.2.8). 7. Calculate the windowed impulse response, for n = 0, 1, . . . , N − 1:
h(n)= w(n)d(n − M)= w(n)·
sin ωc (n − M)
π(n − M)
(10.2.14)
In particular, we have h(M)= w(M)ωc /π = ωc /π, because w(M)= 1. Note that the window parameters {N, α} depend only on the specifications {A, ∆f } and not on fc . However, h(n) does depend on fc . The design steps can be modified easily to design highpass and bandpass filters. For highpass filters, the role of fpass and fstop are interchanged; therefore, the only change in the steps is to define ∆f = fpass −fstop and to use the highpass response from Eq. (10.1.4). The highpass impulse response will be:
!
h(n)= w(n)d(n − M)= w(n)· δ(n − M)−
sin ωc (n − M)
π(n − M)
"
The first term can be simplified to w(n)δ(n − M)= w(M)δ(n − M)= δ(n − M) because w(M)= 1. Therefore, the designed filter will be:
h(n)= δ(n − M)−w(n)·
sin ωc (n − M)
π(n − M)
(10.2.15)
For the same value of ωc , the lowpass and highpass filters are complementary. The sum of Eqs. (10.2.14) and (10.2.15) gives:
hLP (n)+hHP (n)= δ(n − M) ,
n = 0, 1, . . . , N − 1
(10.2.16)
which becomes in the zdomain:
HLP (z)+HHP (z)= z−M
(10.2.17)
For bandpass filters, the desired specifications may be given as in Fig. 10.2.3. There are now two stopbands and two transition widths. The final design will have equal transition widths, given by Eq. (10.2.11). Therefore, we must design the filter based on the smaller of the two widths, that is,
∆f = min(∆fa , ∆fb ) where the left and right transition widths are:
(10.2.18)
546
10. FIR DIGITAL FILTER DESIGN
∆fa = fpa − fsa ,
∆fb = fsb − fpb
(10.2.19)
Figure 10.2.3 shows the case where the left transition width is the smaller one and, thus, defines ∆f . The ideal cutoff frequencies fa and fb can be calculated by taking them to be ∆f /2 away from the passband or from the stopbands. The standard definition is with respect to the passband:
fa = fpa −
1 ∆f , 2
fb = fpb +
1 ∆f 2
(10.2.20)
This choice makes the passband just right and the stopband somewhat wider than required. The alternative definition makes the stopbands right and the passband wider:
fa = fsa +
1 ∆f , 2
fb = fsb −
1 ∆f 2
desired ideal filter D( f ) 1+δpass 1−δpass
standard design alternative design
Apass
1
∆f ∆f 2 2
Astop
(10.2.21)
∆f 2
∆fa
∆f 2 ∆fb
δstop
f
0
fpa
fsa
stopband
fpb
passband
fa
fs /2
fsb fb
fb
stopband
Fig. 10.2.3 Bandpass filter specifications.
Once the cutoff frequencies {fa , fb } and the window parameters {N, α} are calculated, the bandpass impulse response may be defined, for n = 0, 1, . . . , N − 1:
h(n)= w(n)d(n − M)= w(n)·
sin ωb (n − M) − sin ωa (n − M)
π(n − M)
(10.2.22)
where h(M)= (ωb − ωa )/π, and ωa = 2πfa /fs , ωb = 2πfb /fs . Next, we present a lowpass and a bandpass design example. Example 10.2.1: Lowpass Design. Using the Kaiser window, design a lowpass digital filter with the following specifications:
fs = 20 kHz fpass = 4 kHz, fstop = 5 kHz Apass = 0.1 dB, Astop = 80 dB
547
10.2. KAISER WINDOW Solution: First, we calculate δpass and δstop from Eq. (10.2.5): δpass =
100.1/20 − 1 = 0.0058, 100.1/20 + 1
δstop = 10−80/20 = 0.0001
Therefore, δ = min(δpass , δstop )= δstop = 0.0001, which in dB is A = −20 log10 δ = Astop = 80. The D and α parameters are computed by:
α = 0.1102(A − 8.7)= 0.1102(80 − 8.7)= 7.857,
D=
A − 7.95 = 5.017 14.36
The filter width and ideal cutoff frequency are:
∆f = fstop − fpass = 1 kHz,
fc =
1 (fpass + fstop )= 4.5 kHz, 2
ωc =
2πfc
fs
= 0.45π
Eq. (10.2.11) gives for the filter length (rounded up to the nearest odd integer):
N =1+
Dfs = 101.35 ∆f
⇒
N = 103,
M=
1 (N − 1)= 51 2
The windowed impulse response will be, for n = 0, 1, . . . , 102:
h(n)= w(n)d(n − M)=
sin 0.45π(n − 51) I0 7.857 n(102 − n)/51 · I0 (7.857) π(n − 51)
with h(51)= ωc /π = 0.45. Figure 10.2.4 shows the magnitude response in dB of h(n), that is, 20 log10 H(ω), where H(ω) was evaluated by Eq. (10.1.19). Note the transition width extending from 4 to 5 kHz and the stopband specification defined by the horizontal grid line at −80 dB. The passband specification is more than satisfied. It is Apass 17.372δ = 0.0017 dB.
Fig. 10.2.4 Kaiser, Hamming, and rectangular window designs, N = 103. The figure also shows the corresponding Hamming and rectangularly windowed designs for the same length of N = 103. They both have a smaller transition width—the rectangular one even more so, but their stopband attenuations are limited to the standard values of 54 dB and 21 dB, respectively.
548
10. FIR DIGITAL FILTER DESIGN
Example 10.2.2: Bandpass Design. Using the Kaiser window, design a bandpass digital filter with the following specifications:
fs = 20 kHz fsa = 3 kHz, fpa = 4 kHz, fpb = 6 kHz, Apass = 0.1 dB, Astop = 80 dB
fsb = 8 kHz
Solution: The parameters {δpass , δstop , δ, A, α, D} are the same as in the previous example. The two transition widths are:
∆fa = fpa − fsa = 4 − 3 = 1 kHz,
∆fb = fsb − fpb = 8 − 6 = 2 kHz
Therefore, the minimum width is ∆f = min(∆fa , ∆fb )= 1 kHz, and the filter length:
N =1+
Dfs = 101.35 ∆f
⇒
N = 103,
M=
1 (N − 1)= 51 2
Using the standard definition of Eq. (10.2.20), we find for the left and right ideal cutoff frequencies:
fa = fpa −
1 ∆f = 4 − 0.5 = 3.5 kHz, 2
fb = fpb +
1 ∆f = 6 + 0.5 = 6.5 kHz 2
with the normalized values ωa = 2πfa /fs = 0.35π, ωb = 2πfb /fs = 0.65π. For the alternative definition of Eq. (10.2.21), we have fa = 3 + 0.5 = 3.5 and fb = 8 − 0.5 = 7.5 kHz, resulting in ωa = 0.35π and ωb = 0.75π. Figure 10.2.5 shows the magnitude response of the designed filter in dB, both for the standard and the alternative definitions. The standard design has just the right passband extending over [4, 6] kHz and a wider stopband that starts at 7 kHz. The alternative design has a wider passband extending over [4, 7] kHz.
Fig. 10.2.5 Kaiser window design of a bandpass filter.
Next, we discuss three more Kaiser design examples for digital audio applications, namely, twoway and threeway loudspeaker crossover filters and a fiveband graphic equalizer.
549
10.2. KAISER WINDOW
In all three cases, the sampling rate is fs = 44.1 kHz, the stopband attenuation is Astop = 65 dB, and all the transition widths are taken to be equal to ∆f = 2 kHz. This implies that all the filters will have the same length N and Kaiser parameters D and α. With A = Astop = 65 dB, we find
D= N−1=
A − 7.95 = 3.973, 14.36
α = 0.1102(A − 8.7)= 6.204,
Dfs 3.973 × 44.1 = = 87.6 ∆f 2
⇒
N = 89,
M=
1 (N − 1)= 44 2
Note that the given value of A = 65 dB corresponds to δpass = δstop = 10−65/20 = 0.00056, which results in the small passband attenuation Apass = 0.0097 dB. Such filters are to within the capabilities of modern DSP chips. Assuming a typical instruction rate of 20 MIPS, which is 20 instructions per µsec, or, Tinstr = 50 nsec per instruction, and assuming the sample processing implementation requires N MACs per output sample computed, the total computational time for processing each input sample will be NTinstr = 89×50 = 4.45 µsec, which fits well within the time separating each input sample, T = 1/fs = 1/44.1 = 22.68 µsec. Several such filters can even be implemented simultaneously on the same DSP chip, namely, 22.68/4.45 = 5.1, or, about five length89 filters. Conversely, the longest single filter that can be implemented will have length such that NTinstr = T, or, N = T/Tinstr = finstr /fs = 20000/44.1 453, resulting in the smallest implementable transition width of 2
∆fmin
Dfs Dfs = = 0.386 kHz N finstr
Example 10.2.3: TwoWay Crossover Filters. All conventional loudspeakers contain an analog crossover network that splits the incoming analog audio signal into its low and highfrequency components that drive the woofer and tweeter parts of the loudspeaker. More advanced loudspeakers may contain even a third component for the midfrequency part of the input [255]. Digital loudspeaker systems operate on the digitized audio input and use (FIR or IIR) digital filters to split it into the appropriate frequency bands, which are then converted to analog format, amplified, and drive the corresponding parts of the loudspeaker [256,257]. Such “digital” loudspeakers have been available for a while in professional digital studios and are becoming commercially available for home use (where typically the digital output of a CD player is connected to the digital input of the loudspeaker). In this example, we take the cutoff frequency of the lowpass and highpass filters, known as the crossover frequency, to be fc = 3 kHz, which leads to the normalized frequency ωc = 2πfc /fs = 0.136π. (This numerical value of fc is chosen only for plotting convenience—a more realistic value would be 1 kHz.) The designed low and highfrequency driver filters are then: For n = 0, 1, · · · , N − 1
hLP (n) = w(n)dLP (n − M)= w(n)
!
!
sin ωc (n − M)
π(n − M)
hHP (n) = w(n)dHP (n − M)= w(n) δ(n − M)− = δ(n − M)−hLP (n)
"
sin ωc (n − M)
π(n − M)
"
=
550
10. FIR DIGITAL FILTER DESIGN where w(n) is the Kaiser window given by Eq. (10.2.8). The magnitude responses of the designed filters are shown in Fig. 10.2.6, plotted both in absolute scales, H(ω), and in decibels, 20 log10 H(ω).
Fig. 10.2.6 Low and highfrequency magnitude responses. The complementarity relationship between the impulse responses implies in the zdomain:
HHP (z)= z−M − HLP (z) It leads to the realization of Fig. 10.2.7. Instead of realizing the lowpass and highpass filters separately, it requires only the lowpass filter and one multiple delay.
audio in
woofer
HLP(z) zM
+
tweeter
Fig. 10.2.7 Complementary implementation of twoway crossover filters.
Example 10.2.4: ThreeWay Crossover Filters. In this example, the audio input must be split into its low, mid, and highfrequency components. The crossover frequencies are chosen to be fa = 3 kHz and fb = 7 kHz. The midpass filter will be a bandpass filter with these cutoff frequencies. The designed impulse responses will be:
hLP (n) = w(n)dLP (n − M)= w(n)
!
sin ωa (n − M)
"
π(n − M) " sin ωb (n − M) − sin ωa (n − M) hMP (n) = w(n)dMP (n − M)= w(n) π(n − M) ! " sin ωb (n − M) hHP (n) = w(n)dHP (n − M)= w(n) δ(n − M)− π(n − M) !
551
10.2. KAISER WINDOW
where, ωa = 2πfa /fs = 0.136π and ωb = 2πfb /fs = 0.317π. Adding the three impulse responses, we find
hLP (n)+hMP (n)+hHP (n)= δ(n − M) and, in the zdomain
HLP (z)+HMP (z)+HHP (z)= z−M which allows us to express one of them in terms of the other two, for example
HHP (z)= z−M − HLP (z)−HMP (z) The magnitude responses of the designed filters are shown in Fig. 10.2.8. A realization that uses the above complementarity property and requires only two filtering operations
instead of three is shown in Fig. 10.2.9.
Fig. 10.2.8 Lowpass, midpass, and highpass magnitude responses.
audio in
HLP(z)
woofer
HMP(z)
midrange
zM
 +
tweeter
Fig. 10.2.9 Complementary implementation of threeway crossover filters.
Example 10.2.5: FiveBand Graphic Equalizer. Presentday graphic equalizers typically employ secondorder IIR filters. However, there is no reason not to use FIR filters, if the computational cost is manageable. In this example, we choose the crossover frequencies of the five bands to be fa = 3 kHz, fb = 7 kHz, fc = 11 kHz, fd = 15 kHz, defining the five frequency bands:
552
10. FIR DIGITAL FILTER DESIGN
[0, fa ] [fa , fb ] [fb , fc ] [fc , fd ] [fd , fs /2]
band band band band band
1 2 3 4 5
The designed filter impulse responses will be:
h1 (n) = w(n)
!
sin ωa (n − M)
"
π(n − M) " sin ωb (n − M) − sin ωa (n − M) h2 (n) = w(n) π(n − M) ! " sin ωc (n − M) − sin ωb (n − M) h3 (n) = w(n) π(n − M) ! " sin ωd (n − M) − sin ωc (n − M) h4 (n) = w(n) π(n − M) ! " sin ωd (n − M) h5 (n) = w(n) δ(n − M)− π(n − M) !
where, ωa = 2πfa /fs = 0.136π, ωb = 2πfb /fs = 0.317π, ωc = 2πfc /fs = 0.499π, ωd = 2πfd /fs = 0.680π. Adding the five filters we find the relationship:
h1 (n)+h2 (n)+h3 (n)+h4 (n)+h5 (n)= δ(n − M) and, in the zdomain
H1 (z)+H2 (z)+H3 (z)+H4 (z)+H5 (z)= z−M It can be solved for one of the transfer functions in terms of the other ones:
H5 (z)= z−M − H1 (z)−H2 (z)−H3 (z)−H4 (z) The magnitude responses are shown in Fig. 10.2.10. A realization that uses the above complementarity property and requires only four filtering operations instead of five is shown in Fig. 10.2.11. The outputs of the five filters are weighted by the userselectable gains Gi and then summed up to form the “equalized” audio signal. The overall transfer function from the input to the overall output is:
H(z)= G1 H1 (z)+G2 H2 (z)+G3 H3 (z)+G4 H4 (z)+G5 H5 (z) In practice, the crossover frequencies are chosen to follow standard ISO (International Standards Organization) frequencies, dividing the 20 kHz audio range into octaves or fractions
of octaves.
553
10.2. KAISER WINDOW
Fig. 10.2.10 Graphic equalizer magnitude responses.
variable gains audio in
G1
H1(z)
G2
H2(z)
G3
H3(z)
G4
H4(z)
zM
audio out

G5
+
Fig. 10.2.11 Complementary implementation of graphic equalizer.
The above three examples are special cases of parallel filter banks in which the input is split into several nonoverlapping frequency bands covering the Nyquist interval. Applications include multirate filter banks and subband coding of speech, audio, and picture signals in which the outputs of the bank filters are quantized with fewer number of bits and at the same time their sampling rates are dropped, such that the overall bit rate required for the digital transmission or storage of the signal is substantially reduced [275]. For example, in the recent DCC audio cassette system, the allocation of bits in each band is governed by psychoacoustic perceptual criteria in which fewer bits are assigned to bands that will be less audible [295–300]. Wavelets and the discrete wavelet transform are also examples of filter banks [275]. Finally, we consider the definition and computation of the Bessel function I0 (x). It is defined by its Taylor series expansion:
554
10. FIR DIGITAL FILTER DESIGN
I0 (x)=
∞
k=0
!
(x/2)k k!
"2
(10.2.23)
The Kaiser window (10.2.8) requires the evaluation of I0 (x) over the range of argument 0 ≤ x ≤ α. The following C function I0.c evaluates I0 (x) for any x. The routine is essentially a C version of the Fortran routine given by Kaiser in [247]. /* I0.c  Modified Bessel Function I0(x) * 2 $∞ k * I0 (x) = k=0 (x/2) / k! * */ #include <math.h> #define eps
= 10−9
(1.E9)
double I0(x) double x; { int n = 1; double S = 1, D = 1, T; while (D T D S }
usage: y = I0(x)
> eps * S) { = x / (2 * n++); *= T * T; += D;
return S; }
The routine is based on the following recursions, which evaluate the power series (10.2.23) by keeping enough terms in the expansion. We define the partial sum of the series (10.2.23):
Sn =
n
k=0
!
(x/2)k k!
"2
It is initialized to S0 = 1 and satisfies the recursion, for n ≥ 1:
Sn = Sn−1 + Dn ,
where Dn =
(x/2)n n!
2
In turn, Dn itself satisfies a recursion, for n ≥ 1:
Dn =
x 2n
2
Dn−1 = Tn2 Dn−1 ,
where Tn =
x 2n
and it is initialized to D0 = 1. The iteration stops when the successive Dn terms become much smaller than the accumulated terms Sn , that is, when
Dn Sn − Sn−1 = Astop . In summary, given {Ωpass , Ωstop , Apass , Astop }, we solve Eqs. (11.6.10)–(11.6.13) to get the filter parameters N and Ω0 . We note also that we may rewrite Eq. (11.6.7) in terms of the passband parameters; replacing Ω0 by Eq. (11.6.13), we have
596
11. IIR DIGITAL FILTER DESIGN
H(Ω)2 =
1+
1
Ω Ω0
2 N =
1
1 + ε2pass
Ω Ωpass
2N
(11.6.14)
An alternative design can be obtained by matching the stopband specification exactly, resulting in a slightly better passband, that is, A(Ωstop )= Astop and A(Ωpass )< Apass . The 3dB frequency Ω0 is now computed from the second of Eqs. (11.6.9):
Ωstop
Ω0 =
10Astop /10
−1
1/2N =
Ωstop /N ε1stop
In this case, Eq. (11.6.7) can be written in terms of the stopband parameters:
H(Ω)2 =
1
1+
ε2stop
Ω Ωstop
2 N
Ωstop 2N Ω = Ωstop 2N + ε2stop Ω
(11.6.15)
We will see in Section 11.6.6 that the expressions (11.6.14) and (11.6.15) generalize to the Chebyshev type 1 and type 2 filters. The analog Butterworth transfer function H(s) can be constructed from the knowledge of {N, Ω0 } by the method of spectral factorization, as described below. Using ∗ s = jΩ and noting that H(Ω) = H∗ (−Ω), we may write Eq. (11.6.7) in terms of the variable s†
H(s)H∗ (−s)= 1+ Setting H(s)=
1
D(s)
1
s jΩ0
2N =
1 1 + (−1)N
s Ω0
2 N
, we have
D(s)D∗ (−s)= 1 + (−1)N
s Ω0
2N
(11.6.16)
Because the righthand side is a polynomial of degree 2N in s, D(s) will be a polynomial of degree N. There exist 2N different polynomials D(s) of degree N satisfying Eq. (11.6.16). But, among them, there is a unique one that has all its zeros in the lefthand splane. This is the one we want, because then the transfer function H(s)= 1/D(s) will be stable and causal. To find D(s), we first determine all the 2N roots of Eq. (11.6.16) and then choose those that lie in the lefthand splane. The 2N solutions of 1 + (−1)N
s Ω0
2N
=0
⇒
s2N = (−1)N−1 Ω0 2N
are given by † The notation H ∗ (−s) denotes complex conjugation of the filter coefficients and replacement of s by $ $ n an sn . −s, for example, H∗ (−s)= a∗ n (−s) if H(s)=
597
11.6. HIGHERORDER FILTERS
si = Ω0 ejθi ,
θi =
π 2N
(N − 1 + 2i) ,
i = 1, 2, . . . , N, . . . , 2N
(11.6.17)
The index i is chosen such that the first N of the si lie in the lefthand splane, that is, π/2 < θi < 3π/2 for i = 1, 2, . . . , N. Because si  = Ω0 , all of the zeros lie on a circle of radius Ω0 , called the Butterworth circle and shown in Fig. 11.6.2. π/N
s2
splane
s1
. . .
s3 Ω0
−Ω0 . . .
0 Butterworth circle
sN2 sN1
sN
Fig. 11.6.2 Butterworth filter poles lie on Butterworth circle.
It is evident from Eq. (11.6.17) that the si can be paired in complex conjugate pairs; ∗ that is, sN = s∗ 1 , sN−1 = s2 , and so on. If N is even, say N = 2K , then there are exactly K conjugate pairs, namely, {si , s∗ i }, i = 1, 2, . . . , K . In this case, D(s) will factor into secondorder sections as follows:
D(s)= D1 (s)D2 (s)· · · DK (s)
(11.6.18)
where
s s 1− ∗ , Di (s)= 1 − si si
i = 1, 2, . . . , K
(11.6.19)
On the other hand, if N is odd, say N = 2K + 1, there will be K conjugate pairs and one additional zero that cannot be paired and must necessarily be realvalued. That zero must lie in the lefthand splane and on the Butterworth circle; thus, it must be the point s = −Ω0 . The polynomial D(s) factors now as:
D(s)= D0 (s)D1 (s)D2 (s)· · · DK (s),
where
s D0 (s)= 1 + Ω0
The remaining factors Di (s) are the same as in Eq. (11.6.19). They can be rewritten as factors with real coefficients as follows. Inserting si = Ω0 ejθi into Eq. (11.6.19), we find for i = 1, 2, . . . , K:
s s s s2 cos θi + 2 1− ∗ =1−2 Di (s)= 1 − si si Ω0 Ω0
(11.6.20)
598
11. IIR DIGITAL FILTER DESIGN
Inserting these factors into the Butterworth analog transfer function H(s)= 1/D(s), we can express it as a cascade of secondorder sections:
H(s)= H0 (s)H1 (s)H2 (s)· · · HK (s)
(11.6.21)
where
H0 (s) =
Hi (s) =
if N = 2K
1, 1
s , 1+ Ω0
if N = 2K + 1 (11.6.22)
1
1−2
s s2 cos θi + 2 Ω0 Ω0
,
i = 1, 2, . . . , K
Example 11.6.1: The Butterworth polynomials D(s) of orders 1–7 and unity 3dB normalization frequency Ω0 = 1 are shown in Table 11.6.1. For other values of Ω0 , s must be replaced by s/Ω0 in each table entry. The coefficients of s of the secondorder sections are the cosine factors, −2 cos θi , of Eq. (11.6.20). For example, in the case N = 7, we have K = 3 and the three θ’s are calculated from Eq. (11.6.17):
θi =
π 14
(6 + 2i)=
8π 10π 12π , , , 14 14 14
for i = 1, 2, 3
−2 cos θi = 0.4450, 1.2470, 1.8019 The corresponding Butterworth filters H(s) of orders 1–7 are obtained as the inverses of the table entries.
Example 11.6.2: Determine the 2N possible Nth degree polynomials D(s) satisfying Eq. (11.6.16), for the cases N = 2 and N = 3. Take Ω0 = 1. Solution: For N = 2, we must find all seconddegree polynomials that satisfy Eq. (11.6.16), D(s)D∗ (−s)= 1 + (−1)2 s4 . They are: D(s) = 1 + D(s) = 1 −
√ √
D∗ (−s) = 1 −
2s + s2 2s + s2
D(s) = 1 + js2 D(s) = 1 − js2
⇒
D∗ (−s) = 1 +
√
2 s + s2
√
2 s + s2
D∗ (−s) = 1 − js2 D∗ (−s) = 1 + js2
Only the first one has all of its zeros in the lefthand splane. Similarly, for N = 3 the 23 = 8 different thirddegree polynomials D(s) are:
599
11.6. HIGHERORDER FILTERS
N
K
θ1 , θ 2 , . . . , θ K
D(s)
1
0
2
1
3π 4
(1 + 1.4142s + s2 )
3
1
4π 6
(1 + s)(1 + s + s2 )
4
2
5π 7π , 8 8
(1 + 0.7654s + s2 )(1 + 1.8478s + s2 )
5
2
6π 8π , 10 10
(1 + s)(1 + 0.6180s + s2 )(1 + 1.6180s + s2 )
6
3
7π 9π 11π , , 12 12 12
(1 + 0.5176s + s2 )(1 + 1.4142s + s2 )(1 + 1.9319s + s2 )
7
3
8π 10π 12π , , 14 14 14
(1 + s)(1 + 0.4450s + s2 )(1 + 1.2470s + s2 )(1 + 1.8019s + s2 )
(1 + s)
Table 11.6.1 Butterworth polynomials.
D(s) = (1 + s)(1 + s + s2 )
D∗ (−s) = (1 − s)(1 − s + s2 )
D(s) = (1 + s)(1 − s + s2 )
D∗ (−s) = (1 − s)(1 + s + s2 )
D(s) = (1 + s)(1 − s2 e2jπ/3 )
D∗ (−s) = (1 − s)(1 − s2 e−2jπ/3 )
2 −2jπ/3
D(s) = (1 + s)(1 − s e
)
D(s) = (1 − s)(1 − s2 e−2jπ/3 )
⇒
D∗ (−s) = (1 − s)(1 − s2 e2jπ/3 ) D∗ (−s) = (1 + s)(1 − s2 e2jπ/3 )
D(s) = (1 − s)(1 − s2 e2jπ/3 )
D∗ (−s) = (1 + s)(1 − s2 e−2jπ/3 )
D(s) = (1 − s)(1 + s + s2 )
D∗ (−s) = (1 + s)(1 − s + s2 )
D(s) = (1 − s)(1 − s + s2 )
D∗ (−s) = (1 + s)(1 + s + s2 )
They all satisfy D(s)D∗ (−s)= 1 + (−1)3 s6 but, only the first one has its zeros in the lefthand splane. Note also that not all solutions of Eq. (11.6.16) have real coefficients. If we restrict our search to those with real coefficients (pairing the zeros in conjugate pairs), then there are 2K such polynomials D(s) if N = 2K, and 2K+1 if N = 2K + 1.
11.6.2 Digital Lowpass Filters Under the bilinear transformation, the lowpass analog filter will be transformed into a lowpass digital filter. Each analog secondorder section will be transformed into a secondorder section of the digital filter, as follows:
600
11. IIR DIGITAL FILTER DESIGN
1 Gi (1 + z−1 )2 Hi (z)= = 2 s s 1 + ai1 z−1 + ai2 z−2 1−2 cos θi + 2 1−z−1 Ω0 Ω0 s= −1
(11.6.23)
1+z
where the filter coefficients Gi , ai1 , ai2 are easily found to be:
Gi = ai1 = ai2 =
Ω20 1 − 2Ω0 cos θi + Ω0 2 2(Ω20 − 1)
(11.6.24)
1 − 2Ω0 cos θi + Ω0 2 1 + 2Ω0 cos θi + Ω20
1 − 2Ω0 cos θi + Ω0 2
for i = 1, 2, . . . , K. If N is odd, then there is also a firstorder section:
1 G0 (1 + z−1 ) H0 (z)= = s 1 + a01 z−1 1+ Ω0 s= 1−z−−11
(11.6.25)
1+z
where
G0 =
Ω0 , Ω0 + 1
a01 =
Ω0 − 1 Ω0 + 1
(11.6.26)
If N is even, we may set H0 (z)= 1. The overall transfer function of the designed lowpass digital filter is given by:
H(z)= H0 (z)H1 (z)H2 (z)· · · HK (z)
(11.6.27)
with the factors given by Eqs. (11.6.23)–(11.6.26). Note that the 3dB frequency f0 in Hz is related to the Butterworth parameter Ω0 by
Ω0 = tan
ω0 2
= tan
πf0 fs
f0 =
⇒
fs arctan(Ω0 ) π
(11.6.28)
Note that the filter sections have zeros at z = −1, that is, the Nyquist frequency ω = π. Setting Ω = tan(ω/2), the magnitude response of the designed digital filter can be expressed simply via Eq. (11.6.7), as follows:
H(ω)2 =
1
1 + Ω/Ω0
2N =
1
1 + tan(ω/2)/Ω0
2N
(11.6.29)
Note also that each secondorder section has unity gain at zero frequency, f = 0, ω = 0, or z = 1. Indeed, setting z = 1 in Eq. (11.6.23), we obtain the following condition, which can be verified from the definitions (11.6.24): 4Gi =1 1 + ai1 + ai2
and
2G0 =1 1 + a01
601
11.6. HIGHERORDER FILTERS
In summary, the design steps for a lowpass digital filter with given specifications
{fpass , fstop , Apass , Astop } are: 1. Calculate the digital frequencies {ωpass , ωstop } and the corresponding prewarped versions {Ωpass , Ωstop } from Eqs. (11.6.6) and (11.6.5). 2. Calculate the order N and 3dB frequency Ω0 of the equivalent lowpass analog Butterworth filter based on the transformed specifications {Ωpass , Ωstop , Apass , Astop } by Eqs. (11.6.10)–(11.6.13). 3. The transfer function of the desired lowpass digital filter is then obtained from Eq. (11.6.27), where the SOS coefficients are calculated from Eqs. (11.6.24) and (11.6.26). Example 11.6.3: Using the bilinear transformation and a lowpass analog Butterworth prototype, design a lowpass digital filter operating at a rate of 20 kHz and having passband extending to 4 kHz with maximum passband attenuation of 0.5 dB, and stopband starting at 5 kHz with a minimum stopband attenuation of 10 dB. Then, redesign it such that its magnitude response satisfies 1 ≥ H(f )2 ≥ 0.98 in the passband, and H(f )2 ≤ 0.02 in the stopband.
Solution: The digital frequencies in radians per sample are: ωpass =
2πfpass
fs
=
2π · 4 = 0.4π, 20
ωstop =
2πfstop
fs
=
2π · 5 = 0.5π 20
and their prewarped versions:
Ωpass = tan
ωpass 2
= 0.7265,
Ωstop = tan
ωstop 2
=1
Eq. (11.6.4) can be used with Apass = 0.5 dB and Astop = 10 dB to calculate the parameters {εpass , εstop }:
εpass = 10Apass /10 − 1 = 100.5/10 − 1 = 0.3493 εstop = 10Astop /10 − 1 = 1010/10 − 1 = 3 Then, Eq. (11.6.10) gives:
Nexact =
ln(εstop /εpass ) ln(3/0.3493) ln(e) = = = 6.73 ln(w) ln(Ωstop /Ωpass ) ln(1/0.7265)
⇒
N=7
Thus, there is one firstorder section H0 (z) and three secondorder sections. Eq. (11.6.13) gives for Ω0 and its value in Hz:
Ω0 = f0 =
Ωpass /N ε1pass
=
0.7265 = 0.8443 (0.3493)1/7
fs 20 arctan(Ω0 )= arctan(0.8443)= 4.4640 kHz π π
602
11. IIR DIGITAL FILTER DESIGN The Butterworth angles θ1 , θ2 , θ3 were calculated in Example 11.6.1. The SOS coefficients are calculated from Eqs. (11.6.26) and (11.6.24):
i
Gi
0 1 2 3
0.4578 0.3413 0.2578 0.2204
ai1 −0.0844 −0.2749 −0.2076 −0.1775
ai 2 0.6402 0.2386 0.0592
resulting in the transfer function:
H(z) = H0 (z)H1 (z)H2 (z)H3 (z) =
0.4578(1 + z−1 ) 0.3413(1 + z−1 )2 · 1 − 0.0844z−1 1 − 0.2749z−1 + 0.6402z−2
·
0.2578(1 + z−1 )2 0.2204(1 + z−1 )2 · 1 − 0.2076z−1 + 0.2386z−2 1 − 0.1775z−1 + 0.0592z−2
It can be implemented in the time domain by the routines cas or ccas. The left graph of Fig. 11.6.3 shows the magnitude response squared, H(f )2 . The brickwall specifications and the 3dB line intersecting the response at f = f0 are shown on the graph. The magnitude response was calculated using the simpler formula Eq. (11.6.29), with ω expressed in kHz, ω = 2πf /fs :
H(f )2 =
1
1 + tan(πf /fs )/Ω0
2N =
1
1 + tan(πf /20)/0.8443
14
The passband attenuation in absolute units is 10−0.5/10 = 0.89125 and the stopband attenuation 10−10/10 = 0.1. Note that the actual stopband attenuation at f = fstop = 5 kHz is slightly better than required, that is, A(fstop )= 10.68 dB.
Fig. 11.6.3 Digital lowpass Butterworth filters. The second filter has more stringent specifications. The desired passband attenuation is Apass = −10 log10 (0.98)= 0.0877 dB, and the stopband attenuation Astop = −10 log10 (0.02)= 16.9897 dB. With these values, we find the design parameters {εpass , εstop } = {0.1429, 7} and:
603
11.6. HIGHERORDER FILTERS
Nexact = 12.18,
N = 13,
Ω0 = 0.8439,
f0 = 4.4622 kHz
The digital filter will have one firstorder and six secondorder sections. The SOS coefficients were calculated with the MATLAB function lhbutt.m of Appendix D:
i
Gi
0 1 2 3 4 5 6
0.4577 0.3717 0.3082 0.2666 0.2393 0.2221 0.2125
ai2
a i1 −0.0847 −0.3006 −0.2492 −0.2156 −0.1935 −0.1796 −0.1718
0.7876 0.4820 0.2821 0.1508 0.0679 0.0219
Its magnitude response is shown in the right graph of Fig. 11.6.3. As is always the case, making the specifications more stringent results in higher order N.
11.6.3 Digital Highpass Filters There are two possible approaches one can follow to design a highpass digital filter with the bilinear transformation: One is to use the transformation (11.1.3) to map the given specifications onto the specifications of an equivalent highpass analog filter. The other is to use the highpass version of the bilinear transformation given in Eq. (11.1.5) to map the given highpass specifications onto equivalent analog lowpass specifications. The first approach was used in the design of the firstorder highpass filters of Section 11.2. Here, we will follow the second method, which is more convenient for highorder designs because we can use the lowpass Butterworth design we developed already. The mapping of the highpass specifications to the equivalent analog lowpass ones is depicted in Fig. 11.6.4.
desired digital highpass filter
H(f ) 2 1/(1+εp2ass )
1
equivalent analog lowpass filter
H a(Ω ) 2 1
Apass
Apass
Astop
Astop Ω
f
2 ) 1/(1+εstop
0
fstop
stopband
fpass
passband
fs /2
Ωpass
0
Ωstop
passband
stopband
Fig. 11.6.4 Highpass digital filter and its analog lowpass equivalent.
The mapping is accomplished by the highpass version of the bilinear transformation, given in Eqs. (11.1.5) and (11.1.6):
604
11. IIR DIGITAL FILTER DESIGN
s=
1 + z−1 , 1 − z−1
Ω = − cot
ω 2
ω=
,
2πf
fs
(11.6.30)
It maps the point z = −1 to s = 0, or equivalently, the center of the passband of the highpass filter at ω = π to the center of the passband of the lowpass filter at Ω = 0. The prewarped versions of the passband and stopband frequencies are computed as follows:
Ωpass = cot
Ωstop = cot
ωpass 2
ωstop 2
= cot
πfpass fs
= cot
πfstop fs
(11.6.31)
According to Eq. (11.6.30), we should have used Ωpass = − cot(ωpass /2). However, as far as the determination of the parameters N and Ω0 is concerned, it does not matter whether we use positive or negative signs because we are working only with the magnitude response of the analog filter, which is even as a function of Ω. Using Eqs. (11.6.10)–(11.6.13), we determine the parameters N and Ω0 , and the corresponding analog filter sections given by Eq. (11.6.21). Under the highpass bilinear transformation of Eq. (11.6.30), each SOS of the analog filter will be transformed into an SOS of the digital filter, as follows:
1 Gi (1 − z−1 )2 = Hi (z)= 2 s s 1 + ai1 z−1 + ai2 z−2 1−2 cos θi + 2 1+z−1 Ω0 Ω0 s= −1
(11.6.32)
1−z
where the filter coefficients Gi , ai1 , ai2 are easily found to be
Gi =
Ω20 1 − 2Ω0 cos θi + Ω0 2
ai1 = − ai 2 =
2(Ω20 − 1)
1 − 2Ω0 cos θi + Ω0 2
(11.6.33)
1 + 2Ω0 cos θi + Ω20
1 − 2Ω0 cos θi + Ω0 2
for i = 1, 2, . . . , K. If N is odd, then there is also a firstorder section given by
G0 (1 − z−1 ) H0 (z)= = s 1 + a01 z−1 1+ Ω0 s= 1+z−−11 1
(11.6.34)
1−z
where
G0 =
Ω0 , Ω0 + 1
a01 = −
Ω0 − 1 Ω0 + 1
(11.6.35)
605
11.6. HIGHERORDER FILTERS
If N is even, we may set H0 (z)= 1. The overall transfer function of the designed highpass digital filter will be given by
H(z)= H0 (z)H1 (z)H2 (z)· · · HK (z)
(11.6.36)
with the factors given by Eqs. (11.6.32–11.6.35). The 3dB frequency f0 of the designed filter may be calculated from:
Ω0 = cot
ω0 2
= cot
πf0 fs
f0 =
⇒
fs 1 arctan π Ω0
and the magnitude response from:
H(ω)2 =
1
1 + cot(ω/2)/Ω0
2N
Note the similarities and differences between the highpass and lowpass cases: The coefficients Gi and ai2 are the same, but ai1 has reverse sign. Also, the numerator of the SOS is now (1 − z−1 )2 instead of (1 + z−1 )2 , resulting in a zero at z = 1 or ω = 0. These changes are easily understood by noting that the lowpass bilinear transformation (11.1.3) becomes the highpass one given by Eq. (11.6.30) under the substitution z → −z. Example 11.6.4: Using the bilinear transformation and a lowpass analog Butterworth prototype, design a highpass digital filter operating at a rate of 20 kHz and having passband starting at 5 kHz with maximum passband attenuation of 0.5 dB, and stopband ending at 4 kHz with a minimum stopband attenuation of 10 dB. Then, redesign it such that its magnitude response satisfies 1 ≥ H(f )2 ≥ 0.98 in the passband, and H(f )2 ≤ 0.02 in the stopband.
Solution: The digital frequencies and their prewarped versions are: ωpass = ωstop =
2πfpass
fs 2πfstop
fs
= =
2π · 5 = 0.5π, 20 2π · 4 = 0.4π, 20
⇒
Ωpass = cot Ωstop = cot
ωpass 2
ωstop 2
=1 = 1.3764
The dB attenuations {Apass , Astop } = {0.5, 10} correspond to {εpass , εstop } = {0.3493, 3}. Then, Eq. (11.6.10) can be solved for the filter order: ln(εstop /εpass )
Nexact =
ln(Ωstop /Ωpass )
=
ln(3/0.3493) = 6.73 ln(1.3764/1)
⇒
N=7
Thus, there is one firstorder section H0 (z) and three secondorder sections. Eq. (11.6.13) gives for Ω0 :
Ω0 =
Ωpass
10Apass /10 − 1
1/2N =
Ωpass /N ε1pass
=
1
(0.3493)1/7
= 1.1621
The SOS coefficients are calculated from Eqs. (11.6.33) and (11.6.35):
606
11. IIR DIGITAL FILTER DESIGN
i
Gi
0 1 2 3
0.5375 0.4709 0.3554 0.3039
ai1 −0.0750 −0.2445 −0.1845 −0.1577
ai 2 0.6393 0.2372 0.0577
resulting in the transfer function:
H(z) = H0 (z)H1 (z)H2 (z)H3 (z) =
0.5375(1 − z−1 ) 0.4709(1 − z−1 )2 · 1 − 1 − 0.0750z 1 − 0.2445z−1 + 0.6393z−2
·
0.3554(1 − z−1 )2 0.3039(1 − z−1 )2 · 1 2 − − 1 − 0.1845z + 0.2372z 1 − 0.1577z−1 + 0.0577z−2
As in Example 11.6.3, the second filter has passband and stopband attenuations: Apass = −10 log10 (0.98)= 0.0877 dB and Astop = −10 log10 (0.02)= 16.9897 dB. With these values, we find the design parameters {εpass , εstop } = {0.1429, 7} and:
Nexact = 12.18,
N = 13,
Ω0 = 1.1615,
f0 = 4.5253 kHz
The coefficients of the first and secondorder sections are:
i
Gi
0 1 2 3 4 5 6
0.5374 0.5131 0.4252 0.3677 0.3300 0.3062 0.2930
ai1 −0.0747 −0.2655 −0.2200 −0.1903 −0.1708 −0.1584 −0.1516
ai 2 0.7870 0.4807 0.2806 0.1493 0.0663 0.0203
The magnitude responses of the two designs are shown in Fig. 11.6.5.
11.6.4 Digital Bandpass Filters As in the highpass case, we can follow two possible approaches to the design of a digital bandpass filter. We can map the digital bandpass filter onto an equivalent analog bandpass filter using the transformation (11.1.3). Alternatively, we can use the bandpass version of the transformation (11.1.5) to map the bandpass digital filter onto an equivalent lowpass analog filter. The first method was used in Sections 11.3 to design bandpass peaking filters. The second method is, however, more convenient because it reduces the bandpass design problem to a standard lowpass analog design problem. Figure 11.6.6 shows the bandpass specifications and their analog equivalents. The specifications are the quantities {fpa , fpb , fsa , fsb , Apass , Astop }, defining the passband range fpa ≤ f ≤ fpb , the left stopband 0 ≤ f ≤ fsa , and the right stopband
607
11.6. HIGHERORDER FILTERS
Fig. 11.6.5 Digital highpass Butterworth filters.
Fig. 11.6.6 Bandpass digital filter and its analog lowpass equivalent.
fsb ≤ f ≤ fs /2. The stopband attenuations were assumed to be equal in the two stop
bands; if they are not, we may design the filter based on the maximum of the two. The bandpass version of the bilinear† transformation and the corresponding frequency mapping are in this case:
s=
1 − 2cz−1 + z−2 , 1 − z−2
Ω=
c − cos ω , sin ω
ω=
2πf
fs
(11.6.37)
A new parameter c has been introduced. Note that c = 1 recovers the lowpass case, and c = −1 the highpass one. The parameter c is required to be c ≤ 1 in order to map the lefthand splane into the inside of the unit circle in the zplane. Therefore, we may set c = cos ωc , for some value of ωc . The center of the analog passband Ω = 0 corresponds to cos ω = c = cos ωc , or, ω = ωc . Therefore, ωc may be thought of as the “center” frequency of the bandpass filter (although it need not be exactly at the center of the passband). † It
should really be called “biquadratic” in this case.
608
11. IIR DIGITAL FILTER DESIGN
The given bandpass specifications, must be mapped onto the specifications of the equivalent analog filter, {Ωpass , Ωstop , Apass , Astop }. This can be done as follows. We require that the passband [fpa , fpb ] of the digital filter be mapped onto the entire passband [−Ωpass , Ωpass ] of the analog filter. This requires that:
−Ωpass =
c − cos ωpa sin ωpa
Ωpass =
c − cos ωpb sin ωpb
where ωpa = 2πfpa /fs and ωpb = 2πfpb /fs . By adding them, we solve for c. Then, inserting the computed value of c into one or the other we find Ωpass . The resulting solution is:
c=
sin(ωpa + ωpb )
sin ωpa + sin ωpb
,
Ωpass
c − cos ω pb = sin ωpb
(11.6.38)
Note that for ωpa , ωpb in the interval [0, π], the above expression for c implies c ≤ 1, as required for stability. Next, we compute the two numbers:
Ωsa =
c − cos ωsa , sin ωsa
Ωsb =
c − cos ωsb sin ωsb
where ωsa = 2πfsa /fs and ωsb = 2πfsb /fs . Ideally, the stopband of the digital filter should map exactly onto the stopband of the analog filter so that we should have Ωsb = Ωstop and Ωsa = −Ωstop . But this is impossible because c has already been determined from Eq. (11.6.38). Because the Butterworth magnitude response is a monotonically decreasing function of Ω, it is enough to choose the smallest of the two stopbands defined above. Thus, we define:
Ωstop = min Ωsa , Ωsb 
(11.6.39)
With the computed values of Ωpass and Ωstop , we proceed to compute the Butterworth parameters N and Ω0 and the corresponding SOSs of Eq. (11.6.21). Because s is quadratic in z, the substitution of s into these SOSs will give rise to fourthorder sections in z:
1 Hi (z) = 2 s s cos θi + 2 1−2 −2 Ω0 Ω0 s= 1−2cz−1−+z 2 1−z
= where, for i = 1, 2, . . . , K:
1 + ai1
Gi =
z−1
Gi (1 − z−2 )2 + ai2 z−2 + ai3 z−3 + ai4 z−4 Ω20
1 − 2Ω0 cos θi + Ω0 2
(11.6.40)
609
11.6. HIGHERORDER FILTERS
ai1 =
4c(Ω0 cos θi − 1)
1 − 2Ω0 cos θi + Ω0
ai3 = −
ai2 =
2
4c(Ω0 cos θi + 1)
1 − 2Ω0 cos θi + Ω0
ai4 =
2
2(2c2 + 1 − Ω20 )
1 − 2Ω0 cos θi + Ω0 2 1 + 2Ω0 cos θi + Ω20
(11.6.41)
1 − 2Ω0 cos θi + Ω0 2
If N is odd, then there is also a firstorder section in s which becomes a secondorder section in z:
G0 (1 − z−2 ) = H0 (z)= s 1 + a01 z−1 + a02 z−2 1+ −2 Ω0 s= 1−2cz−1−+z 2 1
(11.6.42)
1−z
where
G0 =
Ω0 1 + Ω0
a01 = −
,
2c , 1 + Ω0
a02 =
1 − Ω0 1 + Ω0
(11.6.43)
The overall transfer function of the designed bandpass digital filter will be given as the cascade of fourthorder sections with the possibility of one SOS:
H(z)= H0 (z)H1 (z)H2 (z)· · · HK (z) The order of the digital filter is 2N, because s is quadratic in z. The filter sections have zeros at z = ±1, that is, ω = 0 and ω = π. The left and right 3dB frequencies can be calculated from the equations:
c − cos ω0 = ∓Ω0 sin ω0 They can be solved by writing cos ω0 and sin ω0 in terms of tan(ω0 /2), solving the resulting quadratic equation, and picking the positive solutions:
tan
tan
ω0a 2
ω0 b 2
= tan
πf0a fs
=
= tan
πf0b fs
=
Ω20 + 1 − c2 − Ω0
1+c Ω20 + 1 − c2 + Ω0
(11.6.44)
1+c
Example 11.6.5: Using the bilinear transformation and a lowpass analog Butterworth prototype, design a bandpass digital filter operating at a rate of 20 kHz and having left and right passband frequencies of 2 and 4 kHz, and left and right stopband frequencies of 1.5 and 4.5 kHz. The maximum passband attenuation is required to be 0.5 dB, and the minimum stopband attenuation 10 dB. Then, redesign it such that its magnitude response satisfies 1 ≥ H(f )2 ≥ 0.98 in the passband, and H(f )2 ≤ 0.02 in the stopbands.
Solution: The digital passband frequencies are: ωpa =
2πfpa
fs
=
2π · 2 = 0.2π, 20
ωpb =
2πfpb
fs
=
2π · 4 = 0.4π 20
610
11. IIR DIGITAL FILTER DESIGN Then, we calculate c and Ωpass :
c=
sin(ωpa + ωpb )
sin ωpa + sin ωpb
c − cos ω pb = 0.3249 Ωpass = sin ωpb
= 0.6180,
With the stopband digital frequencies:
ωsa =
2πfsa
fs
=
2π · 1.5 = 0.15π, 20
2πfsb
ωsb =
fs
=
2π · 4.5 = 0.45π 20
we calculate:
Ωsa =
c − cos ωsa = −0.6013, sin ωsa
Ωsb =
c − cos ωsb = 0.4674 sin ωsb
and Ωstop = min Ωsa , Ωsb  = 0.4674. The analog filter with the specifications {Ωpass , Ωstop , Apass , Asto has parameters {εpass , εstop } = {0.3493, 3} and:
Nexact = 5.92,
N = 6,
Ω0 = 0.3872
The leftright 3dB frequencies are calculated from Eq. (11.6.44) to be: f0a = 1.8689 kHz, f0b = 4.2206 kHz. The coefficients of the three fourthorder sections of the digital filter are (computed by the MATLAB function bpsbutt.m):
i
Gi
1 2 3
0.1110 0.0883 0.0790
ai1 −2.0142 −1.8551 −1.7897
ai2
ai 3 −1.6473 −1.0577 −0.8154
2.3906 1.9017 1.7009
ai 4 0.7032 0.3549 0.2118
The magnitude response can be calculated from:
H(ω)2 =
1+
1
Ω Ω0
2N =
1+
1
c − cos ω Ω0 sin ω
2N
The magnitude response is shown in the left graph of Fig. 11.6.7. The passband specifications are met exactly by design. Because the maximum stopband frequency was on the right, Ωstop = Ωsb , the right stopband specification is met stringently. The left stopband specification is more than required. For the second set of specifications, we have Apass = −10 log10 (0.98)= 0.0877 dB, and Astop = −10 log10 (0.02)= 16.9897 dB and {εpass , εstop } = {0.1429, 7}. The design has the same c, Ωpass , and Ωstop , which lead to the Butterworth parameters:
Nexact = 10.71,
N = 11,
Ω0 = 0.3878
The left and right 3dB frequencies are now f0a = 1.8677 kHz, f0b = 4.2228 kHz. The digital filter coefficients of the second and fourthorder sections are:
611
11.6. HIGHERORDER FILTERS
Fig. 11.6.7 Digital bandpass Butterworth filters.
i
Gi
0 1 2 3 4 5
0.2794 0.1193 0.1021 0.0907 0.0834 0.0794
ai 1 −0.8907 −2.0690 −1.9492 −1.8694 −1.8186 −1.7904
ai2 0.4411 2.5596 2.1915 1.9460 1.7900 1.7033
ai3
ai4
−1.8526 −1.4083 −1.1122 −0.9239 −0.8193
0.8249 0.5624 0.3874 0.2762 0.2144
Again, the right stopband specification is more stringently met than the left one. The “center” frequency of the passband is the same for both filters and can be obtained by inverting cos ωc = c. In Hz, we have fc = fs arccos(c)/(2π)= 2.8793 kHz. The magnitude response is normalized to unity at fc .
11.6.5 Digital Bandstop Filters The specifications of a bandstop digital filter are shown in Fig. 11.6.8, together with their analog equivalents. There are now two passbands, that is, 0 ≤ f ≤ fpa and fpb ≤ f ≤ fs /2, and one stopband fsa ≤ f ≤ fsb . The bandstop version of the bilinear transformation and the corresponding frequency mapping were given in Eqs. (11.1.5) and (11.1.6):
s=
1 − z−2 , 1 − 2cz−1 + z−2
Ω=
sin ω , cos ω − c
ω=
2πf
(11.6.45)
fs
The design steps are summarized as follows. First, we compute the digital frequencies in radians per sample:
ωpa =
2πfpa
fs
,
ωpb =
2πfpb
fs
,
ωsa =
2πfsa
fs
,
ωsb =
Then, we calculate c and Ωpass by requiring:
−Ωpass =
sin ωpa cos ωpa − c
,
Ωpass =
sin ωpb cos ωpb − c
2πfsb
fs
612
11. IIR DIGITAL FILTER DESIGN
desired digital bandstop filter
H(f ) 2 1/(1+εp2ass )
1
Apass
equivalent analog lowpass filter
H a(Ω ) 2 Apass
1
Apass
Astop
Astop Ω
f
1/(1+εs2top ) 0
fpa fsa
passband
fsb fpb
stopband
Ωpass
0
fs /2
passband
Ωstop
passband
stopband
Fig. 11.6.8 Bandstop digital filter and its analog lowpass equivalent.
which may be solved as follows:
c=
sin(ωpa + ωpb )
sin ωpa + sin ωpb
,
sin ω pb Ωpass = cos ωpb − c
Next, we compute the two possible stopbands:
Ωsa =
sin ωsa , cos ωsa − c
Ωsb =
sin ωsb cos ωsb − c
and define:
Ωstop = min Ωsa , Ωsb 
Then, use the analog specifications {Ωpass , Ωstop , Apass , Astop } to compute the Butterworth parameters {N, Ω0 }. And finally, transform the analog filter sections into fourthorder sections by Eq. (11.6.45):
1 Hi (z) = 2 s s 1−2 cos θi + 2 Ω0 Ω0 s= =
1−z−2 1−2cz−1 +z−2
Gi (1 − 2cz−1 + z−2 )2 1 + ai1 z−1 + ai2 z−2 + ai3 z−3 + ai4 z−4
where the coefficients are given for i = 1, 2, . . . , K:
Gi = ai1 =
Ω20 1 − 2Ω0 cos θi + Ω0 2
4cΩ0 (cos θi − Ω0 )
1 − 2Ω0 cos θi + Ω0
ai3 = −
ai2 =
2
4cΩ0 (cos θi + Ω0 )
1 − 2Ω0 cos θi + Ω0
2
ai4 =
2(2c2 Ω20 + Ω20 − 1)
1 − 2Ω0 cos θi + Ω0 2 1 + 2Ω0 cos θi + Ω20
1 − 2Ω0 cos θi + Ω0 2
613
11.6. HIGHERORDER FILTERS If N is odd, we also have a secondorder section in z:
where
1 H0 (z)= s 1+ Ω0 s= G0 =
Ω0 1 + Ω0
= 1−z−2 1−2cz−1 +z−2
a01 = −
,
G0 (1 − 2cz−1 + z−2 ) 1 + a01 z−1 + a02 z−2
2cΩ0 , 1 + Ω0
a02 = −
1 − Ω0 1 + Ω0
Note that each section has zeros at 1 − 2cz−1 + z−2 = 0, which correspond to the angles ω = ±ωc , where cos ωc = c. The 3dB frequencies at the edges of the passbands can be determined by solving for the positive solutions of the equations: sin ω0 = ±Ω0 cos ω0 − c which give:
tan
tan
ω0a 2
ω0b 2
= tan
= tan
πf0a fs πf0b fs
=
=
1 + Ω20 (1 − c2 ) − 1
Ω0 (1 + c)
1 + Ω20 (1 − c2 ) + 1
Ω0 (1 + c)
Example 11.6.6: Using the bilinear transformation and a lowpass analog Butterworth prototype, design a bandstop digital filter operating at a rate of 20 kHz and having left and right passband frequencies of 1.5 and 4.5 kHz, and left and right stopband frequencies of 2 and 4 kHz. The maximum passband attenuation is required to be 0.5 dB, and the minimum stopband attenuation 10 dB. Then, redesign it such that its magnitude response satisfies 1 ≥ H(f )2 ≥ 0.98 in the passbands, and H(f )2 ≤ 0.02 in the stopband.
Solution: The digital passband and stopband frequencies are: ωpa = ωsa =
2πfpa
fs 2πfsa
fs
=
2π · 1.5 = 0.15π, 20
ωpb =
=
2π · 2 = 0.2π, 20
ωsb =
2πfpb
fs 2πfsb
fs
=
2π · 4.5 = 0.45π 20
=
2π · 4 = 0.4π 20
Then, we calculate c and Ωpass :
c=
sin(ωpa + ωpb )
sin ωpa + sin ωpb
= 0.6597,
Then, we calculate the stopband frequencies:
Ωsa =
sin ωsa = 3.9361, cos ωsa − c
sin ω pb = 1.9626 Ωpass = cos ωpb − c
Ωsb =
sin ωsb = −2.7121 cos ωsb − c
614
11. IIR DIGITAL FILTER DESIGN
and define Ωstop = min Ωsa , Ωsb  = 2.7121. The analog filter parameters are:
Nexact = 6.65,
N = 7,
Ω0 = 2.2808
The leftright 3dB frequencies are calculated to be f0a = 1.6198 kHz, f0b = 4.2503 kHz. The coefficients of the SOS and the three fourthorder sections of the digital filter are:
i
Gi
0 1 2 3
0.6952 0.7208 0.5751 0.5045
ai1 −0.9172 −2.0876 −1.9322 −1.8570
ai2 0.3904 2.4192 1.9301 1.6932
ai 3
ai 4
−1.7164 −1.1026 −0.8053
0.7187 0.3712 0.2029
The magnitude response of the designed filter is shown in the left graph of Fig. 11.6.9.
Fig. 11.6.9 Digital bandstop Butterworth filters. For the second set of specifications, we have Apass = −10 log10 (0.98)= 0.0877 dB, and Astop = −10 log10 (0.02)= 16.9897 dB. The design has the same c, Ωpass , and Ωstop , which lead to the Butterworth parameters:
Nexact = 12.03,
N = 13,
Ω0 = 2.2795
The leftright 3dB frequencies are now f0a = 1.6194 kHz, f0b = 4.2512 kHz. The digital filter coefficients of the second and fourthorder sections are:
i
Gi
0 1 2 3 4 5 6
0.6951 0.7703 0.6651 0.5914 0.5408 0.5078 0.4892
ai1 −0.9171 −2.1401 −2.0280 −1.9495 −1.8956 −1.8604 −1.8406
ai2 −0.3902 2.5850 2.2319 1.9847 1.8148 1.7041 1.6415
ai 3
ai 4
−1.9251 −1.4820 −1.1717 −0.9584 −0.8194 −0.7410
0.8371 0.5862 0.4105 0.2897 0.2110 0.1666
The magnitude response is shown on the right graph of Fig. 11.6.9. The rounding of the exact N of 12.03 to 13 is perhaps overkill in this case. It causes the actual stopband
615
11.6. HIGHERORDER FILTERS
attenuation at the right edge of the stopband to be A(Ωstop )= 19.67 dB, corresponding to a magnitude square of 0.011 instead of the required 0.02. For both designs, the “center” notch frequency of the stopband can be obtained by inverting cos ωc = c. In Hz, we have fc = fs arccos(c)/(2π)= 2.7069 kHz.
11.6.6 Chebyshev Filter Design∗ In designing the equivalent analog lowpass filters one can use alternative filter prototypes, such as Chebyshev or elliptic filters [269–271]. For the same set of specifications, they provide steeper transition widths and lead to smaller filter orders than the Butterworth filters. Chebyshev filters come in two varieties. Type 1 has equiripple passband and monotonic stopband, and type 2, also known as inverse Chebyshev, has equiripple stopband and monotonic passband. A typical Chebyshev magnitude response is shown in Fig. 11.6.10.
H(Ω ) 1/(1+εp2ass )
2
Type 1
1
H(Ω )
2
Type 2
1
Apass
Apass
Astop
Astop Ω
2 ) 1/(1+εstop
0
Ω
Ωpass Ωstop
passband
0
stopband
Ωpass Ωstop
passband
stopband
Fig. 11.6.10 Magnitude square responses of type 1 and type 2 Chebyshev filters.
It is the equiripple property that is responsible for the narrower transition widths of these filters. For example, for the type 1 case, because the passband response is allowed to go slightly up near the edge of the passband, it can fall off more steeply. The specifications of the filter are {Ωpass , Ωstop , Apass , Astop } and are obtained by prewarping the desired digital filter specifications using the appropriate bilinear transformation (lowpass, highpass, bandpass, or bandstop). Two important design parameters are the quantities {εpass , εstop } that were defined in Eq. (11.6.4), and are shown in Figs. 11.6.1 and 11.6.10. The magnitude response squared of an Nth order Chebyshev filter is expressible in terms of these parameters as follows. For the type 1 case:
H(Ω)2 =
and, for the type 2 case:
1 2 1 + ε2pass CN
Ω Ωpass
(11.6.46)
616
11. IIR DIGITAL FILTER DESIGN
Ωstop 2 CN Ω H(Ω)2 = Ωstop 2 CN + ε2stop Ω
(11.6.47)
where CN (x) is the Chebyshev polynomial [272] of degree N, defined by
CN (x)=
cos N cos−1 (x) , cosh N cosh−1 (x) ,
if x ≤ 1 if x > 1
(11.6.48)
Chebyshev polynomials can be understood by defining the angle θ = cos−1 x, so that x = cos θ and CN (x)= cos(Nθ). When x > 1, the equation x = cos θ requires θ to be imaginary, say θ = jβ, so that x = cos(jβ)= cosh(β) and
CN (x)= cos(Nθ)= cos(Njβ)= cosh(Nβ)= cosh(N cosh−1 x) Using trigonometric identities, it can be shown that cos(Nθ) is expressible as an
Nth order polynomial in cos θ, that is, cos(Nθ)=
N
ci (cos θ)i
i=0
The ci are the coefficients of the Chebyshev polynomials:
CN (x)=
N
c i xi
i=0
For example, we have C1 (x)= cos θ = x, and cos(2θ) = 2 cos2 θ − 1 cos(3θ) = 4 cos3 θ − 3 cos θ
C2 (x) = 2x2 − 1 ⇒
cos(4θ) = 8 cos4 θ − 8 cos2 θ + 1
C3 (x) = 4x3 − 3x C4 (x) = 8x4 − 8x2 + 1
The following routine cheby.c returns the value of the Nth order Chebyshev polynomial for nonnegative values of x and can be used in the numerical evaluation of the magnitude responses: /* cheby.c  Chebyshev polynomial CN (x) */ #include <math.h> usage: y = cheby(N, x); double cheby(N, x) int N; N = polynomial order double x; x must be nonnegative { if (x 1, the values are computed by the alternative expression:
cosh(N cosh−1 x)= cosh N ln x + x2 − 1
Next, we consider the details of the type 1 case. The argument of CN (x) in Eq. (11.6.46) is x = Ω/Ωpass . Therefore, within the passband range 0 ≤ Ω ≤ Ωpass we have 0 ≤ x ≤ 1, which makes CN (x) oscillatory and results in the passband ripples. Within the passband, the magnitude response remains bounded between the values 1 and 1/(1 + ε2pass ). At the edge of the passband, corresponding to x = Ω/Ωpass = 1, we have CN (x)= 1, giving the value H(Ωpass )2 = 1/(1 + ε2pass ). The value at Ω = 0 depends on N. Because CN (0) equals zero for odd N and unity for even N, we have:
H(0)2 = 1 (odd N),
H(0)2 =
1 1 + ε2pass
(even N)
(11.6.49)
The order N can be determined by imposing the stopband specification, that is, H(Ω)2 ≤ 1/(1 + ε2stop ) for Ω ≥ Ωstop . Because of the monotonicity of the stopband,
this condition is equivalent to the stopband edge condition:
H(Ωstop )2 =
1 1 + ε2stop
Using Eq. (11.6.46), we obtain: 1
=
1 + ε2pass cosh2 N cosh−1 (Ωstop /Ωpass ) which gives:
cosh N cosh−1 (Ωstop /Ωpass ) = εstop /εpass
⇒
1 1 + ε2stop
cosh(N cosh−1 w)= e
where, as in Eq. (11.6.11), we used the stopband to passband ratios:
e=
εstop = εpass
1
10Astop /10 − 1 , 10Apass /10 − 1
w=
Ωstop Ωpass
(11.6.50)
Thus, solving for N, we find:
Nexact =
cosh−1 e cosh−1 w
=
√ e2 − 1 √ ln w + w2 − 1 ln e +
(11.6.51)
The final value of N is obtained by rounding Nexact up to the next integer, that is, 2 3 N = Nexact . As in the Butterworth case, increasing N slightly from its exact value results in a slightly better stopband than required, that is, H(Ωstop )2 < 1/(1 + ε2stop ). The 3dB frequency can be calculated by requiring H(Ω)2 = 1/2, which can be solved to give:
1 1 + ε2pass C2N (Ω3dB /Ωpass ) or,
=
1 2
⇒
cosh N cosh−1 (Ω3dB /Ωpass ) =
1
εpass
618
11. IIR DIGITAL FILTER DESIGN
tan
πf3dB fs
= Ω3dB = Ωpass cosh
1
cosh−1
N
1 εpass
(11.6.52)
The transfer function H(s) of the Chebyshev filter can be constructed by determining the lefthandplane poles of Eq. (11.6.46) and pairing them in conjugate pairs to form secondorder sections. These conjugate pairs are {si , s∗ i }, where
si = Ωpass sinh a cos θi + jΩpass cosh a sin θi ,
i = 1, 2, . . . , K
(11.6.53)
where N = 2K or N = 2K + 1. In the odd case, there is also a real pole at
s0 = −Ωpass sinh a
(11.6.54)
where the parameter a is the solution of sinh(Na)=
1
(11.6.55)
εpass
that is,
a=
1
N
sinh−1
1
εpass
=
1
N
ln
1
εpass
+
1
1
ε2pass
+1
(11.6.56)
The angles θi are the same as the Butterworth angles of Eq. (11.6.17):
π
(N − 1 + 2i) , i = 1, 2, . . . , K (11.6.57) 2N The secondquadrant values of these angles place the si in the lefthand splane. The secondorder sections are then: θi =
Hi (s)=
1
s 1− si
s 1− ∗ si
=
s2
si 2 − (2Resi )s + si 2
For convenience, we define the parameters:
Ω0 = Ωpass sinh a,
Ωi = Ωpass sin θi ,
i = 1, 2, . . . , K
(11.6.58)
Then, we may express the secondorder sections in the form:
Hi (s)=
Ω20 + Ωi 2
s2 − 2Ω0 cos θi s + Ω20 + Ωi 2
,
i = 1, 2, . . . , K
(11.6.59)
The firstorder factor H0 (s) is defined by
H0 (s)=
1
1 1 + ε2pass
Ω0 s + Ω0
if N is even, N = 2K
(11.6.60)
if N is odd, N = 2K + 1
If N is odd, all filter sections are normalized to unity gain at DC, as required by Eq. (11.6.49). If N is even, the overall gain is 1/(1 + ε2pass )1/2 . It follows that the overall transfer function will be the cascade:
619
11.6. HIGHERORDER FILTERS
H(s)= H0 (s)H1 (s)H2 (s)· · · HK (s)
(11.6.61)
Next, we verify that the poles are properly given by Eq. (11.6.53). Replacing s = jΩ or Ω = −js into Eq. (11.6.46), we see that the zeros of the denominator are the solutions of the equation:
1 + ε2pass cosh2 N cosh−1 (−js/Ωpass ) = 0 ,
cosh N cosh−1 (−js/Ωpass ) =
or
±j εpass
(11.6.62)
Replacing θi = φi + π/2, where φi = (2i − 1)π/(2N), into Eq. (11.6.53), we find
−jsi /Ωpass = cosh a sin θi − j sinh a cos θi = cosh a cos φi + j sinh a sin φi Using the trigonometric identity cosh(x + jy)= cosh x cos y + j sinh x sin y we find cosh−1 (−jsi /Ωpass )= a + jφi
−jsi /Ωpass = cosh(a + jφi ) ⇒ and therefore,
cosh N cosh−1 (−jsi /Ωpass ) = cosh(Na + jNφi )
= cosh(Na)cos(Nφi )+j sinh(Na)sin(Nφi )=
±j εpass
where we used cos(Nφi )= cos (2i − 1)π/2 = 0, sin(Nφi )= sin (2i − 1)π/2 = ±1, and Eq. (11.6.55). Thus, the si are solutions of the root equation Eq. (11.6.62). Once the analog transfer function is constructed, each secondorder section may be transformed into a digital secondorder section by the appropriate bilinear transformation. For example, applying the lowpass version of the bilinear transformation s = (1 − z−1 )/(1 + z−1 ), we find the digital transfer function:
H(z)= H0 (z)H1 (z)H2 (z)· · · HK (z)
(11.6.63)
where Hi (z) are the transformations of Eq. (11.6.59):
Gi (1 + z−1 )2 , i = 1, 2, . . . , K (11.6.64) 1 + ai1 z−1 + ai2 z−2 where the coefficients are computed in terms of the definitions Eq. (11.6.58): Hi (z)=
Gi = ai1 = ai2 =
Ω20 + Ωi 2
1 − 2Ω0 cos θi + Ω20 + Ωi 2 2(Ω20 + Ωi 2 − 1)
1 − 2Ω0 cos θi + Ω20 + Ωi 2 1 + 2Ω0 cos θi + Ω20 + Ωi 2
1 − 2Ω0 cos θi + Ω20 + Ωi 2
(11.6.65)
620
11. IIR DIGITAL FILTER DESIGN
The firstorder factor is given by
1
where
1 1 + ε2pass H0 (z)= G (1 + z−1 ) 0 1 + a01 z−1
G0 =
Ω0 , Ω0 + 1
a01 =
if N is even (11.6.66) if N is odd
Ω0 − 1 Ω0 + 1
(11.6.67)
Example 11.6.7: Using the bilinear transformation and a lowpass analog Chebyshev type 1 prototype, design a lowpass digital filter operating at a rate of 20 kHz and having passband extending to 4 kHz with maximum passband attenuation of 0.5 dB, and stopband starting at 5 kHz with a minimum stopband attenuation of 10 dB. Then, redesign it such that its magnitude response satisfies 1 ≥ H(f )2 ≥ 0.98 in the passband, and H(f )2 ≤ 0.02 in the stopband.
Solution: The specifications and the prewarped digital frequencies are the same as in Example 11.6.3, that is, Ωpass = 0.7265 and Ωstop = 1. We calculate εpass = 0.3493 and εstop = 3 and the quantities in Eq. (11.6.50) e = εstop /εpass = 8.5883, w = Ωstop /Ωpass = 1.3764. Then, Eq. (11.6.51) gives Nexact = 3.37, which is rounded up to N = 4. Thus, there are K = 2 secondorder sections. The 3dB frequency can be calculated by inverting the bilinear transformation and Eq. (11.6.52):
tan
πf3dB fs
= Ω3dB = Ωpass cosh
1
N
cosh−1
1 εpass
which gives f3dB = 4.2729 kHz. The actual stopband attenuation is larger than Astop because of the increased value of N. We calculate:
A(Ωstop )= 10 log10 1 + ε2pass C2N (Ωstop /Ωpass ) = 14.29 dB The parameter a is calculated from Eq. (11.6.55) to be a = 0.4435. Then, the coefficients of the digital filter are calculated from Eqs. (11.6.65) and (11.6.67), resulting in the transfer function:
H(z)= 0.9441 ·
0.3091(1 + z−1 )2 0.1043(1 + z−1 )2 · 1 − 0.4830z−1 + 0.7194z−2 1 − 0.9004z−1 + 0.3177z−2
The magnitude response squared is shown in the left graph of Fig. 11.6.11. It was computed by inserting the bilinear transformation into Eq. (11.6.46) and evaluating it with cheby, that is,
H(f )2 =
1
2
1 + ε2pass cheby(N, tan(πf /fs )/Ωpass )
For the more stringent specifications, we have Apass = 0.08774 dB and Astop = 16.9897 dB. We calculate the parameters:
621
11.6. HIGHERORDER FILTERS
Fig. 11.6.11 Digital lowpass Chebyshev type 1 filters.
εpass = 0.1429,
εstop = 7,
Nexact = 5.44,
N = 6,
a = 0.4407
The 3dB frequency is found to be f3dB = 4.2865 kHz. The actual stopband attenuation is A(Ωstop )= 21.02 dB, instead of the nominal one of Astop = 16.9897 dB. The digital filter coefficients are then:
i
Gi
0 1 2 3
0.9899 0.3394 0.2028 0.0811
ai1
ai2
−0.4492 −0.6809 −0.9592
0.8069 0.4920 0.2837
√
The gain factor G0 represents here the overall gain 1/ 1 + ε2pass = 0.98 = 0.9899. The magnitude response is shown in the right graph of Fig. 11.6.11. By comparison, recall that the two Butterworth filters of Example 11.6.3 had filter orders of 7 and 13, respectively.
Example 11.6.8: Redesign the highpass digital filters of Example 11.6.4 using a Chebyshev type 1 analog lowpass prototype filter.
Solution: The equivalent analog lowpass specifications {Ωpass , Ωstop , Apass , Astop } are the same as in Example 11.6.4. We have Ωpass = 1 and Ωstop = 1.3764. Based on the first set of specifications, we find the Chebyshev design parameters:
εpass = 0.3493,
εstop = 3,
Nexact = 3.37,
N = 4,
a = 0.4435
εstop = 7,
Nexact = 5.44,
N = 6,
a = 0.4407
and based on the second set:
εpass = 0.1429,
The 3dB frequencies can be calculated by inverting:
cot
πf3dB fs
= Ω3dB = Ωpass cosh
1
N
cosh−1
1 εpass
622
11. IIR DIGITAL FILTER DESIGN which gives for the two specification sets: f0 = 4.7170 and 4.7031 kHz. The actual stopband attenuations attained by the designed filter are in the two cases: A(Ωstop )= 14.29 and 21.02 dB. The digital transfer functions are obtained by transforming the analog filter sections by the highpass bilinear transformation s = (1 + z−1 )/(1 − z−1 ). The digital filter coefficients are obtained from Eqs. (11.6.65) and (11.6.67) by changing the sign of the ai1 coefficients. We have for the two specification sets:
i
Gi
ai 1
ai2
0 1 2
0.9441 0.4405 0.1618
−0.0526 0.5843
0.7095 0.2314
i
Gi
ai1
ai2
0 1 2 3
0.9899 0.4799 0.3008 0.1273
−0.1180 0.2492 0.6742
0.8017 0.4524 0.1834
Thus, for example, the first transfer function will be:
H(z)= 0.9441 ·
0.1618(1 − z−1 )2 0.4405(1 − z−1 )2 · 1 − 0.0526z−1 + 0.7095z−2 1 + 0.5843z−1 + 0.2314z−2
The designed magnitude responses are shown in Fig. 11.6.12.
Fig. 11.6.12 Digital highpass Chebyshev type 1 filters.
Next, we discuss type 2 Chebyshev filters. The argument of the Chebyshev polynomials in Eq. (11.6.47) is now x = Ωstop /Ω. Therefore, the stopband range Ω ≥ Ωstop maps to 0 ≤ x ≤ 1 where the Chebyshev polynomial is oscillatory resulting in the stopband ripples. At the edge of the stopband, Ω = Ωstop , we have x = 1, CN (x)= 1, and magnitude
response equal to H(Ωstop )2 = 1/ 1 + ε2stop . At large frequencies, Ω → ∞, we have x → 0. Because the value of CN (0) depends on N being zero for odd N and unity for even N, it follows that the magnitude response will either tend to zero for odd N or to
1/ 1 + ε2stop for even N. The zero frequency Ω = 0 corresponds to the limit x → ∞ which causes the Chebyshev polynomials to grow like a power xN . It follows that the numerator and denominator of the magnitude response (11.6.47) will both diverge but in such a way that
623
11.6. HIGHERORDER FILTERS
H(0)2 = 1. Thus, type 2 filters are always normalized to unity at DC. The filter order N can be determined by requiring the passband specification: Ωstop 2 CN Ωpass 1 H(Ωpass )2 = = 1 + ε2pass Ω stop 2 + ε2stop CN Ωpass It has the same solution Eq. (11.6.51) as the type 1 case. Once N is fixed, the 3dB frequency can be obtained by solving H(Ω3dB )2 = 1/2 which gives the solution:
Ω3dB =
Ωstop cosh
1
cosh−1 (εstop )
N
(11.6.68)
Because of the nontrivial numerator in Eq. (11.6.47), the filter will have both zeros and poles. They are solutions of the following equations obtained by replacing Ω = −js: 2
cosh
−1
N cosh
Ωstop −js
= 0,
cosh
2
−1
N cosh
jΩstop −js
+ ε2stop = 0
The zeros are the conjugate pairs {zi , z∗ i }:
zi =
jΩstop , sin θi
i = 1, 2, . . . , K
(11.6.69)
where N = 2K or N = 2K + 1. The poles are essentially the reciprocals of the type 1 poles, that is, the pairs {si , s∗ i }:
si =
Ωstop sinh a cos θi + j cosh a sin θi
,
i = 1, 2, . . . , K
(11.6.70)
In the oddN case, there is also a real pole at
s0 = −
Ωstop
(11.6.71)
sinh a
where the parameter a is the solution of sinh(Na)= εstop
(11.6.72)
that is,
a=
1
N
sinh−1 (εstop )=
1
N
ln εstop + ε2stop + 1
(11.6.73)
The angles θi are the same as in the type 1 case and given by Eq. (11.6.57). The secondorder sections are formed by pairing the zeros and poles in conjugate pairs:
s 1− zi Hi (s)= s 1− 1− si 1−
s ∗ zi s ∗ si
(11.6.74)
624
11. IIR DIGITAL FILTER DESIGN
For convenience, we define the parameters:
Ω0 =
Ωstop
Ωi =
,
sinh a
Ωstop sin θi
i = 1, 2, . . . , K
,
(11.6.75)
Then, we may express the secondorder sections in the form:
Hi (s)=
1 + Ωi −2 s2
1 − 2Ω0 cos θi s + (Ω0−2 + Ωi −2 )s2 −1
,
i = 1, 2, . . . , K
(11.6.76)
The firstorder factor H0 (s) is defined by
H0 (s)=
1, Ω0 , Ω0 + s
if N is even if N is odd
(11.6.77)
Again, all filter sections are normalized to unity gain at DC. Under the bilinear transformation s = (1 − z−1 )/(1 + z−1 ), the analog sections transform to digital versions of the form:
Hi (z)=
Gi (1 + bi1 z−1 + z−2 ) , 1 + ai1 z−1 + ai2 z−2
i = 1, 2, . . . , K
(11.6.78)
where the coefficients are computed in terms of the definitions in Eq. (11.6.75):
Gi = ai1 = ai2 =
−1
1 + Ω i −2
−2
1 − 2Ω0 cos θi + Ω0 + Ωi
−2
,
bi1 = 2
1 − Ωi −2 1 + Ωi −2
−2 2 2(1 − Ω− ) 0 − Ωi
(11.6.79)
−2 1 −2 1 − 2Ω− 0 cos θi + Ω0 + Ωi −2 1 −2 1 + 2Ω− 0 cos θi + Ω0 + Ωi −2 1 −2 1 − 2Ω− 0 cos θi + Ω0 + Ωi
The firstorder factor, if present, is given by
H0 (z)= where
G0 =
G0 (1 + z−1 ) 1 + a01 z−1
Ω0 , Ω0 + 1
The overall digital transfer function is then:
a01 =
Ω0 − 1 Ω0 + 1
H(z)= H0 (z)H1 (z)H2 (z)· · · HK (z)
(11.6.80)
(11.6.81)
(11.6.82)
Example 11.6.9: Redesign the two filters of Example 11.6.7 using a type 2 Chebyshev design. Solution: The values of εpass , εstop , Nexact , N remain the same as in Example 11.6.7. The parameter a, calculated from Eq. (11.6.73), is for the two specification sets: a = 0.4546 and 0.4407.
625
11.6. HIGHERORDER FILTERS
The actual passband attenuations are slightly higher than the specified ones. Evaluating Eq. (11.6.47) for the two designs, we find the values A(Ωpass )= 0.18 and 0.03 dB, instead of the required ones 0.5 and 0.08774. The 3dB frequencies are obtained by inverting:
tan
πf3dB fs
= Ω3dB =
Ωstop 1 cosh−1 (εstop ) cosh N
which gives the values f3dB = 4.7009 and 4.7031 kHz. For the first specification set, we have two secondorder sections whose coefficients are calculated from Eq. (11.6.79), resulting in the transfer function:
H(z)=
0.7612(1 + 0.1580z−1 + z−2 ) 0.5125(1 + 1.4890z−1 + z−2 ) · 1 − 0.0615z−1 + 0.7043z−2 1 + 0.5653z−1 + 0.2228z−2
For the second specification set, we have three sections with coefficients:
i
Gi
bi1
1 2 3
0.8137 0.6381 0.4955
0.0693 0.6667 1.7489
ai1 −0.1180 0.2492 0.6742
ai 2 0.8017 0.4524 0.1834
The designed magnitude responses are shown in Fig. 11.6.13.
Fig. 11.6.13 Digital lowpass Chebyshev type 2 filters.
The Chebyshev filter can also be transformed by the bandpass or bandstop versions of the bilinear transformation to design bandpass or bandstop digital filters. For example, transforming a type 2 filter by the bandpass transformation in Eq. (11.1.5) gives rise to fourthorder sections of the form:
Hi (z)= Gi
1 + bi1 z−1 + bi2 z−2 + bi1 z−3 + z−4 , 1 + ai1 z−1 + ai2 z−2 + ai3 z−3 + ai4 z−4
i = 1, 2, . . . , K
(11.6.83)
where by symmetry, the numerator coefficients of z−1 and z−3 are the same. The coefficients are given by:
626
11. IIR DIGITAL FILTER DESIGN
Gi =
1 + Ωi −2
−2 2 1 − 2Ω0 cos θi + Ω− 0 + Ωi −1
bi1 = −
4cΩi −2 1 + Ωi
,
−2
bi 2 =
2 Ωi −2 (2c2 + 1)−1 −2
1 + Ωi −1 −2 −2 4c Ω0 cos θi − Ω0 − Ωi 2 (Ω0−2 + Ωi −2 )(2c2 + 1)−1 ai2 = ai1 = −2 , −2 −1 −2 −1 −2 1 − 2Ω0 cos θi + Ω0 + Ωi 1 − 2Ω0 cos θi + Ω0 + Ωi −1 −2 2 4c Ω0 cos θi + Ω0−2 + Ωi −2 1 + 2Ω0−1 cos θi + Ω− 0 + Ωi ai3 = − ai4 = −2 , −2 1 −2 −1 −2 1 − 2Ω− + Ω 1 − 2 Ω + Ω cos θ + Ω cos θ + Ω i i i i 0 0 0 0 If N is odd, the firstorder analog section H0 (s) is transformed to the same quadratic section H0 (z) given in Section 11.6.4. Similarly, applying the bandstop transformation of Eq. (11.6.45), the type 2 Chebyshev secondorder sections in s are transformed into fourthorder sections in z in the same form of Eq. (11.6.83), but with coefficients given by:
Gi =
1 + Ωi −2
−2 2 1 − 2Ω0 cos θi + Ω− 0 + Ωi
bi1 = − ai1 = − ai3 = −
−1
4c 1 + Ωi −2
,
bi 2 =
2 2c2 + 1 − Ωi −2 1 + Ωi −2
4c 1 − Ω0−1 cos θi
−2 1 −2 1 − 2Ω− 0 cos θi + Ω0 + Ωi
4c 1 + Ω0−1 cos θi −1
−2
1 − 2Ω0 cos θi + Ω0 + Ωi
−2
,
ai2 =
,
ai4 =
−2 2 2 2c2 + 1 − Ω− 0 − Ωi
−2 2 1 − 2Ω0−1 cos θi + Ω− 0 + Ωi −2 2 1 + 2Ω0−1 cos θi + Ω− 0 + Ωi
−2 2 1 − 2Ω0−1 cos θi + Ω− 0 + Ωi
The firstorder section H0 (s) transforms to the same H0 (z) as that of Section 11.6.5, but with Ω0 given by Eq. (11.6.75). Example 11.6.10: Redesign the bandpass digital filters of Example 11.6.5 using a type 2 Chebyshev analog prototype.
Solution: The prewarped frequencies and bilinear transformation parameter c are as in that example: Ωpass = 0.3249, Ωstop = 0.4674, c = 0.6180. The Chebyshev design parameters are for the two specification sets:
εpass = 0.3493,
εstop = 3,
Nexact = 3.14,
N = 4,
a = 0.4546
εpass = 0.1429,
εstop = 7,
Nexact = 5.07,
N = 6,
a = 0.4407
For the first set, there are two fourthorder sections with coefficients:
i
Gi
1 2
0.7334 0.3677
bi1 −1.9684 −0.9922
bi2 2.4015 0.2187
ai1 −1.9604 −1.4221
ai 2 2.2956 0.8671
ai 3 −1.6758 −0.4101
ai4 0.7697 0.1813
627
11.6. HIGHERORDER FILTERS For the second set, there are three fourthorder sections:
i
Gi
1 2 3
0.7840 0.5858 0.3159
b i1 −2.0032 −1.7205 −0.5802
bi 2 2.4793 1.8472 −0.7026
ai 1 −2.0118 −1.7286 −1.3122
ai2 2.4413 1.6780 0.5868
ai3 −1.8265 −1.1223 −0.1879
ai4 0.8501 0.5094 0.0904
The designed magnitude responses are shown in Fig. 11.6.14.
Fig. 11.6.14 Digital bandpass Chebyshev type 2 filters.
Example 11.6.11: Redesign the bandstop digital filters of Example 11.6.6 using a type 2 Chebyshev analog prototype.
Solution: The prewarped frequencies and bilinear transformation parameter c are as in that example: Ωpass = 1.9626, Ωstop = 2.7121, c = 0.6597. For the two specification sets, the exact Chebyshev orders are Nexact = 3.35 and 5.40, which round up to N = 4 and 6, respectively. The other Chebyshev parameters remain the same as in Example 11.6.10. For the first set, the fourthorder sections have coefficients:
i
Gi
1 2
0.8727 0.7442
bi 1 −2.3644 −2.5872
bi 2 3.1438 3.6287
ai1 −2.2003 −2.2339
ai2 2.6965 2.6565
ai3 −1.9264 −1.6168
0.7924 0.5323
ai4
ai3 −2.0326 −1.7441 −1.6241
0.8601 0.6441 0.5238
For the second set, there are three fourthorder sections:
i
Gi
1 2 3
0.9074 0.8009 0.7412
bi 1 −2.3417 −2.4708 −2.6149
bi 2 3.0945 3.3754 3.6889
ai1 −2.2171 −2.2137 −2.2524
ai2 2.7626 2.6612 2.6929
The designed magnitude responses are shown in Fig. 11.6.15.
ai4
628
11. IIR DIGITAL FILTER DESIGN
Fig. 11.6.15 Digital bandstop Chebyshev type 2 filters.
11.7 Problems 11.1 Consider the peaking filter of Eq. (11.3.21). Derive an analytical expression for its impulse response h(n) in terms of the parameters ω0 and ∆ω. Show that its transient (level) time constant is given by:
neff =
ln , ln ρ
ρ=
1
1−β 1+β
11.2 Consider the peaking filter of Eq. (11.3.21). Taking the limit ∆ω → 0 and keeping only the lowestorder terms in ∆ω, show that the pole radius R is related approximately to ∆ω by Eq. (6.4.4), that is, ∆ω 2(1 − R). Show also that neff −2 ln /∆ω. 11.3 Verify the complementarity properties for the filters of Eqs. (11.3.7) and (11.3.21):
Hnotch (z)+Hpeak (z)= 1,
Hnotch (ω)2 + Hpeak (ω)2 = 1,
(when G2B = 1/2)
11.4 Consider the three choices for the bandwidth reference gain in parametric equalizer filters: G2B = (G20 + G2 )/2 (arithmetic mean), G2B = G0 G (geometric mean), and G2B = 2G20 G2 /(G20 + G2 ) (harmonic mean). For each case, discuss how the design parameter β of Eq. (11.4.6) simplifies. For the geometric mean case [268], show that if you design two boost and cut digital filters centered at the same frequency and having equal bandwidths and equal and opposite boost/cut gains (in dB), then their magnitude responses will be related by Hboost (ω)2 Hcut (ω)2 = G40 . Show that the more general weighted geometric mean choice G2B = G10−c G1+c , 0 ≤ c < 1 also satisfies this property. 11.5 Computer Experiment: Peaking and Notching Filters. Reproduce the results and graphs of Example 11.3.1. Plot also the phase responses of all the filters. For each filter, draw its canonical realization and write the corresponding sample processing algorithm. (You may use the MATLAB function parmeq.m to design them.) Calculate the 5% time constants of the filters. Send a unit impulse δ(n) into the input and calculate and plot the impulse responses h(n) of these filters. You must compute h(n) for a period of at least two 5% time constants. (You may use the routines sos.c or sos.m to implement them.) 11.6 Computer Experiment: Parametric EQ Filter Design. Reproduce the results and graphs of Examples 11.4.1 and 11.4.2. Plot also the phase responses of all the filters. (You may use the MATLAB function parmeq.m to design them.)
629
11.7. PROBLEMS
For the filters of Example 11.4.1, compute their 5% time constants and compute and plot their impulse responses h(n) versus n. 11.7 Computer Experiment: Lowpass/Highpass EQ Filters. Write a MATLAB function (similar to parmeq.m) to design the lowpass or highpass shelving equalizer filters defined by Eqs. (11.4.9) and (11.4.11). Use the function to reproduce the results and graphs of Examples 11.2.1 and 11.2.2. 11.8 Computer Experiment: Periodic Comb/Notch Parametric EQ Design. Reproduce the results and graphs of Example 11.5.1. Plot also the phase responses of all the filters. (You may use the MATLAB function combeq.m to design them.) Write a C or MATLAB function, say combfilt, that implements the sample processing algorithm of the time domain operation of the comb filter. It must have usage: y = combfilt(a, b, c, D, w, x); [y, w] = combfilt(a, b, c, D, w, x);
(C version) (MATLAB version)
where w is the (D+1)dimensional delayline buffer, and {x, y} are the input and output samples. The parameters {a, b, c} are generated by combeq. For the C case, you may use a circular buffer. Using this function, calculate and plot the impulse response h(n) of all the designed filters. 11.9 The passband and stopband specifications are defined somewhat differently in FIR and IIR designs. Discuss these differences and explain why the parameter sets {δpass , δstop } of Eq. (10.2.5) and {εpass , εstop } of Eq. (11.6.4) are appropriate for FIR and IIR designs. 11.10 The parameters N and Ω0 of an analog Butterworth filter are determined by solving the two specification equations A(Ωpass )= Apass , A(Ωstop )= Astop . The resulting filter order is then rounded up to the next integer value N. Using this slightly larger N, show that if Ω0 is found from the passband specification, that is, by solving A(Ωpass )= Apass , then the stopband specification is more than satisfied, that is, A(Ωstop )> Astop . Similarly, show that if we find Ω0 from the stopband specification A(Ωstop )= Astop , then the passband specification is more than satisfied, that is, A(Ωpass )< Apass . 11.11 Using the bilinear transformation and a lowpass analog Butterworth prototype filter, design a lowpass digital filter operating at a rate of 40 kHz and having the following specifications: fpass = 10 kHz, Apass = 3 dB, fstop = 15 kHz, Astop = 35 dB. Carry out all the design steps by hand. Draw the cascade realization form and write the difference equations and the corresponding sample processing algorithm implementing this realization in the time domain. 11.12 Using the bilinear transformation method and a Butterworth lowpass analog prototype, design (by hand) a digital highpass filter operating at a rate of 10 kHz and having passband and stopband frequencies of 3 kHz and 2 kHz, respectively. The maximum passband and minimum stopband attenuations are required to be 0.5 dB and 10 dB respectively. a. What are the actual maximum passband and minimum stopband attenuations in dB achieved by the designed filter? b. Draw the cascade realization and write the corresponding difference equations describing the timedomain operation of the filter. c. Give a simple closedform expression of the magnitude response of the designed filter as a function of the variable cot(ω/2). Sketch the magnitude response over the frequency interval 0 ≤ f ≤ 20 kHz.
630
11. IIR DIGITAL FILTER DESIGN
11.13 Show that the generalized bilinear transformation
s=
1 − 2cz−1 + z−2 1 − z−2
(11.7.1)
maps the lefthand splane onto the inside of the unit circle of the zplane, provided the real constant c is such that c ≤ 1. 11.14 In the design of bandpass/bandstop filters, we found that the constant c of the generalized bilinear transformation of Eq. (11.7.1) was given by an expression of the form:
c=
sin(ω1 + ω2 ) sin(ω1 )+ sin(ω2 )
Show that it satisfies the stability condition c ≤ 1, regardless of the values of ω1 and ω2 in the interval [0, π]. 11.15 Using a thirdorder analog lowpass Butterworth prototype filter and the bandpass bilinear transformation of Eq. (11.7.1), design a digital bandpass filter operating at 20 kHz and having attenuation of 0.5 dB at the frequencies 2 kHz and 8 kHz. What is the transfer function of the designed filter? What are the upper and lower 3dB frequencies of this filter? What is its center frequency in kHz? Sketch roughly the magnitude response over the range 0 ≤ f ≤ 30 kHz. 11.16 Carry out the algebra in Eq. (11.6.23) to show the coefficient equations (11.6.24) for designing a digital lowpass Butterworth filter. Verify also Eq. (11.6.26). Repeat for the highpass case, Eqs. (11.6.32)—(11.6.35). Repeat for the bandpass case, Eqs. (11.6.40)–(11.6.43). 11.17 Prove Eqs. (11.6.44) for the left and right 3dB frequencies of a bandpass Butterworth design. 11.18 The bandpass and bandstop Butterworth designs discussed in Sections 11.6.4 and 11.6.5 match the passband specifications exactly and use the more conservative of the two stopbands. Instead, if we were to match the stopbands exactly and use the more conservative passband, what changes in the design procedure should we make? 11.19 Carry out the algebra of the bilinear transformation to verify the design equations of Eqs. (11.6.65) and (11.6.79) for designing digital lowpass type 1 and type 2 Chebyshev filters. 11.20 Equations (11.6.53) and (11.6.58) define the Chebyshev poles si and the quantities {Ω0 , Ωi }. Show that they satisfy the following relationship, which is used in the secondorder Chebyshev sections (11.6.59):
si 2 = Ω20 + Ωi 2 11.21 The IIR cascade filtering routines cas.c or cas.m are appropriate for cascading secondorder sections and can be used in the lowpass and highpass designs. In bandpass and bandstop designs, however, we have the cascade of fourthorder sections whose coefficients are stored in the K×5 matrices A and B that are generated by the filter design functions, such as bpcheb2.m, where K is the number of fourthorder sections. Write C and/or MATLAB versions of the routine cas, say cas4, that works with fourthorder sections. Its inputs must be the matrices A and B, a K×5 state matrix W whose rows are the state vectors of the cascaded fourthorder sections, and the current input sample x. Its outputs must be the current output sample y and the updated state matrix W. It must have usage:
631
11.7. PROBLEMS y = cas4(K, B, A, W, x); [y, W] = cas4(K, B, A, W, x);
(C version) (MATLAB version)
It must call K times a single fourthorder section routine, like the sos routine. Then, write C and/or MATLAB filtering routines, like casfilt of Problem 7.15, that can filter a vector of input samples producing a vector of output samples. 11.22 Computer Experiment: Butterworth Digital Filter Designs. Reproduce all the results and graphs of the lowpass, highpass, bandpass, and bandstop Butterworth design Examples 11.6.3–11.6.6. You may use the MATLAB functions lhbutt.m and bpsbutt.m to design the filters. For each design, also do the following: Plot the phase response of the filter. Compute the filter’s 5% time constant (you will need to use MATLAB’s root finder roots). Then, using the routines cas.c or cas.m, (or cas4.c, cas4.m of Problem 11.21), compute and plot the impulse response h(n) of the filter over a period lasting two time constants. 11.23 Computer Experiment: Chebyshev Digital Filter Designs. Reproduce all the results and graphs of the lowpass, highpass, bandpass, and bandstop Chebyshev design Examples 11.6.7–11.6.11. You may use the MATLAB functions lhcheb1, lhcheb2, bpcheb2, and bscheb2 to design the filters. For each design, also do the following: Plot the phase response of the filter. Compute the filter’s 5% time constant. Then, compute and plot the impulse response h(n) of the filter over a period lasting two time constants. Since the specifications of the filters are the same as those of Problem 11.22, compare the Butterworth and Chebyshev designs in terms of their order N and their phase response. In both problems, the frequency responses can be computed with the included MATLAB functions cas2can and dtft. For example, the frequency response of a type 2 bandstop design can be computed as follows: [A, a = b = w = H =
B, P] = bscheb2(fs, fpa, fpb, fsa, fsb, Apass, Astop); directform denominator cas2can(A); cas2can(B); directform numerator (0:NF1) * pi / NF; NF frequencies over [0, π] dtft(b, w) ./ dtft(a, w); compute H(ω) = N(ω)/D(ω)
12 Interpolation, Decimation, and Oversampling
12.1 Interpolation and Oversampling Sampling rate changes are useful in many applications, such as interconnecting digital processing systems operating at different rates [273–276]. Sampling rate increase is accomplished by interpolation, that is, the process of inserting additional samples between the original lowrate samples. The inserted, or interpolated, samples are calculated by an FIR digital filter.† This is illustrated in Fig. 12.1.1 for the case of a 4fold interpolator which increases the sampling rate by a factor of four, that is, fs = 4fs .
t T
t 4
low rate fs
upsampler
T′=T/4 high rate 4fs
t FIR interpolation filter
T′=T/4 high rate 4fs
Fig. 12.1.1 Sampling rate increase with digital interpolation.
With respect to the fast time scale, the lowrate samples may be thought of as being separated by three zero samples. The 4fold rate expander or upsampler simply inserts three zero samples for every lowrate sample. The job of the FIR filter is to replace the three zeros by the calculated interpolated values. The interpolating filter is sometimes called an oversampling digital filter because it operates at the fast rate 4fs . However, because only one out of every four input samples is nonzero, the required filtering operations may be rearranged in such a way as to operate only on the lowrate samples, thus, effectively reducing the computational requirements of the filter—by a factor of four in this case. This is accomplished by replacing the highrate interpolating FIR filter by four shorter FIR subfilters, known as polyphase filters, operating at the low rate fs . The length of each † IIR
filters can also be used, but are less common in practice.
632
633
12.1. INTERPOLATION AND OVERSAMPLING
subfilter is onequarter that of the original filter. Because each lowrate input sample generates four highrate interpolated outputs (itself and three others), each of the four lowrate subfilters is dedicated to computing only one of the four outputs. Such realization is computationally efficient and lends itself naturally to parallel multiprocessor hardware implementations in which a different DSP chip may be used to implement each subfilter. An interesting application of interpolation is the use of oversampling digital filters in CD or DAT players, where they help to alleviate the need for highquality analog antiimage postfilters in the playback system. Moreover, each highrate sample can be requantized without loss of quality to fewer number of bits (even as low as 1 bit per sample) using appropriate noise shaping quantizers, thus, trading off bits for samples and simplifying the structure of the analog part of the playback system. To understand the motivation behind this application, consider an analog signal sampled at a rate fs , such as 44.1 kHz for digital audio. The analog signal is prefiltered by an analog lowpass antialiasing prefilter having cutoff frequency fc ≤ fs /2 and then sampled at rate fs and quantized. This operation is shown in Fig. 12.1.2.
analog input
lowpass antialiasing prefilter
bandlimited analog signal
digital signal
A/D converter
xa(t)
rate fs
fc < fs /2 Fig. 12.1.2 Prefiltering and sampling of analog signal.
The prefilter ensures that the spectral images generated by the sampling process at integral multiples of fs do not overlap, as required by the sampling theorem. This is shown in Fig. 12.1.3 (we ignore here the scaling factor 1/T).
original spectrum Xa( f )
4fs
3fs
2fs
X( f )
spectral images
fs fs /2 0 fs /2 fs
f 2fs
3fs
4fs
Nyquist interval Fig. 12.1.3 Spectrum of signal sampled at low rate fs .
After digital processing, the sampled signal is reconstructed back to analog form by a D/A staircase reconstructor, followed by an analog antiimage lowpass postfilter with effective cutoff fs /2, as seen in Fig. 12.1.4. The D/A converter, with its typical sin x/x response, removes the spectral images partially; the postfilter completes their removal. The combination of the staircase DAC and the postfilter emulates the ideal reconstructing analog filter. The ideal reconstruc
634
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
digital signal rate fs
staircase analog signal
D/A converter
analog output
lowpass antiimage postfilter fc < fs /2
Fig. 12.1.4 Analog reconstruction of sampled signal.
tor is a lowpass filter with cutoff the Nyquist frequency fs /2. It has a very sharp transition between its passband, that is, the Nyquist interval, and its stopband, as shown in Fig. 12.1.5.
ideal reconstructor
4fs
3fs
2fs
sharp transition
fs fs /2 0 fs /2 fs
f 2fs
3fs
4fs
Fig. 12.1.5 Ideal reconstructor removes spectral images due to sampling.
In hifi applications such as digital audio, to maintain high quality in the resulting reconstructed analog signal, a very high quality analog postfilter is required, which may be expensive. One way to alleviate the need for a high quality postfilter is to increase the sampling rate. This would cause the spectral images to be more widely separated and, therefore, require a less stringent, simpler, lowpass postfilter. This is depicted in Fig. 12.1.6, for a new sampling rate that is four times higher than required, fs = 4fs .
wide transition
fs′
postfilter passband
X′( f ) postfilter stopband
fs′/2
fs′/8 0
fs′/8
7fs′/8 f ′ s
fs′/2
Nyquist interval
f
Fig. 12.1.6 Spectrum of signal resampled at high rate 4fs , and postfilter requirements.
The passband of the postfilter extends up to fpass = fs /8 = fs /2, but its stopband need only begin at fstop = fs − fs /8 = 7fs /8. It is this wide transition region between passband and stopband that allows the use of a less stringent postfilter. For example, in oversampled digital audio applications, simple thirdorder Butterworth or Bessel analog postfilters are used. See Section 12.4.4. The same conclusion can also be drawn in the time domain. Figure 12.1.7 shows the staircase output of the D/A converter for the two sampling rates fs and fs = 4fs . It is evident from this figure that the higher the sampling rate, the more closely the staircase
635
12.1. INTERPOLATION AND OVERSAMPLING
output approximates the true signal, and the easier it is for the postfilter to smooth out the staircase levels.
DAC output
DAC output
t
t
T
T′=T/4
Fig. 12.1.7 Staircase DAC output is smoothed more easily in the oversampled case.
The above approach, however, is impractical because it requires the actual resam pling of the analog signal at the higher rate fs . For example, in a CD player the low rate samples are already stored on the CD at the prescribed rate of 44.1 kHz and the audio signal cannot be resampled. The philosophy of oversampling is to increase the sampling rate digitally using an interpolation filter which operates only on the available lowrate input samples. With respect to the new rate fs and new Nyquist interval [−fs /2, fs /2], the spectrum of the lowrate samples depicted in Fig. 12.1.3 will be as shown in Fig. 12.1.8. This is also the spectrum of the highrate upsampled signal at the output of the rate expander in Fig. 12.1.1.
upsampled spectrum
fs′
fs′/2
fs′/8 0
Xup( f ) = X( f )
fs′/8
fs′/2
Nyquist interval
fs′
f
Fig. 12.1.8 Spectrum of lowrate samples with respect to the high rate 4fs .
A digital lowpass FIR filter with cutoff frequency fs /8 and operating at the high rate fs , would eliminate the three spectral replicas that lie between replicas at multiples of fs , resulting in a spectrum that is identical to that of a signal sampled at the high rate fs , like that shown in Fig. 12.1.6. The digital filter, being periodic in f with period fs , cannot of course remove the spectral replicas that are centered at integral multiples of fs . Those are removed later by the D/A reconstructor and the antiimage analog postfilter. The effect of such a digital filter on the spectrum of the lowrate samples is shown in Fig. 12.1.9, both with respect to the physical frequency f in Hz and the corresponding digital frequency, ω = 2πf /fs , in radians/sample. In summary, a substantial part of the analog reconstruction process is accomplished by DSP methods, that is, using a digital oversampling filter to remove several adjacent spectral replicas and thereby easing the requirements of the analog postfilter. The required sharp transition characteristics of the overall reconstructor are provided by the
636
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
digital filter is periodic with period fs′
lowpass digital filter D( f )
fs′/8 0
fs′/2
fs′
fs′/8
fs′/2
Nyquist interval
digital filter is periodic with period 2π
lowpass digital filter D(ω′)
2π
π
f
fs′
−π/4 0
π/4
π
2π
ω′
Nyquist interval Fig. 12.1.9 Highrate FIR interpolator removes intermediate spectral images.
digital filter. Thus, the highquality analog postfilter is traded off for a highquality digital filter operating at a higher sampling rate. The overall system is depicted in Fig. 12.1.10.
fs
4fs
4 upsampler
FIR interpolation filter
4fs
antiimage lowpass postfilter
D/A converter
analog output
Fig. 12.1.10 4times oversampling digital filter helps analog reconstruction.
How does an interpolation filter operate in the time domain and calculate the missing signal values between lowrate samples? To illustrate the type of operations it must carry out, consider a 4fold interpolator and a set of six successive lowrate samples {A, B, C, D, E, F} as shown in Fig. 12.1.11.
C X
Y
Z
D E
B
F
A
T
T′=T/4
time
Fig. 12.1.11 Filter calculates missing samples from the surrounding lowrate samples.
The filter calculates three intermediate samples, such as {X, Y, Z}, between any two lowrate samples by forming linear combinations of the surrounding lowrate samples.
12.1. INTERPOLATION AND OVERSAMPLING
637
Depending on the type of interpolator and desired quality of the calculated values, several different ways of calculating {X, Y, Z} are possible. For example, the simplest one is to keep the value of the previous sample C constant throughout the sampling interval and define:
X=Y=Z=C This choice corresponds to the socalled hold interpolator. Another simple possibility is to interpolate linearly between samples {C, D} calculating {X, Y, Z} as follows:
X = 0.75C + 0.25D Y = 0.50C + 0.50D
(12.1.1)
Z = 0.25C + 0.75D Indeed, the straight line connecting C and D is parametrized as C + (D − C)t/T, for 0 ≤ t ≤ T. Setting t = T , 2T , 3T with T = T/4 gives the above expressions for {X, Y, Z}. For more accurate interpolation, more surrounding samples must be taken into account. For example, using four samples we have:
X = −0.18B + 0.90C + 0.30D − 0.13E Y = −0.21B + 0.64C + 0.64D − 0.21E
(12.1.2)
Z = −0.13B + 0.30C + 0.90D − 0.18E corresponding to a length17 FIR approximation to the ideal interpolation filter. Similarly, a length25 approximation to the ideal interpolator uses six surrounding lowrate samples as follows:
X = 0.10A − 0.18B + 0.90C + 0.30D − 0.13E + 0.08F Y = 0.13A − 0.21B + 0.64C + 0.64D − 0.21E + 0.13F
(12.1.3)
Z = 0.08A − 0.13B + 0.30C + 0.90D − 0.18E + 0.10F In general, the more the surrounding samples, the more accurate the calculated values. In typical CD players with 4times oversampling filters, about 20–30 surrounding lowrate samples are used. The above expressions do not quite look like the convolutional equations of linear filtering. They are special cases of the polyphase realizations of the interpolation filters and are equivalent to convolution. They will be discussed in detail in the next section, where starting with the frequency domain specifications of the filter, its impulse response and corresponding direct and polyphase realization forms are derived. See also Section 12.4.1.
638
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
12.2 Interpolation Filter Design∗ 12.2.1 Direct Form Consider the general case of an Lfold interpolator, which increases the sampling rate by a factor of L, that is, fs = Lfs . The Lfold rate expander inserts L − 1 zeros between adjacent lowrate samples and the corresponding L− 1 interpolated values are calculated by an FIR digital filter operating at the high rate Lfs , as shown in Fig. 12.2.1.
low rate input
upsampled input
x(n) n
yup(n′)
n′
T low rate fs
high rate output
xup(n′)
n′
T′=T/L
L
high rate Lfs
Lfold rate expander
T′=T/L
H FIR interpolation filter d(k′)
high rate Lfs
Fig. 12.2.1 Lfold digital interpolator.
Let x(n) denote the lowrate samples that are input to the rate expander and let xup (n ) be its highrate output, consisting of the lowrate samples separated by L − 1 zeros. With respect to the highrate time index n , the lowrate samples occur every L highrate ones, that is, at integral multiples of L, n = nL,
xup (nL)= x(n)
(12.2.1)
The L − 1 intermediate samples between xup (nL) and xup (nL + L) are zero:
xup (nL + i)= 0,
i = 1, 2, . . . , L − 1
(12.2.2)
This is shown in Fig. 12.2.2. More compactly, the upsampled signal xup (n ) can be defined with respect to the highrate time index n by:
xup (n )=
x(n), 0,
if n = nL otherwise
(12.2.3)
Given an arbitrary value of the highrate index n , we can always write it uniquely in the form n = nL + i, where i is restricted to the range of values i = 0, 1, . . . , L − 1. Mathematically, the integers n and i are the quotient and remainder of the division of n by L. Intuitively, this means that n will either fall exactly on a lowrate sample (when i = 0), or will fall strictly between two of them (i = 0). Using T = LT , we find the absolute time in seconds corresponding to n
t = n T = nLT + iT = nT + iT that is, it will be offset from a lowrate sampling time by i highrate sampling units T . The interpolated values must be computed at these times.
12.2. INTERPOLATION FILTER DESIGN∗
x(n)
639
x(n+1)
x(n1)
x(n+2) rate fs n1
n
n+1
xup(nL)
xup(nLL)
n = slow time
n+2
xup(nL+L)
xup(nL+2L) rate Lfs
L1 zeros
...
... nL
nLL
nL+1 nL+2
...
n′ = fast time
nL+2L
nL+L
Fig. 12.2.2 Lowrate samples with respect to the slow and fast time scales.
The ideal Lfold interpolation filter is a lowpass filter, operating at the fast rate fs , with cutoff frequency equal to the lowrate Nyquist frequency fc = fs /2, or in terms of fs ,
fs
fc =
2
=
fs 2L
(12.2.4)
and expressed in units of the digital frequency, ω = 2πf /fs : 2πfc
ωc =
fs
=
π L
(12.2.5)
The frequency response of this filter is shown in Fig. 12.2.3. Its passband gain is taken to be L instead of unity. This is justified below. The ideal impulse response coefficients are obtained from the inverse Fourier transform:
d(k )=
π
−π
D(ω )ejω k
dω = 2π
π/L
−π/L
dω sin(πk /L) = 2π πk /L
digital filter is periodic with period 2π
lowpass digital filter D(ω′) L
L
2π
Lejω k
π
−π/L 0
L
π/L
π
2π
ω′
Nyquist interval Fig. 12.2.3 Ideal lowpass digital filter operating at high rate Lfs .
An FIR approximation to the ideal interpolator is obtained by truncating d(k ) to finite length, say N = 2LM + 1:
640
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
d(k )=
sin(πk /L)
πk /L
−LM ≤ k ≤ LM
,
(12.2.6)
A causal version of the filter may be obtained by delaying it by LM samples:
h(n )= d(n − LM)=
sin π(n − LM)/L
π(n − LM)/L
,
n = 0, 1, . . . , N − 1
And a windowed version is obtained by:
h(n )= w(n )d(n − LM) ,
n = 0, 1, . . . , N − 1
(12.2.7)
where w(n ) is an appropriate lengthN window, such as a Hamming window:
w(n )= 0.54 − 0.46 cos
2πn N−1
,
n = 0, 1, . . . , N − 1
or a Kaiser window. The output of the ideal FIR interpolation filter is obtained by the convolution of the upsampled input xup (n ) with the impulse response d(k ):
yup (n )=
LM
k =−LM
d(k )xup (n − k ) ,
n = 0, 1, . . . , N − 1
(12.2.8)
12.2.2 Polyphase Form The interpolated values between the lowrate samples xup (nL) and xup (nL + L), that is, the values at the highrate time instants n = nL + i, are calculated by the filter as follows:
yup (nL + i)=
LM
k =−LM
d(k )xup (nL + i − k ),
i = 0, 1, . . . , L − 1
(12.2.9)
Writing uniquely k = kL + j, with 0 ≤ j ≤ L − 1, and replacing the single summation over k by a double summation over k and j, we find
yup (nL + i)=
M− 1 L− 1
k=−M j=0
d(kL + j)xup (nL + i − kL − j)
To be precise, for the case i = 0, the summation over k should be over the range −M ≤ k ≤ M. But as we will see shortly, the term k = M does not contribute to the sum. Defining the ith polyphase subfilter by†
di (k)= d(kL + i) ,
−M ≤ k ≤ M − 1
for i = 0, 1, . . . , L − 1, we can rewrite the ith interpolated sample value as: † For
i = 0, the range of k is −M ≤ k ≤ M.
(12.2.10)
12.2. INTERPOLATION FILTER DESIGN∗
yup (nL + i)=
641
M− 1 L− 1
k=−M j=0
dj (k)xup (nL − kL + i − j)
But the upsampled input signal is nonzero only at times that are integral multiples of L. Therefore, using Eqs. (12.2.1) and (12.2.2), we have
xup (nL − kL + i − j)= 0,
if i = j
This follows from the fact that i − j ≤ L − 1. Thus, keeping only the j = i term in the above convolution sum, we obtain
yup (nL + i)=
M− 1
k=−M
di (k)xup (nL − kL),
i = 0, 1, . . . , L − 1
(12.2.11)
or, in terms of the lowrate samples:
yi (n)=
M− 1
k=−M
di (k)x(n − k) ,
i = 0, 1, . . . , L − 1
(12.2.12)
where we set yi (n)= yup (nL + i). Thus, the ith interpolated value, yup (nL + i), is computed by the ith polyphase subfilter, di (k), which has length 2M and is acting only on the lowrate input samples x(n). Each interpolated value is computed as a linear combination of M lowrate samples above and M below the desired interpolation time, as shown in Fig. 12.2.4.
yi (n) M lowrate samples x(n1)
M lowrate samples
x(n)
x(n+1) x(n+2) x(n+M)
x(nM+1)
... nM+1
...
... n1
n
n+1
n+2
...
n+M
n
n′ = nL+i Fig. 12.2.4 Interpolator uses M lowrate samples before and after yup (nL + i).
Using the L subfilters, interpolation is performed at a reduced computational cost as compared with the cost of the full, lengthN, interpolation filter d(k ) acting on the upsampled signal xup (n ) by Eq. (12.2.9). The computational cost of Eq. (12.2.9) is essentially 2LM multiplications per interpolated value, or, 2L2 M multiplications for computing L interpolated values. By contrast, Eq. (12.2.11) requires 2M multiplications per polyphase subfilter, or, 2LM multiplications for L interpolated values. Thus, the polyphase subfilter implementation achieves a factor of L in computational savings.
642
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
Another way to view the computational rate is in terms of the total number of multiplications per second required for the filtering operations, that is,
R = N(Lfs )= NLfs
(direct form)
R = L(2M)fs = Nfs
(polyphase form)
where in the direct form we have a single filter of length N operating at rate Lfs and in the polyphase form we have L filters operating at fs , each having computational rate (2M)fs multiplications per second.† The polyphase implementation is depicted in Fig. 12.2.5, where during each lowrate sampling period T, the commutator reads, in sequence of T = T/L seconds, the L interpolated values at the outputs of the subfilters.
subfilter d0(k)
x(n)
subfilter d1(k)
n
y0(n) yup(n′) y1(n)
n′ T/L
T
T′=T/L
low rate fs
subfilter dL1(k)
T
yL1(n)
high rate Lfs
Fig. 12.2.5 Polyphase subfilter implementation of digital interpolator.
This can be seen more formally, as follows. Let ζ −1 denote the unit delay with respect to the high rate Lfs and let z−1 denote the lowrate delay. Since L highrate delays equal one lowrate delay, that is, LT = T, we will have:
z = ζL
ζ = z1/L
(12.2.13)
The ζ transform of the highrate filter output yup (n ) can be expressed in terms of the ztransforms of the L lowrate output signals yi (n) as follows. Writing uniquely n = nL + i with 0 ≤ i ≤ L − 1, we have
Yup (ζ) = =
∞
n =−∞ L− 1 i=0
yup (n )ζ −n =
ζ −i
L− 1
∞
i=0 n=−∞
∞
yi (n)ζ −Ln ,
L− 1
ζ −i Yi (ζ L )=
yup (nL + i)ζ −nL−i
or,
n=−∞
Yup (ζ)=
i=0
L− 1
z−i/L Yi (z)
(12.2.14)
i=0
† Actually, there are L − 1 subfilters of length (2M) and one (the filter d ) of length (2M + 1), giving rise 0 to R = (L − 1)(2M)fs + (2M + 1)fs = Nfs , where N = 2LM + 1.
12.2. INTERPOLATION FILTER DESIGN∗
643
which shows how the L lowrate output signals are put together, in sequence of T/L highrate delays to make up the highrate interpolated output signal. In a similar fashion, we can derive the relationship between the ζ transform of the highrate filter (12.2.6) and the ztransforms of its polyphase subfilters (12.2.10), justifying the realization of Fig. 12.2.5:
D(ζ)=
L− 1
ζ −i Di (ζ L )=
i=0
L− 1
z−i/L Di (z)
(12.2.15)
i=0
Next, we consider the 0th polyphase subfilter, d0 (k), which plays a special role. It follows from Eqs. (12.2.6) and (12.2.10) that:
d0 (k)= d(kL)=
sin(πk)
πk
= δ(k),
−M ≤ k ≤ M
and therefore, its output will be trivially equal to its input, that is, the lowrate input sample x(n)= xup (nL). We have from Eq. (12.2.12):
y0 (n)= yup (nL)=
M− 1
k=−M
d0 (k)x(n − k)=
M− 1
k=−M
δ(k)x(n − k)= x(n)
This property is preserved even for the windowed case of Eq. (12.2.7), because all windows w(n ) are equal to unity at their middle. This result justifies the requirement for the passband gain of the interpolator filter in Fig. 12.2.3 to be L instead of 1. If the gain were 1, we would have yup (nL)= x(n)/L. An alternative, frequency domain justification is given in Section 12.2.3. The causal filter implementation of Eq. (12.2.12) requires that we either delay the output or advance the input by M units. We choose the latter. The polyphase subfilters in Eqs. (12.2.12) can be made causal by a delay of M lowrate samples:
hi (n)= di (n − M)= d (n − M)L + i = d(nL + i − LM)
(12.2.16)
for n = 0, 1, . . . , 2M − 1. For the windowed case, we have:
hi (n)= d(nL + i − LM)w(nL + i),
n = 0, 1, . . . , 2M − 1
(12.2.17)
In terms of the causal subfilters hi (n), Eq. (12.2.12) becomes
yi (n)=
M− 1
k=−M
di (k)x(n − k)=
M− 1
k=−M
hi (k + M)x(n − k)
or, setting m = k + M and k = m − M,
yi (n)=
P
m=0
hi (m)x(M + n − m) ,
i = 0, 1, . . . , L − 1
(12.2.18)
where P = 2M − 1 denotes the order of each polyphase subfilter. In other words, the interpolated samples are obtained by ordinary causal FIR filtering of the timeadvanced
644
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
lowrate input samples. The same result can also be obtained by ztransforms (recall also the implementation of SavitzkyGolay filters in Section 8.3.5.) Definition (12.2.16) reads in the zdomain:
Hi (z)= z−M Di (z) where z−1 represents a lowrate delay. Similarly, Eq. (12.2.12) reads
Yi (z)= Di (z)X(z) Writing Di (z)= zM Hi (z), we obtain the zdomain equivalent of Eq. (12.2.18):
Yi (z)= Di (z)X(z)= Hi (z) zM X(z)
The samplebysample processing implementation of Eq. (12.2.18) requires a common lowrate tapped delay line which is used in sequence by all the subfilters hi (n) before its contents are updated. Figure 12.4.5 shows a concrete example when L = 4 and M = 2. The required timeadvance by M samples is implemented by initially filling the delay line with the first M lowrate samples. The internal states of the tapped delay line can be defined as
wm (n)= x(M + n − m),
m = 0, 1, . . . , P
Then, Eq. (12.2.18) can be written in the dotproduct notation of Chapter 4: P hi (m)wm (n), yi (n)= dot P, hi , w(n) =
i = 0, 1, . . . , L − 1
m=0
After computing the outputs of the L subfilters, the internal state w may be updated to the next time instant by a call to the routine delay, which shifts the contents:
wm (n + 1)= wm−1 (n),
m = 1, 2, . . . , P
This leads to the following sample processing algorithm for the polyphase form: Initialize the internal state vector w(n)= [w0 (n), w1 (n), . . . , wP (n)] by filling it with the first M lowrate input samples, x(0), x(1), . . . , x(M − 1), that is, at time n = 0 start with w(0)= [0, xM−1 , xM−2 , . . . , x0 , 0, 0, . . . , 0]
%
M−1
&'
zeros
(
The value w0 (0) need not be initialized—it is read as the current input sample. If the lowrate samples are being read sequentially from a file or an input port, then this initialization can be implemented by the following algorithm: for m = M down to m = 1 do: read lowrate input sample x
wm = x
(12.2.19)
12.2. INTERPOLATION FILTER DESIGN∗
645
Then, proceed by reading each successive lowrate sample, x(M + n), n = 0, 1, . . . , and processing it by the algorithm: for each lowrate input sample x do:
w0 = x for i = 0, 1, . . . , L − 1 compute: yi = dot(P, hi , w) delay(P, w)
(12.2.20)
12.2.3 Frequency Domain Characteristics Finally, we look in more detail at the passband and stopband characteristics of the ideal lowpass interpolation filter. Let T = 1/fs and T = 1/fs = T/L be the sampling time periods with respect to the low and high rates fs and fs . With reference to Fig. 12.1.2, let xa (t) be the output of the prefilter and let Xa (f ) be its bandlimited spectrum. The spectrum of the sampled lowrate signal x(n)= xa (nT), shown in Fig. 12.1.3, will be related to Xa (f ) by the Poisson summation formula:
X(f )=
n
x(n)e−2πjf nT =
∞
1
T
m=−∞
Xa (f − mfs )
The upsampled signal xup (n ) at the output of the Lfold rate expander of Fig. 12.2.1 has exactly the same spectrum as x(n), as indicated in Fig. 12.1.8. Indeed, using Eqs. (12.2.1) and (12.2.2) and T = LT , we have
Xup (f ) = =
n
xup (n )e−2πjf n T = −2πjf nT
xup (nL)e
n
=
xup (nL)e−2πjf nLT
n
n
x(n)e−2πjf nT = X(f )
Thus,
Xup (f )= X(f )=
∞
1
T
m=−∞
Xa (f − mfs )
(12.2.21)
The same relationship can be expressed in terms of the digital frequencies as:
Xup (ω )= X(ω)= X(ω L) where
ω=
2πf
fs
= 2πf T,
2πf
ω =
fs
= 2πf T ,
ω = ω L
and
Xup (ω )=
n
xup (n )e−jω n ,
X(ω)=
n
x(n)e−jωn
646
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
Similarly, using Eq. (12.2.13), their ztransforms will be related by
Xup (ζ)= X(z)= X(ζ L ) where the slow and fast z variables are related to the corresponding digital frequencies by
z = ejω = e2πjf /fs ,
ζ = ejω = e2πjf /fs = e2πjf /Lfs
If the analog signal xa (t) had actually been resampled at the higher rate fs giving rise to the sampled signal x (n )= xa (n T ), then the corresponding spectrum, depicted in Fig. 12.1.6, would be:
X (f )=
n
xa (n T )e−2πjf n T =
1
T
m
Xa (f − m fs )
(12.2.22)
The difference between x (n ) and xup (n ) is that x (n ) contains the correct interpolated values between lowrate samples, whereas the xup (n ) is zero there. In the time domain, the job of an ideal interpolation filter is to reproduce the interpolated samples correctly, that is, its output is required to be yup (n )= x (n ) for all n . In the frequency domain, its job is to reshape the lowrate sampled spectrum X(f ), shown in Fig. 12.1.8, into the highrate spectrum X (f ) shown in Fig. 12.1.6. Denoting the ideal interpolation filter by D(f ), we have for the spectrum of the output yup (n ):
Yup (f )= D(f )Xup (f )= D(f )X(f ) The filter output is required to be Yup (f )= X (f ), thus,
X (f )= D(f )X(f )
(ideal interpolation)
(12.2.23)
for all f . This condition determines the ideal passband and stopband specifications for D(f ). Using Eqs. (12.2.21) and (12.2.22) and separating out the central replica of X (f ) and the first L replicas of X(f ), we rewrite the above condition as 1
T
Xa (f )+replicas =
L− 1 1 Xa (f − mfs ) + replicas D(f )Xa (f ) + D(f ) m=1 &' ( T %T &' ( %
1
passband
stopband
Because Xa (f ) is bandlimited to within [−fs /2, fs /2], it follows that the L − 1 interme$L−1 diate replicas m=1 Xa (f − mfs ) will be bandlimited to within [fs /2, Lfs − fs /2]. The filter D(f ) is required to remove these replicas, that is,
D(f )= 0,
fs 2
≤ f  ≤ Lfs −
fs 2
as shown in Fig. 12.2.3. Similarly, within the lowrate Nyquist interval −fs /2 ≤ f ≤ fs /2, the filter must satisfy: 1
T
Xa (f )=
1
T
D(f )Xa (f )
⇒
D(f )=
T =L T
12.2. INTERPOLATION FILTER DESIGN∗
647
This justifies the choice L for the passband gain. In summary, the ideal digital inter polation filter D(f ) is defined as follows over the highrate Nyquist interval [−fs /2, fs /2]:
D(f )=
(ideal interpolator)
L, 0,
if f  ≤ if
fs 2
fs 2
< f  ≤
fs
(12.2.24)
2
and is periodically extended outside that interval. It is depicted in Figs. 12.1.9 and 12.2.3. Its impulse response is given by Eq. (12.2.6). The operation of the ideal interpolation filter, expressed by Eq. (12.2.23), can also be understood in the time domain in terms of the sampling theorem. The sampled analog signal x(n)= xa (nT) can be reconstructed to analog form by the analog reconstructor :
xa (t)=
n
xa (nT)h(t − nT)
where h(t) is the ideal reconstructor for the rate fs :
h(t)=
sin(πt/T)
(12.2.25)
πt/T
Resampling at the higher rate fs gives the sampled signal:
x (n )= xa (n T )=
n
xa (nT)h(n T − nT)=
n
xa (nLT )h(n T − nLT )
Denoting
d(k )= h(k T )=
sin(πk T /T)
πk T /T
=
sin(πk /L)
πk /L
(12.2.26)
and using xa (nLT )= xa (nT)= x(n), we obtain h(n T − nLT )= d(n − nL) and the filtering equation:
x (n )=
n
d(n − nL)x(n)=
m
d(n − m )xup (m )
which is recognized as the timedomain version of Eq. (12.2.23). In summary, the effect of the ideal interpolator in the frequency domain is shown in Fig. 12.2.6. The input spectrum consists of replicas at multiples of the input sampling rate fs . The filter removes all of these replicas, except those that are multiples of the output rate Lfs . The output spectrum consists only of replicas at multiples of Lfs . (The scaling by the gain L is not shown.)
12.2.4 Kaiser Window Designs Digital interpolation filters can be designed by a variety of filter design methods, such as the Fourier series method with windowing, ParksMcClellan, or IIR designs. Here we summarize FIR designs based on the Kaiser window method.
648
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
ideal interpolator X(f )
Xup(f )
L upsampler
rate fs
rate Lfs
Yup ( f ) = X′(f )
digital filter D(f )
rate Lfs output spectrum Yup (f )
input spectrum X(f)
0
fs
f
...
2fs
0
Lfs
fs
...
2fs
f Lfs
Fig. 12.2.6 Ideal interpolator in frequency domain.
We follow the design steps of Section 10.2, but use fs in place of fs , because the interpolation filter is operating at the fast rate fs . For any lengthN window w(n ), the interpolator’s impulse response is computed by
h(n )= w(n )d(n − LM),
n = 0, 1, . . . , N − 1 = 2LM
(12.2.27)
The L length(2M) polyphase subfilters are defined in terms of h(n ) as follows. For i = 0, 1, . . . , L − 1:
hi (n)= h(nL + i),
n = 0, 1, . . . , 2M − 1
(12.2.28)
For a Kaiser window design, we start by specifying the desired stopband attenuation
A in dB, and desired transition width ∆f about the ideal cutoff frequency: fc =
fs fs = 2L 2
so that the passband and stopband frequencies are:
fpass = fc −
1 ∆f , 2
fstop = fc +
1 ∆f 2
The Kaiser window parameters are calculated by:
δ = 10−A/20 D=
A − 7.95 14.36
α = 0.1102(A − 8.7) N−1≥
(because, typically, A > 50 dB)
(12.2.29)
Dfs DLfs DL = = ∆f ∆f ∆F
where we used fs in the formula for N and set ∆F = ∆f /fs . Then, N must be rounded up to the smallest odd integer of the form N = 2LM + 1 satisfying the above inequality. The design specifications are shown in Fig. 12.2.7. The designed lengthN impulse response is given by Eq. (12.2.27), with w(n ) given for n = 0, 1, . . . , N − 1:
12.2. INTERPOLATION FILTER DESIGN∗
w(n )=
649
I0 α 1 − (n − LM)2 /(LM)2 I0 α n (2LM − n )/LM = I0 (α) I0 (α)
The frequency response of the designed filter may be computed by:
H(f )=
N− 1
n =0
h(n )e−2πjf n /fs =
N− 1
h(n )e−2πjf n /(Lfs )
n =0
The designed filter h(n ) can be implemented in its direct or polyphase forms.
H( f) /L 1±δ
∆f
A
δ
fs′/2
fs′/2L
0
f
fs′
Fig. 12.2.7 Kaiser design specifications for Lfold interpolation filter.
12.2.5 Multistage Designs Interpolation filters can also be implemented in a multistage form, whereby the sampling rate is gradually increased in stages until the final rate is reached. This is shown in Fig. 12.2.8. The first filter increases the sampling rate by a factor of L0 , the second by a factor of L1 , and the third by L2 , so that the overall interpolation factor is L = L0 L1 L2 . Such multistage realizations allow additional savings in the overall computational rate of the interpolator.
L0 fs fs
L0
H0
L0 L1 fs
L1
H1
L2
H2
L0 L1 L2 f s
Fig. 12.2.8 Threestage interpolation filter.
The first filter H0 (f ) must have the most stringent specifications in the sense that it has the desired transition width ∆f , which is typically very narrow. The remaining stages have much wider transition widths and therefore smaller filter lengths. To see this, consider the design of a 4fold interpolator realized as the cascade of two 2fold interpolators, L = L0 L1 , with L0 = L1 = 2. The desired ideal frequency characteristics of the two interpolation filters are depicted in Fig. 12.2.9. The first interpolator H0 is operating at the intermediate rate fs = L0 fs = 2fs and is designed to act as an ideal lowpass filter with cutoff fc = fs /2 = fs /4. It removes all
650
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
H0
0
H0
H1
fs
2fs
H0
3fs
4fs
H0
5fs
6fs
7fs
f
8fs
∆f1 Fig. 12.2.9 Twostage 2×2 interpolation filter.
the replicas at multiples of its input rate fs , except those that are multiples of its output rate 2fs . It can be designed using a Kaiser window. For example, assuming a narrow transition width ∆f about fc , and a stopband attenuation A, we obtain from Eqs. (12.2.29):
N0 − 1 =
Dfs D(2fs ) 2D = = ∆f ∆f ∆F
where again ∆F = ∆f /fs . The second interpolator H1 is operating at the rate 2fs = 4fs , and must remove all replicas at multiples of its input rate 2fs , except those that are multiples of its output rate 4fs . Therefore, it has a wide transition width given by
∆f1 = fs − fs = 2fs − fs = fs Its Kaiser length will be:
N1 − 1 =
D(4fs ) D(4fs ) = = 4D ∆f1 fs
The combined effect of the two interpolation filters is to remove every three intervening replicas leaving only the replicas at multiples of 4fs . Because H0 is operating at rate 2fs and H1 at rate 4fs , the corresponding frequency responses will be:
H0 (f )=
N 0 −1
h0 (n )e−2πjf n /(2fs ) ,
H1 (f )=
n =0
N 1 −1
h1 (n )e−2πjf n /(4fs )
n =0
Assuming that both filters h0 (n ) and h1 (n ) are realized in their polyphase forms, the total computational rate of the multistage case will be, in MACs per second:
Rmulti = N0 fs + N1 (2fs )
2D + 8D fs = (1 + 4∆F)fs ∆F ∆F 2D
By contrast, a single stage design would have filter length:
N−1=
4D D(Lfs ) = ∆f ∆F
12.2. INTERPOLATION FILTER DESIGN∗
651
and polyphase computational rate:
Rsingle = Nfs
4D fs ∆F
The relative performance of the multistage versus the single stage designs will be 1 + 4∆F 1 Rmulti = = + 2∆F Rsingle 2 2
(12.2.30)
We note that this ratio is independent of the filter lengths and stopband attenuations; it depends only on the transition width. Computational savings will take place whenever: 1 + 2∆F < 1 2
∆F
50 dB)
Then, compute the effective transition widths for the interpolation filters:
∆f0 = ∆f ∆fi = Fi−1 fs − fs = (Fi−1 − 1)fs ,
(12.2.31)
i = 1, 2, . . . , K − 1
The theoretical cutoff frequencies of these filters will be:
fci =
Fi f s 1 = Fi−1 fs 2Li 2
⇒
ωci =
2πfci
Fi f s
=
π Li
for i = 0, 1, . . . , K − 1. In particular, fc0 = fs /2. For Kaiser designs, the above choices of widths imply the following passband and stopband frequencies for the filters. For i = 0, we have
fpass,0 = fc0 −
1 fs 1 ∆f0 = − ∆f , 2 2 2
fstop,0 = fc0 +
1 fs 1 ∆f0 = + ∆f 2 2 2
and for i = 1, 2, . . . , K − 1
fpass,i = fci −
1 fs ∆fi = , 2 2
fstop,i = fci +
1 fs ∆fi = Fi−1 fs − 2 2
Alternatively, we can demand that all filters have exactly the same passband frequency, namely, fs /2 − ∆f /2. This changes all the stopband frequencies by shifting them down by ∆f /2, that is, we can define for i = 1, 2, . . . , K − 1 † If the overall multistage output is reconstructed by a DAC and analog postfilter, then the second and later stages can have less attenuation than A0 because their suppression of the replicas will be aided by the postfilter. See Section 12.4.5.
654
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
fpass,i =
fs 2
−
1 ∆f , 2
fstop,i = Fi−1 fs −
fs
−
2
1 ∆f 2
Note that the transition widths remain the same, but the ideal cutoff frequencies also shift down by ∆f /2, that is, for i = 1, 2, . . . , K − 1
fci =
1 1 1 (fpass,i + fstop,i )= Fi−1 fs − ∆f 2 2 2
⇒
ωci =
2πfci
Fi fs
=
π ∆F −π Li Fi
where ∆F = ∆f /fs . The frequency characteristics of the first filter H0 are as shown in Fig. 12.2.7, with L = L0 . The specifications of the ith stage are shown in Fig. 12.2.11.
ith stage interpolator
Fi1 fs
Fi fs Li
Hi
∆fi
...
Ai
f 0
fpass,i
fci
Fi1 fs
2Fi1 fs
...
(Li 1) Fi1 fs
Li Fi1 fs = Fi fs
fstop,i
Fig. 12.2.11 Hi removes replicas at multiples of Fi−1 fs , but not at Fi fs .
The filter Hi removes all replicas at multiples of its input rate Fi−1 fs except those that are multiples of its output rate Fi fs . The replicas between the first replica and that at Fi−1 fs have already been removed by the previous stages; hence, the wide transition width ∆fi . The corresponding Kaiser filter lengths are:
N0 − 1 =
D0 L0 D0 (F0 fs ) = ∆f0 ∆F
Ni − 1 =
Di (Fi fs ) Di Fi , = ∆fi Fi−1 − 1
(12.2.32)
i = 1, 2, . . . , K − 1
where Ni must be rounded to the next smallest integer of the form:
Ni = 2Li Mi + 1,
i = 0, 1, . . . , K − 1
The windowed impulse responses of the filters will be, for i = 0, 1, . . . , K − 1
hi (n )= d(Li , n − Li Mi )w(αi , Ni , n ),
n = 0, 1, . . . , Ni − 1
where d(Li , k ) is the ideal interpolation filter with cutoff frequency† ωci = π/Li † For
the alternative case, replace ωci by its shifted version ωci = π/Li − π∆F/Fi .
12.2. INTERPOLATION FILTER DESIGN∗
d(Li , k )=
655
sin(ωci k )
ωci k
=
sin(πk /Li )
πk /Li
and w(αi , Ni , n ) is the corresponding Kaiser window:
w(αi , Ni , n )=
I0 αi 1 − (n − Li Mi )2 /(Li Mi )2 I0 (αi )
The polyphase subfilters of each Hi are defined by
hij (n)= h(nLi + j),
j = 0, 1, . . . , Li − 1,
n = 0, 1, . . . , Pi
where Pi = 2Mi − 1. Finally, compute the frequency responses of the individual stages:
Hi (f )=
N i −1
hi (n )e−2πjf n /(Fi fs ) ,
i = 0, 1, . . . , K − 1
n =0
and the total frequency response:
Htot (f )= H0 (f )H1 (f )· · · HK−1 (f ) Note that the effective passband ripple of the combined filter Htot (f ) is worse than the ripples of the individual factors. This can be seen as follows. In the passband frequency range, the individual filters satisfy
Hi (f ) ≤ 1 + δi L
1 − δi ≤
i
where the DC gain Li has been factored out. Multiplying these inequalities together, we obtain the bounds:
+1 H0 (f )H1 (f )· · · HK−1 (f ) K− ≤ (1 − δi )≤ (1 + δi ) L0 L1 · · · LK−1 i=0 i=0
K− +1
For small δi we may use the approximation K− +1 i=0
(1 ± δi ) 1 ±
K− 1
δi
i=0
to get the total passband ripple of the cascaded filter
Htot (f ) ≤ 1 + δtot , L
1 − δtot ≤
where δtot =
K− 1
δi
i=0
For equal ripples δi = δ and K stages, we have δtot = Kδ. If so desired, this effect can be compensated by starting the design of the Hi (f ) using δi ’s that are smaller by a factor of K. It should be noted, however, that this may not always be necessary because the individual filters may not reach their extremum values simultaneously over
656
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
the passband, and therefore the bounds (1 ± δtot ) may be too conservative. This is illustrated in the design examples later. Also, in Kaiser window designs, it is the stopband attenuation A that essentially determines the passband ripples. In order to achieve reasonably high stopband attenuations, for example, in the range 70100 dB, the corresponding passband ripples will be so small that even if they are multiplied by any K of the order of 10, they will still give rise to excellent passbands. The total polyphase computational rate in MACs per second is obtained by adding up the computational rates of all the stages, that is,
Rmulti =
K− 1
Ri ,
where
i=0
Ri = Ni Fi−1 fs ,
i = 0, 1, . . . , K − 1
These follow from the observation that the ith filter operates at rate Fi fs and would have computational rate Ni Fi fs in its direct form. But in its polyphase form we save a factor of Li , resulting in the rate Ni Fi fs /Li = Ni Fi−1 fs . By comparison, the singlestage design will have Kaiser length and polyphase computational rate:
N−1=
DL D(Lfs ) = , ∆f ∆F
Rsingle = Nfs
where we may take A = A0 for the stopband attenuation and D = D0 . It follows that the relative performance of multistage versus single stage designs will be:
N0 + Rmulti = Rsingle
$K−1 i=1
Ni Fi−1
(12.2.33)
N
Assuming that all the attenuations are the same, Ai = A, and therefore all the Di are the same, we may use the approximations:
N0
DL0 , ∆F
Ni
DFi , Fi−1 − 1
N
DL ∆F
to obtain the simplified expression: K− 1 Fi Fi−1 Rmulti L0 + ∆F = Rsingle L (Fi−1 − 1)L i=1
(12.2.34)
For a twostage design with L = L0 L1 , F1 = L, and F0 = L0 , we have
L0 F1 F0 1 L0 Rmulti = + ∆F = + ∆F Rsingle L (F0 − 1)L L1 L0 − 1 Setting L0 = L1 = 2, or L0 = 2, L1 = 4, or L0 = 4, L1 = 2, we recover the results obtained previously for the 2×2, 2×4, and 4×2 cases. The condition that the multistage form be more efficient than the singlestage one is: 1
L1
+
L0 ∆F < 1 L0 − 1
1 1 ∆F < 1 − 1− L0 L1
12.3. LINEAR AND HOLD INTERPOLATORS∗
657
Given this condition, then the most efficient ordering of the two filters is to place first the filter with the smaller oversampling ratio. For example, assuming L0 < L1 then the ordering H0 H1 is more efficient than H1 H0 because 1
L1
+
L0 1 L1 ∆F < + ∆F < 1 L0 − 1 L0 L1 − 1
For a threestage design with F0 = L0 , F1 = L0 L1 , and F2 = L0 L1 L2 = L, we find
Rmulti F1 F0 L0 F2 F1 1 L0 L1 L0 = + ∆F + = + ∆F + Rsingle L (F0 − 1)L (F1 − 1)L L1 L2 L2 (L0 − 1) L0 L1 − 1
Setting L0 = L1 = L2 = 2, we recover the results of the 2×2×2 case. Because the designed filter lengths Ni are slightly larger than those given by the Kaiser formulas, the correct relative computational rate should be computed using Eq. (12.2.33), whereas Eq. (12.2.34) gives only an approximation.
12.3 Linear and Hold Interpolators∗ We saw in Section 12.2.3 that the ideal interpolator may be thought of as the sampled version of the ideal analog reconstructor, sampled at the high rate fs , that is,
d(k )= h(k T )
(12.3.1)
This relationship can be applied to other analog reconstructors, resulting in simpler interpolators. For any analog reconstructor h(t) that reconstructs the lowrate samples by
ya (t)=
h(t − mT)x(m)
m
we can obtain the interpolated samples by resampling ya (t) at the high rate fs :
ya (n T )=
h(n T − mT)x(m)
m
which can be written in the form
yup (n )=
m
d(n − mL)x(m)
(12.3.2)
where d(k ) is obtained from h(t) via Eq. (12.3.1). The interpolation equation can be written also in terms of the upsampled version of x(n)
yup (n )=
m
d(n − m )xup (m )=
k
d(k )xup (n − k )
(12.3.3)
Two of the most common interpolators are the hold and linear interpolators resulting from the sample/hold and linear analog reconstructors having impulse responses:
h(t)=
1, 0,
if 0 ≤ t < T otherwise
and h(t)=
1− 0,
t , T
if t ≤ T otherwise
658
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
They are shown in Fig. 12.3.1. Setting t = k T in these definitions, and using the relationship T = LT , we find the following discretetime versions: (hold)
(linear)
d(k )=
1, 0,
if 0 ≤ k ≤ L − 1 otherwise
1−
k  , L
d(k )=
0,
= u(k )−u(k − L)
if k  ≤ L − 1 otherwise
Note that in the linear case, the endpoints k = ±L are not considered because d(k ) vanishes there. Figure 12.3.1 shows the sampled impulse responses for L = 8.
h(t)
T
0
h(t)
1
1
t
T
T
0
T′=T/8
t
T′=T/8
Fig. 12.3.1 Hold and linear interpolator impulse responses for L = 8.
The filtering operations of these interpolators are very simple. The hold interpolator holds each lowrate sample constant for L highrate sampling times. In other words, each lowrate sample is repeated L times at the high rate. The linear interpolator interpolates linearly between a given lowrate sample and the next one. To see this, we rewrite the filtering equation (12.3.3) in its polyphase form. As we argued for Eq. (12.2.12), we set n = nL + i and k = kL + j and use the fact that xup (nL + i − kL − j)= 0, if i = j, to get
yup (nL + i)=
k
di (k)x(n − k)
(12.3.4)
where di (k) are the corresponding polyphase subfilters:
di (k)= d(kL + i),
i = 0, 1, . . . , L − 1
The summation over k must be determined for each case. In the hold case, we have the restriction on k: 0 ≤ k ≤ L − 1
⇒
0 ≤ kL + i ≤ L − 1
⇒
0≤k≤1−
1+i
L
Because 0 ≤ i ≤ L − 1, the only allowed value of k in that range is k = 0. Similarly, in the linear case, we have:
k  ≤ L − 1
⇒
kL + i ≤ L − 1
⇒
−1 +
1−i
L
≤k≤1−
1+i
L
The only possible integer value in the lefthand side is k = −1, which is realized when i = 1, and the only integer value of the righthand side is k = 0. Therefore, the polyphase subfilters are in the two cases:
12.3. LINEAR AND HOLD INTERPOLATORS∗
(hold) (linear)
659
di (k)= di (0)δ(k) di (k)= di (0)δ(k)+di (−1)δ(k + 1)
where for the hold case, we have:
di (0)= d(i)= u(i)−u(i − L)= 1 − 0 = 1 and for the linear case:
di (0) = d(i)= 1 −
i i =1− L L
di (−1) = d(−L + i)= 1 −
L−i i i − L =1− = L L L
Thus, the polyphase subfilters are: (hold) (linear)
di (k)= δ(k) i i δ(k)+ δ(k + 1) di (k)= 1 − L L
(12.3.5)
for i = 0, 1, . . . , L − 1. Inserting these impulse responses in Eq. (12.3.4), we find the interpolation equations in the two cases. For the hold case:
yup (nL + i)= x(n) ,
i = 0, 1, . . . , L − 1
(12.3.6)
Thus, each lowrate sample is repeated L times. For the linear case we have:
i i yup (nL + i)= 1 − x(n)+ x(n + 1) , L L
i = 0, 1, . . . , L − 1
(12.3.7)
They correspond to linearly weighting the two successive lowrate samples x(n) and x(n + 1). For example, when L = 8 the eight interpolated samples between x(n) and x(n + 1) are calculated by:
yup (8n) = x(n) yup (8n + 1) = 0.875 x(n)+ 0.125 x(n + 1) yup (8n + 2) = 0.750 x(n)+ 0.250 x(n + 1) yup (8n + 3) = 0.625 x(n)+ 0.375 x(n + 1) yup (8n + 4) = 0.500 x(n)+ 0.500 x(n + 1) yup (8n + 5) = 0.375 x(n)+ 0.625 x(n + 1) yup (8n + 6) = 0.250 x(n)+ 0.750 x(n + 1) yup (8n + 7) = 0.125 x(n)+ 0.875 x(n + 1)
660
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
Figure 12.3.2 shows the interpolated signal using 8fold hold and linear interpolators. To understand the frequency domain properties of the hold and linear interpolators and the extent to which they differ from the ideal interpolator, we compute their highrate ζ transforms using Eq. (12.2.15). For the hold case, taking the lowrate ztransform of di (k) given in Eq. (12.3.5), we find
xup(8n8)
hold xup(8n+8)
xup(8n)
8n8 xup(8n8)
n′
8n+8
8n linear
xup(8n+8)
xup(8n)
8n8
8n
n′
8n+8
Fig. 12.3.2 8fold hold and linear interpolators.
⇒
Di (z)= 1
Di (ζ L )= 1
Then, it follows from Eq. (12.2.15)
D(ζ)=
L− 1
ζ −i Di (ζ L )=
i=0
L− 1 i=0
ζ −i =
1 − ζ −L 1 − ζ −1
(12.3.8)
Setting ζ = ejω = e2πjf /fs = e2πjf /Lfs we obtain the frequency response of the hold interpolator:
D(f ) = =
1 − e−jLω sin(Lω /2) −j(L−1)ω /2 e = −jω 1−e sin(ω /2) sin(πf /fs ) −jπ(L−1)f /Lfs e sin(πf /Lfs )
Similarly, the lowrate ztransform of di (k) for the linear case is:
Di (z)= 1 −
i i + z L L
Di (ζ L )= 1 +
⇒
i (ζ L − 1) L
From Eq. (12.2.15) we find:
D(ζ)=
L− 1 i=0
ζ −i Di (ζ L )=
L− 1 i=0
ζ −i +
L−1 ζ L − 1 −i iζ L i=0
(12.3.9)
12.4. DESIGN EXAMPLES∗
661
and using the identity: L− 1 i=0
iζ −i =
Lζ −L (1 − ζ −L )ζ −1 − − 1 2 (1 − ζ ) 1 − ζ −1
we obtain (see also Problem 5.11):
D(ζ)=
1 1 (1 − ζ −L )(1 − ζ L ) = L (1 − ζ −1 )(1 − ζ) L
1 − ζ −L 1 − ζ −1
2
ζ L−1
which leads to the frequency response:
D(f )=
2 1 sin(Lω /2) = 1 L sin(ω /2) L
sin(πf /f ) 2 s sin(πf /Lfs )
(12.3.10)
Both responses (12.3.9) and (12.3.10) are periodic in f with period fs = Lfs and vanish at all multiples of fs which are not multiples of Lfs . Therefore, they partially remove the spectral replicas that are between multiples of fs . They are shown in Fig. 12.3.3 for the case L = 8, together with the ideal response. Because of their simple structure, linear and hold interpolators are used in multistage implementations of interpolators, especially in the latter stages that have higher sampling rates. Some example designs are discussed in Section 12.4.5.
ideal interpolator
D( f )
8
hold interpolator linear interpolator
0
fs
2fs
3fs
4fs
5fs
6fs
7fs
8fs
f
Fig. 12.3.3 Hold and linear interpolator frequency responses for L = 8.
12.4 Design Examples∗ 12.4.1 4fold Interpolators Consider the case of a 4fold interpolator having L = 4 and polyphase filter length 2M = 4 or M = 2. This corresponds to a filter length N = 2LM + 1 = 17. The ideal impulse response will be:
d(k )=
sin(πk /4) , πk /4
−8 ≤ k ≤ 8
662
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
or, numerically,
h = d = [0, −0.13, −0.21, −0.18, 0, 0.30, 0.64, 0.90, 1, 0.90, 0.64,
(12.4.1)
0.30, 0, −0.18, −0.21, −0.13, 0]
where h is the causal version, with time origin shifted to the left of the vector, and d is the symmetric one with time origin at the middle of the vector. This truncated ideal impulse response is shown in Fig. 12.4.1. The four polyphase subfilters are defined by Eq. (12.2.10), that is, for i = 0, 1, 2, 3,
d(k′) 1 0.90
0.90
0.64
L=4, M=2, N=17
0.64
0.30
0.30
8 7 6 5 0.13 0.21
5 6 7 8
4 3 2 1 0 1 2 3 4 0.18 0.18
k′
0.13 0.21
Fig. 12.4.1 Length17 symmetric impulse response of 4fold FIR interpolator.
di (k)= d(4k + i),
−2 ≤ k ≤ 1
They are extracted from h by taking every fourth entry, starting with the ith entry: h0 = d0 = [0, 0, 1, 0] h1 = d1 = [−0.13, 0.30, 0.90, −0.18]
(12.4.2)
h2 = d2 = [−0.21, 0.64, 0.64, −0.21] h3 = d3 = [−0.18, 0.90, 0.30, −0.13]
The interpolated samples between x(n)= xup (4n) and x(n + 1)= xup (4n + 4) are calculated from Eqs. (12.2.18). All four subfilters act on the timeadvanced lowrate input samples {x(n + 2), x(n + 1), x(n), x(n − 1)}, or, {xup (4n + 8), xup (4n + 4), xup (4n), xup (4n − 4)}. Equations (12.2.12) can be cast in a compact matrix form:
yup (4n) y (4n + 1) up yup (4n + 2) yup (4n + 3)
0
−0.13 = −0.21 −0.18
0 0.30 0.64 0.90
1 0.90 0.64 0.30
0 −0.18 −0.21 −0.13
xup (4n + 8) x (4n + 4) up xup (4n) xup (4n − 4)
(12.4.3)
These results can be understood more intuitively using the LTI form of convolution, that is, superimposing the full length17 symmetric impulse response d at the four contributing lowrate samples and summing up their contributions at the four desired time instants, that is, at n = 4n + i, i = 0, 1, 2, 3. This is illustrated in Fig. 12.4.2.
12.4. DESIGN EXAMPLES∗
663
xup(4n)
xup(4n4)
yup(4n+1) xup(4n+4) xup(4n+8)
n′ 4n4
4n+4
4n
4n+8
Fig. 12.4.2 LTI form of convolution by superposition of FIR impulse responses.
For example, referring to the impulse response values indicated on Fig. 12.4.1, we find that at time instant 4n + 1, the input sample xup (4n + 8) will contribute an amount −0.13xup (4n + 8), the sample xup (4n + 4) will contribute an amount 0.30xup (4n + 4), the sample xup (4n) will contribute 0.90xup (4n), and the sample xup (4n− 4) an amount −0.18xup (4n − 4). The interpolated value is built up from these four contributions:
yup (4n + 1)= −0.13xup (4n + 8)+0.30xup (4n + 4)+0.90xup (4n)−0.18xup (4n − 4) Similarly, it should be evident from Fig. 12.4.2 that yup (4n)= xup (4n), with the contributions of the other lowrate inputs vanishing at time instant 4n. We may also use the flipandslide form of convolution, in which the impulse response d(k ) is flipped, delayed, and positioned at the sampling instant n to be computed. For example, at n = 4n + 1, we have:
yup (4n + 1)=
k
d(4n + 1 − k )xup (k )
Figure 12.4.3 shows this operation. Because of symmetry, the flipped impulse response is the same as that in Fig. 12.4.1. It is then translated to n = 4n + 1 and the above linear combination is performed.
xup(4n)
xup(4n4)
0.90
flipped/shifted d(4n+1−k′) = impulse response xup(4n+4) xup(4n+8)
0.30
0.18
4n 4n+4 4n+1
k′ 0.13
Fig. 12.4.3 Flipandslide form of convolution.
The only contributions come from the lowrate samples that fall within the finite extent of the impulse response. Thus, only the terms k = 4n − 4, 4n, 4n + 4, 4n + 8
664
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
contribute, and each is weighted by the appropriate impulse response values that are read off from the figure, that is, {−0.18, 0.90, 0.30, −0.13}, so that again:
yup (4n + 1)= −0.18xup (4n − 4)+0.90xup (4n)+0.30xup (4n + 4)−0.13xup (4n + 8) The Hamming windowed version of the filter is obtained by multiplying the full length17 filter response h by a length17 Hamming window. The resulting impulse response becomes: h = [0, −0.02, −0.05, −0.07, 0, 0.22, 0.55, 0.87, 1, 0.87, 0.55, 0.22, 0,
− 0.07, −0.05, −0.02, 0] The polyphase interpolation equations become in this case:
yup (4n) y (4n + 1) up yup (4n + 2) yup (4n + 3)
0
−0.02 = −0.05 −0.07
0 0.22 0.55 0.87
1 0.87 0.55 0.22
0 −0.07 −0.05 −0.02
xup (4n + 8) x (4n + 4) up xup (4n) xup (4n − 4)
The graphs in Fig. 12.4.4 compare the magnitude responses of the rectangularly and Hamming windowed interpolation filters. A block diagram realization of the polyphase form for this example is shown in Fig. 12.4.5. It is based on Eqs. (12.2.14) and (12.2.15), that is,
Fig. 12.4.4 Magnitude response H(ω ) versus ω = 2πf /fs .
H(ζ) = H0 (ζ 4 )+ζ −1 H1 (ζ 4 )+ζ −2 H2 (ζ 4 )+ζ −3 H3 (ζ 4 ) = H0 (z)+z−1/4 H1 (z)+z−2/4 H2 (z)+z−3/4 H3 (z) with all the subfilters using the same tapped delay line holding the incoming lowrate samples. The block diagram is equivalent to the commutator model of Fig. 12.2.5. The polyphase subfilters are defined by: hi = [hi0 , hi1 , hi2 , hi3 ],
Hi (z)= hi0 + hi1 z−1 + hi2 z−2 + hi3 z−3
12.4. DESIGN EXAMPLES∗
665 h00
lowrate input
h01 h02
x(n+2)
y0(n)
h03
z 1
h10 h11
x(n+1)
h12
y1(n)
z 1/4 highrate output
h13
z 1
h20 h21
x(n)
h22
yup(n′) y2(n)
z 2/4
h23
z
1
h30 h31
x(n1)
h32
y3(n)
z 3/4
h33
Fig. 12.4.5 Polyphase realization of 4fold interpolator.
for i = 0, 1, 2, 3, where hi are given by Eq. (12.4.2). The possibility of a parallel multiprocessor implementation is evident from this diagram. The four outputs of the filters Hi (z) are produced simultaneously in a parallel implementation, but they are not sent to the overall output simultaneously. During each lowrate sampling period T, the sample y0 (n) is sent out first, then T/4 seconds later (represented by the delay z−1/4 ) the second computed interpolated sample y1 (n) is sent out, another T/4 seconds later the third sample y2 (n) is sent out, and T/4 seconds after that, the fourth interpolated sample y3 (n) is sent out. As a concrete filtering example, consider the following lowrate input signal x(n) consisting of 25 DC samples, and depicted in Fig. 12.4.6 with respect to the fast time scale:
x(n)= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} The interpolated values between these lowrate samples are shown in Fig. 12.4.7 for the cases of the rectangularly and Hamming windowed interpolating filters. They were computed by the polyphase sample processing algorithm of Eq. (12.2.20). The inputon and inputoff transients are evident. As another example, consider the case of L = 4 and M = 12, that is, interpolation filter length N = 2LM + 1 = 97. This is a more realistic length for typical 4fold oversampling digital filters used in CD players. The corresponding rectangularly and Hamming windowed magnitude responses are shown in Fig. 12.4.8. The interpolated
666
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
Fig. 12.4.6 Lowrate input samples xup (n ).
Fig. 12.4.7 Highrate interpolated output samples yup (n ).
output signals from these two filters are shown in Fig. 12.4.9 for the same lowrate input signal x(n). Note the longer inputon and inputoff transients.
Fig. 12.4.8 Magnitude responses of length97 interpolation filters.
12.4. DESIGN EXAMPLES∗
667
Fig. 12.4.9 Highrate interpolated outputs yup (n ).
12.4.2 Multistage 4fold Interpolators Here, we follow the discussion of Section 12.2.5 and design multistage and single stage digital interpolation filters using the Kaiser window method. Such filters may be used as oversampling digital filters in CD players.† We take L = 4 for the oversampling ratio, and assume a nominal digital audio sam pling rate of fs = 40 kHz, so that the fast rate will be fs = Lfs = 4 × 40 = 160 kHz. We take the transition width to be ∆f = 5 kHz about the ideal cutoff frequency fc = fs /(2L)= fs /2 = 20 kHz. Therefore, the passband and stopband frequencies of the filter will be
fpass = 20 −
5 = 17.5 kHz, 2
fstop = 20 +
5 = 22.5 kHz 2
and the normalized transition width
∆F =
5 ∆f = 0.125 = fs 40
The stopband attenuation is taken to be A = 80 dB, which gives rise to a passband/stopband ripple δ = 10−4 , passband attenuation Apass = 0.0017 dB, and the following values for the Kaiser window parameters D and α:
D=
A − 7.95 = 5.017, 14.36
α = 0.1102(A − 8.7)= 7.857
For a 2×2 multistage design, shown in Fig. 12.4.10, we may use the general design equations (12.2.31) and (12.2.32) to find the Kaiser lengths of the two filters H0 and H1 :
N0 − 1 =
2D DL0 = = 80.27, ∆F ∆F
N1 − 1 =
DF1 = 4D = 20.07 F0 − 1
which get rounded up to the values: † See
Ref. [282] for actual DSP chips with comparable design characteristics.
668
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
fs 2
H0
4fs
2fs 2
H1 yup(n′)
x(n)
Fig. 12.4.10 2×2 = 4fold oversampling filter.
N0 = 85 = 2L0 M0 + 1 = 4M0 + 1
⇒
M0 = 21
N1 = 25 = 2L1 M1 + 1 = 4M1 + 1
⇒
M1 = 6
The magnitude response of the filter H0 (f ) in dB and a typical lowrate sinusoidal input to be interpolated are shown in Fig. 12.4.11. The 2fold interpolated output of H0 (f ) is shown in Fig. 12.4.12. It serves as the input to the next filter H1 (f ) whose magnitude response is also shown in Fig. 12.4.12.
Fig. 12.4.11 Filter H0 (f ) and its lowrate input signal.
Fig. 12.4.12 Filter H1 (f ) and its input which is the output of H0 (f ).
12.4. DESIGN EXAMPLES∗
669
The 2fold interpolated output of H1 (f ) will be the final 4fold interpolated output. It is shown in Fig. 12.4.13 together with the superimposed plots of the filters H0 (f ) and H1 (f ). In these figures, the frequency responses have been normalized by their DC values, that is, H0 (f )/L0 , H1 (f )/L1 . Finally, we compare the multistage design to an equivalent single stage Kaiser design. In this case the Kaiser filter length will be
N−1=
4D = 160.56 ∆F
which is rounded up to the value
N = 169 = 2LM + 1 = 8M + 1
⇒
M = 21
Its magnitude response H(f ) is shown in Fig. 12.4.14 together with the magnitude response of the combined multistage filter Htot (f )= H0 (f )H1 (f ). Again, we have normalized them to their DC values, namely, H(f )/L, and Htot (f )/L.
Fig. 12.4.13 Filters H0 (f ), H1 (f ) and the overall interpolated output.
Fig. 12.4.14 Multistage filter H0 (f )H1 (f ) and singlestage filter H(f ).
670
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
The multistage realization requires only 80 percent of the computational rate of the singlestage design. Indeed, the relative computational rate of the multistage versus the single stage designs is given according to Eq. (12.2.33) by:
N0 + N1 F0 85 + 25 · 2 Rmulti = = = 0.80 Rsingle N 169 which compares well with the approximate result of Eq. (12.2.30).
Rmulti 1 = + 2∆F = 0.5 + 2 · 0.125 = 0.75 Rsingle 2 Finally, as we saw earlier, the passband of the total filter Htot (f )= H0 (f )H1 (f ) tends to be worse than the passbands of the individual factors. Let δ be the common passband ripple, as calculated from Eq. (12.2.29). Then, the two individual filters will satisfy within their passbands:
H0 (f ) ≤ 1 + δ, L
1−δ≤
0
H1 (f ) ≤1+δ L
1−δ≤
1
Multiplying the two inequalities, we find for the total filter
H0 (f )H1 (f ) ≤ (1 + δ)2 (1 − δ)2 ≤ L0 L1
or, approximately if δ is small,
Htot (f ) ≤ 1 + 2δ L
1 − 2δ ≤
Thus, the passband ripple is effectively doubled, δtot = 2δ. Taking logs of both sides, we obtain the following bounds for the passband attenuations in dB:
H0 (f ) ≤ 8.7δ, −8.7δ ≤ 20 log10 L 0
H1 (f ) ≤ 8.7δ − 8.7δ ≤ 20 log10 L 1 Htot (f ) ≤ 8.7(2δ) −8.7(2δ)≤ 20 log10 L
where we used the smallδ approximation:
20 log10 (1 + δ) 8.7δ Figure 12.4.15 shows a magnified plot of the passband region of the individual and total filters for the above designs, with the passband bounds placed on the figure. It is evident that the actual passband ripple of Htot (f ) is less than the worstcase ripple δtot = 2δ.
12.4. DESIGN EXAMPLES∗
671
Fig. 12.4.15 Magnified passband of 2×2 interpolator.
12.4.3 DAC Equalization In an oversampling DSP system, the interpolator output samples are reconstructed by a staircase D/A converter operating at the high rate fs = Lfs . Its frequency response (normalized to unity gain at DC) is
Hdac (f )=
sin(πf /fs )
πf /fs
e−jπf /fs
It causes some attenuation within the Nyquist interval, with maximum of about 4 dB at the Nyquist frequency fs /2. For an Lfold interpolation filter which has cutoff at fc = fs /2 = fs /2L, the maximum attenuation within the filter’s passband will be:
sin(πf /f ) sin(π/2L) c s = Hdac (fc ) = πfc /fs π/2L
(12.4.4)
For large values of the oversampling ratio L, this attenuation is insignificant, approaching 0 dB. Thus, one of the benefits of oversampling is that the aperture effect of the DAC can be neglected. However, for smaller values of L (for example, L ≤ 8) it may be desirable to compensate this attenuation by designing the interpolation filter to have an inverse shape to the sin x/x DAC response over the relevant passband range. The desired equalized ideal interpolation filter can then be defined by the following equation, replacing Eq. (12.2.24):
D(f )=
LDeq (f ),
if f  ≤
0,
if
fs 2
fs 2
< f  ≤
fs
(12.4.5)
2
where Deq (f ) is essentially the inverse response 1/Hdac (f ) with the phase removed in order to keep D(f ) real and even in f :
Deq (f )=
πf /fs , sin(πf /fs )
f  ≤
fs 2
(12.4.6)
672
12. INTERPOLATION, DECIMATION, AND OVERSAMPLING
In units of the highrate digital frequency ω = 2πf /fs , Eq. (12.4.5) becomes:
ω /2 L , sin(ω /2) D(ω )= 0,
π L π if < ω  ≤ π L
if ω  ≤
(12.4.7)
Such a filter can be designed by the frequency sampling design method of Section 10.3. If the filter order is known, say N = 2LM + 1, then we can compute the desired filter weights by the inverse Npoint DFT:
# )= 1 d(k N
LM
D(ωi )ejωi k ,
i=−LM
−LM ≤ k ≤ LM
(12.4.8)
where ωi are the N DFT frequencies spanning the symmetric Nyquist interval [−π, π]:
ωi =
2πi
N
−LM ≤ i ≤ LM
,
The designed causal windowed filter will be
# − LM)w(n ), h(n )= d(n
0 ≤ n ≤ N − 1
(12.4.9)
In the Hamming window case, we must assume a desired value for N. In the Kaiser case, we may start with a desired stopband attenuation A and transition width ∆f , and then determine the filter length N and the window parameter α. Because the filter is sloping upwards in the passband, to achieve a true attenuation A in the stopband, we may have to carry out the design with a slightly larger value of A. This is illustrated in the examples below. # ) and D(ω ) are realvalued, we may replace the rightNote also that because d(k hand side of Eq. (12.4.8) by its real part and write it in the cosine form:
# )= 1 d(k N
LM
D(ωi )cos(ωi k ),
−LM ≤ k ≤ LM
i=−LM
and because D(ω ) is even in ω
LM
# )= 1 D(ω0 )+2 D(ωi )cos(ωi k ) , d(k
N
i=1
−LM ≤ k ≤ LM
where D(ω0 )= D(0)= L. This expression can be simplified even further by noting that D(ωi ) is nonzero only for 0 < ωi