Uploaded by Eduardo Fernandes

Vinay K. Ingle, John G. Proakis - Digital Signal Processing using MATLAB, 2nd Edition -Cengage Learning (2007)

advertisement
BookWare Companion SeriesTM
Digital Signal Processing
®
Using MATLAB
International Student Edition
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
About the BookWare Companion SeriesTM
R
Expanding Student Learning with MATLAB
The Cengage Learning BookWare Companion SeriesTM promotes problem solving and critical thinking by
R
using MATLAB
as a “virtual laboratory.” The books in this series encourage active learning and
•
•
•
Provide powerful software tools to support course activities
Demonstrate clear, step-by-step techniques for solving relevant problems
Challenge readers to understand and apply these techniques on their own
The BookWare Companion SeriesTM spans the Electrical Engineering curriculum and includes nationally
and world-renowned authors. Books in the series include:
R
Chapman: Essentials of MATLAB
Programming
R
Programming for Engineers 3e
Chapman: MATLAB
R
Djaferis: Automatic Control: The Power of Feedback Using MATLAB
R
Frederick/Chow: Feedback Control Problems Using MATLAB
and the Control System Toolbox
R
R
and SIMULINK
Gardner: Simulations of Machines Using MATLAB
R
Ingle/Proakis: Digital Signal Processing Using MATLAB
2e
R
Pfeiffer: Basic Probability Topics Using MATLAB
R
R
Proakis/Salehi/Bauch: Contemporary Communications Systems Using MATLAB
and SIMULINK
Rashid: Electronics Circuit Design Using ELECTRONICS WORKBENCH
R
Schetzen/Ingle: Discrete Systems Laboratory Using MATLAB
R
Stonick/Bradley: Labs for Signals and Systems Using MATLAB
R
Strum/Kirk: Contemporary Linear Systems Using MATLAB
To learn more about Cengage Learning’s Engineering books, visit our Web site at
www.cengage.com/engineering
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
BookWare Companion SeriesTM
Digital Signal Processing
®
Using MATLAB
Second Edition
Vinay K. Ingle
John G. Proakis
Northeastern University
Australia
• Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
This is an electronic version of the print textbook. Due to electronic rights restrictions, some third party content may
be suppressed. Editorial review has deemed that any suppressed content does not materially affect the overall
learning experience. The publisher reserves the right to remove content from this title at any time if subsequent
restrictions require it. For valuable information on pricing, previous editions, changes to current editions,and
alternate formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Digital Signal Processing Using MATLAB®,
Second Edition
Vinay K. Ingle and John G. Proakis
Director, Global Engineering Program:
Chris Carson
Senior Developmental Editor:
Hilda Gowans
Developmental Editor: Kamilah
Reid Burrell
Marketing Services Coordinator:
Lauren Bestos
Production Service: RPK Editorial Services
Copyeditor: Harlan James
© 2007 Cengage Learning
ALL RIGHTS RESERVED. No part of this work covered by the copyright
herein may be reproduced, transmitted, stored, or used in any form or by
any means—graphic, electronic, or mechanical, including but not limited
to photocopying, recording, scanning, digitizing, taping, Web distribution,
information networks, information storage and retrieval systems, or in any
other manner—except as may be permitted by the license terms herein.
For product information and technology assistance, contact us at
Cengage Learning Customer & Sales Support, 1-800-354-9706.
For permission to use material from this text or product,
submit all requests online at www.cengage.com/permissions.
Further permissions questions can be emailed to
permissionrequest@cengage.com.
Proofreader: Erin Wagner
Indexer: RPK Editorial Services
Library of Congress Control Number: 2006904405
Compositor: International Typesetting
and Composition
U.S. Student Edition:
ISBN-13: 978-0-495-07311-6
ISBN-10: 0-495-07311-3
Senior Art Director: Michelle Kunkler
Internal Designer: Carmela Pereira
Cover Designer: Andrew Adams
Text Permissions Researcher: Vicki Gould
Senior First Print Buyer: Doug Wilke
Cengage Learning
200 First Stamford Place, Suite 400
Stamford, CT 06902
USA
Cengage Learning is a leading provider of customized learning solutions
with office locations around the globe, including Singapore, the United
Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office
at: www.cengage.com/global.
Cengage Learning products are represented in Canada
by Nelson Education Ltd.
For your course and learning solutions,
visit www.cengage.com/engineering.
Purchase any of our products at your local college store or at our preferred
online store www.ichapters.com.
Printed in the United States of America
2 3 4 5 6 11 10 09 08
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Contents
PREFACE
1
xi
INTRODUCTION
1
Overview of Digital Signal Processing
A Few Words about MATLAB®
2
2
6
DISCRETE-TIME SIGNALS AND SYSTEMS
Discrete-time Signals
Discrete Systems
Convolution
7
20
22
Difference Equations
Problems
7
29
34
v
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3
THE DISCRETE-TIME FOURIER ANALYSIS
The Discrete-time Fourier Transform (DTFT)
The Properties of the DTFT
40
40
47
The Frequency Domain Representation of LTI Systems
Sampling and Reconstruction of Analog Signals
Problems
4
The Bilateral z -Transform
80
80
Important Properties of the z -Transform
Inversion of the z -Transform
84
89
System Representation in the z -Domain
Solutions of the Difference Equations
5
95
105
111
THE DISCRETE FOURIER TRANSFORM
The Discrete Fourier Series
The Discrete Fourier Transform
Linear Convolution Using the DFT
Problems
126
131
Properties of the Discrete Fourier Transform
The Fast Fourier Transform
118
119
Sampling and Reconstruction in the z -Domain
vi
60
74
THE z -TRANSFORM
Problems
53
141
155
162
174
CONTENTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
6
DIGITAL FILTER STRUCTURES
Basic Elements
187
IIR Filter Structures
187
FIR Filter Structures
201
Lattice Filter Structures
Problems
7
212
223
FIR FILTER DESIGN
Preliminaries
231
232
Properties of Linear-phase FIR Filters
Window Design Techniques
235
250
Frequency Sampling Design Techniques
Optimal Equiripple Design Technique
Problems
8
186
272
286
302
IIR FILTER DESIGN
Some Preliminaries
313
314
Characteristics of Prototype Analog Filters
Analog-to-Digital Filter Transformations
Lowpass Filter Design Using MATLAB
Frequency-band Transformations
362
Comparison of FIR vs. IIR Filters
375
Problems
CONTENTS
317
339
357
376
vii
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
9
FINITE WORD-LENGTH EFFECTS
Overview
386
386
Representation of Numbers
387
The Process of Quantization and Error Characterizations
Quantization of Filter Coefficients
409
Analysis of A/D Quantization Noise
422
Round-off Effects in IIR Digital Filters
435
Round-off Noise in FIR Filter Realizations
Problems
10
462
474
SAMPLING RATE CONVERSION
Introduction
483
484
Decimation by a Factor D
Interpolation by a Factor I
486
495
Sampling Rate Conversion by a Rational Factor I/D
FIR Filter Designs for Sample Rate Conversion
11
501
506
FIR Filter Structures for Sampling Rate Conversion
Problems
402
528
538
APPLICATIONS IN ADAPTIVE FILTERING
LMS Algorithm for Coefficient Adjustment
System Identification or System Modeling
546
548
551
Suppression of Narrowband Interference
in a Wideband Signal 552
Adaptive Line Enhancement
555
Adaptive Channel Equalization
viii
555
CONTENTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
12
APPLICATIONS IN COMMUNICATIONS
Pulse-Code Modulation
559
Differential PCM (DPCM)
563
Adaptive PCM (ADPCM) and DPCM
Delta Modulation (DM)
570
574
Dual-tone Multifrequency (DTMF) Signals
578
Binary Digital Communications
582
Spread-Spectrum Communications
INDEX
CONTENTS
566
Linear Predictive Coding (LPC) of Speech
BIBLIOGRAPHY
559
583
587
589
ix
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Preface
From the beginning of the 1980s we have witnessed a revolution in computer technology and an explosion in user-friendly applications. This revolution is still continuing today with low-cost personal computer systems
that rival the performance of expensive workstations. This technological prowess should be brought to bear on the educational process and,
in particular, on effective teaching that can result in enhanced learning.
This companion book on digital signal processing (DSP) makes a small
contribution toward reaching that goal.
The teaching methods in signal processing have changed over the
years from the simple “lecture-only” format to a more integrated “lecturelaboratory” environment in which practical hands-on issues are taught
using DSP hardware. However, for effective teaching of DSP the lecture component must also make extensive use of computer-based explanations, examples, and exercises. For the past several years, the
MATLAB software developed by The MathWorks, Inc. has established
itself as the de facto standard for numerical computation in the signalprocessing community and as a platform of choice for algorithm development. There are several reasons for this development, but the most
important reason is that MATLAB is available on practically all computing platforms. Recently, several textbooks in DSP have appeared
that generally provide exercises that can be done using MATLAB.
However, for students (and for practicing engineers interested in DSP)
there are no “how-to” references for effective use of MATLAB in DSP.
In this book we have made an attempt at integrating MATLAB with
traditional topics in DSP so that it can be used to explore difficult
topics and solve problems to gain insight. Many problems or design
xi
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
algorithms in DSP require considerable computation. It is for these
that MATLAB provides a convenient tool so that many scenarios
can be tried with ease. Such an approach can enhance the learning
process.
SCOPE OF THE BOOK
This book is primarily intended for use as a supplement in junior- or
senior-level undergraduate courses on DSP. We assume that the student
(or user) is familiar with the fundamentals of MATLAB. Those topics
are not covered, since several tutorial books and manuals on MATLAB
are available. Similarly, this book is not written as a textbook in DSP
because of the availability of excellent textbooks. What we have tried to
do is to provide enough depth to the material augmented by MATLAB
functions and examples so that the presentation is consistent, logical, and
enjoyable. Therefore, this book can also be used as a self-study guide by
anyone interested in DSP.
ORGANIZATION OF THE BOOK
The first ten chapters of this book discuss traditional material typically
covered in an introductory course on DSP. The final two chapters are
presented as applications in DSP with emphasis on MATLAB-based
projects. The following is a list of chapters and a brief description of their
contents:
Chapter 1, Introduction: This chapter introduces readers to the discipline
of signal processing and discusses the advantages of DSP over analog
signal processing. A brief introduction to MATLAB is also provided.
Chapter 2, Discrete-time Signals and Systems: This chapter provides a
brief review of discrete-time signals and systems in the time domain.
Appropriate use of MATLAB functions is demonstrated.
Chapter 3, The Discrete-time Fourier Analysis: This chapter discusses
discrete-time signal and system representation in the frequency domain.
Sampling and reconstruction of analog signals are also presented.
Chapter 4, The z-Transform: This chapter provides
tem description in the complex frequency domain.
niques are introduced to analyze z-transforms and to
z-transforms. Solutions of difference equations using
and MATLAB are provided.
xii
signal and sysMATLAB techcompute inverse
the z-transform
PREFACE
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Chapter 5, The Discrete Fourier Transform: This chapter is devoted to
the computation of the Fourier transform and to its efficient implementation. The discrete Fourier series is used to introduce the discrete
Fourier transform, and several of its properties are demonstrated using
MATLAB. Topics such as fast convolution and fast Fourier transform
are thoroughly discussed.
Chapter 6, Digital Filter Structures: This chapter discusses several structures for the implementation of digital filters. Several useful MATLAB
functions are developed for the determination and implementation of
these structures. Lattice and ladder filters are also introduced and discussed.
Chapter 7, FIR Filter Design: This chapter and the next introduce the important topic of digital filter design. Three important design techniques
for FIR filters—namely, window design, frequency sampling design, and
the equiripple filter design—are discussed. Several design examples are
provided using MATLAB.
Chapter 8, IIR Filter Design: Included in this chapter are techniques used
in IIR filter design. It begins with analog filter design and introduces
such topics as filter transformations and filter-band transformation.
Once again several design examples using MATLAB are provided.
Chapter 9, Finite Word-Length Effects: The focus of this chapter is on
quantization effects in digital signal processing. Topics treated include
quantization of filter coefficients, round-off noise in FIR and IIR filters,
and quantization noise in analog-to-digital conversion.
Chapter 10, Sampling Rate Conversion: This chapter treats the important problem of sampling rate convesion in digital signal processing.
Topics treated include decimation and interpolation by integer factors,
sampling rate conversion by a rational factor, and filter structures for
sampling rate conversion.
Chapter 11, Applications in Adaptive Filtering: This chapter is the first
of two chapters on projects using MATLAB. Included is an introduction to the theory and implementation of adaptive FIR filters with
projects in system identification, interference suppression, narrowband
frequency enhancement, and adaptive equalization.
Chapter 12, Applications in Communications: This chapter focuses on
several projects dealing with waveform representation and coding
and with digital communications. Included is a description of pulsecode modulation (PCM), differential PCM (DPCM) and adaptive
DPCM (ADPCM), delta modulation (DM) and adaptive DM (ADM),
linear predictive coding (LPC), generation and detection of dualtone multifrequency (DTMF) signals, and a description of signal detection applications in binary communications and spread-spectrum
communications.
PREFACE
xiii
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ABOUT THE SOFTWARE
The book is an outgrowth of our teaching of a MATLAB-based undergraduate DSP course over several years. Many MATLAB functions
discussed in this book were developed in this course. These functions
are available at the BookWare Companion Resource Center, online
at www.cengage.com/engineering. The book also contains numerous
MATLAB scripts in many examples. These scripts are also available
at the Resource Center and are kept in individual directories created for
each chapter. In addition, many figures were produced as MATLAB plots,
and their scripts are available in the figures directory. Students should
study these scripts to gain insight into the MATLAB procedures. We
will appreciate any comments, corrections, or compact coding of these
functions and scripts. Solutions to problems and the associated script
files will be made available to instructors in the near future.
Further information about MATLAB and related publications may
be obtained from
The MathWorks, Inc.
24 Prime Park Way
Natick, MA 01760-1500
Phone: (508) 647-7000 Fax: (508) 647-7001
E-mail: info@mathworks.com
WWW: http://www.mathworks.com
ACKNOWLEDGMENTS
We are indebted to numerous students in our undergraduate DSP course
at Northeastern University who provided us a forum to test teaching ideas
using MATLAB and who endured our constant emphasis on MATLAB.
Some efficient MATLAB functions are due to these students. We are also
indebted to reviewers of the original edition, whose constructive criticism
resulted in a better presentation of the material: Abeer A. H. Alwan,
University of California, Los Angeles; Steven Chin, Catholic University;
Prof. Huaichen, Xidian University, P. R. China; and Joel Trussel, North
Carolina State University. The following reviewers provided additional
encouragement, numerous refinements, and useful comments for the second edition: Jyotsna Bapat, Fairleigh Dickinson University; David Clark,
California State Polytechnic University; Artyom Grigoryan, University of
Texas, San Antonio; Tao Li, University of Florida; and Zixiang Xiong,
Texas A & M University. We sincerely thank all of them.
xiv
PREFACE
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
We would like to thank Tom Robbins, former editor at PWS Publishing Company, for his initiative in creating the BookWare Companion
Series and for his enthusiastic support of MATLAB in classroom teaching,
especially in DSP. The current editor at Cengage Learning, Chris Carson,
took interest in the development of the second edition and provided ample
support for it. Similarly Ms. Hilda Gowans from Cengage Learning managed the edition development and diligently proofread the manuscript.
We sincerely thank them for their efforts. We also appreciate the support
extended by Ms. Naomi Fernandes of MathWorks, Inc., who was always
helpful in providing the newest versions of MATLAB. Finally, we would
like to thank the staff at Cengage Learning for the final preparation of
the manuscript.
Vinay K. Ingle
John G. Proakis
Boston, Massachusetts
PREFACE
xv
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
1
Introduction
During the past several decades the field of digital signal processing (DSP)
has grown to be important, both theoretically and technologically. A major reason for its success in industry is the development and use of low-cost
software and hardware. New technologies and applications in various fields
are now taking advantage of DSP algorithms. This will lead to a greater
demand for electrical and computer engineers with background in DSP.
Therefore, it is necessary to make DSP an integral part of any electrical
engineering curriculum.
Two decades ago an introductory course on DSP was given mainly at
the graduate level. It was supplemented by computer exercises on filter
design, spectrum estimation, and related topics using mainframe (or mini)
computers. However, considerable advances in personal computers and
software during the past two decades have made it necessary to introduce
a DSP course to undergraduates. Since DSP applications are primarily
algorithms that are implemented either on a DSP processor [11] or in
software, a fair amount of programming is required. Using interactive
software, such as MATLAB, it is now possible to place more emphasis
on learning new and difficult concepts than on programming algorithms.
Interesting practical examples can be discussed, and useful problems can
be explored.
With this philosophy in mind, we have developed this book as a companion book (to traditional textbooks like [18, 22]) in which MATLAB is
an integral part in the discussion of topics and concepts. We have chosen
MATLAB as the programming tool primarily because of its wide availability on computing platforms in many universities across the world.
Furthermore, a low-cost student version of MATLAB has been available
1
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
for several years, placing it among the least expensive software products
for educational purposes. We have treated MATLAB as a computational
and programming toolbox containing several tools (sort of a super calculator with several keys) that can be used to explore and solve problems
and, thereby, enhance the learning process.
This book is written at an introductory level in order to introduce
undergraduate students to an exciting and practical field of DSP. We
emphasize that this is not a textbook in the traditional sense but a companion book in which more attention is given to problem solving and
hands-on experience with MATLAB. Similarly, it is not a tutorial book
in MATLAB. We assume that the student is familiar with MATLAB and
is currently taking a course in DSP. The book provides basic analytical
tools needed to process real-world signals (a.k.a. analog signals) using digital techniques. We deal mostly with discrete-time signals and systems,
which are analyzed in both the time and the frequency domains. The
analysis and design of processing structures called filters and spectrum
analyzers is one of the most important aspects of DSP and is treated in
great detail in this book. Two important topics on finite word-length effects and sampling-rate conversion are also discussed in this book. More
advanced topics in modern signal processing like statistical and adaptive
signal processing are generally covered in a graduate course. These are
not treated in this book, but it is hoped that the experience gained in
using this book will allow students to tackle advanced topics with greater
ease and understanding.
In this chapter we provide a brief overview of both DSP and
MATLAB.
OVERVIEW OF DIGITAL SIGNAL PROCESSING
In this modern world we are surrounded by all kinds of signals in various forms. Some of the signals are natural, but most of the signals are
manmade. Some signals are necessary (speech), some are pleasant (music), while many are unwanted or unnecessary in a given situation. In
an engineering context, signals are carriers of information, both useful
and unwanted. Therefore extracting or enhancing the useful information from a mix of conflicting information is the simplest form of signal processing. More generally, signal processing is an operation designed
for extracting, enhancing, storing, and transmitting useful information.
The distinction between useful and unwanted information is often subjective as well as objective. Hence signal processing tends to be application
dependent.
2
Chapter 1
INTRODUCTION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
HOW ARE
SIGNALS
PROCESSED?
The signals that we encounter in practice are mostly analog signals. These
signals, which vary continuously in time and amplitude, are processed
using electrical networks containing active and passive circuit elements.
This approach is known as analog signal processing (ASP)—for example,
radio and television receivers.
Analog signal: xa (t)
−→ Analog signal processor −→ ya (t)
:Analog signal
They can also be processed using digital hardware containing adders,
multipliers, and logic elements or using special-purpose microprocessors.
However, one needs to convert analog signals into a form suitable for
digital hardware. This form of the signal is called a digital signal. It takes
one of the finite number of values at specific instances in time, and hence
it can be represented by binary numbers, or bits. The processing of digital
signals is called DSP; in block diagram form it is represented by
Equivalent Analog Signal Processor
digital
digital
Analog → → PrF −→ ADC −→ DSP −→ DAC −→ PoF → → Analog
Discrete System
The various block elements are discussed as follows.
This is a prefilter or an antialiasing filter, which conditions the analog
signal to prevent aliasing.
ADC: This is an analog-to-digital converter, which produces a stream of
binary numbers from analog signals.
Digital Signal Processor: This is the heart of DSP and can represent a generalpurpose computer or a special-purpose processor, or digital hardware,
and so on.
DAC: This is the inverse operation to the ADC, called a digital-to-analog
converter, which produces a staircase waveform from a sequence of
binary numbers, a first step towards producing an analog signal.
PoF: This is a postfilter to smooth out staircase waveform into the desired
analog signal.
PrF:
It appears from the above two approaches to signal processing, analog
and digital, that the DSP approach is the more complicated, containing
more components than the “simpler looking” ASP. Therefore one might
ask, Why process signals digitally? The answer lies in the many advantages offered by DSP.
ADVANTAGES
OF DSP OVER
ASP
A major drawback of ASP is its limited scope for performing complicated
signal-processing applications. This translates into nonflexibility in processing and complexity in system designs. All of these generally lead to
Overview of Digital Signal Processing
3
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
expensive products. On the other hand, using a DSP approach, it is possible to convert an inexpensive personal computer into a powerful signal
processor. Some important advantages of DSP are these:
1. Systems using the DSP approach can be developed using software running on a general-purpose computer. Therefore DSP is relatively convenient to develop and test, and the software is portable.
2. DSP operations are based solely on additions and multiplications, leading to extremely stable processing capability—for example, stability
independent of temperature.
3. DSP operations can easily be modified in real time, often by simple
programming changes, or by reloading of registers.
4. DSP has lower cost due to VLSI technology, which reduces costs of
memories, gates, microprocessors, and so forth.
The principal disadvantage of DSP is the limited speed of operations
limited by the DSP hardware, especially at very high frequencies. Primarily because of its advantages, DSP is now becoming a first choice in many
technologies and applications, such as consumer electronics, communications, wireless telephones, and medical imaging.
TWO
IMPORTANT
CATEGORIES
OF DSP
Most DSP operations can be categorized as being either signal analysis
tasks or signal filtering tasks as shown below.
Digital signal
✏✏
✏✏
✏✏
✏
✮✏
✏
Analysis
PP
PP
PP
PP
q
P
✲
Digital filter
❄
Measurements
❄
Digital signal
Signal analysis This task deals with the measurement of signal properties. It is generally a frequency-domain operation. Some of its applications are
•
•
•
•
spectrum (frequency and/or phase) analysis
speech recognition
speaker verification
target detection
Signal filtering This task is characterized by the “signal in–signal out”
situation. The systems that perform this task are generally called filters.
4
Chapter 1
INTRODUCTION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
It is usually (but not always) a time-domain operation. Some of the
applications are
•
•
•
•
removal of unwanted background noise
removal of interference
separation of frequency bands
shaping of the signal spectrum
In some applications, such as voice synthesis, a signal is first analyzed
to study its characteristics, which are then used in digital filtering to
generate a synthetic voice.
ORGANIZATION OF THE BOOK
The first part of this book, which comprises Chapters 2 through 5, deals
with the signal-analysis aspect of DSP. Chapter 2 begins with basic descriptions of discrete-time signals and systems. These signals and systems
are analyzed in the frequency domain in Chapter 3. A generalization of
the frequency-domain description, called the z-transform, is introduced in
Chapter 4. The practical algorithms for computing the Fourier transform
are discussed in Chapter 5 in the form of the discrete Fourier transform
and the fast Fourier transform.
Chapters 6 through 8 constitute the second part of this book, which
is devoted to the signal-filtering aspect of DSP. Chapter 6 describes various implementations and structures of digital filters. Chapter 7 introduces
design techniques and algorithms for designing one type of digital filter
called finite-duration impulse response (or FIR) filters, and Chapter 8 provides a similar treatment for another type of filter called infinite-duration
impulse response (or IIR) filters. In both chapters only the simpler but
practically useful techniques of filter design are discussed. More advanced
techniques are not covered.
Finally, the last part, which consists of the remaining four chapters,
provides important topics and applications in DSP. Chapter 9 is devoted
to the effects of signal/coefficient quantization and finite precision arithmetic on filter performance. Chapter 10 deals with the useful application
of the sampling-rate conversion. The last two chapters provide some practical applications in the form of projects that can be done using material
presented in the first eight chapters. In Chapter 11 concepts in adaptive filtering are introduced, and simple projects in system identification,
interference suppression, adaptive line enhancement, and so forth are discussed. In Chapter 12 a brief introduction to digital communications is
presented with projects involving such topics as PCM, DPCM, and LPC
being outlined.
Organization of the book
5
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In all these chapters the central theme is the generous use and adequate demonstration of MATLAB tools. Most of the existing MATLAB
functions for DSP are described in detail, and their correct use is demonstrated in many examples. Furthermore, many new MATLAB functions
are developed to provide insights into the working of many algorithms.
The authors believe that this “hand-holding” approach will enable students to dispel fears about DSP and will provide an enriching learning
experience.
A FEW WORDS ABOUT MATLAB
MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation and visualization. Its strength lies in the
fact that complex numerical problems can be solved easily and in a fraction of the time required with a programming language such as Fortran
or C. It is also powerful in the sense that by using its relatively simple
programming capability, MATLAB can be easily extended to create new
commands and functions.
MATLAB is available on a number of computing environments: PCs
running, DOS, Win9X, Win2K, and WinXP, Apple MACs running OS-X,
UNIX workstations, and several parallel machines. The basic MATLAB
program is further enhanced by the availability of numerous toolboxes (a
collection of specialized functions in a specific topic) over the years. The
information in this book generally applies to all these environments. In
addition to the basic MATLAB product, the Signal Processing toolbox
(SP toolbox) is required for this book. The original development of the
book was done using the professional version 3.5 running under DOS. The
MATLAB scripts and functions described in the book were later extended
and made compatible with the present version of MATLAB. Furthermore,
through the services of of the BookWare Companion Resource Center
(www.brookscole.com/engineering/ee/bookware.htm), every effort will be
made to preserve this compatibility under future versions of MATLAB.
The scope and power of MATLAB go far beyond the few words given
in this section. It is senseless to provide a concise information or tutorial on
MATLAB when MathWorks provides online documentations and tutorials
(including video-based ones) on their products. Students and readers new
to MATLAB should also consult the excellent reference books available
in the literature including [10], [7], and [20]. The information given in
all these references, along with the online facility, usually is sufficient to
enable students to use this book.
6
Chapter 1
INTRODUCTION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
2
Discrete-time
Signals and
Systems
We begin with the concepts of signals and systems in discrete time. A
number of important types of signals and their operations are introduced.
Linear and shift-invariant systems are discussed mostly because they are
easier to analyze and implement. The convolution and the difference equation representations are given special attention because of their importance in digital signal processing and in MATLAB. The emphasis in this
chapter is on the representations and implementation of signals and systems using MATLAB.
DISCRETE-TIME SIGNALS
Signals are broadly classified into analog and discrete signals. An analog
signal will be denoted by xa (t), in which the variable t can represent any
physical quantity, but we will assume that it represents time in seconds.
A discrete signal will be denoted by x(n), in which the variable n is
integer-valued and represents discrete instances in time. Therefore it is
also called a discrete-time signal, which is a number sequence and will be
denoted by one of the following notations:
x(n) = {x(n)} = {. . . , x(−1), x(0), x(1), . . .}
↑
where the up-arrow indicates the sample at n = 0.
7
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In MATLAB we can represent a finite-duration sequence by a row
vector of appropriate values. However, such a vector does not have any
information about sample position n. Therefore a correct representation
of x(n) would require two vectors, one each for x and n. For example, a
sequence x(n) = {2, 1, −1, 0, 1, 4, 3, 7} can be represented in MATLAB by
↑
>> n=[-3,-2,-1,0,1,2,3,4];
x=[2,1,-1,0,1,4,3,7];
Generally, we will use the x-vector representation alone when the sample
position information is not required or when such information is trivial
(e.g. when the sequence begins at n = 0). An arbitrary infinite-duration
sequence cannot be represented in MATLAB due to the finite memory
limitations.
TYPES OF
SEQUENCES
We use several elementary sequences in digital signal processing for analysis purposes. Their definitions and MATLAB representations are given
below.
1. Unit sample sequence:
δ(n) =
1,
0,
n=0
=
n = 0
. . . , 0, 0, 1, 0, 0, . . .
↑
In MATLAB the function zeros(1,N) generates a row vector of N
zeros, which can be used to implement δ(n) over a finite interval. However, the logical relation n==0 is an elegant way of implementing δ(n).
For example, to implement
1, n = n0
δ(n − n0 ) =
0, n = n0
over the n1 ≤ n0 ≤ n2 interval, we will use the following MATLAB
function.
function [x,n] = impseq(n0,n1,n2)
% Generates x(n) = delta(n-n0); n1 <= n <= n2
% ---------------------------------------------% [x,n] = impseq(n0,n1,n2)
%
n = [n1:n2]; x = [(n-n0) == 0];
2. Unit step sequence:
u(n) =
8
1, n ≥ 0
= {. . . , 0, 0, 1, 1, 1, . . .}
0, n < 0
↑
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In MATLAB the function ones(1,N) generates a row vector of N ones.
It can be used to generate u(n) over a finite interval. Once again an
elegant approach is to use the logical relation n>=0. To implement
u(n − n0 ) =
1, n ≥ n0
0, n < n0
over the n1 ≤ n0 ≤ n2 interval, we will use the following MATLAB
function.
function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n <= n2
% -----------------------------------------% [x,n] = stepseq(n0,n1,n2)
%
n = [n1:n2]; x = [(n-n0) >= 0];
3. Real-valued exponential sequence:
x(n) = an , ∀n; a ∈ R
In MATLAB an array operator “.^” is required to implement a real
exponential sequence. For example, to generate x(n) = (0.9)n , 0 ≤
n ≤ 10, we will need the following MATLAB script:
>> n = [0:10]; x = (0.9).^n;
4. Complex-valued exponential sequence:
x(n) = e(σ+jω0 )n , ∀n
where σ produces an attenuation (if <0) or amplification (if >0) and
ω0 is the frequency in radians. A MATLAB function exp is used
to generate exponential sequences. For example, to generate x(n) =
exp[(2 + j3)n], 0 ≤ n ≤ 10, we will need the following MATLAB script:
>> n = [0:10]; x = exp((2+3j)*n);
5. Sinusoidal sequence:
x(n) = A cos(ω0 n + θ), ∀n
where A is an amplitude and θ is the phase in radians. A MATLAB
function cos (or sin) is used to generate sinusoidal sequences.
Discrete-time Signals
9
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
For example, to generate x(n) = 3 cos(0.1πn + π/3) + 2 sin(0.5πn),
0 ≤ n ≤ 10, we will need the following MATLAB script:
>> n = [0:10]; x = 3*cos(0.1*pi*n+pi/3) + 2*sin(0.5*pi*n);
6. Random sequences: Many practical sequences cannot be described by
mathematical expressions like those above. These sequences are called
random (or stochastic) sequences and are characterized by parameters
of the associated probability density functions. In MATLAB two types
of (pseudo-) random sequences are available. The rand(1,N) generates
a length N random sequence whose elements are uniformly distributed
between [0, 1]. The randn(1,N) generates a length N Gaussian random
sequence with mean 0 and variance 1. Other random sequences can be
generated using transformations of the above functions.
7. Periodic sequence: A sequence x(n) is periodic if x(n) = x(n + N ), ∀n.
The smallest integer N that satisfies the above relation is called the
fundamental period. We will use x̃(n) to denote a periodic sequence. To
generate P periods of x̃(n) from one period {x(n), 0 ≤ n ≤ N − 1},
we can copy x(n) P times:
>> xtilde = [x,x,...,x];
But an elegant approach is to use MATLAB’s powerful indexing capabilities. First we generate a matrix containing P rows of x(n) values.
Then we can concatenate P rows into a long row vector using the construct (:). However, this construct works only on columns. Hence we
will have to use the matrix transposition operator ’ to provide the
same effect on rows.
>> xtilde = x’ * ones(1,P);
>> xtilde = xtilde(:);
>> xtilde = xtilde’;
% P columns of x; x is a row vector
% long column vector
% long row vector
Note that the last two lines can be combined into one for compact
coding. This is shown in Example 2.1.
OPERATIONS
ON
SEQUENCES
Here we briefly describe basic sequence operations and their MATLAB
equivalents.
1. Signal addition: This is a sample-by-sample addition given by
{x1 (n)} + {x2 (n)} = {x1 (n) + x2 (n)}
It is implemented in MATLAB by the arithmetic operator “+”. However, the lengths of x1 (n) and x2 (n) must be the same. If sequences are
of unequal lengths, or if the sample positions are different for equallength sequences, then we cannot directly use the operator +. We have
10
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
to first augment x1 (n) and x2 (n) so that they have the same position
vector n (and hence the same length). This requires careful attention to
MATLAB’s indexing operations. In particular, logical operation of intersection “&”, relational operations like “<=” and “==”, and the find
function are required to make x1 (n) and x2 (n) of equal length. The
following function, called the sigadd function, demonstrates these
operations.
function [y,n] = sigadd(x1,n1,x2,n2)
% implements y(n) = x1(n)+x2(n)
% ----------------------------% [y,n] = sigadd(x1,n1,x2,n2)
%
y = sum sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
%
n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n)
y1 = zeros(1,length(n)); y2 = y1;
% initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
% x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
% x2 with duration of y
y = y1+y2;
% sequence addition
Its use is illustrated in Example 2.2.
2. Signal multiplication: This is a sample-by-sample multiplication (or
“dot” multiplication) given by
{x1 (n)} · {x2 (n)} = {x1 (n)x2 (n)}
It is implemented in MATLAB by the array operator “.*”. Once again
the similar restrictions apply for the .* operator as for the + operator.
Therefore we have developed the sigmult function, which is similar to
the sigadd function.
function [y,n] = sigmult(x1,n1,x2,n2)
% implements y(n) = x1(n)*x2(n)
% ----------------------------% [y,n] = sigmult(x1,n1,x2,n2)
%
y = product sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
%
n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n)
y1 = zeros(1,length(n)); y2 = y1;
%
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
% x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
% x2 with duration of y
y = y1 .* y2;
% sequence multiplication
Its use is also given in Example 2.2.
Discrete-time Signals
11
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3. Scaling: In this operation each sample is multiplied by a scalar α.
α {x(n)} = {αx(n)}
An arithmetic operator “*” is used to implement the scaling operation
in MATLAB.
4. Shifting: In this operation each sample of x(n) is shifted by an amount
k to obtain a shifted sequence y(n).
y(n) = {x(n − k)}
If we let m = n−k, then n = m+k and the above operation is given by
y(m + k) = {x (m)}
Hence this operation has no effect on the vector x, but the vector n is
changed by adding k to each element. This is shown in the function
sigshift.
function [y,n] = sigshift(x,m,k)
% implements y(n) = x(n-k)
% ------------------------% [y,n] = sigshift(x,m,k)
%
n = m+k; y = x;
Its use is given in Example 2.2.
5. Folding: In this operation each sample of x(n) is flipped around n = 0
to obtain a folded sequence y(n).
y(n) = {x(−n)}
In MATLAB this operation is implemented by fliplr(x)function for
sample values and by -fliplr(n) function for sample positions as
shown in the sigfold function.
function [y,n] = sigfold(x,n)
% implements y(n) = x(-n)
% ----------------------% [y,n] = sigfold(x,n)
%
y = fliplr(x); n = -fliplr(n);
6. Sample summation: This operation differs from signal addition operation. It adds all sample values of x(n) between n1 and n2 .
n2
x(n) = x(n1 ) + · · · + x(n2 )
n=n1
It is implemented by the sum(x(n1:n2)) function.
12
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
7. Sample products: This operation also differs from signal multiplication
operation. It multiplies all sample values of x(n) between n1 and n2 .
n2
x(n) = x(n1 ) × · · · × x(n2 )
n1
It is implemented by the prod(x(n1:n2)) function.
8. Signal energy: The energy of a sequence x(n) is given by
Ex =
∞
x(n)x∗ (n) =
−∞
∞
|x(n)|
2
−∞
where superscript ∗ denotes the operation of complex conjugation1 .
The energy of a finite-duration sequence x(n) can be computed in
MATLAB using
>> Ex = sum(x .* conj(x)); % one approach
>> Ex = sum(abs(x) .^ 2); % another approach
9. Signal power : The average power of a periodic sequence x̃(n) with
fundamental period N is given by
N −1
1 2
Px =
|x̃(n)|
N 0
EXAMPLE 2.1
Generate and plot each of the following sequences over the indicated interval.
a. x(n) = 2δ(n + 2) − δ(n − 4), −5 ≤ n ≤ 5.
b. x(n) = n[u(n)−u(n−10)]+10e−0.3(n−10) [u(n−10)−u(n−20)], 0 ≤ n ≤ 20.
c. x(n) = cos(0.04πn) + 0.2w(n), 0 ≤ n ≤ 50, where w(n) is a Gaussian
random sequence with zero mean and unit variance.
d. x̃(n) = {..., 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, ...}; −10 ≤ n ≤ 9.
↑
Solution
a. x(n) = 2δ(n + 2) − δ(n − 4),
>>
>>
>>
>>
−5 ≤ n ≤ 5.
n = [-5:5];
x = 2*impseq(-2,-5,5) - impseq(4,-5,5);
stem(n,x); title(’Sequence in Problem 2.1a’)
xlabel(’n’); ylabel(’x(n)’);
The plot of the sequence is shown in Figure 2.1a.
1 The symbol * denotes many operations in digital signal processing. Its font (roman
or computer) and its position (normal or superscript) will distinguish each operation.
Discrete-time Signals
13
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Sequence in Example 2.1a
Sequence in Example 2.1b
3
10
8
1
6
x(n)
x(n)
2
0
4
−1
2
0
−2
−5
0
n
5
0
Sequence in Example 2.1c
5
10
n
15
20
Sequence in Example 2.1d
6
1
4
xtilde(n)
x(n)
0.5
0
−0.5
−1
0
2
0
10
20
30
40
−10
n
FIGURE 2.1
−5
0
n
5
Sequences in Example 2.1
b. x(n) = n [u(n) − u(n − 10)]+10e−0.3(n−10) [u(n − 10) − u(n − 20)], 0 ≤ n ≤
20.
>>
>>
>>
>>
>>
n = [0:20]; x1 = n.*(stepseq(0,0,20)-stepseq(10,0,20));
x2 = 10*exp(-0.3*(n-10)).*(stepseq(10,0,20)-stepseq(20,0,20));
x = x1+x2;
subplot(2,2,3); stem(n,x); title(’Sequence in Problem 2.1b’)
xlabel(’n’); ylabel(’x(n)’);
The plot of the sequence is shown in Figure 2.1b.
c. x(n) = cos(0.04πn) + 0.2w(n), 0 ≤ n ≤ 50.
>> n = [0:50]; x = cos(0.04*pi*n)+0.2*randn(size(n));
>> subplot(2,2,2); stem(n,x); title(’Sequence in Problem 2.1c’)
>> xlabel(’n’); ylabel(’x(n)’);
The plot of the sequence is shown in Figure 2.1c.
d. x̃(n) = {..., 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, ...}; −10 ≤ n ≤ 9.
↑
Note that over the given interval, the sequence x̃ (n) has four periods.
14
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>>
>>
>>
>>
n = [-10:9]; x = [5,4,3,2,1];
xtilde = x’ * ones(1,4);
xtilde = (xtilde(:))’;
subplot(2,2,4); stem(n,xtilde); title(’Sequence in Problem 2.1d’)
xlabel(’n’); ylabel(’xtilde(n)’);
The plot of the sequence is shown in Figure 2.1d.
EXAMPLE 2.2
Let x(n) = {1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1}. Determine and plot the following
sequences.
↑
a. x1 (n) = 2x(n − 5) − 3x(n + 4)
b. x2 (n) = x(3 − n) + x(n) x(n − 2)
Solution
The sequence x(n) is nonzero over −2 ≤ n ≤ 10. Hence
>> n = -2:10; x = [1:7,6:-1:1];
will generate x(n).
a. x1 (n) = 2x(n − 5) − 3x(n + 4).
The first part is obtained by shifting x(n) by 5 and the second part by
shifting x(n) by −4. This shifting and the addition can be easily done using
the sigshift and the sigadd functions.
>>
>>
>>
>>
[x11,n11] = sigshift(x,n,5); [x12,n12] = sigshift(x,n,-4);
[x1,n1] = sigadd(2*x11,n11,-3*x12,n12);
subplot(2,1,1); stem(n1,x1); title(’Sequence in Example 2.2a’)
xlabel(’n’); ylabel(’x1(n)’);
The plot of x1 (n) is shown in Figure 2.2a.
b. x2 (n) = x(3 − n) + x(n) x(n − 2).
The first term can be written as x(−(n − 3)). Hence it is obtained by first
folding x(n) and then shifting the result by 3. The second part is a multiplication of x(n) and x(n − 2), both of which have the same length but different
support (or sample positions). These operations can be easily done using the
sigfold and the sigmult functions.
>>
>>
>>
>>
>>
[x21,n21] = sigfold(x,n); [x21,n21] = sigshift(x21,n21,3);
[x22,n22] = sigshift(x,n,2); [x22,n22] = sigmult(x,n,x22,n22);
[x2,n2] = sigadd(x21,n21,x22,n22);
subplot(2,1,2); stem(n2,x2); title(’Sequence in Example 2.2b’)
xlabel(’n’); ylabel(’x2(n)’);
The plot of x2 (n) is shown in Figure 2.2b.
Discrete-time Signals
15
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Sequence in Example 2.2a
10
5
x1(n)
0
−5
−10
−15
−20
−6
0
15
n
Sequence in Example 2.2b
40
x2(n)
30
20
10
0
−7
0
12
n
FIGURE 2.2
Sequences in Example 2.2
This example shows that the four sig* functions developed in this
section provide a convenient approach for sequence manipulations.
EXAMPLE 2.3
Generate the complex-valued signal
x(n) = e(−0.1+j0.3)n ,
−10 ≤ n ≤ 10
and plot its magnitude, phase, the real part, and the imaginary part in four
separate subplots.
Solution
MATLAB Script:
>>
>>
>>
>>
>>
>>
n = [-10:1:10]; alpha = -0.1+0.3j;
x = exp(alpha*n);
subplot(2,2,1); stem(n,real(x));title(’real part’);xlabel(’n’)
subplot(2,2,2); stem(n,imag(x));title(’imaginary part’);xlabel(’n’)
subplot(2,2,3); stem(n,abs(x));title(’magnitude part’);xlabel(’n’)
subplot(2,2,4); stem(n,(180/pi)*angle(x));title(’phase part’);xlabel(’n’)
The plot of the sequence is shown in Figure 2.3.
16
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
real part
imaginary part
2
1
1
0
0
−1
−1
−2
−3
−10
−5
0
n
5
10
−2
−10
−5
magnitude part
0
n
5
10
5
10
phase part
3
200
100
2
0
1
0
−10
FIGURE 2.3
SOME USEFUL
RESULTS
−100
−5
0
n
5
10
−200
−10
−5
0
n
Complex-valued sequence plots in Example 2.3
There are several important results in discrete-time signal theory. We will
discuss some that are useful in digital signal processing.
Unit sample synthesis Any arbitrary sequence x(n) can be synthesized as a weighted sum of delayed and scaled unit sample sequences, such
as
∞
x(n) =
x(k)δ(n − k)
(2.1)
k=−∞
We will use this result in the next section.
Even and odd synthesis
(symmetric) if
A real-valued sequence xe (n) is called even
xe (−n) = xe (n)
Similarly, a real-valued sequence xo (n) is called odd (antisymmetric) if
xo (−n) = −xo (n)
Then any arbitrary real-valued sequence x(n) can be decomposed into its
even and odd components
x(n) = xe (n) + xo (n)
Discrete-time Signals
(2.2)
17
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where the even and odd parts are given by
xe (n) =
1
[x(n) + x(−n)]
2
and xo (n) =
1
[x(n) − x(−n)]
2
(2.3)
respectively. We will use this decomposition in studying properties of the
Fourier transform. Therefore it is a good exercise to develop a simple
MATLAB function to decompose a given sequence into its even and odd
components. Using MATLAB operations discussed so far, we can obtain
the following evenodd function.
function [xe, xo, m] = evenodd(x,n)
% Real signal decomposition into even and odd parts
% ------------------------------------------------% [xe, xo, m] = evenodd(x,n)
%
if any(imag(x) ~= 0)
error(’x is not a real sequence’)
end
m = -fliplr(n);
m1 = min([m,n]); m2 = max([m,n]); m = m1:m2;
nm = n(1)-m(1); n1 = 1:length(n);
x1 = zeros(1,length(m));
x1(n1+nm) = x; x = x1;
xe = 0.5*(x + fliplr(x)); xo = 0.5*(x - fliplr(x));
The sequence and its support are supplied in x and n arrays, respectively.
It first checks if the given sequence is real and determines the support
of the even and odd components in m array. It then implements (2.3)
with special attention to the MATLAB indexing operation. The resulting
components are stored in xe and xo arrays.
EXAMPLE 2.4
Solution
Let x(n) = u(n) − u(n − 10). Decompose x(n) into even and odd components.
The sequence x(n), which is nonzero over 0 ≤ n ≤ 9, is called a rectangular
pulse. We will use MATLAB to determine and plot its even and odd parts.
>>
>>
>>
>>
>>
>>
>>
>>
n = [0:10]; x = stepseq(0,0,10)-stepseq(10,0,10);
[xe,xo,m] = evenodd(x,n);
subplot(2,2,1); stem(n,x); title(’Rectangular pulse’)
xlabel(’n’); ylabel(’x(n)’); axis([-10,10,0,1.2])
subplot(2,2,2); stem(m,xe); title(’Even Part’)
xlabel(’n’); ylabel(’xe(n)’); axis([-10,10,0,1.2])
subplot(2,2,4); stem(m,xo); title(’Odd Part’)
xlabel(’n’); ylabel(’xe(n)’); axis([-10,10,-0.6,0.6])
The plots shown in Figure 2.4 clearly demonstrate the decomposition. 18
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Even Part
1
1
0.8
0.8
xe(n)
x(n)
Rectangular pulse
0.6
0.6
0.4
0.4
0.2
0.2
0
−10
−5
0
n
5
0
−10
10
−5
0
n
5
10
5
10
Odd Part
0.6
0.4
xe(n)
0.2
0
−0.2
−0.4
−10
FIGURE 2.4
−5
0
n
Even-odd decomposition in Example 2.4
A similar decomposition for complex-valued sequences is explored in
Problem P2.5.
The geometric series A one-sided exponential sequence of the form
{αn , n ≥ 0}, where α is an arbitrary constant, is called a geometric
series. In digital signal processing, the convergence and expression for the
sum of this series are used in many applications. The series converges for
|α| < 1, while the sum of its components converges to
∞
αn −→
n=0
1
,
1−α
for |α| < 1
(2.4)
We will also need an expression for the sum of any finite number of terms
of the series given by
N
−1
n=0
αn =
1 − αN
, ∀α
1−α
(2.5)
These two results will be used throughout this book.
Discrete-time Signals
19
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Correlations of sequences Correlation is an operation used in many
applications in digital signal processing. It is a measure of the degree to
which two sequences are similar. Given two real-valued sequences x(n) and
y(n) of finite energy, the crosscorrelation of x(n) and y(n) is a sequence
rxy () defined as
∞
x(n)y(n − )
(2.6)
rx,y () =
n=−∞
The index is called the shift or lag parameter. The special case of (2.6)
when y(n) = x(n) is called autocorrelation and is defined by
rxx () =
∞
x(n)x(n − )
(2.7)
n=−∞
It provides a measure of self-similarity between different alignments of the
sequence. MATLAB functions to compute auto- and crosscorrelations are
discussed later in the chapter.
DISCRETE SYSTEMS
Mathematically, a discrete-time system (or discrete system for short) is
described as an operator T [·] that takes a sequence x(n) (called excitation)
and transforms it into another sequence y(n) (called response). That is,
y(n) = T [x(n)]
In DSP we will say that the system processes an input signal into an output
signal. Discrete systems are broadly classified into linear and nonlinear
systems. We will deal mostly with linear systems.
LINEAR
SYSTEMS
A discrete system T [·] is a linear operator L[·] if and only if L[·] satisfies
the principle of superposition, namely,
L[a1 x1 (n) + a2 x2 (n)] = a1 L[x1 (n)] + a2 L[x2 (n)], ∀a1 , a2 , x1 (n), x2 (n)
(2.8)
Using (2.1) and (2.8), the output y(n) of a linear system to an arbitrary
input x(n) is given by
∞
∞
y(n) = L[x(n)] = L
x(k) δ(n − k) =
x(k)L[δ(n − k)]
n=−∞
20
Chapter 2
n=−∞
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The response L[δ(n − k)] can be interpreted as the response of a linear
system at time n due to a unit sample (a well-known sequence) at time k.
It is called an impulse response and is denoted by h(n, k). The output
then is given by the superposition summation
y(n) =
∞
x(k)h(n, k)
(2.9)
n=−∞
The computation of (2.9) requires the time-varying impulse response
h(n, k), which in practice is not very convenient. Therefore time-invariant
systems are widely used in DSP.
Linear time-invariant (LTI) system A linear system in which an
input-output pair, x(n) and y(n), is invariant to a shift k in time is called
a linear time-invariant system i.e.,
y(n) = L[x(n)] ⇒ L[x(n − k)] = y(n − k)
(2.10)
For an LTI system the L[·] and the shifting operators are reversible as
shown below.
x(n) −→ L [·] −→ y(n) −→ Shift by k −→ y(n − k)
x(n) −→ Shift by k −→ x(n − k) −→ L [·] −→ y(n − k)
We will denote an LTI system by the operator LT I [·]. Let x(n) and y(n)
be the input-output pair of an LTI system. Then the time-varying function
h(n, k) becomes a time-invariant function h(n − k), and the output from
(2.9) is given by
y(n) = LT I [x(n)] =
∞
x(k)h(n − k)
(2.11)
k=−∞
The impulse response of an LTI system is given by h(n). The mathematical operation in (2.11) is called a linear convolution sum and is denoted
by
(2.12)
y(n) = x(n) ∗ h(n)
Hence an LTI system is completely characterized in the time domain by
the impulse response h(n) as shown below.
x(n) −→ h(n) −→ y(n) = x(n) ∗ h(n)
We will explore several properties of the convolution in Problem P2.14.
Discrete Systems
21
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Stability This is a very important concept in linear system theory. The
primary reason for considering stability is to avoid building harmful systems or to avoid burnout or saturation in the system operation. A system
is said to be bounded-input bounded-output (BIBO) stable if every bounded
input produces a bounded output.
|x(n)| < ∞ ⇒ |y(n)| < ∞, ∀x, y
An LTI system is BIBO stable if and only if its impulse response is absolutely summable.
BIBO Stability ⇐⇒
∞
|h(n)| < ∞
(2.13)
−∞
Causality This important concept is necessary to make sure that systems can be built. A system is said to be causal if the output at index n0
depends only on the input up to and including the index n0 ; that is, the
output does not depend on the future values of the input. An LTI system
is causal if and only if the impulse response
(2.14)
h(n) = 0, n < 0
Such a sequence is termed a causal sequence. In signal processing, unless
otherwise stated, we will always assume that the system is causal.
CONVOLUTION
We introduced the convolution operation (2.12) to describe the response
of an LTI system. In DSP it is an important operation and has many other
uses that we will see throughout this book. Convolution can be evaluated
in many different ways. If the sequences are mathematical functions (of
finite or infinite duration), then we can analytically evaluate (2.12) for all
n to obtain a functional form of y(n).
EXAMPLE 2.5
Let the rectangular pulse x(n) = u(n) − u(n − 10) of Example 2.4 be an input
to an LTI system with impulse response
h(n) = (0.9)n u(n)
Determine the output y(n).
Solution
The input x(n) and the impulse response h(n) are shown in Figure 2.5. From
(2.12)
y(n) =
9
(1) (0.9)(n−k) u(n − k) = (0.9)n
k=0
22
9
(0.9)−k u(n − k)
(2.15)
k=0
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Input Sequence
2
x(n)
1.5
1
0.5
0
−5
0
5
10
15
20
25
30
35
40
45
30
35
40
45
n
Impulse Response
2
h(n)
1.5
1
0.5
0
−5
0
5
10
15
20
25
n
FIGURE 2.5
The input sequence and the impulse response in Example 2.5
The sum in (2.15) is almost a geometric series sum except that the term u(n−k)
takes different values depending on n and k. There are three possible conditions
under which u(n − k) can be evaluated.
CASE i
n < 0: Then u(n − k) = 0,
0 ≤ k ≤ 9. Hence from (2.15)
(2.16)
y(n) = 0
CASE ii
In this case the nonzero values of x(n) and h(n) do not overlap.
0 ≤ n < 9: Then u(n − k) = 1, 0 ≤ k ≤ n. Hence from (2.15)
y(n) = (0.9)n
n
(0.9)−k = (0.9)n
k=0
n
[(0.9)−1 ]k
k=0
1 − (0.9)−(n+1)
= (0.9)
= 10[1 − (0.9)n+1 ],
1 − (0.9)−1
n
CASE iii
0≤n<9
(2.17)
In this case the impulse response h(n) partially overlaps the input x(n).
n ≥ 9: Then u(n − k) = 1, 0 ≤ k ≤ 9 and from (2.15)
y(n) = (0.9)n
9
(0.9)−k
k=0
1 − (0.9)−10
= (0.9)n
= 10(0.9)n−9 [1 − (0.9)10 ],
1 − (0.9)−1
n≥9
(2.18)
In this last case h(n) completely overlaps x(n).
Convolution
23
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Output Sequence
8
y(n)
6
4
2
0
−5
0
5
10
15
20
25
30
35
40
45
n
The output sequence in Example 2.5
FIGURE 2.6
The complete response is given by (2.16), (2.17), and (2.18). It is shown in
Figure 2.6 which depicts the distortion of the input pulse.
The above example can also be done using a method called graphical
convolution, in which (2.12) is given a graphical interpretation. In this
method h(n − k) is interpreted as a folded-and-shifted version of h(k).
The output y(n) is obtained as a sample sum under the overlap of x(k)
and h(n − k). We use an example to illustrate this.
EXAMPLE 2.6
Given the following two sequences
x(n) = [3, 11, 7, 0, −1, 4, 2],
↑
−3 ≤ n ≤ 3;
h(n) = [2, 3, 0, −5, 2, 1],
↑
−1 ≤ n ≤ 4
determine the convolution y(n) = x(n) ∗ h(n).
Solution
In Figure 2.7 we show four plots. The top-left plot shows x(k) and h(k), the
original sequences. The top-right plot shows x(k) and h(−k), the folded version
of h(k). The bottom-left plot shows x(k) and h(−1 − k), the folded-and-shiftedby- −1 version of h(k). Then
x(k)h(−1 − k) = 3 × (−5) + 11 × 0 + 7 × 3 + 0 × 2 = 6 = y(−1)
k
The bottom-right plot shows x(k) and h(2 − k), the folded-and-shifted-by-2
version of h(k), which gives
x(k)h(2 − k) = 11 × 1 + 7 × 2 + 0 × (−5) + (−1) × 0 + 4 × 3 + 2 × 2 = 41 = y(2)
k
Thus we have obtained two values of y(n). Similar graphical calculations can
be done for other remaining values of y(n). Note that the beginning point (first
nonzero sample) of y(n) is given by n = −3 + (−1) = −4, while the end point
(the last nonzero sample) is given by n = 3 + 4 = 7. The complete output is
given by
y(n) = {6, 31, 47, 6, −51, −5, 41, 18, −22, −3, 8, 2}
↑
24
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x(k) and h(k)
10
solid: x
x(k) and h(−k)
dashed: h
10
5
5
0
0
−5
−5
0
k
5
−5
−5
x(k) and h(−1−k)
10
solid: x
−5
−5
FIGURE 2.7
dashed: h
n=0
0
k
5
x(k) and h(2−k)
dashed: h
10
5
0
solid: x
solid: x
dashed: h
5
0
n=−1
0
k
5
−5
−5
n=2
0
k
5
Graphical convolution in Example 2.6
Students are strongly encouraged to verify the above result. Note that the resulting sequence y(n) has a longer length than both the x(n) and h(n) sequences.
MATLAB
IMPLEMENTATION
If arbitrary sequences are of infinite duration, then MATLAB cannot be
used directly to compute the convolution. MATLAB does provide a builtin function called conv that computes the convolution between two finiteduration sequences. The conv function assumes that the two sequences
begin at n = 0 and is invoked by
>> y = conv(x,h);
For example, to do the convolution in Example 2.5, we could use
>> x = [3, 11, 7, 0, -1, 4, 2]; h = [2, 3, 0, -5, 2, 1];
>> y = conv(x, h)
y =
6
31
47
6
-51
-5
41
18
-22
-3
8
2
to obtain the correct y(n) values. However, the conv function neither provides nor accepts any timing information if the sequences have arbitrary
support. What is needed is a beginning point and an end point of y(n).
Convolution
25
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Given finite duration x(n) and h(n), it is easy to determine these points.
Let
{x(n); nxb ≤ n ≤ nxe } and {h(n); nhb ≤ n ≤ nhe }
be two finite-duration sequences. Then referring to Example 2.6 we observe that the beginning and end points of y(n) are
nyb = nxb + nhb
and nye = nxe + nhe
respectively. A simple modification of the conv function, called conv m,
which performs the convolution of arbitrary support sequences can now
be designed.
function [y,ny] = conv_m(x,nx,h,nh)
% Modified convolution routine for signal processing
% -------------------------------------------------% [y,ny] = conv_m(x,nx,h,nh)
% [y,ny] = convolution result
% [x,nx] = first signal
% [h,nh] = second signal
%
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye];
y = conv(x,h);
EXAMPLE 2.7
Solution
Perform the convolution in Example 2.6 using the conv m function.
MATLAB Script:
>> x = [3, 11, 7, 0, -1, 4, 2]; nx = [-3:3];
>> h = [2, 3, 0, -5, 2, 1]; ny = [-1:4];
>> [y,ny] = conv_m(x,nx,h,nh)
y =
6
31
47
6
-51
ny =
-4
-3
-2
-1
0
-5
41
18
-22
-3
8
2
1
2
3
4
5
6
7
Hence
y(n) = {6, 31, 47, 6, −51, −5, 41, 18, −22, −3, 8, 2}
↑
as in Example 2.6.
An alternate method in MATLAB can be used to perform the convolution. This method uses a matrix-vector multiplication approach, which
we will explore in Problem P2.17.
26
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
SEQUENCE
CORRELATIONS
REVISITED
If we compare the convolution operation (2.12) with that of the crosscorrelation of two sequences defined in (2.6), we observe a close resemblance.
The crosscorrelation ryx () can be put in the form
ryx () = y() ∗ x(−)
with the autocorrelation rxx () in the form
rxx () = x() ∗ x(−)
Therefore these correlations can be computed using the conv m function
if sequences are of finite duration.
EXAMPLE 2.8
In this example we will demonstrate one application of the crosscorrelation
sequence. Let
x(n) = [3, 11, 7, 0, −1, 4, 2]
↑
be a prototype sequence, and let y(n) be its noise-corrupted-and-shifted version
y(n) = x(n − 2) + w(n)
where w(n) is Gaussian sequence with mean 0 and variance 1. Compute the
crosscorrelation between y(n) and x(n).
Solution
From the construction of y(n) it follows that y(n) is “similar” to x(n − 2) and
hence their crosscorrelation would show the strongest similarity at = 2. To
test this out using MATLAB, let us compute the crosscorrelation using two
different noise sequences.
% noise sequence 1
>> x = [3, 11, 7, 0, -1, 4, 2]; nx=[-3:3]; % given signal x(n)
>> [y,ny] = sigshift(x,nx,2);
% obtain x(n-2)
>> w = randn(1,length(y)); nw = ny;
% generate w(n)
>> [y,ny] = sigadd(y,ny,w,nw);
% obtain y(n) = x(n-2) + w(n)
>> [x,nx] = sigfold(x,nx);
% obtain x(-n)
>> [rxy,nrxy] = conv_m(y,ny,x,nx);
% crosscorrelation
>> subplot(1,1,1), subplot(2,1,1);stem(nrxy,rxy)
>> axis([-5,10,-50,250]);xlabel(’lag variable l’)
>> ylabel(’rxy’);title(’Crosscorrelation: noise sequence 1’)
%
% noise sequence 2
>> x = [3, 11, 7, 0, -1, 4, 2]; nx=[-3:3]; % given signal x(n)
>> [y,ny] = sigshift(x,nx,2);
% obtain x(n-2)
>> w = randn(1,length(y)); nw = ny;
% generate w(n)
>> [y,ny] = sigadd(y,ny,w,nw);
% obtain y(n) = x(n-2) + w(n)
>> [x,nx] = sigfold(x,nx);
% obtain x(-n)
>> [rxy,nrxy] = conv_m(y,ny,x,nx);
% crosscorrelation
>> subplot(2,1,2);stem(nrxy,rxy)
>> axis([-5,10,-50,250]);xlabel(’lag variable l’)
>> ylabel(’rxy’);title(’Crosscorrelation: noise sequence 2’)
Convolution
27
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Crosscorrelation: noise sequence 1
250
Maximum
200
rxy
150
100
50
0
−50
−4
−2
0
2
lag variable l
4
6
8
6
8
Crosscorrelation: noise sequence 2
200
Maximum
rxy
150
100
50
0
−50
−4
FIGURE 2.8
−2
0
2
lag variable l
4
Crosscorrelation sequence with two different noise realizations
From Figure 2.8 we observe that the crosscorrelation indeed peaks at = 2,
which implies that y(n) is similar to x(n) shifted by 2. This approach can be
used in applications like radar signal processing in identifying and localizing
targets.
It should be noted that the signal-processing toolbox in MATLAB
also provides a function called xcorr for sequence correlation computations. In its simplest form
>> xcorr(x,y)
computes the crosscorrelation between vectors x and y, while
>> xcorr(x)
computes the autocorrelation of vector x. It generates results that are
identical to the one obtained from the proper use of the conv m function.
However, the xcorr function cannot provide the timing (or lag) information (as done by the conv m function), which then must be obtained by
some other means.
28
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
DIFFERENCE EQUATIONS
An LTI discrete system can also be described by a linear constant coefficient difference equation of the form
N
ak y(n − k) =
M
bm x(n − m),
∀n
(2.19)
m=0
k=0
If aN = 0, then the difference equation is of order N . This equation describes a recursive approach for computing the current output, given the
input values and previously computed output values. In practice this equation is computed forward in time, from n = −∞ to n = ∞. Therefore
another form of this equation is
y(n) =
M
bm x(n − m) −
m=0
N
ak y(n − k)
(2.20)
k=1
A solution to this equation can be obtained in the form
y(n) = yH (n) + yP (n)
The homogeneous part of the solution, yH (n), is given by
yH (n) =
N
ck zkn
k=1
where zk , k = 1, . . . , N are N roots (also called natural frequencies) of the
characteristic equation
N
ak z k = 0
0
This characteristic equation is important in determining the stability of
systems. If the roots zk satisfy the condition
|zk | < 1, k = 1, . . . , N
(2.21)
then a causal system described by (2.20) is stable. The particular part
of the solution, yP (n), is determined from the right-hand side of (2.19).
In Chapter 4 we will discuss the analytical approach of solving difference
equations using the z-transform.
MATLAB
IMPLEMENTATION
A function called filter is available to solve difference equations numerically, given the input and the difference equation coefficients. In its
simplest form this function is invoked by
y = filter(b,a,x)
Difference Equations
29
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where
b = [b0, b1, ..., bM]; a = [a0, a1, ..., aN];
are the coefficient arrays from the equation given in (2.19), and x is the
input sequence array. The output y has the same length as input x. One
must ensure that the coefficient a0 not be zero.
To compute and plot impulse response, MATLAB provides the function impz. When invoked by
h = impz(b,a,n);
it computes samples of the impulse response of the filter at the sample
indices given in n with numerator coefficients in b and denominator coefficients in a. When no output arguments are given, the impz function
plots the response in the current figure window using the stem function.
We will illustrate the use of these functions in the following example.
EXAMPLE 2.9
Given the following difference equation
y(n) − y(n − 1) + 0.9y(n − 2) = x(n);
a.
b.
c.
Solution
∀n
Calculate and plot the impulse response h(n) at n = −20, . . . , 100.
Calculate and plot the unit step response s(n) at n = −20, . . . , 100.
Is the system specified by h(n) stable?
From the given difference equation the coefficient arrays are
b = [1]; a=[1, -1, 0.9];
a. MATLAB Script:
>>
>>
>>
>>
b = [1]; a = [1, -1, 0.9]; n = [-20:120];
impz(b,a,n);
subplot(2,1,1); stem(n,h);
title(’Impulse Response’); xlabel(’n’); ylabel(’h(n)’)
The plot of the impulse response is shown in Figure 2.9.
b. MATLAB Script:
>> x = stepseq(0,-20,120);
s = filter(b,a,x);
>> subplot(2,1,2); stem(n,s)
>> title(’Step Response’); xlabel(’n’); ylabel(’s(n)’)
The plot of the unit step response is shown in Figure 2.9.
30
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Impulse Response
1
h(n)
0.5
0
−0.5
−1
−20
0
20
40
60
80
100
120
80
100
120
n
Step Response
2
s(n)
1.5
1
0.5
0
−0.5
−20
0
20
40
60
n
FIGURE 2.9
Impulse response and step response plots in Example 2.9
c. To determine the stability of the system, we have to determine h(n) for all n.
Although we have not described a method to solve the difference equation,
we can use the plot of the impulse
response to observe that h(n) is practically
zero for n > 120. Hence the sum
|h(n)| can be determined from MATLAB
using
>> sum(abs(h))
ans = 14.8785
which implies that the system is stable. An alternate approach is to use the
stability condition (2.21) using MATLAB’s roots function.
>>z = roots(a);
magz = 0.9487
0.9487
magz = abs(z)
Since the magnitudes of both roots are less than one, the system is stable.
In the previous section we noted that if one or both sequences in
the convolution are of infinite length, then the conv function cannot be
used. If one of the sequences is of infinite length, then it is possible to use
MATLAB for numerical evaluation of the convolution. This is done using
the filter function as we will see in the following example.
Difference Equations
31
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Output sequence
8
y(n)
6
4
2
0
−5
0
5
10
15
20
25
30
35
40
45
n
FIGURE 2.10
EXAMPLE 2.10
Output sequence in Example 2.10
Let us consider the convolution given in Example 2.5. The input sequence is of
finite duration
x(n) = u(n) − u(n − 10)
while the impulse response is of infinite duration
h(n) = (0.9)n u(n)
Determine y(n) = x(n) ∗ h(n).
Solution
If the LTI system, given by the impulse response h(n), can be described by a
difference equation, then y(n) can be obtained from the filter function. From
the h(n) expression
(0.9) h(n − 1) = (0.9) (0.9)n−1 u(n − 1) = (0.9)n u(n − 1)
or
h(n) − (0.9) h(n − 1) = (0.9)n u(n) − (0.9)n u(n − 1)
= (0.9)n [u(n) − u(n − 1)] = (0.9)n δ(n)
= δ(n)
The last step follows from the fact that δ(n) is nonzero only at n = 0. By
definition h(n) is the output of an LTI system when the input is δ(n). Hence
substituting x(n) for δ(n) and y(n) for h(n), the difference equation is
y(n) − 0.9y(n − 1) = x(n)
Now MATLAB’s filter function can be used to compute the convolution
indirectly.
>>
>>
>>
>>
>>
32
b = [1]; a = [1,-0.9];
n = -5:50; x = stepseq(0,-5,50) - stepseq(10,-5,50);
y = filter(b,a,x);
subplot(2,1,2); stem(n,y); title(’Output sequence’)
xlabel(’n’); ylabel(’y(n)’); axis([-5,50,-0.5,8])
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The plot of the output is shown in Figure 2.10, which is exactly the same as
that in Figure 2.6.
In Example 2.10 the impulse response was a one-sided exponential sequence for which we could determine a difference equation representation.
This means that not all infinite-length impulse responses can be converted
into difference equations. The above analysis, however, can be extended to
a linear combination of one-sided exponential sequences, which results in
higher-order difference equations. We will discuss this topic of conversion
from one representation to another one in Chapter 4.
ZERO-INPUT
AND
ZERO-STATE
RESPONSES
In digital signal processing the difference equation is generally solved forward in time from n = 0. Therefore initial conditions on x(n) and y(n)
are necessary to determine the output for n ≥ 0. The difference equation
is then given by
y(n) =
M
bm x(n − m) −
m=0
N
ak y(n − k); n ≥ 0
(2.22)
k=1
subject to the initial conditions:
{y(n); −N ≤ n ≤ −1}
and
{x(n); −M ≤ n ≤ −1}
A solution to (2.22) can be obtained in the form
y(n) = yZI (n) + yZS (n)
where yZI (n) is called the zero-input solution, which is a solution due
to the initial conditions alone (assuming they exist), while the zero-state
solution, yZS (n), is a solution due to input x(n) alone (or assuming that
the initial conditions are zero). In MATLAB another form of the function
filter can be used to solve for the difference equation, given its initial
conditions. We will illustrate the use of this form in Chapter 4.
DIGITAL
FILTERS
Filter is a generic name that means a linear time-invariant system designed for a specific job of frequency selection or frequency discrimination.
Hence discrete-time LTI systems are also called digital filters. There are
two types of digital filters.
FIR filter If the unit impulse response of an LTI system is of finite
duration, then the system is called a finite-duration impulse response (or
FIR) filter. Hence for an FIR filter h(n) = 0 for n < n1 and for n > n2 .
Difference Equations
33
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The following part of the difference equation (2.19) describes a causal FIR
filter:
M
y(n) =
bm x(n − m)
(2.23)
m=0
Furthermore, h(0) = b0 , h(1) = b1 , . . . , h(M ) = bM , while all other h(n)’s
are 0. FIR filters are also called nonrecursive or moving average (MA)
filters. In MATLAB FIR filters are represented either as impulse response
values {h(n)} or as difference equation coefficients {bm } and {a0 = 1}.
Therefore to implement FIR filters, we can use either the conv(x,h)
function (and its modification that we discussed) or the filter(b,1,x)
function. There is a difference in the outputs of these two implementations
that should be noted. The output sequence from the conv(x,h) function
has a longer length than both the x(n) and h(n) sequences. On the other
hand, the output sequence from the filter(b,1,x) function has exactly
the same length as the input x(n) sequence. In practice (and especially
for processing signals) the use of the filter function is encouraged.
IIR filter If the impulse response of an LTI system is of infinite duration, then the system is called an infinite-duration impulse response (or
IIR) filter. The following part of the difference equation (2.19):
N
ak y(n − k) = x(n)
(2.24)
k=0
describes a recursive filter in which the output y(n) is recursively computed from its previously computed values and is called an autoregressive
(AR) filter. The impulse response of such filter is of infinite duration and
hence it represents an IIR filter. The general equation (2.19) also describes
an IIR filter. It has two parts: an AR part and an MA part. Such an IIR
filter is called an autoregressive moving average, or an ARMA, filter. In
MATLAB IIR filters are described by the difference equation coefficients
{bm } and {ak } and are implemented by the filter(b,a,x) function.
PROBLEMS
P2.1 Generate the following sequences using the basic MATLAB signal functions and the basic
MATLAB signal operations discussed in this chapter. Plot signal samples using the stem
function.
1. x1 (n) = 3δ(n + 2) + 2δ(n) − δ(n − 3) + 5δ(n − 7), −5 ≤ n ≤ 15.
2. x2 (n) =
5
k=−5
e−|k| δ(n − 2k), −10 ≤ n ≤ 10.
3. x3 (n) = 10u(n) − 5u(n − 5) − 10u(n − 10) + 5u(n − 15).
34
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4. x4 (n) = e0.1n [u(n + 20) − u(n − 10)].
5. x5 (n) = 5[cos(0.49πn) + cos(0.51πn)], −200 ≤ n ≤ 200. Comment on the waveform
shape.
6. x6 (n) = 2 sin(0.01πn) cos(0.5πn), −200 ≤ n ≤ 200. Comment on the waveform shape.
7. x7 (n) = e−0.05n sin(0.1πn + π/3), 0 ≤ n ≤ 100. Comment on the waveform shape.
8. x8 (n) = e0.01n sin(0.1πn), 0 ≤ n ≤ 100. Comment on the waveform shape.
P2.2 Generate the following random sequences and obtain their histogram using the hist
function with 100 bins. Use the bar function to plot each histogram.
1. x1 (n) is a random sequence whose samples are independent and uniformly distributed
over [0, 2] interval. Generate 100,000 samples.
2. x2 (n) is a Gaussian random sequence whose samples are independent with mean 10 and
variance 10. Generate 10,000 samples.
3. x3 (n) = x1 (n) + x1 (n − 1) where x1 (n) is the random sequence given in part 1 above.
Comment
the shape of this histogram and explain the shape.
on
4
4. x4 (n) = k=1 yk (n) where each random sequence yk (n) is independent of others with
samples uniformly distributed over [−0.5, 0.5]. Comment on the shape of this histogram.
P2.3 Generate the following periodic sequences and plot their samples (using the stem function)
over the indicated number of periods.
1. x̃1 (n) = {. . . , −2, −1, 0, 1, 2, . . .}periodic . Plot 5 periods.
↑
2. x̃2 (n) = e0.1n [u(n) − u(n − 20]periodic . Plot 3 periods.
3. x̃3 (n) = sin(0.1πn)[u(n) − u(n − 10)]. Plot 4 periods.
4. x̃4 (n) = {. . . , 1, 2, 3, . . .}periodic + {. . . , 1, 2, 3, 4, . . .}periodic , 0 ≤ n ≤ 24. What is the
↑
↑
period of x̃4 (n)?
P2.4 Let x(n) = {2, 4, −3, 1, −5, 4, 7}. Generate and plot the samples (use the stem function) of
↑
the following sequences.
1.
2.
3.
4.
x1 (n) = 2x(n − 3) + 3x(n + 4) − x(n)
x2 (n) = 4x(4 + n) + 5x(n + 5) + 2x(n)
x3 (n) = x(n + 3)x(n − 2) + x(1 − n)x(n + 1)
x4 (n) = 2e0.5n x(n) + cos (0.1πn) x (n + 2) , −10 ≤ n ≤ 10
P2.5 The complex exponential sequence ejω0 n or the sinusoidal sequence cos (ω0 n) are periodic if
K
ω0
the normalized frequency f0 =
is a rational number; that is, f0 = , where K and N
2π
N
are integers.
1. Prove the above result.
2. Generate exp(0.1πn), −100 ≤ n ≤ 100. Plot its real and imaginary parts using the stem
function. Is this sequence periodic? If it is, what is its fundamental period? From the
examination of the plot what interpretation can you give to the integers K and N above?
3. Generate and plot cos(0.1n), −20 ≤ n ≤ 20. Is this sequence periodic? What do you
conclude from the plot? If necessary examine the values of the sequence in MATLAB to
arrive at your answer.
Problems
35
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P2.6 Using the evenodd function, decompose the following sequences into their even and odd
components. Plot these components using the stem function.
1. x1 (n) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
↑
2. x2 (n) = e0.1n [u(n + 5) − u(n − 10)].
3. x3 (n) = cos(0.2πn + π/4), −20 ≤ n ≤ 20.
4. x4 (n) = e−0.05n sin(0.1πn + π/3), 0 ≤ n ≤ 100.
P2.7 A complex-valued sequence xe (n) is called conjugate-symmetric if xe (n) = x∗e (−n) and a
complex-valued sequence xo (n) is called conjugate-antisymmetric if xo (n) = −x∗o (−n).
Then, any arbitrary complex-valued sequence x(n) can be decomposed into
x(n) = xe (n) + xo (n) where xe (n) and xo (n) are given by
xe (n) =
1
[x(n) + x∗ (−n)]
2
and
xo (n) =
1
[x(n) − x∗ (−n)]
2
(2.25)
respectively.
1. Modify the evenodd function discussed in the text so that it accepts an arbitrary
sequence and decomposes it into its conjugate-symmetric and conjugate-antisymmetric
components by implementing (2.1).
2. Decompose the following sequence:
x(n) = 10 exp([−0.1 + 0.2π]n),
0 ≤ n ≤ 10
into its conjugate-symmetric and conjugate-antisymmetric components. Plot their real
and imaginary parts to verify the decomposition. (Use the subplot function.)
P2.8 The operation of signal dilation (or decimation or down-sampling) is defined by
y(n) = x(nM )
in which the sequence x(n) is down-sampled by an integer factor M . For example, if
x(n) = {. . . , −2, 4, 3, −6, 5, −1, 8, . . .}
↑
then the down-sampled sequences by a factor 2 are given by
y(n) = {. . . , −2, 3, 5, 8, . . .}
↑
1. Develop a MATLAB function dnsample that has the form
function [y,m] = dnsample(x,n,M)
% Downsample sequence x(n) by a factor M to obtain y(m)
to implement the above operation. Use the indexing mechanism of MATLAB with
careful attention to the origin of the time axis n = 0.
2. Generate x(n) = sin(0.125πn), − 50 ≤ n ≤ 50. Decimate x(n) by a factor of 4 to
generate y(n). Plot both x(n) and y(n) using subplot and comment on the results.
3. Repeat the above using x(n) = sin(0.5πn), − 50 ≤ n ≤ 50. Qualitatively discuss the
effect of down-sampling on signals.
36
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P2.9 Using the conv_m function, determine the autocorrelation sequence rxx () and the
crosscorrelation sequence rxy () for the following sequences.
x(n) = (0.9)n ,
0 ≤ n ≤ 20;
y(n) = (0.8)−n ,
− 20 ≤ n ≤ 0
Describe your observations of the above results.
P2.10 In a certain concert hall, echoes of the original audio signal x(n) are generated due to the
reflections at the walls and ceiling. The audio signal experienced by the listener y(n) is a
combination of x(n) and its echoes. Let
y(n) = x(n) + αx(n − k)
where k is the amount of delay in samples and α is its relative strength. We want to
estimate the delay using the correlation analysis.
1. Determine analytically the autocorrelation ryy () in terms of the autocorrelation rxx ().
2. Let x(n) = cos(0.2πn) + 0.5 cos(0.6πn), α = 0.1, and k = 50. Generate 200 samples of
y(n) and determine its autocorrelation. Can you obtain α and k by observing ryy ()?
P2.11 Consider the following discrete-time systems:
T1 [x(n)] = x(n)u(n)
T3 [x(n)] = x(n) +
1
1
x(n − 2) − x(n − 3)x(2n)
2
3
T5 [x(n)] = x(2n)
T2 [x(n)] = x(n) + n x(n + 1)
T4 [x(n)] =
n+5
k=−∞
2x(k)
T6 [x(n)] = round[x(n)]
where round[·] denotes rounding to the nearest integer.
1. Use (2.8) to determine analytically whether the above systems are linear.
2. Let x1 (n) be a uniformly distributed random sequence between [0, 1] over 0 ≤ n ≤ 100,
and let x2 (n) be a Gaussian random sequence with mean 0 and variance 10 over
0 ≤ n ≤ 100. Using these sequences, verify the linearity of the above systems. Choose
any values for constants a1 and a2 in (2.8). You should use several realizations of the
above sequences to arrive at your answers.
P2.12 Consider the discrete-time systems given in Problem P2.11.
1. Use (2.10) to determine analytically whether the above systems are time-invariant.
2. Let x(n) be a Gaussian random sequence with mean 0 and variance 10 over 0 ≤ n ≤ 100.
Using this sequence, verify the time invariance of the above systems. Choose any values
for sample shift k in (2.10). You should use several realizations of the above sequence to
arrive at your answers.
P2.13 For the systems given in Problem P2.11 determine analytically their stability and causality.
P2.14 The linear convolution defined in (2.12) has several properties:
x1 (n) ∗ x2 (n) = x1 (n) ∗ x2 (n)
[x1 (n) ∗ x2 (n)] ∗ x3 (n) = x1 (n) ∗ [x2 (n) ∗ x3 (n)]
: Association
x1 (n) ∗ [x2 (n) + x3 (n)] = x1 (n) ∗ x2 (n) + x1 (n) ∗ x3 (n)
: Distribution
x(n) ∗ δ(n − n0 ) = x(n − n0 )
Problems
: Commutation
(2.26)
: Identity
37
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1. Analytically prove these properties.
2. Using the following three sequences, verify the above properties.
x1 (n) = cos(πn/4)[u(n + 5) − u(n − 25)]
x2 (n) = (0.9)−n [u(n) − u(n − 20)]
x3 (n) = round[5w(n)], −10 ≤ n ≤ 10; where w(n) is uniform over [−1, 1]
Use the conv m function.
P2.15 Determine analytically the convolution y(n) = x(n) ∗ h(n) of the following sequences and
verify your answers using the conv_m function.
1. x(n) = {2, −4, 5, 3, −1, −2, 6}, h(n) = {1, −1, 1, −1, 1}
↑
2. x(n) = {1, 1, 0, 1, 1}, h(n) = {1, −2, −3, 4}
↑
↑
↑
3. x(n) = (1/4)−n [u(n + 1) − u(n − 4)], h(n) = u(n) − u(n − 5)
4. x(n) = n/4[u(n) − u(n − 6)], h(n) = 2[u(n + 2) − u(n − 3)]
P2.16 Let x(n) = (0.8)n u(n), h(n) = (−0.9)n u(n), and y(n) = h(n) ∗ x(n). Use three columns and
one row of subplots for the following parts.
1. Determine y(n) analytically. Plot first 51 samples of y(n) using the stem function.
2. Truncate x(n) and h(n) to 26 samples. Use conv function to compute y(n). Plot y(n)
using the stem function. Compare your results with those of part 1.
3. Using the filter function, determine the first 51 samples of x(n) ∗ h(n). Plot y(n) using
the stem function. Compare your results with those of parts 1 and 2.
P2.17 When the sequences x(n) and h(n) are of finite duration Nx and Nh , respectively, then
their linear convolution (2.11) can also be implemented using matrix-vector multiplication.
If elements of y(n) and x(n) are arranged in column vectors x and y respectively, then from
(2.11) we obtain
y = Hx
where linear shifts in h(n − k) for n = 0, . . . , Nh − 1 are arranged as rows in the matrix H.
This matrix has an interesting structure and is called a Toeplitz matrix. To investigate this
matrix, consider the sequences
x(n) = {1, 2, 3, 4, 5}
and
↑
h(n) = {6, 7, 8, 9}
↑
1. Determine the linear convolution y(n) = h(n) ∗ x(n).
2. Express x(n) as a 5 × 1 column vector x and y(n) as a 8 × 1 column vector y. Now
determine the 8 × 5 matrix H so that y = Hx.
3. Characterize the matrix H. From this characterization can you give a definition of a
Toeplitz matrix? How does this definition compare with that of time invariance?
4. What can you say about the first column and the first row of H?
P2.18 MATLAB provides a function called toeplitz to generate a Toeplitz matrix, given the first
row and the first column.
1. Using this function and your answer to Problem P2.17 part 4, develop another MATLAB
function to implement linear convolution. The format of the function should be
38
Chapter 2
DISCRETE-TIME SIGNALS AND SYSTEMS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
function [y,H]=conv_tp(h,x)
% Linear Convolution using Toeplitz Matrix
% ---------------------------------------% [y,H] = conv_tp(h,x)
% y = output sequence in column vector form
% H = Toeplitz matrix corresponding to sequence h so that y = Hx
% h = Impulse response sequence in column vector form
% x = input sequence in column vector form
2. Verify your function on the sequences given in Problem P2.17.
P2.19 A linear and time-invariant system is described by the difference equation
y(n) − 0.5y(n − 1) + 0.25y(n − 2) = x(n) + 2x(n − 1) + x(n − 3)
1. Using the filter function, compute and plot the impulse response of the system over
0 ≤ n ≤ 100.
2. Determine the stability of the system from the above impulse response.
3. If the input to this system is x(n) = [5 + 3 cos(0.2πn) + 4 sin(0.6πn)] u(n), determine the
response y(n) over 0 ≤ n ≤ 200 using the filter function.
P2.20 A “simple” digital differentiator is given by
y(n) = x(n) − x(n − 1)
which computes a backward first-order difference of the input sequence. Implement this
differentiator on the following sequences and plot the results. Comment on the
appropriateness of this simple differentiator.
1. x(n) = 5 [u(n) − u(n − 20)]: a rectangular pulse
2. x(n) = n [u(n) − u(n − 10)] + (20 − n) [u(n − 10) − u(n − 20)]: a triangular pulse
πn
3. x(n) = sin
[u(n) − u(n − 100)]: a sinusoidal pulse
25
Problems
39
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
3
The Discrete-time
Fourier Analysis
We have seen how a linear and time-invariant system can be represented
using its response to the unit sample sequence. This response, called the
unit impulse response h(n), allows us to compute the system response to
any arbitrary input x(n) using the linear convolution as shown below.
x(n) −→ h(n) −→ y(n) = h(n) ∗ x(n)
This convolution representation is based on the fact that any signal
can be represented by a linear combination of scaled and delayed unit
samples. Similarly, we can also represent any arbitrary discrete signal
as a linear combination of basis signals introduced in Chapter 2. Each
basis signal set provides a new signal representation. Each representation
has some advantages and some disadvantages depending upon the type
of system under consideration. However, when the system is linear and
time-invariant, only one representation stands out as the most useful. It
is based on the complex exponential signal set {ejωn } and is called the
Discrete-time Fourier Transform.
THE DISCRETE-TIME FOURIER TRANSFORM (DTFT)
If x(n) is absolutely summable, that is,
time Fourier transform is given by
X(ejω ) = F[x(n)] =
∞
−∞
∞
|x(n)| < ∞, then its discretex(n)e−jωn
(3.1)
n=−∞
40
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The inverse discrete-time Fourier transform (IDTFT) of X(ejω ) is given
by
π
1
x(n) = F −1 [X(ejω )] =
X(ejω )ejωn dω
(3.2)
2π
−π
The operator F[·] transforms a discrete signal x(n) into a complex-valued
continuous function X(ejω ) of real variable ω, called a digital frequency,
which is measured in radians/sample.
EXAMPLE 3.1
Solution
Determine the discrete-time Fourier transform of x(n) = (0.5)n u(n).
The sequence x(n) is absolutely summable; therefore its discrete-time Fourier
transform exists.
X(ejω ) =
∞
x(n)e−jωn =
∞
−∞
0
∞
=
0
EXAMPLE 3.2
(0.5)n e−jωn
(0.5e−jω )n =
1
ejω
= jω
−jω
1 − 0.5e
e − 0.5
Determine the discrete-time Fourier transform of the following finite-duration
sequence:
x(n) = {1, 2, 3, 4, 5}
↑
Solution
Using definition (3.1),
jω
X(e ) =
∞
x(n)e−jωn = ejω + 2 + 3e−jω + 4e−j2ω + 5e−j3ω
−∞
Since X(ejω ) is a complex-valued function, we will have to plot its
magnitude and its angle (or the real and the imaginary part) with respect
to ω separately to visually describe X(ejω ). Now ω is a real variable
between −∞ and ∞, which would mean that we can plot only a part of the
X(ejω ) function using MATLAB. Using two important properties of the
discrete-time Fourier transform, we can reduce this domain to the [0, π]
interval for real-valued sequences. We will discuss other useful properties
of X(ejω ) in the next section.
TWO
IMPORTANT
PROPERTIES
We will state the following two properties without proof.
1. Periodicity: The discrete-time Fourier transform X(ejω ) is periodic
in ω with period 2π.
X(ejω ) = X(ej[ω+2π] )
The Discrete-time Fourier Transform (DTFT)
41
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Implication: We need only one period of X(ejω ) (i.e., ω ∈[0, 2π], or
[−π, π], etc.) for analysis and not the whole domain −∞ < ω < ∞.
2. Symmetry: For real-valued x(n), X(ejω ) is conjugate symmetric.
X(e−jω ) = X ∗ (ejω )
or
Re[X(e−jω )] = Re[X(ejω )]
(even symmetry)
Im[X(e−jω )] = − Im[X(ejω )]
|X(e−jω )| = |X(ejω )|
−jω
X(e
(even symmetry)
) = − X(e )
jω
(odd symmetry)
(odd symmetry)
jω
Implication: To plot X(e ), we now need to consider only a half
period of X(ejω ). Generally, in practice this period is chosen to be
ω ∈ [0, π].
MATLAB
IMPLEMENTATION
If x(n) is of infinite duration, then MATLAB cannot be used directly
to compute X(ejω ) from x(n). However, we can use it to evaluate the
expression X(ejω ) over [0, π] frequencies and then plot its magnitude and
angle (or real and imaginary parts).
Evaluate X(ejω ) in Example 3.1 at 501 equispaced points between [0, π] and
plot its magnitude, angle, real, and imaginary parts.
EXAMPLE 3.3
Solution
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
MATLAB Script:
w = [0:1:500]*pi/500; % [0, pi] axis divided into 501 points.
X = exp(j*w) ./ (exp(j*w) - 0.5*ones(1,501));
magX = abs(X); angX = angle(X); realX = real(X); imagX = imag(X);
subplot(2,2,1); plot(w/pi,magX); grid
xlabel(’frequency in pi units’); title(’Magnitude Part’); ylabel(’Magnitude’)
subplot(2,2,3); plot(w/pi,angX); grid
xlabel(’frequency in pi units’); title(’Angle Part’); ylabel(’Radians’)
subplot(2,2,2); plot(w/pi,realX); grid
xlabel(’frequency in pi units’); title(’Real Part’); ylabel(’Real’)
subplot(2,2,4); plot(w/pi,imagX); grid
xlabel(’frequency in pi units’); title(’Imaginary Part’); ylabel(’Imaginary’)
The resulting plots are shown in Figure 3.1. Note that we divided the w array by
pi before plotting so that the frequency axes are in the units of π and therefore
easier to read. This practice is strongly recommended.
42
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Real Part
2
1.5
1.5
Real
Magnitude
Magnitude Part
2
1
1
0.5
0
0.5
0.5
0
1
frequency in pi units
0.5
frequency in pi units
Angle Part
1
Imaginary Part
0
0
Imaginary
Radians
–0.2
–0.2
–0.4
–0.4
–0.6
–0.6
0
FIGURE 3.1
0.5
frequency in pi units
1
–0.8
0
0.5
frequency in pi units
1
Plots in Example 3.3
If x(n) is of finite duration, then MATLAB can be used to compute
X(ejω ) numerically at any frequency ω. The approach is to implement
(3.1) directly. If, in addition, we evaluate X(ejω ) at equispaced frequencies between [0, π], then (3.1) can be implemented as a matrix-vector multiplication operation. To understand this, let us assume that the sequence
x(n) has N samples between n1 ≤ n ≤ nN (i.e., not necessarily between
[0, N − 1]) and that we want to evaluate X(ejω ) at
ωk =
π
k,
M
k = 0, 1, . . . , M
which are (M + 1) equispaced frequencies between [0, π]. Then (3.1) can
be written as
X(ejωk ) =
N
e−j(π/M )kn x(n ),
k = 0, 1, . . . , M
=1
When {x (n )} and {X(ejωk )} are arranged as column vectors x and X,
respectively, we have
X = Wx
The Discrete-time Fourier Transform (DTFT)
(3.3)
43
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where W is an (M + 1) × N matrix given by
W = e−j(π/M )kn ; n1 ≤ n ≤ nN , k = 0, 1, . . . , M
In addition, if we arrange {k} and {n } as row vectors k and n respectively,
then
π
W = exp −j kT n
M
In MATLAB we represent sequences and indices as row vectors; therefore
taking the transpose of (3.3), we obtain
π
XT = xT exp −j nT k
M
(3.4)
Note that nT k is an N × (M + 1) matrix. Now (3.4) can be implemented
in MATLAB as follows.
>> k = [0:M]; n = [n1:n2];
>> X = x * (exp(-j*pi/M)) .^ (n’*k);
EXAMPLE 3.4
Solution
Numerically compute the discrete-time Fourier transform of the sequence x(n)
given in Example 3.2 at 501 equispaced frequencies between [0, π].
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
n = -1:3; x = 1:5; k = 0:500; w = (pi/500)*k;
X = x * (exp(-j*pi/500)) .^ (n’*k);
magX = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
subplot(2,2,1); plot(k/500,magX);grid
xlabel(’frequency in pi units’); title(’Magnitude Part’)
subplot(2,2,3); plot(k/500,angX/pi);grid
xlabel(’frequency in pi units’); title(’Angle Part’)
subplot(2,2,2); plot(k/500,realX);grid
xlabel(’frequency in pi units’); title(’Real Part’)
subplot(2,2,4); plot(k/500,imagX);grid
xlabel(’frequency in pi units’); title(’Imaginary Part’)
The frequency-domain plots are shown in Figure 3.2. Note that the angle plot
is depicted as a discontinuous function between −π and π. This is because the
angle function in MATLAB computes the principal angle.
The procedure of the above example can be compiled into a MATLAB
function, say a dtft function, for ease of implementation. This is explored
44
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Part
Real Part
15
15
Real
Magnitude
10
10
5
5
0
0
0
0.5
frequency in pi units
–5
1
0
Angle Part
0.5
frequency in pi units
1
Imaginary Part
4
5
Imaginary
Radians
2
0
0
–5
–2
–4
0
FIGURE 3.2
0.5
frequency in pi units
1
–10
0
0.5
frequency in pi units
1
Plots in Example 3.4
in Problem P3.1. This numerical computation is based on definition (3.1).
It is not the most elegant way of numerically computing the discretetime Fourier transform of a finite-duration sequence. In Chapter 5 we will
discuss in detail the topic of a computable transform called the discrete
Fourier transform (DFT) and its efficient computation called the fast
Fourier transform (FFT). Also there is an alternate approach based on the
z-transform using the MATLAB function freqz, which we will discuss in
Chapter 4. In this chapter we will continue to use the approaches discussed
so far for calculation as well as for investigation purposes.
In the next two examples we investigate the periodicity and symmetry
properties using complex-valued and real-valued sequences.
EXAMPLE 3.5
Solution
Let x(n) = (0.9 exp (jπ/3))n ,
its periodicity.
0 ≤ n ≤ 10. Determine X(ejω ) and investigate
Since x(n) is complex-valued, X(ejω ) satisfies only the periodicity property.
Therefore it is uniquely defined over one period of 2π. However, we will evaluate
and plot it at 401 frequencies over two periods between [−2π, 2π] to observe its
periodicity.
The Discrete-time Fourier Transform (DTFT)
45
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
n = 0:10; x = (0.9*exp(j*pi/3)).^n;
k = -200:200; w = (pi/100)*k;
X = x * (exp(-j*pi/100)) .^ (n’*k);
magX = abs(X); angX =angle(X);
subplot(2,1,1); plot(w/pi,magX);grid
xlabel(’frequency in units of pi’); ylabel(’|X|’)
title(’Magnitude Part’)
subplot(2,1,2); plot(w/pi,angX/pi);grid
xlabel(’frequency in units of pi’); ylabel(’radians/pi’)
title(’Angle Part’)
From the plots in Figure 3.3 we observe that X(ejω ) is periodic in ω but is not
conjugate-symmetric.
Magnitude Part
8
|X|
6
4
2
0
−2
−1.5
−1
−0.5
0
0.5
frequency in units of pi
1
1.5
2
1
1.5
2
Angle Part
1
radians/pi
0.5
0
−0.5
−1
−2
FIGURE 3.3
EXAMPLE 3.6
Solution
46
−1.5
−1
−0.5
0
0.5
frequency in units of pi
Plots in Example 3.5
Let x(n) = 2n , −10 ≤ n ≤ 10. Investigate the conjugate-symmetry property
of its discrete-time Fourier transform.
Once again we will compute and plot X(ejω ) over two periods to study its
symmetry property.
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Part
15
|X|
10
5
0
−2
−1.5
−1
−0.5
0
0.5
frequency in units of pi
1
1.5
2
1
1.5
2
Angle Part
1
radians/pi
0.5
0
−0.5
−1
−2
FIGURE 3.4
−1.5
−1
−0.5
0
0.5
frequency in units of pi
Plots in Example 3.6
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
>>
>>
n = -5:5; x = (-0.9).^n;
k = -200:200; w = (pi/100)*k; X = x * (exp(-j*pi/100)) .^ (n’*k);
magX = abs(X); angX =angle(X);
subplot(2,1,1); plot(w/pi,magX);grid; axis([-2,2,0,15])
xlabel(’frequency in units of pi’); ylabel(’|X|’)
title(’Magnitude Part’)
subplot(2,1,2); plot(w/pi,angX/pi);grid; axis([-2,2,-1,1])
xlabel(’frequency in units of pi’); ylabel(’radians/pi’)
title(’Angle Part’)
From the plots in Figure 3.4 we observe that X(ejω ) is not only periodic in ω
but is also conjugate-symmetric. Therefore for real sequences we will plot their
Fourier transform magnitude and angle graphs from 0 to π.
THE PROPERTIES OF THE DTFT
In the previous section we discussed two important properties that we
needed for plotting purposes. We now discuss the remaining useful
The Properties of the DTFT
47
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
properties, which are given below without proof. Let X(ejω ) be the
discrete-time Fourier transform of x(n).
1. Linearity: The discrete-time Fourier transform is a linear transformation; that is,
F [αx1 (n) + βx2 (n)] = αF [x1 (n)] + βF [x2 (n)]
(3.5)
for every α, β, x1 (n), and x2 (n).
2. Time shifting: A shift in the time domain corresponds to the phase
shifting.
F [x(n − k)] = X(ejω )e−jωk
(3.6)
3. Frequency shifting: Multiplication by a complex exponential corresponds to a shift in the frequency domain.
F x(n)ejω0 n = X(ej(ω−ω0 ) )
(3.7)
4. Conjugation: Conjugation in the time domain corresponds to the
folding and conjugation in the frequency domain.
F [x∗ (n)] = X ∗ (e−jω )
(3.8)
5. Folding: Folding in the time domain corresponds to the folding in the
frequency domain.
F [x(−n)] = X(e−jω )
(3.9)
6. Symmetries in real sequences: We have already studied the conjugate symmetry of real sequences. These real sequences can be decomposed into their even and odd parts as we discussed in Chapter 2.
x(n) = xe (n) + xo (n)
Then
F [xe (n)] = Re X(ejω )
F [xo (n)] = j Im X(ejω )
(3.10)
Implication: If the sequence x(n) is real and even, then X(ejω ) is
also real and even. Hence only one plot over [0, π] is necessary for its
complete representation.
A similar property for complex-valued sequences is explored in
Problem P3.7.
7. Convolution: This is one of the most useful properties that makes
system analysis convenient in the frequency domain.
F [x1 (n) ∗ x2 (n)] = F [x1 (n)] F [x2 (n)] = X1 (ejω )X2 (ejω )
48
Chapter 3
(3.11)
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
8. Multiplication: This is a dual of the convolution property.
π
1
∗
F [x2 (n)] =
X1 (ejθ )X2 (ej(ω−θ) )dθ
F [x1 (n) · x2 (n)] = F [x1 (n)]
2π −π
(3.12)
The convolution-like operation above is called a periodic convolution
and hence denoted by ∗ . It is discussed (in its discrete form) in
Chapter 5.
9. Energy: The energy of the sequence x(n) can be written as
∞
1
Ex =
|x(n)| =
2π
−∞
π
=
π
|X(ejω )|2 dω
2
|X(ejω )|2
dω
π
(3.13)
−π
(for real sequences using even symmetry)
0
This is also known as Parseval’s Theorem. From (3.13) the energy density spectrum of x(n) is defined as
Φx (ω) =
|X(ejω )|2
π
(3.14)
Then the energy of x(n) in the [ω1 , ω2 ] band is given by
ω2
Φx (ω)dω,
0 ≤ ω1 < ω 2 ≤ π
ω1
In the next several examples we will verify some of these properties
using finite-duration sequences. We will follow our numerical procedure
to compute discrete-time Fourier transforms in each case. Although this
does not analytically prove the validity of each property, it provides us
with an experimental tool in practice.
EXAMPLE 3.7
In this example we will verify the linearity property (3.5) using real-valued finiteduration sequences. Let x1 (n) and x2 (n) be two random sequences uniformly
distributed between [0, 1] over 0 ≤ n ≤ 10. Then we can use our numerical
discrete-time Fourier transform procedure as follows.
MATLAB Script:
>>
>>
>>
>>
>>
x1 = rand(1,11); x2 = rand(1,11); n = 0:10;
alpha = 2; beta = 3; k = 0:500; w = (pi/500)*k;
X1 = x1 * (exp(-j*pi/500)).^(n’*k); % DTFT of x1
X2 = x2 * (exp(-j*pi/500)).^(n’*k); % DTFT of x2
x = alpha*x1 + beta*x2;
% Linear combination of x1 & x2
The Properties of the DTFT
49
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> X = x * (exp(-j*pi/500)).^(n’*k);
>> % verification
>> X_check = alpha*X1 + beta*X2;
>> error = max(abs(X-X_check))
error =
7.1054e-015
% DTFT of x
% Linear Combination of X1 & X2
% Difference
Since the maximum absolute error between the two Fourier transform arrays
is less than 10−14 , the two arrays are identical within the limited numerical
precision of MATLAB.
EXAMPLE 3.8
Let x(n) be a random sequence uniformly distributed between [0, 1] over 0 ≤
n ≤ 10 and let y(n) = x(n − 2). Then we can verify the sample shift property
(3.6) as follows.
>> x = rand(1,11); n = 0:10;
>> k = 0:500; w = (pi/500)*k;
>> X = x * (exp(-j*pi/500)).^(n’*k);
>> % signal shifted by two samples
>> y = x; m = n+2;
>> Y = y * (exp(-j*pi/500)).^(m’*k);
>> % verification
>> Y_check = (exp(-j*2).^w).*X;
>> error = max(abs(Y-Y_check))
error =
5.7737e-015
EXAMPLE 3.9
% DTFT of x
% DTFT of y
% multiplication by exp(-j2w)
% Difference
To verify the frequency shift property (3.7), we will use the graphical approach.
Let
x(n) = cos(πn/2),
0 ≤ n ≤ 100
and
y(n) = ejπn/4 x(n)
Then using MATLAB,
>> n = 0:100; x = cos(pi*n/2);
>> k = -100:100; w = (pi/100)*k;
% frequency between -pi and +pi
>> X = x * (exp(-j*pi/100)).^(n’*k);
% DTFT of x
%
>> y = exp(j*pi*n/4).*x;
% signal multiplied by exp(j*pi*n/4)
>> Y = y * (exp(-j*pi/100)).^(n’*k);
% DTFT of y
% Graphical verification
>> subplot(2,2,1); plot(w/pi,abs(X)); grid; axis([-1,1,0,60])
>> xlabel(’frequency in pi units’); ylabel(’|X|’)
>> title(’Magnitude of X’)
>> subplot(2,2,2); plot(w/pi,angle(X)/pi); grid; axis([-1,1,-1,1])
>> xlabel(’frequency in pi units’); ylabel(’radiands/pi’)
>> title(’Angle of X’)
>> subplot(2,2,3); plot(w/pi,abs(Y)); grid; axis([-1,1,0,60])
50
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>>
>>
>>
>>
>>
xlabel(’frequency in pi units’); ylabel(’|Y|’)
title(’Magnitude of Y’)
subplot(2,2,4); plot(w/pi,angle(Y)/pi); grid; axis([-1,1,-1,1])
xlabel(’frequency in pi units’); ylabel(’radians/pi’)
title(’Angle of Y’)
and from plots in Figure 3.5 we observe that X(ejω ) is indeed shifted by π/4
in both magnitude and angle.
Magnitude of X
Angle of X
1
radiands/pi
60
|X|
40
20
0
−1
0.5
0
−0.5
−0.5
0
0.5
frequency in pi units
−1
−1
1
Magnitude of Y
−0.5
0
0.5
frequency in pi units
1
Angle of Y
60
1
0.5
|Y|
radians/pi
40
20
0
−1
FIGURE 3.5
EXAMPLE 3.10
0
−0.5
−0.5
0
0.5
frequency in pi units
1
−1
−1
−0.5
0
0.5
frequency in pi units
1
Plots in Example 3.9
To verify the conjugation property (3.8), let x(n) be a complex-valued random
sequence over −5 ≤ n ≤ 10 with real and imaginary parts uniformly distributed
between [0, 1]. The MATLAB verification is as follows.
>> n = -5:10; x = rand(1,length(n)) + j*rand(1,length(n));
>> k = -100:100; w = (pi/100)*k;
% frequency between -pi and +pi
>> X = x * (exp(-j*pi/100)).^(n’*k);
% DTFT of x
% conjugation property
>> y = conj(x);
% signal conjugation
>> Y = y * (exp(-j*pi/100)).^(n’*k);
% DTFT of y
% verification
>> Y_check = conj(fliplr(X));
% conj(X(-w))
>> error = max(abs(Y-Y_check))
% Difference
error =
0
The Properties of the DTFT
51
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 3.11
To verify the folding property (3.9), let x(n) be a random sequence over −5 ≤
n ≤ 10 uniformly distributed between [0, 1]. The MATLAB verification is as
follows.
MATLAB Script:
>> n = -5:10; x = rand(1,length(n));
>> k = -100:100; w = (pi/100)*k;
>> X = x * (exp(-j*pi/100)).^(n’*k);
% folding property
>> y = fliplr(x); m = -fliplr(n);
>> Y = y * (exp(-j*pi/100)).^(m’*k);
% verification
>> Y_check = fliplr(X);
>> error = max(abs(Y-Y_check))
error =
0
EXAMPLE 3.12
% frequency between -pi and +pi
% DTFT of x
% signal folding
% DTFT of y
% X(-w)
% Difference
In this problem we verify the symmetry property (3.10) of real signals. Let
x(n) = sin(πn/2),
−5 ≤ n ≤ 10
Then using the evenodd function developed in Chapter 2, we can compute
the even and odd parts of x(n) and then evaluate their discrete-time Fourier
transforms. We will provide the numerical as well as graphical verification.
MATLAB Script:
>> n = -5:10; x = sin(pi*n/2);
>> k = -100:100; w = (pi/100)*k;
% frequency between -pi and +pi
>> X = x * (exp(-j*pi/100)).^(n’*k);
% DTFT of x
% signal decomposition
>> [xe,xo,m] = evenodd(x,n);
% even and odd parts
>> XE = xe * (exp(-j*pi/100)).^(m’*k); % DTFT of xe
>> XO = xo * (exp(-j*pi/100)).^(m’*k); % DTFT of xo
% verification
>> XR = real(X);
% real part of X
>> error1 = max(abs(XE-XR))
% Difference
error1 =
1.8974e-019
>> XI = imag(X);
% imag part of X
>> error2 = max(abs(XO-j*XI))
% Difference
error2 =
1.8033e-019
% graphical verification
>> subplot(2,2,1); plot(w/pi,XR); grid; axis([-1,1,-2,2])
>> xlabel(’frequency in pi units’); ylabel(’Re(X)’);
>> title(’Real part of X’)
52
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Imaginary part of X
10
1
5
Im(X)
Re(X)
Real part of X
2
0
–1
–2
–1
0
–5
–0.5
0
0.5
frequency in pi units
–10
–1
1
10
1
5
0
–1
–2
–1
FIGURE 3.6
>>
>>
>>
>>
>>
>>
>>
>>
>>
1
Transform of odd part
2
XO
XE
Transform of even part
–0.5
0
0.5
frequency in pi units
0
–5
–0.5
0
0.5
frequency in pi units
1
–10
–1
–0.5
0
0.5
frequency in pi units
1
Plots in Example 3.12
subplot(2,2,2); plot(w/pi,XI); grid; axis([-1,1,-10,10])
xlabel(’frequency in pi units’); ylabel(’Im(X)’);
title(’Imaginary part of X’)
subplot(2,2,3); plot(w/pi,real(XE)); grid; axis([-1,1,-2,2])
xlabel(’frequency in pi units’); ylabel(’XE’);
title(’Transform of even part’)
subplot(2,2,4); plot(w/pi,imag(XO)); grid; axis([-1,1,-10,10])
xlabel(’frequency in pi units’); ylabel(’XO’);
title(’Transform of odd part’)
From the plots in Figure 3.6 we observe that the real part of X(ejω ) [or the
imaginary part of X(ejω )] is equal to the discrete-time Fourier transform of
xe (n) [or xo (n)].
THE FREQUENCY DOMAIN REPRESENTATION OF LTI SYSTEMS
We earlier stated that the Fourier transform representation is the most
useful signal representation for LTI systems. It is due to the following
result.
The Frequency Domain Representation of LTI Systems
53
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
RESPONSE TO
A COMPLEX
EXPONENTIAL
ejω0 n
Let x(n) = ejω0 n be the input to an LTI system represented by the impulse
response h(n).
ejω0 n −→ h(n) −→ h(n) ∗ ejω0 n
Then
y(n) = h(n) ∗ ejω0 n =
∞
h(k)ejω0 (n−k)
−∞
=
∞
h(k)e−jω0 k ejω0 n
(3.15)
−∞
= [F[h(n)]|ω=ω0 ] ejω0 n
DEFINITION 1
Frequency Response
The discrete-time Fourier transform of an impulse response is called
the Frequency Response (or Transfer Function) of an LTI system and is
denoted by
∞
jωn h(n)e−jωn
(3.16)
H(e ) =
−∞
Then from (3.15) we can represent the system by
x(n) = ejω0 n −→ H(ejω ) −→ y(n) = H(ejω0 ) × ejω0 n
(3.17)
Hence the output sequence is the input exponential sequence modified by
the response of the system at frequency ω0 . This justifies the definition
of H(ejω ) as a frequency response because it is what the complex exponential is multiplied by to obtain the output y(n). This powerful result
can be extended to a linear combination of complex exponentials using
the linearity of LTI systems.
Ak ejωk n −→ h(n) −→
Ak H(ejωk ) ejωk n
k
k
In general, the frequency response H(ejω ) is a complex function of
ω. The magnitude |H(ejω )| of H(ejω ) is called the magnitude (or gain)
response function, and the angle H(ejω ) is called the phase response
function as we shall see below.
RESPONSE TO
SINUSOIDAL
SEQUENCES
Let x(n) = A cos(ω0 n + θ0 ) be an input to an LTI system h(n). Then
from (3.17) we can show that the response y(n) is another sinusoid of the
same frequency ω0 , with amplitude gained by |H(ejω0 )| and phase shifted
by H(ejω0 ), that is,
y(n) = A|H(ejω0 )| cos(ω0 n + θ0 + H(ejω0 ))
54
Chapter 3
(3.18)
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
This response is called the steady-state response denoted by yss (n). It can
be extended to a linear combination of sinusoidal sequences.
Ak cos(ωk n + θk ) −→ H(ejω ) −→
Ak |H(ejωk )| cos(ωk n + θk + H(ejωk ))
k
RESPONSE TO
ARBITRARY
SEQUENCES
k
Finally, (3.17) can be generalized to arbitrary absolutely summable sequences. Let X(ejω ) = F[x(n)] and Y (ejω ) = F[y(n)]; then using the
convolution property (3.11), we have
Y (ejω ) = H(ejω ) X(ejω )
(3.19)
Therefore an LTI system can be represented in the frequency domain by
X(ejω ) −→ H(ejω ) −→ Y (ejω ) = H(ejω ) X(ejω )
The output y(n) is then computed from Y (ejω ) using the inverse
discrete-time Fourier transform (3.2). This requires an integral operation,
which is not a convenient operation in MATLAB. As we shall see in
Chapter 4, there is an alternate approach to the computation of output to
arbitrary inputs using the z-transform and partial fraction expansion. In
this chapter we will concentrate on computing the steady-state response.
EXAMPLE 3.13
Solution
Determine the frequency response H(ejω ) of a system characterized by h(n) =
(0.9)n u(n). Plot the magnitude and the phase responses.
Using (3.16),
H(ejω ) =
∞
h(n)e−jωn =
−∞
(0.9e−jω )n =
0
Hence
(0.9)n e−jωn
0
∞
=
∞
1
1 − 0.9e−jω
1
1
= √
(1 − 0.9 cos ω)2 + (0.9 sin ω)2
1.81 − 1.8 cos ω
|H(e )| =
jω
and
H(ejω ) = − arctan
0.9 sin ω
1 − 0.9 cos ω
To plot these responses, we can either implement the |H(ejω )| and H(ejω )
functions or the frequency response H(ejω ) and then compute its magnitude
and phase. The latter approach is more useful from a practical viewpoint [as
shown in (3.18)].
The Frequency Domain Representation of LTI Systems
55
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>>
>>
>>
>>
>>
>>
>>
>>
>>
w = [0:1:500]*pi/500; % [0, pi] axis divided into 501 points.
H = exp(j*w) ./ (exp(j*w) - 0.9*ones(1,501));
magH = abs(H); angH = angle(H);
subplot(2,1,1); plot(w/pi,magH); grid;
xlabel(’frequency in pi units’); ylabel(’|H|’);
title(’Magnitude Response’);
subplot(2,1,2); plot(w/pi,angH/pi); grid
xlabel(’frequency in pi units’); ylabel(’Phase in pi Radians’);
title(’Phase Response’);
The plots are shown in Figure 3.7.
Magnitude Response
10
8
|H|
6
4
2
0
0
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
1
0.7
0.8
0.9
1
Phase Response
Phase in pi Radians
0
−0.1
−0.2
−0.3
−0.4
0
FIGURE 3.7
EXAMPLE 3.14
Solution
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
Frequency response plots in Example 3.13
Let an input to the system in Example 3.13 be 0.1u(n). Determine the steadystate response yss (n).
Since the input is not absolutely summable, the discrete-time Fourier transform
is not particularly useful in computing the complete response. However, it can
be used to compute the steady-state response. In the steady state (i.e., n → ∞)
the input is a constant sequence (or a sinusoid with ω0 = θ0 = 0). Then the
output is
yss (n) = 0.1 × H(ej0 ) = 0.1 × 10 = 1
56
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where the gain of the system at ω = 0 (also called the DC gain) is H(ej0 ) = 10,
which is obtained from Figure 3.7.
FREQUENCY
RESPONSE
FUNCTION
FROM
DIFFERENCE
EQUATIONS
When an LTI system is represented by the difference equation
y(n) +
N
a y(n − ) =
M
bm x(n − m)
(3.20)
m=0
=1
then to evaluate its frequency response from (3.16), we would need the impulse response h(n). However, using (3.17), we can easily obtain H(ejω ).
We know that when x(n) = ejωn , then y(n) must be H(ejω )ejωn . Substituting in (3.20), we have
H(ejω )ejωn +
N
a H(ejω )ejω(n−) =
M
bm ejω(n−m)
m=0
=1
or
M
H(ejω ) =
1
−jωm
m=0 bm e
N
+ =1 a e−jω
(3.21)
after canceling the common factor ejωn term and rearranging. This equation can easily be implemented in MATLAB, given the difference equation
parameters.
EXAMPLE 3.15
An LTI system is specified by the difference equation
y(n) = 0.8y(n − 1) + x(n)
a. Determine H(ejω ).
b. Calculate and plot the steady-state response yss (n) to
x(n) = cos(0.05πn)u(n)
Solution
Rewrite the difference equation as y(n) − 0.8y(n − 1) = x(n).
a. Using (3.21), we obtain
H(ejω ) =
The Frequency Domain Representation of LTI Systems
1
1 − 0.8e−jω
(3.22)
57
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
b. In the steady state the input is x(n) = cos(0.05πn) with frequency ω0 =
0.05π and θ0 = 0◦ . The response of the system is
H(ej0.05π ) =
1
= 4.0928e−j0.5377
1 − 0.8e−j0.05π
Therefore
yss (n) = 4.0928 cos(0.05πn − 0.5377) = 4.0928 cos [0.05π(n − 3.42)]
This means that at the output the sinusoid is scaled by 4.0928 and shifted
by 3.42 samples. This can be verified using MATLAB.
>>
>>
>>
>>
>>
>>
>>
>>
subplot(1,1,1)
b = 1; a = [1,-0.8];
n=[0:100];x = cos(0.05*pi*n);
y = filter(b,a,x);
subplot(2,1,1); stem(n,x);
xlabel(’n’); ylabel(’x(n)’); title(’Input sequence’)
subplot(2,1,2); stem(n,y);
xlabel(’n’); ylabel(’y(n)’); title(’Output sequence’)
From the plots in Figure 3.8 we note that the amplitude of yss (n) is approximately 4. To determine the shift in the output sinusoid, we can compare
Input sequence
1
x(n)
0.5
0
−0.5
−1
0
10
20
30
40
50
n
60
70
80
90
100
Output sequence
5
3.42
y(n)
4.092
0
−5
0
FIGURE 3.8
58
10
20
30
40
50
n
60
70
80
90
100
Plots in Example 3.15
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
zero crossings of the input and the output. This is shown in Figure 3.8, from
which the shift is approximately 3.4 samples.
In Example 3.15 the system was characterized by a first-order difference equation. It is fairly straightforward to implement (3.22) in
MATLAB as we did in Example 3.13. In practice the difference equations
are of large order and hence we need a compact procedure to implement
the general expression (3.21). This can be done using a simple matrixvector multiplication. If we evaluate H(ejω ) at k = 0, 1, . . . , K equispaced
frequencies over [0, π], then
M
jωk
H(e
)=
1
−jωk m
m=0 bm e
,
N
+ =1 a e−jωk k = 0, 1, . . . , K
(3.23)
If we let {bm }, {a } (with a0 = 1), {m = 0, . . . , M }, { = 0, . . . , N }, and
{ωk } be arrays (or row vectors), then the numerator and the denominator
of (3.23) become
b exp(−jmT ω);
a exp(−jT ω)
respectively. Now the array H(ejωk ) in (3.23) can be computed using a ./
operation. This procedure can be implemented in a MATLAB function to
determine the frequency response function, given {bm } and {a } arrays.
We will explore this in Example 3.16 and in Problem P3.16.
EXAMPLE 3.16
A 3rd-order lowpass filter is described by the difference equation
y(n) = 0.0181x(n) + 0.0543x(n − 1) + 0.0543x(n − 2) + 0.0181x(n − 3)
+ 1.76y(n − 1) − 1.1829y(n − 2) + 0.2781y(n − 3)
Plot the magnitude and the phase response of this filter and verify that it is a
lowpass filter.
Solution
>>
>>
>>
>>
>>
>>
b =
a =
m =
K =
w =
num
We will implement the above procedure in MATLAB and then plot the filter
responses.
[0.0181, 0.0543, 0.0543, 0.0181];
[1.0000, -1.7600, 1.1829, -0.2781];
0:length(b)-1; l = 0:length(a)-1;
500; k = 0:1:K;
pi*k/K;
= b * exp(-j*m’*w);
The Frequency Domain Representation of LTI Systems
%
%
%
%
%
%
filter coefficient array b
filter coefficient array a
index arrays m and l
index array k for frequencies
[0, pi] axis divided into 501 points.
Numerator calculations
59
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
1
0.8
|H|
0.6
0.4
0.2
0
0
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
1
0.7
0.8
0.9
1
Phase Response
Phase in pi Radians
1
0.5
0
−0.5
−1
0
FIGURE 3.9
>>
>>
>>
>>
>>
>>
>>
>>
>>
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
Plots for Example 3.16
den = a * exp(-j*l’*w);
% Denominator calculations
H = num ./ den;
% Frequency response
magH = abs(H); angH = angle(H);
% mag and phase responses
subplot(2,1,1); plot(w/pi,magH); grid; axis([0,1,0,1])
xlabel(’frequency in pi units’); ylabel(’|H|’);
title(’Magnitude Response’);
subplot(2,1,2); plot(w/pi,angH/pi); grid
xlabel(’frequency in pi units’); ylabel(’Phase in pi Radians’);
title(’Phase Response’);
From the plots in Figure 3.9 we see that the filter is indeed a lowpass filter. SAMPLING AND RECONSTRUCTION OF ANALOG SIGNALS
In many applications—for example, in digital communications—realworld analog signals are converted into discrete signals using sampling
and quantization operations (collectively called analog-to-digital conversion or ADC). These discrete signals are processed by digital signal
processors, and the processed signals are converted into analog signals
60
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
using a reconstruction operation (called digital-to-analog conversion or
DAC). Using Fourier analysis, we can describe the sampling operation
from the frequency-domain viewpoint, analyze its effects, and then address the reconstruction operation. We will also assume that the number
of quantization levels is sufficiently large that the effect of quantization
on discrete signals is negligible. We will study the effects of quantization
in Chapter 9.
SAMPLING
Let xa (t) be an analog (absolutely integrable) signal. Its continuous-time
Fourier transform (CTFT) is given by
∞
Xa (jΩ) =
xa (t)e−jΩt dt
(3.24)
−∞
where Ω is an analog frequency in radians/sec. The inverse continuoustime Fourier transform is given by
1
xa (t) =
2π
∞
Xa (jΩ)ejΩt dΩ
(3.25)
−∞
We now sample xa (t) at sampling interval Ts seconds apart to obtain the
discrete-time signal x(n).
x(n) = xa ( nTs )
Let X(ejω ) be the discrete-time Fourier transform of x(n). Then it can be
shown [22] that X(ejω ) is a countable sum of amplitude-scaled, frequencyscaled, and translated versions of the Fourier transform Xa (jΩ).
∞
ω
1 2π
Xa j
−
X(e ) =
Ts
Ts
Ts
jω
(3.26)
=−∞
The above relation is known as the aliasing formula. The analog and
digital frequencies are related through Ts
ω = ΩTs
(3.27)
while the sampling frequency Fs is given by
Fs =
1
,
Ts
sam/sec
(3.28)
The graphical illustration of (3.26) is shown in Figure 3.10, from which
we observe that, in general, the discrete signal is an aliased version of the
corresponding analog signal because higher frequencies are aliased into
Sampling and Reconstruction of Analog Signals
61
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Xa (j Ω)
xa (t)
1
CTFT
t
0
A
−Ω0
Ω0
0
Ω
eq. (3.27)
Sample
X (e jw )
x (n)
A /Ts
1
DTFT
Ts < π/Ω0
Ω 0 /Ts
−Ω 0 /Ts
−5
0
5
n
−2π
−π
0
π
2π
w
X (e jw )
x (n)
A /Ts
Ts > π/Ω0
−Ω 0 /Ts
−2
−1
0
1
2
FIGURE 3.10
n
−2π
−π
Ω 0 /Ts
0
π
2π
w
Sampling operation in the time and frequency domains
lower frequencies if there is an overlap. However, it is possible to recover
the Fourier transform Xa (jΩ) from X(ejω ) [or equivalently, the analog
signal xa (t) from its samples x(n)] if the infinite “replicas” of Xa (jΩ) do
not overlap with each other to form X(ejω ). This is true for band-limited
analog signals.
DEFINITION 2
62
Band-limited Signal
A signal is band-limited if there exists a finite radian frequency Ω0
such that Xa (jΩ) is zero for |Ω| > Ω0 . The frequency F0= Ω0 /2π is called
the signal bandwidth in Hz.
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Referring to Figure 3.10, if π > Ω0 Ts —or equivalently, Fs /2 > F0 —
then
π
1
ω
ω
π
X(ejω ) =
; −
X j
<
≤
(3.29)
Ts
Ts
Ts
Ts
Ts
which leads to the sampling theorem for band-limited signals.
THEOREM 3
Sampling Principle
A band-limited signal xa (t) with bandwidth F0 can be reconstructed
from its sample values x(n) = xa (nTs ) if the sampling frequency Fs =
1/Ts is greater than twice the bandwidth F0 of xa (t).
Fs > 2F0
Otherwise aliasing would result in x(n). The sampling rate of 2F0 for an
analog band-limited signal is called the Nyquist rate.
It should be noted that after xa (t) is sampled, the highest analog
frequency that x(n) represents is Fs /2 Hz (or ω = π). This agrees with
the implication stated in Property 2 of the discrete-time Fourier transform
in the first section of this chapter.
MATLAB
IMPLEMENTATION
In a strict sense it is not possible to analyze analog signals using MATLAB
unless we use the Symbolic toolbox. However, if we sample xa (t) on a fine
grid that has a sufficiently small time increment to yield a smooth plot
and a large enough maximum time to show all the modes, then we can
approximate its analysis. Let ∆t be the grid interval such that ∆t Ts .
Then
(3.30)
xG (m) = xa (m∆t)
can be used as an array to simulate an analog signal. The sampling interval Ts should not be confused with the grid interval ∆t, which is used
strictly to represent an analog signal in MATLAB. Similarly, the Fourier
transform relation (3.24) should also be approximated in light of (3.30)
as follows
Xa (jΩ) ≈
m
xG (m)e−jΩm∆t ∆t = ∆t
xG (m)e−jΩm∆t
(3.31)
m
Now if xa (t) [and hence xG (m)] is of finite duration, then (3.31) is similar
to the discrete-time Fourier transform relation (3.3) and hence can be
implemented in MATLAB in a similar fashion to analyze the sampling
phenomenon.
Sampling and Reconstruction of Analog Signals
63
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 3.17
Solution
Let xa (t) = e−1000|t| . Determine and plot its Fourier transform.
From (3.24)
∞
Xa (jΩ) =
−jΩt
xa (t)e
0
dt =
−∞
1000t −jΩt
e
e
−∞
∞
dt +
e−1000t e−jΩt dt
0
0.002
=
Ω
1 + ( 1000
)2
(3.32)
which is a real-valued function since xa (t) is a real and even signal. To evaluate
Xa (jΩ) numerically, we have to first approximate xa (t) by a finite-duration
grid sequence xG (m). Using the approximation e−5 ≈ 0, we note that xa (t)
can be approximated by a finite-duration signal over −0.005 ≤ t ≤ 0.005 (or
equivalently, over [−5, 5] msec). Similarly from (3.32), Xa (jΩ) ≈ 0 for Ω ≥
2π (2000). Hence choosing
∆t = 5 × 10−5
1
= 25 × 10−5
2 (2000)
we can obtain xG (m) and then implement (3.31) in MATLAB.
% Analog Signal
>> Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));
% Continuous-time Fourier Transform
>>Wmax = 2*pi*2000; K = 500; k = 0:1:K; W = k*Wmax/K;
>>Xa = xa * exp(-j*t’*W) * Dt; Xa = real(Xa);
>>W = [-fliplr(W), W(2:501)]; % Omega from -Wmax to Wmax
>>Xa = [fliplr(Xa), Xa(2:501)]; % Xa over -Wmax to Wmax interval
>>subplot(2,1,1);plot(t*1000,xa);
>>xlabel(’t in msec.’); ylabel(’xa(t)’)
>>title(’Analog Signal’)
>>subplot(2,1,2);plot(W/(2*pi*1000),Xa*1000);
>>xlabel(’Frequency in KHz’); ylabel(’Xa(jW)*1000’)
>>title(’Continuous-time Fourier Transform’)
Figure 3.11 shows the plots of xa (t) and Xa (jΩ). Note that to reduce the number
of computations, we computed Xa (jΩ) over [0, 4000π] radians/sec (or equivalently, over [0, 2] KHz) and then duplicated it over [−4000π, 0] for plotting
purposes. The displayed plot of Xa (jΩ) agrees with (3.32).
EXAMPLE 3.18
To study the effect of sampling on the frequency-domain quantities, we will
sample xa (t) in Example 3.17 at two different sampling frequencies.
a. Sample xa (t) at Fs = 5000 sam/sec to obtain x1 (n). Determine and plot
X1 (ejω ).
b. Sample xa (t) at Fs = 1000 sam/sec to obtain x2 (n). Determine and plot
X2 (ejω ).
64
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Analog Signal
1
xa(t)
0.8
0.6
0.4
0.2
0
−5
−4
−3
−2
−1
0
t in msec.
1
2
3
4
5
Continuous-time Fourier Transform
Xa(jW)*1000
2
1.5
1
0.5
0
−2
FIGURE 3.11
Solution
−1.5
−1
−0.5
0
0.5
Frequency in KHz
1
1.5
2
Plots in Example 3.17
a. Since the bandwidth of xa (t) is 2KHz, the Nyquist rate is 4000 sam/sec,
which is less than the given Fs . Therefore aliasing will be (almost) nonexistent.
MATLAB Script:
% Analog Signal
>> Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));
% Discrete-time Signal
>> Ts = 0.0002; n = -25:1:25; x = exp(-1000*abs(n*Ts));
% Discrete-time Fourier transform
>> K = 500; k = 0:1:K; w = pi*k/K;
>> X = x * exp(-j*n’*w); X = real(X);
>> w = [-fliplr(w), w(2:K+1)];
X = [fliplr(X), X(2:K+1)];
>> subplot(2,1,1);plot(t*1000,xa);
>> xlabel(’t in msec.’); ylabel(’x1(n)’)
>> title(’Discrete Signal’); hold on
>> stem(n*Ts*1000,x); gtext(’Ts=0.2 msec’); hold off
>> subplot(2,1,2);plot(w/pi,X);
>> xlabel(’Frequency in pi units’); ylabel(’X1(w)’)
>> title(’Discrete-time Fourier Transform’)
In the top plot in Figure 3.12 we have superimposed the discrete signal x1 (n)
over xa (t) to emphasize the sampling. The plot of X2 (ejω ) shows that it is a
scaled version (scaled by Fs = 5000) of Xa (jΩ). Clearly there is no aliasing.
Sampling and Reconstruction of Analog Signals
65
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Discrete Signal
1
Ts=0.2 msec
x1(n)
0.8
0.6
0.4
0.2
0
−5
−4
−3
−2
−1
0
t in msec.
1
2
3
4
5
0.6
0.8
1
Discrete-time Fourier Transform
10
X1(w)
8
6
4
2
0
−1
FIGURE 3.12
−0.8
−0.6
−0.4
−0.2
0
0.2
Frequency in pi units
0.4
Plots in Example 3.18a
b. Here Fs = 1000 < 4000. Hence there will be a considerable amount of
aliasing. This is evident from Figure 3.13, in which the shape of X(ejω )
is different from that of Xa (jΩ) and can be seen to be a result of adding
overlapping replicas of Xa (jΩ).
RECONSTRUCTION
From the sampling theorem and the above examples it is clear that if we
sample band-limited xa (t) above its Nyquist rate, then we can reconstruct
xa (t) from its samples x(n). This reconstruction can be thought of as a
two-step process:
• First the samples are converted into a weighted impulse train.
∞
x(n)δ(t−nTs ) = · · ·+x(−1)δ(n+Ts )+x(0)δ(t)+x(1)δ(n−Ts )+· · ·
n=−∞
• Then the impulse train is filtered through an ideal analog lowpass filter
band-limited to the [−Fs /2, Fs /2] band.
x(n) −→
66
Impulse train
conversion
Chapter 3
−→
Ideal lowpass
filter
−→ xa (t)
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Discrete Signal
1
Ts=1 msec
x2(n)
0.8
0.6
0.4
0.2
0
−5
−4
−3
−2
−1
0
t in msec.
1
2
3
4
5
0.6
0.8
1
Discrete-time Fourier Transform
2.5
X2(w)
2
1.5
1
0.5
0
−1
FIGURE 3.13
−0.8
−0.6
−0.4
−0.2
0
0.2
Frequency in pi units
0.4
Plots in Example 3.18b
This two-step procedure can be described mathematically using an interpolating formula [22]
xa (t) =
∞
x(n) sinc [Fs (t − nTs )]
(3.33)
n=−∞
where sinc(x) = sinπxπx is an interpolating function. The physical interpretation of the above reconstruction (3.33) is given in Figure 3.14, from
which we observe that this ideal interpolation is not practically feasible
because the entire system is noncausal and hence not realizable.
Practical D/A converters In practice we need a different approach
than (3.33). The two-step procedure is still feasible, but now we replace
the ideal lowpass filter by a practical analog lowpass filter. Another interpretation of (3.33) is that it is an infinite-order interpolation. We want
finite-order (and in fact low-order) interpolations. There are several approaches to do this.
Sampling and Reconstruction of Analog Signals
67
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
..
+.
x (0) sinc[Fs t ]
t
0
+
x (1) sinc[Fs (t − Ts)]
t
Ts
xa(t )
+
x (2) sinc[Fs (t − 2Ts)]
t
2Ts
−Ts
Ts
0
2Ts 3Ts
t
+
x (3) sinc[Fs (t − 3Ts)]
Sample at
t = nTs
3Ts
+.
..
x (n )
x (−1)
t
=
x (0)
xa (t ) = Σ x (n ) sinc[Fs (t − nTs)]
x (1)
x (2) x (3)
−1
0
1
2
3
n
−Ts
Sampling
FIGURE 3.14
0
Ts
2Ts
3Ts
t
Reconstruction
Reconstruction of band-limited signal from its samples
• Zero-order-hold (ZOH) interpolation: In this interpolation a given
sample value is held for the sample interval until the next sample is
received.
nTs ≤ n < (n + 1)Ts
x̂a (t) = x(n),
which can be obtained by filtering the impulse train through an interpolating filter of the form
h0 (t) =
68
Chapter 3
1,
0 ≤ t ≤ Ts
0,
otherwise
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
which is a rectangular pulse. The resulting signal is a piecewise-constant
(staircase) waveform which requires an appropriately designed analog
post-filter for accurate waveform reconstruction.
x(n) −→ ZOH −→ x̂a (t) −→ Post-Filter −→ xa (t)
• First-order-hold (FOH) interpolation: In this case the adjacent
samples are joined by straight lines. This can be obtained by filtering
the impulse train through

t


1 + , 0 ≤ t ≤ Ts


T

s

t
h1 (t) = 1 − , T ≤ t ≤ 2T
s
s


Ts




0,
otherwise
Once again, an appropriately designed analog postfilter is required
for accurate reconstruction. These interpolations can be extended
to higher orders. One particularly useful interpolation employed by
MATLAB is the following.
• Cubic spline interpolation: This approach uses spline interpolants
for a smoother, but not necessarily more accurate, estimate of the analog signals between samples. Hence this interpolation does not require
an analog postfilter. The smoother reconstruction is obtained by using a set of piecewise continuous third-order polynomials called cubic
splines, given by [3]
2
xa (t) = α0 (n) + α1 (n) (t − nTs ) + α2 (n) (t − nTs )
3
+ α3 (n) (t − nTs ) , nTs ≤ n < (n + 1)Ts
(3.34)
where {αi (n), 0 ≤ i ≤ 3} are the polynomial coefficients, which are determined by using least-squares analysis on the sample values. (Strictly
speaking, this is not a causal operation but is a convenient one in MATLAB.)
MATLAB
IMPLEMENTATION
For interpolation between samples MATLAB provides several approaches.
The function sinc(x), which generates the (sin πx) /πx function, can
be used to implement (3.33), given a finite number of samples. If
{x(n), n1 ≤ n ≤ n2 } is given, and if we want to interpolate xa (t) on
a very fine grid with the grid interval ∆t, then from (3.33)
xa (m∆t) ≈
n2
x(n) sinc [Fs (m∆t − nTs )] ,
t1 ≤ m∆t ≤ t2
(3.35)
n=n1
Sampling and Reconstruction of Analog Signals
69
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
which can be implemented as a matrix-vector multiplication operation as
shown below.
>> n = n1:n2; t = t1:t2; Fs = 1/Ts; nTs = n*Ts; % Ts is the sampling interval
>> xa = x * sinc(Fs*(ones(length(n),1)*t-nTs’*ones(1,length(t))));
Note that it is not possible to obtain an exact analog xa (t) in light of the
fact that we have assumed a finite number of samples. We now demonstrate the use of the sinc function in the following two examples and also
study the aliasing problem in the time domain.
EXAMPLE 3.19
Solution
From the samples x1 (n) in Example 3.18a, reconstruct xa (t) and comment on
the results.
Note that x1 (n) was obtained by sampling xa (t) at Ts = 1/Fs = 0.0002 sec. We
will use the grid spacing of 0.00005 sec over −0.005 ≤ t ≤ 0.005, which gives
x(n) over −25 ≤ n ≤ 25.
MATLAB Script:
% Discrete-time Signal x1(n)
>> Ts = 0.0002; n = -25:1:25; nTs = n*Ts; x = exp(-1000*abs(nTs));
% Analog Signal reconstruction
>> Dt = 0.00005; t = -0.005:Dt:0.005;
>> xa = x * sinc(Fs*(ones(length(n),1)*t-nTs’*ones(1,length(t))));
% check
>> error = max(abs(xa - exp(-1000*abs(t))))
error =
0.0363
The maximum error between the reconstructed and the actual analog signal is
0.0363, which is due to the fact that xa (t) is not strictly band-limited (and also
we have a finite number of samples). From Figure 3.15 we note that visually
the reconstruction is excellent.
Reconstructed Signal from x1(n) using sinc function
1
xa(t)
0.8
0.6
0.4
0.2
0
–5
FIGURE 3.15
70
–4
–3
–2
–1
0
t in msec.
1
2
3
4
5
Reconstructed signal in Example 3.19
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 3.20
Solution
From the samples x2 (n) in Example 3.18b reconstruct xa (t) and comment on
the results.
In this case x2 (n) was obtained by sampling xa (t) at Ts = 1/Fs = 0.001 sec. We
will again use the grid spacing of 0.00005 sec over −0.005 ≤ t ≤ 0.005, which
gives x(n) over −5 ≤ n ≤ 5.
% Discrete-time Signal x2(n)
>> Ts = 0.001; n = -5:1:5; nTs = n*Ts; x = exp(-1000*abs(nTs));
% Analog Signal reconstruction
>> Dt = 0.00005; t = -0.005:Dt:0.005;
>> xa = x * sinc(Fs*(ones(length(n),1)*t-nTs’*ones(1,length(t))));
% check
>> error = max(abs(xa - exp(-1000*abs(t))))
error =
0.1852
The maximum error between the reconstructed and the actual analog signal is
0.1852, which is significant and cannot be attributed to the nonband-limitedness
of xa (t) alone. From Figure 3.16 observe that the reconstructed signal differs
from the actual one in many places over the interpolated regions. This is the
visual demonstration of aliasing in the time domain.
Reconstructed Signal from x2(n) using sinc function
1
xa(t)
0.5
0
–0.5
–5
FIGURE 3.16
–4
–3
–2
–1
0
t in msec.
1
2
3
4
5
Reconstructed signal in Example 3.20
The second MATLAB approach for signal reconstruction is a plotting
approach. The stairs function plots a staircase (ZOH) rendition of the
analog signal, given its samples, while the plot function depicts a linear
(FOH) interpolation between samples.
EXAMPLE 3.21
Solution
Plot the reconstructed signal from the samples x1 (n) in Example 3.18 using the
ZOH and the FOH interpolations. Comment on the plots.
Note that in this reconstruction we do not compute xa (t) but merely plot it
using its samples.
Sampling and Reconstruction of Analog Signals
71
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Discrete-time Signal x1(n) : Ts = 0.0002
>> Ts = 0.0002; n = -25:1:25; nTs = n*Ts; x = exp(-1000*abs(nTs));
% Plots
>> subplot(2,1,1); stairs(nTs*1000,x);
>> xlabel(’t in msec.’); ylabel(’xa(t)’)
>> title(’Reconstructed Signal from x1(n) using zero-order-hold’); hold on
>> stem(n*Ts*1000,x); hold off
%
% Discrete-time Signal x2(n) : Ts = 0.001
>> Ts = 0.001; n = -5:1:5; nTs = n*Ts; x = exp(-1000*abs(nTs));
% Plots
>> subplot(2,1,2); stairs(nTs*1000,x);
>> xlabel(’t in msec.’); ylabel(’xa(t)’)
>> title(’Reconstructed Signal from x2(n) using zero-order-hold’); hold on
>> stem(n*Ts*1000,x); hold off
The plots are shown in Figure 3.17, from which we observe that the ZOH reconstruction is a crude one and that the further processing of analog signal is
necessary. The FOH reconstruction appears to be a good one, but a careful
observation near t = 0 reveals that the peak of the signal is not correctly reproduced. In general, if the sampling frequency is much higher than the Nyquist
rate, then the FOH interpolation provides an acceptable reconstruction.
Reconstructed Signal from x1(n) using zero–order–hold
1
xa(t)
0.8
0.6
0.4
0.2
0
–5
–4
–3
–2
–1
0
t in msec.
1
2
3
4
5
4
5
Reconstructed Signal from x1(n) using first–order–hold
1
xa(t)
0.8
0.6
0.4
0.2
0
–5
FIGURE 3.17
–4
–3
–2
–1
0
t in msec.
1
2
3
Signal reconstruction in Example 3.21
The third approach of reconstruction in MATLAB involves the use
of cubic spline functions. The spline function implements interpolation
72
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
between sample points. It is invoked by xa = spline(nTs,x,t), in which
x and nTs are arrays containing samples x(n) at nTs instances, respectively, and t array contains a fine grid at which xa (t) values are desired.
Note once again that it is not possible to obtain an exact analog xa (t).
EXAMPLE 3.22
Solution
From the samples x1 (n) and x2 (n) in Example 3.18, reconstruct xa (t) using the
spline function. Comment on the results.
This example is similar to Examples 3.19 and 3.20. Hence sampling parameters
are the same as before.
MATLAB Script:
% a) Discrete-time Signal x1(n): Ts = 0.0002
>> Ts = 0.0002; n = -25:1:25; nTs = n*Ts;
x = exp(-1000*abs(nTs));
% Analog Signal reconstruction
>> Dt = 0.00005; t = -0.005:Dt:0.005;
xa = spline(nTs,x,t);
% check
>> error = max(abs(xa - exp(-1000*abs(t))))
error = 0.0317
The maximum error between the reconstructed and the actual analog signal is
0.0317, which is due to the nonideal interpolation and the fact that xa (t) is
nonband-limited. Comparing this error with that from the sinc (or ideal) interpolation, we note that this error is lower. The ideal interpolation generally suffers more from time-limitedness (or from a finite number of samples). From the
top plot in Figure 3.18 we observe that visually the reconstruction is excellent.
Reconstructed Signal from x1(n) using cubic spline function
1
xa(t)
0.8
0.6
0.4
0.2
0
–5
–4
–3
–2
–1
0
t in msec.
1
2
3
4
5
4
5
Reconstructed Signal from x2(n) using cubic spline function
1
xa(t)
0.8
0.6
0.4
0.2
0
–5
FIGURE 3.18
–4
–3
–2
–1
0
t in msec.
1
2
3
Reconstructed signal in Example 3.22
Sampling and Reconstruction of Analog Signals
73
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB Script:
% Discrete-time Signal x2(n): Ts = 0.001
>> Ts = 0.001; n = -5:1:5; nTs = n*Ts;
x = exp(-1000*abs(nTs));
% Analog Signal reconstruction
>> Dt = 0.00005; t = -0.005:Dt:0.005;
xa = spline(nTs,x,t);
% check
>> error = max(abs(xa - exp(-1000*abs(t))))
error = 0.1679
The maximum error in this case is 0.1679, which is significant and cannot be
attributed to the nonideal interpolation or nonband-limitedness of xa (t). From
the bottom plot in Figure 3.18 observe that the reconstructed signal again
differs from the actual one in many places over the interpolated regions.
From these examples it is clear that for practical purposes the spline
interpolation provides the best results.
PROBLEMS
P3.1 Using the matrix-vector multiplication approach discussed in this chapter, write a
MATLAB function to compute the DTFT of a finite-duration sequence. The format of the
function should be
function [X] = dtft(x,n,w)
% Computes Discrete-time Fourier Transform
% [X] = dtft(x,n,w)
%
X = DTFT values computed at w frequencies
%
x = finite duration sequence over n
%
n = sample position vector
%
w = frequency location vector
Use this function to compute the DTFT X(ejω ) of the following finite-duration sequences
over −π ≤ ω ≤ π. Plot DTFT magnitude and angle graphs in one figure window.
1.
2.
3.
4.
x(n) = (0.6)|n| [u(n + 10) − u(n − 11)]. Comment on the angle plot.
x(n) = n(0.9)n [u(n) − u(n − 21)].
x(n) = [cos(0.5πn) + j sin(0.5πn)][u(n) − u(n − 51)]. Comment on the magnitude plot.
x(n) = {4, 3, 2, 1, 1, 2, 3, 4}. Comment on the angle plot.
↑
5. x(n) = {4, 3, 2, 1, −1, −2, −3, −4}. Comment on the angle plot.
↑
P3.2 Let x1 (n) = {1, 2, 2, 1}. A new sequence x2 (n) is formed using
↑
x2 (n) =
74
x1 (n),
x1 (n − 4),
0,
Chapter 3
0 ≤ n ≤ 3;
4 ≤ n ≤ 7;
Otherwise.
(3.36)
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1. Express X2 (ejω ) in terms of X1 (ejω ) without explicitly computing X1 (ejω ).
2. Verify your result using MATLAB by computing and plotting magnitudes of the
respective DTFTs.
P3.3 Determine analytically the DTFT of each of the following sequences. Plot the magnitude
and angle of X(ejω ) over 0 ≤ ω ≤ π.
1.
2.
3.
4.
5.
x(n) = 2 (0.5)3 u(n + 2).
x(n) = (0.6)|n| [u(n + 10) − u(n − 11)].
x(n) = n (0.9)n u(n + 3).
x(n) = (n + 3) (0.8)n−1 u(n − 2).
x(n) = 4 (−0.7)n cos(0.25πn)u(n).
P3.4 The following finite-duration sequences are called windows and are very useful in DSP.
Rectangular: RM (n) =
1,
0,
0≤n<M
;
otherwise
2πn
RM (n)
M −1
|M − 1 − 2n|
RM (n);
Triangular: TM (n) = 1 −
M +1
2πn
RM (n)
Hamming: HM (n) = 0.54 − 0.46 cos
M −1
Hanning: CM (n) = 0.5 1 − cos
For each of these windows, determine their DTFTs for M = 10, 25, 50, 101. Scale transform
values so that the maximum value is equal to 1. Plot the magnitude of the normalized
DTFT over −π ≤ ω ≤ π. Study these plots and comment on their behavior as a function of
M.
P3.5 Using the definition of the DTFT in (3.1), determine the sequences corresponding to the
following DTFTs:
1.
2.
3.
4.
5.
X(ejω ) = 3 + 2 cos(ω) + 4 cos(2ω).
X(ejω ) = [1 − 6 cos(3ω) + 8 cos(5ω)] e−j3ω .
X(ejω ) = 2 + j4 sin(2ω) − 5 cos(4ω).
X(ejω ) = [1 + 2 cos(ω) + 3 cos(2ω)] cos(ω/2)e−j5ω/2 .
X(ejω ) = j [3 + 2 cos(ω) + 4 cos(2ω)] sin(ω)e−j3ω .
P3.6 Using the definition of the inverse DTFT in (3.2), determine the sequences corresponding to
the following DTFTs:
1. X(ejω ) =
2. X(ejω ) =
jω
3. X(e ) =
Problems
1,
0,
0 ≤ |ω| ≤ π/3;
π/3 < |ω| ≤ π.
0,
1,
0 ≤ |ω| ≤ 3π/4;
3π/4 < |ω| ≤ π.
2,
1,
0,
0 ≤ |ω| ≤ π/8;
π/8 < |ω| ≤ 3π/4.
3π/4 < |ω| ≤ π.
75
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
jω
4. X(e ) =
0,
1,
0,
−π ≤ ω < π/4;
π/4 ≤ ω ≤ 3π/4.
3π/4 < ω ≤ π.
5. X(ejω ) = ω ej(π/2−10ω) .
Remember that the above transforms are periodic in ω with period equal to 2π. Hence,
functions are given only over the primary period of −π ≤ ω ≤ π.
P3.7 A complex-valued sequence x(n) can be decomposed into a conjugate symmetric part xe (n)
and an conjugate anti-symmetric part xo (n) as discussed in Chapter 2. Show that
F [xe (n)] = XR (ejω )
and
F [xo (n)] = jXI (ejω )
where XR (ejω ) and XR (ejω ) are the real and imaginary parts of the DTFT X(ejω )
respectively. Verify this property on
x(n) = 2(0.9)−n [cos(0.1πn) + j sin(0.9πn)] [u(n) − u(n − 10)]
using the MATLAB functions developed in Chapter 2.
P3.8 A complex-valued DTFT X(ejω ) can also be decomposed into its conjugate symmetric part
Xe (ejω ) and conjugate anti-symmetric part Xo (ejω ), i.e.,
X(ejω ) = Xe (ejω ) + Xo (ejω )
where
Xe (ejω ) =
1
1
[X(ejω ) + X ∗ (e−jω )] and X0 (ejω ) = [X(ejω ) − X ∗ (e−jω )]
2
2
Show that
F −1 [Xe (ejω )] = xR (n) and F −1 [X0 (ejω )] = jxI (n)
where xR (n) and xI (n) are the real and imaginary parts of x(n). Verify this property on
x(n) = ej0.1πn [u(n) − u (n − 20)]
using the MATLAB functions developed in Chapter 2.
P3.9 Using the frequency-shifting property of the DTFT, show that the real part of X(ejω ) of a
sinusoidal pulse
x(n) = (cos ωo n)RM (n)
where RM (n) is the rectangular pulse given in Problem P3.4 is given by
XR (ejω ) =
1
cos
2
+
1
cos
2
(ω − ω0 )(M − 1)
2
(ω + ω0 )(M − 1)
2
sin {(ω − ω0 ) N/2}
sin {(ω − ω0 ) /2}
sin {[ω − (2π − ω0 )] N/2}
sin {[ω − (2π − ω0 )] /2}
Compute and plot XR (ejω ) for ωo = π/2 and M = 5, 15, 25, 100. Use the plotting interval
[−π, π]. Comment on your results.
P3.10 Let x(n) = T10 (n) be a triangular pulse given in Problem P3.4. Using properties of the
DTFT, determine and plot the DTFT of the following sequences.
1. x(n) = T10 (−n)
76
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
2.
3.
4.
5.
x(n) = T10 (n) − T10 (n − 10)
x(n) = T10 (n) ∗ T10 (−n)
x(n) = T10 (n)ejπn
x(n) = cos(0.1πn)T10 (n)
P3.11 For each of the linear, shift-invariant systems described by the impulse response, determine
the frequency response function H(ejω ). Plot the magnitude response |H(ejω )| and the
phase response H(ejω ) over the interval [−π, π].
1.
2.
3.
4.
5.
h(n) = (0.9)|n|
h(n) = sinc(0.2n)[u(n + 20) − u(n − 20)], where sinc 0 = 1.
h(n) = sinc(0.2n)[u(n) − u(n − 40)]
h(n) = [(0.5)n + (0.4)n ]u(n)
h(n) = (0.5)|n| cos(0.1πn)
P3.12 Let x(n) = A cos(ω0 n + θ0 ) be an input sequence to an LTI system described by the impulse
response h(n). Show that the output sequence y(n) is given by
y(n) = A|H(ejω0 )| cos[ω0 n + θ0 + H(ejω0 )]
P3.13 Let x(n) = 3 cos (0.5πn + 60◦ ) + 2 sin (0.3πn) be the input to each of the systems described
in Problem P3.11. In each case determine the output sequence y(n).
P3.14 An ideal lowpass filter is described in the frequency-domain by
Hd (ejω ) =
1 · e−jαω ,
0,
|ω| ≤ ωc
ωc < |ω| ≤ π
where ωc is called the cutoff frequency and α is called the phase delay.
1. Determine the ideal impulse response hd (n) using the IDTFT relation (3.2).
2. Determine and plot the truncated impulse response
h(n) =
hd (n),
0,
0≤n≤N −1
otherwise
for N = 41, α = 20, and ωc = 0.5π.
3. Determine and plot the frequency response function H(ejω ) and compare it with the
ideal lowpass filter response Hd (ejω ). Comment on your observations.
P3.15 An ideal highpass filter is described in the frequency-domain by
jω
Hd (e ) =
1 · e−jαω ,
0,
ωc < |ω| ≤ π
|ω| ≤ ωc
where ωc is called the cutoff frequency and α is called the phase delay.
1. Determine the ideal impulse response hd (n) using the IDTFT relation (3.2).
2. Determine and plot the truncated impulse response
h(n) =
hd (n),
0,
0≤n≤N −1
otherwise
for N = 31, α = 15, and ωc = 0.5π.
Problems
77
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3. Determine and plot the frequency response function H(ejω ) and compare it with the
ideal highpass filter response Hd (ejω ). Comment on your observations
P3.16 For a linear, shift-invariant system described by the difference equation
y(n) =
M
bm x (n − m) −
m=0
N
a y (n − )
=1
the frequency response function is given by
H(ejω ) =
M
b e−jωm
m=0 m
N
−jω
1+
=1
a e
write a MATLAB function freqresp to implement the above relation. The format of this
function should be
function [H] = freqresp(b,a,w)
% Frequency response function from difference equation
% [H] = freqresp(b,a,w)
% H = frequency response array evaluated at w frequencies
% b = numerator coefficient array
% a = denominator coefficient array (a(1)=1)
% w = frequency location array
P3.17 Determine H(ejω ) and plot its magnitude and phase for each of the following systems:
1.
2.
3.
4.
5.
4
y(n) = 15 m=0 x(n − m)
y(n) = x(n) − x(n − 2) + 0.95y(n − 1) − 0.9025y(n − 2)
y(n) = x(n) − x(n − 1) + x(n − 2) + 0.95y(n − 1) − 0.9025y(n − 2)
y(n) = x(n) − 1.7678x(n − 1) + 1.5625x(n − 2) + 1.1314y(n − 1) − 0.64y(n − 2)
5
y(n) = x(n) − =1 (0.5) y (n − )
P3.18 A linear, shift-invariant system is described by the difference equation
y(n) =
3
x (n − 2m) −
m=0
3
(0.81) y (n − 2)
=1
Determine the steady-state response of the system to the following inputs:
1.
2.
3.
4.
5.
x(n) = 5 + 10 (−1)n
x(n) = 1 + cos (0.5πn + π/2)
x(n) = 2 sin (πn/4) + 3 cos (3πn/4)
5
x(n) = k=0 (k + 1) cos (πkn/4)
x(n) = cos (πn)
In each case generate x(n), 0 ≤ n ≤ 200 and process it through the filter function to
obtain y(n). Compare your y(n) with the steady-state responses in each case.
78
Chapter 3
THE DISCRETE-TIME FOURIER ANALYSIS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P3.19 An analog signal xa (t) = sin (1000πt) is sampled using the following sampling intervals. In
each case plot the spectrum of the resulting discrete-time signal.
1. Ts = 0.1 ms
2. Ts = 1 ms
3. Ts = 0.01 sec
P3.20 We implement the following analog filter using a discrete filter.
x(n)
y(n)
xa (t) −→ A/D −→ h(n) −→ D/A −→ ya (t)
The sampling rate in the A/D and D/A is 8000 sam/sec, and the impulse response is
h(n) = (−0.9)n u(n).
1.
2.
3.
4.
What is the digital frequency in x(n) if xa (t) = 10 cos (10000πt)?
Determine the steady-state output ya (t) if xa (t) = 10 cos (10000πt).
Determine the steady-state output ya (t) if xa (t) = 5 sin(8000πt).
Find two other analog signals xa (t), with different analog frequencies, that will give the
same steady-state output ya (t) when xa (t) = 10 cos(10000πt) is applied.
5. To prevent aliasing, a pre-filter would be required to process xa (t) before it passes to the
A/D converter. What type of filter should be used and what should be the largest cutoff
frequency that would work for the given configuration?
P3.21 Consider an analog signal xa (t) = sin (20πt) , 0 ≤ t ≤ 1. It is sampled at Ts = 0.01, 0.05,
and 0.1 sec intervals to obtain x(n).
1. For each Ts plot x(n).
2. Reconstruct the analog signal ya (t) from the samples x(n) using the sinc interpolation
(Use ∆t = 0.001) and determine the frequency in ya (t) from your plot. (Ignore the end
effects.)
3. Reconstruct the analog signal ya (t) from the samples x(n) using the cubic spline
interpolation and determine the frequency in ya (t) from your plot. (Again ignore the
end effects.)
4. Comments on your results.
P3.22 Consider the analog signal xa (t) = cos (20πt + θ) , 0 ≤ t ≤ 1. It is sampled at Ts = 0.05 sec
intervals to obtain x(n). Let θ = 0, π/6, π/4, π/3, π/2. For each of these θ values, perform
the following.
1. Plot xa (t) and superimpose x(n) on it using the plot(n,x,’o’) function.
2. Reconstruct the analog signal ya (t) from the samples x(n) using the sinc interpolation
(Use ∆t = 0.001) and superimpose x(n) on it.
3. Reconstruct the analog signal ya (t) from the samples x(n) using the cubic spline
interpolation and superimpose x(n) on it.
4. You should observe that the resultant reconstruction in each case has the correct
frequency but a different amplitude. Explain this observation. Comment on the role of
phase of xa (t) on sampling and reconstruction of signals.
Problems
79
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
4
The z-Transform
In Chapter 3 we studied the discrete-time Fourier transform approach for
representing discrete signals using complex exponential sequences. This
representation clearly has advantages for LTI systems because it describes
systems in the frequency domain using the frequency response function
H(ejω ). The computation of the sinusoidal steady-state response is greatly
facilitated by the use of H(ejω ). Furthermore, response to any arbitrary
absolutely summable sequence x(n) can easily be computed in the frequency domain by multiplying the transform X(ejω ) and the frequency
response H(ejω ). However, there are two shortcomings to the Fourier
transform approach. First, there are many useful signals in practice—
such as u(n) and nu(n)—for which the discrete-time Fourier transform
does not exist. Second, the transient response of a system due to initial conditions or due to changing inputs cannot be computed using the
discrete-time Fourier transform approach.
Therefore we now consider an extension of the discrete-time Fourier
transform to address the above two problems. This extension is called the
z-transform. Its bilateral (or two-sided) version provides another domain
in which a larger class of sequences and systems can be analyzed, while its
unilateral (or one-sided) version can be used to obtain system responses
with initial conditions or changing inputs.
THE BILATERAL z-TRANSFORM
The z-transform of a sequence x(n) is given by
∞
x(n)z −n
X(z) = Z[x(n)] =
(4.1)
n=−∞
80
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where z is a complex variable. The set of z values for which X(z) exists
is called the region of convergence (ROC) and is given by
Rx− < |z| < Rx+
(4.2)
for some non-negative numbers Rx− and Rx+ .
The inverse z-transform of a complex function X(z) is given by
x(n) = Z −1 [X(z)] =
1
2πj
X(z)z n−1 dz
(4.3)
C
where C is a counterclockwise contour encircling the origin and lying
in the ROC.
Comments:
1. The complex variable z is called the complex frequency given by z =
|z|ejω , where |z| is the magnitude and ω is the real frequency.
2. Since the ROC (4.2) is defined in terms of the magnitude |z|, the shape
of the ROC is an open ring as shown in Figure 4.1. Note that Rx− may
be equal to zero and/or Rx+ could possibly be ∞.
3. If Rx+ < Rx− , then the ROC is a null space and the z-transform does
not exist.
4. The function |z| = 1 (or z = ejω ) is a circle of unit radius in the z-plane
and is called the unit circle. If the ROC contains the unit circle, then
we can evaluate X(z) on the unit circle.
X(z)|z=ejω = X(ejω ) =
∞
x(n)e−jω = F[x(n)]
n=−∞
Therefore the discrete-time Fourier transform X(ejω ) may be viewed
as a special case of the z-transform X(z).
Im{z}
Rx+
R e{z}
Rx –
FIGURE 4.1
The Bilateral z -Transform
A general region of convergence
81
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Im{z}
a
Re{z}
0
FIGURE 4.2
EXAMPLE 4.1
The ROC in Example 4.1
Let x1 (n) = an u(n),
sequence). Then
X1 (z) =
∞
0 < |a| < ∞. (This sequence is called a positive-time
an z −n =
0
=
z
,
z−a
∞ a n
z
0
=
1
;
1 − az −1
|z| > |a| ⇒ ROC1 :
a
if < 1
z
|a| < |z| <
∞
Rx+
Rx−
Note:
X1 (z) in this example is a rational function; that is,
X1 (z) =
B(z)
z
=
A(z)
z−a
where B(z) = z is the numerator polynomial and A(z) = z−a is the denominator
polynomial. The roots of B(z) are called the zeros of X(z), while the roots of
A(z) are called the poles of X(z). In this example X1 (z) has a zero at the origin
z = 0 and a pole at z = a. Hence x1 (n) can also be represented by a pole-zero
diagram in the z-plane in which zeros are denoted by ‘◦’ and poles by ‘×’ as
shown in Figure 4.2.
EXAMPLE 4.2
Let x2 (n) = −bn u(−n−1), 0 < |b| < ∞. (This sequence is called a negative-time
sequence.) Then
X2 (z) = −
−1
−∞
=1−
bn z −n = −
−1 n
b
−∞
1
z
=
,
1 − z/b
z−b
z
=−
∞ z n
1
b
=1−
∞ z n
0
b
0 < |z| < |b|
ROC2 : Rx−
Rx+
The ROC2 and the pole-zero plot for this x2 (n) are shown in Figure 4.3.
Im{z}
0
FIGURE 4.3
82
Re{z}
b
The ROC in Example 4.2
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Note: If b = a in this example, then X2 (z) = X1 (z) except for their respective
ROCs; that is, ROC1 = ROC2 . This implies that the ROC is a distinguishing
feature that guarantees the uniqueness of the z-transform. Hence it plays a very
important role in system analysis.
EXAMPLE 4.3
Let x3 (n) = x1 (n) + x2 (n) = an u(n) − bn u(−n − 1) (This sequence is called a
two-sided sequence.) Then using the above two examples,
X3 (z) =
∞
n −n
a z
−
−1
bn z −n
−∞
n=0
z
z
=
, ROC1 : |z| > |a| +
, ROC1 : |z| < |b|
z−a
z−b
z
z
=
+
; ROC3 : ROC1 ∩ ROC2
z−a
z−b
If |b| < |a|, the ROC3 is a null space and X3 (z) does not exist. If |a| < |b|,
then the ROC3 is |a| < |z| < |b| and X3 (z) exists in this region as shown in
Figure 4.4.
PROPERTIES
OF THE ROC
From the observation of the ROCs in the above three examples, we state
the following properties.
1. The ROC is always bounded by a circle since the convergence
condition is on the magnitude |z|.
2. The sequence x1 (n) = an u(n) in Example 4.1 is a special case of a
right-sided sequence, defined as a sequence x(n) that is zero for some
n < n0 . From Example 4.1 the ROC for right-sided sequences is always
outside of a circle of radius Rx− . If n0 ≥ 0, then the right-sided
sequence is also called a causal sequence.
3. The sequence x2 (n) = −bn u(−n−1) in Example 4.2 is a special case of a
left-sided sequence, defined as a sequence x(n) that is zero for some n >
n0 . If n0 ≤ 0, the resulting sequence is called an anticausal sequence.
From Example 4.2 the ROC for left-sided sequences is always inside
of a circle of radius Rx+ .
Im{z}
Im{z}
a
a
0
Re{z}
b
a>b
FIGURE 4.4
The Bilateral z -Transform
Re{z}
0
b
a<b
The ROC in Example 4.3
83
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4. The sequence x3 (n) in Example 4.3 is a two-sided sequence. The ROC
for two-sided sequences is always an open ring Rx− < |z| < Rx+
if it exists.
5. The sequences that are zero for n < n1 and n > n2 are called
finite-duration sequences. The ROC for such sequences is the entire
z-plane. If n1 < 0, then z = ∞ is not in the ROC. If n2 > 0, then
z = 0 is not in the ROC.
6. The ROC cannot include a pole since X(z) converges uniformly in
there.
7. There is at least one pole on the boundary of a ROC of a rational X(z).
8. The ROC is one contiguous region; that is, the ROC does not come in
pieces.
In digital signal processing, signals are assumed to be causal since
almost every digital data is acquired in real time. Therefore the only
ROC of interest to us is the one given in 2 above.
IMPORTANT PROPERTIES OF THE z-TRANSFORM
The properties of the z-transform are generalizations of the properties
of the discrete-time Fourier transform that we studied in Chapter 3. We
state the following important properties of the z-transform without proof.
1. Linearity:
Z [a1 x1 (n) + a2 x2 (n)] = a1 X1 (z) + a2 X2 (z);
ROC: ROCx1 ∩ ROCx2
(4.4)
2. Sample shifting:
Z [x (n − n0 )] = z −n0 X(z);
ROC: ROCx
(4.5)
3. Frequency shifting:
Z [an x(n)] = X
z a
;
ROC: ROCx scaled by |a|
(4.6)
ROC: Inverted ROCx
(4.7)
4. Folding:
Z [x (−n)] = X (1/z) ;
5. Complex conjugation:
Z [x∗ (n)] = X ∗ (z ∗ );
84
ROC: ROCx
Chapter 4
(4.8)
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
6. Differentiation in the z-domain:
Z [nx(n)] = −z
dX(z)
;
dz
ROC: ROCx
(4.9)
This property is also called “multiplication by a ramp” property.
7. Multiplication:
1
X1 (ν)X2 (z/ν) ν −1 dν;
(4.10)
Z [x1 (n)x2 (n)] =
2πj C
ROC: ROCx1 ∩ Inverted ROCx2
where C is a closed contour that encloses the origin and lies in the
common ROC.
8. Convolution:
Z [x1 (n) ∗ x2 (n)] = X1 (z)X2 (z);
ROC: ROCx1 ∩ ROCx2
(4.11)
This last property transforms the time-domain convolution operation
into a multiplication between two functions. It is a significant property
in many ways. First, if X1 (z) and X2 (z) are two polynomials, then their
product can be implemented using the conv function in MATLAB.
EXAMPLE 4.4
Solution
Let X1 (z) = 2 + 3z −1 + 4z −2 and X2 (z) = 3 + 4z −1 + 5z −2 + 6z −3 . Determine
X3 (z) = X1 (z)X2 (z).
From the definition of the z-transform we observe that
x1 (n) = {2, 3, 4}
↑
and
x2 (n) = {3, 4, 5, 6}
↑
Then the convolution of the above two sequences will give the coefficients of the
required polynomial product.
MATLAB Script:
>> x1 = [2,3,4]; x2 = [3,4,5,6]; x3 = conv(x1,x2)
x3 =
6
17
34
43
38
24
Hence
X3 (z) = 6 + 17z −1 + 34z −2 + 43z −3 + 38z −4 + 24z −5
Using the conv m function developed in Chapter 2, we can also multiply
two z-domain polynomials corresponding to noncausal sequences.
EXAMPLE 4.5
Let X1 (z) = z + 2 + 3z −1 and X2 (z) = 2z 2 + 4z + 3 + 5z −1 . Determine X3 (z) =
X1 (z)X2 (z).
Important Properties of the z -Transform
85
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
Note that
x1 (n) = {1, 2, 3}
and
↑
x2 (n) = {2, 4, 3, 5}
↑
Using the MATLAB Script,
>> x1 = [1,2,3]; n1 = [-1:1]; x2 = [2,4,3,5]; n2 = [-2:1];
>> [x3,n3] = conv_m(x1,n1,x2,n2)
x3 =
2
8
17
23
19
15
n3 =
-3
-2
-1
0
1
2
we have
X3 (z) = 2z 3 + 8z 2 + 17z + 23 + 19z −1 + 15z −2
In passing we note that to divide one polynomial by another one, we
would require an inverse operation called deconvolution [22, Chapter 6].
In MATLAB [p,r] = deconv(b,a) computes the result of dividing b by
a in a polynomial part p and a remainder r. For example, if we divide the
polynomial X3 (z) in Example 4.4 by X1 (z),
>> x3 = [6,17,34,43,38,24]; x1 = [2,3,4]; [x2,r] = deconv(x3,x1)
x2 =
3
4
5
6
r =
0
0
0
0
0
0
then we obtain the coefficients of the polynomial X2 (z) as expected. To
obtain the sample index, we will have to modify the deconv function as
we did in the conv m function. This is explored in Problem P4.10. This
operation is useful in obtaining a proper rational part from an improper
rational function.
The second important use of the convolution property is in system
output computations as we shall see in a later section. This interpretation
is particularly useful for verifying the z-transform expression X(z) of a
casual sequence using MATLAB. Note that since MATLAB is a numerical
processor (unless the Symbolic toolbox is used), it cannot be used for
symbolic z-transform calculations. We will now elaborate on this. Let
x(n) be a sequence with a rational transform
X(z) =
B(z)
A(z)
where B(z) and A(z) are polynomials in z −1 . If we use the coefficients of
B(z) and A(z) as the b and a arrays in the filter routine and excite this
86
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
filter by the impulse sequence δ(n), then from (4.11) and using Z[δ(n)] =
1, the output of the filter will be x(n). (This is a numerical approach
of computing the inverse z-transform; we will discuss the analytical approach in the next section.) We can compare this output with the given
x(n) to verify that X(z) is indeed the transform of x(n). This is illustrated in Example 4.6. An equivalent approach is to use the impz function
discussed in Chapter 2.
SOME
COMMON
z-TRANSFORM
PAIRS
Using the definition of z-transform and its properties, one can determine
z-transforms of common sequences. A list of some of these sequences is
given in Table 4.1.
TABLE 4.1
Some common z-transform pairs
Sequence
δ(n)
u(n)
−u(−n − 1)
an u(n)
−bn u(−n − 1)
EXAMPLE 4.6
Solution
Transform
ROC
1
∀z
1
1 − z −1
1
1 − z −1
1
1 − az −1
1
1 − bz −1
|z| > 1
|z| < 1
|z| > |a|
|z| < |b|
[an sin ω0 n] u(n)
(a sin ω0 )z −1
1 − (2a cos ω0 )z −1 + a2 z −2
|z| > |a|
[an cos ω0 n] u(n)
1 − (a cos ω0 )z −1
1 − (2a cos ω0 )z −1 + a2 z −2
|z| > |a|
nan u(n)
az −1
(1 − az −1 )2
|z| > |a|
−nbn u(−n − 1)
bz −1
(1 − bz −1 )2
|z| < |b|
Using z-transform properties and the z-transform table, determine the ztransform of
π
x(n) = (n − 2)(0.5)(n−2) cos
(n − 2) u(n − 2)
3
Applying the sample-shift property,
X(z) = Z[x(n)] = z −2 Z n(0.5)n cos
Important Properties of the z -Transform
πn
u(n)
3
87
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
with no change in the ROC. Applying the multiplication by a ramp property,
X(z) = z −2
−z
dZ[(0.5)n cos( π3 n)u(n)]
dz
with no change in the ROC. Now the z-transform of (0.5)n cos( π3 n)u(n) from
Table 4.1 is
Z (0.5)n cos
1 − (0.5 cos π3 )z −1
πn
u(n) =
;
3
1 − 2(0.5 cos π3 )z −1 + 0.25z −2
=
1 − 0.25z −1
;
1 − 0.5z −1 + 0.25z −2
|z| > 0.5
|z| > 0.5
Hence
X(z) = −z
−1
= −z
−1
d
dz
=
1−
1 − 0.25z −1
1 − 0.5z −1 + 0.25z −2
|z| > 0.5
,
−0.25z −2 + 0.5z −3 − 0.0625z −4
1 − z −1 + 0.75z −2 − 0.25z −3 + 0.0625z −4
,
0.25z −3 − 0.5z −4 + 0.0625z −5
,
+ 0.75z −2 − 0.25z −3 + 0.0625z −4
|z| > 0.5
|z| > 0.5
z −1
MATLAB verification: To check that the above X(z) is indeed the correct expression, let us compute the first 8 samples of the sequence x(n) corresponding
to X(z) as discussed before.
>> b = [0,0,0,0.25,-0.5,0.0625]; a = [1,-1,0.75,-0.25,0.0625];
>> [delta,n]=impseq(0,0,7)
delta =
1
0
0
0
0
0
0
0
n =
0
1
2
3
4
5
6
7
>> x = filter(b,a,delta) % check sequence
x =
Columns 1 through 4
0
0
0 0.25000000000000
Columns 5 through 8
-0.25000000000000 -0.37500000000000 -0.12500000000000
0.07812500000000
>> x = [(n-2).*(1/2).^(n-2).*cos(pi*(n-2)/3)].*stepseq(2,0,7) % original sequence
x =
Columns 1 through 4
0
0
0 0.25000000000000
Columns 5 through 8
-0.25000000000000 -0.37500000000000 -0.12500000000000
0.07812500000000
This approach can be used to verify the z-transform computations.
88
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
INVERSION OF THE z-TRANSFORM
From equation (4.3) the inverse z-transform computation requires an evaluation of a complex contour integral that, in general, is a complicated
procedure. The most practical approach is to use the partial fraction expansion method. It makes use of the z-transform Table 4.1 (or similar
tables available in many textbooks.) The z-transform, however, must be
a rational function. This requirement is generally satisfied in digital signal
processing.
Central Idea: When X(z) is a rational function of z −1 , it can be expressed as a sum of simple factors using the partial fraction expansion.
The individual sequences corresponding to these factors can then be written down using the z-transform table.
The inverse z-transform procedure can be summarized as follows:
Method:
Given
X(z) =
b0 + b1 z −1 + · · · + bM z −M
, Rx− < |z| < Rx+
1 + a1 z −1 + · · · + aN z −N
(4.12)
• express it as
M
−N
b̃0 + b̃1 z −1 + · · · + b̃N −1 z −(N −1)
+
X(z) =
1 + a1 z −1 + · · · + aN z −N
Proper rational part
k=0
Ck z −k
polynomial part if M ≥N
where the first term on the right-hand side is the proper rational part
and the second term is the polynomial (finite-length) part. This can
be obtained by performing polynomial division if M ≥ N using the
deconv function.
• perform a partial fraction expansion on the proper rational part of X(z)
to obtain
N
M
−N
Rk
+
Ck z −k
(4.13)
X(z) =
1 − pk z −1
k=1
k=0
M ≥N
where pk is the kth pole of X(z) and Rk is the residue at pk . It is
assumed that the poles are distinct for which the residues are given by
b̃0 + b̃1 z −1 + · · · + b̃N −1 z −(N −1)
−1 Rk =
(1
−
p
z
)
k
1 + a1 z −1 + · · · + aN z −N
z=pk
Inversion of the z -Transform
89
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
For repeated poles the expansion (4.13) has a more general form. If a
pole pk has multiplicity r, then its expansion is given by
r
Rk, z −(
=1
−1)
(1 − pk z −1 )
=
Rk,1
Rk,2 z −1
Rk,r z −(r−1)
+
+
·
·
·
+
r
2
1 − pk z −1
(1 − pk z −1 )
(1 − pk z −1 )
(4.14)
where the residues Rk, are computed using a more general formula,
which is available in [22].
• assuming distinct poles as in (4.13), write x(n) as
x(n) =
N
Rk Z −1
k=1
M
−N
1
+
Ck δ(n − k)
1 − pk z −1
k=0
M ≥N
• finally, use the relation from Table 4.1
pnk u(n)
|zk | ≤ Rx−
z
−1
=
Z
n
z − pk
−pk u(−n − 1) |zk | ≥ Rx+
(4.15)
to complete x(n). A similar procedure is used for repeated poles.
EXAMPLE 4.7
Solution
Find the inverse z-transform of x(z) =
z
.
3z 2 − 4z + 1
Write
X(z) =
=
z
=
3(z 2
−
(1 −
1 −1
z
3
−1
z )(1 − 13 z −1 )
4
z
3
+
1
)
3
1−
1 −1
z
3
4 −1
z
+ 13 z −2
3
=
or
X(z) =
1
2
1
1 − z −1
−
1
2
1
2
1−
z −1
−
1−
1
1
2
1 −1
z
3
1 − 13 z −1
Now, X(z) has two poles: z1 = 1 and z2 = 13 ; and since the ROC is not specified,
there are three possible ROCs as shown in Figure 4.5.
a. ROC1 : 1 < |z| < ∞. Here both poles are on the interior side of the ROC1 ;
that is, |z1 | ≤ Rx− = 1 and |z2 | ≤ 1. Hence from (4.15)
x1 (n) =
1
1
u(n) −
2
2
n
1
3
u(n)
which is a right-sided sequence.
90
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Im{z}
0 1/3
Im{z}
Re{z}
Re{z}
1
1/3
ROC1
FIGURE 4.5
Im{z}
Re{z}
1
1/3
ROC 2
1
ROC 3
The ROCs in Example 4.7
b. ROC2 : 0 < |z| < 13 . Here both poles are on the exterior side of the ROC2 ;
that is, |z1 | ≥ Rx+ = 13 and |z2 | ≥ 13 . Hence from (4.15)
x2 (n) =
=
1
1 1 n
− 3 u(−n − 1)
{−u(−n − 1)} −
2
2
1
2
n
1
3
u(−n − 1) −
1
u(−n − 1)
2
which is a left-sided sequence.
c. ROC3 : 13 < |z| < 1. Here pole z1 is on the exterior side of the ROC3 —that
is, |z1 | ≥ Rx+ = 1—while pole z2 is on the interior side—that is, |z2 | ≤ 13 .
Hence from (4.15)
1
1
x3 (n) = − u(−n − 1) −
2
2
n
1
3
u(n)
which is a two-sided sequence.
MATLAB
IMPLEMENTATION
A MATLAB function residuez is available to compute the residue part
and the direct (or polynomial) terms of a rational function in z −1 . Let
X(z) =
=
B(z)
b0 + b1 z −1 + · · · + bM z −M
=
a0 + a1 z −1 + · · · + aN z −N
A(z)
M
−N
Rk
+
Ck z −k
1 − pk z −1
k=1
k=0
N
M ≥N
be a rational function in which the numerator and the denominator polynomials are in ascending powers of z −1 . Then [R,p,C]=residuez(b,a)
computes the residues, poles, and direct terms of X(z) in which two polynomials B(z) and A(z) are given in two vectors b and a, respectively.
The returned column vector R contains the residues, column vector p
Inversion of the z -Transform
91
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
contains the pole locations, and row vector C contains the direct terms.
If p(k)=...=p(k+r-1) is a pole of multiplicity r, then the expansion includes the term of the form
Rk
Rk+1
Rk+r−1
+
+ ··· +
r
2
−1
1 − pk z
(1 − pk z −1 )
(1 − pk z −1 )
(4.16)
which is different from (4.14).
Similarly, [b,a]=residuez(R,p,C), with three input arguments and
two output arguments, converts the partial fraction expansion back to
polynomials with coefficients in row vectors b and a.
EXAMPLE 4.8
To check our residue calculations, let us consider the rational function
z
3z 2 − 4z + 1
X(z) =
given in Example 4.7.
Solution
First rearrange X(z) so that it is a function in ascending powers of z −1 .
X(z) =
0 + z −1
z −1
=
−1
−2
3 − 4z + z
3 − 4z −1 + z −2
Now using the MATLAB Script,
>> b = [0,1]; a = [3,-4,1]; [R,p,C] = residuez(b,a)
R =
0.5000
-0.5000
p =
1.0000
0.3333
c =
[]
we obtain
X(z) =
1
2
1−
z −1
−
1−
1
2
1 −1
z
3
as before. Similarly, to convert back to the rational function form,
>> [b,a] = residuez(R,p,C)
b =
0.0000
0.3333
92
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
a =
1.0000
-1.3333
0.3333
so that
X(z) =
0 + 13 z −1
z −1
z
=
= 2
4 −1
1 −2
3 − 4z −1 + z −2
3z − 4z + 1
1 − 3z + 3z
as before.
EXAMPLE 4.9
Compute the inverse z-transform of
X(z) =
Solution
1
,
(1 − 0.9z −1 )2 (1 + 0.9z −1 )
|z| > 0.9
We will evaluate the denominator polynomial as well as the residues using the
MATLAB Script:
>> b = 1; a = poly([0.9,0.9,-0.9])
a =
1.0000
-0.9000
-0.8100
>> [R,p,C]=residuez(b,a)
R =
0.2500
0.5000
0.2500
p =
0.9000
0.9000
-0.9000
c =
[]
0.7290
Note that the denominator polynomial is computed using MATLAB’s polynomial function poly, which computes the polynomial coefficients, given its roots.
We could have used the conv function, but the use of the poly function is more
convenient for this purpose. From the residue calculations and using the order
of residues given in (4.16), we have
X(z) =
0.25
0.5
0.25
+
+
,
2
−1
1 − 0.9z −1
1
+
0.9z −1
(1 − 0.9z )
0.9z −1
0.25
0.5
0.25
=
+
+
,
z
1 − 0.9z −1
0.9 (1 − 0.9z −1 )2
1 + 0.9z −1
Inversion of the z -Transform
|z| > 0.9
|z| > 0.9
93
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Hence from Table 4.1 and using the z-transform property of time-shift,
5
(n + 1)(0.9)n+1 u(n + 1) + 0.25 (−0.9)n u(n)
9
which upon simplification becomes
x(n) = 0.25(0.9)n u(n) +
x(n) = 0.75(0.9)n u(n) + 0.5n(0.9)n u(n) + 0.25 (−0.9)n u(n)
MATLAB verification:
>> [delta,n] = impseq(0,0,7); x = filter(b,a,delta) % check sequence
x =
Columns 1 through 4
1.00000000000000
0.90000000000000
1.62000000000000
1.45800000000000
Columns 5 through 8
1.96830000000000
1.77147000000000
2.12576400000000
1.91318760000000
>> x = (0.75)*(0.9).^n + (0.5)*n.*(0.9).^n + (0.25)*(-0.9).^n % answer sequence
x =
Columns 1 through 4
1.00000000000000
0.90000000000000
1.62000000000000
1.45800000000000
Columns 5 through 8
1.96830000000000
1.77147000000000
2.12576400000000
1.91318760000000
EXAMPLE 4.10
Determine the inverse z-transform of
X(z) =
√
1 + 0.4 2z −1
√
1 − 0.8 2z −1 + 0.64z −2
so that the resulting sequence is causal and contains no complex numbers.
Solution
We will have to find the poles of X(z) in the polar form to determine the ROC
of the causal sequence.
MATLAB Script:
>> b = [1,0.4*sqrt(2)]; a=[1,-0.8*sqrt(2),0.64];
>> [R,p,C] = residuez(b,a)
R =
0.5000 - 1.0000i
0.5000 + 1.0000i
p =
0.5657 + 0.5657i
0.5657 - 0.5657i
C =
[]
>> Mp=(abs(p))’
% pole magnitudes
Mp =
0.8000
0.8000
>> Ap=(angle(p))’/pi
% pole angles in pi units
Ap =
0.2500
-0.2500
94
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
From the above calculations
X(z) =
0.5 + j
0.5 − j
+
,
π
π
1 − 0.8e+j 4 z −1
1 − 0.8e−j 4 z −1
|z| > 0.8
and from Table 4.1 we have
π
π
x(n) = (0.5 − j) 0.8n e+j 4 n u(n) + (0.5 + j) 0.8n e−j 4 n u(n)
π
π
π
π
= 0.8n [0.5{e+j 4 n + e−j 4 n } − j{e+j 4 n − e−j 4 n }]u(n)
= 0.8n cos
πn
4
+ 2 sin
πn
4
u(n)
MATLAB verification:
>> [delta, n] = impseq(0,0,6);
x = filter(b,a,delta) % check sequence
x =
Columns 1 through 4
1.00000000000000
1.69705627484771
1.28000000000000
Columns 5 through 8
-0.40960000000000 -0.69511425017762 -0.52428800000000
>> x = ((0.8).^n).*(cos(pi*n/4)+2*sin(pi*n/4))
x =
Columns 1 through 4
1.00000000000000
1.69705627484771
1.28000000000000
Columns 5 through 8
-0.40960000000000 -0.69511425017762 -0.52428800000000
0.36203867196751
-0.14829104003789
0.36203867196751
-0.14829104003789
SYSTEM REPRESENTATION IN THE z-DOMAIN
Similar to the frequency response function H(ejω ), we can define the
z-domain function, H(z), called the system function. However, unlike
H(ejω ), H(z) exists for systems that may not be BIBO stable.
DEFINITION 1
The System Function
The system function H(z) is given by
H(z) = Z [h(n)] =
∞
h(n)z −n ;
Rh− < |z| < Rh+
(4.17)
−∞
Using the convolution property (4.11) of the z-transform, the output
transform Y (z) is given by
Y (z) = H(z) X(z)
System Representation in the z -Domain
: ROCy = ROCh ∩ ROCx
(4.18)
95
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
provided ROCx overlaps with ROCh . Therefore a linear and timeinvariant system can be represented in the z-domain by
X(z) −→ H(z) −→ Y (z) = H(z) X(z)
SYSTEM
FUNCTION
FROM THE
DIFFERENCE
EQUATION
REPRESENTATION
When LTI systems are described by a difference equation
y(n) +
N
ak y(n − k) =
M
k=1
b x(n − )
(4.19)
=0
the system function H(z) can easily be computed. Taking the z-transform
of both sides, and using properties of the z-transform,
Y (z) +
N
ak z −k Y (z) =
M
k=1
b z − X(z)
=0
or
M
−
Y (z)
B(z)
=0 b z
H(z) =
=
=
N
−k
X(z)
A(z)
1 + k=1 ak z
b0 z −M z M + · · · + bbM0
=
z −N (z N + · · · + aN )
(4.20)
After factorization, we obtain
H(z) = b0 z
N −M
N
=1 (z
−z )
k=1 (z
− pk )
N
(4.21)
where z ’s are the system zeros and pk ’s are the system poles. Thus H(z)
(and hence an LTI system) can also be represented in the z-domain using
a pole-zero plot. This fact is useful in designing simple filters by proper
placement of poles and zeros.
To determine zeros and poles of a rational H(z), we can use the
MATLAB function roots on both the numerator and the denominator
polynomials. (Its inverse function poly determines polynomial coefficients
from its roots as we discussed in the previous section.) It is also possible
to use MATLAB to plot these roots for a visual display of a pole-zero plot.
The function zplane(b,a) plots poles and zeros, given the numerator row
vector b and the denominator row vector a. As before, the symbol “o”
represents a zero and the symbol “x” represents a pole. The plot includes
the unit circle for reference. Similarly, zplane(z,p) plots the zeros in
96
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
column vector z and the poles in column vector p. Note very carefully the
form of the input arguments for the proper use of this function.
TRANSFER
FUNCTION
REPRESENTATION
If the ROC of H(z) includes a unit circle (z = ejω ), then we can evaluate
H(z) on the unit circle, resulting in a frequency response function or
transfer function H(ejω ). Then from (4.21)
j(N −M )ω
jω
H(e ) = b0 e
M
1
(ejω − z )
1
(ejω − pk )
N
(4.22)
The factor (ejω −z ) can be interpreted as a vector in the complex z-plane
from a zero z to the unit circle at z = ejω , while the factor (ejω − pk )
can be interpreted as a vector from a pole pk to the unit circle at z = ejω .
This is shown in Figure 4.6. Hence the magnitude response function
|H(ejω )| = |b0 |
|ejω − z1 | · · · |ejω − zM |
|ejω − p1 | · · · |ejω − pN |
(4.23)
can be interpreted as a product of the lengths of vectors from zeros to the
unit circle divided by the lengths of vectors from poles to the unit circle
and scaled by |b0 |. Similarly, the phase response function
H(ejω ) =[0 or π] + [(N − M ) ω] +
constant
linear
M
(ejω − zk ) −
1
N
(ejω − pk )
1
nonlinear
(4.24)
can be interpreted as a sum of a constant factor, a linear-phase factor,
and a nonlinear-phase factor (angles from the “zero vectors” minus the
sum of angles from the “pole vectors”).
Im{z}
pk
w
0
Unit
circle
FIGURE 4.6
System Representation in the z -Domain
Re{z}
zl
Pole and zero vectors
97
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB
IMPLEMENTATION
In Chapter 3 we plotted magnitude and phase responses in MATLAB by
directly implementing their functional forms. MATLAB also provides a
function called freqz for this computation, which uses the interpretation
given above. In its simplest form this function is invoked by
[H,w] = freqz(b,a,N)
which returns the N-point frequency vector w and the N-point complex frequency response vector H of the system, given its numerator and denominator coefficients in vectors b and a. The frequency response is evaluated
at N points equally spaced around the upper half of the unit circle. Note
that the b and a vectors are the same vectors we use in the filter function or derived from the difference equation representation (4.19). The
second form
[H,w] = freqz(b,a,N,’whole’)
uses N points around the whole unit circle for computation. In yet another
form
H = freqz(b,a,w)
it returns the frequency response at frequencies designated in vector w,
normally between 0 and π. It should be noted that the freqz function can
also be used for numerical computation of the DTFT of a finite-duration,
causal sequence x(n). In this approach, b = x and a = 1.
EXAMPLE 4.11
Given a causal system
y(n) = 0.9y(n − 1) + x(n)
a. Determine H(z) and sketch its pole-zero plot.
b. Plot |H(ejω )| and H(ejω ).
c. Determine the impulse response h(n).
Solution
The difference equation can be put in the form
y(n) − 0.9y(n − 1) = x(n)
a. From (4.21)
H(z) =
1
;
1 − 0.9z −1
|z| > 0.9
since the system is causal. There is one pole at 0.9 and one zero at the origin.
We will use MATLAB to illustrate the use of the zplane function.
98
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> b = [1, 0]; a = [1, -0.9];
zplane(b,a)
Note that we specified b=[1,0] instead of b=1 because the zplane function
assumes that scalars are zeros or poles. The resulting pole-zero plot is shown
in Figure 4.7.
b. Using (4.23) and (4.24), we can determine the magnitude and phase of
H(ejω ). Once again we will use MATLAB to illustrate the use of the freqz
function. Using its first form, we will take 100 points along the upper half of
the unit circle.
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
[H,w] = freqz(b,a,100); magH = abs(H); phaH = angle(H);
subplot(2,1,1);plot(w/pi,magH);grid
xlabel(’frequency in pi units’); ylabel(’Magnitude’);
title(’Magnitude Response’)
subplot(2,1,2);plot(w/pi,phaH/pi);grid
xlabel(’frequency in pi units’); ylabel(’Phase in pi units’);
title(’Phase Response’)
The response plots are shown in Figure 4.8. If you study these plots carefully,
you will observe that the plots are computed between 0 ≤ ω ≤ 0.99π and
Pole–Zero Plot
1
0.8
0.6
Imaginary part
0.4
0.2
0
0
0.9
−0.2
−0.4
−0.6
−0.8
−1
−1
FIGURE 4.7
System Representation in the z -Domain
−0.5
0
Real part
0.5
1
Pole-zero plot of Example 4.11a
99
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Magnitude
15
10
5
0
0
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
1
0.7
0.8
0.9
1
Phase Response
Phase in pi units
0
−0.1
−0.2
−0.3
−0.4
0
FIGURE 4.8
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
Frequency response plots in Example 4.11
fall short at ω = π. This is due to the fact that in MATLAB the lower half
of the unit circle begins at ω = π. To overcome this problem, we will use the
second form of the freqz function as follows.
>> [H,w] = freqz(b,a,200,’whole’);
>> magH = abs(H(1:101)); phaH = angle(H(1:101));
Now the 101st element of the array H will correspond to ω = π. A similar
result can be obtained using the third form of the freqz function.
>> w = [0:1:100]*pi/100; H = freqz(b,a,w);
>> magH = abs(H); phaH = angle(H);
In the future we will use any one of these forms, depending on our convenience. Also note that in the plots we divided the w and phaH arrays by pi
so that the plot axes are in the units of π and easier to read. This practice
is strongly recommended.
c. From the z-transform Table 4.1
h(n) = Z −1
100
1
, |z| > 0.9 = (0.9)n u(n)
1 − 0.9z −1
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 4.12
Given that
H(z) =
z+1
z 2 − 0.9z + 0.81
is a causal system, find
a. its transfer function representation,
b. its difference equation representation, and
c. its impulse response representation.
Solution
The poles of the system function are at z = 0.9 ± π/3. Hence the ROC of the
above causal system is |z| > 0.9. Therefore the unit circle is in the ROC, and
the discrete-time Fourier transform H(ejω ) exists.
a. Substituting z = ejω in H(z),
H(ejω ) =
ej2ω
ejω + 1
ejω + 1
= jω
jω
jπ/3
− 0.9e + 0.81
(e − 0.9e
)(ejω − 0.9e−jπ/3 )
b. Using H(z) = Y (z)/X(z),
Y (z)
z+1
= 2
X(z)
z − 0.9z + 0.81
z −2
z −2
=
z −1 + z −2
1 − 0.9z −1 + 0.81z −2
Cross multiplying,
Y (z) − 0.9z −1 Y (z) + 0.81z −2 Y (z) = z −1 X(z) + z −2 X(z)
Now taking the inverse z-transform,
y(n) − 0.9y(n − 1) + 0.81y(n − 2) = x(n − 1) + x(n − 2)
or
y(n) = 0.9y(n − 1) − 0.81y(n − 2) + x(n − 1) + x(n − 2)
c. Using the MATLAB Script,
>> b = [0,1,1]; a = [1,-0.9,0.81];
R =
-0.6173 - 0.9979i
-0.6173 + 0.9979i
p =
0.4500 + 0.7794i
0.4500 - 0.7794i
C =
1.2346
>> Mp = (abs(p))’
Mp =
0.9000
0.9000
>> Ap = (angle(p))’/pi
Ap =
0.3333
-0.3333
System Representation in the z -Domain
[R,p,C] = residuez(b,a)
101
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
we have
H(z) = 1.2346 +
−0.6173 − j0.9979
−0.6173 + j0.9979
+
,
1 − 0.9e−jπ/3 z −1
1 − 0.9ejπ/3 z −1
|z| > 0.9
Hence from Table 4.1
h(n) = 1.2346δ(n) + [(−0.6173 + j0.9979)0.9n e−jπn/3
+(−0.6173 − j0.9979)0.9n ejπn/3 ]u(n)
= 1.2346δ(n) + 0.9n [−1.2346 cos(πn/3) + 1.9958 sin(πn/3)]u(n)
= 0.9n [−1.2346 cos(πn/3) + 1.9958 sin(πn/3)]u(n − 1)
The last step results from the fact that h(0) = 0.
RELATIONSHIPS In this and the previous two chapters we developed several system repreBETWEEN
sentations. Figure 4.9 depicts the relationships between these representaSYSTEM
tions in a graphical form.
REPRESENTATIONS
H (z)
Express H(z) in z –1
cross multiply and
take inverse
Take
z-transform
solve for Y /X
Take inverse
z -transform
Take
z-transform
Diff Eqn
h(n)
Substitute
z = e jw
Take DTFT
solve for Y /X
FIGURE 4.9
STABILITY
AND
CAUSALITY
102
Take inverse
DTFT
Take Fourier
transform
H (e jw )
System representations in pictorial form
∞
For LTI systems the BIBO stability is equivalent to −∞ |h(k)| < ∞.
From the existence of the discrete-time Fourier transform this stability
implies that H(ejω ) exists, which further implies that the unit circle |z| =
1 must be in the ROC of H(z). This result is called the z-domain stability
theorem; therefore the dashed paths in Figure 4.9 exist only if the system
is stable.
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
THEOREM 2
z-Domain LTI Stability
An LTI system is stable if and only if the unit circle is in the ROC
of H(z).
For LTI causality we require that h(n) = 0, for n < 0 (i.e., a rightsided sequence). This implies that the ROC of H(z) must be outside of
some circle of radius Rh− . This is not a sufficient condition since any
right-sided sequence has a similar ROC. However, when the system is
stable, then its causality is easy to check.
THEOREM 3
EXAMPLE 4.13
z-Domain Causal LTI Stability
A causal LTI system is stable if and only if the system function H(z)
has all its poles inside the unit circle.
A causal LTI system is described by the following difference equation:
y(n) = 0.81y(n − 2) + x(n) − x(n − 2)
Determine
a.
b.
c.
d.
Solution
the system function H(z),
the unit impulse response h(n),
the unit step response v(n), that is, the response to the unit step u(n), and
the frequency response function H(ejω ), and plot its magnitude and phase
over 0 ≤ ω ≤ π.
Since the system is causal, the ROC will be outside of a circle with radius equal
to the largest pole magnitude.
a. Taking the z-transform of both sides of the difference equation and then
solving for Y (z)/X(z) or using (4.20), we obtain
H(z) =
1 − z −2
1 − z −2
=
,
−2
1 − 0.81z
(1 + 0.9z −1 ) (1 − 0.9z −1 )
|z| > 0.9
b. Using the MATLAB Script for the partial fraction expansion,
>> b = [1,0,-1]; a = [1,0,-0.81]; [R,p,C] = residuez(b,a);
R =
-0.1173
-0.1173
p =
-0.9000
0.9000
C =
1.2346
System Representation in the z -Domain
103
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
we have
H(z) = 1.2346 − 0.1173
1
1
− 0.1173
, |z| > 0.9
1 + 0.9z −1
1 − 0.9z −1
or from Table 4.1
h(n) = 1.2346δ(n) − 0.1173 {1 + (−1)n } (0.9)n u(n)
c. From Table 4.1 Z[u(n)] = U (z) =
1
, |z| > 1. Hence
1 − z −1
V (z) = H(z)U (z)
=
(1 + z −1 )(1 − z −1 )
(1 + 0.9z −1 ) (1 − 0.9z −1 )
=
1 + z −1
,
(1 + 0.9z −1 ) (1 − 0.9z −1 )
1
, |z| > 0.9 ∩ |z| > 1
1 − z −1
|z| > 0.9
or
V (z) = 1.0556
1
1
− 0.0556
,
1 − 0.9z −1
1 + 0.9z −1
|z| > 0.9
Finally,
v(n) = [1.0556(0.9)n − 0.0556 (−0.9)n ] u(n)
Note that in the calculation of V (z) there is a pole-zero cancellation at z = 1.
This has two implications. First, the ROC of V (z) is still {|z| > 0.9} and not
{|z| > 0.9 ∩ |z| > 1 = |z| > 1}. Second, the step response v(n) contains no
steady-state term u(n).
d. Substituting z = ejω in H(z),
H(ejω ) =
1 − e−j2ω
1 − 0.81e−j2ω
We will use the MATLAB Script to compute and plot responses.
>>
>>
>>
>>
>>
>>
>>
>>
w = [0:1:500]*pi/500; H = freqz(b,a,w);
magH = abs(H); phaH = angle(H);
subplot(2,1,1); plot(w/pi,magH); grid
xlabel(’frequency in pi units’); ylabel(’Magnitude’)
title(’Magnitude Response’)
subplot(2,1,2); plot(w/pi,phaH/pi); grid
xlabel(’frequency in pi units’); ylabel(’Phase in pi units’)
title(’Phase Response’)
The frequency response plots are shown in Figure 4.10.
104
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Magnitude
1.5
1
0.5
0
0
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
1
0.7
0.8
0.9
1
Phase Response
Phase in pi units
0.5
0
−0.5
0
FIGURE 4.10
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
Frequency response plots for Example 4.13
SOLUTIONS OF THE DIFFERENCE EQUATIONS
In Chapter 2 we mentioned two forms for the solution of linear constant
coefficient difference equations. One form involved finding the particular and the homogeneous solutions, while the other form involved finding the zero-input (initial condition) and the zero-state responses. Using
z-transforms, we now provide a method for obtaining these forms. In addition, we will also discuss the transient and the steady-state responses.
In digital signal processing difference equations generally evolve in the
positive n direction. Therefore our time frame for these solutions will be
n ≥ 0. For this purpose we define a version of the bilateral z-transform
called the one-sided z-transform.
DEFINITION 4
The One-sided z Transform
The one-sided z-transform of a sequence x(n) is given by
Z + [x(n)] = Z [x(n)u(n)] = X + [z] =
∞
x(n)z −n
(4.25)
n=0
Solutions of the Difference Equations
105
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Then the sample shifting property is given by
Z + [x(n − k)] = Z [x(n − k)u(n)]
=
∞
x(n − k)z
−n
=
n=0
=
∞
x(m)z −(m+k)
m=−k
−1
x(m)z
−(m+k)
∞
+
x(m)z
−m
z −k
m=0
m=−k
or
Z + [x(n − k)] = x(−1)z 1−k + x(−2)z 2−k + · · · + x(−k) + z −k X + (z)
(4.26)
This result can now be used to solve difference equations with nonzero
initial conditions or with changing inputs. We want to solve the difference
equation
N
M
ak y(n − k) =
bm x(n − m), n ≥ 0
1+
m=0
k=1
subject to these initial conditions:
{y(i), i = −1, . . . , −N }
and {x(i), i = −1, . . . , −M }.
We now demonstrate its solution using an example.
EXAMPLE 4.14
Solve
y(n) −
3
1
y(n − 1) + y(n − 2) = x(n),
2
2
n≥0
where
n
x(n) =
1
4
u(n)
subject to y(−1) = 4 and y(−2) = 10.
Solution
Taking the one-sided z-transform of both sides of the difference equation, we
obtain
3
1
1
Y + (z) − [y(−1) + z −1 Y + (z)] + [y(−2) + z −1 y(−1) + z −2 Y + (z)] =
2
2
1 − 14 z −1
Substituting the initial conditions and rearranging,
Y + (z) 1 −
106
3 −1 1 −2
1
=
+ (1 − 2z −1 )
z + z
2
2
1 − 14 z −1
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
or
1
1 −1
1
−
z
1 − 2z −1
4
+
Y + (z) =
3 −1
1 −2
1 − 2z + 2z
1 − 32 z −1 + 12 z −2
(4.27)
Finally,
Y + (z) =
(1 −
2 − 94 z −1 + 12 z −2
1 −1
z )(1 − z −1 )(1 − 14 z −1 )
2
Using the partial fraction expansion, we obtain
Y + (z) =
1
1−
1 −1
z
2
+
2
3
1−
z −1
+
1−
1
3
1 −1
z
4
(4.28)
After inverse transformation the solution is
n
y(n) =
1
2
+
2
1
+
3
3
n
1
4
u(n)
(4.29)
Forms of the Solutions The above solution is the complete response
of the difference equation. It can be expressed in several forms.
• Homogeneous and particular parts:
n
n
1
2
1 1
y(n) =
u(n) +
+
u(n)
2
3
3 4
homogeneous part
particular part
The homogeneous part is due to the system poles and the particular
part is due to the input poles.
• Transient and steady-state responses:
n n 1 1
1
y(n) =
u(n) +
+
3 4
2
transient response
2
u(n)
3 steady-state response
The transient response is due to poles that are inside the unit circle,
while the steady-state response is due to poles that are on the unit
circle. Note that when the poles are outside the unit circle, the response
is termed an unbounded response.
• Zero-input (or initial condition) and zero-state responses:
In equation (4.27) Y + (z) has two parts. The first part can be interpreted as
YZS (z) = H(z)X(z)
Solutions of the Difference Equations
107
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
while the second part as
YZI (z) = H(z)XIC (z)
where XIC (z) can be thought of as an equivalent initial-condition input that generates the same output YZI as generated by the initial
conditions. In this example xIC (n) is
xIC (n) = {1, −2}
↑
Now taking the inverse z-transform of each part of (4.27), we write the
complete response as
n
n
n
1
8
1
1 1
u(n) + 3
−2
+
− 2 u(n)
y(n) =
3 4
2
3
2
zero-state response
zero-input response
From this example it is clear that each part of the complete solution
is, in general, a different function and emphasizes a different aspect of
system analysis.
MATLAB
IMPLEMENTATION
In Chapter 2 we used the filter function to solve the difference equation,
given its coefficients and an input. This function can also be used to find
the complete response when initial conditions are given. In this form the
filter function is invoked by
y = filter(b,a,x,xic)
where xic is an equivalent initial-condition input array. To find the complete response in Example 4.14, we will use the MATLAB Script
>> n = [0:7]; x = (1/4).^n; xic = [1, -2];
>> format long; y1 = filter(b,a,x,xic)
y1 =
Columns 1 through 4
2.00000000000000
1.25000000000000
0.93750000000000
0.79687500000000
Columns 5 through 8
0.73046875000000
0.69824218750000
0.68237304687500
0.67449951171875
>> y2 = (1/3)*(1/4).^n+(1/2).^n+(2/3)*ones(1,8) % MATLAB Check
y2 =
Columns 1 through 4
2.00000000000000
1.25000000000000
0.93750000000000
0.79687500000000
Columns 5 through 8
0.73046875000000
0.69824218750000
0.68237304687500
0.67449951171875
108
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
which agrees with the response given in (4.29). In Example 4.14 we computed xIC (n) analytically. However, in practice, and especially for largeorder difference equations, it is tedious to determine xIC (n) analytically.
MATLAB provides a function called filtic, which is available only in
the Signal Processing toolbox. It is invoked by
xic = filtic(b,a,Y,X)
in which b and a are the filter coefficient arrays and Y and X are the initialcondition arrays from the initial conditions on y(n) and x(n), respectively,
in the form
Y = [y(−1), y(−2), . . . , y(−N )]
X = [x(−1), x(−2), . . . , x(−M )]
If x(n) = 0, n ≤ −1 then X need not be specified in the filtic function.
In Example 4.14 we could have used
>> Y = [4, 10];
xic =
1
-2
xic = filtic(b,a,Y)
to determine xIC (n).
EXAMPLE 4.15
Solve the difference equation
y(n) =
1
[x(n) + x(n − 1) + x(n − 2)] + 0.95y(n − 1) − 0.9025y(n − 2),
3
n≥0
where x(n) = cos(πn/3)u(n) and
y(−1) = −2, y(−2) = −3;
x(−1) = 1, x(−2) = 1
First determine the solution analytically and then by using MATLAB.
Solution
Taking a one-sided z-transform of the difference equation
Y + (z) =
1 +
[X (z) + x(−1) + z −1 X + (z) + x(−2) + z −1 x(−1) + z −2 X + (z)]
3
+ 0.95[y(−1) + z −1 Y + (z)] − 0.9025[y(−2) + z −1 y(−1) + z −2 Y + (z)]
and substituting the initial conditions, we obtain
Y + (z) =
+ 13 z −1 + 13 z −2
1.4742 + 2.1383z −1
X + (z) +
1 − 0.95z −1 + 0.9025z −2
1 − 0.95z −1 + 0.9025z −2
1
3
1 − 0.5z −1
1 − z −1 + z −2
and simplifying, we will obtain Y + (z) as a rational function. This simplification
and further partial fraction expansion can be done using MATLAB as shown
below.
Clearly, xIC (n) = [1.4742, 2.1383]. Now substituting X + (z) =
Solutions of the Difference Equations
109
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB Script:
>> b = [1,1,1]/3; a = [1,-0.95,0.9025];
>> Y = [-2,-3]; X = [1,1]; xic=filtic(b,a,Y,X)
xic =
1.4742
2.1383
>> bxplus = [1,-0.5]; axplus = [1,-1,1]; % X(z) transform coeff.
>> ayplus = conv(a,axplus) % Denominator of Yplus(z)
ayplus =
1.0000
-1.9500
2.8525
-1.8525
0.9025
>> byplus = conv(b,bxplus)+conv(xic,axplus) % Numerator of Yplus(z)
byplus =
1.8075
0.8308
-0.4975
1.9717
>> [R,p,C] = residuez(byplus,ayplus)
R =
0.0584 + 3.9468i
0.0584 - 3.9468i
0.8453 + 2.0311i
0.8453 - 2.0311i
p =
0.5000 - 0.8660i
0.5000 + 0.8660i
0.4750 + 0.8227i
0.4750 - 0.8227i
C =
[]
>> Mp = abs(p), Ap = angle(p)/pi % Polar form
Mp =
1.0000
1.0000
0.9500
0.9500
Ap =
-0.3333
0.3333
0.3333
-0.3333
Hence
Y + (z) =
=
1.8075 + 0.8308z −1 − 0.4975z −2 + 1.9717z −3
1 − 1.95z −1 + 2.8525z −2 − 1.8525z −3 + 0.9025z −4
0.0584 + j3.9468
0.0584 − j3.9468
+
1 − e−jπ/3 z −1
1 − ejπ/3 z −1
+
0.8453 + j2.0311
0.8453 − j2.0311
+
1 − 0.95ejπ/3 z −1
1 − 0.95e−jπ/3 z −1
Now from Table 4.1
y(n) = (0.0584 + j3.9468) e−jπn/3 + (0.0584 − j3.9468) ejπn/3
+ (0.8453 + j2.031) (0.95)n ejπn/3 + (0.8453 − j2.031) (0.95)n e−jπn/3
= 0.1169 cos(πn/3) + 7.8937 sin(πn/3)
+ (0.95)n [1.6906 cos(πn/3) − 4.0623 sin(πn/3)] ,
n≥0
The first two terms of y(n) correspond to the steady-state response, as well as
to the particular response, while the last two terms are the transient response
(and homogeneous response) terms.
To solve this example using MATLAB, we will need the filtic function,
which we have already used to determine the xIC (n) sequence. The solution
will be a numerical one. Let us determine the first 8 samples of y(n).
110
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB Script:
>> n = [0:7]; x = cos(pi*n/3); y = filter(b,a,x,xic)
y =
Columns 1 through 4
1.80750000000000
4.35545833333333
2.83975000000000 -1.56637197916667
Columns 5 through 8
-4.71759442187500 -3.40139732291667
1.35963484230469
5.02808085078841
% Matlab Verification
>> A=real(2*R(1)); B=imag(2*R(1)); C=real(2*R(3)); D=imag(2*R(4));
>> y=A*cos(pi*n/3)+B*sin(pi*n/3)+((0.95).^n).*(C*cos(pi*n/3)+D*sin(pi*n/3))
y =
Columns 1 through 4
1.80750000000048
4.35545833333359
2.83974999999978 -1.56637197916714
Columns 5 through 8
-4.71759442187528 -3.40139732291648
1.35963484230515
5.02808085078871
PROBLEMS
P4.1 Determine the z-transform of the following sequences using the definition (4.1). Indicate the
region of convergence for each sequence and verify the z-transform expression using
MATLAB.
1. x(n) = {3, 2, 1, −2, −3}.
↑
2.
3.
4.
5.
x(n) = (0.8)n u(n − 2). Verify the z-transform expression using MATLAB.
x(n) = [(0.5)n + (−0.8)n ]u(n). Verify the z-transform expression using MATLAB.
x(n) = 2n cos(0.4πn)u(−n).
x(n) = (n + 1)(3)n u(n). Verify the z-transform expression using MATLAB.
P4.2 Consider the sequence x(n) = (0.9)n cos(πn/4)u(n). Let
y(n) =
x(n/2),
0,
n = 0, ±2, ±4, · · ·;
otherwise.
1. Show that the z-transform Y (z) of y(n) can be expressed in terms of the z-transform
X(z) of x(n) as Y (z) = X(z 2 ).
2. Determine Y (z).
3. Using MATLABverify that the sequence y(n) has the z-transform Y (z).
P4.3 Determine the z-transform of the following sequences using the z-transform table and the
z-transform properties. Express X(z) as a rational function in z −1 . Verify your results using
MATLAB. Indicate the region of convergence in each case and provide a pole-zero plot.
1. x(n) = 2δ(n − 2) + 3u(n − 3)
2. x(n) = 3(0.75)n cos(0.3πn)u(n) + 4(0.75)n sin(0.3πn)u(n)
)u(n) + (0.9)n u(n − 2)
3. x(n) = n sin( πn
3
Problems
111
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4. x(n) = n2 (2/3)n−2 u(n − 1)
5. x(n) = (n − 3)( 14 )n−2 cos{ π2 (n − 1)}u(n)
P4.4 Let x(n) be a complex-valued sequence with the real part xR (n) and the imaginary part
xI (n).
1. Prove the following z-transform relations:
X(z) + X ∗ (z ∗ )
X(z) − X ∗ (z ∗ )
and XI (z) = Z [xI (n)] =
2
2
2. Verify the above relations for x(n) = exp {(−1 + j0.2π)n} u(n).
XR (z) = Z [xR (n)] =
P4.5 The z-transform of x(n) is X(z) = 1/(1 + 0.5z −1 ), |z| ≥ 0.5. Determine the z-transforms of
the following sequences and indicate their region of convergence.
1.
2.
3.
4.
5.
x1 (n) = x(3 − n) + x(n − 3)
x2 (n) = (1 + n + n2 )x(n)
x3 (n) = ( 12 )n x(n − 2)
x4 (n) = x(n + 2) ∗ x(n − 2)
x5 (n) = cos(πn/2)x∗ (n)
P4.6 Repeat Problem P4.5 if
X(z) =
1 + z −1
1
; |z| >
2
1+
+ 16 z −2
5 −1
z
6
P4.7 The inverse z-transform of X(z) is x(n) = (1/2)n u(n). Using the z-transform properties,
determine the sequences in each of the following cases.
1.
2.
3.
4.
X1 (z) = z−1
X(z)
z
X2 (z) = zX(z −1 )
X3 (z) = 2X(3z) + 3X(z/3)
X4 (z) = X(z)X(z −1 )
5. X5 (z) = z 2 dX(z)
dz
P4.8 If sequences x1 (n), x2 (n), and x3 (n) are related by x3 (n) = x1 (n) ∗ x2 (n) then
∞
n=−∞
x3 (n) =
∞
n=−∞
x1 (n)
∞
x2 (n)
n=−∞
1. Prove the above result by substituting the definition of convolution in the left-hand side.
2. Prove the above result using the convolution property.
3. Verify the above result using MATLABand choosing any two random sequences x1 (n)
and x2 (n).
P4.9 Determine the results of the following polynomial operations using MATLAB.
1.
2.
3.
4.
5.
112
X1 (z) = (1 − 2z −1 + 3z −2 − 4z −3 )(4 + 3z −1 − 2z −2 + z −3 )
X2 (z) = (z 2 − 2z + 3 + 2z −1 + z −2 )(z 3 − z −3 )
X3 (z) = (1 + z −1 + z −2 )3
X4 (z) = X1 (z)X2 (z) + X3 (z)
X5 (z) = (z −1 − 3z −3 + 2z −5 + 5z −7 − z −9 )(z + 3z 2 + 2z 3 + 4z 4 )
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P4.10 The deconv function is useful in dividing two causal sequences. Write a MATLAB function
deconv m to divide two non causal sequences (similar to the conv function). The format of
this function should be
function [p,np,r,nr] = deconv_m(b,nb,a,na)
% Modified deconvolution routine for noncausal sequences
% function [p,np,r,nr] = deconv_m(b,nb,a,na)
%
% p = polynomial part of support np1 <= n <= np2
% np = [np1, np2]
% r = remainder part of support nr1 <= n <= nr2
% nr = [nr1, nr2]
% b = numerator polynomial of support nb1 <= n <= nb2
% nb = [nb1, nb2]
% a = denominator polynomial of support na1 <= n <= na2
% na = [na1, na2]
%
Check your function on the following operartion
z 2 + z + 1 + z −1 + z −2 + z −3
3z −2 + 3z −3
= (z − 1 + 2z −1 − 2z −2 ) +
−1
z+2+z
z + 2 + z −1
P4.11 Determine the following inverse z-transforms using the partial fraction expansion method.
1. X1 (z) = (1 − z −1 − 4z −2 + 4z −3 )/(1 − 11
z −1 + 13
z −2 − 14 z −3 ). The sequence is rightsided.
4
8
2. X2 (z) = (1 − z −1 − 4z −2 + 4z −3 )/(1 −
absolutely summable.
11 −1
z
4
+
13 −2
z
8
− 14 z −3 ). The sequence is
3. X3 (z) = (z 3 − 3z 2 + 4z + 1)/(z 3 − 4z 2 + z − 0.16). The sequence is leftsided.
4. X4 (z) = z/(z 3 + 2z 2 + 1.25z + 0.25), |z| > 1.
5. X5 (z) = z/(z 2 − 0.25)2 , |z| < 0.5.
P4.12 Consider the sequence given below:
x(n) = Ac (r)n cos(πv0 n)u(n) + As (r)n sin(πv0 n)u(n)
(4.30)
The z-transform of this sequence is a second-order (proper) rational function that contains
a complex-conjugate pole pair. The objective of this problem is to develop a MATLAB
function which can be used to obtain the inverse z-transform of such a rational function so
that the inverse does not contain any complex numbers.
1. Show that the z-transform of x(n) in (4.30) is given by
X(z) =
b0 + b1 z −1
;
1 + a1 z −1 + a2 z −2
|z| > |r|
(4.31)
where
b0 = Ac ; b1 = r[As sin(πv0 ) − Ac cos(πv0 )]; a1 = −2r cos(πv0 ); a2 = r2
(4.32)
2. Using (4.32), determine the signal parameters Ac , As , r, and v0 in terms of the rational
function parameters b0 , b1 , a1 , and a2 .
Problems
113
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3. Using your results in part b above, design a MATLABfunction, invCCPP, that computes
signal parameters using the rational function parameters. The format of this function
should be:
function [As,Ac,r,v0] = invCCPP(b0,b1,a1,a2)
P4.13 Suppose X(z) is given as follows:
X(z) =
2 + 3z −1
, |z| > 0.9
1 − z −1 + 0.81z −2
1. Using the MATLABfunction invCCPP given in Problem P4.12, determine x(n) in a form
that contains no complex numbers.
2. Using MATLAB, compute the first 20 samples of x(n) and compare them with your
answer in the above part.
P4.14 The z-transform of a causal sequence is given as:
X(z) =
−2 + 5.65z −1 − 2.88z −2
1 − 0.1z −1 + 0.09z −2 + 0.648z −3
(4.33)
which contains a complex-conjugate pole pair as well as a real-valued pole.
1. Using the residuez function express (4.33) as
X(z) =
( )
( ) + ( )z −1
+
1 + ( )z −1 + ( )z −2
1 + ( )z −1
(4.34)
Note that you will have to use the residuez function in both directions.
2. Now using your function invCCPP and the inverse of the real-valued pole factor,
determine the causal sequence x(n) from the X(z) in (4.34) so that it contains no
complex numbers.
P4.15 For the linear and time-invariant systems described by the impulse responses below,
determine (i) the system function representation, (ii) the differenceequation
representation,
n
(iii) pole-zero plot, and (iv) the output y(n) if the input is x(n) = 14 u(n).
1. h(n) = 5(1/4)n u(n)
2. h(n) = n(1/3)n u(n) + (−1/4)n u(n)
3. h(n) = 3(0.9)n cos(πn/4 + π/3)u(n + 1)
4. h(n) =
(0.5)n sin[(n + 1)π/3]
u(n)
sin(π/3)
5. h(n) = [2 − sin(πn)]u(n)
114
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P4.16 Consider the system shown below.
1. Using the z-transform approach, show that the impulse response, h(n), of the overall
system is given by
h(n) = δ(n) −
1
δ(n − 1)
2
2. Determine the difference equation representation of the overall system that relates the
output y(n) to the input x(n).
3. Is this system causal? BIBO (Bounded-Input Bounded-Output) stable? Explain clearly
to receive full credit.
4. Determine the frequency response H(ejω ) of the overall system.
5. Using MATLAB, provide a plot of this frequency response over 0 ≤ ω ≤ π.
P4.17 For the linear and time-invariant systems described by the system functions below,
determine (i) the impulse response representation, (ii) the difference equation
representation, (iii) pole-zero plot, and (iv) the output y(n) if the input is
x(n) = 3 cos(πn/3)u(n)
1. H(z) = (z + 1)/(z − 0.5), causal system.
2. H(z) = (1 + z −1 + z −2 )/(1 + 0.5z −1 − 0.25z −2 ), stable system.
3. H(z) = (z 2 − 1)/(z − 3)2 , anti-causal system.
4. H(z) =
1 − 0.5z −1
z
, stable system.
+
z − 0.25
1 + 2z −1
5. H(z) = (1 + z −1 + z −2 )2
P4.18 For the linear, causal and time-invariant systems described by the difference equations
below, determine (i) the impulse response representation, (ii) the system function
representation, (iii) pole-zero plot, and (iv) the output y(n) if the input is
x(n) = 2(0.9)n u(n)
1. y(n) = [x(n) + 2x(n − 1) + x(n − 3)] /4
2. y(n) = x(n) + 0.5x(n − 1) − 0.5y(n − 1) + 0.25y(n − 2)
3. y(n) = 2x(n) + 0.9y(n − 1)
4. y(n) = −0.45x(n) − 0.4x(n − 1) + x(n − 2) + 0.4y(n − 1) + 0.45y(n − 2)
5. y(n) =
Problems
4
m=0
(0.8)m x(n − m) −
4
=1
(0.9) y(n − )
115
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P4.19 The output sequence y(n) in Problem P4.18 is the total response. For each of the systems
given in Problem P4.18, separate y(n) into (i) the homogeneous part, (ii) the particular
part, (iii) the transient response, and (iv) the steady-state response.
P4.20 A stable system has four zeros and four poles as given below:
zeros: ± 1, ±j1
Poles: ± 0.9, ±j0.9
It is also known that the frequency response function H(ejω ) evaluated at ω = π/4 is equal
to 1, i.e.,
H(ejπ/4 ) = 1
1.
2.
3.
4.
Determine
Determine
Determine
Determine
the
the
the
the
system function H(z) and indicate its region of convergence.
difference equation representation.
steady-state response yss (n) if the input is x(n) = cos(πn/4)u(n).
transient response ytr (n) if the input is x(n) = cos(πn/4)u(n).
P4.21 A digital filter is described by the frequency response function
H(ejω ) = [1 + 2 cos(ω) + 3 cos(2ω)] cos(ω/2)e−j5ω/2
1. Determine the difference equation representation.
2. Using the freqz function plot the magnitude and phase of the frequency response of the
above filter. Note the magnitude and phase at ω = π/2 and at ω = π.
3. Generate 200 samples of the signal x(n) = sin(πn/2) + 5 cos(πn) and process through the
filter to obtain y(n). Compare the steady-state portion of y(n) to x(n). How are the
amplitudes and phases of two sinusoids affected by the filter?
P4.22 Repeat the above problem for the following filter
H(ejω ) =
1 + e−j4ω
1 − 0.8145e−j4ω
P4.23 Solve the following difference equation for y(n) using the one-sided z-transform approach.
y(n)
x(n)
=
=
0.81y(n − 2) + x(n) − x(n − 1), n ≥ 0;
(0.7)n u(n + 1)
y(−1) = 2, y(−3) = 2
Generate the first 20 samples of y(n) using MATLAB and compare them with your answer.
P4.24 Solve the difference equation for y(n), n ≥ 0
y(n) − 0.4y(n − 1) − 0.45y(n − 2) = 0.45x(n) + 0.4x(n − 1) − x(n − 2)
driven by the input x(n) = 2 +
1 n
2
u(n) and subject to
y(−1) = 0, y(−2) = 3; x(−1) == x(−2) = 2
Decompose the solution y(n) into (i) transient response, (ii) steady-state response, (iii) zero
input response, and (iv) zero-state response.
116
Chapter 4
THE z-TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P4.25 A stable, linear and time-invariant system is given by the following system function
√
4z 2 − 2 2z + 1
√
H(z) =
z2 − 2 2 + 4
1.
2.
3.
4.
Determine the difference equation representation for this system.
Plot the poles and zeros of H(z) and indicate the ROC.
determine the unit sample response h(n) of this system.
Is this system causal? If the answer is yes, justify it. If the answer is no, find a causal
unit sample response that satisfies the system function.
P4.26 Determine the zero-input, zero-state, and steady-state responses of the system
y(n) = 0.9801y(n − 2) + x(n) + 2x(n − 1) + x(n − 2), n ≥ 0;
y(−2) = 1, y(−1) = 0
to the input x(n) = 5(−1)n u(n).
Problems
117
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
5
The Discrete
Fourier Transform
In Chapters 3 and 4 we studied transform-domain representations
of discrete signals. The discrete-time Fourier transform provided the
frequency-domain (ω) representation for absolutely summable sequences.
The z-transform provided a generalized frequency-domain (z) representation for arbitrary sequences. These transforms have two features in
common. First, the transforms are defined for infinite-length sequences.
Second, and the most important, they are functions of continuous variables (ω or z). From the numerical computation viewpoint (or from
MATLAB’s viewpoint), these two features are troublesome because one
has to evaluate infinite sums at uncountably infinite frequencies. To use
MATLAB, we have to truncate sequences and then evaluate the expressions at finitely many points. This is what we did in many examples in the
two previous chapters. The evaluations were obviously approximations to
the exact calculations. In other words, the discrete-time Fourier transform
and the z-transform are not numerically computable transforms.
Therefore we turn our attention to a numerically computable transform. It is obtained by sampling the discrete-time Fourier transform in the
frequency domain (or the z-transform on the unit circle). We develop this
transform by first analyzing periodic sequences. From Fourier analysis we
know that a periodic function (or sequence) can always be represented by
a linear combination of harmonically related complex exponentials (which
is a form of sampling). This gives us the Discrete Fourier Series (or DFS)
representation. Since the sampling is in the frequency domain, we study
the effects of sampling in the time domain and the issue of reconstruction
in the z-domain. We then extend the DFS to finite-duration sequences,
118
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
which leads to a new transform, called the Discrete Fourier Transform
(or DFT). The DFT avoids the two problems mentioned above and is
a numerically computable transform that is suitable for computer implementation. We study its properties and its use in system analysis in detail.
The numerical computation of the DFT for long sequences is prohibitively
time consuming. Therefore several algorithms have been developed to
efficiently compute the DFT. These are collectively called fast Fourier
transform (or FFT) algorithms. We will study two such algorithms in
detail.
THE DISCRETE FOURIER SERIES
In Chapter 2 we defined the periodic sequence by x̃(n), satisfying the
condition
x̃(n) = x̃(n + kN ), ∀n, k
(5.1)
where N is the fundamental period of the sequence. From Fourier analysis
we know that the periodic functions can be synthesized as a linear combination of complex exponentials whose frequencies are multiples (or harmonics) of the fundamental frequency (which in our case is 2π/N ). From
the frequency-domain periodicity of the discrete-time Fourier transform,
we conclude that there are a finite number of harmonics; the frequencies
k = 0, 1, . . . , N − 1}. Therefore a periodic sequence x̃(n) can
are { 2π
N k,
be expressed as
x̃(n) =
N −1
2π
1 X̃(k)ej N kn , n = 0, ±1, . . . ,
N
(5.2)
k=0
where {X̃(k), k = 0, ±1, . . . , } are called the discrete Fourier series coefficients, which are given by
X̃(k) =
N
−1
x̃(n)e−j N nk , k = 0, ±1, . . . ,
2π
(5.3)
n=0
Note that X̃(k) is itself a (complex-valued) periodic sequence with fundamental period equal to N , that is,
X̃(k + N ) = X̃(k)
(5.4)
The pair of equations (5.3) and (5.2) taken together is called the discrete
2π
Fourier series representation of periodic sequences. Using WN = e−j N to
The Discrete Fourier Series
119
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
denote the complex exponential term, we express (5.3) and (5.2) as
X̃(k) = DFS[x̃(n)] =
N
−1
n=0
x̃(n) = IDFS[X̃(k)] =
EXAMPLE 5.1
x̃(n)WNnk
: Analysis or a
DFS equation
−1
1 N
X̃(k)WN−nk
N k=0
: Synthesis or an inverse
DFS equation
(5.5)
Find DFS representation of the periodic sequence given below:
x̃(n) = {. . . , 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, . . .}
↑
Solution
The fundamental period of the above sequence is N = 4. Hence W4 = e−j
−j. Now
X̃(k) =
3
2π
4
=
k = 0, ±1, ±2, . . .
x̃(n)W4nk ,
n=0
Hence
X̃(0) =
3
x̃(n)W40·n =
0
3
x̃(n) = x̃(0) + x̃(1) + x̃(2) + x̃(3) = 6
0
Similarly,
X̃(1) =
3
x̃(n)W4n =
3
0
X̃(2) =
3
0
x̃(n)W42n =
3
0
X̃(3) =
3
120
x̃(n)(−j)2n = 2
0
x̃(n)W43n =
3
0
MATLAB
IMPLEMENTATION
x̃(n)(−j)n = (−2 + 2j)
x̃(n)(−j)3n = (−2 − 2j)
0
A careful look at (5.5) reveals that the DFS is a numerically computable
representation. It can be implemented in many ways. To compute each
sample X̃(k), we can implement the summation as a for...end loop.
To compute all DFS coefficients would require another for...end loop.
This will result in a nested two for...end loop implementation. This is
clearly inefficient in MATLAB. An efficient implementation in MATLAB
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
would be to use a matrix-vector multiplication for each of the relations
in (5.5). We have used this approach earlier in implementing a numerical
approximation to the discrete-time Fourier transform. Let x̃ and X̃ denote
column vectors corresponding to the primary periods of sequences x̃(n)
and X̃(k), respectively. Then (5.5) is given by
X̃ = WN x̃
x̃ =
(5.6)
1
W∗ X̃
N N
where the matrix WN is given by

1
WN =
WNkn 0≤k,n≤N −1

1

= k .
↓  ..

1
1
n −→
···
1
(N −1)
WN1
..
.
···
..
.
(N −1)
· · · WN
WN
WN
..
.







(5.7)
(N −1)2
The matrix WN is a square matrix and is called a DFS matrix. The
following MATLAB function dfs implements the above procedure.
function [Xk] = dfs(xn,N)
% Computes Discrete Fourier Series Coefficients
% --------------------------------------------% [Xk] = dfs(xn,N)
% Xk = DFS coeff. array over 0 <= k <= N-1
% xn = One period of periodic signal over 0 <= n <= N-1
% N = Fundamental period of xn
%
n = [0:1:N-1];
% row vector for n
k = [0:1:N-1];
% row vecor for k
WN = exp(-j*2*pi/N);
% Wn factor
nk = n’*k;
% creates a N by N matrix of nk values
WNnk = WN .^ nk;
% DFS matrix
Xk = xn * WNnk;
% row vector for DFS coefficients
The DFS in Example 5.1 can be computed using MATLAB as
>> xn = [0,1,2,3]; N = 4; Xk = dfs(xn,N)
Xk =
6.0000
-2.0000 + 2.0000i -2.0000 - 0.0000i
The Discrete Fourier Series
-2.0000 - 2.0000i
121
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The following idfs function implements the synthesis equation.
function [xn] = idfs(Xk,N)
% Computes Inverse Discrete Fourier Series
% ---------------------------------------% [xn] = idfs(Xk,N)
% xn = One period of periodic signal over 0 <= n <= N-1
% Xk = DFS coeff. array over 0 <= k <= N-1
% N = Fundamental period of Xk
%
n = [0:1:N-1];
% row vector for n
k = [0:1:N-1];
% row vecor for k
WN = exp(-j*2*pi/N);
% Wn factor
nk = n’*k;
% creates a N by N matrix of nk values
WNnk = WN .^ (-nk);
% IDFS matrix
xn = (Xk * WNnk)/N;
% row vector for IDFS values
Caution: The above functions are efficient approaches of implementing
(5.5) in MATLAB. They are not computationally efficient, especially for
large N . We will deal with this problem later in this chapter.
EXAMPLE 5.2
A periodic “square wave” sequence is given by
x̃(n) =
1,
mN ≤ n ≤ mN + L − 1
0,
mN + L ≤ n ≤ (m + 1) N − 1
;
m = 0, ±1, ±2, . . .
where N is the fundamental period and L/N is the duty cycle.
a. Determine an expression for |X̃(k)| in terms of L and N .
b. Plot the magnitude |X̃(k)| for L = 5, N = 20; L = 5, N = 40; L = 5,
N = 60; and L = 7, N = 60.
c. Comment on the results.
Solution
A plot of this sequence for L = 5 and N = 20 is shown in Figure 5.1.
Three periods of xtilde(n)
1.5
xtilde
1
0.5
0
−0.5
−20
FIGURE 5.1
122
−10
0
10
n
20
30
Periodic square wave sequence
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
a. By applying the analysis equation (5.3),
N −1
X̃(k) =
n=0
L−1
2π
e−j N nk =
n=0


=
L−1
2π
x̃(n)e−j N nk =
2π
e−j N k
n
n=0
k = 0, ±N, ±2N, . . .
L,
−j2πLk/N
1 − e
1 − e−j2πk/N
,
otherwise
The last step follows from the sum of the geometric terms formula (2.5) in
Chapter 2. The last expression can be simplified to
e−jπLk/N ejπLk/N − e−jπLk/N
1 − e−j2πLk/N
= −jπk/N
−j2πk/N
1−e
e
ejπk/N − e−jπk/N
sin (πkL/N )
= e−jπ(L−1)k/N
sin (πk/N )
or the magnitude of X̃(k) is given by

L,
k = 0, ±N, ±2N, . . .


X̃(k) = sin (πkL/N ) 
 sin (πk/N ) , otherwise
b. MATLAB script for L = 5 and N = 20 is given below.
>>
>>
>>
>>
>>
>>
>>
L = 5; N = 20; k = [-N/2:N/2];
% Sq wave parameters
xn = [ones(1,L), zeros(1,N-L)];
% Sq wave x(n)
Xk = dfs(xn,N);
% DFS
magXk = abs([Xk(N/2+1:N) Xk(1:N/2+1)]); % DFS magnitude
subplot(2,2,1); stem(k,magXk); axis([-N/2,N/2,-0.5,5.5])
xlabel(’k’); ylabel(’Xtilde(k)’)
title(’DFS of SQ. wave: L=5, N=20’)
The plots for the above and all other cases are shown in Figure 5.2. Note
that since X̃(k) is periodic, the plots are shown from −N/2 to N/2.
c. Several interesting observations can be made from plots in Figure 5.2. The
envelopes of the DFS coefficients of square waves look like “sinc” functions.
The amplitude at k = 0 is equal to L, while the zeros of the functions are
at multiples of N/L, which is the reciprocal of the duty cycle. We will study
these functions later in this chapter.
RELATION
TO THE
z-TRANSFORM
Let x(n) be a finite-duration sequence of duration N such that
Nonzero, 0 ≤ n ≤ N − 1
x(n) =
0,
elsewhere
The Discrete Fourier Series
(5.8)
123
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
DFS of SQ. wave: L=5, N=40
5
5
4
4
|Xtilde(k)|
|Xtilde(k)|
DFS of SQ. wave: L=5, N=20
3
2
1
3
2
1
0
0
−10
−5
0
k
5
−20
10
DFS of SQ. wave: L=5, N=60
−10
0
k
10
20
DFS of SQ. wave: L=7, N=60
5
6
|Xtilde(k)|
|Xtilde(k)|
4
3
2
4
2
1
0
0
−20
FIGURE 5.2
0
k
−20
20
0
k
20
The DFS plots of a periodic square wave for various L and N
Then we can compute its z-transform:
X(z) =
N
−1
x(n)z −n
(5.9)
n=0
Now we construct a periodic sequence x̃(n) by periodically repeating x(n)
with period N , that is,
x̃(n), 0 ≤ n ≤ N − 1
x(n) =
(5.10)
0,
elsewhere
The DFS of x̃(n) is given by
X̃(k) =
N
−1
x̃(n)e−j N nk =
2π
n=0
N
−1
2π −n
x(n) ej N k
(5.11)
n=0
Comparing it with (5.9), we have
X̃(k) = X(z)|
j 2π k
N
z=e
(5.12)
which means that the DFS X̃(k) represents N evenly spaced samples of
the z-transform X(z) around the unit circle.
124
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
RELATION TO
THE DTFT
Since x(n) in (5.8) is of finite duration of length N , it is also absolutely
summable. Hence its DTFT exists and is given by
N
−1
X(ejω ) =
x(n)e−jωn =
n=0
N
−1
x̃(n)e−jωn
(5.13)
n=0
Comparing (5.13) with (5.11), we have
X̃(k) = X(ejω )ω= 2π k
(5.14)
N
Let
ω1 =
2π
N
and
ωk =
2π
k = kω1
N
then the DFS X(k) = X(ejωk ) = X(ejkω1 ), which means that the DFS is
obtained by evenly sampling the DTFT at ω1 = 2π
N intervals. From (5.12)
and (5.14) we observe that the DFS representation gives us a sampling
mechanism in the frequency domain which, in principle, is similar to sampling in the time domain. The interval ω1 = 2π
N is the sampling interval
in the frequency domain. It is also called the frequency resolution because
it tells us how close are the frequency samples (or measurements).
EXAMPLE 5.3
Let x(n) = {0, 1, 2, 3}.
↑
a. Compute its discrete-time Fourier transform X(ejω ).
b. Sample X(ejω ) at kω1 = 2π
k, k = 0, 1, 2, 3 and show that it is equal to
4
X̃(k) in Example 5.1.
Solution
The sequence x(n) is not periodic but is of finite duration.
a. The discrete-time Fourier transform is given by
X(ejω ) =
∞
x(n)e−jωn = e−jω + 2e−j2ω + 3e−j3ω
n=−∞
b. Sampling at kω1 =
2π
k,
4
k = 0, 1, 2, 3, we obtain
X(ej0 ) = 1 + 2 + 3 = 6 = X̃(0)
X(ej2π/4 ) = e−j2π/4 + 2e−j4π/4 + 3e−j6π/4 = −2 + 2j = X̃(1)
X(ej4π/4 ) = e−j4π/4 + 2e−j8π/4 + 3e−j12π/4 = 2 = X̃(2)
X(ej6π/4 ) = e−j6π/4 + 2e−j12π/4 + 3e−j18π/4 = −2 − 2j = X̃(3)
as expected.
The Discrete Fourier Series
125
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
SAMPLING AND RECONSTRUCTION IN THE z-DOMAIN
Let x(n) be an arbitrary absolutely summable sequence, which may be of
infinite duration. Its z-transform is given by
∞
X(z) =
x(m)z −m
m=−∞
and we assume that the ROC of X (z) includes the unit circle. We sample
X(z) on the unit circle at equispaced points separated in angle by ω1 =
2π/N and call it a DFS sequence,
X̃(k) = X(z)|
j 2π k
N
z=e
∞
=
k = 0, ±1, ±2, . . .
,
x(m)e−j N km =
2π
m=−∞
∞
x(m)WNkm
(5.15)
m=−∞
which is periodic with period N . Finally, we compute the IDFS of X̃(k),
x̃(n) = IDFS X̃(k)
which is also periodic with period N . Clearly, there must be a relationship
between the arbitrary x(n) and the periodic x̃(n). This is an important
issue. In order to compute the inverse DTFT or the inverse z-transform
numerically, we must deal with a finite number of samples of X(z) around
the unit circle. Therefore we must know the effect of such sampling on
the time-domain sequence. This relationship is easy to obtain.
N −1
1 X̃(k)WN−kn
N
k=0
∞
N −1
1 km
=
WN−kn
x(m)WN
N
m=−∞
x̃(n) =
(from (5.2))
(from (5.15))
k=0
or
∞
N −1
∞
∞
1 −k(n−m)
x(m)
WN
x(m)
δ(n−m−rN )
x̃(n) =
=
N 0
m=−∞
m=−∞
r=−∞
1, n − m = rN
=
0, elsewhere
∞
∞
x(m)δ(n − m − rN )
=
r=−∞ m=−∞
126
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
or
x̃(n) =
∞
x(n − rN ) = · · · + x(n + N ) + x(n) + x(n − N ) + · · · (5.16)
r=−∞
which means that when we sample X(z) on the unit circle, we obtain a
periodic sequence in the time domain. This sequence is a linear combination of the original x(n) and its infinite replicas, each shifted by multiples
of ±N . This is illustrated in Example 5.5. From (5.16) we observe that if
x(n) = 0 for n < 0 and n ≥ N , then there will be no overlap or aliasing in
the time domain. Hence we should be able to recognize and recover x(n)
from x̃(n), that is,
x(n) = x̃(n) for 0 ≤ n ≤ (N − 1)
or
x̃(n),
x(n) = x̃(n)RN (n) =
0,
0≤n≤N −1
else
where RN (n) is called a rectangular window of length N . Therefore we
have the following theorem.
THEOREM 1
EXAMPLE 5.4
Frequency Sampling
If x(n) is time-limited (i.e., of finite duration) to [0, N − 1], then N
samples of X(z) on the unit circle determine X(z) for all z.
Let x1 (n) = {6, 5, 4, 3, 2, 1}. Its DTFT X1 (ejω ) is sampled at
↑
ωk =
2πk
,
4
k = 0, ±1, ±2, ±3, . . .
to obtain a DFS sequence X̃2 (k). Determine the sequence x̃2 (n), which is the
inverse DFS of X̃2 (k).
Solution
Without computing the DTFT, the DFS, or the inverse DFS, we can evaluate
x̃2 (n) by using the aliasing formula (5.16).
x̃2 (n) =
∞
x1 (n − 4r)
r=−∞
Thus x(4) is aliased into x(0), and x(5) is aliased into x(1). Hence
x̃2 (n) = {. . . , 8, 6, 4, 3, 8, 6, 4, 3, 8, 6, 4, 3, . . .}
↑
Sampling and Reconstruction in the z -Domain
127
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 5.5
Solution
Let x(n) = (0.7)n u(n). Sample its z-transform on the unit circle with N = 5,
10, 20, 50 and study its effect in the time domain.
From Table 4.1 the z-transform of x(n) is
X(z) =
1
z
=
,
1 − 0.7z −1
z − 0.7
|z| > 0.7
We can now use MATLAB to implement the sampling operation
k = 0, ±1, ±2, . . .
X̃(k) = X(z)|z=ej2πk/N ,
and the inverse DFS computation to determine the corresponding time-domain
sequence. The MATLAB script for N = 5 is shown below.
>>
>>
>>
>>
>>
>>
>>
N = 5; k = 0:1:N-1;
% sample index
wk = 2*pi*k/N; zk = exp(j*wk);
% samples of z
Xk = (zk)./(zk-0.7);
% DFS as samples of X(z)
xn = real(idfs(Xk,N));
% IDFS
xtilde = xn’* ones(1,8); xtilde = (xtilde(:))’; % Periodic sequence
subplot(2,2,1); stem(0:39,xtilde);axis([0,40,-0.1,1.5])
xlabel(’n’); ylabel(’xtilde(n)’); title(’N=5’)
The plots in Figure 5.3 clearly demonstrate the aliasing in the time domain,
especially for N = 5 and N = 10. For large values of N the tail end of x(n)
N=10
1.5
1
1
xtilde(n)
xtilde(n)
N=5
1.5
0.5
0
0
0.5
0
10
20
n
30
40
0
10
1.5
1
1
0.5
0
0
FIGURE 5.3
128
30
40
30
40
N=40
1.5
xtilde(n)
xtilde(n)
N=20
20
n
0.5
0
10
20
n
30
40
0
10
20
n
Plots in Example 5.5
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
is sufficiently small to result in any appreciable amount of aliasing in practice.
Such information is useful in effectively truncating an infinite-duration sequence
prior to taking its transform.
THE
z-TRANSFORM
RECONSTRUCTION
FORMULA
Let x(n) be time-limited to [0, N − 1]. Then from Theorem 1 we should
be able to recover the z-transform X(z) using its samples X̃(k). This is
given by
X(z) = Z [x(n)] = Z [x̃(n)RN (n)]
= Z[ IDFS{
}RN (n)]
X̃(k)
samples of X(z)
The above approach results in the z-domain reconstruction formula.
X(z) =
N
−1
0
=
N
−1
x(n)z −n =
0
1
=
N
1
=
N
1
=
N
N
−1
x̃(n)z −n
0
1
N
N
−1
N
−1
0
X̃(k)
X̃(k)
k=0
N
−1
X̃(k)WN−kn
N −1
z −n
WN−kn z −n
0
k=0
N
−1
N −1
n
WN−k z −1
X̃(k)
k=0
0
1 − WN−kN z −N
1 − WN−k z −1
Since WN−kN = 1, we have
X(z) =
THE DTFT
INTERPOLATION
FORMULA
N −1
1 − z −N X̃(k)
N
1
−
WN−k z −1
k=0
(5.17)
The reconstruction formula (5.17) can be specialized for the discrete-time
Fourier transform by evaluating it on the unit circle z = ejω . Then
N −1
X̃(k)
1 − e−jωN X(e ) =
j2πk/N e−jω
N
1
−
e
k=0
jω
=
N
−1
k=0
Sampling and Reconstruction in the z -Domain
X̃(k)
1 − e−jωN
N 1 − ej2πk/N e−jω
129
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Consider
1 − e−jωN
1 − e−j(ω− N )N
=
2πk
N 1 − ej2πk/N e−jω
N 1 − e−j(ω− N )
N
2πk
N
sin (ω − 2πk
e−j 2 (ω− N )
N )2
=
1
2πk
1
e− 2 j(ω− N ) N sin (ω − 2πk
N )2
2πk
Let
Φ(ω) =
sin( ωN
2 ) −jω( N 2−1 )
e
: an interpolating function
N sin( ω2 )
Then
X(ejω ) =
N
−1
k=0
"
!
2πk
X̃(k)Φ ω −
N
(5.18)
(5.19)
This is the DTFT interpolation formula to reconstruct X(ejω ) from its
samples X̃ (k). Since Φ(0) = 1, we have that X(ej2πk/N ) = X̃(k), which
means that the interpolation is exact at sampling points. Recall the
time-domain interpolation formula (3.33) for analog signals:
xa (t) =
∞
x(n) sinc [Fs (t − nTs )]
(5.20)
n=−∞
The DTFT interpolating formula (5.19) looks similar.
However, there are some differences. First, the time-domain formula
(5.20) reconstructs an arbitrary nonperiodic analog signal, while the
frequency-domain formula (5.19) gives us a periodic waveform. Second, in
x)
(5.19) we use a sin(N
N sin x interpolation function instead of our more familiar
sin x
x (sinc) function. The Φ(ω) function is a periodic function and hence
is known as a periodic-sinc function. It is also known as the Dirichlet
function. This is the function we observed in Example 5.2.
MATLAB
IMPLEMENTATION
130
The interpolation formula (5.19) suffers the same fate as that of (5.20)
while trying to implement it in practice. One has to generate several interpolating functions (5.18) and perform their linear combinations to obtain
the discrete-time Fourier transform X(ejω ) from its computed samples
X̃(k). Furthermore, in MATLAB we have to evaluate (5.19) on a finer grid
over 0 ≤ ω ≤ 2π. This is clearly an inefficient approach. Another approach
is to use the cubic spline interpolation function as an efficient approximation to (5.19). This is what we did to implement (5.20) in Chapter 3.
However, there is an alternate and efficient approach based on the DFT,
which we will study in the next section.
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
THE DISCRETE FOURIER TRANSFORM
The discrete Fourier series provided us a mechanism for numerically computing the discrete-time Fourier transform. It also alerted us to a potential problem of aliasing in the time domain. Mathematics dictates that
the sampling of the discrete-time Fourier transform result in a periodic
sequence x̃(n). But most of the signals in practice are not periodic. They
are likely to be of finite duration. How can we develop a numerically computable Fourier representation for such signals? Theoretically, we can take
care of this problem by defining a periodic signal whose primary shape is
that of the finite-duration signal and then using the DFS on this periodic
signal. Practically, we define a new transform called the Discrete Fourier
Transform (DFT), which is the primary period of the DFS. This DFT
is the ultimate numerically computable Fourier transform for arbitrary
finite-duration sequences.
First we define a finite-duration sequence x(n) that has N samples
over 0 ≤ n ≤ N − 1 as an N -point sequence. Let x̃(n) be a periodic signal
of period N , created using the N -point sequence x(n); that is, from (5.19)
x̃(n) =
∞
x(n − rN )
r=−∞
This is a somewhat cumbersome representation. Using the modulo-N operation on the argument we can simplify it to
x̃(n) = x(n mod N )
(5.21)
A simple way to interpret this operation is the following: if the argument
n is between 0 and N − 1, then leave it as it is; otherwise add or subtract multiples of N from n until the result is between 0 and N − 1. Note
carefully that (5.21) is valid only if the length of x(n) is N or less. Furthermore, we use the following convenient notation to denote the modulo-N
operation.
x((n))N = x(n mod N )
(5.22)
Then the compact relationships between x(n) and x̃(n) are
x̃(n) = x((n))N
(Periodic extension)
x(n) = x̃(n)RN (n)
(Window operation)
(5.23)
The rem(n,N) function in MATLAB determines the remainder after dividing n by N . This function can be used to implement our modulo-N
The Discrete Fourier Transform
131
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
operation when n ≥ 0. When n < 0, we need to modify the result to
obtain correct values. This is shown below in the m=mod(n,N) function.
function m = mod(n,N)
% Computes m = (n mod N) index
% ---------------------------% m = mod(n,N)
m = rem(n,N); m = m+N; m = rem(m,N);
In this function n can be any integer array, and the array m contains the
corresponding modulo-N values.
From the frequency sampling theorem we conclude that N equispaced
samples of the discrete-time Fourier transform X(ejω ) of the N -point sequence x(n) can uniquely reconstruct X(ejω ). These N samples around
the unit circle are called the discrete Fourier transform coefficients. Let
X̃(k) = DFS x̃(n), which is a periodic (and hence of infinite duration)
sequence. Its primary interval then is the discrete Fourier transform,
which is of finite duration. These notions are made clear in the following definitions. The Discrete Fourier Transform of an N -point sequence is
given by
X̃(k),
X(k) = DFT [x(n)] =
0,
0≤k ≤N −1
= X̃(k)RN (k)
elsewhere
or
X(k) =
N
−1
0≤k ≤N −1
x(n)WNnk ,
(5.24)
n=0
Note that the DFT X(k) is also an N -point sequence, that is, it is
not defined outside of 0 ≤ k ≤ N − 1. From (5.23) X̃(k) = X((k))N ;
that is, outside the 0 ≤ k ≤ N − 1 interval only the DFS X̃(k) is defined, which of course is the periodic extension of X(k). Finally, X(k) =
X̃(k)RN (k) means that the DFT X(k) is the primary interval of X̃(k).
The inverse discrete Fourier transform of an N -point DFT X(k) is
given by
x(n) = IDFT [X(k)] = x̃(n)RN (n)
or
x(n) =
N −1
1 X(k)WN−kn ,
N
0≤n≤N −1
(5.25)
k=0
132
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Once again x(n) is not defined outside 0 ≤ n ≤ N − 1. The extension of
x (n) outside this range is x̃(n).
MATLAB
IMPLEMENTATION
It is clear from the discussions at the top of this section that the DFS is
practically equivalent to the DFT when 0 ≤ n ≤ N − 1. Therefore the
implementation of the DFT can be done in a similar fashion. If x(n) and
X(k) are arranged as column vectors x and X, respectively, then from
(5.24) and (5.25) we have
X = WN x
x=
1
W∗ X
N N
(5.26)
where WN is the matrix defined in (5.7) and will now be called a DFT
matrix. Hence the earlier dfs and idfs MATLAB functions can be renamed as the dft and idft functions to implement the discrete Fourier
transform computations.
function [Xk] = dft(xn,N)
% Computes Discrete Fourier Transform
% ----------------------------------% [Xk] = dft(xn,N)
% Xk = DFT coeff. array over 0 <= k <= N-1
% xn = N-point finite-duration sequence
% N = Length of DFT
%
n = [0:1:N-1];
% row vector for n
k = [0:1:N-1];
% row vecor for k
WN = exp(-j*2*pi/N);
% Wn factor
nk = n’*k;
% creates a N by N matrix of nk values
WNnk = WN .^ nk;
% DFT matrix
Xk = xn * WNnk;
% row vector for DFT coefficients
function [xn] = idft(Xk,N)
% Computes Inverse Discrete Transform
% ----------------------------------% [xn] = idft(Xk,N)
% xn = N-point sequence over 0 <= n <= N-1
% Xk = DFT coeff. array over 0 <= k <= N-1
% N = length of DFT
%
n = [0:1:N-1];
% row vector for n
k = [0:1:N-1];
% row vecor for k
WN = exp(-j*2*pi/N);
% Wn factor
nk = n’*k;
% creates a N by N matrix of nk values
WNnk = WN .^ (-nk);
% IDFT matrix
xn = (Xk * WNnk)/N;
% row vector for IDFT values
The Discrete Fourier Transform
133
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 5.6
Let x(n) be a 4-point sequence:
x(n) =
1,
0≤n≤3
0,
otherwise
a. Compute the discrete-time Fourier transform X(ejω ) and plot its magnitude
and phase.
b. Compute the 4-point DFT of x(n).
Solution
a. The discrete-time Fourier transform is given by
X(ejω ) =
3
x(n)e−jωn = 1 + e−jω + e−j2ω + e−j3ω
0
sin(2ω) −j3ω/2
1 − e−j4ω
=
=
e
1 − e−jω
sin(ω/2)
Hence
X(ejω ) = sin(2ω) sin(ω/2) and
jω
X(e ) =

3ω


− 2 ,

3ω

−
± π,
2
when
sin(2ω)
>0
sin(ω/2)
when
sin(2ω)
<0
sin(ω/2)
The plots are shown in Figure 5.4.
b. Let us denote the 4-point DFT by X4 (k). Then
X4 (k) =
3
x(n)W4nk ;
k = 0, 1, 2, 3; W4 = e−j2π/4 = −j
n=0
These calculations are similar to those in Example 5.1. We can also use
MATLAB to compute this DFT.
>> x = [1,1,1,1]; N = 4; X = dft(x,N);
>> magX = abs(X), phaX = angle(X)*180/pi
magX =
4.0000
0.0000
0.0000
0.0000
phaX =
0 -134.9810 -90.0000 -44.9979
Hence
X4 (k) = {4, 0, 0, 0}
↑
Note that when the magnitude sample is zero, the corresponding angle is not
zero. This is due to a particular algorithm used by MATLAB to compute the
134
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude of the DTFT
4
|X|
3
2
1
0
0
0.2
0.4
0.6
0.8
1
1.2
frequency in pi units
1.4
1.6
1.8
2
1.4
1.6
1.8
2
Angle of the DTFT
200
Degrees
100
0
−100
−200
0
FIGURE 5.4
0.2
0.4
0.6
0.8
1
1.2
frequency in pi units
The DTFT plots in Example 5.6
angle part. Generally these angles should be ignored. The plot of DFT values
is shown in Figure 5.5. The plot of X(ejω ) is also shown as a dashed line for
comparison. From the plot in Figure 5.5 we observe that X4 correctly gives
4 samples of X(ejω ), but it has only one nonzero sample. Is this surprising?
By looking at the 4-point x(n), which contains all 1’s, one must conclude
that its periodic extension is
x̃(n) = 1, ∀n
which is a constant (or a DC) signal. This is what is predicted by the DFT
X4 (k), which has a nonzero sample at k = 0 (or ω = 0) and has no values
at other frequencies.
EXAMPLE 5.7
Solution
How can we obtain other samples of the DTFT X(ejω )?
It is clear that we should sample at dense (or finer) frequencies; that is, we
should increase N . Suppose we take twice the number of points, or N = 8
instead of 4. This we can achieve by treating x(n) as an 8-point sequence by
appending 4 zeros.
x(n) = {1, 1, 1, 1, 0, 0, 0, 0}
↑
The Discrete Fourier Transform
135
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude of the DFT: N=4
4
|X(k)|
3
2
1
0
−1
0
0.5
1
1.5
2
k
2.5
3
3.5
4
3
3.5
4
Angle of the DFT: N=4
200
Degrees
100
0
−100
−200
0
FIGURE 5.5
0.5
1
1.5
2
k
2.5
The DFT plots of Example 5.6
This is a very important operation called a zero-padding operation. This operation is necessary in practice to obtain a dense spectrum of signals as we shall
see. Let X8 (k) be an 8-point DFT, then
X8 (k) =
7
k = 0, 1, . . . , 7; W8 = e−jπ/4
x(n)W8nk ;
n=0
In this case the frequency resolution is ω1 = 2π/8 = π/4.
MATLAB Script:
>> x = [1,1,1,1, zeros(1,4)]; N = 8; X = dft(x,N);
>> magX = abs(X), phaX = angle(X)*180/pi
magX =
4.0000
2.6131
0.0000
1.0824
0.0000
phaX =
0 -67.5000 -134.9810 -22.5000 -90.0000
1.0824
0.0000
2.6131
22.5000
-44.9979
67.5000
Hence
◦
◦
◦
X8 (k) = {4, 2.6131e−j67.5 , 0, 1.0824e−j22.5 , 0, 1.0824ej22.5 ,
↑
◦
0, 2.6131ej67.5 }
136
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude of the DFT: N=8
4
|X(k)|
3
2
1
0
−1
0
1
2
3
4
k
5
6
7
8
6
7
8
Angle of the DFT: N=8
200
Degrees
100
0
−100
−200
0
FIGURE 5.6
1
2
3
4
k
5
The DFT plots of Example 5.7: N = 8
which is shown in Figure 5.6. Continuing further, if we treat x(n) as a 16-point
sequence by padding 12 zeros, such that
x(n) = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
↑
then the frequency resolution is ω1 = 2π/16 = π/8 and W16 = e−jπ/8 . Therefore
we get a more dense spectrum with spectral samples separated by π/8. The
sketch of X16 (k) is shown in Figure 5.7.
Comments: Based on the last two examples there are several comments
that we can make.
1. Zero-padding is an operation in which more zeros are appended to the
original sequence. The resulting longer DFT provides closely spaced
samples of the discrete-time Fourier transform of the original sequence.
In MATLAB zero-padding is implemented using the zeros function.
2. In Example 5.6 all we needed to accurately plot the discrete-time
Fourier transform X(ejω ) of x(n) was X4 (k), the 4-point DFT. This
is because x(n) had only 4 nonzero samples, so we could have used the
interpolation formula (5.19) on X4 (k) to obtain X(ejω ). However, in
practice, it is easier to obtain X8 (k) and X16 (k), and so on, to fill in
the values of X(ejω ) rather than using the interpolation formula. This
approach can be made even more efficient using fast Fourier transform
algorithms to compute the DFT.
The Discrete Fourier Transform
137
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude of the DFT: N=16
4
|X(k)|
3
2
1
0
−1
0
2
4
6
8
k
10
12
14
16
12
14
16
Angle of the DFT: N=16
200
Degrees
100
0
−100
−200
0
FIGURE 5.7
2
4
6
8
k
10
The DFT plots of Example 5.7: N = 16
3. The zero-padding gives us a high-density spectrum and provides a better
displayed version for plotting. But it does not give us a high-resolution
spectrum because no new information is added to the signal; only additional zeros are added in the data.
4. To get a high-resolution spectrum, one has to obtain more data from
the experiment or observations (see Example 5.8 below). There are
also other advanced methods that use additional side information or
nonlinear techniques.
EXAMPLE 5.8
To illustrate the difference between the high-density spectrum and the
high-resolution spectrum, consider the sequence
x(n) = cos (0.48πn) + cos (0.52πn)
We want to determine its spectrum based on the finite number of samples.
a. Determine and plot the discrete-time Fourier transform of x(n), 0 ≤
n ≤ 10.
b. Determine and plot the discrete-time Fourier transform of x(n), 0 ≤ n ≤
100.
Solution
138
We could determine analytically the discrete-time Fourier transform in each
case, but MATLAB is a good vehicle to study these problems.
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
a. We can first determine the 10-point DFT of x(n) to obtain an estimate of
its discrete-time Fourier transform.
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
n = [0:1:99]; x = cos(0.48*pi*n)+cos(0.52*pi*n);
n1 = [0:1:9] ;y1 = x(1:1:10);
subplot(2,1,1) ;stem(n1,y1); title(’signal x(n), 0 <= n <= 9’);xlabel(’n’)
Y1 = dft(y1,10); magY1 = abs(Y1(1:1:6));
k1 = 0:1:5 ;w1 = 2*pi/10*k1;
subplot(2,1,2);plot(w1/pi,magY1);title(’Samples of DTFT Magnitude’);
xlabel(’frequency in pi units’)
The plots in Figure 5.8 show there aren’t enough samples to draw any conclusions. Therefore we will pad 90 zeros to obtain a dense spectrum.
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
n2 = [0:1:99]; y2 = [x(1:1:10) zeros(1,90)];
subplot(2,1,1) ;stem(n2,y2) ;title(’signal x(n), 0 <= n <= 9 + 90 zeros’);
xlabel(’n’)
Y2 =dft(y2,100); magY2 = abs(Y2(1:1:51));
k2 = 0:1:50; w2 = 2*pi/100*k2;
subplot(2,1,2); plot(w3/pi,magY3); title(’DTFT Magnitude’);
xlabel(’frequency in pi units’)
signal x(n), 0 <= n <= 9
2
1
0
−1
−2
0
1
2
3
4
5
n
6
7
8
9
10
0.7
0.8
0.9
1
Samples of DTFT Magnitude
10
8
6
4
2
0
0
FIGURE 5.8
The Discrete Fourier Transform
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
Signal and its spectrum in Example 5.8a: N = 10
139
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
signal x(n), 0 <= n <= 9 + 90 zeros
2
1
0
−1
−2
0
10
20
30
40
50
n
60
70
80
90
100
0.7
0.8
0.9
1
DTFT Magnitude
10
8
6
4
2
0
0
0.1
FIGURE 5.9
0.2
0.3
0.4
0.5
0.6
frequency in pi units
Signal and its spectrum in Example 5.8a: N = 100
Now the plot in Figure 5.9 shows that the sequence has a dominant frequency
at ω = 0.5π. This fact is not supported by the original sequence, which
has two frequencies. The zero-padding provided a smoother version of the
spectrum in Figure 5.8.
b. To get better spectral information, we will take the first 100 samples of x(n)
and determine its discrete-time Fourier transform.
MATLAB Script:
>>
>>
>>
>>
>>
>>
subplot(2,1,1); stem(n,x);
title(’signal x(n), 0 <= n <= 99’); xlabel(’n’)
X = dft(x,100); magX = abs(X(1:1:51));
k = 0:1:50; w = 2*pi/100*k;
subplot(2,1,2); plot(w/pi,magX); title(’DTFT Magnitude’);
xlabel(’frequency in pi units’)
Now the discrete-time Fourier transform plot in Figure 5.10 clearly shows two
frequencies, which are very close to each other. This is the high-resolution
spectrum of x(n). Note that padding more zeros to the 100-point sequence
will result in a smoother rendition of the spectrum in Figure 5.10 but will
not reveal any new information. Readers are encouraged to verify this. 140
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
signal x(n), 0 <= n <= 99
2
1
0
−1
−2
0
10
20
30
40
50
n
60
70
80
90
100
0.7
0.8
0.9
1
DTFT Magnitude
60
40
20
0
0
0.1
FIGURE 5.10
0.2
0.3
0.4
0.5
0.6
frequency in pi units
Signal and its spectrum in Example 5.8b: N = 100
PROPERTIES OF THE DISCRETE FOURIER TRANSFORM
The DFT properties are derived from those of the DFS because mathematically DFS is the valid representation. We discuss several useful properties, which are given without proof. These properties also apply to the
DFS with necessary changes. Let X(k) be an N -point DFT of the sequence x(n). Unless otherwise stated, the N -point DFTs will be used in
these properties.
1. Linearity: The DFT is a linear transform
DFT [ax1 (n) + bx2 (n)] = a DFT [x1 (n)] + b DFT [x2 (n)]
(5.27)
Note: If x1 (n) and x2 (n) have different durations—that is, they are
N1 -point and N2 -point sequences, respectively—then choose N3 =
max(N1 , N2 ) and proceed by taking N3 -point DFTs.
2. Circular folding: If an N -point sequence is folded, then the result
x(−n) would not be an N -point sequence, and it would not be possible
Properties of the Discrete Fourier Transform
141
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
to compute its DFT. Therefore we use the modulo-N operation on the
argument (−n) and define folding by
x(0),
n=0
x ((−n))N =
(5.28)
x(N − n), 1 ≤ n ≤ N − 1
This is called a circular folding. To visualize it, imagine that the sequence x(n) is wrapped around a circle in the counterclockwise direction so that indices n = 0 and n = N overlap. Then x((−n))N can be
viewed as a clockwise wrapping of x(n) around the circle; hence the
name circular folding. In MATLAB the circular folding can be achieved
by x=x(mod(-n,N)+1). Note that the arguments in MATLAB begin
with 1. The DFT of a circular folding is given by
X(0),
k=0
(5.29)
DFT [x ((−n))N ] = X ((−k))N =
X(N − k), 1 ≤ k ≤ N − 1
EXAMPLE 5.9
Let x(n) = 10 (0.8)n ,
0 ≤ n ≤ 10.
a. Determine and plot x ((−n))11 .
b. Verify the circular folding property.
Solution
a. MATLAB Script:
>>
>>
>>
>>
>>
n = 0:100; x = 10*(0.8) .^ n; y = x(mod(-n,11)+1);
subplot(2,1,1); stem(n,x); title(’Original sequence’)
xlabel(’n’); ylabel(’x(n)’);
subplot(2,1,2); stem(n,y); title(’Circularly folded sequence’)
xlabel(’n’); ylabel(’x(-n mod 10)’);
The plots in Figure 5.11 show the effect of circular folding.
b. MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
>>
>>
X = dft(x,11); Y = dft(y,11);
subplot(2,2,1); stem(n,real(X));
title(’Real{DFT[x(n)]}’); xlabel(’k’);
subplot(2,2,2); stem(n,imag(X));
title(’Imag{DFT[x(n)]}’); xlabel(’k’);
subplot(2,2,3); stem(n,real(Y));
title(’Real{DFT[x((-n))11]}’); xlabel(’k’);
subplot(2,2,4); stem(n,imag(Y));
title(’Imag{DFT[x((-n))11]}’); xlabel(’k’);
The plots in Figure 5.12 verify the property.
142
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Original sequence
10
8
x(n)
6
4
2
0
0
1
2
3
4
5
n
6
7
8
9
10
7
8
9
10
Circularly folded sequence
10
x(-n mod 11)
8
6
4
2
0
0
FIGURE 5.11
1
2
3
4
5
n
6
Circular folding in Example 5.9a
Real{DFT[x(n)]}
Imag{DFT[x(n)]}
50
20
40
10
30
0
20
10
−10
0
0
5
k
10
−20
0
Real{DFT[x((-n))11]}
5
k
10
Imag{DFT[x((-n))11]}
50
20
40
10
30
0
20
10
−10
0
0
FIGURE 5.12
5
k
10
−20
0
5
k
10
Circular folding property in Example 5.9b
Properties of the Discrete Fourier Transform
143
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3. Conjugation: Similar to the above property we have to introduce the
circular folding in the frequency domain.
DFT [x∗ (n)] = X ∗ ((−k))N
(5.30)
4. Symmetry properties for real sequences: Let x(n) be a realvalued N -point sequence. Then x(n) = x∗ (n). Using the above property,
X(k) = X ∗ ((−k))N
(5.31)
This symmetry is called a circular conjugate symmetry. It further implies that
Re [X(k)] = Re [X ((−k))N ]
=⇒ Circular-even sequence
Im [X(k)] = − Im [X ((N − k))N ] =⇒ Circular-odd sequence
|X(k)| = |X ((−k))N |
X(k) = − X ((−k))N
=⇒ Circular-even sequence
=⇒ Circular-odd sequence
(5.32)
Comments:
1. Observe the magnitudes and angles of the various DFTs in Examples 5.6 and 5.7. They do satisfy the above circular symmetries. These
symmetries are different than the usual even and odd symmetries. To
visualize this, imagine that the DFT samples are arranged around a
circle so that the indices k = 0 and k = N overlap; then the samples will be symmetric with respect to k = 0, which justifies the name
circular symmetry.
2. The corresponding symmetry for the DFS coefficients is called the periodic conjugate symmetry.
3. Since these DFTs have symmetry, one needs to compute X(k) only for
k = 0, 1, . . . ,
or for
k = 0, 1, . . . ,
N
;
2
N −1
;
2
N even
N odd
This results in about 50% savings in computation as well as in storage.
4. From (5.30)
X(0) = X ∗ ((−0))N = X ∗ (0)
which means that the DFT coefficient at k = 0 must be a real number.
But k = 0 means that the frequency ωk = kω1 = 0, which is the DC
144
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
frequency. Hence the DC coefficient for a real-valued x(n) must be a
real number. In addition, if N is even, then N/2 is also an integer.
Then from (5.32)
X(N/2) = X ∗ ((−N/2))N = X ∗ (N/2)
which means that even the k = N/2 component is also real-valued.
This component is called the Nyquist component since k = N/2 means
that the frequency ωN/2 = (N/2)(2π/N ) = π, which is the digital
Nyquist frequency.
The real-valued signals can also be decomposed into their even and odd
components, xe (n) and xo (n), respectively, as discussed in Chapter 2.
However, these components are not N -point sequences and therefore we
cannot take their N -point DFTs. Hence we define a new set of components
using the circular folding discussed above. These are called circular-even
and circular-odd components defined by
x(0),
n=0
1
xec (n) = 2 [x(n) + x ((−n))N ] = 1
2 [x (n) + x (N − n)] , 1 ≤ n ≤ N − 1
0,
n=0
xoc (n) = 12 [x(n) − x ((−n))N ] = 1
2 [x (n) − x (N − n)] , 1 ≤ n ≤ N − 1
(5.33)
Then
DFT [xec (n)] = Re [X(k)] = Re [X ((−k))N ]
DFT [xoc (n)] = Im [X(k)] = Im [X ((−k))N ]
(5.34)
Implication: If x(n) is real and circular-even, then its DFT is also real
and circular-even. Hence only the first 0 ≤ n ≤ N/2 coefficients are
necessary for complete representation.
Using (5.33), it is easy to develop a function to decompose an N -point
sequence into its circular-even and circular-odd components. The following circevod function uses the mod function given earlier to implement
the modulo-N operation.
function [xec, xoc] = circevod(x)
% signal decomposition into circular-even and circular-odd parts
% -------------------------------------------------------------% [xec, xoc] = circevod(x)
%
if any(imag(x) ~= 0)
error(’x is not a real sequence’)
Properties of the Discrete Fourier Transform
145
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
end
N = length(x); n = 0:(N-1);
xec = 0.5*(x + x(mod(-n,N)+1));
EXAMPLE 5.10
Let x(n) = 10 (0.8)n ,
xoc = 0.5*(x - x(mod(-n,N)+1));
0 ≤ n ≤ 10 as in Example 5.9.
a. Decompose and plot the xec (n) and xoc (n) components of x(n).
b. Verify the property in (5.34).
Solution
a. MATLAB Script:
>>
>>
>>
>>
>>
>>
n = 0:10; x = 10*(0.8) .^ n;
[xec,xoc] = circevod(x);
subplot(2,1,1); stem(n,xec); title(’Circular-even component’)
xlabel(’n’); ylabel(’xec(n)’); axis([-0.5,10.5,-1,11])
subplot(2,1,2); stem(n,xoc); title(’Circular-odd component’)
xlabel(’n’); ylabel(’xoc(n)’); axis([-0.5,10.5,-4,4])
The plots in Figure 5.13 show the circularly symmetric components of x(n).
Circular-even component
10
xec(n)
8
6
4
2
0
0
1
2
3
4
5
n
6
7
8
9
10
7
8
9
10
Circular-odd component
4
xoc(n)
2
0
−2
−4
0
FIGURE 5.13
1
2
3
4
5
n
6
Circular-even and circular-odd components of the sequence in
Example 5.10a
146
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
b. MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
>>
>>
X = dft(x,11); Xec = dft(xec,11); Xoc = dft(xoc,11);
subplot(2,2,1); stem(n,real(X)); axis([-0.5,10.5,-5,50])
title(’Real{DFT[x(n)]}’); xlabel(’k’);
subplot(2,2,2); stem(n,imag(X)); axis([-0.5,10.5,-20,20])
title(’Imag{DFT[x(n)]}’); xlabel(’k’);
subplot(2,2,3); stem(n,real(Xec)); axis([-0.5,10.5,-5,50])
title(’DFT[xec(n)]’); xlabel(’k’);
subplot(2,2,4); stem(n,imag(Xoc)); axis([-0.5,10.5,-20,20])
title(’DFT[xoc(n)]’); xlabel(’k’);
From the plots in Figure 5.14 we observe that the DFT of xec (n) is the same as
the real part of X(k) and that the DFT of xoc (n) is the same as the imaginary
part of X(k).
A similar property for complex-valued sequences is explored in Problem P5.18.
5. Circular shift of a sequence: If an N -point sequence is shifted in
either direction, then the result is no longer between 0 ≤ n ≤ N − 1.
Therefore we first convert x(n) into its periodic extension x̃(n), and
then shift it by m samples to obtain
x̃(n − m) = x ((n − m))N
Real{DFT[x(n)]}
(5.35)
Imag{DFT[x(n)]}
50
20
40
10
30
0
20
10
−10
0
0
5
k
10
−20
0
DFT[xec(n)]
5
k
10
DFT[xoc(n)]
50
20
40
10
30
0
20
10
−10
0
0
FIGURE 5.14
5
k
10
−20
0
5
k
10
Plots of DFT symmetry properties in Example 5.10b
Properties of the Discrete Fourier Transform
147
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
This is called a periodic shift of x̃(n). The periodic shift is then converted into an N -point sequence. The resulting sequence
x̃(n − m)RN (n) = x ((n − m))N RN (n)
(5.36)
is called the circular shift of x(n). Once again to visualize this, imagine
that the sequence x(n) is wrapped around a circle. Now rotate the circle
by k samples and unwrap the sequence from 0 ≤ n ≤ N − 1. Its DFT
is given by
DFT [x ((n − m))N RN (n)] = WNkm X(k)
EXAMPLE 5.11
Let x(n) = 10 (0.8)n ,
(5.37)
0 ≤ n ≤ 10 be an 11-point sequence.
a. Sketch x((n + 4))11 R11 (n), that is, a circular shift by 4 samples toward the
left.
b. Sketch x((n − 3))15 R15 (n), that is, a circular shift by 3 samples toward the
right, where x(n) is assumed to be a 15-point sequence.
Solution
We will use a step-by-step graphical approach to illustrate the circular shifting
operation. This approach shows the periodic extension x̃(n) = x((n))N of x(n),
followed by a linear shift in x̃(n) to obtain x̃(n − m) = x((n − m))N , and finally
truncating x̃(n − m) to obtain the circular shift.
a. Figure 5.15 shows four sequences. The top-left shows x(n), the bottom-left
shows x̃(n), the top-right shows x̃(n + 4), and finally the bottom-right shows
x((n + 4))11 R11 (n). Note carefully that as samples move out of the [0, N − 1]
window in one direction, they reappear from the opposite direction. This is
the meaning of the circular shift, and it is different from the linear shift.
b. In this case the sequence x(n) is treated as a 15-point sequence by padding
4 zeros. Now the circular shift will be different than when N = 11. This
is shown in Figure 5.16. In fact the circular shift x ((n − 3))15 looks like a
linear shift x(n − 3).
To implement a circular shift, we do not have to go through the
periodic shift as shown in Example 5.11. It can be implemented directly
in two ways. In the first approach, the modulo-N operation can be used
on the argument (n − m) in the time domain. This is shown below in the
cirshftt function.
function y = cirshftt(x,m,N)
% Circular shift of m samples wrt size N in sequence x: (time domain)
% ------------------------------------------------------------------% [y] = cirshftt(x,m,N)
% y = output sequence containing the circular shift
% x = input sequence of length <= N
% m = sample shift
% N = size of circular buffer
% Method: y(n) = x((n-m) mod N)
148
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Original x(n)
Periodic shift
10
10
8
8
6
6
4
4
2
2
0
0
−5
0
5
n
10
15
−5
0
Periodic extention
10
8
8
6
6
4
4
2
2
0
0
FIGURE 5.15
0
5
n
10
−5
15
0
15
5
n
10
15
Graphical interpretation of circular shift, N = 11
Original x(n)
Periodic shift
10
10
8
8
6
6
4
4
2
2
0
0
0
10
20
0
10
n
n
Periodic extention
Circular shift
10
10
8
8
6
6
4
4
2
2
0
0
0
10
n
FIGURE 5.16
10
Circular shift
10
−5
5
n
20
0
10
20
20
n
Graphical interpretation of circular shift, N = 15
Properties of the Discrete Fourier Transform
149
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Check for length of x
if length(x) > N
error(’N must be >= the length of x’)
end
x = [x zeros(1,N-length(x))];
n = [0:1:N-1]; n = mod(n-m,N); y = x(n+1);
In the second approach, the property 5.37 can be used in the frequency
domain. This is explored in Problem P5.20.
EXAMPLE 5.12
Solution
Given an 11-point sequence x(n) = 10 (0.8)n ,
x ((n − 6))15 .
0 ≤ n ≤ 10, determine and plot
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
n = 0:10; x = 10*(0.8) .^ n; y = cirshftt(x,6,15);
n = 0:14; x = [x, zeros(1,4)];
subplot(2,1,1); stem(n,x); title(’Original sequence’)
xlabel(’n’); ylabel(’x(n)’);
subplot(2,1,2); stem(n,y);
title(’Circularly shifted sequence, N=15’)
xlabel(’n’); ylabel(’x((n-6) mod 15)’);
The results are shown in Figure 5.17.
6. Circular shift in the frequency domain: This property is a dual
of the above property given by
DFT WN−n x(n) = X ((k − ))N RN (k)
(5.38)
7. Circular convolution: A linear convolution between two N -point
sequences will result in a longer sequence. Once again we have to
restrict our interval to 0 ≤ n ≤ N − 1. Therefore instead of linear
shift, we should consider the circular shift. A convolution operation
that contains a circular shift is called the circular convolution and is
given by
x1 (n) N x2 (n) =
N
−1
x1 (m)x2 ((n − m))N ,
0≤n≤N −1
(5.39)
m=0
Note that the circular convolution is also an N -point sequence. It has
a structure similar to that of a linear convolution. The differences
are in the summation limits and in the N -point circular shift. Hence
it depends on N and is also called an N -point circular convolution.
150
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Original sequence
10
x(n)
8
6
4
2
0
0
5
10
15
n
Circularly shifted sequence, N=15
x((n-6) mod 15)
10
8
6
4
2
0
0
5
10
15
n
FIGURE 5.17
Circularly shifted sequence in Example 5.12
Therefore the use of the notation N is appropriate. The DFT property for the circular convolution is
DFT x1 (n) N x2 (n) = X1 (k) · X2 (k)
(5.40)
An alternate interpretation of this property is that when we multiply two N -point DFTs in the frequency domain, we get the circular
convolution (and not the usual linear convolution) in the time domain.
EXAMPLE 5.13
Solution
Let x1 (n) = {1, 2, 2} and x2 (n) = {1, 2, 3, 4}. Compute the 4-point circular
convolution x1 (n) 4 x2 (n).
Note that x1 (n) is a 3-point sequence, hence we will have to pad one zero to
make it a 4-point sequence before we perform the circular convolution. We will
compute this convolution in the time domain as well as in the frequency domain.
In the time domain we will use the mechanism of circular convolution, while in
the frequency domain we will use the DFTs.
• Time-domain approach: The 4-point circular convolution is given by
x1 (n) 4 x2 (n) =
3
x1 (m) x2 ((n − m))4
m=0
Properties of the Discrete Fourier Transform
151
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Thus we have to create a circularly folded and shifted sequence x2 ((n−m))N
for each value of n, multiply it sample-by-sample with x1 (m), add the samples
to obtain the circular convolution value for that n, and then repeat the
procedure for 0 ≤ n ≤ 3. Consider
x1 (m) = {1, 2, 2, 0}
x2 (m) = {1, 2, 3, 4}
and
for n = 0
3
x1 (m) · x2 ((0 − m))5 =
m=0
3
[{1, 2, 2, 0} · {1, 4, 3, 2}]
m=0
=
3
{1, 8, 6, 0} = 15
m=0
for n = 1
3
x1 (m) · x2 ((1 − m))5 =
m=0
3
[{1, 2, 2, 0} · {2, 1, 4, 3}]
m=0
=
3
{2, 2, 8, 0} = 12
m=0
for n = 2
3
x1 (m) · x2 ((2 − m))5 =
m=0
3
[{1, 2, 2, 0} · {3, 2, 1, 4}]
m=0
=
3
{3, 4, 2, 0} = 9
m=0
for n = 3
3
x1 (m) · x2 ((3 − m))5 =
m=0
3
[{1, 2, 2, 0} · {4, 3, 2, 1}]
m=0
=
3
{4, 6, 4, 0} = 14
m=0
Hence
4 x2 (n) = {15, 12, 9, 14}
x1 (n) • Frequency-domain approach: In this approach we first compute 4-point DFTs
of x1 (n) and x2 (n), multiply them sample-by-sample, and then take the
inverse DFT of the result to obtain the circular convolution.
152
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
DFT of x1 (n)
x1 (n) = {1, 2, 2, 0} =⇒ X1 (k) = {5, −1 − j2, 1, −1 + j2}
DFT of x2 (n)
x2 (n) = {1, 2, 3, 4} =⇒ X2 (k) = {10, −2 + j2, −2, −2 − j2}
Now
X1 (k) · X2 (k) = {50, 6 + j2, −2, 6 − j2}
Finally after IDFT,
x1 (n) 4 x2 (n) = {15, 12, 9, 14}
which is the same as before.
Similar to the circular shift implementation, we can implement the
circular convolution in a number of different ways. The simplest approach
would be to implement (5.39) literally by using the cirshftt function
and requiring two nested for...end loops. Obviously, this is not efficient.
Another approach is to generate a sequence x ((n − m))N for each n in
[0, N − 1] as rows of a matrix and then implement (5.39) as a matrixvector multiplication similar to our dft function. This would require
one for...end loop. The following circonvt function incorporates these
steps.
function y = circonvt(x1,x2,N)
% N-point circular convolution between x1 and x2: (time-domain)
% ------------------------------------------------------------% [y] = circonvt(x1,x2,N)
% y = output sequence containing the circular convolution
% x1 = input sequence of length N1 <= N
% x2 = input sequence of length N2 <= N
% N = size of circular buffer
% Method: y(n) = sum (x1(m)*x2((n-m) mod N))
% Check for length of x1
if length(x1) > N
error(’N must be >= the length of x1’)
end
% Check for length of x2
if length(x2) > N
error(’N must be >= the length of x2’)
end
x1=[x1 zeros(1,N-length(x1))];
x2=[x2 zeros(1,N-length(x2))];
m = [0:1:N-1]; x2 = x2(mod(-m,N)+1); H = zeros(N,N);
Properties of the Discrete Fourier Transform
153
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
for n = 1:1:N
H(n,:) = cirshftt(x2,n-1,N);
end
y = x1*conj(H’);
Problems P5.24 and P5.25 explore an approach to eliminate the for...end
loop in the circonvt function. The third approach would be to implement the frequency-domain operation (5.40) using the dft function. This
is explored in Problem P5.26.
EXAMPLE 5.14
Solution
Let us use MATLAB to perform the circular convolution in Example 5.13.
The sequences are x1 (n) = {1, 2, 2} and x2 (n) = {1, 2, 3, 4}.
MATLAB Script:
>> x1 = [1,2,2]; x2 = [1,2,3,4];
y =
15
12
9
14
y = circonvt(x1, x2, 4)
Hence
x1 (n) 4 x2 (n) = {15, 12, 9, 14}
as before.
EXAMPLE 5.15
In this example we will study the effect of N on the circular convolution. Obviously, N ≥ 4; otherwise there will be a time-domain aliasing for x2 (n). We will
use the same two sequences from Example 5.13.
5 x2 (n).
a. Compute x1 (n) b. Compute x1 (n) 6 x2 (n).
c. Comment on the results.
Solution
The sequences are x1 (n) = {1, 2, 2} and x2 (n) = {1, 2, 3, 4}. Even though the
sequences are the same as in Example 5.14, we should expect different results
for different values of N . This is not the case with the linear convolution, which
is unique, given two sequences.
a. MATLAB script for 5-point circular convolution:
>> x1 = [1,2,2]; x2 = [1,2,3,4];
y =
9
4
9
14
14
y = circonvt(x1, x2, 5)
Hence
x1 (n) 5 x2 (n) = {9, 4, 9, 14, 14}
154
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
b. MATLAB script for 6-point circular convolution:
>> x1 = [1,2,2]; x2 = [1,2,3,4];
y =
1
4
9
14
14
y = circonvt(x1, x2, 6)
8
Hence
x1 (n) 6 x2 (n) = {1, 4, 9, 14, 14, 8}
c. A careful observation of 4-, 5-, and 6-point circular convolutions from
this and the previous example indicates some unique features. Clearly, an
N -point circular convolution is an N -point sequence. However, some samples in these convolutions have the same values, while other values can be
obtained as a sum of samples in other convolutions. For example, the first
sample in the 5-point convolution is a sum of the first and the last sample
of the 6-point convolution. The linear convolution between x1 (n) and x2 (n)
is given by
x1 (n) ∗ x2 (n) = {1, 4, 9, 14, 14, 8}
which is equivalent to the 6-point circular convolution. These and other
issues are explored in the next section.
8. Multiplication: This is the dual of the circular convolution property.
It is given by
1
X1 (k) N X2 (k)
(5.41)
N
in which the circular convolution is performed in the frequency domain.
The MATLAB functions developed for circular convolution can also be
used here since X1 (k) and X2 (k) are also N -point sequences.
9. Parseval’s relation: This relation computes the energy in the frequency domain.
DFT [x1 (n) · x2 (n)] =
Ex =
N
−1
2
|x(n)| =
n=0
N −1
1 2
|X(k)|
N
(5.42)
k=0
is called the energy spectrum of finite-duration seThe quantity |X(k)|
N
2
quences. Similarly, for periodic sequences, the quantity | X̃(k)
N | is called
the power spectrum.
2
LINEAR CONVOLUTION USING THE DFT
One of the most important operations in linear systems is the linear convolution. In fact FIR filters are generally implemented in practice using this
linear convolution. On the other hand, the DFT is a practical approach
Linear Convolution Using the DFT
155
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
for implementing linear system operations in the frequency domain. As we
shall see later, it is also an efficient operation in terms of computations.
However, there is one problem. The DFT operations result in a circular
convolution (something that we do not desire), not in a linear convolution
that we want. Now we shall see how to use the DFT to perform a linear
convolution (or equivalently, how to make a circular convolution identical
to the linear convolution). We alluded to this problem in Example 5.15.
Let x1 (n) be an N1 -point sequence and let x2 (n) be an N2 -point
sequence. Define the linear convolution of x1 (n) and x2 (n) by x3 (n),
that is,
x3 (n) = x1 (n) ∗ x2 (n)
=
∞
x1 (k)x2 (n − k) =
N
1 −1
x1 (k)x2 (n − k)
(5.43)
0
k=−∞
Then x3 (n) is a (N1 + N2 − 1)-point sequence. If we choose N =
N
max(N1 , N2 ) and compute an N -point circular convolution x1 (n) x2 (n), then we get an N -point sequence, which obviously is different
from x3 (n). This observation also gives us a clue. Why not choose
N = N1 + N2 − 1 and perform an (N1 + N2 − 1)-point circular convolution? Then at least both of these convolutions will have an equal
number of samples.
Therefore let N = N1 + N2 − 1 and let us treat x1 (n) and x2 (n) as
N -point sequences. Define the N -point circular convolution by x4 (n).
N x2 (n)
x4 (n) = x1 (n) #N −1
$
=
x1 (m)x2 ((n − m))N RN (n)
m=0
=
#N −1
x1 (m)
m=0

(5.44)
$
∞
x2 (n − m − rN ) RN (n)
r=−∞

 ∞ N1 −1

 

=
x1 (m)x2 (n − m − rN ) 
 RN (n)
r=−∞ m=0

#
=
x3 (n−rN )
∞
$
x3 (n − rN ) RN (n)
using (5.43)
r=−∞
This analysis shows that, in general, the circular convolution is an aliased
version of the linear convolution. We observed this fact in Example 5.15.
156
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Now since x3 (n) is an N = (N1 + N2 − 1)-point sequence, we have
x4 (n) = x3 (n);
0 ≤ n ≤ (N − 1)
which means that there is no aliasing in the time domain.
Conclusion: If we make both x1 (n) and x2 (n) N = N1 + N2 − 1 point
sequences by padding an appropriate number of zeros, then the circular
convolution is identical to the linear convolution.
EXAMPLE 5.16
Let x1 (n) and x2 (n) be the two 4-point sequences given below.
x1 (n) = {1, 2, 2, 1} ,
x2 (n) = {1, −1, −1, 1}
a. Determine their linear convolution x3 (n).
b. Compute the circular convolution x4 (n) so that it is equal to x3 (n).
Solution
We will use MATLAB to do this problem.
a. MATLAB Script:
>> x1 = [1,2,2,1]; x2 = [1,-1,-1,1];
x3 =
1
1
-1
-2
-1
x3 = conv(x1,x2)
1
1
Hence the linear convolution x3 (n) is a 7-point sequence given by
x3 (n) = {1, 1, −1, −2, −1, 1, 1}
b. We will have to use N ≥ 7. Choosing N = 7, we have
>> x4 = circonvt(x1,x2,7)
x4 =
1
1
-1
-2
-1
1
1
Hence
x4 = {1, 1, −1, −2, −1, 1, 1} = x3 (n)
ERROR
ANALYSIS
In order to use the DFT for linear convolution, we must choose N properly.
However, in practice it may not be possible to do so, especially when
N is very large and there is a limit on memory. Then an error will be
introduced when N is chosen less than the required value to perform the
circular convolution. We want to compute this error, which is useful in
Linear Convolution Using the DFT
157
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
practice. Obviously, N ≥ max(N1 , N2 ). Therefore let
max(N1 , N2 ) ≤ N < (N1 + N2 − 1)
Then from our previous analysis (5.44)
# ∞
$
x3 (n − rN ) RN (n)
x4 (n) =
r=−∞
Let an error e(n) be given by
e(n) = x4 (n) − x3 (n)


=
x3 (n − rN ) RN (n)
r=0
Since N ≥ max(N1 , N2 ), only two terms corresponding to r = ±1 remain
in the above summation. Hence
e(n) = [x3 (n − N ) + x3 (n + N )] RN (n)
Generally, x1 (n) and x2 (n) are causal sequences. Then x3 (n) is also causal,
which means that
x3 (n − N ) = 0;
0≤n≤N −1
Therefore
e(n) = x3 (n + N ),
0≤n≤N −1
(5.45)
This is a simple yet important relation. It implies that when
max(N1 , N2 ) ≤ N < (N1 + N2 − 1) the error value at n is the same as the
linear convolution value computed N samples away. Now the linear convolution will be zero after (N1 +N2 −1) samples. This means that the first
few samples of the circular convolution are in error, while the remaining
ones are the correct linear convolution values.
EXAMPLE 5.17
Solution
Consider the sequences x1 (n) and x2 (n) from the previous example. Evaluate
circular convolutions for N = 6, 5, and 4. Verify the error relations in each case.
Clearly, the linear convolution x3 (n) is still the same.
x3 (n) = {1, 1, −1, −2, −1, 1, 1}
When N = 6, we obtain a 6-point sequence.
6 x2 (n) = {2, 1, −1, −2, −1, 1}
x4 (n) = x1 (n) 158
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Therefore
e(n) = {2, 1, −1, −2, −1, 1} − {1, 1, −1, −2, −1, 1} ,
0≤n≤5
= {1, 0, 0, 0, 0, 0}
= x3 (n + 6)
as expected. When N = 5, we obtain a 5-point sequence,
x4 (n) = x1 (n) 5 x2 (n) = {2, 2, −1, −2, −1}
and
e(n) = {2, 2, −1, −2, −1} − {1, 1, −1, −2, −1} ,
0≤n≤4
= {1, 1, 0, 0, 0}
= x3 (n + 5)
Finally, when N = 4, we obtain a 4-point sequence,
x4 (n) = x1 (n) 4 x2 (n) = {0, 2, 0, −2}
and
e(n) = {0, 2, 0, −2} − {1, 1, −1, −2} ,
0≤n≤3
= {−1, 1, 1, 0}
= x3 (n + 4)
The last case of N = 4 also provides the useful observation given below.
Observation: When N = max(N1 , N2 ) is chosen for circular convolution, then
the first (M − 1) samples are in error (i.e., different from the linear convolution),
where M = min(N1 , N2 ). This result is useful in implementing long convolutions
in the form of block processing.
BLOCK CONVOLUTIONS
When we want to filter an input sequence that is being received continuously, such as a speech signal from a microphone, then for practical
purposes we can think of this sequence as an infinite-length sequence. If
we want to implement this filtering operation as an FIR filter in which
the linear convolution is computed using the DFT, then we experience
some practical problems. We will have to compute a large DFT, which is
generally impractical. Furthermore, output samples are not available until all input samples are processed. This introduces an unacceptably large
amount of delay. Therefore we have to segment the infinite-length input
sequence into smaller sections (or blocks), process each section using the
DFT, and finally assemble the output sequence from the outputs of each
Linear Convolution Using the DFT
159
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
section. This procedure is called a block convolution (or block processing)
operation.
Let us assume that the sequence x(n) is sectioned into N -point sequences and that the impulse response of the filter is an M -point sequence, where M < N . Then from the observation in Example 5.17 we
note that the N -point circular convolution between the input block and
the impulse response will yield a block output sequence in which the first
(M − 1) samples are not the correct output values. If we simply partition
x(n) into nonoverlapping sections, then the resulting output sequence will
have intervals of incorrect samples. To correct this problem, we can partition x(n) into sections, each overlapping with the previous one by exactly
(M − 1) samples, save the last (N − M + 1) output samples, and finally
concatenate these outputs into a sequence. To correct for the first (M − 1)
samples in the first output block, we set the first (M − 1) samples in the
first input block to zero. This procedure is called an overlap-save method
of block convolutions. Clearly, when N M , this method is more efficient. We illustrate it using a simple example.
EXAMPLE 5.18
Let x(n) = (n + 1) ,
0 ≤ n ≤ 9 and h(n) = {1, 0, −1}. Implement the overlap↑
save method using N = 6 to compute y(n) = x(n) ∗ h(n).
Solution
Since M = 3, we will have to overlap each section with the previous one by two
samples. Now x(n) is a 10-point sequence, and we will need (M − 1) = 2 zeros
in the beginning. Since N = 6, we will need 3 sections. Let the sections be
x1 (n) = {0, 0, 1, 2, 3, 4}
x2 (n) = {3, 4, 5, 6, 7, 8}
x3 (n) = {7, 8, 9, 10, 0, 0}
Note that we have to pad x3 (n) by two zeros since x(n) runs out of values at
n = 9. Now we will compute the 6-point circular convolution of each section
with h(n).
y1 = x1 (n) 6 h(n) = {−3, −4, 1, 2, 2, 2}
y2 = x2 (n) 6 h(n) = {−4, −4, 2, 2, 2, 2}
y3 = x3 (n) 6 h(n) = {7, 8, 2, 2, −9, −10}
Noting that the first two samples in each section are to be discarded, we assemble
the output y(n) as
y(n) = {1, 2, 2, 2, 2, 2, 2, 2, 2, 2, −9, −10}
↑
160
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The linear convolution is given by
x(n) ∗ h(n) = {1, 2, 2, 2, 2, 2, 2, 2, 2, 2, −9, −10}
↑
which agrees with the overlap-save method.
MATLAB
IMPLEMENTATION
Using the above example as a guide, we can develop a MATLAB function to implement the overlap-save method for a very long input sequence
x(n). The key step in this function is to obtain a proper indexing for the
segmentation. Given x(n) for n ≥ 0, we have to set the first (M − 1)
samples to zero to begin the block processing. Let this augmented sequence be
x̂(n) = {0, 0, . . . , 0 , x(n)},
n≥0
(M −1) zeros
and let L = N − M + 1, then the kth block xk (n),
given by
xk (n) = x̂(m);
0 ≤ n ≤ N − 1, is
kL ≤ m ≤ kL + N − 1, k ≥ 0, 0 ≤ n ≤ N − 1
The total number of blocks is given by
&
%
Nx + M − 2
+1
K=
L
where Nx is the length of x(n) and · is the truncation operation. Now
each block can be circularly convolved with h(n) using the circonvt
function developed earlier to obtain
N h(n)
yk (n) = xk (n) Finally, discarding the first (M − 1) samples from each yk (n) and concatenating the remaining samples, we obtain the linear convolution y(n).
This procedure is incorporated in the following ovrlpsav function.
function [y] = ovrlpsav(x,h,N)
% Overlap-Save method of block convolution
% ---------------------------------------% [y] = ovrlpsav(x,h,N)
% y = output sequence
% x = input sequence
% h = impulse response
% N = block length
%
Lenx = length(x); M = length(h); M1 = M-1; L = N-M1;
Linear Convolution Using the DFT
161
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
h = [h zeros(1,N-M)];
%
x = [zeros(1,M1), x, zeros(1,N-1)];
K = floor((Lenx+M1-1)/(L));
Y = zeros(K+1,N);
% convolution with succesive blocks
for k=0:K
xk = x(k*L+1:k*L+N);
Y(k+1,:) = circonvt(xk,h,N);
end
Y = Y(:,M:N)’;
y = (Y(:))’;
% preappend (M-1) zeros
% # of blocks
% discard the first (M-1) samples
% assemble output
It should be noted that the ovrlpsav function as developed here is not
the most efficient approach. We will come back to this issue when we
discuss the fast Fourier transform.
EXAMPLE 5.19
Solution
To verify the operation of the ovrlpsav function, let us consider the sequences
given in Example 5.18.
MATLAB Script:
>> n = 0:9; x = n+1; h = [1,0,-1]; N = 6;
y =
1
2
2
2
2
2
2
y = ovrlpsav(x,h,N)
2
This is the correct linear convolution as expected.
2
2
-9
-10
There is an alternate method called an overlap-add method of block
convolutions. In this method the input sequence x(n) is partitioned into
nonoverlapping blocks and convolved with the impulse response. The resulting output blocks are overlapped with the subsequent sections and
added to form the overall output. This is explored in Problem P5.32.
THE FAST FOURIER TRANSFORM
The DFT (5.24) introduced earlier is the only transform that is discrete in
both the time and the frequency domains, and is defined for finite-duration
sequences. Although it is a computable transform, the straightforward
implementation of (5.24) is very inefficient, especially when the sequence
length N is large. In 1965 Cooley and Tukey [1] showed a procedure to
substantially reduce the amount of computations involved in the DFT.
This led to the explosion of applications of the DFT, including in the
162
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
digital signal processing area. Furthermore, it also led to the development
of other efficient algorithms. All these efficient algorithms are collectively
known as fast Fourier transform (FFT) algorithms.
Consider an N -point sequence x(n). Its N -point DFT is given by
(5.24) and reproduced here
X(k) =
N
−1
x(n)WNnk ,
0≤k ≤N −1
(5.46)
n=0
where WN = e−j2π/N . To obtain one sample of X(k), we need N complex
multiplications and (N −1) complex additions. Hence to obtain a complete
set of DFT coefficients, we need N 2 complex multiplications and N (N −
2
2
1)
nkN complex additions. Also one has to store N complex coefficients
WN (or generate internally at an extra cost). Clearly, the number of
DFT computations for an N -point sequence depends quadratically on N ,
which will be denoted by the notation
CN = o N 2
For large N , o N 2 is unacceptable in practice. Generally, the processing time for one addition is much less than that for one multiplication.
Hence from now on we will concentrate on the number of complex multiplications, which itself requires 4 real multiplications and 2 real additions.
Goal of an Efficient Computation In an efficiently designed algorithm the number of computations should be constant per data sample,
and therefore the total number of computations should be linear with
respect to N .
The quadratic dependence on N can be reduced by realizing that most
of the computations (which are done again and again) can be eliminated
using the periodicity property
k(n+N )
WNkn = WN
(k+N )n
= WN
and the symmetry property
kn+N/2
WN
= −WNkn
of the factor WNnk .
One algorithm that considers only the periodicity of WNnk is the
Goertzel algorithm. This algorithm still requires CN = o(N 2 ) multiplications, but it has certain advantages. This algorithm is described in
Chapter 12. We first begin with an example to illustrate the advantages of
the symmetry and periodicity properties in reducing the number of computations. We then describe and analyze two specific FFT algorithms that
The Fast Fourier Transform
163
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
require CN = o(N log N ) operations. They are the decimation-in-time
(DIT-FFT) and decimation-in-frequency (DIF-FFT) algorithms.
EXAMPLE 5.20
Let us discuss the computations of a 4-point DFT and develop an efficient
algorithm for its computation.
X(k) =
3
x(n)W4nk ,
0 ≤ k ≤ 3;
W4 = e−j2π/4 = −j
n=0
Solution
The above computations can be done in the matrix form
X(0)
W 0
4
W40
W40
W40
X(1) 

 
X(2) = 
X(3)
 x(0)
W40
W40
W40
W41
W42
W43  x(1)
W42
W43
W44
W46
W49


W46  x(2)
x(3)
which requires 16 complex multiplications.
Efficient Approach:
Using periodicity,
W40 = W44 = 1
;
W41 = W49 = −j
W42 = W46 = −1
;
W43 = j
and substituting in the above matrix form, we get
X(0)
1
1
1
X(1) 1 −j

 
X(2) = 1 −1
−1
X(3)
1
j
 x(0)
1
j  x(1)


−1 x(2)
1
−1
−j
x(3)
Using symmetry, we obtain
X(0) = x(0) + x(1) + x(2) + x(3) = [x(0) + x(2)] + [x(1) + x(3) ]
g1
g2
X(1) = x(0) − jx(1) − x(2) + jx(3) = [x(0) − x(2)] −j[x(1) − x(3) ]
h1
h2
X(2) = x(0) − x(1) + x(2) − x(3) = [x(0) + x(2)] − [x(1) + x(3) ]
g1
g2
X(3) = x(0) + jx(1) − x(2) − jx(3) = [x(0) − x(2)] + j[x(1) − x(3) ]
h1
164
Chapter 5
h2
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Hence an efficient algorithm is
'
'
'
'
'
'
'
'
'
'
'
Step 1
g1 = x(0) + x(2)
g2 = x(1) + x(3)
h1 = x(0) − x(2)
h2 = x(1) − x(3)
Step 2
X(0) = g1 + g2
X(1) = h1 − jh2
(5.47)
X(2) = g1 − g2
X(3) = h1 + jh2
which requires only 2 complex multiplications, which is a considerably smaller
number, even for this simple example. A signal flowgraph structure for this
algorithm is given in Figure 5.18.
An Interpretation: This efficient algorithm (5.47) can be interpreted differently. First, a 4-point sequence x(n) is divided into two 2-point sequences, which
are arranged into column vectors as given below.
((
) (
x(0)
x(2)
,
))
x(1)
(
=
x(3)
)
x(0)
x(1)
x(2)
x(3)
Second, a smaller 2-point DFT of each column is taken.
(
W2
)
x(0)
x(1)
x(2)
x(3)
(
=
)(
1
x(0)
x(1)
1
−1
x(2)
x(3)
(
=
)
1
)
x(0) + x(2)
x(1) + x(3)
x(0) − x(2)
x(1) − x(3)
(
=
g1
g2
h1
h2
)
Then each element of the resultant matrix is multiplied by {W4pq }, where p is
the row index and q is the column index; that is, the following dot-product is
performed:
(
x (0)
)
1
1
1
−j
(
·∗
g1
g2
h1
h2
)
(
=
g1
g2
h1
−jh2
)
X (0)
g1
x (2)
−1
x (1)
X (1)
h1
−j
−1
g2
x (3)
−1
FIGURE 5.18
The Fast Fourier Transform
h2
j
X (2)
X (3)
Signal flowgraph in Example 5.20
165
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Finally, two more smaller 2-point DFTs are taken of row vectors.
(
g1
g2
h1
−jh2
)
(
W2 =
g1
g2
h1
−jh2
(
=
)(
X(0)
X(2)
X(1)
X(3)
)
1
1
1
−1
(
=
g1 + g2
g1 − g2
h1 − jh2
h1 + jh2
)
)
Although this interpretation seems to have more multiplications than the efficient algorithm, it does suggest a systematic approach of computing a larger
DFT based on smaller DFTs.
DIVIDE-ANDCOMBINE
APPROACH
To reduce the DFT computation’s quadratic dependence on N , one must
choose a composite number N = LM since
L2 + M 2 N 2 for large N
Now divide the sequence into M smaller sequences of length L, take M
smaller L-point DFTs, and then combine these into a larger DFT using L
smaller M -point DFTs. This is the essence of the divide-and-combine
approach. Let N = LM , then the indices n and k in (5.46) can be
written as
n = M + m,
0 ≤ ≤ L − 1,
0≤m≤M −1
k = p + Lq,
0 ≤ p ≤ L − 1,
0≤q ≤M −1
(5.48)
and write sequences x(n) and X(k) as arrays x(, m) and X(p, q), respectively. Then (5.46) can be written as
X(p, q) =
M
−1 L−1
(M +m)(p+Lq)
x(, m)WN
m=0 =0
=
M
−1
WNmp
#L−1
m=0
=
$
x(, m)WNM p
WNLmq
=0




M
−1 

WNmp

m=0 



#L−1
x(, m)WLp
=0
L-point DFT



$







mq
WM
(5.49)
M -point DFT
166
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Hence (5.49) can be implemented as a three-step procedure:
1. First, we compute the L-point DFT array
F (p, m) =
L−1
x(, m)WLp ;
0≤p≤L−1
(5.50)
=0
for each of the columns m = 0, . . . , M − 1.
2. Second, we modify F (p, m) to obtain another array.
0≤p≤L−1
G(p, m) = WNpm F (p, m),
0≤m≤M −1
(5.51)
The factor WNpm is called a twiddle factor.
3. Finally, we compute the M -point DFTs
X(p, q) =
M
−1
mq
G(p, m)WM
0≤q ≤M −1
(5.52)
m=0
for each of the rows p = 0, . . . , L − 1.
The total number of complex multiplications for this approach can now
be given by
(5.53)
CN = M L2 + N + LM 2 < o N 2
This procedure can be further repeated if M or L are composite numbers. Clearly, the most efficient algorithm is obtained when N is a highly
composite number, that is, N = Rν . Such algorithms are called radix-R
FFT algorithms. When N = R1ν1 R2ν2 · · ·, then such decompositions are
called mixed-radix FFT algorithms. The one most popular and easily programmable algorithm is the radix-2 FFT algorithm.
RADIX-2 FFT
ALGORITHM
Let N = 2ν ; then we choose M = 2 and L = N/2 and divide x(n) into
two N/2-point sequences according to (5.48) as
g1 (n) = x(2n)
;
g2 (n) = x(2n + 1)
0≤n≤
N
−1
2
The sequence g1 (n) contains even-ordered samples of x(n), while g2 (n)
contains odd-ordered samples of x(n). Let G1 (k) and G2 (k) be N/2-point
DFTs of g1 (n) and g2 (n), respectively. Then (5.49) reduces to
X(k) = G1 (k) + WNk G2 (k),
The Fast Fourier Transform
0≤k ≤N −1
(5.54)
167
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
This is called a merging formula, which combines two N/2-point DFTs
into one N -point DFT. The total number of complex multiplications reduces to
N2
+ N = o N 2 /2
CN =
2
This procedure can be repeated again and again. At each stage the
sequences are decimated and the smaller DFTs combined. This decimation ends after ν stages when we have N one-point sequences, which are
also one-point DFTs. The resulting procedure is called the decimation-intime FFT (DIT-FFT) algorithm, for which the total number of complex
multiplications is
CN = N ν = N log2 N
Clearly, if N is large, then CN is approximately linear in N , which was
the goal of our efficient algorithm. Using additional symmetries, CN can
be reduced to N2 log2 N . The signal flowgraph for this algorithm is shown
in Figure 5.19 for N = 8.
x (0)
X (0)
0
WN
x (4)
WN
X (1)
4
WN
2
WN
x (2)
4
X (2)
WN
2
WN
X (3)
6
WN
WN
3
WN
x (1)
4
0
WN
x (5)
0
5
4
2
WN
x (3)
4
0
WN
4
WN
FIGURE 5.19
168
X (4)
WN
WN
WN
x (7)
1
WN
4
0
WN
x (6)
0
0
WN
6
WN
WN
6
WN
7
WN
X (5)
WN
X (6)
X (7)
Decimation-in-time FFT structure for N = 8
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In an alternate approach we choose L = 2, M = N/2 and follow
the steps in (5.49). Note that the initial DFTs are 2-point DFTs, which
contain no complex multiplications. From (5.50)
F (0, m) = x(0, m) + x(1, m)W20
= x(n) + x(n + N/2), 0 ≤ n ≤ N/2
F (1, m) = x(0, m) + x(1, m)W21
= x(n) − x(n + N/2),
0 ≤ n ≤ N/2
and from (5.51)
G(0, m) = F (0, m)WN0
= x(n) + x(n + N/2),
0 ≤ n ≤ N/2
G(1, m) = F (1, m)WNm
= [x(n) − x(n + N/2)] WNn ,
(5.55)
0 ≤ n ≤ N/2
Let G(0, m) = d1 (n) and G(1, m) = d2 (n) for 0 ≤ n ≤ N/2 − 1 (since
they can be considered as time-domain sequences); then from (5.52) we
have
X(0, q) = X(2q)
= D1 (q)
(5.56)
X(1, q) = X(2q + 1) = D2 (q)
This implies that the DFT values X(k) are computed in a decimated
fashion. Therefore this approach is called a decimation-in-frequency FFT
(DIF-FFT) algorithm. Its signal flowgraph is a transposed structure of
the DIT-FFT structure, and its computational complexity is also equal
to N2 log2 N .
MATLAB
IMPLEMENTATION
MATLAB provides a function called fft to compute the DFT of a vector x. It is invoked by X = fft(x,N), which computes the N -point DFT.
If the length of x is less than N, then x is padded with zeros. If the argument N is omitted, then the length of the DFT is the length of x. If x is a
matrix, then fft(x,N) computes the N -point DFT of each column of x.
This fft function is written in machine language and not using
MATLAB commands (i.e., it is not available as a .m file). Therefore it
executes very fast. It is written as a mixed-radix algorithm. If N is a
power of two, then a high-speed radix-2 FFT algorithm is employed. If
N is not a power of two, then N is decomposed into prime factors and
a slower mixed-radix FFT algorithm is used. Finally, if N is a prime
number, then the fft function is reduced to the raw DFT algorithm.
The inverse DFT is computed using the ifft function, which has the
same characteristics as fft.
The Fast Fourier Transform
169
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 5.21
Solution
In this example we will study the execution time of the fft function for 1 ≤
N ≤ 2048. This will reveal the divide-and-combine strategy for various values
of N . One note of caution. The results obtained in this example are valid only
for MATLAB Versions 5 and earlier. Beginning in Version 6, MATLAB is using
a new numerical computing core called LAPACK. It is optimized for memory
references and cache usage and not for individual floating-point operations.
Therefore, results for Version 6 and later are difficult to interpret. Also the
execution times given here are for a specific computer and may vary on different
computers.
To determine the execution time, MATLAB provides two functions. The clock
function provides the instantaneous clock reading, while the etime(t1,t2) function computes the elapsed time between two time marks t1 and t2. To determine
the execution time, we will generate random vectors from length 1 through 2048,
compute their FFTs, and save the computation time in an array. Finally, we
will plot this execution time versus N .
MATLAB Script:
>>
>>
>>
>>
>>
>>
>>
Nmax = 2048; fft_time=zeros(1,Nmax);
for n=1:1:Nmax
x=rand(1,n);
t=clock;fft(x);fft_time(n)=etime(clock,t);
end
n=[1:1:Nmax];
plot(n,fft_time,’.’)
xlabel(’N’);ylabel(’Time in Sec.’) title(’FFT execution times’)
The plot of the execution times is shown in Figure 5.20. This plot is very
informative. The points in the plot do not show one clear function but appear
to group themselves into various trends. The uppermost group depicts a o(N 2 )
dependence on N , which means that these values must be prime numbers between 1 and 2048 for which the FFT algorithm defaults
to the
DFT algorithm.
Similarly, there are groups corresponding to the o N 2 /2 , o N 2 /3 , o N 2 /4 ,
and so on, dependencies for which the number N has fewer decompositions.
The last group shows the (almost linear) o (N log N ) dependence, which is for
N = 2ν , 0 ≤ ν ≤ 11. For these values of N , the radix-2 FFT algorithm is used.
For all other values, a mixed-radix FFT algorithm is employed. This shows that
the divide-and-combine strategy is very effective when N is highly composite.
For example, the execution time is 0.16 second for N = 2048, 2.48 seconds for
N = 2047, and 46.96 seconds for N = 2039.
The MATLAB functions developed previously in this chapter should
now be modified by substituting the fft function in place of the dft
function. From the above example care must be taken to use a highly
composite N . A good practice is to choose N = 2ν unless a specific
situation demands otherwise.
170
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FFT execution times
50
o(N*N)
45
40
Time in Sec.
35
30
25
o(N*N/2)
20
15
o(N*N/4)
10
5
0
0
o(N*logN)
500
1000
1500
2000
2500
N
FIGURE 5.20
FFT execution times for 1 <= N <= 2048
FAST
The conv function in MATLAB is implemented using the filter function
CONVOLUTIONS (which is written in C) and is very efficient for smaller values of N (< 50).
For larger values of N it is possible to speed up the convolution using the
FFT algorithm. This approach uses the circular convolution to implement
the linear convolution, and the FFT to implement the circular convolution. The resulting algorithm is called a fast convolution algorithm. In
addition, if we choose N = 2ν and implement the radix-2 FFT, then the
algorithm is called a high-speed convolution. Let x1 (n) be a N1 -point sequence and x2 (n) be a N2 -point sequence; then for high-speed convolution
N is chosen to be
N =2
log2 (N1 +N2 −1)
(5.57)
where x is the smallest integer greater than x (also called a ceiling
function). The linear convolution x1 (n) ∗ x2 (n) can now be implemented
by two N -point FFTs, one N -point IFFT, and one N -point dot-product.
x1 (n) ∗ x2 (n) = IFFT [FFT [x1 (n)] · FFT [x2 (n)]]
(5.58)
For large values of N , (5.58) is faster than the time-domain convolution
as we see in the following example.
The Fast Fourier Transform
171
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 5.22
Solution
To demonstrate the effectiveness of the high-speed convolution, let us compare
the execution times of two approaches. Let x1 (n) be an L-point uniformly
distributed random number between [0, 1], and let x2 (n) be an L-point Gaussian
random sequence with mean 0 and variance 1. We will determine the average
execution times for 1 ≤ L ≤ 150, in which the average is computed over the
100 realizations of random sequences. (Please see the cautionary note given in
Example 5.21)
MATLAB Script:
conv_time = zeros(1,150); fft_time = zeros(1,150);
%
for L = 1:150
tc = 0; tf=0;
N = 2*L-1; nu = ceil(log10(NI)/log10(2)); N = 2^nu;
for I=1:100
h = randn(1,L); x = rand(1,L);
t0 = clock; y1 = conv(h,x); t1=etime(clock,t0); tc = tc+t1;
t0 = clock; y2 = ifft(fft(h,N).*fft(x,N)); t2=etime(clock,t0);
tf = tf+t2;
end
%
conv_time(L)=tc/100; fft_time(L)=tf/100;
end
%
n = 1:150; subplot(1,1,1);
plot(n(25:150),conv_time(25:150),n(25:150),fft_time(25:150))
Figure 5.21 shows the linear convolution and the high-speed convolution times
for 25 ≤ L ≤ 150. It should be noted that these times are affected by the
computing platform used to execute the MATLAB script. The plot in Figure
5.21 was obtained on a 33-MHz 486 computer. It shows that for low values of
L the linear convolution is faster. The crossover point appears to be L = 50,
beyond which the linear convolution time increases exponentially, while the
high-speed convolution time increases fairly linearly. Note that since N = 2ν ,
the high-speed convolution time is constant over a range on L.
HIGH-SPEED
Earlier we discussed a block convolution algorithm called the overlap-andBLOCK
save method (and its companion the overlap-and-add method), which is
CONVOLUTIONS used to convolve a very large sequence with a relatively smaller sequence.
The MATLAB function ovrlpsav developed in that section uses the DFT
to implement the linear convolution. We can now replace the DFT by the
radix-2 FFT algorithm to obtain a high-speed overlap-and-save algorithm.
172
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Comparison of convolution times
0.35
convolution
0.3
time in sec.
0.25
0.2
0.15
0.1
high–speed convolution
0.05
0
0
50
100
150
sequence length N
FIGURE 5.21
Comparison of linear and high-speed convolution times
To further reduce the computations, the FFT of the shorter (fixed) sequence can be computed only once. The following hsolpsav function
shows this algorithm.
function [y] = hsolpsav(x,h,N)
% High-speed Overlap-Save method of block convolutions using FFT
% -------------------------------------------------------------% [y] = hsolpsav(x,h,N)
% y = output sequence
% x = input sequence
% h = impulse response
% N = block length (must be a power of two)
%
N = 2^(ceil(log10(N)/log10(2));
Lenx = length(x); M = length(h);
M1 = M-1; L = N-M1; h = fft(h,N);
%
x = [zeros(1,M1), x, zeros(1,N-1)];
K = floor((Lenx+M1-1)/(L)); % # of blocks
Y = zeros(K+1,N);
The Fast Fourier Transform
173
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
for k=0:K
xk = fft(x(k*L+1:k*L+N));
Y(k+1,:) = real(ifft(xk.*h));
end
Y = Y(:,M:N)’; y = (Y(:))’;
A similar modification can be done to the overlap-and-add algorithm.
MATLAB also provides the function fftfilt to implement the overlapand-add algorithm.
PROBLEMS
P5.1 Compute the DFS coefficients of the following periodic sequences using the DFS definition
and then verify your answers using MATLAB.
1.
2.
3.
4.
5.
x̃1 (n) = {4, 1, −1, 1}, N = 4
x̃2 (n) = {2, 0, 0, 0, −1, 0, 0, 0}, N = 8
x̃3 (n) = {1, 0, −1, −1, 0}, N = 5
x̃4 (n) = {0, 0, 2j, 0, 2j, 0}, N = 6
x̃5 (n) = {3, 2, 1}, N = 3
P5.2 Determine the periodic sequences given the following periodic DFS coefficients. First use
the IDFS definition and then verify your answers using MATLAB.
1.
2.
3.
4.
5.
X̃1 (k) = {4, 3j, −3j}, N = 3
X̃2 (k) = {j, 2j, 3j, 4j}, N = 4
X̃3 (k) = {1, 2 + 3j, 4, 2 − 3j}, N = 4
X̃4 (k) = {0, 0, 2, 0}, N = 5
X̃5 (k) = {3, 0, 0, 0, −3, 0, 0, 0}, N = 8
P5.3 Let x̃1 (n) be periodic with fundamental period N = 40 where one period is given by
x̃1 (n) =
5 sin(0.1πn),
0,
0 ≤ n ≤ 19
20 ≤ n ≤ 39
and let x̃2 (n) be periodic with fundamental period N = 80, where one period is given by
x̃2 (n) =
5 sin(0.1πn),
0,
0 ≤ n ≤ 19
20 ≤ n ≤ 79
These two periodic sequences differ in their periodicity but otherwise have the same
non-zero samples.
1. Compute the DFS X̃1 (k) of x̃1 (n) and plot samples (using the stem function) of its
magnitude and angle versus k.
2. Compute the DFS X̃2 (k) of x̃2 (n) and plot samples of its magnitude and angle versus k.
3. What is the difference between the above two DFS plots?
174
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P5.4 Consider the periodic sequence x̃1 (n) given in Problem P5.3. Let x̃2 (n) be periodic with
fundamental period N = 40, where one period is given by
0 ≤ n ≤ 19
20 ≤ n ≤ 39
x̃1 (n),
−x̃1 (n − 20),
x̃2 (n) =
1. Determine analytically the DFS X̃2 (k) in terms of X̃ − 1(k).
2. Compute the DFS X̃2 (k) of x̃2 (n) and plot samples of its magnitude and angle versus k.
3. Verify your answer in part 1 above using the plots of X̃1 (k) and X̃2 (k)?
P5.5 Consider the periodic sequence x̃1 (n) given in Problem P5.3. Let x̃3 (n) be periodic with
period 80, obtained by concatenating two periods of x̃1 (n), i.e.,
x̃3 (n) = [x̃1 (n), x̃1 (n)]PERIODIC
Clearly, x̃3 (n) is different from x̃2 (n) of Problem P5.3 even though both of them are
periodic with period 80.
1. Compute the DFS X̃3 (k) of x̃3 (n) and plot samples of its magnitude and angle versus k.
2. What effect does the periodicity doubling have on the DFS?
3. Generalize the above result to M -fold periodicity. In particular show that if




x̃M (n) = x̃1 (n), x̃1 (n), . . . , x̃1 (n) 
M
times
PERIODIC
then
X̃M (M k) = M X̃1 (k),
= 0,
X̃M (k)
k = 0, 1, . . . , N − 1
k = 0, M, . . . , M N
P5.6 Let X(ejω ) be the DTFT of a finite-length sequence
x(n) =
n + 1,
100 − n,
0,
0 ≤ n ≤ 49;
50 ≤ n ≤ 99;
otherwise.
1. Let
10-point y1 (n) = IDFS X(ej0 ), X(ej2π/10 ), X(ej4π/10 ), . . . , X(ej18π/10 )
Determine y1 (n) using the frequency sampling theorem. Verify your answer using
MATLAB.
2. Let
200-point y2 (n) = IDFS
X(ej0 ), X(ej2π/200 ), X(ej4π/200 ), . . . , X(ej398π/200 )
Determine y2 (n) using the frequency sampling theorem. Verify your answer using
MATLAB.
3. Comment on your results in parts (a) and (b) above.
Problems
175
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P5.7 Let x̃(n) be a periodic sequence with period N and let
ỹ(n) = x̃(−n) = x̃(N − n)
that is, ỹ(n) is a periodically folded version of x̃(n). Let X̃(k) and Ỹ (k) be the DFS
sequences.
1. Show that
Ỹ (k) = X̃(−k) = X̃(N − k)
that is, Ỹ (k) is also a periodically folded version of X̃(k).
2. Let x̃(n) = {2, 4, 6, 1, 3, 5}PERIODIC with N = 4.
↑
(a)
(b)
(c)
(d)
Sketch ỹ(n) for 0 ≤ n ≤ 5.
Compute X̃(k) for 0 ≤ k ≤ 5.
Compute Ỹ (k) for 0 ≤ k ≤ 5.
Verify the relation in part 1 above.
P5.8 Consider the finite-length sequence given below.
x(n) =
sin c2 {(n − 50)/2},
0,
0 ≤ n ≤ 100;
else.
1. Determine the DFT X(k) of x(n). Plot (using the stem function) its magnitude and
phase.
2. Plot the magnitude and phase of the DTFT X(ejω ) of x(n) using MATLAB.
3. Verify that the above DFT is the sampled version of X(ejω ). It might be helpful to
combine the above two plots in one graph using the hold function.
4. Is it possible to reconstruct the DTFT X(ejω ) from the DFT X(k)? If possible, give the
necessary interpolation formula for reconstruction. If not possible, state why this
reconstruction cannot be done.
P5.9 Let a finite-length sequence be given by
x(n) =
2e−0.9|n| ,
0,
−5 ≤ n ≤ 5;
otherwise.
Plot the DTFT X(ejω ) of the above sequence using DFT as a computation tool. Choose the
length N of the DFT so that this plot appears to be a smooth graph.
P5.10 Plot the DTFT magnitude and angle of each of the following sequences using the DFT as a
computation tool. Make an educated guess about the length N so that your plots are
meaningful.
1.
2.
3.
4.
x(n) = (0.6)|n| [u(n + 10) − u(n − 11)].
x(n) = n(0.9)n [u(n) − u(n − 21)].
x(n) = [cos(0.5πn) + j sin(0.5πn)][u(n) − u(n − 51)].
x(n) = {1, 2, 3, 4, 3, 2, 1}.
↑
5. x(n) = {−1, −2, −3, 0, 3, 2, 1}.
↑
176
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P5.11 Let H(ejω ) be the frequency response of a real, causal discrete-time LSI system.
1. If
Re H ejω
=
5
(0.9)k cos (kω)
k=0
determine the impulse response h(n) analytically. Verify your answer using IDFT as a
computation tool. Choose the length N appropriately.
2. If
Im H ejω
=
5
2! sin (!ω) ,
π
H(ejω )dω = 0
and
−π
=0
determine the impulse response h(n) analytically. Verify your answer using IDFT as a
computation tool. Again choose the length N appropriately.
P5.12 Let X(k) denote the N -point DFT of an N -point sequence x(n). The DFT X(k) itself is an
N -point sequence.
1. If the DFT of X(k) is computed to obtain another N -point sequence x1 (n), show that
x1 (n) = N x((−n))N ,
0≤n≤N −1
2. Using the above property, design a MATLAB function to implement an N -point circular
folding operation x2 (n) = x1 ((−n))N . The format should be
x2 = circfold(x1,N)
% Circular folding using DFT
% x2 = circfold(x1,N)
% x2 = circularly folded output sequence
% x1 = input sequence of length <= N
% N = circular buffer length
3. Determine the circular folding of the following sequence
x1 (n) = {1, 3, 5, 7, 9, −7, −5, −3, −1}
P5.13 Let X(k) be an N -point DFT of an N -point sequence x(n). Let N be an even integer.
1. If x(n) = x(n + N/2) for all n then show that X(k) = 0 for k odd (i.e., non-zero for k
even). Verify this result for x(n) = {1, 2, −3, 4, 5, 1, 2, −3, 4, 5}.
2. If x(n) = −x(n + N/2) for all n then show that X(k) = 0 for k even (i.e., non-zero for k
odd). Verify this result for x(n) = {1, 2, −3, 4, 5, −1, −2, 3, −4, −5}.
P5.14 Let X(k) be an N -point DFT of an N -point sequence x(n). Let N = 4ν where ν is an
integer.
1. If x(n) = x(n + ν) for all n then show that X(k) is non-zero for k = 4! for 0 ≤ ! ≤ ν − 1.
Verify this result for x(n) = {1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3}.
2. If x(n) = −x(n + ν) for all n then show that X(k) is non-zero for k = 4! + 2 for
0 ≤ ! ≤ ν − 1. Verify this result for x(n) = {1, 2, 3, −1, −2, −3, 1, 2, 3, −1, −2, −3}.
Problems
177
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P5.15 Let X(k) be an N -point DFT of an N -point sequence x(n). Let N = 2µν where µ and ν are
integers.
1. If x(n) = x(n + ν) for all n then show that X(k) is non-zero for k = µ(2!) for 0 ≤ ! ≤
ν − 1. Verify this result for x(n) = {1, −2, 3, 1, −2, 3, 1, −2, 3, 1, −2, 3, 1, −2, 3, 1, −2, 3}.
2. If x(n) = −x(n + ν) for all n then show that X(k) is non-zero for k = µ(2! + 1) for
0 ≤ ! ≤ ν − 1. Verify this result for x(n) = {1, −2, 3, −1, 2, −3, 1, −2, 3, −1, 2, −3, 1, −2,
3, −1, 2, −3}.
P5.16 Let X(k) and Y (k) be 10-point DFTs of two 10-point sequences x(n) and y(n),
respectively. If
X(k) = exp(j0.2πk),
0≤k≤9
determine Y (k) in each of the following cases without computing the DFT.
1.
2.
3.
4.
5.
y(n) = x((n − 5))10
y(n) = x((n + 4))10
y(n) = x((3 − n))10
y(n) = x(n)ej3πn/5
y(n) = x(n) 10 x((−n))10
Verify your answers using MATLAB.
P5.17 The first six values of the 10-point DFT of a real-valued sequence x(n) are given by
{10, −2 + j3, 3 + j4, 2 − j3, 4 + j5, 12}
Determine the DFT of each of the following sequences using DFT properties.
1.
2.
3.
4.
5.
x1 (n) = x((2 − n))10
x2 (n) = x((n + 5))10
x3 (n) = x(n)x((−n))10
x4 (n) = x(n) 10 x((−n))10
x5 (n) = x(n)e−j4πn/5
P5.18 Complex-valued N -point sequence x(n) can be decomposed into N -point circular-conjugatesymmetric and circular-conjugate-antisymmetric sequences using the following relations
1
[x(n) + x∗ ((−n))N ]
2
1
[x(n) − x∗ ((−n))N ]
2
xccs (n) =
xcca (n) =
If XR (k) and XI (k) are the real and imaginary parts of the N -point DFT of x(n), then
DFT [xccs (n)] = XR (k)
and
DFT [xcca (n)] = jXI (k)
1. Prove the above property analytically.
2. Modify the circevod function developed in the chapter so that it can be used for
complex-valued sequences.
3. Let X(k) = [3 cos(0.2πk) + j4 sin(0.1πk)][u(k) − u(k − 20)] be a 20-point DFT. Verify the
above symmetry property using your circevod function.
178
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P5.19 If X(k) is the N -point DFT of an N -point complex-valued sequence
x(n) = xR (n) + jxI (n)
where xR (n) and xI (n) are the real and imaginary parts of x(n), then
DFT [xR (n)] = Xccs (k)
and
DFT [jxI (n)] = Xcca (k)
where Xccs (k) and Xcca (k) are the circular-even and circular-odd components of X(k) as
defined in Problem P5.18.
1. Prove the above property analytically.
2. This property can be used to compute the DFTs of two real-valued N -point sequences
using one N -point DFT operation. Specifically, let x1 (n) and x2 (n) be two N -point
sequences. Then we can form a complex-valued sequence
x(n) = x1 (n) + jx2 (n)
and use the above property. Develop a MATLAB function to implement this approach
with the following format.
function [X1,X2] = real2dft(x1,x2,N)
% DFTs of two real sequences
% [X1,X2] = real2dft(x1,x2,N)
% X1 = n-point DFT of x1
% X2 = n-point DFT of x2
% x1 = sequence of length <= N
% x2 = sequence of length <= N
%
N = length of DFT
3. Compute and plot the DFTs of the following two sequences using the above function
x1 (n) = cos(0.1πn), x2 (n) = sin(0.2πn);
0 ≤ n ≤ 39
P5.20 Using the frequency domain approach, devise a MATLAB function to determine a circular
shift x((n − m))N , given an N1 -point sequence x(n) where N1 ≤ N . Your function should
have the following format.
function y = cirshftf(x,m,N)
% Circular shift of m samples wrt size N in sequence x: (freq domain)
% ------------------------------------------------------------------% y = cirshftf(x,m,N)
%
y : output sequence containing the circular shift
%
x : input sequence of length <= N
%
m : sample shift
%
N : size of circular buffer
%
Method: y(n) = idft(dft(x(n))*WN^(mk))
%
%
If m is a scalar then y is a sequence (row vector)
%
If m is a vector then y is a matrix, each row is a circular shift
%
in x corresponding to entries in vecor m
%
M and x should not be matrices
Problems
179
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Verify your function on the following sequence
x(n) = {5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4},
↑
0 ≤ n ≤ 10
with (a) m = −5, N = 11 and (b) m = 8, N = 15.
P5.21 Using the analysis and synthesis equations of the DFT, show that the energy of a sequence
satisfies
EX =
N −1
|x(n)|2 =
n=0
N −1
1 |X(k)|2
N
k=0
This is commonly referred to as a Parseval’s relation for the DFT. Verify this relation using
MATLAB on the sequence in Problem P5.20.
P5.22 A 512-point DFT X(k) of a real-valued sequence x(n) has the following DFT values:
X(0) = 20 + jα;
X(k2 ) = 20 − j30;
X(5)
X(k1 ) = −10 + j15;
= 20 + j30;
X(k3 ) = 17 − j23;
X(480) = 10 − j15;
X(152 = 17 + j23;
X(256) = 30 + jβ
and all other values are known to be zero.
1.
2.
3.
4.
Determine the real-valued coefficients α and β.
Determine the values of the integers k1 , k2 , and k3 .
Determine the energy of the signal x(n).
Express the sequence x(n) in a closed form.
P5.23 Let x(n) be a finite length sequence given by
.
x(n) =
. . . , 0, 0, 0, 1, 2, −3, 4, −5, 0, . . .
↑
Determine and sketch the sequence x((−8 − n))7 R7 (n) where
R7 (n) =
1,
0,
0≤n≤6
else
P5.24 The circonvt function developed in this chapter implements the circular convolution as a
matrix-vector multiplication. The matrix corresponding to the circular shifts {x((n − m))N ;
0 ≤ n ≤ N − 1} has an interesting structure. This matrix is called a circulant matrix which
is a special case of Toeplitz matrix introduced in Chapter 2.
1. Consider the sequences given in Example 5.13. Express x1 (n) as a column vector x1 and
x2 ((n − m))N as a circulant matrix X2 with rows corresponding to n = 0, 1, 2, 3.
Characterize this matrix X2 . Can it completely be described by its first row (or column)?
2. Determine the circular convolution as X2 x1 and verify your calculations.
P5.25 Develop a MATLAB function to construct a circulant matrix C given an N -point sequence
x(n). Use the toeplitz function to implement matrix C. Your subroutine function should
have the following format:
180
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
function [C] = circulnt(x,N)
% Circulant Matrix from an N-point sequence
% [C] = circulnt(x,N)
% C = circulant matrix of size NxN
% x = sequence of length <= N
% N = size of circulant matrix
Using this function, modify the circular convolution function circonvt discussed in the
chapter so that the for...end loop is eliminated. Verify your functions on the sequences in
Problem P5.24.
P5.26 Using the frequency domain approach, devise a MATLAB function to implement the
circular convolution operation between two sequences. The format of the sequence should
be
function x3 = circonvf(x1,x2,N)
% Circular convolution in the frequency domain
% x3 = circonvf(x1,x2,N)
% x3 = convolution result of length N
% x1 = sequence of length <= N
% x2 = sequence of length <= N
%
N = length of circular buffer
Using your function, compute the circular convolution {4, 3, 2, 1} 4 {1, 2, 3, 4}.
P5.27 The following four sequences are given:
5 x2 (n)
x1 (n) = {1, 3, 2, −1}; x2 (n) = {2, 1, 0, −1}; x3 (n) = x1 (n) ∗ x2 (n); x4 (n) = x1 (n) ↑
↑
a) Determine and sketch x3 (n).
b) Using x3 (n) alone, determine and sketch x4 (n). Do not directly compute x4 (n).
P5.28 Compute the N -point circular convolution for the following sequences. Plot their samples.
1.
2.
3.
4.
5.
x1 (n) = sin(πn/3)R6 (n), x2 (n) = cos(πn/4)R8 (n); N = 10
x1 (n) = cos (2πn/N ) RN (n), x2 (n) = sin (2πn/N ) RN (n); N = 32
x1 (n) = (0.8)n RN (n), x2 (n) = (−0.8)n RN (n); N = 20
x1 (n) = nRN (n), x2 (n) = (N − n) RN (n); N = 10
x1 (n) = (0.8)n R20 , x2 (n) = u(n) − u(n − 40); N = 50
P5.29 Let x1 (n) and x2 (n) be two N -point sequences.
1. If y(n) = x1 (n) N x2 (n) show that
N −1
n=0
y(n) =
/N −1
0 /N −1
x1 (n)
n=0
0
x2 (n)
n=0
2. Verify the above result for the following sequences.
x1 (n) = {9, 4, −1, 4, −4, −1, 8, 3};
Problems
x2 (n) = {−5, 6, 2, −7, −5, 2, 2, −2}
181
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P5.30 Let X(k) be the 8-point DFT of a 3-point sequence x(n) = {5, −4, 3}. Let Y (k) be the
↑
8-point DFT of a sequence y(n). Determine y(n) when Y (k) = W85k X((k))8 .
P5.31 For the following sequences compute (i) the N -point circular convolution x3 (n) = x1 (n)
N x2 (n), (ii) the linear convolution x4 (n) = x1 (n) ∗ x2 (n), and (iii) the error sequence
e(n) = x3 (n) − x4 (n).
1.
2.
3.
4.
5.
x1 (n) = {1, 1, 1, 1} , x2 (n) = cos (πn/4) R6 (n); N = 8
x1 (n) = cos (2πn/N ) R16 (n), x2 (n) = sin (2πn/N ) R16 (n);
x1 (n) = (0.8)n R10 (n), x2 (n) = (−0.8)n R10 (n); N = 15
x1 (n) = nR10 (n), x2 (n) = (N − n) R10 (n); N = 10
x1 (n) = {1, −1, 1, −1} , x2 (n) = {1, 0, −1, 0} ; N = 5
N = 32
In each case verify that e(n) = x4 (n + N ).
P5.32 The overlap-add method of block convolution is an alternative to the overlap-save method.
Let x(n) be a long sequence of length M L where M, L 1. Divide x(n) into M segments
{xm (n), m = 1, . . . , M } each of length L
xm (n) =
x(n),
0,
mM ≤ n ≤ (m + 1) M − 1
elsewhere
M −1
so that
x(n) =
xm (n)
m=0
Let h(n) be an L-point impulse response, then
M −1
y(n) = x(n) ∗ h(n) =
M −1
xm (n) ∗ h(n) =
m=0
ym (n);
ym (n) = xm (n) ∗ h(n)
m=0
Clearly, ym (n) is a (2L − 1)-point sequence. In this method we have to save the
intermediate convolution results and then properly overlap these before adding to form the
final result y(n). To use DFT for this operation we have to choose N ≥ (2L − 1).
1. Develop a MATLAB function to implement the overlap-add method using the circular
convolution operation. The format should be
function [y] = ovrlpadd(x,h,N)
% Overlap-Add method of block convolution
% [y] = ovrlpadd(x,h,N)
%
% y = output sequence
% x = input sequence
% h = impulse response
% N = block length >= 2*length(h)-1
2. Incorporate the radix-2 FFT implementation in the above function to obtain a
high-speed overlap-add block convolution routine. Remember to choose N = 2ν .
3. Verify your functions on the following two sequences
x(n) = cos (πn/500) R4000 (n),
h(n) = {1, −1, 1, −1}
P5.33 Given the sequences x1 (n) and x2 (n) shown below:
x1 (n) = {2, 1, 1, 2} ,
182
x2 (n) = {1, −1, −1, 1}
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1. Compute the circular convolution x1 (n) N x2 (n) for N = 4, 7 and 8.
2. Compute the linear convolution x1 (n) ∗ x2 (n).
3. Using results of calculations, determine the minimum value of N necessary so that linear
and circular convolutions are same on the N -point interval.
4. Without performing the actual convolutions, explain how you could have obtained the
result of P5.33.3 above.
P5.34 Let
x(n) =
A cos (2π!n/N ) ,
0,
0≤n≤N −1
= A cos (2π!n/N ) RN (n)
elsewhere
where ! is an integer. Notice that x(n) contains exactly ! periods (or cycles) of the cosine
waveform in N samples. This is a windowed cosine sequence containing no leakage.
1. Show that the DFT X(k) is a real sequence given by
AN
AN
δ (k − !) +
δ (k − N + !) ; 0 ≤ k ≤ (N − 1) ,
2
2
2. Show that if ! = 0, then the DFT X(k) is given by
X(k) =
X(k) = AN δ(k);
0<!<N
0 ≤ k ≤ (N − 1)
3. Explain clearly how the above results should be modified if ! < 0 or ! > N .
4. Verify the results of parts 1., 2., and 3. above using the following sequences. Plot the real
parts of the DFT sequences using the stem function.
(a)
(b)
(c)
(d)
(e)
x1 (n) = 3 cos (0.04πn) R200 (n)
x2 (n) = 5R50 (n)
x3 (n) = [1 + 2 cos (0.5πn) + cos (πn)] R100 (n)
x4 (n) = cos (25πn/16) R64 (n)
x5 (n) = [4 cos (0.1πn) − 3 cos (1.9πn)] RN (n)
P5.35 Let x(n) = A cos (ω0 n) RN (n), where ω0 is a real number.
1. Using the properties of the DFT, show that the real and the imaginary parts of X(k) are
given by
X(k) = XR (k) + jXI (k)
XR (k) = (A/2) cos
π(N −1)
+ (A/2) cos
XI (k) = − (A/2) sin
− (A/2) sin
N
π(N −1)
N
π(N −1)
N
π(N −1)
N
sin [π (k − f0 N )]
(k − f0 N )
sin [π (k − f0 N ) /N ]
sin [π (k − N + f0 N )]
(k + f0 N )
sin [π (k − N + f0 N ) /N ]
sin [π (k − f0 N )]
(k − f0 N )
sin [π (k − f0 N ) /N ]
sin [π (k − N + f0 N )]
(k + f0 N )
sin [π (k − N + f0 N ) /N ]
2. The above result implies that the original frequency ω0 of the cosine waveform has leaked
into other frequencies that form the harmonics of the time-limited sequence and hence it
is called the leakage property of cosines. It is a natural result due to the fact that
bandlimited periodic cosines are sampled over noninteger periods. Explain this result
using the periodic extension x̃(n) of x(n) and the result in Problem P5.34.1.
Problems
183
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3. Verify the leakage property using x(n) = cos (5πn/99) R200 (n). Plot the real and the
imaginary parts of X(k) using the stem function.
P5.36 Let
x(n) =
A sin (2π!n/N ) ,
0,
0≤n≤N −1
= A sin (2π!n/N ) RN (n)
elsewhere
where ! is an integer. Notice that x(n) contains exactly ! periods (or cycles) of the sine
waveform in N samples. This is a windowed sine sequence containing no leakage.
1. Show that the DFT X(k) is a purely imaginary sequence given by
X(k) =
AN
AN
δ (k − !) −
δ (k − N + !) ;
2j
2j
0 ≤ k ≤ (N − 1) ,
0<!<N
2. Show that if ! = 0 then the DFT X(k) is given by
X(k) = 0;
0 ≤ k ≤ (N − 1)
3. Explain clearly how the above results should be modified if ! < 0 or ! > N .
4. Verify the results of parts 1., 2., and 3. above using the following sequences. Plot the
imaginary parts of the DFT sequences using the stem function.
(a)
(b)
(c)
(d)
(e)
x1 (n) = 3 sin (0.04πn) R200 (n)
x2 (n) = 5 sin 10πnR50 (n)
x3 (n) = [2 sin (0.5πn) + sin (πn)] R100 (n)
x4 (n) = sin (25πn/16) R64 (n)
x5 (n) = [4 sin (0.1πn) − 3 sin (1.9πn)] RN (n)
P5.37 Let x(n) = A sin (ω0 n) RN (n), where ω0 is a real number.
1. Using the properties of the DFT, show that the real and the imaginary parts of X(k) are
given by
X(k) = XR (k) + jXI (k)
XR (k) = (A/2) sin
π(N −1)
− (A/2) sin
XI (k) = − (A/2) cos
+ (A/2) cos
N
π(N −1)
N
π(N −1)
N
π(N −1)
N
sin [π (k − f0 N )]
(k − f0 N )
sin [π (k − f0 N ) /N ]
sin [π (k − N + f0 N )]
(k + f0 N )
sin [π (k − N + f0 N ) /N ]
sin [π (k − f0 N )]
(k − f0 N )
sin [π (k − f0 N ) /N ]
sin [π (k − N + f0 N )]
(k + f0 N )
sin [π (k − N + f0 N ) /N ]
2. The above result is the leakage property of sines. Explain it using the periodic extension
x̃(n) of x(n) and the result in Problem P5.36.1.
3. Verify the leakage property using x(n) = sin (5πn/99) R200 (n). Plot the real and the
imaginary parts of X(k) using the stem function.
P5.38 An analog signal xa (t) = 2 sin (4πt) + 5 cos (8πt) is sampled at t = 0.01n for
n = 0, 1, . . . , N − 1 to obtain an N -point sequence x(n). An N -point DFT is used to obtain
an estimate of the magnitude spectrum of xa (t).
184
Chapter 5
THE DISCRETE FOURIER TRANSFORM
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1. From the following values of N , choose the one which will provide the accurate estimate
of the spectrum of xa (t). Plot the real and imaginary parts of the DFT spectrum |X(k)|.
(a) N = 40,
(b) N = 50,
(c) N = 60.
2. From the following values of N , choose the one which will provide the least amount of
leakage in the spectrum of xa (t). Plot the real and imaginary parts of the DFT spectrum
|X(k)|.
(a) N = 90,
(b) N = 95,
(c) N = 99.
P5.39 Using (5.49), determine and draw the signal flow graph for the N = 8 point, radix-2
decimation-in-frequency FFT algorithm. Using this flow graph, determine the DFT of the
sequence
x(n) = cos (πn/2) ,
0 ≤ n ≤ 7.
P5.40 Using (5.49), determine and draw the signal flow graph for the N = 16 point, radix-4
decimation-in-time FFT algorithm. Using this flow graph determine the DFT of the
sequence
x(n) = cos (πn/2) ,
0 ≤ n ≤ 15.
P5.41 Let x(n) be a uniformly distributed random number between [−1, 1] for 0 ≤ n ≤ 106 . Let
h(n) = sin(0.4πn),
0 ≤ n ≤ 100
1. Using the conv function, determine the output sequence y(n) = x(n) ∗ h(n).
2. Consider the overlap-and-save method of block convolution along with the FFT
algorithm to implement high-speed block convolution. Using this approach, determine
y(n) with FFT sizes of 1024, 2048, and 4096.
3. Compare the above approaches in terms of the convolution results and their execution
times.
Problems
185
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
6
Digital Filter
Structures
In earlier chapters we studied the theory of discrete systems in both the
time and frequency domains. We will now use this theory for the processing of digital signals. To process signals, we have to design and implement
systems called filters (or spectrum analyzers in some contexts). The filter
design issue is influenced by such factors as the type of the filter (i.e., IIR
or FIR) or the form of its implementation (structures). Hence before we
discuss the design issue, we first concern ourselves with how these filters
can be implemented in practice. This is an important concern because
different filter structures dictate different design strategies.
As we discussed earlier, IIR filters are characterized by infiniteduration impulse responses. Some of these impulse responses can be
modeled by rational system functions or, equivalently, by difference equations. Such filters are termed as auto-regressive moving average (ARMA)
or, more generally, as recursive filters. Those IIR filters that cannot be so
modeled are called nonrecursive filters. In DSP, IIR filters generally imply
recursive ones because these can be implemented efficiently. Therefore
we will always use the term IIR to imply recursive filters. Furthermore,
ARMA filters include moving average filters that are FIR filters. However,
we will treat FIR filters separately from IIR filters for both design and
implementation purposes.
We begin with a description of basic building blocks that are used
to describe filter structures. In the remaining sections we briefly describe
IIR, FIR, and lattice filter structures, respectively, and provide MATLAB
functions to implement these structures.
186
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x1(n) + x 2(n)
x1(n)
x2(n)
(a) Adder
z −1
a
x(n)
ax(n)
(b) Multiplier
FIGURE 6.1
x(n)
x(n − 1)
(c) Delay element
Three basic elements
BASIC ELEMENTS
Since our filters are LTI systems, we need the following three elements to
describe digital filter structures. These elements are shown in Figure 6.1.
• Adder: This element has two inputs and one output and is shown
in Figure 6.1(a). Note that the addition of three or more signals is
implemented by successive two-input adders.
• Multiplier (gain): This is a single-input, single-output element and is
shown in Figure 6.1(b). Note that the multiplication by 1 is understood
and hence not explicitly shown.
• Delay element (shifter or memory): This element delays the signal passing through it by one sample as shown in Figure 6.1(c). It is
implemented by using a shift register.
Using these basic elements, we can now describe various structures of
both IIR and FIR filters. MATLAB is a convenient tool in the development of these structures that require operations on polynomials.
IIR FILTER STRUCTURES
The system function of an IIR filter is given by
M
−n
b0 + b1 z −1 + · · · + bM z −M
B(z)
n=0 bn z
=
; a0 = 1
= N
−n
A(z)
1 + a1 z −1 + · · · + aN z −N
n=0 an z
(6.1)
where bn and an are the coefficients of the filter. We have assumed without
loss of generality that a0 = 1. The order of such an IIR filter is called N if
H(z) =
IIR Filter Structures
187
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
aN = 0. The difference equation representation of an IIR filter is expressed
as
M
N
y(n) =
bm x(n − m) −
am y(n − m)
(6.2)
m=0
m=1
Three different structures can be used to implement an IIR filter:
• Direct form: In this form the difference equation (6.2) is implemented
directly as given. There are two parts to this filter, namely the moving
average part and the recursive part (or equivalently, the numerator
and denominator parts). Therefore this implementation leads to two
versions: direct form I and direct form II structures.
• Cascade form: In this form the system function H(z) in equation
(6.1) is factored into smaller second-order sections, called biquads. The
system function is then represented as a product of these biquads. Each
biquad is implemented in a direct form, and the entire system function
is implemented as a cascade of biquad sections.
• Parallel form: This is similar to the cascade form, but after factorization, a partial fraction expansion is used to represent H(z) as a sum of
smaller second-order sections. Each section is again implemented in a
direct form, and the entire system function is implemented as a parallel
network of sections.
We will briefly discuss these forms in this section. IIR filters are generally described using the rational form version (or the direct form structure) of the system function. Hence we will provide MATLAB functions for
converting direct form structures to cascade and parallel form structures.
DIRECT FORM
As the name suggests, the difference equation (6.2) is implemented as
given using delays, multipliers, and adders. For the purpose of illustration,
let M = N = 4. Then the difference equation is
y(n) = b0 x(n) + b1 x(n − 1) + b2 x(n − 2) + b3 x(n − 3) + b4 x(n − 4)
− a1 y(n − 1) − a2 y(n − 2) − a3 y(n − 3) − a4 y(n − 4)
which can be implemented as shown in Figure 6.2. This block diagram is
called direct form I structure.
The direct form I structure implements each part of the rational function H(z) separately with a cascade connection between them. The numerator part is a tapped delay line followed by the denominator part,
which is a feedback tapped delay line. Thus there are two separate delay
lines in this structure, and hence it requires eight delay elements. We can
reduce this delay element count or eliminate one delay line by interchanging the order in which the two parts are connected in the cascade. Now the
two delay lines are close to each other, connected by a unity gain branch.
188
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.2
Direct form I structure
Therefore one delay line can be removed, and this reduction leads to a
canonical structure called direct form II structure, shown in Figure 6.3.
It should be noted that both direct forms are equivalent from the inputoutput point of view. Internally, however, they have different signals.
TRANSPOSED
STRUCTURE
An equivalent structure to the direct form can be obtained using a procedure called transposition. In this operation three steps are performed:
1. All path arrow directions are reversed.
2. All branch nodes are replaced by adder nodes and all adder nodes are
replaced by branch nodes.
3. The input and output nodes are interchanged.
The resulting structure is called the transposed direct form structure. The
transposed direct form II structure is shown in Figure 6.3(b). Problem
P6.3 explains this equivalent structure.
MATLAB
IMPLEMENTATION
In MATLAB the direct form structure is described by two row vectors;
b containing the {bn } coefficients and a containing the {an } coefficients.
The filter function, which is discussed in Chapter 2, implements the
transposed direct form II structure.
b0
x (n)
−a 1
z −1
−a 2
z −1
−a 3
z −1
−a 4
z −1
y (n)
x (n)
b1
b1
b2
b2
b3
b3
b4
b4
(a) Normal
FIGURE 6.3
IIR Filter Structures
b0
y (n)
z −1
−a 1
z −1
−a 2
z −1
−a 3
z −1
−a 4
(b) Transposed
Direct form II structure
189
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.4
CASCADE
FORM
Biquad section structure
In this form the system function H(z) is written as a product of
second-order sections with real coefficients. This is done by factoring
the numerator and denominator polynomials into their respective roots
and then combining either a complex conjugate root pair or any two real
roots into second-order polynomials. In the remainder of this chapter we
assume that N is an even integer. Then
b0 + b1 z −1 + · · · + bN z −N
1 + a1 z −1 + · · · + aN z −N
1 + bb10 z −1 + · · · + bbN0 z −N
= b0
1 + a1 z −1 + · · · + aN z −N
K
1 + Bk,1 z −1 + Bk,2 z −2
= b0
1 + Ak,1 z −1 + Ak,2 z −2
H(z) =
(6.3)
k=1
where K is equal to N2 , and Bk,1 , Bk,2 , Ak,1 , and Ak,2 are real numbers
representing the coefficients of second-order sections. The second-order
section
Hk (z) =
1 + Bk,1 z −1 + Bk,2 z −2
Yk+1 (z)
=
;
Yk (z)
1 + Ak,1 z −1 + Ak,2 z −2
k = 1, . . . , K
with
Y1 (z) = b0 X(z);
YK+1 (z) = Y (z)
is called the kth biquad section. The input to the kth biquad section is
the output from the (k − 1)th biquad section, while the output from the
kth biquad is the input to the (k + 1)th biquad. Now each biquad section
Hk (z) can be implemented in direct form II as shown in Figure 6.4. The
entire filter is then implemented as a cascade of biquads.
As an example, consider N = 4. Figure 6.5 shows a cascade form
structure for this fourth-order IIR filter.
FIGURE 6.5
190
Cascade form structure for N = 4
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB
IMPLEMENTATION
Given the coefficients {bn } and {an } of the direct form filter, we have to
obtain the coefficients b0 , {Bk,i }, and {Ak,i }. This is done by the function
dir2cas given below.
function [b0,B,A] = dir2cas(b,a);
% DIRECT-form to CASCADE-form conversion (cplxpair version)
% --------------------------------------------------------% [b0,B,A] = dir2cas(b,a)
% b0 = gain coefficient
% B = K by 3 matrix of real coefficients containing bk’s
% A = K by 3 matrix of real coefficients containing ak’s
% b = numerator polynomial coefficients of DIRECT form
% a = denominator polynomial coefficients of DIRECT form
% compute gain coefficient b0
b0 = b(1); b = b/b0; a0 = a(1); a = a/a0; b0 = b0/a0;
%
M = length(b); N = length(a);
if N > M
b = [b zeros(1,N-M)];
elseif M > N
a = [a zeros(1,M-N)]; N = M;
else
NM = 0;
end
%
K = floor(N/2); B = zeros(K,3); A = zeros(K,3);
if K*2 == N;
b = [b 0]; a = [a 0];
end
%
broots = cplxpair(roots(b)); aroots = cplxpair(roots(a));
for i=1:2:2*K
Brow = broots(i:1:i+1,:);
Brow = real(poly(Brow));
B(fix((i+1)/2),:) = Brow;
Arow = aroots(i:1:i+1,:);
Arow = real(poly(Arow));
A(fix((i+1)/2),:) = Arow;
end
The above function converts the b and a vectors into K × 3 B and A
matrices. It begins by computing b0 , which is equal to b0 /a0 (assuming
a0 = 1). It then makes the vectors b and a of equal length by zeropadding the shorter vector. This ensures that each biquad has a nonzero
numerator and denominator. Next it computes the roots of the B(z)
and A(z) polynomials. Using the cplxpair function, these roots are ordered in complex conjugate pairs. Now every pair is converted back into a
IIR Filter Structures
191
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
second-order numerator or denominator polynomial using the poly function. The SP toolbox function, tf2sos (transfer function to second-order
section), also performs a similar operation.
The cascade form is implemented using a casfiltr function, which
is given below. It employs the filter function in a loop using the coefficients of each biquad stored in B and A matrices. The input is scaled
by b0, and the output of each filter operation is used as an input to the
next filter operation. The output of the final filter operation is the overall
output.
function y = casfiltr(b0,B,A,x);
% CASCADE form realization of IIR and FIR filters
% ----------------------------------------------% y = casfiltr(b0,B,A,x);
% y = output sequence
% b0 = gain coefficient of CASCADE form
% B = K by 3 matrix of real coefficients containing bk’s
% A = K by 3 matrix of real coefficients containing ak’s
% x = input sequence
%
[K,L] = size(B);
N = length(x); w = zeros(K+1,N); w(1,:) = x;
for i = 1:1:K
w(i+1,:) = filter(B(i,:),A(i,:),w(i,:));
end
y = b0*w(K+1,:);
The following MATLAB function, cas2dir, converts a cascade form
to a direct form. This is a simple operation that involves multiplication of
several second-order polynomials. For this purpose the MATLAB function
conv is used in a loop over K factors. The SP toolbox function, sos2tf
also performs a similar operation.
function [b,a] = cas2dir(b0,B,A);
% CASCADE-to-DIRECT form conversion
% --------------------------------% [b,a] = cas2dir(b0,B,A)
% b = numerator polynomial coefficients of DIRECT form
% a = denominator polynomial coefficients of DIRECT form
% b0 = gain coefficient
% B = K by 3 matrix of real coefficients containing bk’s
% A = K by 3 matrix of real coefficients containing ak’s
%
[K,L] = size(B);
192
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
b = [1]; a = [1];
for i=1:1:K
b=conv(b,B(i,:)); a=conv(a,A(i,:));
end
b = b*b0;
EXAMPLE 6.1
A filter is described by the following difference equation:
16y(n) + 12y(n − 1) + 2y(n − 2) − 4y(n − 3) − y(n − 4)
= x(n) − 3x(n − 1) + 11x(n − 2) − 27x(n − 3) + 18x(n − 4)
Determine its cascade form structure.
Solution
MATLAB Script:
>> b=[1 -3 11 -27 18]; a=[16 12 2 -4 -1];
>> [b0,B,A]=dir2cas(b,a)
b0 = 0.0625
B =
1.0000
-0.0000
9.0000
1.0000
-3.0000
2.0000
A =
1.0000 1.0000
0.5000
1.0000
-0.2500
-0.1250
The resulting structure is shown in Figure 6.6. To check that our cascade structure is correct, let us compute the first 8 samples of the impulse response using
both forms.
>> delta = impseq(0,0,7)
delta =
1
0
0
0
0
>> format long
>> hcas=casfiltr(b0,B,A,delta)
FIGURE 6.6
IIR Filter Structures
0
0
0
Cascade structure in Example 6.1.
193
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
hcas =
Columns 1 through 4
0.06250000000000 -0.23437500000000
Columns 5 through 8
2.67651367187500 -1.52264404296875
>> hdir=filter(b,a,delta)
hdir =
Columns 1 through 4
0.06250000000000 -0.23437500000000
Columns 5 through 8
2.67651367187500 -1.52264404296875
0.85546875000000
-2.28417968750000
0.28984069824219
0.49931716918945
0.85546875000000
-2.28417968750000
0.28984069824219
0.49931716918945
PARALLEL
FORM
In this form the system function H(z) is written as a sum of second order
sections using partial fraction expansion.
H(z) =
=
b0 + b1 z −1 + · · · + bM z −M
B(z)
=
A(z)
1 + a1 z −1 + · · · + aN z −N
M
−N
b̂0 + b̂1 z −1 + · · · + b̂N −1 z 1−N
+
Ck z −k
1 + a1 z −1 + · · · + aN z −N
0
only if M ≥N
=
K
k=1
Bk,0 + Bk,1 z −1
+
1 + Ak,1 z −1 + Ak,2 z −2
M
−N
0
Ck z −k
(6.4)
only if M ≥N
where K is equal to N2 , and Bk,0 , Bk,1 , Ak,1 , and Ak,2 are real numbers
representing the coefficients of second-order sections. The second-order
section
Hk (z) =
Yk+1 (z)
Bk,0 + Bk,1 z −1
;
=
Yk (z)
1 + Ak,1 z −1 + Ak,2 z −2
with
Yk (z) = Hk (z)X(z),
Y (z) =
Yk (z),
k = 1, . . . , K
M <N
is the kth proper rational biquad section. The filter input is available to
all biquad sections as well as to the polynomial section if M ≥ N (which
is an FIR part). The output from these sections is summed to form the
filter output. Now each biquad section Hk (z) can be implemented in direct
form II. Due to the summation of subsections, a parallel structure can be
built to realize H(z). As an example, consider M = N = 4. Figure 6.7
shows a parallel form structure for this fourth-order IIR filter.
194
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.7
MATLAB
IMPLEMENTATION
Parallel form structure for N = 4
The function dir2par given below converts the direct form coefficients
{bn } and {an } into parallel form coefficients {Bk,i } and {Ak,i }.
function [C,B,A] = dir2par(b,a);
% DIRECT-form to PARALLEL-form conversion
% -------------------------------------% [C,B,A] = dir2par(b,a)
% C = Polynomial part when length(b) >= length(a)
% B = K by 2 matrix of real coefficients containing bk’s
% A = K by 3 matrix of real coefficients containing ak’s
% b = numerator polynomial coefficients of DIRECT form
% a = denominator polynomial coefficients of DIRECT form
%
M = length(b); N = length(a);
[r1,p1,C] = residuez(b,a);
p = cplxpair(p1,10000000*eps);
I = cplxcomp(p1,p);
r = r1(I);
K = floor(N/2); B = zeros(K,2); A = zeros(K,3);
if K*2 == N; %N even, order of A(z) odd, one factor is first order
for i=1:2:N-2
Brow = r(i:1:i+1,:); Arow = p(i:1:i+1,:);
[Brow,Arow] = residuez(Brow,Arow,[]);
B(fix((i+1)/2),:) = real(Brow); A(fix((i+1)/2),:) = real(Arow);
end
[Brow,Arow] = residuez(r(N-1),p(N-1),[]);
B(K,:) = [real(Brow) 0]; A(K,:) = [real(Arow) 0];
IIR Filter Structures
195
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
else
for i=1:2:N-1
Brow = r(i:1:i+1,:); Arow = p(i:1:i+1,:);
[Brow,Arow] = residuez(Brow,Arow,[]);
B(fix((i+1)/2),:) = real(Brow); A(fix((i+1)/2),:) = real(Arow);
end
end
The dir2cas function first computes the z-domain partial fraction expansion using the residuez function. We need to arrange pole-and-residue
pairs into complex conjugate pole-and-residue pairs followed by real poleand-residue pairs. To do this, the cplxpair function from MATLAB can
be used; this sorts a complex array into complex conjugate pairs. However, two consecutive calls to this function, one each for pole and residue
arrays, will not guarantee that poles and residues will correspond to each
other. Therefore a new cplxcomp function is developed, which compares
two shuffled complex arrays and returns the index of one array, which can
be used to rearrange another array.
function I = cplxcomp(p1,p2)
% I = cplxcomp(p1,p2)
% Compares two complex pairs which contain the same scalar elements
% but (possibly) at differrent indices. This routine should be
% used after CPLXPAIR routine for rearranging pole vector and its
% corresponding residue vector.
%
p2 = cplxpair(p1)
%
I=[];
for j=1:1:length(p2)
for i=1:1:length(p1)
if (abs(p1(i)-p2(j)) < 0.0001)
I=[I,i];
end
end
end
I=I’;
After collecting these pole-and-residue pairs, the dir2cas function computes the numerator and denominator of the biquads by employing the
residuez function in the reverse fashion.
These parallel form coefficients are then used in the function
parfiltr, which implements the parallel form. The parfiltr function
uses the filter function in a loop using the coefficients of each biquad
stored in the B and A matrices. The input is first filtered through the FIR
part C and stored in the first row of a w matrix. Then the outputs of all
196
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
biquad filters are computed for the same input and stored as subsequent
rows in the w matrix. Finally, all the columns of the w matrix are summed
to yield the output.
function y = parfiltr(C,B,A,x);
% PARALLEL form realization of IIR filters
% ---------------------------------------% [y] = parfiltr(C,B,A,x);
% y = output sequence
% C = polynomial (FIR) part when M >= N
% B = K by 2 matrix of real coefficients containing bk’s
% A = K by 3 matrix of real coefficients containing ak’s
% x = input sequence
%
[K,L] = size(B); N = length(x); w = zeros(K+1,N);
w(1,:) = filter(C,1,x);
for i = 1:1:K
w(i+1,:) = filter(B(i,:),A(i,:),x);
end
y = sum(w);
To obtain a direct form from a parallel form, the function par2dir can
be used. It computes poles and residues of each proper biquad and combines these into system poles and residues. Another call of the residuez
function in reverse order computes the numerator and denominator
polynomials.
function [b,a] = par2dir(C,B,A);
% PARALLEL-to-DIRECT form conversion
% ---------------------------------% [b,a] = par2dir(C,B,A)
% b = numerator polynomial coefficients of DIRECT form
% a = denominator polynomial coefficients of DIRECT form
% C = Polynomial part of PARALLEL form
% B = K by 2 matrix of real coefficients containing bk’s
% A = K by 3 matrix of real coefficients containing ak’s
%
[K,L] = size(A); R = []; P = [];
for i=1:1:K
[r,p,k]=residuez(B(i,:),A(i,:)); R = [R;r]; P = [P;p];
end
[b,a] = residuez(R,P,C); b = b(:)’; a = a(:)’;
IIR Filter Structures
197
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 6.2
Consider the filter given in Example 6.1.
16y(n) + 12y(n − 1) + 2y(n − 2) − 4y(n − 3) − y(n − 4)
= x(n) − 3x(n − 1) + 11x(n − 2) − 27x(n − 3) + 18x(n − 4)
Now determine its parallel form.
Solution
MATLAB Script:
>> b=[1 -3 11 -27 18]; a=[16 12 2 -4 -1];
>> [C,B,A]=dir2par(b,a)
C =
-18
B =
10.0500
-3.9500
28.1125 -13.3625
A =
1.0000
1.0000
0.5000
1.0000
-0.2500
-0.1250
The resulting structure is shown in Figure 6.8. To check our parallel structure,
let us compute the first 8 samples of the impulse response using both forms.
>> format long; delta = impseq(0,0,7);
hpar =
Columns 1 through 4
0.06250000000000 -0.23437500000000
FIGURE 6.8
198
hpar=parfiltr(C,B,A,delta)
0.85546875000000
-2.28417968750000
Parallel form structure in Example 6.2.
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Columns 5 through 8
2.67651367187500 -1.52264404296875
>> hdir = filter(b,a,delta)
hdir =
Columns 1 through 4
0.06250000000000 -0.23437500000000
Columns 5 through 8
2.67651367187500 -1.52264404296875
0.28984069824219
0.49931716918945
0.85546875000000
-2.28417968750000
0.28984069824219
0.49931716918945
EXAMPLE 6.3
Solution
What would be the overall direct, cascade, or parallel form if a structure contains
a combination of these forms? Consider the block diagram shown in Figure 6.9.
This structure contains a cascade of two parallel sections. The first parallel
section contains two biquads, while the second one contains three biquads. We
will have to convert each parallel section into a direct form using the par2dir
function, giving us a cascade of two direct forms. The overall direct form can be
computed by convolving the corresponding numerator and denominator polynomials. The overall cascade and parallel forms can now be derived from the
direct form.
MATLAB Script:
>>
>>
>>
b1
C0=0; B1=[2 4;3 1]; A1=[1 1 0.9; 1 0.4 -0.4];
B2=[0.5 0.7;1.5 2.5;0.8 1]; A2=[1 -1 0.8;1 0.5 0.5;1 0 -0.5];
[b1,a1]=par2dir(C0,B1,A1)
=
5.0000
8.8000
4.5000
-0.7000
FIGURE 6.9
IIR Filter Structures
Block diagram in Example 6.3
199
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
a1 =
1.0000
1.4000
0.9000
-0.0400
-0.3600
>> [b2,a2]=par2dir(C0,B2,A2)
b2 =
2.8000
2.5500
-1.5600
2.0950
0.5700
a2 =
1.0000
-0.5000
0.3000
0.1500
0.0000
>> b=conv(b1,b2) % Overall direct form numerator
b =
Columns 1 through 7
14.0000
37.3900
27.2400
6.2620
12.4810
Columns 8 through 9
-3.8865
0.5425
>> a=conv(a1,a2) % Overall direct form denominator
a =
Columns 1 through 7
1.0000
0.9000
0.5000
0.0800
0.1400
Columns 8 through 11
-0.2890
-0.1820
-0.0100
0.0720
>> [b0,Bc,Ac]=dir2cas(b,a) % Overall cascade form
b0 =
14.0000
Bc =
1.0000
1.8836
1.1328
1.0000
-0.6915
0.6719
1.0000
2.0776
0.8666
1.0000
0
0
1.0000
-0.5990
0.0588
Ac =
1.0000
1.0000
0.9000
1.0000
0.5000
0.5000
1.0000
-1.0000
0.8000
1.0000
1.5704
0.6105
1.0000
-1.1704
0.3276
>> [C0,Bp,Ap]=dir2par(b,a) % Overall parallel form
C0 = []
Bp =
-20.4201
-1.6000
24.1602
5.1448
2.4570
3.3774
-0.8101
-0.2382
8.6129
-4.0439
Ap =
1.0000
1.0000
0.9000
1.0000
0.5000
0.5000
1.0000
-1.0000
0.8000
1.0000
1.5704
0.6105
1.0000
-1.1704
0.3276
200
Chapter 6
-0.7750
0.0500
-0.2000
11.6605
-5.7215
0.3530
-0.2440
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
This example shows that by using the MATLAB functions developed in this
section, we can probe and construct a wide variety of structures.
FIR FILTER STRUCTURES
A finite-duration impulse response filter has a system function of the form
H(z) = b0 + b1 z −1 + · · · + bM −1 z 1−M =
M
−1
bn z −n
(6.5)
n=0
Hence the impulse response h(n) is
b , 0≤n≤M −1
h(n) = n
0, else
(6.6)
and the difference equation representation is
y(n) = b0 x(n) + b1 x(n − 1) + · · · + bM −1 x(n − M + 1)
(6.7)
which is a linear convolution of finite support.
The order of the filter is M − 1, while the length of the filter (which
is equal to the number of coefficients) is M . The FIR filter structures are
always stable, and they are relatively simple compared to IIR structures.
Furthermore, FIR filters can be designed to have a linear-phase response,
which is desirable in some applications.
We will consider the following four structures:
• Direct form: In this form the difference equation (6.7) is implemented
directly as given.
• Cascade form: In this form the system function H(z) in (6.5) is factored into second-order factors, which are then implemented in a cascade connection.
• Linear-phase form: When an FIR filter has a linear phase response,
its impulse response exhibits certain symmetry conditions. In this form
we exploit these symmetry relations to reduce multiplications by about
half.
• Frequency sampling form: This structure is based on the DFT of
the impulse response h(n) and leads to a parallel structure. It is also
suitable for a design technique based on the sampling of frequency
response H ejω .
We will briefly describe the above four forms along with some examples. The MATLAB function dir2cas developed in the previous section
is also applicable for the cascade form.
FIR Filter Structures
201
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.10
DIRECT FORM
Direct form FIR structure
The difference equation (6.7) is implemented as a tapped delay line since
there are no feedback paths. Let M = 5 (i.e., a fourth-order FIR filter);
then
y(n) = b0 x(n) + b1 x(n − 1) + b2 x(n − 2) + b3 x(n − 3) + b4 x(n − 4)
The direct form structure is given in Figure 6.10. Note that since the
denominator is equal to unity, there is only one direct form structure.
MATLAB
IMPLEMENTATION
In MATLAB the direct form FIR structure is described by the row vector
b containing the {bn } coefficients. The structure is implemented by the
filter function, in which the vector a is set to the scalar value 1 as
discussed in Chapter 2.
CASCADE
FORM
This form is similar to that of the IIR form. The system function H(z)
is converted into products of second-order sections with real coefficients.
These sections are implemented in direct form and the entire filter as a
cascade of second-order sections. From (6.5)
H(z) = b0 + b1 z −1 + · · · + bM −1 z −M +1
b1
bM −1 −M +1
= b0 1 + z −1 + · · · +
z
b0
b0
= b0
K
(6.8)
1 + Bk,1 z −1 + Bk,2 z −2
k=1
where K is equal to M
2 , and Bk,1 and Bk,2 are real numbers representing
the coefficients of second-order sections. For M = 7 the cascade form is
shown in Figure 6.11.
FIGURE 6.11
202
Cascade form FIR structure
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB
IMPLEMENTATION
Although it is possible to develop a new MATLAB function for the FIR
cascade form, we will use our dir2cas function by setting the denominator
vector a equal to 1. Similarly, cas2dir can be used to obtain the direct
form from the cascade form.
LINEAR-PHASE
FORM
For frequency-selective filters (e.g., lowpass filters) it is generally desirable
to have a phase response that is a linear function of frequency; that is, we
want
H(ejω ) = β − αω,
−π < ω ≤ π
(6.9)
where β = 0 or ±π/2 and α is a constant. For a causal FIR filter with
impulse response over [0, M − 1] interval, the linear-phase condition (6.9)
imposes the following symmetry conditions on the impulse response h(n)
(See Problem P6.16):
h(n) = h(M − 1 − n);
h(n) = −h(M − 1 − n);
β = 0, α =
M −1
, 0≤n≤M −1
2
β = ±π/2, α =
(6.10)
M −1
, 0 ≤ n ≤ M − 1 (6.11)
2
An impulse response that satisfies (6.10) is called a symmetric impulse
response, while that in (6.11) is called an antisymmetric impulse response.
These symmetry conditions can now be exploited in a structure called the
linear-phase form.
Consider the difference equation given in (6.7) with a symmetric impulse response in (6.10). We have
y(n) = b0 x(n) + b1 x(n − 1) + · · · + b1 x(n − M + 2) + b0 x(n − M + 1)
= b0 [x(n) + x(n − M + 1)] + b1 [x(n − 1) + x(n − M + 2)] + · · ·
The block diagram implementation of the above difference equation is
shown in Figure 6.12 for both odd and even M .
FIGURE 6.12
FIR Filter Structures
Linear phase form FIR structures (symmetric impulse response)
203
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Clearly, this structure requires 50% fewer multiplications than the direct form. A similar structure can be derived for an antisymmetric impulse
response.
MATLAB
IMPLEMENTATION
The linear-phase structure is essentially a direct form drawn differently
to save on multiplications. Hence in a MATLAB representation of the
linear-phase structure is equivalent to the direct form.
An FIR filter is given by the system function
EXAMPLE 6.4
H(z) = 1 + 16
1 −4
z + z −8
16
Determine and draw the direct, linear-phase, and cascade form structures.
a. Direct form: The difference equation is given by
y(n) = x(n) + 16.0625x(n − 4) + x(n − 8)
and the direct form structure is shown in Figure 6.13(a).
b. Linear-phase form: The difference equation can be written in the form
y(n) = [x(n) + x(n − 8)] + 16.0625x(n − 4)
and the resulting structure is shown in Figure 6.13(b).
c. Cascade form: We use the following MATLAB Script.
>> b=[1,0,0,0,16+1/16,0,0,0,1];
FIGURE 6.13
204
[b0,B,A] = dir2cas(b,1)
FIR filter structures in Example 6.4
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
b0 = 1
B =
1.0000
1.0000
1.0000
1.0000
A =
1
0
1
0
1
0
1
0
2.8284
0.7071
-0.7071
-2.8284
4.0000
0.2500
0.2500
4.0000
0
0
0
0
The cascade form structure is shown in Figure 6.13(c).
EXAMPLE 6.5
Solution
For the filter in Example 6.4 what would be the structure if we desire a cascade
form containing linear-phase components with real coefficients?
We are interested in cascade sections that have symmetry and real coefficients.
From the properties of linear-phase FIR filters (see Chapter 7), if such a filter
has an arbitrary zero at z = r θ, then there must be three other zeros at
(1/r) θ, r − θ, and (1/r) − θ to have real filter coefficients. We can now make
use of this property. First we will determine the zero locations of the given
eighth-order polynomial. Then we will group four zeros that satisfy the above
property to obtain one (fourth-order) linear-phase section. There are two such
sections, which we will connect in cascade.
MATLAB Script:
>> b=[1,0,0,0,16+1/16,0,0,0,1]; broots=roots(b)
broots =
-1.4142 + 1.4142i
-1.4142 - 1.4142i
1.4142 + 1.4142i
1.4142 - 1.4142i
-0.3536 + 0.3536i
-0.3536 - 0.3536i
0.3536 + 0.3536i
0.3536 - 0.3536i
>> B1=real(poly([broots(1),broots(2),broots(5),broots(6)]))
B1 =
1.0000
3.5355
6.2500
3.5355
1.0000
>> B2=real(poly([broots(3),broots(4),broots(7),broots(8)]))
B2 =
1.0000
-3.5355
6.2500
-3.5355
1.0000
The structure is shown in Figure 6.14.
FIR Filter Structures
205
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.14
FREQUENCY
SAMPLING
FORM
Cascade of FIR linear-phase elements
In this form we use the fact that the system function H (z) of an FIR
filter can be reconstructed from its samples on the unit circle. From our
discussions on the DFT in Chapter 5 we recall that these samples are in
fact the M -point DFT values {H (k) , 0 ≤ k ≤ M − 1} of the M -point
impulse response h (n). Therefore we have
H (z) = Z [h (n)] = Z [IDFT {H (k)}]
Using this procedure, we obtain [see (5.17) on page 129]
H (z) =
1 − z −M
M
M
−1
k=0
H (k)
−k −1
1 − WM
z
(6.12)
This shows that the DFT H (k), rather than the impulse response
h (n) (or the difference equation), is used in this structure. It is also interesting to note that the FIR filter described by (6.12) has a recursive
form similar to an IIR filter because (6.12) contains both poles and zeros.
−k
The resulting filter is an FIR filter since the poles at WM
are canceled
by the roots of
1 − z −M = 0
The system function in (6.12) leads to a parallel structure as shown in
Figure 6.15 for M = 4.
One problem with the structure in Figure 6.15 is that it requires a
complex arithmetic implementation. Since an FIR filter is almost always a
real-valued filter, it is possible to obtain an alternate realization in which
only real arithmetic is used. This realization is derived using the symmetry
−k
properties of the DFT and the WM
factor. Then (6.12) can be expressed
as (see Problem P6.19)
1 − z −M
H (z) =
M
206
L
k=1
H (0)
H (M/2)
2 |H (k)| Hk (z) +
+
1 − z −1
1 + z −1
Chapter 6
(6.13)
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.15
Frequency sampling structure for M = 4
where L = M2−1 for M odd, L = M
2 −1 for M even, and {Hk (z) ,
. . . , L} are second-order sections given by
Hk (z) =
cos [ H (k)] − z −1 cos
1 − 2z −1 cos
2πk
M
H (k) −
+ z −2
2πk
M
k = 1,
(6.14)
Note that the DFT samples H (0) and H (M/2) are real-valued and that
the third term on the right-hand side of (6.13) is absent if M is odd. Using
(6.13) and (6.14), we show a frequency sampling structure in Figure 6.16
for M = 4 containing real coefficients.
FIGURE 6.16
FIR Filter Structures
Frequency sampling structure for M = 4 with real coefficients
207
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB
IMPLEMENTATION
Given the impulse response h (n) or the DFT H(k), we have to determine
the coefficients in (6.13) and (6.14). The following MATLAB function,
dir2fs, converts a direct form (h (n) values) to the frequency sampling
form by directly implementing (6.13) and (6.14).
function [C,B,A] = dir2fs(h)
% Direct form to Frequency Sampling form conversion
% ------------------------------------------------% [C,B,A] = dir2fs(h)
% C = Row vector containing gains for parallel sections
% B = Matrix containing numerator coefficients arranged in rows
% A = Matrix containing denominator coefficients arranged in rows
% h = impulse response vector of an FIR filter
%
M = length(h); H = fft(h,M);
magH = abs(H); phaH = angle(H)’;
% check even or odd M
if (M == 2*floor(M/2))
L = M/2-1;
% M is even
A1 = [1,-1,0;1,1,0]; C1 = [real(H(1)),real(H(L+2))];
else
L = (M-1)/2; % M is odd
A1 = [1,-1,0]; C1 = [real(H(1))];
end
k = [1:L]’;
% initialize B and A arrays
B = zeros(L,2); A = ones(L,3);
% compute denominator coefficients
A(1:L,2) = -2*cos(2*pi*k/M); A = [A;A1];
% compute numerator coefficients
B(1:L,1) = cos(phaH(2:L+1));
B(1:L,2) = -cos(phaH(2:L+1)-(2*pi*k/M));
% compute gain coefficients
C = [2*magH(2:L+1),C1]’;
In the above function the impulse response values are supplied
through the h array. After conversion, the C array contains the gain
values for each parallel section. The gain values for the second-order parallel sections are given first, followed by H (0) and H (M/2) (if M is even).
The B matrix contains the numerator coefficients, which are arranged in
length-2 row vectors for each second-order section. The A matrix contains
the denominator coefficients, which are arranged in length-3 row vectors
for the second-order sections corresponding to those in B, followed by the
coefficients for the first-order sections.
208
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
A practical problem with the structure in Figure 6.16 is that it has
poles on the unit circle, which makes this filter critically unstable. If the
filter is not excited by one of the pole frequencies, then the output is
bounded. We can avoid this problem by sampling H (z) on a circle |z| = r,
where the radius r is very close to one but is less than one (e.g., r = 0.99),
which results in
H (z) =
M −1
H (k)
1 − rM z −M ;
−k −k
M
1 − rWM
z
k=0
H (k) = H rej2πk/M
(6.15)
Now approximating H rej2πk/M ≈ H ej2πk/M for r ≈ 1, we can obtain
a stable structure similar to the one in Figure 6.16 containing real values.
This is explored in Problem P6.20.
EXAMPLE 6.6
Solution
Let h (n) = 19 {1, 2, 3, 2, 1}. Determine and draw the frequency sampling form.
↑
MATLAB Script:
>> h = [1,2,3,2,1]/9;
C =
0.5818
0.0849
1.0000
B =
-0.8090
0.8090
0.3090
-0.3090
A =
1.0000
-0.6180
1.0000
1.6180
1.0000
-1.0000
[C,B,A] = dir2fs(h)
1.0000
1.0000
0
Since M = 5 is odd, there is only one first-order section. Hence
1 − z −5
−0.809 + 0.809z −1
H (z) =
0.5818
5
1 − 0.618z −1 + z −2
0.309 − 0.309z −1
1
+ 0.0848
+
1 + 1.618z −1 + z −2
1 − z −1
The frequency sampling form is shown in Figure 6.17.
FIR Filter Structures
209
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.17
EXAMPLE 6.7
Frequency sampling structure in Example 6.6
The frequency samples of a 32-point linear-phase FIR filter are given by
1,
0.5,
0,
|H (k)| =
k = 0, 1, 2
k=3
k = 4, 5, . . . , 15
Determine its frequency sampling form, and compare its computational complexity with the linear-phase form.
Solution
In this example since the samples of the DFT H (k) are given, we could use
(6.13) and (6.14) directly to determine the structure. However, we will use the
dir2fs function for which we will have to determine the impulse response h (n).
Using the symmetry property and the linear-phase constraint, we assemble the
DFT H (k) as
H (k) = |H (k)| ej
H(k)
,
k = 0, 1, . . . , 31
|H (k)| = |H (32 − k)| , k = 1, 2, . . . , 31; H (0) = 1
31 2π
H (k) = −
k = − H (32 − k) , k = 0, 1, . . . , 31
2 32
Now the IDFT of H (k) will result in the desired impulse response.
MATLAB Script:
>>
>>
>>
>>
>>
210
M = 32; alpha = (M-1)/2;
magHk = [1,1,1,0.5,zeros(1,25),0.5,1,1];
k1 = 0:15; k2 = 16:M-1;
angHk = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = magHk.*exp(j*angHk); h = real(ifft(H,M)); [C,B,A] = dir2fs(h)
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
C =
2.0000
2.0000
1.0000
0.0000
0.0000
0.0000
0.0000
0
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
1.0000
0
B =
-0.9952
0.9808
-0.9569
-0.8944
0.9794
0.8265
-0.6754
1.0000
0.6866
0.5191
-0.4430
-0.8944
-0.2766
0.9343
-0.9077
0.9952
-0.9808
0.9569
0.3162
-0.7121
0.2038
0.8551
0.0000
-0.5792
0.9883
0.4993
-0.3162
0.3039
0.9996
-0.8084
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
-1.9616
-1.8478
-1.6629
-1.4142
-1.1111
-0.7654
-0.3902
0.0000
0.3902
0.7654
1.1111
1.4142
1.6629
A =
FIR Filter Structures
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
211
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1.0000
1.0000
1.0000
1.0000
1.8478
1.9616
-1.0000
1.0000
1.0000
1.0000
0
0
Note that only four gain coefficients are nonzero. Hence the frequency sampling
form is

−32
H (z) =
1−z
32



2
−0.9952 + 0.9952z −1
0.9808 − 0.9808z −1
+2
+
−1
−2
1 − 1.9616z + z
1 − 1.8478z −1 + z −2


−0.9569 + 0.9569z −1
1
+
1 − 1.6629z −1 + z −2
1 − z −1
To determine the computational complexity, note that since H (0) = 1, the firstorder section requires no multiplication, while the three second-order sections
require three multiplications each for a total of nine multiplications per output
sample. The total number of additions is 13. To implement the linear-phase
structure would require 16 multiplications and 31 additions per output sample.
Therefore the frequency sampling structure of this FIR filter is more efficient
than the linear-phase structure.
LATTICE FILTER STRUCTURES
The lattice filter is extensively used in digital speech processing and in
the implementation of adaptive filters. It is a preferred form of realization
over other FIR or IIR filter structures because in speech analysis and
in speech synthesis the small number of coefficients allows a large number
of formants to be modeled in real time. The all-zero lattice is the FIR
filter representation of the lattice filter, while the lattice ladder is the IIR
filter representation.
ALL-ZERO
LATTICE
FILTERS
An FIR filter of length M (or order M − 1) has a lattice structure with
M − 1 stages as shown in Figure 6.18. Each stage of the filter has an input
and output that are related by the order-recursive equations [22]:
fm (n) = fm−1 (n) + Km gm−1 (n − 1),
m = 1, 2, . . . , M − 1
gm (n) = Km fm−1 (n) + gm−1 (n − 1),
m = 1, 2, . . . , M − 1
(6.16)
where the parameters Km , m = 1, 2, . . . , M − 1, called the reflection
coefficients, are the lattice filter coefficients. If the initial values of fm (n)
and gm (m) are both the scaled value (scaled by K0 ) of the filter input
x(n), then the output of the (M − 1) stage lattice filter corresponds to
212
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.18
All-zero lattice filter
the output of an (M − 1) order FIR filter; that is,
f0 (n) = g0 (n) = K0 x(n)
(6.17)
y(n) = fM −1 (n)
If the FIR filter is given by the direct form
H(z) =
M
−1
bm z
−m
= b0
1+
m=0
M
−1
m=1
bm −m
z
b0
(6.18)
and if we denote the polynomial AM −1 (z) by
AM −1 (z) =
1+
M
−1
αM −1 (m)z
−m
;
(6.19)
m=1
αM −1 (m) =
bm
, m = 1, . . . , M − 1
b0
then the lattice filter coefficients {Km } can be obtained by the following
recursive algorithm [19]:
K0 = b0
KM −1 = αM −1 (M − 1)
Jm (z) = z −m Am z −1 ;
m = M − 1, . . . , 1
Am (z) − Km Jm (z)
, m = M − 1, . . . , 1
Am−1 (z) =
2
1 − Km
Km = αm (m),
(6.20)
m = M − 2, . . . , 1
Note that the above algorithm will fail if |Km | = 1 for any m = 1, . . . ,
M − 1. Clearly, this condition is satisfied by linear-phase FIR filters since
bM −1 =1
b0 = |bM −1 | ⇒ |KM −1 | = |αM −1 (M − 1)| = b0 Lattice Filter Structures
213
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Therefore linear-phase FIR filters cannot be implemented using lattice
structures.
MATLAB
IMPLEMENTATION
Given the coefficients {bn } of the direct form, we can obtain the lattice
filter coefficients {Km } using (6.20). This is done by the MATLAB function dir2latc given below. Note that the equation to compute Jm (z)
implies that the polynomial Jm (z) is a fliplr operation on the Am (z)
polynomial.
function [K] = dir2latc(b)
% FIR Direct form to All-Zero Lattice form Conversion
% --------------------------------------------------% [K] = dir2latc(b)
% K = Lattice filter coefficients (reflection coefficients)
% b = FIR direct form coefficients (impulse response)
%
M = length(b); K = zeros(1,M); b1 = b(1);
if b1 == 0
error(’b(1) is equal to zero’)
end
K(1) = b1; A = b/b1;
for m=M:-1:2
K(m) = A(m); J = fliplr(A);
A = (A-K(m)*J)/(1-K(m)*K(m)); A = A(1:m-1);
end
The lattice filter is implemented using (6.16) and (6.17), which is done by
a latcfilt function, which is given below.
function [y] = latcfilt(K,x)
% LATTICE form realization of FIR filters
% --------------------------------------% y = latcfilt(K,x)
%
y = output sequence
%
K = LATTICE filter (reflection) coefficient array
%
x = input sequence
%
Nx = length(x)-1; x = K(1)*x;
M = length(K)-1; K = K(2:M+1); fg = [x; [0 x(1:Nx)]];
for m = 1:M
fg = [1,K(m);K(m),1]*fg;
fg(2,:) = [0 fg(2,1:Nx)];
end
y = fg(1,:);
214
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The equations (6.20) can also be used to determine the direct form
coefficients {bm } from the lattice filter coefficients {Km } using a recursive
procedure [22]:
A0 (z) = J0 (z) = 1
Am (z) = Am−1 (z) + Km z −1 Jm−1 (z) ,
m = 1, 2, . . . , M − 1
Jm (z) = z −m Am z −1 ,
m = 1, 2, . . . , M − 1
bm = K0 αM −1 (m),
(6.21)
m = 0, 1, . . . , M − 1
The MATLAB function latc2dir given below implements (6.21).
Note that the product Km z −1 Jm−1 (z) is obtained by convolving the two
corresponding arrays, while the polynomial Jm (z) is obtained by using a
fliplr operation on the Am (z) polynomial.
function [b] = latc2dir(K)
% All-Zero Lattice form to FIR Direct form Conversion
% --------------------------------------------------% [b] = latc2dir(K)
% b = FIR direct form coefficients (impulse response)
% K = Lattice filter coefficients (reflection coefficients)
%
M = length(K); J = 1; A = 1;
for m=2:1:M
A = [A,0]+conv([0,K(m)],J); J = fliplr(A);
end
b=A*K(1);
EXAMPLE 6.8
An FIR filter is given by the difference equation
y(n) = 2x(n) +
13
5
2
x(n − 1) + x(n − 2) + x(n − 3)
12
4
3
Determine its lattice form.
Solution
MATLAB Script:
>> b=[2, 13/12, 5/4, 2/3]; K=dir2latc(b)
K =
2.0000
0.2500
0.5000
0.3333
Lattice Filter Structures
215
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.19
FIR filter structures in Example 6.8: (a) Direct form (b) Lattice
form
Hence
K0 = 2, K1 =
1
1
1
, K2 = , K3 =
4
2
3
The direct form and the lattice form structures are shown in Figure 6.19. To
check that our lattice structure is correct, let us compute the impulse response
of the filter using both forms.
>> [x,n] = impseq(0,0,3]; format long
hdirect =
2.00000000000000
1.08333333333333
>> hlattice=latcfilt(K,delta)
hlattice =
2.00000000000000
1.08333333333333
hdirect=filter(b,1,delta)
1.25000000000000
0.66666666666667
1.25000000000000
0.66666666666667
ALL-POLE
LATTICE
FILTERS
A lattice structure for an IIR filter is restricted to an all-pole system
function. It can be developed from an FIR lattice structure. Let an allpole system function be given by
1
H(z) =
1+
N
(6.22)
aN (m)z −m
m=1
which from (6.19) is equal to H(z) = 1/AN (z). Clearly, it is an inverse
system to the FIR lattice of Figure 6.18 (except for factor b0 ). This IIR
filter of order N has a lattice structure with N stages as shown in Figure
6.20. Each stage of the filter has an input and output that are related by
216
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.20
All-pole lattice filter
the order-recursive equations [22]:
fN (n) = x(n)
fm−1 (n) = fm (n) − Km gm−1 (n − 1),
m = N, N − 1, . . . , 1
gm (n) = Km fm−1 (n) + gm−1 (n − 1), m = N, N − 1, . . . , 1
(6.23)
y(n) = f0 (n) = g0 (n)
where the parameters Km , m = 1, 2, . . . , M − 1, are the reflection coefficients of the all-pole lattice and are obtained from (6.20) except for K0 ,
which is equal to 1.
MATLAB
IMPLEMENTATION
Since the IIR lattice coefficients are derived from the same (6.20) procedure used for an FIR lattice filter, we can use the dir2latc function in
MATLAB. Care must be taken to ignore the K0 coefficient in the K array.
Similarly, the latc2dir function can be used to convert the lattice {Km }
coefficients into the direct form {aN (m)} provided that K0 = 1 is used as
the first element of the K array. The implementation of an IIR lattice is
given by (6.23), and we will discuss it in the next section.
Consider an all-pole IIR filter given by
EXAMPLE 6.9
H(z) =
1+
13 −1
z
24
1
+ 58 z −2 + 13 z −3
Determine its lattice structure.
Solution
MATLAB Script:
>> a=[1, 13/24, 5/8, 1/3]; K=dir2latc(b)
K =
1.0000
0.2500
0.5000
0.3333
Hence
K1 =
Lattice Filter Structures
1
,
4
K2 =
1
,
2
and
K3 =
1
3
217
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.21
IIR filter structures in Example 6.9: (a) Direct form (b) Lattice
form
The direct form and the lattice form structures of this IIR filter are shown in
Figure 6.21.
LATTICELADDER
FILTERS
A general IIR filter containing both poles and zeros can be realized as
a lattice-type structure by using an all-pole lattice as the basic building
block. Consider an IIR filter with system function
M
H(z) =
bM (k)z
k=0
N
−k
aN (k)z −k
1+
=
BM (z)
AN (z)
(6.24)
k=1
where, without loss of generality, we assume that N ≥ M . A latticetype structure can be constructed by first realizing an all-pole lattice
with coefficients Km , 1 ≤ m ≤ N for the denominator of (6.24), and
then adding a ladder part by taking the output as a weighted linear
combination of {gm (n)} as shown in Figure 6.22 for M = N . The result
FIGURE 6.22
218
Lattice-ladder structure for realizing a pole-zero IIR filter
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
is a pole-zero IIR filter that has the lattice-ladder structure. Its output is
given by
M
y(n) =
Cm gm (n)
(6.25)
m=0
where {Cm } are called the ladder coefficients that determine the zeros of
the system function H(z). It can be shown [22] that {Cm } are given by
BM (z) =
M
Cm Jm (z)
(6.26)
m=0
where Jm (z) is the polynomial in (6.20). From (6.26) one can obtain a
recursive relation
Bm (z) = Bm−1 (z) + Cm Jm (z);
m = 0, 2, . . . , M
or equivalently,
Cm = bm +
M
Ci αi (i − m);
m = M, M − 1, . . . , 0
(6.27)
i=m+1
from the definitions of Bm (z) and Am (z).
MATLAB
IMPLEMENTATION
To obtain a lattice-ladder structure for a general rational IIR filter, we can
first obtain the lattice coefficients {Km } from AN (z) using the recursion
(6.20). Then we can solve (6.27) recursively for the ladder coefficients
{Cm } to realize the numerator BM (z). This is done in the MATLAB
function dir2ladr given below. It can also be used to determine the allpole lattice parameters when the array b is set to b=[1].
function [K,C] = dir2ladr(b,a)
% IIR Direct form to pole-zero Lattice/Ladder form Conversion
% ----------------------------------------------------------% [K,C] = dir2ladr(b,a)
% K = Lattice coefficients (reflection coefficients), [K1,...,KN]
% C = Ladder Coefficients, [C0,...,CN]
% b = Numerator polynomial coefficients (deg <= Num deg)
% a = Denominator polynomial coefficients
%
a1 = a(1); a = a/a1; b = b/a1;
M = length(b); N = length(a);
if M > N
error(’
*** length of b must be <= length of a ***’)
end
Lattice Filter Structures
219
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
b = [b, zeros(1,N-M)]; K = zeros(1,N-1);
A = zeros(N-1,N-1); C = b;
for m = N-1:-1:1
A(m,1:m) = -a(2:m+1)*C(m+1);
K(m) = a(m+1); J = fliplr(a);
a = (a-K(m)*J)/(1-K(m)*K(m)); a = a(1:m);
C(m) = b(m) + sum(diag(A(m:N-1,1:N-m)));
end
Note: To use this function, N ≥ M . If M > N , then the numerator
AN (z) should be divided into the denominator BM (z) using the deconv
function to obtain a proper rational part and a polynomial part. The
proper rational part can be implemented using a lattice-ladder structure,
while the polynomial part is implemented using a direct structure.
To convert a lattice-ladder form into a direct form, we first use the
recursive procedure in (6.21) on {Km } coefficients to determine {aN (k)}
and then solve (6.27) recursively to obtain {bM (k)}. This is done in the
MATLAB function ladr2dir given below.
function [b,a] = ladr2dir(K,C)
% Lattice/Ladder form to IIR Direct form Conversion
% ------------------------------------------------% [b,a] = ladr2dir(K,C)
% b = numerator polynomial coefficients
% a = denominator polymonial coefficients
% K = Lattice coefficients (reflection coefficients)
% C = Ladder coefficients
%
N = length(K); M = length(C);
C = [C, zeros(1,N-M+1)];
J = 1; a = 1; A = zeros(N,N);
for m=1:1:N
a = [a,0]+conv([0,K(m)],J);
A(m,1:m) = -a(2:m+1); J = fliplr(a);
end
b(N+1) = C(N+1);
for m = N:-1:1
A(m,1:m) = A(m,1:m)*C(m+1);
b(m) = C(m) - sum(diag(A(m:N,1:N-m+1)));
end
The lattice-ladder filter is implemented using (6.23) and (6.25). This is
done in the MATLAB function ladrfilt, which is given below. It should
be noted that due to the recursive nature of this implementation along
with the feedback loops, this MATLAB function is neither an elegant
220
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
nor an efficient method of implementation. It is not possible to exploit
MATLAB’s inherent parallel processing capabilities in implementing this
lattice-ladder structure.
function [y] = ladrfilt(K,C,x)
% LATTICE/LADDER form realization of IIR filters
% ---------------------------------------------% [y] = ladrfilt(K,C,x)
% y = output sequence
% K = LATTICE (reflection) coefficient array
% C = LADDER coefficient array
% x = input sequence
%
Nx = length(x); y = zeros(1,Nx);
N = length(C); f = zeros(N,Nx); g = zeros(N,Nx+1);
f(N,:) = x;
for n = 2:1:Nx+1
for m = N:-1:2
f(m-1,n-1) = f(m,n-1) - K(m-1)*g(m-1,n-1);
g(m,n) = K(m-1)*f(m-1,n-1) + g(m-1,n-1);
end
g(1,n) = f(1,n-1);
end
y = C*g(:,2:Nx+1);
EXAMPLE 6.10
Convert the following pole-zero IIR filter into a lattice-ladder structure.
H(z) =
Solution
1 + 2z −1 + 2z −2 + z −3
1 + 13
z −1 + 58 z −2 + 13 z −3
24
MATLAB Script:
>> b = [1,2,2,1] a = [1, 13/24, 5/8, 1/3];
K =
0.2500
0.5000
0.3333
C =
-0.2695
0.8281
1.4583
1.0000
[K,C] = dir2ladrc(b)
Hence
K1 =
1
1
1
, K2 = , K3 = ;
4
2
3
and
C0 = −0.2695, C1 = 0.8281, C2 = 1.4583, C3 = 1
Lattice Filter Structures
221
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 6.23
IIR filter structures in Example 6.10: (a) Direct form (b) Lattice-
ladder form
The resulting direct form and the lattice-ladder form structures are shown in
Figure 6.23. To check that our lattice-ladder structure is correct, let us compute
the first 8 samples of its impulse response using both forms.
>> [x,n]=impseq(0,0,7) format long hdirect = filter(b,a,x)
hdirect =
Columns 1 through 4
1.00000000000000
1.45833333333333
0.58506944444444 -0.56170428240741
Columns 5 through 8
-0.54752302758488
0.45261700163162
0.28426911049255 -0.25435705167494
>> hladder = ladrfilt(K,C,x)
hladder =
Columns 1 through 4
1.00000000000000
1.45833333333333
0.58506944444444 -0.56170428240741
Columns 5 through 8
-0.54752302758488
0.45261700163162
0.28426911049255 -0.25435705167494
Finally, we note that the SP toolbox also provides functions similar to
the ones discussed in this section—the complementary functions, tf2latc
and latc2tf, compute all-pole lattice, all-zero lattice, and lattice-ladder
structure coefficients, and vice versa. Similarly, the function latcfilt
(the same name as the book function) implements the all-zero lattice
structure. The SP toolbox does not provide a function to implement the
lattice-ladder structure.
222
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
PROBLEMS
P6.1 Draw direct form I block diagram structures for each of the following LTI systems with
input node x(n) and output node y(n).
1. y(n) = x(n) + 2 x(n − 1) + 3x(n − 2)
1
2. H(z) =
1 − 1.7z −1 + 1.53z −2 − 0.648z −3
3. y(n) = 1.7 y(n − 1) − 1.36 y(n − 2) + 0.576 y(n − 3) + x(n)
4. y(n) = 1.6 y(n − 1) + 0.64 y(n − 2) + x(n) + 2 x(n − 1) + x(n − 2)
5. H(z) =
1 − 3z −1 + 3z −2 + z −3
1 + 0.2z −1 − 0.14z −2 + 0.44z −3
P6.2 Two block diagrams are shown in Figure P6.1. Answer the following for each structure.
1. Determine the system function H(z) = Y (z)/X(z).
2. Is the structure canonical (i.e., with the least number of delays)? If not, draw a
canonical structure.
3. Determine the value of K so that H(ej 0 ) = 1.
P6.3 Consider the LTI system described by
y(n) = a y(n − 1) + b x(n)
(6.28)
1. Draw a block diagram of the above system with input node x(n) and output node y(n).
2. Now perform the following two operations on the structure drawn in part 1: (i) reverse
all arrow directions and (ii) interchange the input node with the output node. Notice
that the branch node becomes the adder node and vice versa. Redraw the block diagram
so that input node is on the left side and the output node is on the right side. This is the
transposed block diagram.
3. Determine the difference equation representation of your transposed structure in part 2
above and verify that it is the same equation as (6.28).
P6.4 Consider the LTI system given by
H(z) =
1 − 2.818z −1 + 3.97z −2 − 2.8180z −3 + z −4
1 − 2.536z −1 + 3.215z −2 − 2.054z −3 + 0.6560z −4
(6.29)
z −1
2
x (n)
K
y (n)
z −1
0.5
x (n)
z −1
K
−0.9
z −1
(i)
FIGURE P6.1
Problems
2
z −1
0.5
y (n )
1.8
z −1
(ii)
Block diagrams for Problem 6.2
223
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1. Draw the normal direct form I structure block diagram.
2. Draw the transposed direct form I structure block diagram.
3. Draw the normal direct form II structure block diagram. Observe that it looks very
similar to that in part 2.
4. Draw the transposed direct form II structure block diagram. Observe that it looks very
similar to that in part 1.
P6.5 Consider the LTI system given in Problem P6.4.
1.
2.
3.
4.
Draw
Draw
Draw
Draw
a
a
a
a
cascade structure containing second-order normal direct from II sections.
cascade structure containing second-order transposed direct from II sections.
parallel structure containing second-order normal direct from II sections.
parallel structure containing second-order transposed direct from II sections.
P6.6 A causal linear time-invariant system is described by
y(n) =
4
cos(0.1πk)x(n − k) +
k=0
5
(0.8)k sin(0.1πk)y(n − k)
=1
Determine and draw the block diagrams of the following structures. Compute the response
of the system to
x(n) = [1 + 2(−1)n ] ,
0 ≤ n ≤ 50
in each case, using the following structures.
1.
2.
3.
4.
5.
Normal direct form I
Transposed direct form II
Cascade form containing second-order normal direct form II sections
Parallel form containing second-order transposed direct form II sections
Lattice-ladder form
P6.7 An IIR filter is described by the following system function
H(z) = 2
1 + 0z −1 + z −2
1 − 0.8z −1 + 0.64z −2
+
2 − z −1
1 − 0.75z −1
+
1 + 2z −1 + z −2
1 + 0.81z −2
Determine and draw the following structures.
1.
2.
3.
4.
5.
Transposed direct form I
Normal direct form II
Cascade form containing transposed second-order direct form II sections
Parallel form containing normal second-order direct form II sections
Lattice-ladder form
P6.8 An IIR filter is described by the following system function
H(z) =
−14.75 − 12.9z −1
3 −2
1 − 78 z −1 + 32
z
+
24.5 + 26.82z −1
1 − z −1 + 12 z −2
1 + 2z −1 + z −2
1 + 0.81z −2
Determine and draw the following structures:
1. Normal direct form I
2. Normal direct form II
3. Cascade form containing transposed second-order direct form II sections
224
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x(n)
−1/2
1/2
−2/3
0.56
2/3
−0.56
z −1
z −1
z −1
y(n)
FIGURE P6.2
Structure for Problem 6.9
4. Parallel form containing transposed second-order direct form II sections
5. Lattice-ladder form
P6.9 Figure P6.2 describes a causal linear time-invariant system. Determine and draw the
following structures:
1.
2.
3.
4.
Direct form I
Direct form II
Cascade form containing second-order direct form II sections
Parallel form containing second-order direct form II sections
P6.10 A linear time-invariant system with system function
H(z) =
0.05 − 0.01z −1 − 0.13z −2 + 0.13z −4 + 0.01z −5 − 0.05z −6
1 − 0.77z −1 + 1.59z −2 − 0.88z −3 + 1.2z −4 − 0.35z −5 + 0.31z −6
is to be implemented using a flow graph of the form shown in Figure P6.3.
1. Fill in all the coefficients in the diagram.
2. Is your solution unique? Explain.
P6.11 A linear time-invariant system with system function
H(z) =
0.051 + 0.088z −1 + 0.06z −2 − 0.029z −3 − 0.069z −4 − 0.046z −5
1 − 1.34z −1 + 1.478z −2 − 0.789z −3 + 0.232z −4
is to be implemented using a flow graph of the form shown in Figure P6.4. Fill in all the
coefficients in the diagram.
x(n)
FIGURE P6.3
Problems
z −1
z −1
z −1
z −1
z −1
z −1
z −1
z −1
y (n)
Structure for Problem 6.10
225
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
z −1
z −1
z −1
x(n)
y (n)
z −1
z −1
FIGURE P6.4
Problem for Problem 6.11
P6.12 Consider the linear time-invariant system given in Problem P6.10.
H(z) =
0.05 − 0.01z −1 − 0.13z −2 + 0.13z −4 + 0.01z −5 − 0.05z −6
1 − 0.77z −1 + 1.59z −2 − 0.88z −3 + 1.2z −4 − 0.35z −5 + 0.31z −6
It is to be implemented using a flow graph of the form shown in Figure P6.5.
1. Fill in all the coefficients in the diagram.
2. Is your solution unique? Explain.
x(n)
z −1
z −1
z −1
z −1
y(n)
z −1
z −1
FIGURE P6.5
Structure for Problem 6.12
P6.13 The filter structure shown in Figure P6.6 contains a parallel connection of cascade sections.
Determine and draw the overall
1. direct form (normal) structure,
2. direct form (transposed) structure,
226
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
0.5
−1
−0.9
z −1
1
2
1
z −1
1.5
−0.8
z −1
3
z −1
1
3
y(n)
x(n)
−0.5
−0.5
0.4
FIGURE P6.6
z −1
z −1
2
−0.4
1
−0.4
z −1
−0.5
z −1
2
z −1
Structure for Problem 6.13
3. cascade form structure containing second-order sections,
4. parallel form structure containing second-order sections.
P6.14 In filter structure shown in Figure P6.7, systems H1 (z) and H2 (z) are subcomponents of a
larger system H(z). The system function H1 (z) is given in the parallel form
H1 (z) = 2 +
0.2 − 0.3z −1
0.4 + 0.5z −1
+
−1
−2
1 + 0.9z + 0.9z
1 + −0.8z −1 + 0.8z −2
and the system function H2 (z) is given in the cascade form
H2 (z) =
2 + z −1 − z −2
1 + 1.7z −1 + 0.72z −2
3 + 4z −1 + 5z −2
1 − 1.5z −1 + 0.56z −2
1. Express H(z) as a rational function.
2. Draw the block diagram of H(z) as a cascade form structure.
3. Draw the block diagram of H(z) as a parallel form structure.
P6.15 The digital filter structure shown in Figure P6.8 is a cascade of two parallel sections and
corresponds to a 10th -order IIR digital filter system function
H(z) =
1 − 2.2z −2 + 1.6368z −4 − 0.48928z −6 + 5395456 × 10−8 z −8 − 147456 × 10−8 z −10
1 − 1.65z −2 + 0.8778z −4 − 0.17281z −6 + 1057221 × 10−8 z −8 − 893025 × 10−10 z −10
H(z)
H1(z)
y(n)
x(n)
H2(z)
FIGURE P6.7
Problems
Structure for Problem 6.14
227
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4.0635
4.0635
−0.0793
−1.6
−0.63
−2.8255
z −1
z −1
−0.0815
0.7747
0.4
z −1
z −1
−0.03
−0.5502
x(n)
−0.8
−0.15
−0.2076
−0.2245
1.2
0.1319
z −1
z −1
−0.35
−0.0304
−2.4609
−0.1
y (n)
z −1
z −1
z −1
z −1
−0.9
Structure for Problem 6.15
FIGURE P6.8
1. Due to an error in labeling, two of the multiplier coefficients (rounded to 4 decimals) in
this structure have incorrect values. Locate these two multipliers and determine their
correct values.
2. Determine and draw an overall cascade structure containing second-order section and
which contains the least number of multipliers.
P6.16 As described in this chapter, a linear-phase FIR filter is obtained by requiring certain
symmetry conditions on its impulse responses.
1. In the case of symmetrical impulse response, we have h(n) = h(M − 1 − n),
0 ≤ n ≤ M − 1. Show that the resulting phase response is linear in ω and is given by
H ejω = −
M −1
ω,
2
−π < ω ≤ π
2. Draw the linear-phase structures for the above form when M = 5 and M = 6.
3. In the case of antisymmetrical impulse response, we have h(n) = −h(M − 1 − n),
0 ≤ n ≤ M − 1. Show that the resulting phase response is given by
H ejω = ±
π
−
2
M −1
ω,
2
−π < ω ≤ π
4. Draw the linear-phase structures for the above form when M = 5 and M = 6.
P6.17 An FIR filter is described by the difference equation
y(n) =
6
e−0.9|k−3| x(n − k)
k=0
Determine and draw the block diagrams of the following structures.
228
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1.
2.
3.
4.
Direct form
Linear-phase form
Cascade form
Frequency sampling form
P6.18 A linear time-invariant system is given by the system function
H(z) = 2 + 3z −1 + 5z −2 − 3z −3 + 4z −5 + 8z −7 − 7z −8 + 4z −9
Determine and draw the block diagrams of the following structures.
1.
2.
3.
4.
Direct form
Cascade form
Lattice form
Frequency sampling form
P6.19 Using the conjugate symmetry property of the DFT
H (k) =
H (0) ,
H ∗ (M − k) ,
k=0
k = 1, . . . , M − 1
−k
and the conjugate symmetry property of the WM
factor show that (6.12) can be put in the
form (6.13) and (6.14) for real FIR filters.
P6.20 To avoid poles on the unit circle in the frequency sampling structure, one samples H (z) at
zk = rej2πk/M , k = 0, . . . , M − 1 where r ≈ 1(but < 1) as discussed in Section 6.3.
1. Using
H rej2πk/M ≈ H (k) ,
show that the frequency sampling structure is given by
1 − (rz)−M
H (z) =
M
L
k=1
H (0)
H (M/2)
2 |H (k)| Hk (z) +
+
1 − rz −1
1 + rz −1
where
Hk (z) =
cos [ H (k)] − rz −1 cos
1 − 2rz −1 cos
2πk
M
H (k) −
+ z −2
2πk
M
,
k = 1, . . . , L
and M is even.
2. Modify the MATLAB function dir2fs (which was developed in Section 6.3) to
implement the above frequency sampling form. The format of this function should be
Problems
229
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
[C,B,A,rM] = dir2fs(h,r)
% Direct form to Frequency Sampling form conversion
% ------------------------------------------------% [C,B,A] = dir2fs(h)
% C = Row vector containing gains for parallel sections
% B = Matrix containing numerator coefficients arranged in rows
% A = Matrix containing denominator coefficients arranged in rows
% rM = r^M factor needed in the feedforward loop
% h = impulse response vector of an FIR filter
% r = radius of the circle over which samples are taken (r<1)
%
3. Determine the frequency sampling structure for the impulse response given in Example
6.6 using the above function.
P6.21 Determine the impulse response of an FIR filter with lattice parameters
K0 = 2,
K1 = 0.6,
K2 = 0.3,
K3 = 0.5,
K4 = 0.9
Draw the direct form and lattice form structures of the above filter.
P6.22 Consider the following system function of an FIR filter
H(z) = 1 − 4z −1 + 6.4z −2 − 5.12z −3 + 2.048z −4 − 0.32768z −5
1. Provide block diagram structures in the following form:
(a) Normal and transposed direct forms,
(b) Cascade of five first-order sections,
(c) Cascade of one first-order section and two second-order sections,
(d) Cascade of one second-order section and one third-order section, and
(e) Frequency-sampling structure with real coefficients.
2. The computational complexity of a digital filter structure can be given by the total
number of multiplications and the total number of two-input additions that are required
per output point. Assume that x(n) is real and that multiplication by 1 is not counted as
a multiplication. Compare the computational complexity of each of the above structures.
P6.23 A causal digital filter is described by the following zeros:
◦
z2 = 0.5 e−j60 ,
◦
z6 = 0.25 e−j30 ,
z1 = 0.5 ej60 ,
z5 = 0.25 ej30 ,
◦
◦
◦
z4 = 2 e−j60 ,
◦
z8 = 4 e−j30 ,
z3 = 2 ej60 ,
z7 = 4 ej30 ,
◦
◦
and poles: {pi }8i=1 = 0.
1.
2.
3.
4.
230
Determine the phase response of this filter and show that it is a linear-phase FIR filter.
Determine the impulse response of the filter.
Draw a block diagram of the filter structure in the direct form.
Draw a block diagram of the filter structure in the linear-phase form.
Chapter 6
DIGITAL FILTER STRUCTURES
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
7
FIR Filter
Design
We now turn our attention to the inverse problem of designing systems
from the given specifications. It is an important as well as a difficult
problem. In digital signal processing there are two important types of
systems. The first type of systems perform signal filtering in the time
domain and hence are called digital filters. The second type of systems
provide signal representation in the frequency domain and are called
spectrum analyzers. In Chapter 5 we described signal representations
using the DFT. In this and the next chapter we will study several basic
design algorithms for both FIR and IIR filters. These designs are mostly
of the frequency selective type; that is, we will design primarily multiband
lowpass, highpass, bandpass, and bandstop filters. In FIR filter design
we will also consider systems like differentiators or Hilbert transformers,
which, although not frequency-selective filters, nevertheless follow the
design techniques being considered. More sophisticated filter designs are
based on arbitrary frequency-domain specifications and require tools that
are beyond the scope of this book.
We first begin with some preliminary issues related to design philosophy and design specifications. These issues are applicable to both FIR
and IIR filter designs. We will then study FIR filter design algorithms in
the rest of this chapter. In Chapter 8 we will provide a similar treatment
for IIR filters.
231
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
PRELIMINARIES
The design of a digital filter is carried out in three steps:
• Specifications: Before we can design a filter, we must have some specifications. These specifications are determined by the applications.
• Approximations: Once the specifications are defined, we use various
concepts and mathematics that we studied so far to come up with a
filter description that approximates the given set of specifications. This
step is the topic of filter design.
• Implementation: The product of the above step is a filter description
in the form of either a difference equation, or a system function H(z),
or an impulse response h(n). From this description we implement the
filter in hardware or through software on a computer as we discussed
in Chapter 6.
In this and the next chapter we will discuss in detail only the second step,
which is the conversion of specifications into a filter description.
In many applications like speech or audio signal processing, digital
filters are used to implement frequency-selective operations. Therefore,
specifications are required in the frequency-domain in terms of the desired magnitude and phase response of the filter. Generally a linear phase
response in the passband is desirable. In the case of FIR filters, it is possible to have exact linear phase as we have seen in Chapter 6. In the case
of IIR filters a linear phase in the passband is not achievable. Hence we
will consider magnitude-only specifications.
The magnitude specifications are given in one of two ways. The first
approach is called absolute specifications, which provide a set of requirements on the magnitude response function |H(ejω )|. These specifications
are generally used for FIR filters. IIR filters are specified in a somewhat
different way, which we will discuss in Chapter 8. The second approach is
called relative specifications, which provide requirements in decibels (dB),
given by
|H(ejω )|
dB scale = −20 log10
≥0
|H(ejω )|max
This approach is the most popular one in practice and is used for both
FIR and IIR filters. To illustrate these specifications, we will consider a
lowpass filter design as an example.
ABSOLUTE
SPECIFICATIONS
232
A typical absolute specification of a lowpass filter is shown in Figure 7.1a,
in which
• band [0, ωp ] is called the passband, and δ1 is the tolerance (or ripple)
that we are willing to accept in the ideal passband response,
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1 + d1
1
1 − d1
|H (e jw)|
Passband
ripple
(a)
Stopband
ripple
Transition
band
d2
0
wp
0
ws
p
w
w
0
Decibels
Rp
As
(b)
FIGURE 7.1
FIR filter specifications: (a) Absolute (b) Relative
• band [ωs , π] is called the stopband, and δ2 is the corresponding tolerance
(or ripple), and
• band [ωp , ωs ] is called the transition band, and there are no restrictions
on the magnitude response in this band.
RELATIVE (DB)
SPECIFICATIONS
A typical absolute specification of a lowpass filter is shown in Figure 7.1b,
in which
• Rp is the passband ripple in dB, and
• As is the stopband attenuation in dB.
The parameters given in the above two specifications are obviously
related. Since |H(ejω )|max in absolute specifications is equal to (1 + δ1 ),
we have
1 − δ1
Rp = −20 log10
> 0 (≈ 0)
(7.1)
1 + δ1
and
δ2
As = −20 log10
> 0 ( 1)
(7.2)
1 + δ1
EXAMPLE 7.1
Solution
In a certain filter’s specifications the passband ripple is 0.25 dB, and the stopband attenuation is 50 dB. Determine δ1 and δ2 .
Using (7.1), we obtain
Rp = 0.25 = −20 log10
Preliminaries
1 − δ1
⇒ δ1 = 0.0144
1 + δ1
233
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Using (7.2), we obtain
δ2
δ2
= −20 log10
⇒ δ2 = 0.0032
1 + δ1
1 + 0.0144
Given the passband tolerance δ1 = 0.01 and the stopband tolerance δ2 = 0.001,
determine the passband ripple Rp and the stopband attenuation As .
As = 50 = −20 log10
EXAMPLE 7.2
Solution
From (7.1) the passband ripple is
Rp = −20 log10
1 − δ1
= 0.1737 dB
1 + δ1
and from (7.2) the stopband attenuation is
As = −20 log10
δ2
= 60 dB
1 + δ1
Problem P7.1 develops MATLAB functions to convert one set of specifications into another.
The above specifications were given for a lowpass filter. Similar specifications can also be given for other types of frequency-selective filters,
such as highpass or bandpass. However, the most important design parameters are frequency-band tolerances (or ripples) and band-edge frequencies.
Whether the given band is a passband or a stopband is a relatively minor
issue. Therefore in describing design techniques, we will concentrate on a
lowpass filter. In the next chapter we will discuss how to transform a lowpass filter into other types of frequency-selective filters. Hence it makes
more sense to develop techniques for a lowpass filter so that we can compare these techniques. However, we will also provide examples of other
types of filters. In light of this discussion our design goal is the following.
Problem Statement Design a lowpass filter (i.e., obtain its system
function H(z) or its difference equation) that has a passband [0, ωp ] with
tolerance δ1 (or Rp in dB) and a stopband [ωs , π] with tolerance δ2 (or
As in dB).
In this chapter we turn our attention to the design and approximation
of FIR digital filters. These filters have several design and implementational advantages:
•
•
•
•
The phase response can be exactly linear.
They are relatively easy to design since there are no stability problems.
They are efficient to implement.
The DFT can be used in their implementation.
As we discussed in Chapter 6, we are generally interested in linearphase frequency-selective FIR filters. Advantages of a linear-phase response are:
• design problem contains only real arithmetic and not complex
arithmetic;
• linear-phase filters provide no delay distortion and only a fixed amount
of delay;
234
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
• for the filter of length M (or order M − 1) the number of operations
are of the order of M/2 as we discussed in the linear-phase filter implementation.
We first begin with a discussion of the properties of the linear-phase
FIR filters, which are required in design algorithms. Then we will discuss
three design techniques, namely the window design, the frequency sampling design, and the optimal equiripple design techniques for linear-phase
FIR filters.
PROPERTIES OF LINEAR-PHASE FIR FILTERS
In this section we discuss shapes of impulse and frequency responses and
locations of system function zeros of linear-phase FIR filters. Let h(n),
0 ≤ n ≤ M − 1 be the impulse response of length (or duration) M . Then
the system function is
H(z) =
M
−1
h(n)z −n = z −(M −1)
n=0
M
−1
h(n)z M −1−n
n=0
which has (M − 1) poles at the origin z = 0 (trivial poles) and (M − 1)
zeros located anywhere in the z-plane. The frequency response function
is
M
−1
H(ejω ) =
h(n)e−jωn , −π < ω ≤ π
n=0
Now we will discuss specific requirements on the forms of h(n) and H(ejω )
as well as requirements on the specific locations of (M − 1) zeros that the
linear-phase constraint imposes.
IMPULSE
RESPONSE
h(n)
We impose a linear-phase constraint
H(ejω ) = −αω,
−π < ω ≤ π
where α is a constant phase delay. Then we know from Chapter 6 that
h(n) must be symmetric, that is,
h (n) = h(M − 1 − n),
0 ≤ n ≤ (M − 1) with α =
M −1
2
(7.3)
Hence h(n) is symmetric about α, which is the index of symmetry. There
are two possible types of symmetry:
• M odd: In this case α = (M − 1)/2 is an integer. The impulse response
is as shown below.
Properties of Linear-phase FIR Filters
235
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
h(n)
Symmetric Impulse Response: M odd
0
0
(M – 1)/2
n
(M – 1)
• M even: In this case α = (M − 1)/2 is not an integer. The impulse
response is as shown below.
h(n)
Symmetric Impulse Response: M even
0
0
M/2 + 1 M/2
n
M–1
We also have a second type of “linear-phase” FIR filter if we require
that the phase response H(ejω ) satisfy the condition
H(ejω ) = β − αω
which is a straight line but not through the origin. In this case α is not a
constant phase delay, but
d H(ejω )
= −α
dω
is constant, which is the group delay. Therefore α is called a constant
group delay. In this case, as a group, frequencies are delayed at a constant
rate. But some frequencies may get delayed more and others delayed less.
For this type of linear phase one can show that
h (n) = −h(M −1−n),
236
0 ≤ n ≤ (M −1); α =
π
M −1
,β=±
2
2
Chapter 7
(7.4)
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
This means that the impulse response h(n) is antisymmetric. The index
of symmetry is still α = (M − 1)/2. Once again we have two possible
types, one for M odd and one for M even.
• M odd: In this case α = (M − 1)/2 is an integer and the impulse
response is as shown below.
h(n)
Antisymmetric Impulse Response: M odd
0
0
(M – 1)/2
n
M–1
Note that the sample h(α) at α = (M − 1)/2 must necessarily be equal
to zero, i.e., h((M − 1)/2) = 0.
• M even: In this case α = (M − 1)/2 is not an integer and the impulse
response is as shown below.
h(n)
Antisymmetric Impulse Response: M even
0
0
FREQUENCY
RESPONSE
H(ejω )
M/2 +1 M/2
n
M–1
When the cases of symmetry and antisymmetry are combined with odd
and even M , we obtain four types of linear-phase FIR filters. Frequency
response functions for each of these types have some peculiar expressions
and shapes. To study these responses, we write H(ejω ) as
H(ejω ) = Hr (ω)ej(β−αω) ;
Properties of Linear-phase FIR Filters
π
M −1
β=± ,α=
2
2
(7.5)
237
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where Hr (ω) is an amplitude response function and not a magnitude response function. The amplitude response is a real function, but unlike
the magnitude response, which is always positive, the amplitude response
may be both positive and negative. The phase response associated with
the magnitude response is a discontinuous function, while that associated
with the amplitude response is a continuous linear function. To illustrate
the difference between these two types of responses, consider the following
example.
EXAMPLE 7.3
Let the impulse response be h(n) = {1, 1, 1}. Determine and draw frequency
↑
responses.
Solution
The frequency response function is
H(ejω ) =
2
h(n)ejωn = 1 + 1e−jω + e−j2ω = ejω + 1 + e−jω e−jω
0
= {1 + 2 cos ω} e−jω
From this the magnitude and the phase responses are
|H(ejω )| = |1 + 2 cos ω| ,
H(ejω ) =
0<ω≤π
−ω,
0 < ω < 2π/3
π − ω,
2π/3 < ω < π
since cos ω can be both positive and negative. In this case the phase response
is piecewise linear. On the other hand, the amplitude and the corresponding
phase responses are
Hr (ω) = 1 + 2 cos ω,
H(ejω ) = −ω,
−π <ω ≤π
In this case the phase response is truly linear. These responses are shown in
Figure 7.2. From this example the difference between the magnitude and the amplitude (or between the piecewise linear and the linear-phase) responses should
be clear.
Type-1 linear-phase FIR filter: Symmetrical impulse response,
M odd In this case β = 0, α = (M − 1)/2 is an integer, and h(n) =
h(M − 1 − n), 0 ≤ n ≤ M − 1. Then we can show (see Problem P7.2)
that


(M −1)/2
H(ejω ) = 
a(n) cos ωn e−jω(M −1)/2
(7.6)
n=0
238
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Amplitude Response
Hr
|H|
Magnitude Response
0
0
0
2/3
frequency in pi units
1
0
2/3
0
−2/3
0
FIGURE 7.2
1
Linear Phase Response
angle in pi units
angle in pi units
Piecewise Linear Phase Response
2/3
frequency in pi units
0
−2/3
2/3
frequency in pi units
1
0
2/3
frequency in pi units
1
Frequency responses in Example 7.3
where sequence a(n) is obtained from h(n) as
a(0) = h
a(n) = 2h
M −1
2
:
the middle sample
M −1
−n ,
2
M −3
1≤n≤
2
(7.7)
Comparing (7.5) with (7.6), we have
(M −1)/2
Hr (ω) =
a(n) cos ωn
(7.8)
n=0
Type-2 linear-phase FIR filter: Symmetrical impulse response,
M even In this case again β = 0 , h(n) = h(M −1−n), 0 ≤ n ≤ M −1,
but α = (M −1)/2 is not an integer. Then we can show (see Problem P7.3)
that


M/2
1
 e−jω(M −1)/2
H(ejω ) = 
b(n) cos ω n −
(7.9)
2
n=1
Properties of Linear-phase FIR Filters
239
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where
b(n) = 2h
Hence
M
−n ,
2
n = 1, 2, . . . ,
M
2
(7.10)
1
b(n) cos ω n −
2
n=1
M/2
Hr (ω) =
Note:
(7.11)
At ω = π we get
1
b(n) cos π n −
2
n=1
M/2
Hr (π) =
=0
regardless of b(n) or h(n). Hence we cannot use this type (i.e., symmetric
h(n), M even) for highpass or bandstop filters.
Type-3 linear-phase FIR filter: Antisymmetric impulse response,
M odd In this case β = π/2, α = (M − 1)/2 is an integer, h(n) =
−h(M − 1 − n), 0 ≤ n ≤ M − 1, and h((M − 1)/2) = 0. Then we can
show (see Problem P7.4) that

(M −1)/2
H(ejω ) = 

c(n) sin ωn ej [ 2 −(
π
M −1
2
)ω]
(7.12)
n=1
where
c(n) = 2h
M −1
−n ,
2
n = 1, 2, . . . ,
M −1
2
(7.13)
and
(M −1)/2
Hr (ω) =
c(n) sin ωn
(7.14)
n=1
Note: At ω = 0 and ω = π we have Hr (ω) = 0, regardless of c(n) or
h(n). Furthermore, ejπ/2 = j, which means that jHr (ω) is purely imaginary. Hence this type of filter is not suitable for designing a lowpass filter
or a highpass filter. However, this behavior is suitable for approximating ideal digital Hilbert transformers and differentiators. An ideal Hilbert
transformer [19] is an all-pass filter that imparts a 90◦ phase shift on the
input signal. It is frequently used in communication systems for modulation purposes. Differentiators are used in many analog and digital systems
to take the derivative of a signal.
240
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Type-4 linear-phase FIR filter: Antisymmetric impulse response,
M even This case is similar to Type-2. We have (see Problem P7.5)

M/2
H(ejω ) = 
d(n) sin ω n −
n=1

1
2
 ej[ π2 −ω(M −1)/2]
(7.15)
where
d(n) = 2h
M
−n ,
2
n = 1, 2, . . . ,
M
2
(7.16)
and
1
d(n) sin ω n −
2
n=1
M/2
Hr (ω) =
(7.17)
Note: At ω = 0, Hr (0) = 0 and ejπ/2 = j. Hence this type is also
suitable for designing digital Hilbert transformers and differentiators.
MATLAB
IMPLEMENTATION
The MATLAB function freqz computes the frequency response from
which we can determine the magnitude response but not the amplitude
response. The SP toolbox now provides the function zerophase that can
compute the amplitude response. However, it easy to write simple functions to compute amplitude responses for each of the four types. We provide four functions to do this.
1. Hr type1:
function [Hr,w,a,L] = Hr_Type1(h);
% Computes Amplitude response Hr(w) of a Type-1 LP FIR filter
% ----------------------------------------------------------% [Hr,w,a,L] = Hr_Type1(h)
% Hr = Amplitude Response
% w = 500 frequencies between [0 pi] over which Hr is computed
% a = Type-1 LP filter coefficients
% L = Order of Hr
% h = Type-1 LP filter impulse response
%
M = length(h); L = (M-1)/2;
a = [h(L+1) 2*h(L:-1:1)]; % 1x(L+1) row vector
n = [0:1:L];
% (L+1)x1 column vector
w = [0:1:500]’*pi/500; Hr = cos(w*n)*a’;
Properties of Linear-phase FIR Filters
241
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
2. Hr type2:
function [Hr,w,b,L] = Hr_Type2(h);
% Computes Amplitude response of a Type-2 LP FIR filter
% ----------------------------------------------------% [Hr,w,b,L] = Hr_Type2(h)
% Hr = Amplitude Response
% w = frequencies between [0 pi] over which Hr is computed
% b = Type-2 LP filter coefficients
% L = Order of Hr
% h = Type-2 LP impulse response
%
M = length(h); L = M/2;
b = 2*[h(L:-1:1)]; n = [1:1:L]; n = n-0.5;
w = [0:1:500]’*pi/500; Hr = cos(w*n)*b’;
3. Hr type3:
function [Hr,w,c,L] = Hr_Type3(h);
% Computes Amplitude response Hr(w) of a Type-3 LP FIR filter
% ----------------------------------------------------------% [Hr,w,c,L] = Hr_Type3(h)
% Hr = Amplitude Response
% w = frequencies between [0 pi] over which Hr is computed
% c = Type-3 LP filter coefficients
% L = Order of Hr
% h = Type-3 LP impulse response
%
M = length(h); L = (M-1)/2;
c = [2*h(L+1:-1:1)]; n = [0:1:L];
w = [0:1:500]’*pi/500; Hr = sin(w*n)*c’;
4. Hr type4:
function [Hr,w,d,L] = Hr_Type4(h);
% Computes Amplitude response of a Type-4 LP FIR filter
% ----------------------------------------------------% [Hr,w,d,L] = Hr_Type4(h)
% Hr = Amplitude Response
% w = frequencies between [0 pi] over which Hr is computed
% d = Type-4 LP filter coefficients
% L = Order of d
% h = Type-4 LP impulse response
%
M = length(h); L = M/2;
d = 2*[h(L:-1:1)]; n = [1:1:L]; n = n-0.5;
w = [0:1:500]’*pi/500; Hr = sin(w*n)*d’;
242
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
These four functions can be combined into one function called
ampl-res that can be written to determine the type of the linear-phase
filter and to implement the appropriate amplitude response expression.
This is explored in Problem P7.6. The use of these functions is described
in Examples 7.4 through 7.7.
The zerophase function from the SP toolbox is similar in use to the
freqz function. The invocation [Hr,w, phi] = zerophase(b,a) returns
the amplitude response in Hr, evaluated at 512 values around the top half
of the unit circle in the array w and the continuous phase response in
phi. Thus, this function can be used for both FIR and IIR filters. Other
invocations are also available.
ZERO
LOCATIONS
Recall that for an FIR filter there are (M − 1) (trivial) poles at the origin
and (M − 1) zeros located somewhere in the z-plane. For linear-phase
FIR filters, these zeros possess certain symmetries that are due to the
symmetry constraints on h(n). It can be shown (see [22] and Problem
P7.7) that if H(z) has a zero at
z = z1 = rejθ
then for linear phase there must be a zero at
z=
1
1
= e−jθ
z1
r
For a real-valued filter we also know that if z1 is complex, then there must
be a conjugate zero at z1∗ = re−jθ , which implies that there must be a
zero at 1/z1∗ = (1/r) ejθ . Thus a general zero constellation is a quadruplet
rejθ ,
1 jθ
e ,
r
re−jθ ,
and
1 −jθ
e
r
as shown in Figure 7.3. Clearly, if r = 1, then 1/r = 1, and hence the
zeros are on the unit circle and occur in pairs
ejθ
and
e−jθ
If θ = 0 or θ = π, then the zeros are on the real line and occur in pairs
r
and
1
r
Finally, if r = 1 and θ = 0 or θ = π, the zeros are either at z = 1 or
z = −1. These symmetries can be used to implement cascade forms with
linear-phase sections.
Properties of Linear-phase FIR Filters
243
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 7.3
A general zero constellation
In the following examples we illustrate the above described properties
of linear-phase FIR filters.
EXAMPLE 7.4
Let h(n) = {−4, 1, −1, −2, 5, 6, 5, −2, −1, 1, −4}. Determine the amplitude re↑
sponse Hr (ω) and the locations of the zeros of H (z).
Solution
Since M = 11, which is odd, and since h(n) is symmetric about α = (11−1)/2 =
5, this is a Type-1 linear-phase FIR filter. From (7.7) we have
a(0) = h (α) = h(5) = 6,
a(1) = 2h(5 − 1) = 10,
a(2) = 2h(5 − 2) = −4
a (3) = 2h (5 − 3) = −2,
a (4) = 2h (5 − 4) = 2,
a (5) = 2h (5 − 5) = −8
From (7.8), we obtain
Hr (ω) = a(0) + a(1) cos ω + a(2) cos 2ω + a(3) cos 3ω + a(4) cos 4ω + a(5) cos 5ω
= 6 + 10 cos ω − 4 cos 2ω − 2 cos 3ω + 2 cos 4ω − 8 cos 5ω
MATLAB Script:
>> h = [-4,1,-1,-2,5,6,5,-2,-1,1,-4];
>> M = length(h); n = 0:M-1;
>> [Hr,w,a,L] = Hr_Type1(h);
244
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> a,L
a = 6
10
-4
-2
2
-8
L = 5
>> amax = max(a)+1; amin = min(a)-1;
>> subplot(2,2,1); stem(n,h); axis([-1 2*L+1 amin amax])
>> xlabel(’n’); ylabel(’h(n)’); title(’Impulse Response’)
>> subplot(2,2,3); stem(0:L,a); axis([-1 2*L+1 amin amax])
>> xlabel(’n’); ylabel(’a(n)’); title(’a(n) coefficients’)
>> subplot(2,2,2); plot(w/pi,Hr);grid
>> xlabel(’frequency in pi units’); ylabel(’Hr’)
>> title(’Type-1 Amplitude Response’)
>> subplot(2,2,4); pzplotz(h,1)
The plots and the zero locations are shown in Figure 7.4. From these plots we
observe that there are no restrictions on Hr (ω) either at ω = 0 or at ω = π.
There is one zero-quadruplet constellation and three zero pairs.
EXAMPLE 7.5
Let h(n) = {−4, 1, −1, −2, 5, 6, 6, 5, −2, −1, 1, −4}. Determine the amplitude
↑
response Hr (ω) and the locations of the zeros of H (z).
Impulse Response
Type–1 Amplitude Response
20
10
10
Hr
h(n)
5
0
0
−10
−5
0
5
n
10
−20
0
0.5
frequency in pi units
a(n) coefficients
1
Pole–Zero Plot
z–plane
10
imaginary axis
1
a(n)
5
0
−5
0
FIGURE 7.4
Properties of Linear-phase FIR Filters
5
n
10
0
−1
−1
0
real axis
1
Plots in Example 7.4
245
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
This is a Type-2 linear-phase FIR filter since M = 12 and since h (n) is symmetric with respect to α = (12 − 1) /2 = 5.5. From (7.10) we have
b(1) = 2h
12
2
− 1 = 12,
b(2) = 2h
12
2
− 2 = 10, b(3) = 2h
12
2
− 3 = −4
b(4) = 2h
12
2
− 4 = −2, b(5) = 2h
12
2
− 5 = 2,
12
2
− 6 = −8
b(6) = 2h
Hence from (7.11) we obtain
Hr (ω) = b(1) cos ω 1 −
1
2
+ b(4) cos ω 4 −
1
2
+ b(5) cos ω 5 −
3ω
5ω
− 4 cos
2
2
9ω
11ω
+ 2 cos
− 8 cos
2
2
= 12 cos
ω
2
1
2
+ b(2) cos ω 2 −
+ 10 cos
+ b(3) cos ω 3 −
1
2
1
2
+ b(6) cos ω 6 −
− 2 cos
7ω
2
1
2
MATLAB Script:
>> h = [-4,1,-1,-2,5,6,6,5,-2,-1,1,-4];
>> M = length(h); n = 0:M-1; [Hr,w,a,L] = Hr_Type2(h);
>> b,L
b = 12
10
-4
-2
2
-8
L = 6
>> bmax = max(b)+1; bmin = min(b)-1;
>> subplot(2,2,1); stem(n,h); axis([-1 2*L+1 bmin bmax])
>> xlabel(’n’); ylabel(’h(n)’); title(’Impulse Response’)
>> subplot(2,2,3); stem(1:L,b); axis([-1 2*L+1 bmin bmax])
>> xlabel(’n’); ylabel(’b(n)’); title(’b(n) coefficients’)
>> subplot(2,2,2); plot(w/pi,Hr);grid
>> xlabel(’frequency in pi units’); ylabel(’Hr’)
>> title(’Type-1 Amplitude Response’)
>> subplot(2,2,4); pzplotz(h,1)
The plots and the zero locations are shown in Figure 7.5. From these plots we
observe that Hr (ω) is zero at ω = π. There is one zero-quadruplet constellation,
three zero pairs, and one zero at ω = π as expected.
EXAMPLE 7.6
Let h(n) = {−4, 1, −1, −2, 5, 0, −5, 2, 1, −1, 4}. Determine the amplitude re↑
sponse Hr (ω) and the locations of the zeros of H (z).
Solution
246
Since M = 11, which is odd, and since h(n) is antisymmetric about α =
(11 − 1)/2 = 5, this is a Type-3 linear-phase FIR filter. From (7.13) we have
c(0) = h (α) = h(5) = 0,
c(1) = 2h(5 − 1) = 10,
c(2) = 2h(2 − 2) = −4
c (3) = 2h (5 − 3) = −2,
c (4) = 2h (5 − 4) = 2,
c (5) = 2h (5 − 5) = −8
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Impulse Response
Type–2 Amplitude Response
30
10
20
10
Hr
h(n)
5
0
0
−5
−10
0
5
10
−20
0
n
0.5
frequency in pi units
b(n) coefficients
Pole–Zero Plot
1
z–plane
imaginary axis
10
b(n)
5
0
−5
0
5
10
n
FIGURE 7.5
1
0
−1
−1
0
real axis
1
Plots in Example 7.5
From (7.14) we obtain
Hr (ω) = c(0) + c(1) sin ω + c(2) sin 2ω + c(3) sin 3ω + c(4) sin 4ω + c(5) sin 5ω
= 0 + 10 sin ω − 4 sin 2ω − 2 sin 3ω + 2 sin 4ω − 8 sin 5ω
MATLAB Script:
>> h = [-4,1,-1,-2,5,0,-5,2,1,-1,4];
>> M = length(h); n = 0:M-1; [Hr,w,c,L] = Hr_Type3(h);
>> c,L
a = 0
10
-4
-2
2
-8
L = 5
>> cmax = max(c)+1; cmin = min(c)-1;
>> subplot(2,2,1); stem(n,h); axis([-1 2*L+1 cmin cmax])
>> xlabel(’n’); ylabel(’h(n)’); title(’Impulse Response’)
>> subplot(2,2,3); stem(0:L,c); axis([-1 2*L+1 cmin cmax])
>> xlabel(’n’); ylabel(’c(n)’); title(’c(n) coefficients’)
>> subplot(2,2,2); plot(w/pi,Hr);grid
>> xlabel(’frequency in pi units’); ylabel(’Hr’)
>> title(’Type-1 Amplitude Response’)
>> subplot(2,2,4); pzplotz(h,1)
Properties of Linear-phase FIR Filters
247
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The plots and the zero locations are shown in Figure 7.6. From these plots we
observe that Hr (ω) = 0 at ω = 0 and at ω = π. There is one zero-quadruplet
constellation, two zero pairs, and zeros at ω = 0 and ω = π as expected.
Impulse Response
Type–3 Amplitude Response
30
10
20
Hr
h(n)
5
0
10
0
−5
0
5
n
−10
0
10
0.5
frequency in pi units
c(n) coefficients
1
Pole–Zero Plot
z–plane
10
imaginary axis
1
c(n)
5
0
−5
0
5
n
EXAMPLE 7.7
−1
−1
10
0
real axis
1
Plots in Example 7.6
FIGURE 7.6
0
Let h(n) = {−4, 1, −1, −2, 5, 6, −6, −5, 2, 1, −1, 4}. Determine the amplitude
↑
response Hr (ω) and the locations of the zeros of H (z).
Solution
This is a Type-4 linear-phase FIR filter since M = 12 and since h (n) is antisymmetric with respect to α = (12 − 1) /2 = 5.5. From (7.16) we have
d(1) = 2h
12
2
− 1 = 12,
d(2) = 2h
12
2
− 2 = 10, d(3) = 2h
12
2
− 3 = −4
d(4) = 2h
12
2
− 4 = −2, d(5) = 2h
12
2
− 5 = 2,
12
2
− 6 = −8
Hence from (7.17) we obtain
Hr (ω) = d(1) sin ω 1 −
1
2
+d(4) sin ω 4 −
1
2
+ d(2) sin ω 2 −
+ d(5) sin ω 5 −
ω
3ω
5ω
+ 10 sin
− 4 sin
2
2
2
9ω
11ω
+2 sin
− 8 sin
2
2
= 12 sin
248
1
2
d(6) = 2h
1
2
+ d(3) sin ω 3 −
1
2
+ d(6) sin ω 6 −
− 2 sin
Chapter 7
7ω
2
1
2
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB Script:
>> h = [-4,1,-1,-2,5,6,-6,-5,2,1,-1,4];
>> M = length(h); n = 0:M-1; [Hr,w,d,L] = Hr_Type4(h);
>> b,L
d = 12
10
-4
-2
2
-8
L = 6
>> dmax = max(d)+1; dmin = min(d)-1;
>> subplot(2,2,1); stem(n,h); axis([-1 2*L+1 dmin dmax])
>> xlabel(’n’); ylabel(’h(n)’); title(’Impulse Response’)
>> subplot(2,2,3); stem(1:L,d); axis([-1 2*L+1 dmin dmax])
>> xlabel(’n’); ylabel(’d(n)’); title(’d(n) coefficients’)
>> subplot(2,2,2); plot(w/pi,Hr);grid
>> xlabel(’frequency in pi units’); ylabel(’Hr’)
>> title(’Type-1 Amplitude Response’)
>> subplot(2,2,4); pzplotz(h,1)
The plots and the zero locations are shown in Figure 7.7. From these plots we
observe that Hr (ω) is zero at ω = 0. There is one zero-quadruplet constellation,
three zero pairs, and one zero at ω = 0 as expected.
Impulse Response
Type–4 Amplitude Response
30
10
20
Hr
h(n)
5
10
0
0
−5
0
5
10
−10
0
n
0.5
frequency in pi units
d(n) coefficients
Pole–Zero Plot
1
z–plane
imagninary axis
10
d(n)
5
0
−5
0
5
10
n
FIGURE 7.7
Properties of Linear-phase FIR Filters
1
0
−1
−1
0
real axis
1
Plots in Example 7.7
249
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
WINDOW DESIGN TECHNIQUES
The basic idea behind the window design is to choose a proper ideal
frequency-selective filter (which always has a noncausal, infinite-duration
impulse response) and then truncate (or window) its impulse response
to obtain a linear-phase and causal FIR filter. Therefore the emphasis
in this method is on selecting an appropriate windowing function and
an appropriate ideal filter. We will denote an ideal frequency-selective
filter by Hd (ejω ), which has a unity magnitude gain and linear-phase
characteristics over its passband, and zero response over its stopband. An
ideal LPF of bandwidth ωc < π is given by
jω
Hd (e ) =
1 · e−jαω ,
0,
|ω| ≤ ωc
(7.18)
ωc < |ω| ≤ π
where ωc is also called the cutoff frequency, and α is called the sample
delay (note that from the DTFT properties, e−jαω implies shift in the
positive n direction or delay). The impulse response of this filter is of
infinite duration and is given by
hd (n) = F
=
−1
1
2π
1
Hd (e ) =
2π
jω
ωc
π
Hd (ejω )ejωn dω
(7.19)
−π
1 · e−jαω ejωn dω
−ωc
sin [ωc (n − α)]
=
π(n − α)
Note that hd (n) is symmetric with respect to α, a fact useful for linearphase FIR filters.
To obtain an FIR filter from hd (n), one has to truncate hd (n) on both
sides. To obtain a causal and linear-phase FIR filter h(n) of length M , we
must have
hd (n), 0 ≤ n ≤ M − 1
M −1
(7.20)
h(n) =
and
α=
2
0,
elsewhere
This operation is called “windowing.” In general, h(n) can be thought of
as being formed by the product of hd (n) and a window function w(n) as
follows:
h(n) = hd (n)w(n)
250
Chapter 7
(7.21)
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where


some symmetric function with respect to
w(n) = α over 0 ≤ n ≤ M − 1


0, otherwise
Depending on how we define w(n) above, we obtain different window
designs. For example, in (7.20) above
1, 0 ≤ n ≤ M − 1
w(n) =
= RM (n)
0,
otherwise
which is the rectangular window defined earlier.
In the frequency domain the causal FIR filter response H(ejω ) is given
by the periodic convolution of Hd (ejω ) and the window response W (ejω );
that is,
H(e ) = Hd (e ) ∗ W (ejω ) =
jω
jω
1
2π
π
W ejλ Hd ej(ω−λ) dλ
−π
(7.22)
This is shown pictorially in Figure 7.8 for a typical window response, from
which we have the following observations:
1. Since the window w(n) has a finite length equal to M , its response has
a peaky main lobe whose width is proportional to 1/M , and has side
lobes of smaller heights.
Hd (e jw)
−p
−wc
wc
0
p
H (e jw)
w
Transition
bandwidth
Ripples
W (e jw)
Max side-lobe
height
−p
Periodic
convolution
0
Main lobe
width
FIGURE 7.8
Window Design Techniques
p
w
−p
−wc
0
wc
p
w
Minimum
stopband
attenuation
Windowing operation in the frequency domain
251
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
2. The periodic convolution (7.22) produces a smeared version of the ideal
response Hd (ejω ).
3. The main lobe produces a transition band in H(ejω ) whose width is
responsible for the transition width. This width is then proportional to
1/M . The wider the main lobe, the wider will be the transition width.
4. The side lobes produce ripples that have similar shapes in both the
passband and stopband.
Basic Window Design Idea For the given filter specifications choose
the filter length M and a window function w(n) for the narrowest main
lobe width and the smallest side lobe attenuation possible.
From observation 4 above we note that the passband tolerance δ1 and
the stopband tolerance δ2 cannot be specified independently. We generally
take care of δ2 alone, which results in δ2 = δ1 . We now briefly describe
various well-known window functions. We will use the rectangular window
as an example to study their performances in the frequency domain.
RECTANGULAR
WINDOW
This is the simplest window function but provides the worst performance
from the viewpoint of stopband attenuation. It was defined earlier by
w(n) =
1,
0≤n≤M −1
0,
(7.23)
otherwise
Its frequency response function is
sin
W (e ) =
sin
jω
ωM
2
ω
2
e−jω
M −1
2
⇒ Wr (ω) =
sin
sin
ωM
2
ω
2
which is the amplitude response. From (7.22) the actual amplitude response Hr (ω) is given by
1
Hr (ω) 2π
ω+ω
c
−π
1
Wr (λ) dλ =
2π
ω+ω
c
−π
sin
sin
ωM
2
ω
2
dλ,
M 1
(7.24)
This implies that the running integral of the window amplitude response
(or accumulated amplitude response) is necessary in the accurate analysis of the transition bandwidth and the stopband attenuation. Figure
7.9 shows the rectangular window function w (n), its amplitude response
W (ω), the amplitude response in dB, and the accumulated amplitude
response (7.24) in dB. From the observation of plots in Figure 7.9 we can
make several observations.
252
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Rectangular Window : M=45
Amplitude Response in dB
1
w(n)
Decibels
0
13
0
0
22
n
40
−1
45
Amplitude Response
0
frequency in pi units
1
Accumulated Amplitude Response
45
Width=(1.8)*pi/M
Wr
Decibels
0
21
0
−1
FIGURE 7.9
0
frequency in pi units
50
−1
1
1
frequency in pi units
Rectangular window: M = 45
1. The amplitude response Wr (ω) has the first zero at ω = ω1 , where
ω1 M
=π
2
or
ω1 =
2π
M
Hence the width of the main lobe is 2ω1 = 4π/M . Therefore the approximate transition bandwidth is 4π/M .
2. The magnitude of the first side lobe (which is also the peak side lobe
magnitude) is approximately at ω = 3π/M and is given by
2M
sin 3π
3π
2
Wr ω =
=
for M 1
3π
sin 2M M
3π
Comparing this with the main lobe amplitude, which is equal to M ,
the peak side lobe magnitude is
2
= 21.22% ≡ 13 dB
3π
of the main lobe amplitude.
3. The accumulated amplitude response has the first side lobe magnitude
at 21 dB. This results in the minimum stopband attenuation of 21 dB
irrespective of the window length M .
Window Design Techniques
253
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4. Using the minimum stopband attenuation, the transition bandwidth
can be accurately computed. It is shown in the accumulated amplitude
response plot in Figure 7.9. This computed exact transition bandwidth is
ωs − ωp =
1.8π
M
which is less than half the approximate bandwidth of 4π/M .
1
0
−1
1
M = 51
1
0
−1
FIGURE 7.10
254
0
frequency in pi units
0
frequency in pi units
1
Integrated Amplitude Response
M=7
Integrated Amplitude Response
Integrated Amplitude Response
Integrated Amplitude Response
Clearly, this is a simple window operation in the time domain and
an easy function to analyze in the frequency domain. However, there are
two main problems. First, the minimum stopband attenuation of 21 dB is
insufficient in practical applications. Second, the rectangular windowing
being a direct truncation of the infinite length hd (n), it suffers from the
Gibbs phenomenon. If we increase M , the width of each side lobe will
decrease, but the area under each lobe will remain constant. Therefore the
relative amplitudes of side lobes will remain constant, and the minimum
stopband attenuation will remain at 21 dB. This implies that all ripples
will bunch up near the band edges. It is shown in Figure 7.10.
Since the rectangular window is impractical in many applications,
we consider other fixed window functions that provide a fixed amount
M = 21
1
0
−1
0
frequency in pi units
1
M = 101
1
0
−1
0
frequency in pi units
1
Gibbs phenomenon
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
of attenuation. These window functions bear the names of the people
who first proposed them. Although these window functions can also be
analyzed similar to the rectangular window, we present only their results.
BARTLETT
WINDOW
Since the Gibbs phenomenon results from the fact that the rectangular
window has a sudden transition from 0 to 1 (or 1 to 0), Bartlett suggested
a more gradual transition in the form of a triangular window, which is
given by

2n
M −1


,
0≤n≤


M −1
2



2n
M −1
w(n) =
(7.25)
2−
,
≤n≤M −1


M
−
1
2





0,
otherwise
This window and its frequency-domain responses are shown in Figure
7.11.
Bartlett Window : M=45
Amplitude Response in dB
1
w(n)
Decibels
0
27
0
0
22
n
60
1
45
Amplitude Response
0
frequency in pi units
1
Accumulated Amplitude Response
0
Width=(6.1)*pi/M
Wr
Decibels
22
26
0
−1
FIGURE 7.11
Window Design Techniques
0
frequency in pi units
1
60
−1
1
frequency in pi units
Bartlett window: M = 45
255
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Hann Window : M=45
Amplitude Response in dB
1
w(n)
Decibels
0
32
0
0
22
n
60
−1
45
Amplitude Response
0
frequency in pi units
1
Accumulated Amplitude Response
Width=(6.2)*pi/M
0
Wr
Decibels
23
44
0
−1
FIGURE 7.12
HANN
WINDOW
0
frequency in pi units
60
−1
1
1
frequency in pi units
Hann window: M = 45
This is a raised cosine window function given by
w(n) =
 0.5 1 − cos

2πn
M −1
,
0,
0≤n≤M −1
(7.26)
otherwise
This window and its frequency-domain responses are shown in Figure
7.12.
HAMMING
WINDOW
This window is similar to the Hann window except that it has a small
amount of discontinuity and is given by
w(n) =
0.54 − 0.46 cos
0,
2πn
M −1
,
0≤n≤M −1
otherwise
(7.27)
This window and its frequency-domain responses are shown in Figure
7.13.
256
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Hamming Window : M=45
Amplitude Response in dB
1
w(n)
Decibels
0
43
0
−22
0
n
60
−1
22
Amplitude Response
0
frequency in pi units
1
Accumulated Amplitude Response
0
Width=(6.6)*pi/M
Wr
Decibels
23.84
54
0
0
FIGURE 7.13
BLACKMAN
WINDOW
22
frequency in pi units
45
70
−1
1
frequency in pi units
Hamming window: M = 45
This window is also similar to the previous two but contains a second
harmonic term and is given by

0.42 − 0.5 cos 2πn + 0.08 cos 4πn , 0 ≤ n ≤ M − 1
M −1
M −1
w(n) =

0,
otherwise
(7.28)
This window and its frequency-domain responses are shown in Figure
7.14.
In Table 7.1 we provide a summary of fixed window function characteristics in terms of their transition widths (as a function of M ) and their
minimum stopband attenuations in dB. Both the approximate as well as
the exact transition bandwidths are given. Note that the transition widths
and the stopband attenuations increase as we go down the table. The
Hamming window appears to be the best choice for many applications.
KAISER
WINDOW
This is an adjustable window function that is widely used in practice. The
window function is due to J. F. Kaiser and is given by
2
I0 β 1 − (1 − M2n
)
−1
w(n) =
, 0≤n≤M −1
(7.29)
I0 [β]
Window Design Techniques
257
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Blackman Window : M=45
Amplitude Response in dB
1
w(n)
Decibels
0
58
0
−22
0
n
−1
22
Amplitude Response
0
frequency in pi units
1
Accumulated Amplitude Response
Width=(11)*pi/M
0
Wr
Decibels
18.48
74
0
0
FIGURE 7.14
TABLE 7.1
Window
Name
258
22
frequency in pi units
45
−1
1
frequency in pi units
Blackman window: M = 45
Summary of commonly used window function characteristics
Transition Width ∆ω
Approximate
Exact Values
Min. Stopband
Attenuation
Rectangular
4π
M
1.8π
M
21 dB
Bartlett
8π
M
6.1π
M
25 dB
Hann
8π
M
6.2π
M
44 dB
Hamming
8π
M
6.6π
M
53 dB
Blackman
12π
M
11π
M
74 dB
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where I0 [ · ] is the modified zero-order Bessel function given by
I0 (x) = 1 +
2
∞ (x/2)k
k!
k=0
which is positive for all real values of x. The parameter β controls the
minimum stopband attenuation As and can be chosen to yield different
transition widths for near-optimum As . This window can provide different
transition widths for the same M , which is something other fixed windows
lack. For example,
• if β = 5.658, then the transition width is equal to 7.8π/M , and the
minimum stopband attenuation is equal to 60 dB. This is shown in
Figure 7.15.
• if β = 4.538, then the transition width is equal to 5.8π/M , and the
minimum stopband attenuation is equal to 50 dB.
Hence the performance of this window is comparable to that of the
Hamming window. In addition, the Kaiser window provides flexible transition bandwidths. Due to the complexity involved in the Bessel functions,
the design equations for this window are not easy to derive. Fortunately,
Kaiser has developed empirical design equations, which we provide below
Kaiser Window : M=45
Amplitude Response in dB
1
w(n)
Decibels
0
42
0
−22
0
n
−1
22
Amplitude Response
0
frequency in pi units
1
Accumulated Amplitude Response
0
Width=(7.8)*pi/M
Wr
Decibels
22.6383
60
0
0
FIGURE 7.15
Window Design Techniques
22
frequency in pi units
45
−1
1
frequency in pi units
Kaiser window: M = 45, β = 5.658
259
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
without proof. Given ωp , ωs , Rp , and As the parameters M and β are
given by
transition width = ∆ω = ωs − ωp
As − 7.95
Filter length M +1
2.285∆ω
(7.30)

0.1102 (As − 8.7) ,


Parameter β =
MATLAB
IMPLEMENTATION
As ≥ 50
0.4
0.5842 (As − 21)

+ 0.07886 (As − 21) ,
21 < As < 50
MATLAB provides several functions to implement window functions discussed in this section. A brief description of these functions is given below.
• w=boxcar(M) returns the M-point rectangular window function in array w.
• w=bartlett(M) returns the M-point Bartlett window function in array w.
• w=hann(M) returns the M-point Hann window function in array w.
• w=hamming(M) returns the M-point Hamming window function in array w.
• w=blackman(M) returns the M-point Blackman window function in array w.
• w=kaiser(M,beta) returns the beta-valued M-point rectangular window function in array w.
Using these functions, we can use MATLAB to design FIR filters based
on the window technique, which also requires an ideal lowpass impulse
response hd (n). Therefore it is convenient to have a simple routine that
creates hd (n) as shown below.
function hd = ideal_lp(wc,M);
% Ideal LowPass filter computation
% -------------------------------% [hd] = ideal_lp(wc,M)
% hd = ideal impulse response between 0 to M-1
% wc = cutoff frequency in radians
%
M = length of the ideal filter
%
alpha = (M-1)/2; n = [0:1:(M-1)];
m = n - alpha; fc = wc/pi; hd = fc*sinc(fc*m);
260
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
To display the frequency-domain plots of digital filters, MATLAB
provides the freqz function, which we used in earlier chapters. Using this
function, we have developed a modified version, called freqz m, which
returns the magnitude response in absolute as well as in relative dB scale,
the phase response, and the group delay response. We will need the group
delay response in the next chapter.
function [db,mag,pha,grd,w] = freqz_m(b,a);
% Modified version of freqz subroutine
% -----------------------------------% [db,mag,pha,grd,w] = freqz_m(b,a);
% db = Relative magnitude in dB computed over 0 to pi radians
% mag = absolute magnitude computed over 0 to pi radians
% pha = Phase response in radians over 0 to pi radians
% grd = Group delay over 0 to pi radians
%
w = 501 frequency samples between 0 to pi radians
%
b = numerator polynomial of H(z)
(for FIR: b=h)
%
a = denominator polynomial of H(z) (for FIR: a=[1])
%
[H,w] = freqz(b,a,1000,’whole’);
H = (H(1:1:501))’; w = (w(1:1:501))’;
mag = abs(H); db = 20*log10((mag+eps)/max(mag));
pha = angle(H); grd = grpdelay(b,a,w);
DESIGN
EXAMPLES
We now provide several examples of FIR filter design using window techniques and MATLAB functions.
Design a digital FIR lowpass filter with the following specifications:
EXAMPLE 7.8
ωp = 0.2π,
Rp = 0.25 dB
ωs = 0.3π,
As = 50 dB
Choose an appropriate window function from Table 7.1. Determine the impulse
response and provide a plot of the frequency response of the designed filter.
Solution
Both the Hamming and Blackman windows can provide attenuation of more
than 50 dB. Let us choose the Hamming window, which provides the smaller
transition band and hence has the smaller order. Although we do not use the
passband ripple value of Rp = 0.25 dB in the design, we will have to check
the actual ripple from the design and verify that it is indeed within the given
tolerance. The design steps are given in the following MATLAB script.
Window Design Techniques
261
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> wp = 0.2*pi; ws = 0.3*pi; tr_width = ws - wp;
>> M = ceil(6.6*pi/tr_width) + 1
M = 67
>> n=[0:1:M-1];
>> wc = (ws+wp)/2, % Ideal LPF cutoff frequency
>> hd = ideal_lp(wc,M); w_ham = (hamming(M))’; h = hd .* w_ham;
>> [db,mag,pha,grd,w] = freqz_m(h,[1]); delta_w = 2*pi/1000;
>> Rp = -(min(db(1:1:wp/delta_w+1)));
% Actual Passband Ripple
Rp = 0.0394
>> As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband attenuation
As = 52
% plots
>> subplot(2,2,1); stem(n,hd); title(’Ideal Impulse Response’)
>> axis([0 M-1 -0.1 0.3]); xlabel(’n’); ylabel(’hd(n)’)
>> subplot(2,2,2); stem(n,w_ham);title(’Hamming Window’)
>> axis([0 M-1 0 1.1]); xlabel(’n’); ylabel(’w(n)’)
>> subplot(2,2,3); stem(n,h);title(’Actual Impulse Response’)
>> axis([0 M-1 -0.1 0.3]); xlabel(’n’); ylabel(’h(n)’)
>> subplot(2,2,4); plot(w/pi,db);title(’Magnitude Response in dB’);grid
>> axis([0 1 -100 10]); xlabel(’frequency in pi units’); ylabel(’Decibels’)
Note that the filter length is M = 67, the actual stopband attenuation is
52 dB, and the actual passband ripple is 0.0394 dB. Clearly, the passband
ripple is satisfied by this design. This practice of verifying the passband ripple
is strongly recommended. The time- and the frequency-domain plots are shown
in Figure 7.16.
EXAMPLE 7.9
Solution
For the design specifications given in Example 7.8, choose the Kaiser window
to design the necessary lowpass filter.
The design steps are given in the following MATLAB script.
>> wp = 0.2*pi; ws = 0.3*pi; As = 50; tr_width = ws - wp;
>> M = ceil((As-7.95)/(2.285*tr_width/)+1) + 1
M = 61
>> n=[0:1:M-1]; beta = 0.1102*(As-8.7)
beta = 4.5513
>> wc = (ws+wp)/2; hd = ideal_lp(wc,M);
262
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Ideal Impulse Response
Hamming Window
1
0.8
w(n)
hd(n)
0.2
0.1
0.6
0.4
0
−0.1
0
0.2
0
0
20
40
60
n
Actual Impulse Response
20
40
60
n
Magnitude Response in dB
0
Decibels
h(n)
0.2
0.1
50
0
−0.1
0
20
40
60
0
n
FIGURE 7.16
0.2 0.3
frequency in pi units
1
Lowpass filter plots for Example 7.8
>> w_kai = (kaiser(M,beta))’; h = hd .* w_kai;
>> [db,mag,pha,grd,w] = freqz_m(h,[1]); delta_w = 2*pi/1000;
>> As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband Attenuation
As = 52
% Plots
>> subplot(2,2,1); stem(n,hd); title(’Ideal Impulse Response’)
>> axis([0 M-1 -0.1 0.3]); xlabel(’n’); ylabel(’hd(n)’)
>> subplot(2,2,2); stem(n,w_kai);title(’Kaiser Window’)
>> axis([0 M-1 0 1.1]); xlabel(’n’); ylabel(’w(n)’)
>> subplot(2,2,3); stem(n,h);title(’Actual Impulse Response’)
>> axis([0 M-1 -0.1 0.3]); xlabel(’n’); ylabel(’h(n)’)
>> subplot(2,2,4);plot(w/pi,db);title(’Magnitude Response in dB’);grid
>> axis([0 1 -100 10]); xlabel(’frequency in pi units’); ylabel(’Decibels’)
Note that the Kaiser window parameters are M = 61 and β = 4.5513 and that
the actual stopband attenuation is 52 dB. The time- and the frequency-domain
plots are shown in Figure 7.17.
Window Design Techniques
263
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Ideal Impulse Response
Kaiser Window
1
0.8
w(n)
hd(n)
0.2
0.1
0.6
0.4
0
0.2
−0.1
0
20
40
0
0
60
20
40
n
n
Actual Impulse Response
Magnitude Response in dB
60
0
Decibels
h(n)
0.2
0.1
50
0
−0.1
0
20
40
60
0
0.2 0.3
frequency in pi units
n
FIGURE 7.17
EXAMPLE 7.10
1
Lowpass filter plots for Example 7.9
Let us design the following digital bandpass filter.
lower stopband edge:
ω1s = 0.2π,
As = 60 dB
lower passband edge:
ω1p = 0.35π,
Rp = 1 dB
upper passband edge:
ω2p = 0.65π
Rp = 1 dB
upper stopband edge:
ω2s = 0.8π
As = 60 dB
These quantities are shown in Figure 7.18.
0
0.35
0.35
0.65
0.8
1
w
p
Decibels
0
1
60
FIGURE 7.18
264
Bandpass filter specifications in Example 7.10
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
There are two transition bands, namely, ∆ω1 = ω1p − ω1s and ∆ω2 = ω2s − ω2p .
These two bandwidths must be the same in the window design; that is, there is
no independent control over ∆ω1 and ∆ω2 . Hence ∆ω1 = ∆ω2 = ∆ω. For this
design we can use either the Kaiser window or the Blackman window. Let us
use the Blackman Window. We will also need the ideal bandpass filter impulse
response hd (n). Note that this impulse response can be obtained from two ideal
lowpass magnitude responses, provided they have the same phase response. This
is shown in Figure 7.19. Therefore the MATLAB routine ideal lp(wc,M) is
sufficient to determine the impulse response of an ideal bandpass filter. The
design steps are given in the following MATLAB script.
>> ws1 = 0.2*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.8*pi; As = 60;
>> tr_width = min((wp1-ws1),(ws2-wp2)); M = ceil(11*pi/tr_width) + 1
M = 75
>> n=[0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;
>> hd = ideal_lp(wc2,M) - ideal_lp(wc1,M);
>> w_bla = (blackman(M))’; h = hd .* w_bla;
>> [db,mag,pha,grd,w] = freqz_m(h,[1]); delta_w = 2*pi/1000;
>> Rp = -min(db(wp1/delta_w+1:1:wp2/delta_w)) % Actua; Passband Ripple
Rp = 0.0030
>> As = -round(max(db(ws2/delta_w+1:1:501))) % Min Stopband Attenuation
As = 75
%Plots
>> subplot(2,2,1); stem(n,hd); title(’Ideal Impulse Response’)
>> axis([0 M-1 -0.4 0.5]); xlabel(’n’); ylabel(’hd(n)’)
>> subplot(2,2,2); stem(n,w_bla);title(’Blackman Window’)
>> axis([0 M-1 0 1.1]); xlabel(’n’); ylabel(’w(n)’)
>> subplot(2,2,3); stem(n,h);title(’Actual Impulse Response’)
>> axis([0 M-1 -0.4 0.5]); xlabel(’n’); ylabel(’h(n)’)
>> subplot(2,2,4);plot(w/pi,db);axis([0 1 -150 10]);
>> title(’Magnitude Response in dB’);grid;
>> xlabel(’frequency in pi units’); ylabel(’Decibels’)
wc2
0
p
+
0
0
wc1
FIGURE 7.19
Window Design Techniques
wc1
wc2
p
p
Ideal bandpass filter from two lowpass filters
265
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Ideal Impulse Response
Blackman Window
1
0.4
0.8
w(n)
hd(n)
0.2
0
0.6
0.4
−0.2
−0.4
0
0.2
20
40
n
0
0
60
Actual Impulse Response
40
n
60
Magnitude Response in dB
0
0.4
Decibels
0.2
h(n)
20
0
60
−0.2
−0.4
0
FIGURE 7.20
20
40
n
60
0
0.2 0.35
0.65 0.8
frequency in pi units
1
Bandpass filter plots in Example 7.10
Note that the Blackman window length is M = 61 and that the actual stopband
attenuation is 75 dB. The time- and the frequency-domain plots are shown in
Figure 7.20.
EXAMPLE 7.11
The frequency response of an ideal bandstop filter is given by
He (ejω ) =

 1,

0,
1,
0 ≤ |ω| < π/3
π/3 ≤ |ω| ≤ 2π/3
2π/3 < |ω| ≤ π
Using a Kaiser window, design a bandstop filter of length 45 with stopband
attenuation of 60 dB.
Solution
Note that in these design specifications, the transition bandwidth is not given.
It will be determined by the length M = 45 and the parameter β of the
Kaiser window. From the design equations (7.30) we can determine β from As ;
that is,
β = 0.1102 × (As − 8.7)
266
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The ideal bandstop impulse response can also be determined from the ideal
lowpass impulse response using a method similar to Figure 7.19. We can now
implement the Kaiser window design and check for the minimum stopband
attenuation. This is shown in the following MATLAB script.
>> M = 45; As = 60; n=[0:1:M-1];
>> beta = 0.1102*(As-8.7)
beta = 5.6533
>> w_kai = (kaiser(M,beta))’; wc1 = pi/3; wc2 = 2*pi/3;
>> hd = ideal_lp(wc1,M) + ideal_lp(pi,M) - ideal_lp(wc2,M);
>> h = hd .* w_kai; [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> subplot(2,2,1); stem(n,hd); title(’Ideal Impulse Response’)
>> axis([-1 M -0.2 0.8]); xlabel(’n’); ylabel(’hd(n)’)
>> subplot(2,2,2); stem(n,w_kai);title(’Kaiser Window’)
>> axis([-1 M 0 1.1]); xlabel(’n’); ylabel(’w(n)’)
>> subplot(2,2,3); stem(n,h);title(’Actual Impulse Response’)
>> axis([-1 M -0.2 0.8]); xlabel(’n’); ylabel(’h(n)’)
>> subplot(2,2,4);plot(w/pi,db); axis([0 1 -80 10]);
>> title(’Magnitude Response in dB’);grid;
>> xlabel(’frequency in pi units’); ylabel(’Decibels’)
The β parameter is equal to 5.6533, and from the magnitude plot in Figure
7.21 we observe that the minimum stopband attenuation is smaller than 60 dB.
Clearly, we have to increase β to increase the attenuation to 60 dB. The required
value was found to be β = 5.9533.
Magnitude Response in dB
Decibels
0
60
0
1/3
2/3
1
frequency in pi units
FIGURE 7.21
Bandstop filter magnitude response in Example 7.11 for β =
5.6533
Window Design Techniques
267
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> M = 45; As = 60; n=[0:1:M-1];
>> beta = 0.1102*(As-8.7)+0.3
beta = 5.9533
>> w_kai = (kaiser(M,beta))’; wc1 = pi/3; wc2 = 2*pi/3;
>> hd = ideal_lp(wc1,M) + ideal_lp(pi,M) - ideal_lp(wc2,M);
>> h = hd .* w_kai; [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> subplot(2,2,1); stem(n,hd); title(’Ideal Impulse Response’)
>> axis([-1 M -0.2 0.8]); xlabel(’n’); ylabel(’hd(n)’)
>> subplot(2,2,2); stem(n,w_kai);title(’Kaiser Window’)
>> axis([-1 M 0 1.1]); xlabel(’n’); ylabel(’w(n)’)
>> subplot(2,2,3); stem(n,h);title(’Actual Impulse Response’)
>> axis([-1 M -0.2 0.8]); xlabel(’n’); ylabel(’h(n)’)
>> subplot(2,2,4);plot(w/pi,db); axis([0 1 -80 10]);
>> title(’Magnitude Response in dB’);grid;
>> xlabel(’frequency in pi units’); ylabel(’Decibels’)
The time- and the frequency-domain plots are shown in Figure 7.22, in which
the designed filter satisfies the necessary requirements.
Ideal Impulse Response
Kaiser Window
0.8
1
0.8
0.4
w(n)
hd(n)
0.6
0.2
0.4
0
−0.2
0.6
0.2
0
10
20
n
30
0
40
0
Actual Impulse Response
10
20
n
30
40
Magnitude Response in dB
0.8
0
Decibels
h(n)
0.6
0.4
0.2
60
0
−0.2
0
FIGURE 7.22
268
10
20
n
30
40
0
1/3
2/3
frequency in pi units
1
Bandstop filter plots in Example 7.11: β = 5.9533
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 7.12
The frequency response of an ideal digital differentiator is given by
jω
Hd (e ) =
jω,
−jω,
0<ω≤π
−π < ω < 0
(7.31)
Using a Hamming window of length 21, design a digital FIR differentiator. Plot
the time- and the frequency-domain responses.
Solution
The ideal impulse response of a digital differentiator with linear phase is given
by
−jαω
hd (n) = F Hd (e )e
jω
1
=
2π
π
Hd (ejω )e−jαω ejωn dω
−π
=
1
2π
0
(−jω) e−jαω ejωn dω +
−π

π
(jω) e−jαω ejωn dω
0

 cos π (n − α) ,
=
1
2π
(n − α)
n=α
0,
n=α
The above impulse response can be implemented in MATLAB along with the
Hamming window to design the required differentiator. Note that if M is an
even number, then α = (M − 1)/2 is not an integer and hd (n) will be zero for
all n. Hence M must be an odd number, and this will be a Type-3 linearphase FIR filter. However, the filter will not be a full-band differentiator since
Hr (π) = 0 for Type-3 filters.
>> M = 21; alpha = (M-1)/2; n = 0:M-1;
>> hd = (cos(pi*(n-alpha)))./(n-alpha); hd(alpha+1)=0;
>> w_ham = (hamming(M))’; h = hd .* w_ham; [Hr,w,P,L] = Hr_Type3(h);
% plots
>> subplot(2,2,1); stem(n,hd); title(’Ideal Impulse Response’)
>> axis([-1 M -1.2 1.2]); xlabel(’n’); ylabel(’hd(n)’)
>> subplot(2,2,2); stem(n,w_ham);title(’Hamming Window’)
>> axis([-1 M 0 1.2]); xlabel(’n’); ylabel(’w(n)’)
>> subplot(2,2,3); stem(n,h);title(’Actual Impulse Response’)
>> axis([-1 M -1.2 1.2]); xlabel(’n’); ylabel(’h(n)’)
>> subplot(2,2,4);plot(w/pi,Hr/pi); title(’Amplitude Response’);grid;
>> xlabel(’frequency in pi units’); ylabel(’slope in pi units’); axis([0 1 0 1]);
The plots are shown in Figure 7.23.
Window Design Techniques
269
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Ideal Impulse Response
Hamming Window
1
1
0.8
w(n)
hd(n)
0.5
0
0.6
0.4
−0.5
0.2
−1
0
5
10
n
15
0
20
0
Actual Impulse Response
5
10
n
15
20
Amplitude Response
1
slope in pi units
1
h(n)
0.5
0
−0.5
−1
0
FIGURE 7.23
EXAMPLE 7.13
Solution
5
10
n
15
0.8
0.6
0.4
0.2
0
0
20
0.2
0.4
0.6
0.8
frequency in pi units
1
FIR differentiator design in Example 7.12
Design a length-25 digital Hilbert transformer using a Hann window.
The ideal frequency response of a linear-phase Hilbert transformer is given by
Hd (ejω ) =
−je−jαω ,
+je
−jαω
,
0<ω<π
(7.32)
−π < ω < 0
After inverse transformation the ideal impulse response is given by
hd (n) =

2
 2 sin π (n − α) /2 ,
n=α

n=α
π
n−α
0,
which can be easily implemented in MATLAB. Note that since M = 25, the
designed filter is of Type-3.
MATLAB Script:
>>
>>
>>
>>
>>
270
M = 25; alpha = (M-1)/2; n = 0:M-1;
hd = (2/pi)*((sin((pi/2)*(n-alpha)).^2)./(n-alpha)); hd(alpha+1)=0;
w_han = (hann(M))’; h = hd .* w_han; [Hr,w,P,L] = Hr_Type3(h);
subplot(2,2,1); stem(n,hd); title(’Ideal Impulse Response’)
axis([-1 M -1.2 1.2]); xlabel(’n’); ylabel(’hd(n)’)
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Ideal Impulse Response
Hann Window
1
1
0.8
w(n)
hd(n)
0.5
0
0.6
0.4
−0.5
0.2
−1
0
5
10
15
0
20
0
5
10
15
20
n
n
Actual Impulse Response
Amplitude Response
1
1
Hr
h(n)
0.5
0
0
−0.5
−1
0
5
10
15
n
FIGURE 7.24
>>
>>
>>
>>
>>
>>
>>
>>
20
−1
−1
0
frequency in pi units
1
FIR Hilbert transformer design in Example 7.13
subplot(2,2,2); stem(n,w_han);title(’Hann Window’)
axis([-1 M 0 1.2]); xlabel(’n’); ylabel(’w(n)’)
subplot(2,2,3); stem(n,h);title(’Actual Impulse Response’)
axis([-1 M -1.2 1.2]); xlabel(’n’); ylabel(’h(n)’)
w = w’; Hr = Hr’;
w = [-fliplr(w), w(2:501)]; Hr = [-fliplr(Hr), Hr(2:501)];
subplot(2,2,4);plot(w/pi,Hr); title(’Amplitude Response’);grid;
xlabel(’frequency in pi units’); ylabel(’Hr’); axis([-1 1 -1.1 1.1]);
The plots are shown in Figure 7.24. Observe that the amplitude response is
plotted over −π ≤ ω ≤ π.
The SP toolbox provides a function called fir1 which designs conventional lowpass, highpass, and other multiband FIR filters using window
technique. This function’s syntax has several forms including:
• h = fir1(N,wc) designs an N th-order (N = M − 1) lowpass FIR
filter and returns the impulse response in vector h. By default this is
a Hamming-window based, linear-phase design with normalized cutoff
frequency in wc which is a number between 0 and 1, where 1 corresponds
to π rad/sample. If wc is a two-element vector, i.e., wc = [wc1 wc2],
Window Design Techniques
271
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
then fir1 returns a bandpass filter with passband cutoffs wc1 and wc2.
If wc is a multi-element (more than two) vector, then fir1 returns a
multiband filter with cutoffs given in wc.
• h = fir1(N,wc,’ftype’) specifies a filter type, where ’ftype’ is:
a. ’high’ for a highpass filter with cutoff frequency Wn.
b. ’stop’ for a bandstop filter, if Wc = [wc1 wc2]. The stopband frequency range is specified by this interval.
c. ’DC-1’ to make the first band of a multiband filter a passband.
d. ’DC-0’ to make the first band of a multiband filter a stopband.
• h = fir1(N,wc,’ftype’,window) or h = fir1(N,wc,window) uses
the vector window of length N+1 obtained from one of the specified
MATLAB window function. The default window function used is the
Hamming window.
To design FIR filters using the Kaiser window, the SP toolbox provides the function kaiserord which estimates window parameters that
can be used in the fir1 function. The basic syntax is
[N,wc,beta,ftype] = kaiserord(f,m,ripple);
The function computes the window order N, the cutoff frequency vector
wc, parameter β in beta, and the filter type ftype as discussed above. The
vector f is a vector of normalized band edges and m is a vector specifying
the desired amplitude on the bands defined by f. The length of f is twice
the length of m, minus 2; i.e., f does not contain 0 or 1. The vector ripple
specifies tolerances in each band (not in decibels). Using the estimated
parameters, Kaiser window array can be computed and used in the fir1
function.
To design FIR filters using window technique with arbitrary shaped
magnitude response, the SP toolbox provides the function fir2, which
also incorporates the frequency sampling technique. It is explained in the
following section.
FREQUENCY SAMPLING DESIGN TECHNIQUES
In this design approach we use the fact that the system function H (z)
can be obtained from the samples H(k) of the frequency response H(ejω ).
Furthermore, this design technique fits nicely with the frequency sampling
structure that we discussed in Chapter 6. Let h(n) be the impulse response
of an M -point FIR filter, H(k) be its M -point DFT, and H(z) be its
272
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
system function. Then from (6.12) we have
H (z) =
M
−1
h (n) z −n =
n=0
and
H(ejω ) =
M −1
H(k)
1 − e−jωM −jω
M
1−e
ej2πk/M
k=0
with
M −1
H(k)
1 − z −M −1 ej2πk/M
M
1
−
z
k=0
H (k) = H ej2πk/M
=
H (0) ,
(7.33)
(7.34)
k=0
H ∗ (M − k) , k = 1, . . . , M − 1
For a linear-phase FIR filter we have
h(n) = ±h(M − 1 − n),
n = 0, 1, . . . , M − 1
where the positive sign is for the Type-1 and Type-2 linear-phase filters,
while the negative sign is for the Type-3 and Type-4 linear-phase filters.
Then H (k) is given by
H (k) = Hr
where
Hr




 −
H (k) =



+
and
M −1
2
M −1
2
2πk
M
2πk
M
ej
H(k)

k=0
Hr (0) ,
=
Hr 2π(M −k) , k = 1, . . . , M − 1
M
(7.35)
(7.36)
!
M −1
2
, (Type-1 & 2)
!
M −1
2π
(M − k) , k =
+ 1, . . . , M − 1
M
2
(7.37)
2πk
M
,
k = 0, . . . ,
or
!

M −1
2πk
M −1
π

−
, k = 0, . . . ,

±


2
2
M
2



 π
M − 1 2π
+
(M − k) ,
H (k) = − ±
, (Type-3 & 4)

2
2
M


!



M −1

(7.38)

k=
+ 1, . . . , M − 1
2
Frequency Sampling Design Techniques
273
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Finally, we have
(7.39)
h(n) = IDFT [H(k)]
Note that several textbooks (e.g., [18, 22, 23]) provide explicit formulas to compute h(n), given H(k). We will use MATLAB’s ifft function
to compute h(n) from (7.39).
Basic Idea Given the ideal lowpass filter Hd (ejω ), choose the filter
length M and then sample Hd (ejω ) at M equispaced frequencies between
0 and 2π. The actual response H(ejω ) is the interpolation of the samples
H(k) given by (7.34). This is shown in Figure 7.25. The impulse response
is given by (7.39). Similar steps apply to other frequency-selective filters.
Furthermore, this idea can also be extended for approximating arbitrary
frequency-domain specifications.
From Figure 7.25 we observe the following:
1. The approximation error—that is, the difference between the ideal and
the actual response—is zero at the sampled frequencies.
2. The approximation error at all other frequencies depends on the shape
of the ideal response; that is, the sharper the ideal response, the larger
the approximation error.
3. The error is larger near the band edges and smaller within the band.
There are two design approaches. In the first approach we use the
basic idea literally and provide no constraints on the approximation error; that is, we accept whatever error we get from the design. This approach is called a naive design method. In the second approach we try to
minimize error in the stopband by varying values of the transition band
samples. It results in a much better design called an optimum design
method.
Hd (e jw )
H (e jw )
Ideal Response and
Frequency Samples
1
0
0
1
2
3
4
5
6
7
8
FIGURE 7.25
274
9 10 p
Frequency Samples and
Approximated Response
1
kw
0
0
1
2
3 4
5
6
7
8
9 10 p
kw
Pictorial description of frequency sampling technique
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
NAIVE DESIGN
METHOD
In this method we set H(k) = Hd (ej2πk/M ), k = 0, . . . , M − 1 and use
(7.35) through (7.39) to obtain the impulse response h(n).
Consider the lowpass filter specifications from Example 7.8.
EXAMPLE 7.14
ωp = 0.2π,
Rp = 0.25 dB
ωs = 0.3π,
As = 50 dB
Design an FIR filter using the frequency sampling approach.
Solution
Let us choose M = 20 so that we have a frequency sample at ωp , that is, at
k = 2:
ωp = 0.2π =
2π
2
20
and the next sample at ωs , that is, at k = 3:
ωs = 0.3π =
2π
3
20
Thus we have 3 samples in the passband [0 ≤ ω ≤ ωp ] and 7 samples in the
stopband [ωs ≤ ω ≤ π]. From (7.36) we have
Hr (k) = [1, 1, 1, 0, . . . , 0 , 1, 1]
" #$ %
15 zeros
Since M = 20, α =
from (7.37) we have
20−1
2
H (k) =
= 9.5 and since this is a Type-2 linear-phase filter,

−9.5 2π k = −0.95πk,
20
+0.95π (20 − k) ,
0≤k≤9
10 ≤ k ≤ 19
Now from (7.35) we assemble H (k) and from (7.39) determine the impulse
response h (n). The MATLAB script follows:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
M = 20; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hdr = [1,1,0,0]; wdl = [0,0.25,0.25,1]; %Ideal Amp Res for plotting
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
subplot(2,2,1);plot(wl(1:11)/pi,Hrs(1:11),’o’,wdl,Hdr);
axis([0,1,-0.1,1.1]); title(’Frequency Samples: M=20’)
xlabel(’frequency in pi units’); ylabel(’Hr(k)’)
Frequency Sampling Design Techniques
275
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>>
>>
>>
>>
>>
>>
>>
>>
subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3])
title(’Impulse Response’); xlabel(’n’); ylabel(’h(n)’);
subplot(2,2,3); plot(ww/pi,Hr,wl(1:11)/pi,Hrs(1:11),’o’);
axis([0,1,-0.2,1.2]); title(’Amplitude Response’)
xlabel(’frequency in pi units’); ylabel(’Hr(w)’)
subplot(2,2,4);plot(w/pi,db); axis([0,1,-60,10]); grid
title(’Magnitude Response’); xlabel(’frequency in pi units’);
ylabel(’Decibels’);
The time- and the frequency-domain plots are shown in Figure 7.26. Observe
that the minimum stopband attenuation is about 16 dB, which is clearly unacceptable. If we increase M , then there will be samples in the transition band,
for which we do not precisely know the frequency response. Therefore the naive
design method is seldom used in practice.
OPTIMUM
DESIGN
METHOD
To obtain more attenuation, we will have to increase M and make the
transition band samples free samples—that is, we vary their values to
obtain the largest attenuation for the given M and the transition width.
This problem is known as an optimization problem, and it is solved using
linear programming techniques. We demonstrate the effect of transition
band sample variation on the design using the following example.
Frequency Samples: M=20
Impulse Response
1
h(n)
Hr(k)
0.2
0.1
0
0
0
0.2 0.3
frequency in pi units
1
0.1
0
Amplitude Response
5
10
n
15
20
Magnitude Response
0
Hr(w)
Decibels
1
16
0
0
0.2 0.3
frequency in pi units
FIGURE 7.26
276
1
0
0.2 0.3
frequency in pi units
1
Naive frequency sampling design method
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 7.15
Solution
Using the optimum design method, design a better lowpass filter of Example
7.14.
Let us choose M = 40 so that we have one sample in the transition band
0.2π < ω < 0.3π. Since ω1 = 2π/40, the transition band samples are at k = 5
and at k = 40 − 5 = 35. Let us denote the value of these samples by T1 ,
0 < T1 < 1; then the sampled amplitude response is
Hr (k) = [1, 1, 1, 1, 1, T1 , 0, . . . , 0 , T1 , 1, 1, 1, 1]
" #$ %
29 zeros
Since α =
40−1
2
= 19.5, the samples of the phase response are
H (k) =

−19.5 2π k = −0.975πk,
40
+0.975π (40 − k) ,
0 ≤ k ≤ 19
20 ≤ k ≤ 39
Now we can vary T1 to get the best minimum stopband attenuation. This will
result in the widening of the transition width. We first see what happens when
T1 = 0.5 using the following MATLAB script.
% T1 = 0.5
>> M = 40; alpha = (M-1)/2;
>> Hrs = [ones(1,5),0.5,zeros(1,29),0.5,ones(1,4)];
>> k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
>> angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
>> H = Hrs.*exp(j*angH);
>> h = real(ifft(H,M));
From the plots of this design in Figure 7.27 we observe that the minimum
stopband attenuation is now 30 dB, which is better than the naive design attenuation but is still not at the acceptable level of 50 dB. The best value for T1
was obtained by varying it manually (although more efficient linear programming techniques are available, these were not used in this case), and the near
optimum solution was found at T1 = 0.39. The resulting filter is a obtained
using the following MATLAB script.
% T1 = 0.39
>> M = 40; alpha = (M-1)/2;
>> Hrs = [ones(1,5),0.39,zeros(1,29),0.39,ones(1,4)];
>> k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
>> angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
>> H = Hrs.*exp(j*angH); h = real(ifft(H,M));
From the plots in Figure 7.28 we observe that the optimum stopband attenuation is 43 dB. It is obvious that to further increase the attenuation, we will
have to vary more than one sample in the transition band.
Frequency Sampling Design Techniques
277
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Frequency Samples: M=40,T1=0.5
Impulse Response
1
h(n)
Hr(k)
0.2
0.5
0.1
0
0
0
0.2 0.3
frequency in pi units
1
−0.1
0
Amplitude Response
20
n
30
40
Magnitude Response
1
0
Decibels
Hr(w)
10
0.5
30
0
0
FIGURE 7.27
0.2 0.3
frequency in pi units
1
0
0.2 0.3
frequency in pi units
1
Optimum frequency design method: T1 = 0.5
Frequency Samples: M=40,T1=0.39
Impulse Response
1
h(n)
Hr(k)
0.2
0.39
0.1
0
0
0
0.2 0.3
frequency in pi units
1
−0.1
0
Amplitude Response
20
n
30
40
Magnitude Response
1
0
Decibels
Hr(w)
10
0.39
43
0
0
FIGURE 7.28
278
0.2 0.3
frequency in pi units
1
0
0.2 0.3
frequency in pi units
1
Optimum frequency design method: T1 = 0.39
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Clearly, this method is superior in that by varying one sample we
can get a much better design. In practice the transition bandwidth is
generally small, containing either one or two samples. Hence we need to
optimize at most two samples to obtain the largest minimum stopband
attenuation. This is also equivalent to minimizing the maximum side lobe
magnitudes in the absolute sense. Hence this optimization problem is also
called a minimax problem. This problem is solved by Rabiner et al. [23],
and the solution is available in the form of tables of transition values.
A selected number of tables are also available in [22, Appendix B]. This
problem can also be solved in MATLAB, but it would require the use of
the Optimization toolbox. We will consider a more general version of this
problem in the next section. We now illustrate the use of these tables in
the following examples.
EXAMPLE 7.16
Solution
Let us revisit our lowpass filter design in Example 7.14. We will solve it using two
samples in the transition band so that we can get a better stopband attenuation.
Let us choose M = 60 so that there are two samples in the transition band. Let
the values of these transition band samples be T1 and T2 . Then Hr (ω) is given
by
H (ω) = [1, . . . , 1 , T1 , T2 , 0, . . . , 0 , T2 , T1 , 1, . . . , 1 ]
" #$ %
" #$ %
" #$ %
7 ones
43 zeros
6 ones
From tables in [22, Appendix B] T1 = 0.5925 and T2 = 0.1099. Using these
values, we use MATLAB to compute h (n).
>>
>>
>>
>>
>>
>>
>>
M = 60; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [ones(1,7),0.5925,0.1099,zeros(1,43),0.1099,0.5925,ones(1,6)];
Hdr = [1,1,0,0]; wdl = [0,0.2,0.3,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
The time- and the frequency-domain plots are shown in Figure 7.29. The minimum stopband attenuation is now at 63 dB, which is acceptable.
EXAMPLE 7.17
Design the bandpass filter of Example 7.10 using the frequency sampling technique. The design specifications are these:
Frequency Sampling Design Techniques
lower stopband edge:
ω1s = 0.2π,
As = 60 dB
lower passband edge:
ω1p = 0.35π,
Rp = 1 dB
upper passband edge:
ω2p = 0.65π
Rp = 1 dB
upper stopband edge:
ω2s = 0.8π
As = 60 dB
279
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Lowpass: M=60,T1=0.59, T2=0.109
Impulse Response
1
0.59
h(n)
Hr(k)
0.2
0.1
0
0.109
0
0
0.2 0.3
frequency in pi units
−0.1
1
0
40
60
n
Amplitude Response
Magnitude Response
1
0
Decibels
Hr(w)
20
0.59
63
0.109
0
0
0.2 0.3
frequency in pi units
FIGURE 7.29
Solution
1
0
0.2 0.3
frequency in pi units
1
Lowpass filter design plots in Example 7.16
Let us choose M = 40 so that we have two samples in the transition band.
Let the frequency samples in the lower transition band be T1 and T2 . Then the
samples of the amplitude response are
Hr (ω) = [0, . . . , 0 , T1 , T2 , 1, . . . , 1 , T2 , T1 , 0, . . . , 0 , T1 , T2 , 1, . . . , 1 , T2 , T1 , 0, . . . , 0 ]
" #$ %
" #$ %
" #$ %
" #$ %
" #$ %
5
7
9
7
4
The optimum values of T1 and T2 for M = 40 and seven samples in the passband
[19, Appendix B] are
T1 = 0.109021,
T2 = 0.59417456
The MATLAB script is
>>
>>
>>
>>
>>
>>
>>
>>
M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
T1 = 0.109021; T2 = 0.59417456;
Hrs=[zeros(1,5),T1,T2,ones(1,7),T2,T1,zeros(1,9),T1,T2,ones(1,7),T2,T1,zeros(1,4)];
Hdr = [0,0,1,1,0,0]; wdl = [0,0.2,0.35,0.65,0.8,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
The plots in Figure 7.30 show an acceptable bandpass filter design.
280
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 7.18
Solution
Design the following highpass filter:
Stopband edge:
ωs = 0.6π
As = 50 dB
Passband edge:
ωp = 0.8π
Rp = 1 dB
Recall that for a highpass filter M must be odd (or Type-1 filter). Hence we
will choose M = 33 to get two samples in the transition band. With this choice
of M it is not possible to have frequency samples at ωs and ωp . The samples of
the amplitude response are
Hr (k) = [0, . . . , 0 , T1 , T2 , 1, . . . , 1 , T2 , T1 , 0, . . . , 0 ]
" #$ %
" #$ %
" #$ %
11
8
10
while the phase response samples are
H (k) =

33 − 1 2π
32

−
k = − πk,
0 ≤ k ≤ 16

+ 32 π (33 − k) ,
17 ≤ k ≤ 32
2
33
33
33
The optimum values of transition samples are T1 = 0.1095 and T2 = 0.598.
Using these values, the MATLAB design is given in the following script.
Bandpass: M=40,T1=0.5941, T2=0.109
Impulse Response
0.4
1
0.59
h(n)
Hr(k)
0.2
−0.2
0.109
0
0
0
0.2 0.35
0.65 0.8
frequency in pi units
1
−0.4
0
Amplitude Response
20
n
30
40
Magnitude Response
1
0
Decibels
Hr(w)
10
0.59
60
0.109
0
0
FIGURE 7.30
Frequency Sampling Design Techniques
0.2 0.35
0.65 0.8
frequency in pi units
1
0
0.2 0.35
0.65 0.8
frequency in pi units
1
Bandpass filter design plots in Example 7.17
281
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>>
>>
>>
>>
>>
>>
>>
>>
M = 33; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
T1 = 0.1095; T2 = 0.598;
Hrs = [zeros(1,11),T1,T2,ones(1,8),T2,T1,zeros(1,10)];
Hdr = [0,0,1,1]; wdl = [0,0.6,0.8,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type1(h);
The time- and the frequency-domain plots of the design are shown in Figure
7.31.
EXAMPLE 7.19
Solution
Design a 33-point digital differentiator based on the ideal differentiator of (7.31)
given in Example 7.12.
From (7.31) the samples of the (imaginary-valued) amplitude response are given
by

2π

+j k,
jHr (k) =
&
'
M −1
2
&
'
M −1
+ 1, . . . , M − 1
k=
2
k = 0, . . . ,
M

−j 2π (M − k) ,
M
Highpass: M=33,T1=0.1095,T2=0.598
Impulse Response
0.4
1
0.59
h(n)
Hr(k)
0.2
0
−0.2
0.109
0
0
.6
.8
frequency in pi units
1
−0.4
0
20
30
n
Amplitude Response
Magnitude Response
1
0
Decibels
Hr(w)
10
0.59
50
0.109
0
0
FIGURE 7.31
282
.6
.8
frequency in pi units
1
0
.6
.8
frequency in pi units
1
Highpass filter design plots in Example 7.18
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
and for linear phase the phase samples are

&
'
M − 1 2π
M −1
M −1

k=−
πk, k = 0, . . . ,
−
2 M
M
2
H (k) =
&
'
M
−
1
M
−
1

+
+ 1, . . . , M − 1
π (M − k) ,
k=
M
2
Therefore
H (k) = jHr (k) ej
H(k)
,
0≤k ≤M −1
and
h (n) = IDFT [H (k)]
MATLAB Script:
>>
>>
>>
>>
>>
M = 33; alpha = (M-1)/2; Dw = 2*pi/M; l = 0:M-1; wl = Dw*l;
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
Hrs = [j*Dw*k1,-j*Dw*(M-k2)];
angH = [-alpha*Dw*k1, alpha*Dw*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M)); [Hr,ww,a,P]=Hr_Type3(h);
The time- and the frequency-domain plots are shown in Figure 7.32. We observe
that the differentiator is not a full-band differentiator.
EXAMPLE 7.20
Design a 51-point digital Hilbert transformer based on the ideal Hilbert transformer of (7.32).
Differentiator, frequency sampling design : M = 33
Hr in pi units
1.5
1
0.5
0
−0.5
0
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
1
Impulse response
1
h(n)
0.5
0
−0.5
−1
0
FIGURE 7.32
Frequency Sampling Design Techniques
16
n
32
Differentiator design plots in Example 7.19
283
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
From (7.32) the samples of the (imaginary-valued) amplitude response are
given by



−j,


jHr (k) =
0,




+j,
&
k = 1, . . . ,
k=0
&
k=
M −1
2
'
'
M −1
+ 1, . . . , M − 1
2
Since this is a Type-3 linear-phase filter, the amplitude response will be zero
at ω = π. Hence to reduce the ripples, we should choose the two samples (in
transition bands) near ω = π optimally between 0 and j. Using our previous
experience, we could select this value as 0.39j. The samples of the phase response
are selected similar to those in Example 7.19.
MATLAB Script:
>>
>>
>>
>>
>>
M = 51; alpha = (M-1)/2; Dw = 2*pi/M; l = 0:M-1; wl = Dw*l;
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
Hrs = [0,-j*ones(1,(M-3)/2),-0.39j,0.39j,j*ones(1,(M-3)/2)];
angH = [-alpha*Dw*k1, alpha*Dw*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M)); [Hr,ww,a,P]=Hr_Type3(h);
The plots in Figure 7.33 show the effect of the transition band samples.
Amplitude response
Hilbert Transformer, frequency sampling design : M = 51
1
0.39
0
0
0.2
0.4
0.6
frequency in pi units
0.8
1
Impulse response
1
h(n)
0.5
0
−0.5
−1
0
FIGURE 7.33
284
25
n
50
Digital Hilbert transformer design plots in Example 7.20
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The SP toolbox provides a function called fir2 which combines frequency sampling technique with the window technique to design arbitrary
shaped magnitude response FIR filters. After computing filter impulse response using the naive design method, fir2 then applies a selected window to minimize ripples near the band-edge frequencies. This function’s
syntax also has several forms including:
• h = fir2(N,f,m) designs an N th-order (N = M −1) lowpass FIR filter
and returns the impulse response in vector h. The desired magnitude
response of the filter is supplied in vectors f and m, which must be
of the same length. The vector f contains normalized frequencies in
the range from 0 to 1, where 1 corresponds to π rad/sample. The first
value of f must be 0 and the last value 1. The vector m, contains the
samples of the desired magnitude response at the values specified in f.
The desired frequency response is then interpolated onto a dense, evenly
spaced grid of length 512. Thus, this syntax corresponds to the naive
design method.
• h = fir2(N,f,m,window) uses the vector window of length N+1
tained from one of the specified MATLAB window function. The
fault window function used is the Hamming window.
• h = fir2(N,f,m,npt) or h = fir2(N,f,m,npt,window) specifies
number of points, npt, for the grid onto which fir2 interpolates
frequency response. The default npt value is 512.
obdethe
the
It should be noted that the fir2 does not implement the classic optimum frequency sampling method. By incorporating window design, fir2
has found an alternative (and somewhat clever) approach to do away with
the optimum transition band values and the associated tables. By densely
sampling values in the entire band, interpolation errors are reduced (but
not minimized), and stopband attenuation is increased to an acceptable
level. However, the basic design is contaminated by the window operation;
hence, the frequency response does not go through the original sampled
values. It is more suitable for designing FIR filters with arbitrary shaped
frequency responses.
The type of frequency sampling filter that we considered is called a
Type-A filter, in which the sampled frequencies are
2π
k, 0 ≤ k ≤ M − 1
M
There is a second set of uniformly spaced samples given by
ωk =
2π k + 12
, 0≤k ≤M −1
M
This is called a Type-B filter, for which a frequency sampling structure is
also available. The expressions for the magnitude response H(ejω ) and the
impulse response h(n) are somewhat more complicated and are available
ωk =
Frequency Sampling Design Techniques
285
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
in [22]. Their design can also be done in MATLAB using the approach
discussed in this section.
OPTIMAL EQUIRIPPLE DESIGN TECHNIQUE
The last two techniques—namely, the window design and the frequency
sampling design—were easy to understand and implement. However, they
have some disadvantages. First, we cannot specify the band frequencies
ωp and ωs precisely in the design; that is, we have to accept whatever
values we obtain after the design. Second, we cannot specify both δ1 and
δ2 ripple factors simultaneously. Either we have δ1 = δ2 in the window
design method, or we can optimize only δ2 in the frequency sampling
method. Finally, the approximation error—that is, the difference between
the ideal response and the actual response—is not uniformly distributed
over the band intervals. It is higher near the band edges and smaller in
the regions away from band edges. By distributing the error uniformly,
we can obtain a lower-order filter satisfying the same specifications. Fortunately, a technique exists that can eliminate the above three problems.
This technique is somewhat difficult to understand and requires a computer for its implementation.
For linear-phase FIR filters it is possible to derive a set of conditions
for which it can be proved that the design solution is optimal in the sense
of minimizing the maximum approximation error (sometimes called the
minimax or the Chebyshev error). Filters that have this property are called
equiripple filters because the approximation error is uniformly distributed
in both the passband and the stopband. This results in lower-order filters.
In the following we first formulate a minimax optimal FIR design
problem and discuss the total number of maxima and minima (collectively called extrema) that one can obtain in the amplitude response of
a linear-phase FIR filter. Using this, we then discuss a general equiripple
FIR filter design algorithm, which uses polynomial interpolation for its solution. This algorithm is known as the Parks-McClellan algorithm, and it
incorporates the Remez exchange algorithm for polynomial solution. This
algorithm is available as a subroutine on many computing platforms. In
this section we will use MATLAB to design equiripple FIR filters.
DEVELOPMENT
OF THE
MINIMAX
PROBLEM
Earlier in this chapter we showed that the frequency response of the four
cases of linear-phase FIR filters can be written in the form
H(ejω ) = ejβ e−j
M −1
2 ω
Hr (w)
where the values for β and the expressions for Hr (ω) are given in
Table 7.2.
286
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
TABLE 7.2
Amplitude response and β-values for linear-phase FIR filters
Linear-phase FIR Filter Type
β
Type-1: M odd, symmetric h(n)
0
Hr (ejω )
(
(M −1)/2
a(n) cos ωn
0
(
M/2
Type-2: M even, symmetric h(n)
0
b(n) cos [ω(n − 1/2)]
1
Type-3: M odd, antisymmetric h(n)
Type-4: M even, antisymmetric h(n)
(
(M −1)/2
π
2
π
2
c(n) sin ωn
1
(
M/2
d(n) sin [ω(n − 1/2)]
1
Using simple trigonometric identities, each expression for Hr (ω) above
can be written as a product of a fixed function of ω (call this Q(ω)) and a
function that is a sum of cosines (call this P (ω)). For details see [22] and
Problems P7.2–P7.5. Thus
(7.40)
Hr (ω) = Q(ω)P (ω)
where P (ω) is of the form
P (ω) =
L
(7.41)
α(n) cos ωn
n=0
and Q(ω), L, P (ω) for the four cases are given in Table 7.3.
TABLE 7.3
Q(ω), L, and P (ω) for linear-phase FIR filters
LP FIR Filter Type
Q(ω)
L
Type-1
1
M −1
2
Type-2
Type-3
Type-4
Optimal Equiripple Design Technique
ω
2
M
−1
2
sin ω
M −3
2
cos
sin
ω
2
M
−1
2
P (ω)
L
(
a(n) cos ωn
0
L
(
b̃(n) cos ωn
0
L
(
c̃(n) cos ωn
0
L
(
˜ cos ωn
d(n)
0
287
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The purpose of the previous analysis was to have a common form
for Hr (ω) across all four cases. It makes the problem formulation much
easier. To formulate our problem as a Chebyshev approximation problem,
we have to define the desired amplitude response Hdr (ω) and a weighting
function W (ω), both defined over passbands and stopbands. The weighting function is necessary so that we can have an independent control over
δ1 and δ2 . The weighted error is defined as
E (ω) = W (ω) [Hdr (ω) − Hr (ω)] ,
ω ∈ S = [0, ωp ] ∪ [ωs , π]
(7.42)
These concepts are made clear in the following set of figures. It shows a
typical equiripple filter response along with its ideal response.
Amplitude Response of an Equiripple Filter
1.10
1.0
Ideal Response
0.90
0.05
0.0
−0.05
0
Ideal Response
0.3
0.5
frequency in pi units
1
The error [Hdr (ω) − Hr (ω)] response is shown below.
Error Function
0.10
0.05
0.0
−0.05
−0.10
0
288
0.3
0.5
frequency in pi units
Chapter 7
1
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Now if we choose

 δ2 ,
W (ω) = δ1

1,
in the passband
(7.43)
in the stopband
Then the weighted error E(ω) response is
Weighted Error Function
weight = 0.5
weight = 1.0
0.05
0.0
−0.05
0
0.3
0.5
frequency in pi units
1
Thus the maximum error in both the passband and stopband is δ2 . Therefore, if we succeed in minimizing the maximum weighted error to δ2 , we
automatically also satisfy the specification in the passband to δ1 . Substituting Hr (ω) from (7.40) into (7.42), we obtain
E (ω) = W (ω) [Hdr (ω) − Q (ω) P (ω)]
Hdr (ω)
− P (ω) ,
= W (ω) Q (ω)
Q (ω)
ω∈S
If we define
Ŵ (ω) = W (ω)Q(w)
then we obtain
and
Ĥdr (ω) =
E(ω) = Ŵ (ω) Ĥdr (ω) − P (ω) ,
Hdr (ω)
Q (ω)
ω∈S
(7.44)
Thus we have a common form of E(ω) for all four cases.
Problem Statement
be defined as:
The Chebyshev approximation problem can now
˜ [or equivaDetermine the set of coefficients a(n) or b̃(n) or c̃(n) or d(n)
lently a(n) or b(n) or c(n) or d(n)] to minimize the maximum absolute
value of E (ω) over the passband and stopband, i.e.,
max |E (ω)|
(7.45)
min
over coeff.
Optimal Equiripple Design Technique
ω∈S
289
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Now we have succeeded in specifying the exact ωp , ωs , δ1 , and δ2 . In
addition the error can now be distributed uniformly in both the passband
and stopband.
CONSTRAINT
ON THE
NUMBER OF
EXTREMA
Before we give the solution to the above problem, we will first discuss
the issue: how many local maxima and minima exist in the error function
E(ω) for a given M -point filter? This information is used by the ParksMcClellan algorithm to obtain the polynomial interpolation. The answer
is in the expression P (ω). From (7.41) P (ω) is a trigonometric function
in ω. Using trigonometric identities of the form
cos (2ω) = 2 cos2 (ω) − 1
cos (3ω) = 4 cos3 (ω) − 3 cos (ω)
..
.
. = ..
P (ω) can be converted to a trigonometric polynomial in cos (ω), which
we can write (7.41) as
P (ω) =
L
β(n) cosn ω
(7.46)
n=0
EXAMPLE 7.21
1
Let h(n) = 15
[1, 2, 3, 4, 3, 2, 1] . Then M = 7 and h(n) is symmetric, which
means that we have a Type-1 linear-phase filter. Hence L = (M − 1)/2 = 3.
Now from (7.7)
α(n) = a(n) = 2h(3 − n),
or α(n) =
1
[4, 6, 4, 2].
15
P (ω) =
3
0
=
1
15
1 ≤ n ≤ 2;
α(0) = a(0) = h(3)
Hence
α(n) cos ωn =
and
1
15
(4 + 6 cos ω + 4 cos 2ω + 2 cos 3ω)
4 + 6 cos ω + 4(2 cos2 ω − 1) + 2(4 cos3 ω − 3 cos ω)
= 0+0+
8
15
cos2 ω +
8
15
cos3 ω =
3
β(n) cosn ω
0
8 8
.
,
15 15
From (7.46) we note that P (ω) is an Lth-order polynomial in cos(ω). Since
cos(ω) is a monotone function in the open interval 0 < ω < π, then it follows
that the Lth-order polynomial P (ω) in cos(ω) should behave like an ordinary
Lth-order polynomial P (x) in x. Therefore P (ω) has at most (i.e., no more
or β(n) = 0, 0,
290
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
than) (L − 1) local extrema in the open interval 0 < ω < π. For example,
cos2 (ω) =
1 + cos 2ω
2
has only one minimum at ω = π/2. However, it has three extrema in the closed
interval 0 ≤ ω ≤ π (i.e., a maximum at ω = 0, a minimum at ω = π/2, and
a maximum at ω = π). Now if we include the end points ω = 0 and ω = π,
then P (ω) has at most (L + 1) local extrema in the closed interval 0 ≤ ω ≤ π.
Finally, we would like the filter specifications to be met exactly at band edges
ωp and ωs . Then the specifications can be met at no more than (L + 3) extremal
frequencies in the 0 ≤ ω ≤ π interval.
Conclusion
EXAMPLE 7.22
Solution
The error function E(ω) has at most (L + 3) extrema in S. Let us plot the amplitude response of the filter given in Example 7.21 and count
the total number of extrema in the corresponding error function.
The impulse response is
h(n) =
and α(n) =
1
[1, 2, 3, 4, 3, 2, 1],
15
1
[4, 6, 4, 2]
15
and β(n) = 0, 0,
P (ω) =
M =7
8
, 8
15 15
or
L=3
from Example 7.21. Hence
8
8
cos2 ω +
cos3 ω
15
15
which is shown in Figure 7.34. Clearly, P (ω) has (L − 1) = 2 extrema in the
open interval 0 < ω < π. Also shown in Figure 7.34 is the error function, which
has (L + 3) = 6 extrema.
Let us now turn our attention to the problem statement and equation (7.45). It is a well-known problem in approximation theory, and the
solution is given by the following important theorem.
THEOREM 1
Alternation Theorem
Let S be any closed subset of the closed interval [0, π]. In order that
P (ω) be the unique minimax approximation to Hdr (ω) on S, it is necessary
and sufficient that the error function E(ω) exhibit at least (L + 2) “alternations” or extremal frequencies in S; that is, there must exist (L + 2)
frequencies ωi in S such that
E (ωi ) = −E (ωi−1 ) = ± max |E (ω)|
S
(7.47)
= ±δ, ∀ ω0 < ω1 < · · · < ωL+1 ∈ S
Combining this theorem with our earlier conclusion, we infer that
the optimal equiripple filter has either (L + 2) or (L + 3) alternations
Optimal Equiripple Design Technique
291
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1.07
Amplitude Response
1.0
0.93
Error Function
L +3 =6
extrema
0.07
w /p
0
−0.07
0.4
0.1
1
L −1 =2
extrema
0.04
0.0
−0.04
w /p
0.1
FIGURE 7.34
0.4
1
Amplitude response and the error function in Example 7.22
in its error function over S. Most of the equiripple filters have (L + 2)
alternations. However, for some combinations of ωp and ωs , we can get
filters with (L+3) alternations. These filters have one extra ripple in their
response and hence are called Extra-ripple filters.
PARKSMcCLELLAN
ALGORITHM
292
The alternation theorem ensures that the solution to our minimax approximation problem exists and is unique, but it does not tell us how
to obtain this solution. We know neither the order M (or equivalently,
L), nor the extremal frequencies ωi , nor the parameters {α(n)}, nor the
maximum error δ. Parks and McClellan [19] provided an iterative solution
using the Remez exchange algorithm. It assumes that the filter length M
(or L) and the ratio δ2 /δ1 are known. If we choose the weighting function
as in (7.43), and if we choose the order M correctly, then δ = δ2 when
the solution is obtained. Clearly, δ and M are related; the larger the M ,
the smaller the δ. In the filter specifications δ1 , δ2 , ωp , and ωs are given.
Therefore M has to be assumed. Fortunately, a simple formula, due to
Kaiser, exists for approximating M . It is given by
√
−20 log10 δ1 δ2 − 13
+ 1; ∆ω = ωs − ωp
(7.48)
M̂ =
2.285∆ω
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The Parks-McClellan algorithm begins by guessing (L + 2) extremal
frequencies {ωi } and estimating the maximum error δ at these frequencies.
It then fits an Lth-order polynomial (7.46) through points given in (7.47).
Local maximum errors are determined over a finer grid, and the extremal
frequencies {ωi } are adjusted at these new extremal values. A new Lthorder polynomial is fit through these new frequencies, and the procedure
is repeated. This iteration continues until the optimum set {ωi } and the
global maximum error δ are found. The iterative procedure is guaranteed
to converge, yielding the polynomial P (ω). From (7.46) coefficients β(n)
are determined. Finally, the coefficients a(n) as well as the impulse response h(n) are computed. This algorithm is available in MATLAB as
the firpm function, which is described below.
Since we approximated M , the maximum error δ may not be equal to
δ2 . If this is the case, then we have to increase M (if δ > δ2 ) or decrease
M (if δ < δ2 ) and use the firpm algorithm again to determine a new
δ. We repeat this procedure until δ ≤ δ2 . The optimal equiripple FIR
filter, which satisfies all the three requirements discussed earlier is now
determined.
MATLAB
IMPLEMENTATION
The Parks-McClellan algorithm is available in MATLAB as a function
called firpm, the most general syntax of which is
[h] = firpm(N,f,m,weights,ftype)
There are several versions of this syntax
• [h] = firpm(N,f,m) designs an Nth-order (note that the length of the
filter is M = N + 1) FIR digital filter whose frequency response is
specified by the arrays f and m. The filter coefficients (or the impulse
response) are returned in array h of length M . The array f contains
band-edge frequencies in units of π, that is, 0.0 ≤ f ≤ 1.0. These frequencies must be in increasing order, starting with 0.0 and ending with
1.0. The array m contains the desired magnitude response at frequencies
specified in f. The lengths of f and m arrays must be same and must
be an even number. The weighting function used in each band is equal
to unity, which means that the tolerances (δi ’s) in every band are the
same.
• [h] = firpm(N,f,m,weights) is similar to the above case except that
the array weights specifies the weighting function in each band.
• [h] = firpm(N,f,m,ftype) is similar to the first case except when
ftype is the string ‘differentiator’ or ‘hilbert’, it designs digital
differentiators or digital Hilbert transformers, respectively. For the digital Hilbert transformer the lowest frequency in the f array should not
Optimal Equiripple Design Technique
293
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
be 0, and the highest frequency should not be 1. For the digital differentiator, the m vector does not specify the desired slope in each band
but the desired magnitude.
• [h] = firpm(N,f,m,weights,ftype) is similar to the above case except that the array weights specifies the weighting function in each
band.
To estimate the filter order N , the SP toolbox provides the function
firpmord which also estimates other parameters that can be used in the
firpm function. The basic syntax is
[N,f0,m0,weights] = firpmord(f,m,delta);
The function computes the window order N, the normalized frequency
band edges in f0, amplitude response in a0, and the band weights in
weights. The vector f is a vector of normalized band edges and m is a
vector specifying the desired amplitude on the bands defined by f. The
length of f is two less than twice the length of m; i.e., f does not contain 0
or 1. The vector delta specifies tolerances in each band (not in decibels).
The estimated parameters can now be used in the firpm function.
As explained during the description of the Parks-McClellan algorithm,
we have to first guess the order of the filter using (7.48) to use the function
firpm. After we obtain the filter coefficients in array h, we have to check
the minimum stopband attenuation and compare it with the given As
and then increase (or decrease) the filter order. We have to repeat this
procedure until we obtain the desired As . We illustrate this procedure in
the following several MATLAB examples. These examples also use the
ripple conversion function db2delta which is developed in Problem P7.1.
EXAMPLE 7.23
Let us design the lowpass filter described in Example 7.8 using the ParksMcClellan algorithm. The design parameters are
ωp = 0.2π ,
Rp = 0.25 dB
ωs = 0.3π ,
As = 50 dB
We provide a MATLAB script to design this filter.
>> wp = 0.2*pi; ws = 0.3*pi; Rp = 0.25; As = 50;
>> [delta1,delta2] = db2delta(Rp,As);
>> [N,f,m,weights] = firpmord([wp,ws]/pi,[1,0],[delta1,delta2]);
>> h = firpm(N,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> delta_w = 2*pi/1000; wsi=ws/delta_w+1; wpi = wp/delta_w;
>> Asd = -max(db(wsi:1:501))
Asd = 47.8404
294
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> N = N+1
N = 43
>> h = firpm(N,f,m,weights);
>> Asd = -max(db(wsi:1:501))
Asd = 48.2131
>> N = N+1
N = 44
>> h = firpm(N,f,m,weights);
>> Asd = -max(db(wsi:1:501))
Asd = 48.8689
>> N = N+1
N = 45
>> h = firpm(N,f,m,weights);
>> Asd = -max(db(wsi:1:501))
Asd = 49.8241
>> N = N+1
N = 46
>> h = firpm(N,f,m,weights);
>> Asd = -max(db(wsi:1:501))
Asd = 51.0857
>> M = N+1
M = 47
[db,mag,pha,grd,w] = freqz_m(h,[1]);
[db,mag,pha,grd,w] = freqz_m(h,[1]);
[db,mag,pha,grd,w] = freqz_m(h,[1]);
[db,mag,pha,grd,w] = freqz_m(h,[1]);
Note that we stopped the above iterative procedure when the computed stopband attenuation exceeded the given stopband attenuation As , and the optimal
value of M was found to be 47. This value is considerably lower than the window
design techniques (M = 61 for a Kaiser window) or the frequency sampling technique (M = 60). In Figure 7.35 we show the time- and the frequency-domain
plots of the designed filter along with the error function in both the passband
and the stopband to illustrate the equiripple behavior.
EXAMPLE 7.24
Let us design the bandpass filter described in Example 7.10 using the ParksMcClellan algorithm. The design parameters are:
ω1s = 0.2π
;
Rp = 1 dB
;
As = 60 db
ω1p = 0.35π
ω2p = 0.65π
ω2s = 0.8π
Solution
The following MATLAB script shows how to design this filter.
>> ws1 = 0.2*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.8*pi;
>> Rp = 1.0; As = 60;
>> [delta1,delta2] = db2delta(Rp,As);
Optimal Equiripple Design Technique
295
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> f = [ws1,wp1,wp2,ws2]/pi; m = [0,1,0]; delta = [delta2,delta1,delta2];
>> [N,f,m,weights] = firpmord(f,m,delta); N
N = 26
>> h = firpm(N,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> delta_w=2*pi/1000;
>> ws1i=floor(ws1/delta_w)+1; wp1i = floor(wp1/delta_w)+1;
>> ws2i=floor(ws2/delta_w)+1; wp2i = floor(wp2/delta_w)+1;
>> Asd = -max(db(1:1:ws1i))
Asd = 54.7756
>> N = N+1;
>> h = firpm(N,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> Asd = -max(db(1:1:ws1i))
Asd = 56.5910
>> N = N+1;
>> h = firpm(N,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
Asd = -max(db(1:1:ws1i))
>> Asd = 61.2843
>> M = N+1
M = 29
Actual Impulse Response
Magnitude Response in dB
0.3
0
Decibels
h(n)
0.2
0.1
50
0
−0.1
0
46
0
n
Amplitude Response
0.2 0.3
frequency in pi units
1
Error Response
0.0144
Hr(w)
Hr(w)
1
0
0
FIGURE 7.35
296
0.2 0.3
frequency in pi units
1
0.0032
0
−0.0032
−0.0144
0
0.2 0.3
frequency in pi units
1
Plots for equiripple lowpass FIR filter in Example 7.23
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Actual Impulse Response
Magnitude Response in dB
0.4
0
Decibels
h(n)
0.2
0
−0.2
60
−0.4
0
30
0
n
Amplitude Response
1.0575
0.2 0.35
0.65 0.8
frequency in pi units
× 10−3
1
Weighted Error
Hr(w)
Hr(w)
1
0
0
FIGURE 7.36
0.2 0.35
0.65 0.8
frequency in pi units
1
0
−1.0575
0
0.2 0.35
0.65 0.8
frequency in pi units
1
Plots for equiripple bandpass FIR filter in Example 7.24
The optimal value of M was found to be 29. The time- and the frequency-domain
plots of the designed filter are shown in Figure 7.36.
EXAMPLE 7.25
Solution
Design a highpass filter that has the following specifications:
ωs = 0.6π,
As = 50 dB
ωp = 0.75π,
Rp = 0.5 dB
Since this is a highpass filter, we must ensure that the length M is an odd
number. This is shown in the following MATLAB script.
>> ws = 0.6*pi; wp = 0.75*pi; Rp = 0.5; As = 50;
>> [delta1,delta2] = db2delta(Rp,As);
>> [N,f,m,weights] = firpmord([ws,wp]/pi,[0,1],[delta2,delta1]); N
N = 26
>> h = firpm(N,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> delta_w = 2*pi/1000; wsi=ws/delta_w; wpi = wp/delta_w;
Optimal Equiripple Design Technique
297
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> Asd = -max(db(1:1:wsi))
Asd = 49.5918
>> N = N+2;
>> h = firpm(N,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> Asd = -max(db(1:1:wsi))
>> Asd = 50.2253
>> M = N+1
M = 29
Note also that we increased the value of N by two to maintain its even value.
The optimum M was found to be 29. The time- and the frequency-domain plots
of the designed filter are shown in Figure 7.37.
EXAMPLE 7.26
In this example we will design a “staircase” filter, which has three bands with
different ideal responses and different tolerances in each band. The design specifications are
Band-1:
0 ≤ ω ≤ 0.3π,
Band-2:
Band-3:
Ideal gain = 1,
Tolerance δ1 = 0.01
0.4π ≤ ω ≤ 0.7π,
Ideal gain = 0.5,
Tolerance δ2 = 0.005
0.8π ≤ ω ≤ π,
Ideal gain = 0,
Tolerance δ3 = 0.001
Actual Impulse Response
Magnitude Response in dB
0.4
0
Decibels
h(n)
0.2
0
−0.2
−0.4
0
28
50
0
n
Amplitude Response
0.6 0.75
frequency in pi units
1
Error Response
0.0288
Hr(w)
Hr(w)
1
0
0
FIGURE 7.37
298
0.6 0.75
frequency in pi units
1
0.0033
0
−0.0033
−0.0288
0
0.6 0.75
frequency in pi units
1
Plots for equiripple highpass FIR filter in Example 7.25
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
The following MATLAB script describes the design procedure.
>> w1 = 0; w2 = 0.3*pi; delta1 = 0.01;
>> w3 = 0.4*pi; w4 = 0.7*pi; delta2 = 0.005;
>> w5 = 0.8*pi; w6 = pi; delta3 = 0.001;
>> weights = [delta3/delta1 delta3/delta2 1];
>> Dw = min((w3-w2), (w5-w3));
>> M = ceil((-20*log10((delta1*delta2*delta3)^(1/3))-13)/(2.285*Dw)+1)
>> M = 51
>> f = [0 w2/pi w3/pi w4/pi w5/pi 1];
>> m = [1 1 0.5 0.5 0 0];
>> h = firpm(M-1,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> delta_w = 2*pi/1000;
>> w1i=floor(w1/delta_w)+1; w2i = floor(w2/delta_w)+1;
>> w3i=floor(w3/delta_w)+1; w4i = floor(w4/delta_w)+1;
>> w5i=floor(w5/delta_w)+1; w6i = floor(w6/delta_w)+1;
>> Asd = -max(db(w5i:w6i))
Asd = 62.0745
>> M = M-1; h = firpm(M-1,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> Asd = -max(db(w5i:w6i))
Asd = 60.0299
>> M = M-1; h = firpm(M-1,f,m,weights);
>> [db,mag,pha,grd,w] = freqz_m(h,[1]);
>> Asd = -max(db(w5i:w6i))
Asd = 60.6068
>> M
M = 49
The time- and the frequency-domain plots of the designed filter are shown in
Figure 7.38.
EXAMPLE 7.27
Solution
In this example we will design a digital differentiator with different slopes in
each band. The specifications are
Band-1:
0 ≤ ω ≤ 0.2π,
Slope = 1 sam/cycle
Band-2:
0.4π ≤ ω ≤ 0.6π,
Slope = 2 sam/cycle
Band-3:
0.8π ≤ ω ≤ π,
Slope = 3 sam/cycle
We need desired magnitude response values in each band. These can be obtained by multiplying band-edge frequencies in cycles/sam by the slope values
in sam/cycle
Band-1:
0 ≤ f ≤ 0.1,
Slope = 1 sam/cycle ⇒ 0.0 ≤ |H| ≤ 0.1
Band-2:
0.2 ≤ f ≤ 0.3,
Slope = 2 sam/cycle ⇒ 0.4 ≤ |H| ≤ 0.6
Band-3:
0.4 ≤ f ≤ 0.5,
Slope = 3 sam/cycle ⇒ 1.2 ≤ |H| ≤ 1.5
Optimal Equiripple Design Technique
299
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Actual Impulse Response
Magnitude Response in dB
0.6
0
0.5
Decibels
0.4
h(n)
0.3
0.2
0.1
60
0
−0.1
0
48
0
n
Amplitude Response
1
× 10−3
0.3 0.4
0.7 0.8
frequency in pi units
1
Weighted Error
Hr(w)
Hr(w)
1
0.5
0
0
FIGURE 7.38
0.3 0.4
0.7 0.8
frequency in pi units
1
0
−1
0
0.3 0.4
0.7 0.8
frequency in pi units
1
Plots for equiripple staircase FIR filter in Example 7.26
Let the weights be equal in all bands. The MATLAB script is:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
300
f = [0 0.2 0.4 0.6 0.8 1];
% in w/pi unis
m = [0,0.1,0.4,0.6,1.2,1.5];
% magnitude values
h = firpm(25,f,m,’differentiator’);
[db,mag,pha,grd,w] = freqz_m(h,[1]);
subplot(2,1,1); stem([0:25],h); title(’Impulse Response’);
xlabel(’n’); ylabel(’h(n)’); axis([0,25,-0.6,0.6])
set(gca,’XTickMode’,’manual’,’XTick’,[0,25])
set(gca,’YTickMode’,’manual’,’YTick’,[-0.6:0.2:0.6]);
subplot(2,1,2); plot(w/(2*pi),mag); title(’Magnitude Response’)
xlabel(’Normalized frequency f’); ylabel(’|H|’)
set(gca,’XTickMode’,’manual’,’XTick’,f/2)
set(gca,’YTickMode’,’manual’,’YTick’,[0,0.1,0.4,0.6,1.2,1.5]); grid
The frequency-domain response is shown in Figure 7.39.
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Impulse Response
0.6
0.4
h(n)
0.2
0
−0.2
−0.4
−0.6
0
25
n
Magnitude Response
1.5
|H|
1.2
0.6
0.4
0.1
0
0
FIGURE 7.39
EXAMPLE 7.28
Solution
0.1
0.2
0.3
Normalized frequency f
0.4
0.5
Plots of the differentiator in Example 7.27
Finally, we design a Hilbert transformer over the band 0.05π ≤ ω ≤ 0.95π.
Since this is a wideband Hilbert transformer, we will choose an odd length for
our filter (i.e., a Type-3 filter). Let us choose M = 51. The MATLAB script is:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
f = [0.05,0.95]; m = [1 1]; h = firpm(50,f,m,’hilbert’);
[db,mag,pha,grd,w] = freqz_m(h,[1]);
subplot(2,1,1); stem([0:50],h); title(’Impulse Response’);
xlabel(’n’); ylabel(’h(n)’); axis([0,50,-0.8,0.8])
set(gca,’XTickMode’,’manual’,’XTick’,[0,50])
set(gca,’YTickMode’,’manual’,’YTick’,[-0.8:0.2:0.8]);
subplot(2,1,2); plot(w/pi,mag); title(’Magnitude Response’)
xlabel(’frequency in pi units’); ylabel(’|H|’)
set(gca,’XTickMode’,’manual’,’XTick’,[0,f,1])
set(gca,’YTickMode’,’manual’,’YTick’,[0,1]);grid
The plots of this Hilbert transformer are shown in Figure 7.40.
Optimal Equiripple Design Technique
301
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Impulse Response
0.8
0.6
0.4
h(n)
0.2
0
−0.2
−0.4
−0.6
−0.8
0
50
n
Magnitude Response
|H|
1
0
0 0.05
0.95 1
frequency in pi units
FIGURE 7.40
Plots of the Hilbert transformer in Example 7.28
PROBLEMS
P7.1 The absolute and relative (dB) specifications for a lowpass filter are related by (7.1) and
(7.2). In this problem we will develop a simple MATLAB function to convert one set of
specifications into another.
1. Write a MATLAB function to convert absolute specifications δ1 and δ2 into the relative
specifications Rp and As in dB. The format of the function should be
function [Rp,As] = delta2db(delta1,delta2)
% Converts absolute specs delta1 and delta2 into dB specs Rp and As
% [Rp,As] = delta2db(delta1,delta2)
Verify your function using the specifications given in Example 7.2.
2. Write a MATLAB function to convert relative (dB) specifications Rp and As into the
absolute specifications δ1 and δ2 . The format of the function should be
function [delta1,delta2] = db2delta(Rp,As)
% Converts dB specs Rp and As into absolute specs delta1 and delta2
% [delta1,delta2] = db2delta(Rp,As)
Verify your function using the specifications given in Example 7.1.
302
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P7.2 The Type-1 linear-phase FIR filter is characterized by
h(n) = h(M − 1 − n)),
0 ≤ n ≤ M − 1,
M odd
Show that its amplitude response Hr (ω) is given by
Hr (ω) =
L
a(n) cos(ωn),
L=
n=0
M −1
2
where coefficients {a(n)} are obtained as defined in (7.6).
P7.3 The Type-2 linear-phase FIR filter is characterized by
h(n) = h(M − 1 − n),
0 ≤ n ≤ M − 1,
M even
1. Show that its amplitude response Hr (ω) is given by
M/2
Hr (ω) =
b(n) cos ω n −
1
2
n=1
where coefficients {b(n)} are obtained as defined in (7.10).
2. Show that the above Hr (ω) can be further expressed as
Hr (ω) = cos
L
ω
2
b̃(n) cos(ωn),
L=
n=0
M
−1
2
where coefficients b̃(n) are given by
b(1) = b̃(0) + 12 b̃(1),
1
b̃(n − 1) + b̃(n) ,
b(n) =
2
1
M
−1 .
b 2 = b̃ M
2
2
2≤n≤
M
− 1,
2
P7.4 The Type-3 linear-phase FIR filter is characterized by
h(n) = −h(M − 1 − n),
0 ≤ n ≤ M − 1,
M odd
1. Show that its amplitude response Hr (ω) is given by
(M −1)/2
Hr (ω) =
c(n) sin(ωn)
n=1
where coefficients {c(n)} are obtained as defined in (7.13).
2. Show that the above Hr (ω) can be further expressed as
Hr (ω) = sin(ω)
L
n=0
Problems
c̃(n) cos(ωn),
L=
M −3
2
303
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where coefficients c̃(n) are given by
c(1) = c̃(0) − 12 c̃(1),
1
c(n) = [c̃(n − 1) − c̃(n)] ,
2
1
M −1
M −3
= c̃
.
c
2
2
2
2≤n≤
M −3
,
2
P7.5 The Type-4 linear-phase FIR filter is characterized by
h(n) = −h(M − 1 − n),
0 ≤ n ≤ M − 1,
M even
1. Show that its amplitude response Hr (ω) is given by
M/2
Hr (ω) =
d(n) sin ω n −
1
2
n=1
where coefficients {d(n)} are obtained as defined in (7.16).
2. Show that the above Hr (ω) can be further expressed as
Hr (ω) = sin
L
ω
2
L=
M
−1
2
2≤n≤
M
− 1,
2
˜ cos(ωn),
d(n)
n=0
˜
where coefficients d(n)
are given by
˜
˜ − 1 d(1),
d(1) = d(0)
2
1 ˜
˜
,
d(n − 1) − d(n)
d(n) =
2
1
M
= d˜ M
−1 .
d
2
2
2
P7.6 Write a MATLAB function to compute the amplitude response Hr (ω) given a linear phase
impulse response h(n). The format of this function should be
function [Hr,w,P,L] = Ampl_Res(h);
% Computes Amplitude response Hr(w) and its polynomial P of order L,
% given a linear-phase FIR filter impulse response h.
% The type of filter is determined automatically by the subroutine.
%
% [Hr,w,P,L] = Ampl_Res(h)
% Hr = Amplitude Response
% w = frequencies between [0 pi] over which Hr is computed
% P = Polynomial coefficients
% L = Order of P
% h = Linear Phase filter impulse response
The function should first determine the type of the linear-phase FIR filter and then use the
appropriate Hr Type# function discussed in this chapter. It should also check if the given
304
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
h(n) is of a linear-phase type. Verify your function on sequences given below
hI (n) = (0.9)|n−5| cos[π(n − 5)/12] [u(n) − u(n − 11)]
hII (n) = (0.9)|n−4.5| cos[π(n − 4.5)/11] [u(n) − u(n − 10)]
hIII (n) = (0.9)|n−5| sin[π(n − 5)/12] [u(n) − u(n − 11)]
hIV (n) = (0.9)|n−4.5| sin[π(n − 4.5)/11] [u(n) − u(n − 10)]
h(n) = (0.9)n cos[π(n − 5)/12] [u(n) − u(n − 11)]
P7.7 Prove the following properties of linear-phase FIR filters.
1. If H(z) has four zeros at z1 = rejθ , z2 = r1 e−jθ , z3 = re−jθ , and z4 = r1 e−jθ then H(z)
represents a linear-phase FIR filter.
2. If H(z) has two zeros at z1 = ejθ and z2 = e−jθ then H(z) represents a linear-phase FIR
filter.
3. If H(z) has two zeros at z1 = r and z2 = r1 then H(z) represents a linear-phase FIR
filter.
4. If H(z) has a zero at z1 = 1 or a zero at z1 = −1 then H(z) represents a linear-phase
FIR filter.
5. For each of the sequences given in Problem P7.6, plot the locations of zeros. Determine
which sequences imply linear-phase FIR filters.
P7.8 A notch filter is an LTI system which is used to eliminate an arbitrary frequency ω = ω0 .
The ideal linear-phase notch filter frequency response is given by
jω
Hd e
=
0,
1 · e−jαω ,
|ω| = ω0 ;
otherwise.
(α is a delay in samples)
1. Determine the ideal impulse response, hd (n), of the ideal notch filter.
2. Using hd (n), design a linear-phase FIR notch filter using a length 51 rectangular window
to eliminate the frequency ω0 = π/2 rad/sample. Plot amplitude the response of
resulting filter.
3. Repeat the above part using a length 51 Hamming window. Compare your results.
P7.9 Design a linear-phase bandpass filter using the Hann window design technique. The
specifications are
lower stopband edge:
upper stopband edge:
lower passband edge:
upper passband edge:
0.2π
0.75π
0.35π
0.55π
As = 40 dB
Rp = 0.25 dB
Plot the impulse response and the magnitude response (in dB) of the designed filter. Do not
use the fir1 function.
P7.10 Design a bandstop filter using the Hamming window design technique. The specifications are
lower stopband edge:
upper stopband edge:
lower passband edge:
upper passband edge:
0.4π
0.6π
0.3π
0.7π
As = 50 dB
Rp = 0.2 dB
Plot the impulse response and the magnitude response (in dB) of the designed filter. Do not
use the fir1 function.
Problems
305
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P7.11 Design a bandpass filter using the Hamming window design technique. The specifications are
lower stopband edge:
upper stopband edge:
lower passband edge:
upper passband edge:
0.3π
0.6π
0.4π
0.5π
As = 50 dB
Rp = 0.5 dB
Plot the impulse response and the magnitude response (in dB) of the designed filter. Do not
use the fir1 function.
P7.12 Design a highpass filter using one of the fixed window functions. The specifications are
stopband edge:
passband edge:
As = 50 dB
Rp = 0.001 dB
0.4π,
0.6π,
Plot the zoomed magnitude response (in dB) of the designed filter in the passband to verify
the passband ripple Rp . Do not use the fir1 function.
P7.13 Using the Kaiser window method, design a linear-phase FIR digital filter that meets the
following specifications
0.975
0
0.975
≤
≤
≤
|H(ejω )|
|H(ejω )|
|H(ejω )|
≤
≤
≤
1.025,
0.005,
1.025,
0
0.35π
0.75π
≤
≤
≤
≤
≤
≤
ω
ω
ω
0.25π
0.65π
π
Determine the minimum length impulse response h(n) of such a filter. Provide a plot
containing subplots of the amplitude response and the magnitude response in dB. Do not
use the fir1 function.
P7.14 We wish to use the Kaiser window method to design a linear-phase FIR digital filter that
meets the following specifications:
0
0.95
0
≤
≤
≤
|H(ejω )|
|H(ejω )|
|H(ejω )|
≤
≤
≤
0.01,
1.05,
0.01,
0
0.35π
0.75π
≤
≤
≤
ω
ω
ω
≤
≤
≤
0.25π
0.65π
π
Determine the minimum length impulse response h(n) of such a filter. Provide a plot
containing subplots of the amplitude response and the magnitude response in dB. Do not
use the fir1 function.
P7.15 Design the staircase filter of Example 7.26 using the Kaiser window approach. The
specifications are
Band-1:
Band-2:
Band-3:
0
0.4π
0.8π
≤
≤
≤
ω
ω
ω
≤
≤
≤
0.3π,
0.7π,
π,
Ideal gain = 1,
Ideal gain = 0.5,
Ideal gain = 0,
δ1 = 0.01
δ2 = 0.005
δ3 = 0.001
Compare the filter length of this design with that of Example 7.26. Provide a plot of the
magnitude response in dB. Do not use the fir1 function.
P7.16 Design a bandpass filter using a fixed window design technique that has the minimum
length and that satisfies the following specifications:
lower stopband edge = 0.3π
upper stopband edge = 0.6π
As
=
40 dB
lower passband edge = 0.4π
upper passband edge = 0.5π
Rp
=
0.5 dB.
Provide a plot of the log-magnitude response in dB and stem plot of the impulse response.
306
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P7.17 Repeat Problem P7.9 using the fir1 function.
P7.18 Repeat Problem P7.10 using the fir1 function.
P7.19 Repeat Problem P7.11 using the fir1 function.
P7.20 Repeat Problem P7.12 using the fir1 function.
P7.21 Repeat Problem P7.13 using the fir1 function.
P7.22 Repeat Problem P7.14 using the fir1 function.
P7.23 Consider an ideal lowpass filter with the cutoff frequency ωc = 0.3π. We want to
approximate this filter using a frequency sampling design in which we choose 40 samples.
1. Choose the sample at ωc equal to 0.5 and use the naive design method to compute h(n).
Determine the minimum stopband attenuation.
2. Now vary the sample at ωc and determine the optimum value to obtain the largest
minimum stopband attenuation.
3. Plot the magnitude responses in dB of the above two designs in one plot and comment
on the results.
P7.24 Design the bandstop filter of Problem P7.10 using the frequency sampling method. Choose
the order of the filter appropriately so that there are two samples in the transition band.
Use optimum values for these samples. Compare your results with those obtained using the
fir2 function.
P7.25 Design the bandpass filter of Problem P7.11 using the frequency sampling method. Choose
the order of the filter appropriately so that there are two samples in the transition band.
Use optimum values for these samples. Compare your results with those obtained using the
fir2 function.
P7.26 Design the highpass filter of Problem P7.12 using the frequency sampling method. Choose
the order of the filter appropriately so that there are two samples in the transition band.
Use optimum values. Compare your results with those obtained using the fir2 function.
P7.27 We want to design a narrow bandpass filter to pass the center frequency at ω0 = 0.5π. The
bandwidth should be no more than 0.1π.
1. Use the frequency sampling technique and choose M so that there is one sample in the
transition band. Use the optimum value for transition band samples and draw the
frequency sampling structure.
2. Use the Kaiser window technique so that the stopband attenuation is same as that of
the above frequency sampling design. Determine the impulse response h(n) and draw the
linear-phase structure.
3. Compare the above two filter designs in terms of their implementation and their filtering
effectiveness.
P7.28 Consider the filter specifications given in Figure P7.1. Use the fir2 function and a
Hamming window to design a linear-phase FIR filter via the frequency sampling method.
Experiment with the filter length to achieve the required design. Plot the amplitude
response of the resulting filter.
P7.29 Design a bandpass filter using the frequency sampling method. Choose the order of the
filter appropriately so that there is one sample in the transition band. Use optimum value
Problems
307
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
H r (w)
2.02
1.98
1
0
0
0.25
FIGURE P7.1
0.35
0.65
0.75
1
w
p
Filter Specifications for Problem P7.28
for this sample. The specifications are given below:
lower stopband edge = 0.3π
upper stopband edge = 0.7π
As
=
40 dB
Rp
=
0.5 dB.
lower passband edge = 0.4π
upper passband edge = 0.6π
Provide a plot of the log-magnitude response in dB and stem plot of the impulse response.
P7.30 The frequency response of an ideal bandpass filter is given by
Hd (ejω ) =
0,
1,
0,
0
π/3
2π/3
≤ |ω| ≤
≤ |ω| ≤
≤ |ω| ≤
π/3
2π/3
π
1. Determine the coefficients of a 25-tap filter based on the Parks-McClellan algorithm
with stopband attenuation of 50 dB. The designed filter should have the smallest
possible transition width.
2. Plot the amplitude response of the filter using the function developed in Problem P7.6.
P7.31 Consider the bandstop filter given in Problem P7.10.
1. Design a linear-phase bandstop FIR filter using the Parks-McClellan algorithm. Note
that the length of the filter must be odd. Provide a plot of the impulse response and the
magnitude response in dB of the designed filter.
2. Plot the amplitude response of the designed filter and count the total number of extrema
in stopband and passbands. Verify this number with the theoretical estimate of the total
number of extrema.
3. Compare the order of this filter with those of the filters in Problems P7.10 and P7.24.
4. Verify the operation of the designed filter on the following signal
x(n) = 5 − 5 cos
308
πn
;
2
0 ≤ n ≤ 300
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P7.32 Using the Parks-McClellan algorithm, design a 25-tap FIR differentiator with slope equal to
1 sample/cycle.
1. Choose the frequency band of interest between 0.1π and 0.9π. Plot the impulse response
and the amplitude response.
2. Generate 100 samples of the sinusoid
x(n) = 3 sin(0.25πn),
n = 0, ..., 100
and process through the above FIR differentiator. Compare the result with the
theoretical “derivative” of x(n). Note: Don’t forget to take the 12-sample delay of the
FIR filter into account.
P7.33 Design a lowest order equiripple linear-phase FIR filter to satisfy the specifications given in
Figure P7.2. Provide a plot of the amplitude response and a plot of the impulse response.
P7.34 A digital signal x(n) contains a sinusoid of frequency π/2 and a Gaussian noise w(n) of zero
mean and unit variance; i.e.,
x(n) = 2 cos
πn
+ w(n)
2
We want to filter out the noise component using a 50th order causal and linear-phase FIR
filter.
1. Using the Parks-McClellan algorithm, design a narrow bandpass filter with passband
width of no more than 0.02π and stopband attenuation of at least 30 dB. Note that no
other parameters are given and you have to choose the remaining parameters for the
firpm function to satisfy the requirements. Provide a plot of the log-magnitude response
in dB of the designed filter.
2. Generate 200 samples of the sequence x(n) and processed through the above filter to
obtain the output y(n). Provide subplots of x(n) and y(n) for 100 ≤ n ≤ 200 on one plot
and comment on your results.
1.00
A mplitude Response
0.90
0.45
0.35
0.05
0.00
0
FIGURE P7.2
Problems
0.4
0.5
frequency w in p units
0.7
0.8
1
Filter Specifications for Problem P7.33
309
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P7.35 Design an equiripple digital Hilbert transformer for the following specifications:
passband : 0.1π ≤ |ω| ≤ 0.5π
stopband : 0.5π ≤ |ω| ≤ π
ripple δ1 = 0.01
ripple δ2 = 0.01
Plot the amplitude response over −π ≤ ω ≤ π.
P7.36 Design a minimum order linear-phase FIR filter, using the Parks-McClellan algorithm, to
satisfy the requirements given in Figure P7.1.
1. Provide a plot of the amplitude response with grid-lines and axis labeling as shown in
Figure P7.1.
2. Generate the following signals
x1 (n) = cos(0.25πn),
x2 (n) = cos(0.5πn),
x3 (n) = cos(0.75πn);
0 ≤ n ≤ 100.
Process these signals through the above filter to obtain the corresponding output signals
y1 (n), y2 (n), and y3 (n). Provide stem plots of all input and output signals in one figure.
P7.37 Design a minimum order linear-phase FIR filter, using the Parks-McClellan algorithm, to
satisfy the requirements given in Figure P7.3. Provide a plot of the amplitude response with
grid-lines and axis labeling as shown in Figure P7.3.
P7.38 The specifications on the amplitude response of an FIR filter are given in Figure P7.4.
1. Using a window design approach and a fixed window function, design a minimum-length
linear-phase FIR filter to satisfy the given requirements. Provide a plot of the amplitude
response with grid-lines as shown in Figure P7.4.
2. Using a window design approach and the Kaiser window function, design a
minimum-length linear-phase FIR filter to satisfy the given requirements. Provide a plot
of the amplitude response with grid-lines as shown in Figure P7.4.
3. Using a frequency-sampling design approach and with no more than two samples in the
transition bands, design a minimum-length linear-phase FIR filter to satisfy the given
requirements. Provide a plot of the amplitude response with grid-lines as shown in
Figure P7.4.
Hr (w)
(Not to scale)
3.3
2.7
2.2
1.8
1.1
0.9
0.05
−0.05
0
FIGURE P7.3
310
0.2 0.25
0.45
0.55
0.7 0.75
1
w
p
Filter Specifications for Problem P7.37
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Hr (w)
4.3
4.0
2.1
1.9
0.05
−0.05
0.25
0
FIGURE P7.4
0.45
0.2
0.75
0.5
1.0
0.7
w
p
Filter Specifications for Problem P7.38
4. Using the Parks-McClellan design approach, design a minimum-length linear-phase FIR
filter to satisfy the given requirements. Provide a plot of the amplitude response with
grid-lines as shown in Figure P7.4.
5. Compare the above four design methods in terms of
• the order of the filter
• the exact band-edge frequencies
• the exact tolerances in each band
P7.39 Design a minimum-order linear-phase FIR filter, using the Parks-McClellan algorithm, to
satisfy the requirements given in Figure P7.5. Provide a plot of the amplitude response with
grid-lines as shown in Figure P7.5.
Hr (w)
4.1
4.0
3.1
3.0
2.1
1.9
1.0
0.9
0.35
0
FIGURE P7.5
Problems
0.3
0.5
0.55
0.8
0.75
1.0
w
p
Filter Specifications for Problem P7.39
311
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P7.40 Design a minimum-length linear-phase bandpass filter of Problem P7.9 using the
Parks-McClellan algorithm.
1. Plot the impulse response and the magnitude response in dB of the designed filter in one
figure plot.
2. Plot the amplitude response of the designed filter and count the total number of extrema
in passband and stopbands. Verify this number with the theoretical estimate of the total
number of extrema.
3. Compare the order of this filter with that of the filter in Problem P7.9.
312
Chapter 7
FIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
8
IIR Filter
Design
IIR filters have infinite-duration impulse responses, hence they can be
matched to analog filters, all of which generally have infinitely long impulse responses. Therefore the basic technique of IIR filter design transforms well-known analog filters into digital filters using complex-valued
mappings. The advantage of this technique lies in the fact that both
analog filter design (AFD) tables and the mappings are available extensively in the literature. This basic technique is called the A/D (analogto-digital) filter transformation. However, the AFD tables are available
only for lowpass filters. We also want to design other frequency-selective
filters (highpass, bandpass, bandstop, etc.). To do this, we need to apply
frequency-band transformations to lowpass filters. These transformations
are also complex-valued mappings, and they are also available in the literature. There are two approaches to this basic technique of IIR filter design:
Approach 1:
Design analog
−→
lowpass filter
Apply freq. band
Apply filter
Desired IIR
transformation −→ transformation −→
filter
s→s
s→z
Approach 2:
Apply filter
Apply freq. band
Design analog
Desired IIR
−→ transformation −→ transformation −→
lowpass filter
filter
s→z
z→z
313
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The first approach is used in MATLAB to design IIR filters. A
straightforward use of these MATLAB functions does not provide any
insight into the design methodology. Therefore we will study the second
approach because it involves the frequency-band transformation in the
digital domain. Hence in this IIR filter design technique we will follow
the following steps:
• Design analog lowpass filters.
• Study and apply filter transformations to obtain digital lowpass filters.
• Study and apply frequency-band transformations to obtain other digital filters from digital lowpass filters.
The main problem with these approaches is that we have no control
over the phase characteristics of the IIR filter. Hence IIR filter designs
will be treated as magnitude-only designs. More sophisticated techniques,
which can simultaneously approximate both the magnitude and the phase
responses, require advanced optimization tools and hence will not be covered in this book.
We begin with a discussion on the analog filter specifications and the
properties of the magnitude-squared response used in specifying analog
filters. This will lead us into the characteristics of three widely used analog filters, namely, Butterworth, Chebyshev, and Elliptic filters. We will
then study transformations to convert these prototype analog filters into
different frequency-selective digital filters. Finally, we will conclude this
chapter with a discussion on the merits and comparisons of FIR and IIR
digital filters.
SOME PRELIMINARIES
We discuss two preliminary issues in this section. First, we consider the
magnitude-squared response specifications, which are more typical of analog (and hence of IIR) filters. These specifications are given on the relative
linear scale. Second, we study the properties of the magnitude-squared
response.
RELATIVE
LINEAR
SCALE
314
Let Ha (jΩ) be the frequency response of an analog filter. Then the lowpass
filter specifications on the magnitude-squared response are given by
1
≤ |Ha (jΩ)|2 ≤ 1, |Ω| ≤ Ωp
1 + 2
1
0 ≤ |Ha (jΩ)|2 ≤ 2 , Ωs ≤ |Ω|
A
Chapter 8
(8.1)
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
|Ha( jΩ)|2
1
1
1+
1
A2
0
0
FIGURE 8.1
Ωp
Ω
Ωs
Analog lowpass filter specifications
where is a passband ripple parameter, Ωp is the passband cutoff frequency in rad/sec, A is a stopband attenuation parameter, and Ωs is the
stopband cutoff in rad/sec. These specifications are shown in Figure 8.1,
2
from which we observe that |Ha (jΩ)| must satisfy
1
1 + 2
1
|Ha (jΩs )|2 =
A2
|Ha (jΩp )|2 =
at Ω = Ωp
(8.2)
at Ω = Ωs
The parameters and A are related to parameters Rp and As , respectively, of the dB scale. These relations are given by
Rp = −10 log10
1
=⇒
=
10Rp /10 − 1
1 + 2
(8.3)
and
As = −10 log10
1
=⇒ A = 10As /20
A2
(8.4)
The ripples, δ1 and δ2 , of the absolute scale are related to and A by
1 − δ1
=
1 + δ1
√
1
2 δ1
=⇒ =
1 + 2
1 − δ1
and
δ2
1 + δ1
1
=⇒ A =
=
1 + δ1
A
δ2
Some Preliminaries
315
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
PROPERTIES
OF |Ha (jΩ)|2
Analog filter specifications (8.1), which are given in terms of the
magnitude-squared response, contain no phase information. Now to evaluate the s-domain system function Ha (s), consider
Ha (jΩ) = Ha (s)|s=jΩ
Then we have
|Ha (jΩ)| = Ha (jΩ)Ha∗ (jΩ) = Ha (jΩ)Ha (−jΩ) = Ha (s)Ha (−s)|s=jΩ
2
or
2
Ha (s)Ha (−s) = |Ha (jΩ)| (8.5)
Ω=s/j
Therefore the poles and zeros of the magnitude-squared function are distributed in a mirror-image symmetry with respect to the jΩ axis. Also for
real filters, poles and zeros occur in complex conjugate pairs (or mirrorimage symmetry with respect to the real axis). A typical pole-zero pattern of Ha (s)Ha (−s) is shown in Figure 8.2. From this pattern we can
construct Ha (s), which is the system function of our analog filter. We
want Ha (s) to represent a causal and stable filter. Then all poles of Ha (s)
must lie within the left half-plane. Thus we assign all left-half poles of
Ha (s)Ha (−s) to Ha (s). However, zeros of Ha (s) can lie anywhere in the
s-plane. Therefore they are not uniquely determined unless they all are
on the jΩ axis. We will choose the zeros of Ha (s)Ha (−s) lying left to or
on the jΩ axis as the zeros of Ha(s). The resulting filter is then called a
minimum-phase filter.
jΩ
s-plane
s
FIGURE 8.2
316
Typical pole-zero pattern of Ha (s)Ha (−s)
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHARACTERISTICS OF PROTOTYPE ANALOG FILTERS
IIR filter design techniques rely on existing analog filters to obtain digital
filters. We designate these analog filters as prototype filters. Three prototypes are widely used in practice. In this section we briefly summarize
the characteristics of the lowpass versions of these prototypes: Butterworth lowpass, Chebyshev lowpass (Type I and II), and Elliptic lowpass.
Although we will use MATLAB functions to design these filters, it is necessary to learn the characteristics of these filters so that we can use proper
parameters in MATLAB functions to obtain correct results.
BUTTERWORTH
LOWPASS
FILTERS
This filter is characterized by the property that its magnitude response is
flat in both passband and stopband. The magnitude-squared response of
an N th-order lowpass filter is given by
2
|Ha (jΩ)| =
1+
1
Ω
Ωc
2N
(8.6)
where N is the order of the filter and Ωc is the cutoff frequency in rad/sec.
The plot of the magnitude-squared response is shown below.
From this plot we can observe the following properties:
2
• at Ω = 0, |Ha (j0)| = 1 for all N .
2
• at Ω = Ωc , |Ha (jΩc )| = 12 for all N , which implies a 3 dB attenuation
at Ωc .
2
• |Ha (jΩ)| is a monotonically decreasing function of Ω.
2
• |Ha (jΩ)| approaches an ideal lowpass filter as N → ∞.
2
• |Ha (jΩ)| is maximally flat at Ω = 0 since derivatives of all orders exist
and are equal to zero.
Characteristics of Prototype Analog Filters
317
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
To determine the system function Ha (s), we put (8.6) in the form of (8.5)
to obtain
2
Ha (s)Ha (−s) = |Ha (jΩ)| =
Ω=s/j
1+
1
s
jΩc
2N =
(jΩ)2N
2N
s2N + (jΩc )
(8.7)
The roots of the denominator polynomial (or poles of Ha (s)Ha (−s)) from
(8.7) are given by
1
π
pk = (−1) 2N (jΩ) = Ωc ej 2N (2k+N +1) ,
k = 0, 1, . . . , 2N − 1
(8.8)
An interpretation of (8.8) is that
• there are 2N poles of Ha (s)Ha (−s), which are equally distributed on
a circle of radius Ωc with angular spacing of π/N radians,
• for N odd the poles are given by pk = Ωc ejkπ/N , k = 0, 1, . . . , 2N −1,
π
kπ
• for N even the poles are given by pk = Ωc ej ( 2N + N ) , k = 0, 1, . . . ,
2N − 1,
• the poles are symmetrically located with respect to the jΩ axis, and
• a pole never falls on the imaginary axis, and falls on the real axis only
if N is odd.
As an example, poles of third- and fourth-order Butterworth filters are
shown in Figure 8.3.
A stable and causal filter Ha (s) can now be specified by selecting
poles in the left half-plane, and Ha (s) can be written in the form
Ha (s) =
ΩN
c
(s − pk )
(8.9)
LHP poles
jΩ
jΩ
Ωc
Ωc
k=0
0
s
k=0
s
0
k = 2N − 1
k = 2N − 1
N=3
FIGURE 8.3
318
N=4
Pole plots for Butterworth filters
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 8.4
EXAMPLE 8.1
Pole plot for Example 8.1
Given that |Ha (jΩ)|2 =
1
, determine the analog filter system function
1 + 64Ω6
Ha (s).
Solution
From the given magnitude-squared response,
|Ha (jΩ)|2 =
1
=
1 + 64Ω6
1+
1
Ω 2(3)
0.5
Comparing this with expression (8.6), we obtain N = 3 and Ωc = 0.5. The poles
of Ha (s)Ha (−s) are as shown in Figure 8.4.
Hence
Ha (jΩ) =
MATLAB
IMPLEMENTATION
Ω3c
(s − p2 )(s − p3 )(s − p4 )
=
1/8
(s + 0.25 − j0.433)(s + 0.5)(s + 0.25 + j0.433)
=
0.125
(s + 0.5)(s2 + 0.5s + 0.25)
MATLAB provides a function called [z,p,k]=buttap(N) to design a normalized (i.e., Ωc = 1) Butterworth analog prototype filter of order N ,
which returns zeros in z array, poles in p array, and the gain value k.
However, we need an unnormalized Butterworth filter with arbitrary Ωc .
From Example 8.1 we observe that there are no zeros and that the poles
of the unnormalized filter are on a circle with radius Ωc instead of on a
unit circle. This means that we have to scale the array p of the normalized filter by Ωc and the gain k by ΩN
c . In the following function, called
U buttap(N,Omegac), we design the unnormalized Butterworth analog
prototype filter.
Characteristics of Prototype Analog Filters
319
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
function [b,a] = u_buttap(N,Omegac);
% Unnormalized Butterworth Analog Lowpass Filter Prototype
% -------------------------------------------------------% [b,a] = u_buttap(N,Omegac);
%
b = numerator polynomial coefficients of Ha(s)
%
a = denominator polynomial coefficients of Ha(s)
%
N = Order of the Butterworth Filter
% Omegac = Cutoff frequency in radians/sec
%
[z,p,k] = buttap(N);
p = p*Omegac;
k = k*Omegac^N;
B = real(poly(z));
b0 = k; b = k*B; a = real(poly(p));
The above function provides a direct form (or numerator-denominator)
structure. Often we also need a cascade form structure. In Chapter 6 we
have already studied how to convert a direct form into a cascade form.
The following sdir2cas function describes the procedure that is suitable
for analog filters.
function [C,B,A] = sdir2cas(b,a);
% DIRECT-form to CASCADE-form conversion in s-plane
% ------------------------------------------------% [C,B,A] = sdir2cas(b,a)
% C = gain coefficient
% B = K by 3 matrix of real coefficients containing bk’s
% A = K by 3 matrix of real coefficients containing ak’s
% b = numerator polynomial coefficients of DIRECT form
% a = denominator polynomial coefficients of DIRECT form
%
Na = length(a)-1; Nb = length(b)-1;
% compute gain coefficient C
b0 = b(1); b = b/b0; a0 = a(1); a = a/a0; C = b0/a0;
%
% Denominator second-order sections:
p= cplxpair(roots(a)); K = floor(Na/2);
if K*2 == Na
% Computation when Na is even
A = zeros(K,3);
for n=1:2:Na
Arow = p(n:1:n+1,:); Arow = poly(Arow);
A(fix((n+1)/2),:) = real(Arow);
end
320
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
elseif Na == 1
% Computation when Na = 1
A = [0 real(poly(p))];
else
% Computation when Na is odd and > 1
A = zeros(K+1,3);
for n=1:2:2*K
Arow = p(n:1:n+1,:); Arow = poly(Arow);
A(fix((n+1)/2),:) = real(Arow);
end
A(K+1,:) = [0 real(poly(p(Na)))];
end
% Numerator second-order sections:
z = cplxpair(roots(b)); K = floor(Nb/2);
if Nb == 0
% Computation when Nb = 0
B = [0 0 poly(z)];
elseif K*2 == Nb
% Computation when Nb is even
B = zeros(K,3);
for n=1:2:Nb
Brow = z(n:1:n+1,:); Brow = poly(Brow);
B(fix((n+1)/2),:) = real(Brow);
end
elseif Nb == 1
% Computation when Nb = 1
B = [0 real(poly(z))];
else
% Computation when Nb is odd and > 1
B = zeros(K+1,3);
for n=1:2:2*K
Brow = z(n:1:n+1,:); Brow = poly(Brow);
B(fix((n+1)/2),:) = real(Brow);
end
B(K+1,:) = [0 real(poly(z(Nb)))];
end
EXAMPLE 8.2
Solution
Design a third-order Butterworth analog prototype filter with Ωc = 0.5 given
in Example 8.1.
MATLAB Script:
>> N = 3; OmegaC = 0.5; [b,a] = u_buttap(N,OmegaC);
>> [C,B,A] = sdir2cas(b,a)
C = 0.1250
B = 0
0
1
Characteristics of Prototype Analog Filters
321
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
A = 1.0000
0
0.5000
1.0000
0.2500
0.5000
The cascade form coefficients agree with those in Example 8.1.
DESIGN
EQUATIONS
The analog lowpass filter is specified by the parameters Ωp , Rp , Ωs , and
As . Therefore the essence of the design in the case of Butterworth filter
is to obtain the order N and the cutoff frequency Ωc , given these specifications. We want
2
• at Ω = Ωp , −10 log10 |Ha (jΩ)| = Rp or



−10 log10 

1+


2N  = Rp

Ωp
1
Ωc
and
2
• at Ω = Ωs , −10 log10 |Ha (jΩ)| = As or



−10 log10 

1+




2N  = As

Ωs
1
Ωc
Solving these two equations for N and Ωc , we have
log10 10Rp /10 − 1 / 10As /10 − 1
N=
2 log10 (Ωp /Ωs )
In general, the above N will not be an integer. Since we want N to be an
integer, we must choose
log10 10Rp /10 − 1 / 10As /10 − 1
(8.10)
N=
2 log10 (Ωp /Ωs )
where the operation x means “choose the smallest integer larger than
x”—for example, 4.5 = 5. Since the actual N chosen is larger than required, specifications can be either met or exceeded either at Ωp or at Ωs .
To satisfy the specifications exactly at Ωp ,
Ωc =
2N
322
Ωp
10Rp /10 − 1
Chapter 8
(8.11)
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
or, to satisfy the specifications exactly at Ωs ,
Ωc =
2N
EXAMPLE 8.3
Solution
Ωs
(8.12)
10As /10 − 1
Design a lowpass Butterworth filter to satisfy
Passband cutoff: Ωp = 0.2π ;
Passband ripple: Rp = 7dB
Stopband cutoff: Ωs = 0.3π ;
Stopband ripple: As = 16dB
From (8.10)
N=
log10
100.7 − 1 / 101.6 − 1
2 log10 (0.2π/0.3π)
= 2.79 = 3
To satisfy the specifications exactly at Ωp , from (8.11) we obtain
Ωc = 6
0.2π
(100.7 − 1)
= 0.4985
To satisfy specifications exactly at Ωs , from (8.12) we obtain
Ωc = 6
0.3π
(101.6 − 1)
= 0.5122
Now we can choose any Ωc between the above two numbers. Let us choose
Ωc = 0.5. We have to design a Butterworth filter with N = 3 and Ωc = 0.5,
which we did in Example 8.1. Hence
Ha (jΩ) =
MATLAB
IMPLEMENTATION
0.125
(s + 0.5) (s2 + 0.5s + 0.25)
The above design procedure can be implemented in MATLAB as a simple
function. Using the U buttap function, we provide the afd butt function
to design an analog Butterworth lowpass filter, given its specifications.
This function uses (8.11).
function [b,a] = afd_butt(Wp,Ws,Rp,As);
% Analog Lowpass Filter Design: Butterworth
% ----------------------------------------% [b,a] = afd_butt(Wp,Ws,Rp,As);
% b = Numerator coefficients of Ha(s)
% a = Denominator coefficients of Ha(s)
% Wp = Passband edge frequency in rad/sec; Wp > 0
% Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0
% Rp = Passband ripple in +dB; (Rp > 0)
Characteristics of Prototype Analog Filters
323
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% As = Stopband attenuation in +dB; (As > 0)
%
if Wp <= 0
error(’Passband edge must be larger than 0’)
end
if Ws <= Wp
error(’Stopband edge must be larger than Passband edge’)
end
if (Rp <= 0) | (As < 0)
error(’PB ripple and/or SB attenuation ust be larger than 0’)
end
N = ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws)));
fprintf(’\n*** Butterworth Filter Order = %2.0f \n’,N)
OmegaC = Wp/((10^(Rp/10)-1)^(1/(2*N)));
[b,a]=u_buttap(N,OmegaC);
To display the frequency-domain plots of analog filters, we provide a
function called freqs m, which is a modified version of a function freqs
provided by MATLAB. This function computes the magnitude response
in absolute as well as in relative dB scale and the phase response. This
function is similar to the freqz m function discussed earlier. One main
difference between them is that in the freqs m function the responses are
computed up to a maximum frequency Ωmax .
function [db,mag,pha,w] = freqs_m(b,a,wmax);
% Computation of s-domain frequency response: Modified version
% -----------------------------------------------------------% [db,mag,pha,w] = freqs_m(b,a,wmax);
%
db = Relative magnitude in db over [0 to wmax]
% mag = Absolute magnitude over [0 to wmax]
% pha = Phase response in radians over [0 to wmax]
%
w = array of 500 frequency samples between [0 to wmax]
%
b = Numerator polynomial coefficents of Ha(s)
%
a = Denominator polynomial coefficents of Ha(s)
% wmax = Maximum frequency in rad/sec over which response is desired
%
w = [0:1:500]*wmax/500; H = freqs(b,a,w);
mag = abs(H); db = 20*log10((mag+eps)/max(mag)); pha = angle(H);
The impulse response ha (t) of the analog filter is computed using
MATLAB’s impulse function.
324
EXAMPLE 8.4
Design the analog Butterworth lowpass filter specified in Example 8.3 using
MATLAB.
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
MATLAB Script:
>> Wp = 0.2*pi; Ws = 0.3*pi; Rp = 7; As = 16;
>> Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20);
>> % Analog filter design:
>> [b,a] = afd_butt(Wp,Ws,Rp,As);
*** Butterworth Filter Order = 3
>> % Calculation of second-order sections:
>> [C,B,A] = sdir2cas(b,a)
C = 0.1238
B = 0
0
1
A = 1.0000
0.4985
0.2485
0
1.0000
0.4985
>> % Calculation of Frequency Response:
>> [db,mag,pha,w] = freqs_m(b,a,0.5*pi);
>> % Calculation of Impulse response:
>> [ha,x,t] = impulse(b,a);
The system function is given by
Ha (s) =
0.1238
(s2 + 0.4985s + 0.2485) (s + 0.4985)
This Ha (s) is slightly different from the one in Example 8.3 because in that
example we used Ωc = 0.5, while in the afd butt function Ωc is chosen to
satisfy the specifications at Ωp . The filter plots are shown in Figure 8.5.
CHEBYSHEV
LOWPASS
FILTERS
There are two types of Chebyshev filters. The Chebyshev-I filters have
equiripple response in the passband, while the Chebyshev-II filters have
equiripple response in the stopband. Butterworth filters have monotonic
response in both bands. Recall our discussions regarding equiripple FIR
filters. We noted that by choosing a filter that has an equiripple rather
than a monotonic behavior, we can obtain a lower-order filter. Therefore
Chebyshev filters provide lower order than Butterworth filters for the
same specifications.
The magnitude-squared response of a Chebyshev-I filter is
1
2
|Ha (jΩ)| =
1+
2 TN2
Ω
Ωc
(8.13)
where N is the order of the filter, is the passband ripple factor, which is
related to Rp , and TN (x) is the N th-order Chebyshev polynomial given
by
cos N cos−1 (x) , 0 ≤ x ≤ 1
Ω
where x =
TN (x) =
Ωc
cosh cosh−1 (x) , 1 < x < ∞
Characteristics of Prototype Analog Filters
325
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Magnitude in dB
1
|H|
decibels
0
0.4467
7
16
0.1585
0
0
0.2
0.3
Analog frequency in pi units
30
0
0.5
0.2
0.3
Analog frequency in pi units
Impulse Response
1
0.2
0.5
0.15
ha(t)
radians
Phase Response
0.5
0
0.1
0.05
−0.5
0
−1
0
FIGURE 8.5
0.2
0.3
Analog frequency in pi units
0.5
0
10
20
time in seconds
30
Butterworth analog filter in Example 8.4
The equiripple response of the Chebyshev filters is due to this polynomial
TN (x). Its key properties are (a) for 0 < x < 1, TN (x) oscillates between −1 and 1, and (b) for 1 < x < ∞, TN (x) increases monotonically
to ∞.
There are two possible shapes of |Ha (jΩ)|2 , one for N odd and one for
N even as shown below. Note that x = Ω/Ωc is the normalized frequency.
|Ha (j Ω)|
|Ha (j Ω)|
N Odd
1
N Even
1
1
1+
1
1+
1
A2
0
326
1
Ωr
Ωc
x=
Ω
Ωc
1
A2
0
1
Ωr
Ωc
Chapter 8
x=
Ω
Ωc
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
From the above two response plots we observe the following properties:
• At x = 0 (or Ω = 0);
|Ha (j0)|2 = 1
• At x = 1 (or Ω = Ωc );
for N odd.
1
|Ha (j0)|2 =
1 + 2
1
2
|Ha (j1)| =
1 + 2
for N even.
for all N .
2
• For 0 ≤ x ≤ 1 (or 0 ≤ Ω ≤ Ωc ), |Ha (jx)| oscillates between 1 and
1
.
1 + 2
2
• For x > 1 (or Ω > Ωc ), |Ha (jx)| decreases monotonically to 0.
2
• At x = Ωr , |Ha (jx)| =
1
.
A2
To determine a causal and stable Ha (s), we must find the poles of
Ha (s)Ha (−s) and select the left half-plane poles for Ha (s). The poles of
Ha (s)Ha (−s) are obtained by finding the roots of
2
1+
TN2
s
jΩc
The solution of this equation is tedious if not difficult to obtain. It can be
shown that if pk = σk + jΩk , k = 0, . . . , N − 1 are the (left half-plane)
roots of the above polynomial, then
π (2k + 1)π
+
2
2N
k = 0, . . . , N − 1
π (2k + 1)π
Ωk = (bΩc ) sin
+
2
2N
σk = (aΩc ) cos
(8.14)
where
√
1 N
a=
α − N 1/α ,
2
√
1 N
b=
α + N 1/α ,
2
1
and α = +
1
2
(8.15)
1+
These roots fall on an ellipse with major axis bΩc and minor axis aΩc .
Now the system function is given by
Ha (s) = K
(s − pk )
(8.16)
k
Characteristics of Prototype Analog Filters
327
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where K is a normalizing factor chosen to make


1,
N odd

Ha (j0) =
1

, N even
√
1 + 2
MATLAB
IMPLEMENTATION
(8.17)
MATLAB provides a function called [z,p,k]=cheb1ap(N,Rp) to design
a normalized Chebyshev-I analog prototype filter of order N and passband ripple Rp and that returns zeros in z array, poles in p array, and
the gain value k. We need an unnormalized Chebyshev-I filter with arbitrary Ωc . This is achieved by scaling the array p of the normalized filter
by Ωc . Similar to the Butterworth prototype, this filter has no zeros.
The new gain k is determined using (8.17), which is achieved by scaling
the old k by the ratio of the unnormalized to the normalized denominator polynomials evaluated at s = 0. In the following function, called
U chb1ap(N,Rp,Omegac), we design an unnormalized Chebyshev-I analog
prototype filter that returns Ha (s) in the direct form.
function [b,a] = u_chb1ap(N,Rp,Omegac);
% Unnormalized Chebyshev-1 Analog Lowpass Filter Prototype
% -------------------------------------------------------% [b,a] = u_chb1ap(N,Rp,Omegac);
%
b = numerator polynomial coefficients
%
a = denominator polynomial coefficients
%
N = Order of the Elliptic Filter
%
Rp = Passband Ripple in dB; Rp > 0
% Omegac = Cutoff frequency in radians/sec
%
[z,p,k] = cheb1ap(N,Rp); a = real(poly(p)); aNn = a(N+1);
p = p*Omegac; a = real(poly(p)); aNu = a(N+1);
k = k*aNu/aNn;
b0 = k; B = real(poly(z)); b = k*B;
DESIGN
EQUATIONS
Given Ωp , Ωs , Rp , and AS , three parameters are required to determine a
Chebyshev-I filter: , Ωc , and N . From equations (8.3) and (8.4) we obtain
=
100.1Rp − 1
A = 10As /20
and
From the properties discussed above we have
Ω c = Ωp
328
and
Ωr =
Ωs
Ωp
Chapter 8
(8.18)
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The order N is given by
(A2 − 1) /2

log10 g + g 2 − 1
N =

 log10 Ωr + Ω2r − 1
g=
(8.19)




(8.20)
Now using (8.15), (8.14), and (8.16), we can determine Ha (s).
EXAMPLE 8.5
Solution
Design a lowpass Chebyshev-I filter to satisfy
Passband cutoff: Ωp = 0.2π ;
Passband ripple: Rp = 1dB
Stopband cutoff: Ωs = 0.3π ;
Stopband ripple: As = 16dB
First compute the necessary parameters.
√
=
100.1(1) − 1 = 0.5088
A = 1016/20 = 6.3096
Ωc = Ωp = 0.2π
Ωr =
(A2 − 1) /
g=
2
= 12.2429
0.3π
= 1.5
0.2π
N =4
Now we can determine Ha (s).
α =
1
+
1+
a = 0.5
√
N
b = 0.5
√
N
1
2
= 4.1702
α−
N
α+
N
1/α = 0.3646
1/α = 1.0644
There are four poles for Ha (s):
p0,3 = (aΩc ) cos
p1,2 = (aΩc ) cos
π
π
π
π
± (bΩc ) sin
= −0.0877 ± j0.6179
+
+
2
8
2
8
π
π
3π
3π
± (bΩc ) sin
= −0.2117 ± j0.2559
+
+
2
8
2
8
Hence
Ha (s) =
K
3
(s − pk )
#
0.03829
$%
&
0.89125 × .1103 × .3895
= 2
(s + 0.1754s + 0.3895) (s2 + 0.4234s + 0.1103)
k=0
Characteristics of Prototype Analog Filters
329
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Note that the numerator is such that
Ha (j0) = √
MATLAB
IMPLEMENTATION
1
1+
2
= 0.89125
Using the U chb1ap function, we provide a function called afd chb1 to
design an analog Chebyshev-II lowpass filter, given its specifications. This
is shown below and uses the procedure described in Example 8.5.
function [b,a] = afd_chb1(Wp,Ws,Rp,As);
% Analog Lowpass Filter Design: Chebyshev-1
% ----------------------------------------% [b,a] = afd_chb1(Wp,Ws,Rp,As);
% b = Numerator coefficients of Ha(s)
% a = Denominator coefficients of Ha(s)
% Wp = Passband edge frequency in rad/sec; Wp > 0
% Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0
% Rp = Passband ripple in +dB; (Rp > 0)
% As = Stopband attenuation in +dB; (As > 0)
%
if Wp <= 0
error(’Passband edge must be larger than 0’)
end
if Ws <= Wp
error(’Stopband edge must be larger than Passband edge’)
end
if (Rp <= 0) | (As < 0)
error(’PB ripple and/or SB attenuation ust be larger than 0’)
end
ep = sqrt(10^(Rp/10)-1); A = 10^(As/20);
OmegaC = Wp; OmegaR = Ws/Wp; g = sqrt(A*A-1)/ep;
N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1)));
fprintf(’\n*** Chebyshev-1 Filter Order = %2.0f \n’,N)
[b,a]=u_chb1ap(N,Rp,OmegaC);
EXAMPLE 8.6
Solution
Design the analog Chebyshev-I lowpass filter given in Example 8.5 using
MATLAB.
MATLAB Script:
>> Wp = 0.2*pi; Ws = 0.3*pi; Rp = 1; As = 16;
>> Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20);
>> % Analog filter design:
>> [b,a] = afd_chb1(Wp,Ws,Rp,As);
*** Chebyshev-1 Filter Order = 4
330
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> % Calculation of second-order sections:
>> [C,B,A] = sdir2cas(b,a)
C = 0.0383
B = 0
0
1
A = 1.0000
0.4233
0.1103
1.0000
0.1753
0.3895
>> % Calculation of Frequency Response:
>> [db,mag,pha,w] = freqs_m(b,a,0.5*pi);
>> % Calculation of Impulse response:
>> [ha,x,t] = impulse(b,a);
The specifications are satisfied by a 4th-order Chebyshev-I filter whose system
function is
Ha (s) =
0.0383
(s2 + 4233s + 0.1103) (s2 + 0.1753s + 0.3895)
The filter plots are shown in Figure 8.6.
A Chebyshev-II filter is related to the Chebyshev-I filter through a
simple transformation. It has a monotone passband and an equiripple
stopband, which implies that this filter has both poles and zeros in the
s-plane. Therefore the group delay characteristics are better (and the
Magnitude Response
Magnitude in dB
1
0.8913
|H|
decibels
0
1
16
0.1585
0
0
0.2
0.3
Analog frequency in pi units
30
0
0.5
0.2
0.3
Analog frequency in pi units
Phase Response
Impulse Response
1
0.2
0.15
ha(t)
radians
0.5
0
−0.5
−1
0
FIGURE 8.6
0.5
0.1
0.05
0
−0.05
0.2
0.3
Analog frequency in pi units
0.5
0
10
20
30
40
time in seconds
Chebyshev-I analog filter in Example 8.6
Characteristics of Prototype Analog Filters
331
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
phase response more linear) in the passband than the Chebyshev-I prototype. If we replace the term 2 TN2 (Ω/Ωc ) in (8.13) by its reciprocal and
also the argument x = Ω/Ωc by its reciprocal, we obtain the magnitudesquared response of Chebyshev-II as
|Ha (jΩ)|2 =
1
1+
(8.21)
−1
[2 TN2 (Ωc /Ω)]
One approach to designing a Chebyshev-II filter is to design the corresponding Chebyshev-I first and then apply the above transformations.
We will not discuss the details of this filter but will use a function from
MATLAB to design a Chebyshev-II filter.
MATLAB
IMPLEMENTATION
MATLAB provides a function called [z,p,k]=cheb2ap(N,As) to design a
normalized Chebyshev-II analog prototype filter of order N and passband
ripple As and that returns zeros in z array, poles in p array, and the gain
value k. We need an unnormalized Chebyshev-I filter with arbitrary Ωc .
This is achieved by scaling the array p of the normalized filter by Ωc . Since
this filter has zeros, we also have to scale the array z by Ωc . The new gain
k is determined using (8.17), which is achieved by scaling the old k by the
ratio of the unnormalized to the normalized rational functions evaluated
at s = 0. In the following function, called U chb2ap(N,As,Omegac), we
design an unnormalized Chebyshev-II analog prototype filter that returns
Ha (s) in the direct form.
function [b,a] = u_chb2ap(N,As,Omegac);
% Unnormalized Chebyshev-2 Analog Lowpass Filter Prototype
% -------------------------------------------------------% [b,a] = u_chb2ap(N,As,Omegac);
%
b = numerator polynomial coefficients
%
a = denominator polynomial coefficients
%
N = Order of the Elliptic Filter
%
As = Stopband Ripple in dB; As > 0
% Omegac = Cutoff frequency in radians/sec
%
[z,p,k] = cheb2ap(N,As);
a = real(poly(p)); aNn = a(N+1);
p = p*Omegac; a = real(poly(p)); aNu = a(N+1);
b = real(poly(z)); M = length(b); bNn = b(M);
z = z*Omegac; b = real(poly(z)); bNu = b(M);
k = k*(aNu*bNn)/(aNn*bNu);
b0 = k; b = k*b;
332
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The design equations for the Chebyshev-II prototype are similar to
those of the Chebyshev-I except that Ωc = Ωs since the ripples are in the
stopband. Therefore we can develop a MATLAB function similar to the
afd chb1 function for the Chebyshev-II prototype.
function [b,a] = afd_chb2(Wp,Ws,Rp,As);
% Analog Lowpass Filter Design: Chebyshev-2
% ----------------------------------------% [b,a] = afd_chb2(Wp,Ws,Rp,As);
% b = Numerator coefficients of Ha(s)
% a = Denominator coefficients of Ha(s)
% Wp = Passband edge frequency in rad/sec; Wp > 0
% Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0
% Rp = Passband ripple in +dB; (Rp > 0)
% As = Stopband attenuation in +dB; (As > 0)
%
if Wp <= 0
error(’Passband edge must be larger than 0’)
end
if Ws <= Wp
error(’Stopband edge must be larger than Passband edge’)
end
if (Rp <= 0) | (As < 0)
error(’PB ripple and/or SB attenuation ust be larger than 0’)
end
ep = sqrt(10^(Rp/10)-1); A = 10^(As/20);
OmegaC = Wp; OmegaR = Ws/Wp; g = sqrt(A*A-1)/ep;
N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1)));
fprintf(’\n*** Chebyshev-2 Filter Order = %2.0f \n’,N)
[b,a]=u_chb2ap(N,As,Ws);
EXAMPLE 8.7
Solution
Design a Chebyshev-II analog lowpass filter to satisfy the specifications given
in Example 8.5:
Passband cutoff: Ωp = 0.2π ;
Passband ripple: Rp = 1dB
Stopband cutoff: Ωs = 0.3π ;
Stopband ripple: As = 16dB
MATLAB Script:
>> Wp = 0.2*pi; Ws = 0.3*pi; Rp = 1; As = 16;
>> Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20);
>> % Analog filter design:
>> [b,a] = afd_chb2(Wp,Ws,Rp,As);
*** Chebyshev-2 Filter Order = 4
Characteristics of Prototype Analog Filters
333
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> % Calculation of second-order sections:
>> [C,B,A] = sdir2cas(b,a)
C = 0.1585
B = 1.0000
0
6.0654
1.0000
0
1.0407
A = 1.0000
1.9521
1.4747
1.0000
0.3719
0.6784
>> % Calculation of Frequency Response:
>> [db,mag,pha,w] = freqs_m(b,a,0.5*pi);
>> % Calculation of Impulse response:
>> [ha,x,t] = impulse(b,a);
The specifications are satisfied by a 4th-order Chebyshev-II filter whose system
function is
Ha (s) =
0.1585 s2 + 6.0654
s2 + 1.0407
(s2 + 1.9521s + 1.4747) (s2 + 0.3719s + 0.6784)
The filter plots are shown in Figure 8.7.
Magnitude Response
Magnitude in dB
1
0.8913
|H|
decibels
0
1
16
0.1585
0
0
0.2
0.3
Analog frequency in pi units
30
0
0.5
0.2
0.3
Analog frequency in pi units
Phase Response
0.5
Impulse Response
1
0.2
0.1
ha(t)
radians
0.5
0
0
−0.1
−0.2
−0.5
−0.3
−1
0
FIGURE 8.7
334
0.2
0.3
Analog frequency in pi units
0.5
0
10
20
time in seconds
30
Chebyshev-II analog filter in Example 8.7
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ELLIPTIC
LOWPASS
FILTERS
These filters exhibit equiripple behavior in the passband as well as in
the stopband. They are similar in magnitude response characteristics to
the FIR equiripple filters. Therefore elliptic filters are optimum filters
in that they achieve the minimum order N for the given specifications
(or alternately, achieve the sharpest transition band for the given order
N ). These filters, for obvious reasons, are very difficult to analyze and,
therefore, to design. It is not possible to design them using simple tools,
and often programs or tables are needed to design them.
The magnitude-squared response of elliptic filters is given by
1
|Ha (jΩ)|2 =
2
1 + 2 UN
Ω
Ωc
(8.22)
where N is the order, is the passband ripple (which is related to Rp ),
and UN (·) is the N th order Jacobian elliptic function. The analysis of
this function, even on a superficial level, is beyond the scope of this book.
Note the similarity between the above response (8.22) and that of the
Chebyshev filters given by (8.13). Typical responses for odd and even N
are shown below.
|Ha (j Ω)|
|Ha (j Ω)|
N Odd
1
N Even
1
1
1+
1
1+
1
A2
0
COMPUTATION
OF FILTER
ORDER N
1
A2
Ω
Ωc
Ωc
0
Ω
Even though the analysis of (8.22) is difficult, the order calculation formula is very compact and is available in many textbooks [18, 22, 23]. It
is given by
K(k)K
1 − k12
√
N=
(8.23)
K (k1 ) K
1 − k2
where
k=
Characteristics of Prototype Analog Filters
Ωp
,
Ωs
k1 = √
A2
−1
335
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
and
'
π/2
dθ
K(x) =
0
1 − x2 sin2 θ
is the complete elliptic integral of the first kind. MATLAB provides the
function ellipke to numerically compute the above integral, which we
will use to compute N and to design elliptic filters.
MATLAB
IMPLEMENTATION
MATLAB provides a function called [z,p,k]=ellipap(N,Rp,As) to design a normalized elliptic analog prototype filter of order N, passband
ripple Rp, and stopband attenuation As, and that returns zeros in z array,
poles in p array, and the gain value k. We need an unnormalized elliptic
filter with arbitrary Ωc . This is achieved by scaling the arrays p and z of
the normalized filter by Ωc and the gain k by the ratio of the unnormalized
to the normalized rational functions evaluated at s = 0. In the following
function, called U elipap(N,Rp,As,Omegac), we design an unnormalized
elliptic analog prototype filter that returns Ha (s) in the direct form.
function [b,a] = u_elipap(N,Rp,As,Omegac);
% Unnormalized Elliptic Analog Lowpass Filter Prototype
% ----------------------------------------------------% [b,a] = u_elipap(N,Rp,As,Omegac);
%
b = numerator polynomial coefficients
%
a = denominator polynomial coefficients
%
N = Order of the Elliptic Filter
%
Rp = Passband Ripple in dB; Rp > 0
%
As = Stopband Attenuation in dB; As > 0
% Omegac = Cutoff frequency in radians/sec
%
[z,p,k] = ellipap(N,Rp,As);
a = real(poly(p)); aNn = a(N+1);
p = p*Omegac; a = real(poly(p)); aNu = a(N+1);
b = real(poly(z)); M = length(b); bNn = b(M);
z = z*Omegac; b = real(poly(z)); bNu = b(M);
k = k*(aNu*bNn)/(aNn*bNu);
b0 = k; b = k*b;
Using the U elipap function, we provide a function called afd elip
to design an analog elliptic lowpass filter, given its specifications. This
is shown below and uses the filter order computation formula given in
(8.23).
336
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
function [b,a] = afd_elip(Wp,Ws,Rp,As);
% Analog Lowpass Filter Design: Elliptic
% -------------------------------------% [b,a] = afd_elip(Wp,Ws,Rp,As);
% b = Numerator coefficients of Ha(s)
% a = Denominator coefficients of Ha(s)
% Wp = Passband edge frequency in rad/sec; Wp > 0
% Ws = Stopband edge frequency in rad/sec; Ws > Wp > 0
% Rp = Passband ripple in +dB; (Rp > 0)
% As = Stopband attenuation in +dB; (As > 0)
%
if Wp <= 0
error(’Passband edge must be larger than 0’)
end
if Ws <= Wp
error(’Stopband edge must be larger than Passband edge’)
end
if (Rp <= 0) | (As < 0)
error(’PB ripple and/or SB attenuation ust be larger than 0’)
end
ep = sqrt(10^(Rp/10)-1); A = 10^(As/20);
OmegaC = Wp; k = Wp/Ws; k1 = ep/sqrt(A*A-1);
capk = ellipke([k.^2 1-k.^2]); % Version 4.0 code
capk1 = ellipke([(k1 .^2) 1-(k1 .^2)]); % Version 4.0 code
N = ceil(capk(1)*capk1(2)/(capk(2)*capk1(1)));
fprintf(’\n*** Elliptic Filter Order = %2.0f \n’,N)
[b,a]=u_elipap(N,Rp,As,OmegaC);
EXAMPLE 8.8
Solution
Design an analog elliptic lowpass filter to satisfy the following specifications of
Example 8.5:
Ωp = 0.2π,
Rp = 1 dB
Ωs = 0.3π,
As = 16 db
MATLAB Script:
>>
>>
>>
>>
Wp = 0.2*pi; Ws = 0.3*pi; Rp = 1; As = 16;
Ripple = 10 ^ (-Rp/20); Attn = 10 ^ (-As/20);
% Analog filter design:
[b,a] = afd_elip(Wp,Ws,Rp,As);
Characteristics of Prototype Analog Filters
337
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
*** Elliptic Filter Order = 3
>> % Calculation of second-order sections:
>> [C,B,A] = sdir2cas(b,a)
C = 0.2740
B = 1.0000
0
0.6641
A = 1.0000
0.1696
0.4102
0
1.0000
0.4435
>> % Calculation of Frequency Response:
>> [db,mag,pha,w] = freqs_m(b,a,0.5*pi);
>> % Calculation of Impulse response:
>> [ha,x,t] = impulse(b,a);
The specifications are satisfied by a 3rd-order elliptic filter whose system function is
Ha (s) =
0.274 s2 + 0.6641
(s2 + 0.1696s + 0.4102) (s + 0.4435)
The filter plots are shown in Figure 8.8.
Magnitude Response
Magnitude in dB
0
1
|H|
decibels
1
0.8913
16
0.1585
0
0
0.2
0.3
Analog frequency in pi units
30
0
0.5
0.2
0.3
Analog frequency in pi units
Phase Response
0.5
Impulse Response
1
0.2
ha(t)
radians
0.5
0
−0.5
−1
0
FIGURE 8.8
338
0.1
0
0.2
0.3
Analog frequency in pi units
0.5
0
10
20
30
40
time in seconds
Elliptic analog lowpass filter in Example 8.8
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
PHASE
RESPONSES
OF PROTOTYPE FILTERS
Elliptic filters provide optimal performance in the magnitude-squared response but have highly nonlinear phase response in the passband (which
is undesirable in many applications). Even though we decided not to
worry about phase response in our designs, phase is still an important
issue in the overall system. At the other end of the performance scale are
the Butterworth filters, which have maximally flat magnitude response
and require a higher-order N (more poles) to achieve the same stopband
specification. However, they exhibit a fairly linear phase response in
their passband. The Chebyshev filters have phase characteristics that lie
somewhere in between. Therefore in practical applications we do consider
Butterworth as well as Chebyshev filters, in addition to elliptic filters.
The choice depends on both the filter order (which influences processing speed and implementation complexity) and the phase characteristics
(which control the distortion).
ANALOG-TO-DIGITAL FILTER TRANSFORMATIONS
After discussing different approaches to the design of analog filters, we
are now ready to transform them into digital filters. These transformations are complex-valued mappings that are extensively studied in
the literature. These transformations are derived by preserving different
aspects of analog and digital filters. If we want to preserve the shape
of the impulse response from analog to digital filter, then we obtain a
technique called impulse invariance transformation. If we want to convert a differential equation representation into a corresponding difference
equation representation, then we obtain a finite difference approximation
technique. Numerous other techniques are also possible. One technique,
called step invariance, preserves the shape of the step response; this is
explored in Problem P8.14. Another technique that is similar to the
impulse invariance is the matched-z transformation, which matches the
pole-zero representation. It is described at the end of this section and is
explored in Problem P8.16. The most popular technique used in practice
is called a Bilinear transformation, which preserves the system function
representation from analog to digital domain. In this section we will study
in detail impulse invariance and bilinear transformations, both of which
can be easily implemented in MATLAB.
IMPULSE
INVARIANCE
TRANSFORMATION
In this design method we want the digital filter impulse response to look
“similar” to that of a frequency-selective analog filter. Hence we sample
ha (t) at some sampling interval T to obtain h(n); that is,
h(n) = ha (nT )
Analog-to-Digital Filter Transformations
339
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The parameter T is chosen so that the shape of ha (t) is “captured” by
the samples. Since this is a sampling operation, the analog and digital
frequencies are related by
ω = ΩT or ejω = ejΩT
Since z = ejω on the unit circle and s = jΩ on the imaginary axis, we
have the following transformation from the s-plane to the z-plane:
z = esT
(8.24)
The system functions H(z) and Ha (s) are related through the frequencydomain aliasing formula (3.27):
∞
1 (
2π
H(z) =
Ha s − j k
T
T
k=−∞
The complex plane transformation under the mapping (8.24) is shown in
Figure 8.9, from which we have the following observations:
1. Using σ = Re(s), we note that
σ < 0 maps into |z| < 1 (inside of the UC)
σ = 0 maps onto |z| = 1 (on the UC)
σ > 0 maps into |z| > 1 (outside of the UC)
2. All semi-infinite strips (shown above) of width 2π/T map into |z| < 1.
Thus this mapping is not unique but a many-to-one mapping.
3. Since the entire left half of the s-plane maps into the unit circle, a
causal and stable analog filter maps into a causal and stable digital
filter.
jΩ
Im {z}
3p /T
Unit circle
p/T
s
−p/T
s -plane
FIGURE 8.9
340
−3p/T
Many-to-one
transformation
e sT = z
Re {z}
z -plane
Complex-plane mapping in impulse invariance transformation
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4. If Ha (jΩ) = Ha (jω/T ) = 0 for |Ω| ≥ π/T , then
H(ejω ) =
1
Ha (jω/T ),
T
|ω| ≤ π
and there will be no aliasing. However, no analog filter of finite order
can be exactly band-limited. Therefore some aliasing error will occur
in this design procedure, and hence the sampling interval T plays a
minor role in this design method.
DESIGN
PROCEDURE
Given the digital lowpass filter specifications ωp , ωs , Rp , and As , we want
to determine H(z) by first designing an equivalent analog filter and then
mapping it into the desired digital filter. The steps required for this procedure are
1. Choose T and determine the analog frequencies
ωp
ωs
Ωp =
and
Ωs =
Tp
T
2. Design an analog filter Ha (s) using the specifications Ωp , Ωs , Rp , and
As . This can be done using any one of the three (Butterworth, Chebyshev, or elliptic) prototypes of the previous section.
3. Using partial fraction expansion, expand Ha (s) into
N
(
Ha (s) =
k=1
Rk
s − pk
4. Now transform analog poles {pk } into digital poles {epk T } to obtain
the digital filter:
N
(
Rk
(8.25)
H(z) =
1 − epk T z −1
k=1
EXAMPLE 8.9
Transform
Ha (s) =
s+1
s2 + 5s + 6
into a digital filter H(z) using the impulse invariance technique in which
T = 0.1.
Solution
We first expand Ha (s) using partial fraction expansion:
Ha (s) =
s+1
2
1
=
−
s2 + 5s + 6
s+3
s+2
The poles are at p1 = −3 and p2 = −2. Then from (8.25) and using T = 0.1,
we obtain
H(z) =
Analog-to-Digital Filter Transformations
2
1 − e−3T z −1
−
1
1 − e−2T z −1
=
1 − 0.8966z −1
1 − 1.5595z −1 + 0.6065z −2
341
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
It is easy to develop a MATLAB function to implement the impulse invariance mapping. Given a rational function description of Ha (s), we can use the
residue function to obtain its pole-zero description. Then each analog pole is
mapped into a digital pole using (8.24). Finally, the residuez function can be
used to convert H(z) into rational function form. This procedure is given in the
function imp invr.
function [b,a] = imp_invr(c,d,T)
% Impulse Invariance Transformation from Analog to Digital Filter
% --------------------------------------------------------------% [b,a] = imp_invr(c,d,T)
% b = Numerator polynomial in z^(-1) of the digital filter
% a = Denominator polynomial in z^(-1) of the digital filter
% c = Numerator polynomial in s of the analog filter
% d = Denominator polynomial in s of the analog filter
% T = Sampling (transformation) parameter
%
[R,p,k] = residue(c,d); p = exp(p*T);
[b,a] = residuez(R,p,k); b = real(b’); a = real(a’);
A similar function called impinvar is available in the SP toolbox of MATLAB.
EXAMPLE 8.10
Solution
We demonstrate the use of the imp invr function on the system function from
Example 8.9.
MATLAB Script:
>> c = [1,1]; d = [1,5,6]; T = 0.1;
>> [b,a] = imp_invr(c,d,T)
b = 1.0000
-0.8966
a = 1.0000
-1.5595
0.6065
The digital filter is
H(z) =
1 − 0.8966z −1
1 − 1.5595z −1 + 0.6065z −2
as expected. In Figure 8.10 we show the impulse responses and the magnitude
responses (plotted up to the sampling frequency 1/T ) of the analog and the
resulting digital filter. Clearly, the aliasing in the frequency domain is evident.
In the next several examples we illustrate the impulse invariance design procedure on all three prototypes.
342
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Impulse Responses
1
Amplitude
0.8
0.6
0.4
0.2
0
0
0.5
1
1.5
time in sec
2
2.5
3
Magnitude Responses
Magnitude
3
2
Digital filter
1
Analog filter
0
0
FIGURE 8.10
EXAMPLE 8.11
Solution
1
2
3
4
5
6
frequency in Hz
7
8
9
10
Impulse and frequency response plots in Example 8.10
Design a lowpass digital filter using a Butterworth prototype to satisfy
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
The design procedure is described in the following MATLAB script:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
>>
>>
>>
>>
% Analog Prototype Specifications: Inverse mapping for frequencies
T = 1;
% Set T=1
OmegaP = wp / T;
% Prototype Passband freq
OmegaS = ws / T;
% Prototype Stopband freq
%
%
%
%
digital Passband freq in Hz
digital Stopband freq in Hz
Passband ripple in dB
Stopband attenuation in dB
>> % Analog Butterworth Prototype Filter Calculation:
>> [cs,ds] = afd_butt(OmegaP,OmegaS,Rp,As);
*** Butterworth Filter Order = 6
Analog-to-Digital Filter Transformations
343
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> % Impulse Invariance transformation:
>> [b,a] = imp_invr(cs,ds,T); [C,B,A] = dir2par(b,a)
C = []
B = 1.8557
-0.6304
-2.1428
1.1454
0.2871
-0.4466
A = 1.0000
-0.9973
0.2570
1.0000
-1.0691
0.3699
1.0000
-1.2972
0.6949
The desired filter is a 6th-order Butterworth filter whose system function H(z)
is given in the parallel form
H(z) =
1.8587 − 0.6304z −1
−2.1428 + 1.1454z −1
+
−1
−2
1 − 0.9973z + 0.257z
1 − 1.0691z −1 + 0.3699z −2
−1
0.2871 − 0.4463z
+
1 − 1.2972z −1 + 0.6449z −2
The frequency response plots are given in Figure 8.11.
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
0
1
0.2 0.3
frequency in pi units
Magnitude in dB
1
Group Delay
10
8
Samples
decibels
0
1
15
6
4
2
0
FIGURE 8.11
344
0.2 0.3
frequency in pi units
1
0
0
0.2 0.3
frequency in pi units
1
Digital Butterworth lowpass filter using impulse invariance design
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 8.12
Solution
Design a lowpass digital filter using a Chebyshev-I prototype to satisfy
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
The design procedure is described in the following MATLAB script:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
>>
>>
>>
>>
% Analog Prototype Specifications: Inverse mapping for frequencies
T = 1;
% Set T=1
OmegaP = wp / T;
% Prototype Passband freq
OmegaS = ws / T;
% Prototype Stopband freq
%
%
%
%
digital Passband freq in rad
digital Stopband freq in rad
Passband ripple in dB
Stopband attenuation in dB
>> % Analog Chebyshev-1 Prototype Filter Calculation:
>> [cs,ds] = afd_chb1(OmegaP,OmegaS,Rp,As);
*** Chebyshev-1 Filter Order = 4
>> % Impulse Invariance transformation:
>> [b,a] = imp_invr(cs,ds,T); [C,B,A] = dir2par(b,a)
C = []
B =-0.0833
-0.0246
0.0833
0.0239
A = 1.0000
-1.4934
0.8392
1.0000
-1.5658
0.6549
The desired filter is a 4th-order Chebyshev-I filter whose system function H(z)
is
H(z) =
−0.0833 − 0.0246z −1
−0.0833 + 0.0239z −1
+
−1
−2
1 − 1.4934z + 0.8392z
1 − 1.5658z −1 + 0.6549z −2
The frequency response plots are given in Figure 8.12.
EXAMPLE 8.13
Solution
Design a lowpass digital filter using a Chebyshev-II prototype to satisfy
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
Recall that the Chebyshev-II filter is equiripple in the stopband. It means that
this analog filter has a response that does not go to zero at high frequencies in
the stopband. Therefore after impulse invariance transformation, the aliasing
effect will be significant; this can degrade the passband response. The MATLAB
script is shown:
Analog-to-Digital Filter Transformations
345
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
1
0
0.2 0.3
frequency in pi units
Magnitude in dB
1
Group Delay
15
Samples
decibels
0
1
15
0
FIGURE 8.12
0.2 0.3
frequency in pi units
10
5
0
0
1
0.2 0.3
frequency in pi units
1
Digital Chebyshev-I lowpass filter using impulse invariance design
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
>>
>>
>>
>>
% Analog Prototype Specifications: Inverse mapping for frequencies
T = 1;
% Set T=1
OmegaP = wp / T;
% Prototype Passband freq
OmegaS = ws / T;
% Prototype Stopband freq
%
%
%
%
digital Passband freq in rad
digital Stopband freq in rad
Passband ripple in dB
Stopband attenuation in dB
>> % Analog Chebyshev-1 Prototype Filter Calculation:
>> [cs,ds] = afd_chb2(OmegaP,OmegaS,Rp,As);
*** Chebyshev-2 Filter Order = 4
>> % Impulse Invariance transformation:
>> [b,a] = imp_invr(cs,ds,T); [C,B,A] = dir2par(b,a);
From the frequency response plots in Figure 8.13 we clearly observe the passband as well as stopband degradation. Hence the impulse invariance design
technique has failed to produce a desired digital filter.
346
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
1
0
0.2 0.3
frequency in pi units
Magnitude in dB
1
Group Delay
15
Samples
decibels
0
1
15
0
FIGURE 8.13
0.2 0.3
frequency in pi units
10
5
0
0
1
0.2 0.3
frequency in pi units
1
Digital Chebyshev-II lowpass filter using impulse invariance
design
EXAMPLE 8.14
Solution
Design a lowpass digital filter using an elliptic prototype to satisfy
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
The elliptic filter is equiripple in both bands. Hence this situation is similar to
that of the Chebyshev-II filter, and we should not expect a good digital filter.
The MATLAB script is shown:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
>>
>>
>>
>>
% Analog Prototype Specifications: Inverse mapping for frequencies
T = 1;
% Set T=1
OmegaP = wp / T;
% Prototype Passband freq
OmegaS = ws / T;
% Prototype Stopband freq
%
%
%
%
digital Passband freq in rad
digital Stopband freq in rad
Passband ripple in dB
Stopband attenuation in dB
>> % Analog Elliptic Prototype Filter Calculation:
>> [cs,ds] = afd_elip(OmegaP,OmegaS,Rp,As);
*** Elliptic Filter Order = 3
Analog-to-Digital Filter Transformations
347
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
1
0
0.2 0.3
frequency in pi units
Magnitude in dB
1
Group Delay
15
Samples
decibels
0
1
15
0
FIGURE 8.14
0.2 0.3
frequency in pi units
1
10
5
0
0
0.2 0.3
frequency in pi units
1
Digital elliptic lowpass filter using impulse invariance design
>> % Impulse Invariance transformation:
>> [b,a] = imp_invr(cs,ds,T); [C,B,A] = dir2par(b,a);
From the frequency response plots in Figure 8.14 we clearly observe that once
again the impulse invariance design technique has failed.
The advantages of the impulse invariance mapping are that it is a
stable design and that the frequencies Ω and ω are linearly related. But
the disadvantage is that we should expect some aliasing of the analog
frequency response, and in some cases this aliasing is intolerable. Consequently, this design method is useful only when the analog filter is essentially band-limited to a lowpass or bandpass filter in which there are no
oscillations in the stopband.
BILINEAR
TRANSFORMATION
This mapping is the best transformation method; it involves a well-known
function given by
s=
348
1 + sT /2
2 1 − z −1
=⇒ z =
T 1 + z −1
1 − sT /2
(8.26)
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where T is a parameter. Another name for this transformation is the linear
fractional transformation because when cleared of fractions, we obtain
T
T
sz + s − z + 1 = 0
2
2
which is linear in each variable if the other is fixed, or bilinear in s and z.
The complex plane mapping under (8.26) is shown in Figure 8.15, from
which we have the following observations:
1. Using s = σ + jΩ in (8.26), we obtain
z=
Hence
1+
ΩT
σT
+j
2
2
)
1−
σT
ΩT
−j
2
2
1 + σT + j ΩT
2
2
σ < 0 =⇒ |z| = ΩT
1 − σT
−
j
2
2
1 + j ΩT 2 σ = 0 =⇒ |z| =
1 − j ΩT
2
1 + σT + j ΩT
2
2
σ > 0 =⇒ |z| = ΩT
1 − σT
2 −j 2
(8.27)
<1
=1
>1
2. The entire left half-plane maps into the inside of the unit circle. Hence
this is a stable transformation.
3. The imaginary axis maps onto the unit circle in a one-to-one fashion.
Hence there is no aliasing in the frequency domain.
jΩ
Im {z}
Unit circle
s
One-to-one
transformation
1 + (sT /2)
=
1 − (sT /2)
s -plane
FIGURE 8.15
Analog-to-Digital Filter Transformations
Re {z}
z
z -plane
Complex-plane mapping in bilinear transformation
349
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Substituting σ = 0 in (8.27), we obtain
z=
1 + j ΩT
2
= ejω
1 − j ΩT
2
since the magnitude is 1. Solving for ω as a function of Ω, we obtain
ω ΩT
2
or
Ω = tan
(8.28)
ω = 2 tan−1
2
T
2
This shows that Ω is nonlinearly related to (or warped into) ω but that
there is no aliasing. Hence in (8.28) we will say that ω is prewarped into
Ω.
EXAMPLE 8.15
Solution
s+1
into a digital filter using the bilinear transfors2 + 5s + 6
mation. Choose T = 1.
Transform Ha (s) =
Using (8.26), we obtain
H(z) = Ha
2 1 − z −1 T 1 + z −1 T =1
= Ha
2
1 − z −1
1 + z −1
1 − z −1
+1
1 + z −1
= 2
1 − z −1
1 − z −1
2
+5 2
+6
1 + z −1
1 + z −1
2
Simplifying,
H(z) =
0.15 + 0.1z −1 − 0.05z −2
3 + 2z −1 − z −2
=
20 + 4z −1
1 + 0.2z −1
MATLAB provides a function called bilinear to implement this
mapping. Its invocation is similar to the imp invr function, but it also
takes several forms for different input-output quantities. The SP toolbox manual should be consulted for more details. Its use is shown in the
following example.
EXAMPLE 8.16
Solution
Transform the system function Ha (s) in Example 8.15 using the bilinear function.
MATLAB Script:
>> c = [1,1]; d = [1,5,6]; T = 1; Fs = 1/T;
>> [b,a] = bilinear(c,d,Fs)
b = 0.1500
0.1000
-0.0500
a = 1.0000
0.2000
0.0000
350
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The filter is
H(z) =
0.15 + 0.1z −1 − 0.05z −2
1 + 0.2z −1
as before.
DESIGN
PROCEDURE
Given digital filter specifications ωp , ωs , Rp , and As , we want to determine
H(z). The design steps in this procedure are the following:
1. Choose a value for T . This is arbitrary, and we may set T = 1.
2. Prewarp the cutoff frequencies ωp and ωs ; that is, calculate Ωp and Ωs
using (8.28):
ω ω 2
2
p
s
Ωp = tan
, Ωs = tan
(8.29)
T
2
T
2
3. Design an analog filter Ha (s) to meet the specifications Ωp , Ωs , Rp ,
and As . We have already described how to do this in the previous
section.
4. Finally, set
2 1 − z −1
H(z) = Ha
T 1 + z −1
and simplify to obtain H(z) as a rational function in z −1 .
In the next several examples we demonstrate this design procedure
on our analog prototype filters.
EXAMPLE 8.17
Solution
Design the digital Butterworth filter of Example 8.11. The specifications are
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
MATLAB Script:
>> % Digital Filter Specifications:
>> wp = 0.2*pi;
% digital Passband freq in rad
>> ws = 0.3*pi;
% digital Stopband freq in rad
>> Rp = 1;
% Passband ripple in dB
>> As = 15;
% Stopband attenuation in dB
>> % Analog Prototype Specifications: Inverse mapping for frequencies
>> T = 1; Fs = 1/T;
% Set T=1
>> OmegaP = (2/T)*tan(wp/2);
% Prewarp Prototype Passband freq
>> OmegaS = (2/T)*tan(ws/2);
% Prewarp Prototype Stopband freq
>> % Analog Butterworth Prototype Filter Calculation:
>> [cs,ds] = afd_butt(OmegaP,OmegaS,Rp,As);
*** Butterworth Filter Order = 6
Analog-to-Digital Filter Transformations
351
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> % Bilinear transformation:
>> [b,a] = bilinear(cs,ds,Fs);
C = 5.7969e-004
B = 1.0000
2.0183
1.0186
1.0000
1.9814
0.9817
1.0000
2.0004
1.0000
A = 1.0000
-0.9459
0.2342
1.0000
-1.0541
0.3753
1.0000
-1.3143
0.7149
[C,B,A] = dir2cas(b,a)
The desired filter is once again a 6th-order filter and has 6 zeros. Since the
6th-order zero of Ha (s) at s = −∞ is mapped to z = −1, these zeros should be
at z = −1. Due to the finite precision of MATLAB these zeros are not exactly
at z = −1. Hence the system function should be
H(z) =
0.00057969 1 + z −1
6
(1 − 0.9459z −1 + 0.2342z −2 ) (1 − 1.0541z −1 + 0.3753z −2 ) (1 − 1.3143z −1 + 0.7149z −2 )
The frequency response plots are given in Figure 8.16. Comparing these plots
with those in Figure 8.11, we observe that these two designs are very similar.
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
1
0
0.2 0.3
frequency in pi units
Magnitude in dB
1
Group Delay
10
8
Samples
decibels
0
1
15
6
4
2
0
FIGURE 8.16
352
0.2 0.3
frequency in pi units
1
0
0
0.2 0.3
frequency in pi units
1
Digital Butterworth lowpass filter using bilinear transformation
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 8.18
Solution
Design the digital Chebyshev-I filter of Example 8.12. The specifications are
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
MATLAB Script:
>> % Digital Filter Specifications:
>> wp = 0.2*pi;
% digital Passband freq in rad
>> ws = 0.3*pi;
% digital Stopband freq in rad
>> Rp = 1;
% Passband ripple in dB
>> As = 15;
% Stopband attenuation in dB
>> % Analog Prototype Specifications: Inverse mapping for frequencies
>> T = 1; Fs = 1/T;
% Set T=1
>> OmegaP = (2/T)*tan(wp/2);
% Prewarp Prototype Passband freq
>> OmegaS = (2/T)*tan(ws/2);
% Prewarp Prototype Stopband freq
>> % Analog Chebyshev-1 Prototype Filter Calculation:
>> [cs,ds] = afd_chb1(OmegaP,OmegaS,Rp,As);
*** Chebyshev-1 Filter Order = 4
>> % Bilinear transformation:
>> [b,a] = bilinear(cs,ds,Fs); [C,B,A] = dir2cas(b,a)
C = 0.0018
B = 1.0000
2.0000
1.0000
1.0000
2.0000
1.0000
A = 1.0000
-1.4996
0.8482
1.0000
-1.5548
0.6493
The desired filter is a 4th-order filter and has 4 zeros at z = −1. The system
function is
H(z) =
0.0018 1 + z −1
4
(1 − 1.4996z −1 + 0.8482z −2 ) (1 − 1.5548z −1 + 0.6493z −2 )
The frequency response plots are given in Figure 8.17 which are similar to those
in Figure 8.12.
EXAMPLE 8.19
Solution
Design the digital Chebyshev-II filter of Example 8.13. The specifications are
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
MATLAB Script:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
Analog-to-Digital Filter Transformations
%
%
%
%
digital Passband freq in rad
digital Stopband freq in rad
Passband ripple in dB
Stopband attenuation in dB
353
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
1
0
0.2 0.3
frequency in pi units
Magnitude in dB
1
Group Delay
15
Samples
decibels
0
1
15
0
FIGURE 8.17
0.2 0.3
frequency in pi units
1
10
5
0
0
0.2 0.3
frequency in pi units
1
Digital Chebyshev-I lowpass filter using bilinear transformation
>> % Analog Prototype Specifications: Inverse mapping for frequencies
>> T = 1; Fs = 1/T;
% Set T=1
>> OmegaP = (2/T)*tan(wp/2);
% Prewarp Prototype Passband freq
>> OmegaS = (2/T)*tan(ws/2);
% Prewarp Prototype Stopband freq
>> % Analog Chebyshev-2 Prototype Filter Calculation:
>> [cs,ds] = afd_chb2(OmegaP,OmegaS,Rp,As);
*** Chebyshev-2 Filter Order = 4
>> % Bilinear transformation:
>> [b,a] = bilinear(cs,ds,Fs); [C,B,A] = dir2cas(b,a)
C = 0.1797
B = 1.0000
0.5574
1.0000
1.0000
-1.0671
1.0000
A = 1.0000
-0.4183
0.1503
1.0000
-1.1325
0.7183
The desired filter is again a 4th-order filter with system function
H(z) =
0.1797 1 + 0.5574z −1 + z −2
1 − 1.0671z −1 + z −2
(1 − 0.4183z −1 + 0.1503z −2 ) (1 − 1.1325z −1 + 0.7183z −2 )
The frequency response plots are given in Figure 8.18. Note that the bilinear
transformation has properly designed the Chebyshev-II digital filter.
354
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
1
0
Magnitude in dB
0.2 0.3
frequency in pi units
1
Group Delay
15
15
0
FIGURE 8.18
EXAMPLE 8.20
Solution
Samples
decibels
0
1
0.2 0.3
frequency in pi units
1
10
5
0
0
0.2 0.3
frequency in pi units
1
Digital Chebyshev-II lowpass filter using bilinear transformation
Design the digital elliptic filter of Example 8.14. The specifications are
ωp = 0.2π,
Rp = 1 dB
ωs = 0.3π,
As = 15 dB
MATLAB Script:
>> % Digital Filter Specifications:
>> wp = 0.2*pi;
% digital Passband freq in rad
>> ws = 0.3*pi;
% digital Stopband freq in rad
>> Rp = 1;
% Passband ripple in dB
>> As = 15;
% Stopband attenuation in dB
>> % Analog Prototype Specifications: Inverse mapping for frequencies
>> T = 1; Fs = 1/T;
% Set T=1
>> OmegaP = (2/T)*tan(wp/2);
% Prewarp Prototype Passband freq
>> OmegaS = (2/T)*tan(ws/2);
% Prewarp Prototype Stopband freq
>> % Analog Elliptic Prototype Filter Calculation:
>> [cs,ds] = afd_elip(OmegaP,OmegaS,Rp,As);
*** Elliptic Filter Order = 3
>> % Bilinear transformation:
Analog-to-Digital Filter Transformations
355
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> [b,a] = bilinear(cs,ds,Fs);
C = 0.1214
B = 1.0000
-1.4211
1.0000
1.0000
1.0000
0
A = 1.0000
-1.4928
0.8612
1.0000
-0.6183
0
[C,B,A] = dir2cas(b,a)
The desired filter is a 3rd-order filter with system function
H(z) =
0.1214 1 − 1.4211z −1 + z −2
1 + z −1
(1 − 1.4928z −1 + 0.8612z −2 ) (1 − 0.6183z −1 )
The frequency response plots are given in Figure 8.19. Note that the bilinear
transformation has again properly designed the elliptic digital filter.
The advantages of this mapping are that (a) it is a stable design,
(b) there is no aliasing, and (c) there is no restriction on the type of filter
that can be transformed. Therefore this method is used exclusively in
computer programs including MATLAB as we shall see next.
MATCHED-z
TRANSFORMATION
In this method of filter transformation, zeros and poles of Ha (s) are directly mapped into zeros and poles in the z-plane using an exponential
function. Given a root (zero or pole) at the location s = a in the s-plane,
Magnitude Response
Phase Response
1
|H|
pi units
1
0.8913
0
0.1778
0
0
0.2 0.3
frequency in pi units
−1
1
0
0.2 0.3
frequency in pi units
Magnitude in dB
1
Group Delay
15
15
0
FIGURE 8.19
356
Samples
decibels
0
1
0.2 0.3
frequency in pi units
1
10
5
0
0
0.2 0.3
frequency in pi units
1
Digital elliptic lowpass filter using bilinear transformation
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
we map it in the z-plane at z = eaT where T is a sampling interval. Thus,
the system function Ha (s) with zeros {zk } and poles {p } is mapped into
the digital filter system function H(z) as
M M
zk T −1
z
k=1 1 − e
k=1 (s − zk )
Ha (s) = N
→ H(z) = N
(8.30)
p T z −1 )
=1 (s − p )
=1 (s − e
Clearly the z-transform system function is “matched” to the s-domain
system function.
Note that this technique appears to be similar to the impulse invariance mapping in that the pole locations are identical and aliasing is unavoidable. However, these two techniques differ in zero locations. Also the
matched-z transformation does not preserve either the impulse response
or the frequency response characteristics. Hence it is suitable when designing using pole-zero placement, but it is generally unsuitable when the
frequency-domain specifications are given.
LOWPASS FILTER DESIGN USING MATLAB
In this section we will demonstrate the use of MATLAB’s filter design
functions to design digital lowpass filters. These functions use the bilinear
transformation because of its desirable advantages as discussed in the
previous section. These functions are as follows:
1. [b,a]=butter(N,wn)
This function designs an Nth-order lowpass digital Butterworth filter
and returns the filter coefficients in length N + 1 vectors b and a. The
filter order is given by (8.10), and the cutoff frequency wn is determined
by the prewarping formula (8.29). However, in MATLAB all digital
frequencies are given in units of π. Hence wn is computed by using the
following relation:
Ωc T
2
ωn = tan−1
π
2
The use of this function is given in Example 8.21.
2. [b,a]=cheby1(N,Rp,wn)
This function designs an Nth-order lowpass digital Chebyshev-I filter
with Rp decibels of ripple in the passband. It returns the filter coefficients in length N + 1 vectors b and a. The filter order is given by
(8.20), and the cutoff frequency wn is the digital passband frequency
in units of π; that is,
ωn = ωp /π
The use of this function is given in Example 8.22.
Lowpass Filter Design Using MATLAB
357
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3. [b,a]=cheby2(N,As,wn)
This function designs an Nth-order lowpass digital Chebyshev-II filter
with the stopband attenuation As decibels. It returns the filter coefficients in length N + 1 vectors b and a. The filter order is given by
(8.20), and the cutoff frequency wn is the digital stopband frequency
in units of π; that is,
ωn = ωs /π
The use of this function is given in Example 8.23.
4. [b,a]=ellip(N,Rp,As,wn)
This function designs an Nth-order lowpass digital elliptic filter with
the passband ripple of Rp decibels and a stopband attenuation of As
decibels. It returns the filter coefficients in length N + 1 vectors b and
a. The filter order is given by (8.23), and the cutoff frequency wn is the
digital passband frequency in units of π; that is,
ωn = ωp /π
The use of this function is given in Example 8.24.
All these above functions can also be used to design other frequencyselective filters, such as highpass and bandpass. We will discuss their
additional capabilities in Section 8.5.
There is also another set of filter functions, namely the buttord,
cheb1ord, cheb2ord, and ellipord functions, which can provide filter
order N and filter cutoff frequency ωn , given the specifications. These
functions are available in the Signal Processing toolbox. In the examples
to follow we will determine these parameters using the formulas given
earlier. We will discuss the filter-order functions in the next section.
In the following examples we will redesign the same lowpass filters
of previous examples and compare their results. The specifications of the
lowpass digital filter are
ωp = 0.2π, Rp = 1 dB
ωs = 0.3π,
358
EXAMPLE 8.21
As = 15 dB
Digital Butterworth lowpass filter design:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
%digital Passband freq in rad
%digital Stopband freq in rad
%Passband ripple in dB
%Stopband attenuation in dB
>>
>>
>>
>>
% Analog Prototype Specifications:
T = 1;
OmegaP = (2/T)*tan(wp/2);
OmegaS = (2/T)*tan(ws/2);
%Set T=1
%Prewarp Prototype Passband freq
%Prewarp Prototype Stopband freq
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>>
>>
>>
**
>>
>>
% Analog Prototype Order Calculation:
N =ceil((log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(OmegaP/OmegaS)));
fprintf(’\n*** Butterworth Filter Order = %2.0f \n’,N)
Butterworth Filter Order = 6
OmegaC = OmegaP/((10^(Rp/10)-1)^(1/(2*N))); %Analog BW prototype cutoff
wn = 2*atan((OmegaC*T)/2);
%Digital BW cutoff freq
>> % Digital Butterworth Filter Design:
>> wn = wn/pi;
%Digital Butter cutoff in pi units
>> [b,a]=butter(N,wn); [b0,B,A] = dir2cas(b,a)
C = 5.7969e-004
B = 1.0000
2.0297
1.0300
1.0000
1.9997
1.0000
1.0000
1.9706
0.9709
A = 1.0000
-0.9459
0.2342
1.0000
-1.0541
0.3753
1.0000
-1.3143
0.7149
The system function is
H(z) =
0.00057969 1 + z −1
6
(1 − 0.9459z −1 + 0.2342z −2 ) (1 − 1.0541z −1 + 0.3753z −2 ) (1 − 1.3143z −1 + 0.7149z −2 )
which is the same as in Example 8.17. The frequency-domain plots were shown
in Figure 8.16.
EXAMPLE 8.22
Digital Chebyshev-I lowpass filter design:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
%digital Passband freq in rad
%digital Stopband freq in rad
%Passband ripple in dB
%Stopband attenuation in dB
>>
>>
>>
>>
% Analog Prototype Specifications:
T = 1;
OmegaP = (2/T)*tan(wp/2);
OmegaS = (2/T)*tan(ws/2);
%Set T=1
%Prewarp Prototype Passband freq
%Prewarp Prototype Stopband freq
>> % Analog Prototype Order Calculation:
>> ep = sqrt(10^(Rp/10)-1);
%Passband Ripple Factor
>> A = 10^(As/20);
%Stopband Attenuation Factor
>> OmegaC = OmegaP;
%Analog Prototype Cutoff freq
>> OmegaR = OmegaS/OmegaP;
%Analog Prototype Transition Ratio
>> g = sqrt(A*A-1)/ep;
%Analog Prototype Intermediate cal.
>> N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1)));
>> fprintf(’\n*** Chebyshev-1 Filter Order = %2.0f \n’,N)
*** Chebyshev-1 Filter Order = 4
Lowpass Filter Design Using MATLAB
359
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> % Digital Chebyshev-I Filter Design:
>> wn = wp/pi;
%Digital Passband freq in pi units
>> [b,a]=cheby1(N,Rp,wn); [b0,B,A] = dir2cas(b,a)
b0 = 0.0018
B = 1.0000
2.0000
1.0000
1.0000
2.0000
1.0000
A = 1.0000
-1.4996
0.8482
1.0000
-1.5548
0.6493
The system function is
H(z) =
0.0018 1 + z −1
4
(1 − 1.4996z −1 + 0.8482z −2 ) (1 − 1.5548z −1 + 0.6493z −2 )
which is the same as in Example 8.18. The frequency-domain plots were shown
in Figure 8.17.
EXAMPLE 8.23
Digital Chebyshev-II lowpass filter design:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
%digital Passband freq in rad
%digital Stopband freq in rad
%Passband ripple in dB
%Stopband attenuation in dB
>>
>>
>>
>>
% Analog Prototype Specifications:
T = 1;
OmegaP = (2/T)*tan(wp/2);
OmegaS = (2/T)*tan(ws/2);
%Set T=1
%Prewarp Prototype Passband freq
%Prewarp Prototype Stopband freq
>> % Analog Prototype Order Calculation:
>> ep = sqrt(10^(Rp/10)-1);
%Passband Ripple Factor
>> A = 10^(As/20);
%Stopband Attenuation Factor
>> OmegaC = OmegaP;
%Analog Prototype Cutoff freq
>> OmegaR = OmegaS/OmegaP;
%Analog Prototype Transition Ratio
>> g = sqrt(A*A-1)/ep;
%Analog Prototype Intermediate cal.
>> N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1)));
>> fprintf(’\n*** Chebyshev-2 Filter Order = %2.0f \n’,N)
*** Chebyshev-2 Filter Order = 4
>> % Digital Chebyshev-II Filter Design:
>> wn = ws/pi;
%Digital Stopband freq in pi units
>> [b,a]=cheby2(N,As,wn); [b0,B,A] = dir2cas(b,a)
b0 = 0.1797
B = 1.0000
0.5574
1.0000
1.0000
-1.0671
1.0000
A = 1.0000
-0.4183
0.1503
1.0000
-1.1325
0.7183
360
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The system function is
H(z) =
0.1797 1 + 0.5574z −1 + z −2
1 − 1.0671z −1 + z −2
(1 − 0.4183z −1 + 0.1503z −2 ) (1 − 1.1325z −1 + 0.7183z −2 )
which is the same as in Example 8.19. The frequency-domain plots were shown
in Figure 8.18.
EXAMPLE 8.24
Digital elliptic lowpass filter design:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
wp = 0.2*pi;
ws = 0.3*pi;
Rp = 1;
As = 15;
%digital Passband freq in rad
%digital Stopband freq in rad
%Passband ripple in dB
%Stopband attenuation in dB
>>
>>
>>
>>
% Analog Prototype Specifications:
T = 1;
OmegaP = (2/T)*tan(wp/2);
OmegaS = (2/T)*tan(ws/2);
%Set T=1
%Prewarp Prototype Passband freq
%Prewarp Prototype Stopband freq
>> % Analog Elliptic Filter order calculations:
>> ep = sqrt(10^(Rp/10)-1);
%Passband Ripple Factor
>> A = 10^(As/20);
%Stopband Attenuation Factor
>> OmegaC = OmegaP;
%Analog Prototype Cutoff freq
>> k = OmegaP/OmegaS;
%Analog Prototype Transition Ratio;
>> k1 = ep/sqrt(A*A-1);
%Analog Prototype Intermediate cal.
>> capk = ellipke([k.^2 1-k.^2]);
>> capk1 = ellipke([(k1 .^2) 1-(k1 .^2)]);
>> N = ceil(capk(1)*capk1(2)/(capk(2)*capk1(1)));
>> fprintf(’\n*** Elliptic Filter Order = %2.0f \n’,N)
*** Elliptic Filter Order = 3
>> % Digital Elliptic Filter Design:
>> wn = wp/pi;
%Digital Passband freq in pi units
>> [b,a]=ellip(N,Rp,As,wn); [b0,B,A] = dir2cas(b,a)
b0 = 0.1214
B = 1.0000
-1.4211
1.0000
1.0000
1.0000
0
A = 1.0000
-1.4928
0.8612
1.0000
-0.6183
0
The system function is
H(z) =
0.1214 1 − 1.4211z −1 + z −2
1 + z −1
(1 − 1.4928z −1 + 0.8612z −2 ) (1 − 0.6183z −1 )
which is the same as in Example 8.20. The frequency-domain plots were shown
in Figure 8.19.
Lowpass Filter Design Using MATLAB
361
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
TABLE 8.1
Prototype
Butterworth
Chebyshev-I
Elliptic
COMPARISON
OF THREE
FILTERS
Comparison of three filters
Order N
Stopband Att.
6
4
3
15
25
27
In our examples we designed the same digital filter using four different
prototype analog filters. Let us compare their performance. The specifications were ωp = 0.2π, Rp = 1 dB, ωs = 0.3π, and As = 15 dB. This
comparison in terms of order N and the minimum stopband attenuations
is shown in Table 8.1.
Clearly, the elliptic prototype gives the best design. However, if we
compare their phase responses, then the elliptic design has the most nonlinear phase response in the passband.
FREQUENCY-BAND TRANSFORMATIONS
In the preceding two sections we designed digital lowpass filters from
their corresponding analog filters. Certainly, we would like to design other
types of frequency-selective filters, such as highpass, bandpass, and bandstop. This is accomplished by transforming the frequency axis (or band)
of a lowpass filter so that it behaves as another frequency-selective filter. These transformations on the complex variable z are very similar
to bilinear transformations, and the design equations are algebraic. The
procedure to design a general frequency-selective filter is to first design
a digital prototype (of fixed bandwidth, say unit bandwidth) lowpass filter and then to apply these algebraic transformations. In this section we
will describe the basic philosophy behind these mappings and illustrate
their mechanism through examples. MATLAB provides functions that
incorporate frequency-band transformation in the s-plane. We will first
demonstrate the use of the z-plane mapping and then illustrate the use
of MATLAB functions. Typical specifications for most commonly used
types of frequency-selective digital filters are shown in Figure 8.20.
Let HLP (Z) be the given prototype lowpass digital filter, and let H(z)
be the desired frequency-selective digital filter. Note that we are using
two different frequency variables, Z and z, with HLP and H, respectively.
Define a mapping of the form
Z −1 = G(z −1 )
such that
H(z) = HLP (Z)|Z −1 =G(z−1 )
362
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 8.20
Specifications of frequency-selective filters
To do this, we simply replace Z −1 everywhere in HLP by the function
G(z −1 ). Given that HLP (Z) is a stable and causal filter, we also want
H(z) to be stable and causal. This imposes the following requirements:
1. G(·) must be a rational function in z −1 so that H(z) is implementable.
2. The unit circle of the Z-plane must map onto the unit circle of the
z-plane.
3. For stable filters, the inside of the unit circle of the Z-plane must also
map onto the inside of the unit circle of the z-plane.
Let ω and ω be the frequency variables of Z and z, respectively—that
is, Z = ejω and z = ejω on their respective unit circles. Then requirement
2 above implies that
−1 Z = G(z −1 ) = G(e−jω ) = 1
and
or
Frequency-band Transformations
e−jω = G(e−jω ) ej
G(e−jω )
−ω = G(e−jω )
363
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The general form of the function G(·) that satisfies the above requirements
is a rational function of the all-pass type given by
n
*
z −1 − αk
Z −1 = G z −1 = ±
1 − αk z −1
k=1
where |αk | < 1 for stability and to satisfy requirement 3.
Now by choosing an appropriate order n and the coefficients {αk }, we
can obtain a variety of mappings. The most widely used transformations
are given in Table 8.2. We will now illustrate the use of this table for
designing a highpass digital filter.
Frequency transformation for digital filters (prototype lowpass filter
has cutoff frequency ωc )
TABLE 8.2
Type of
Transformation
Transformation
Lowpass
z −1 −→
z −1 − α
1 − αz −1
Parameters
ωc = cutoff frequency of new filter
α=
Highpass
z −1 −→ −
z −1 + α
1 + αz −1
sin [(ωc − ωc ) /2]
sin [(ωc + ωc ) /2]
ωc = cutoff frequency of new filter
α=−
Bandpass
z −1 −→ −
z −2 − α1 z −1 + α2
α2 z −2 − α1 z −1 + 1
cos [(ωc + ωc ) /2]
cos [(ωc − ωc ) /2]
ω = lower cutoff frequency
ωu = upper cutoff frequency
α1 = −2βK/(K + 1)
α2 = (K − 1)/(K + 1)
β=
cos [(ωu + ω ) /2]
cos [(ωu − ω ) /2]
K = cot
Bandstop
z −1 −→
z −2 − α1 z −1 + α2
α2 z −2 − α1 z −1 + 1
ωu − ω
ω
tan c
2
2
ω = lower cutoff frequency
ωu = upper cutoff frequency
α1 = −2β/(K + 1)
α2 = (K − 1)/(K + 1)
β=
cos [(ωu + ω ) /2]
cos [(ωu − ω ) /2]
K = tan
364
ωu − ω
ω
tan c
2
2
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 8.25
In Example 8.22 we designed a Chebyshev-I lowpass filter with specifications
ωp = 0.2π,
Rp = 1 dB
ωs
As = 15 dB
= 0.3π,
and determined its system function
HLP (Z) =
(1 −
1.4996Z −1
0.001836(1 + Z −1 )4
+ 0.8482Z −2 )(1 − 1.5548Z −1 + 0.6493Z −2 )
Design a highpass filter with the above tolerances but with passband beginning
at ωp = 0.6π.
Solution
We want to transform the given lowpass filter into a highpass filter such that
the cutoff frequency ωp = 0.2π is mapped onto the cutoff frequency ωp = 0.6π.
From Table 8.2
cos[(0.2π + 0.6π)/2]
(8.31)
= −0.38197
α=−
cos[(0.2π − 0.6π)/2]
Hence
HLP (z) = H(Z)|
−1 −0.38197
Z=− z
−1
1−0.38197z
=
0.02426(1 − z −1 )4
(1 + 0.5661z −1 + 0.7657z −2 )(1 + 1.0416z −1 + 0.4019z −2 )
which is the desired filter. The frequency response plots of the lowpass filter
and the new highpass filter are shown in Figure 8.21.
Lowpass Filter Magnitude Response
Lowpass Filter Magnitude in dB
0
1
|H|
decibels
1
0.8913
0
0
0.2
frequency in pi units
30
0
1
Highpass Filter Magnitude Response
1
0.8913
1
Highpass Filter Magnitude in dB
0
1
decibels
|H|
0
0
FIGURE 8.21
Frequency-band Transformations
0.2
frequency in pi units
0.6
frequency in pi units
1
30
0
0.6
frequency in pi units
1
Magnitude response plots for Example 8.25
365
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
From the above example it is obvious that to obtain the rational
function of a new digital filter from the prototype lowpass digital filter,
we should be able to implement rational function substitutions from Table 8.2. This appears to be a difficult task, but since these are algebraic
functions, we can use the conv function repetitively for this purpose. The
following zmapping function illustrates this approach.
function [bz,az] = zmapping(bZ,aZ,Nz,Dz)
% Frequency band Transformation from Z-domain to z-domain
% ------------------------------------------------------% [bz,az] = zmapping(bZ,aZ,Nz,Dz)
% performs:
%
b(z)
b(Z)|
%
---- = ----|
N(z)
%
a(z)
a(Z)|@Z = ---%
D(z)
%
bNzord = (length(bZ)-1)*(length(Nz)-1);
aDzord = (length(aZ)-1)*(length(Dz)-1);
bzord = length(bZ)-1; azord = length(aZ)-1;
bz = zeros(1,bNzord+1);
for k = 0:bzord
pln = [1];
for l = 0:k-1
pln = conv(pln,Nz);
end
pld = [1];
for l = 0:bzord-k-1
pld = conv(pld,Dz);
end
bz = bz+bZ(k+1)*conv(pln,pld);
end
az = zeros(1,aDzord+1);
for k = 0:azord
pln = [1];
for l = 0:k-1
pln = conv(pln,Nz);
end
pld = [1];
for l = 0:azord-k-1
pld = conv(pld,Dz);
end
az = az+aZ(k+1)*conv(pln,pld);
end
366
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 8.26
Solution
Use the zmapping function to perform the lowpass-to-highpass transformation
in Example 8.25.
First we will design the lowpass digital filter in MATLAB using the bilinear
transformation procedure and then use the zmapping function.
MATLAB Script:
>> % Digital Lowpass Filter Specifications:
>> wplp = 0.2*pi;
% digital Passband freq in rad
>> wslp = 0.3*pi;
% digital Stopband freq in rad
>>
Rp = 1;
% Passband ripple in dB
>>
As = 15;
% Stopband attenuation in dB
>>
>>
>>
>>
% Analog Prototype Specifications: Inverse mapping for frequencies
T = 1; Fs = 1/T;
% Set T=1
OmegaP = (2/T)*tan(wplp/2);
% Prewarp Prototype Passband freq
OmegaS = (2/T)*tan(wslp/2);
% Prewarp Prototype Stopband freq
>> % Analog Chebyshev Prototype Filter Calculation:
>> [cs,ds] = afd_chb1(OmegaP,OmegaS,Rp,As);
** Chebyshev-1 Filter Order = 4
>> % Bilinear transformation:
>> [blp,alp] = bilinear(cs,ds,Fs);
>> % Digital Highpass Filter Cutoff frequency:
>> wphp = 0.6*pi;
% Passband edge frequency
>> % LP-to-HP frequency-band transformation:
>> alpha = -(cos((wplp+wphp)/2))/(cos((wplp-wphp)/2))
alpha = -0.3820
>> Nz = -[alpha,1]; Dz = [1,alpha];
>> [bhp,ahp] = zmapping(blp,alp,Nz,Dz);
C = 0.0243
B = 1.0000
-2.0000
1.0000
1.0000
-2.0000
1.0000
A = 1.0000
1.0416
0.4019
1.0000
0.5561
0.7647
[C,B,A] = dir2cas(bhp,ahp)
The system function of the highpass filter is
H(z) =
0.0243(1 − z −1 )4
(1 + 0.5661z −1 + 0.7647z −2 )(1 + 1.0416z −1 + 0.4019z −2 )
which is essentially identical to that in Example 8.25.
Frequency-band Transformations
367
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
DESIGN
PROCEDURE
In Example 8.26 a lowpass prototype digital filter was available to transform into a highpass filter so that a particular band-edge frequency was
properly mapped. In practice we have to first design a prototype lowpass
digital filter whose specifications should be obtained from specifications
of other frequency-selective filters as given in Figure 8.20. We will now
show that the lowpass prototype filter specifications can be obtained from
the transformation formulas given in Table 8.2.
Let us use the highpass filter of Example 8.25 as an example. The
passband-edge frequencies were transformed using the parameter α =
−0.38197 in (8.31). What is the stopband-edge frequency of the highpass
filter, say ωs , corresponding to the stopband edge ωs = 0.3π of the prototype lowpass filter? This can be answered by (8.31). Since α is fixed for
the transformation, we set the equation
α=−
cos[(0.3π + ωs )/2]
= −0.38197
cos[(0.3π − ωs )/2]
This is a transcendental equation whose solution can be obtained iteratively from an initial guess. It can be done using MATLAB, and the
solution is
ωs = 0.4586π
Now in practice we will know the desired highpass frequencies ωs and
ωp , and we are required to find the prototype lowpass cutoff frequencies
ωs and ωp . We can choose the passband frequency ωp with a reasonable
value, say ωp = 0.2π, and determine α from ωp using the formula from
Table 8.2. Now ωs can be determined (for our highpass filter example)
from α and
Z=−
z −1 + α
1 + αz −1
where Z = ejωs and z = ejωs , or
ωs = −
e−jωs + α
1 + αe−jωs
(8.32)
Continuing our highpass filter example, let ωp = 0.6π and ωs = 0.4586π be
the band-edge frequencies. Let us choose ωp = 0.2π. Then α = −0.38197
from (8.31), and from (8.32)
ωs = 368
−
e−j0.4586π − 0.38197
1 − 0.38197e−j−0.38197
= 0.3π
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
as expected. Now we can design a digital lowpass filter and transform
it into a highpass filter using the zmapping function to complete our
design procedure. For designing a highpass Chebyshev-I digital filter, the
above procedure can be incorporated into a MATLAB function called the
cheb1hpf function shown below.
function [b,a] = cheb1hpf(wp,ws,Rp,As)
% IIR Highpass filter design using Chebyshev-1 prototype
% function [b,a] = cheb1hpf(wp,ws,Rp,As)
%
b = Numerator polynomial of the highpass filter
%
a = Denominator polynomial of the highpass filter
% wp = Passband frequency in radians
% ws = Stopband frequency in radians
% Rp = Passband ripple in dB
% As = Stopband attenuation in dB
%
% Determine the digital lowpass cutoff frequencies:
wplp = 0.2*pi;
alpha = -(cos((wplp+wp)/2))/(cos((wplp-wp)/2));
wslp = angle(-(exp(-j*ws)+alpha)/(1+alpha*exp(-j*ws)));
%
% Compute Analog lowpass Prototype Specifications:
T = 1; Fs = 1/T;
OmegaP = (2/T)*tan(wplp/2);
OmegaS = (2/T)*tan(wslp/2);
% Design Analog Chebyshev Prototype Lowpass Filter:
[cs,ds] = afd_chb1(OmegaP,OmegaS,Rp,As);
% Perform Bilinear transformation to obtain digital lowpass
[blp,alp] = bilinear(cs,ds,Fs);
% Transform digital lowpass into highpass filter
Nz = -[alpha,1]; Dz = [1,alpha];
[b,a] = zmapping(blp,alp,Nz,Dz);
We will demonstrate this procedure in the following example.
EXAMPLE 8.27
Design a highpass digital filter to satisfy
ωp = 0.6π,
Rp = 1 dB
ωs = 0.4586π,
As = 15 dB
Use the Chebyshev-I prototype.
Frequency-band Transformations
369
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
MATLAB Script:
>>
>>
>>
>>
>>
% Digital Highpass Filter Specifications:
wp = 0.6*pi;
% digital Passband freq in rad
ws = 0.4586*pi;
% digital Stopband freq in rad
Rp = 1;
% Passband ripple in dB
As = 15;
% Stopband attenuation in dB
>> [b,a] = cheb1hpf(wp,ws,Rp,As);
C = 0.0243
B = 1.0000
-2.0000
1.0000
1.0000
-2.0000
1.0000
A = 1.0000
1.0416
0.4019
1.0000
0.5561
0.7647
[C,B,A] = dir2cas(b,a)
The system function is
H(z) =
0.0243(1 − z −1 )4
(1 + 0.5661z −1 + 0.7647z −2 )(1 + 1.0416z −1 + 0.4019z −2 )
which is identical to that in Example 8.26.
The above highpass filter design procedure can be easily extended
to other frequency-selective filters using the transformation functions in
Table 8.2. These design procedures are explored in Problems P8.24, P8.26,
P8.28, and P8.30. We now describe MATLAB’s filter design functions for
designing arbitrary frequency-selective filters.
MATLAB
IMPLEMENTATION
In the preceding section we discussed four MATLAB functions to design
digital lowpass filters. These same functions can also be used to design
highpass, bandpass, and bandstop filters. The frequency-band transformations in these functions are done in the s-plane, that is, they use
Approach-1 discussed on page 313. For the purpose of illustration we
will use the function butter. It can be used with the following variations
in its input arguments.
• [b,a] = BUTTER(N,wn,’high’) designs an Nth-order highpass filter
with digital 3-dB cutoff frequency wn in units of π.
• [b,a] = BUTTER(N,wn,)designs an order 2N bandpass filter if wn is a
two-element vector, wn=[w1 w2], with 3-dB passband w1 < w < w2 in
units of π.
• [b,a] = BUTTER(N,wn,’stop’) is an order 2N bandstop filter if wn=[w1
w2]with 3-dB stopband w1 < w < w2 in units of π.
To design any frequency-selective Butterworth filter, we need to know
the order N and the 3-dB cutoff frequency vector wn. In this chapter we
370
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
described how to determine these parameters for lowpass filters. However,
these calculations are more complicated for bandpass and bandstop filters.
In their SP toolbox, MATLAB provides a function called buttord to
compute these parameters. Given the specifications, ωp , ωs , Rp , and As ,
this function determines the necessary parameters. Its syntax is
[N,wn] = buttord(wp,ws,Rp,As)
The parameters wp and ws have some restrictions, depending on the type
of filter:
• for lowpass filters wp < ws,
• for highpass filters wp > ws,
• for bandpass filters wp and ws are two-element vectors, wp=[wp1,
wp2] and ws=[ws1,ws2], such that ws1 < wp1 < wp2 < ws2, and
• for bandstop filters wp1 < ws1 < ws2 < wp2.
Now using the buttord function in conjunction with the butter function, we can design any Butterworth IIR filter. Similar discussions apply
for cheby1, cheby2, and ellip functions with appropriate modifications.
We illustrate the use of these functions through the following examples.
EXAMPLE 8.28
Solution
In this example we will design a Chebyshev-I highpass filter whose specifications
were given in Example 8.27.
MATLAB Script:
>>
>>
>>
>>
>>
% Digital Filter Specifications:
ws = 0.4586*pi;
wp = 0.6*pi;
Rp = 1;
As = 15;
%
%
%
%
%
Type: Chebyshev-I highpass
Dig. stopband edge frequency
Dig. passband edge frequency
Passband ripple in dB
Stopband attenuation in dB
>> % Calculations of Chebyshev-I Filter Parameters:
>> [N,wn] = cheb1ord(wp/pi,ws/pi,Rp,As);
>> % Digital Chebyshev-I Highpass Filter Design:
>> [b,a] = cheby1(N,Rp,wn,’high’);
>> % Cascade Form Realization:
>> [b0,B,A] = dir2cas(b,a)
b0 = 0.0243
B = 1.0000
-1.9991
0.9991
1.0000
-2.0009
1.0009
A = 1.0000
1.0416
0.4019
1.0000
0.5561
0.7647
Frequency-band Transformations
371
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The cascade form system function
H(z) =
(1 +
0.5661z −1
0.0243(1 − z −1 )4
+ 0.7647z −2 )(1 + 1.0416z −1 + 0.4019z −2 )
is identical to the filter designed in Example 8.27, which demonstrates that
the two approaches described on page 313 are identical. The frequency-domain
plots are shown in Figure 8.22.
EXAMPLE 8.29
>>
>>
>>
>>
>>
In this example we will design an elliptic bandpass filter whose specifications
are given in the following MATLAB script:
% Digital Filter Specifications:
ws = [0.3*pi 0.75*pi];
wp = [0.4*pi 0.6*pi];
Rp = 1;
As = 40;
%
%
%
%
%
Type: Elliptic Bandpass
Dig. stopband edge frequency
Dig. passband edge frequency
Passband ripple in dB
Stopband attenuation in dB
>> % Calculations of Elliptic Filter Parameters:
>> [N,wn] = ellipord(wp/pi,ws/pi,Rp,As);
>> % Digital Elliptic Bandpass Filter Design:
>> [b,a] = ellip(N,Rp,As,wn);
Magnitude Response
Phase Response
1
phase in pi units
1
0.8913
0.1778
0
0
0.46 0.6
Digital frequency in pi units
0.5
0
−0.5
−1
1
0
Magnitude in dB
delay in samples
decibels
10
15
0
FIGURE 8.22
372
1
Group Delay
0
1
30
0.46 0.6
frequency in pi units
0.46 0.6
frequency in pi units
1
8
6
4
2
0
0
0.46 0.6
frequency in pi units
1
Digital Chebyshev-I highpass filter in Example 8.28
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> % Cascade Form Realization:
>> [b0,B,A] = dir2cas(b,a)
b0 = 0.0197
B = 1.0000
1.5066
1.0000
1.0000
0.9268
1.0000
1.0000
-0.9268
1.0000
1.0000
-1.5066
1.0000
A = 1.0000
0.5963
0.9399
1.0000
0.2774
0.7929
1.0000
-0.2774
0.7929
1.0000
-0.5963
0.9399
Note that the designed filter is a 10th-order filter. The frequency-domain plots
are shown in Figure 8.23.
EXAMPLE 8.30
>>
>>
>>
>>
>>
Finally, we will design a Chebyshev-II bandstop filter whose specifications are
given in the following MATLAB script.
% Digital Filter Specifications:
ws = [0.4*pi 0.7*pi];
wp = [0.25*pi 0.8*pi];
Rp = 1;
As = 40;
%
%
%
%
%
Type: Chebyshev-II Bandstop
Dig. stopband edge frequency
Dig. passband edge frequency
Passband ripple in dB
Stopband attenuation in dB
Magnitude Response
Phase Response
1
phase in pi units
1
0.8913
0
0
0.3 0.4
0.6 0.75
frequency in pi units
0.5
0
−0.5
−1
1
0
Magnitude in dB
0.3 0.4
0.6 0.75
frequency in pi units
1
Group Delay
0
40
samples
30
10
40
0
FIGURE 8.23
Frequency-band Transformations
20
0.3 0.4
0.6 0.75
frequency in pi units
1
0
0
0.3 0.4
0.6 0.75
frequency in pi units
1
Digital elliptic bandpass filter in Example 8.29
373
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
>> % Calculations of Chebyshev-II Filter Parameters:
>> [N,wn] = cheb2ord(wp/pi,ws/pi,Rp,As);
>> % Digital Chebyshev-II Bandstop Filter Design:
>> [b,a] = cheby2(N,As,ws/pi,’stop’);
>> % Cascade Form Realization:
>> [b0,B,A] = dir2cas(b,a)
b0 = 0.1558
B = 1.0000
1.1456
1.0000
1.0000
0.8879
1.0000
1.0000
0.3511
1.0000
1.0000
-0.2434
1.0000
1.0000
-0.5768
1.0000
A = 1.0000
1.3041
0.8031
1.0000
0.8901
0.4614
1.0000
0.2132
0.2145
1.0000
-0.4713
0.3916
1.0000
-0.8936
0.7602
This is also a 10th-order filter. The frequency domain plots are shown in Figure
8.24.
Magnitude Response
Phase Response
1
phase in pi units
1
0.8913
0
0
0.25 0.4
0.7 0.8
Digital frequency in pi units
1
0.5
0
−0.5
−1
0
Magnitude in dB
0.25 0.4
0.7 0.8
Digital frequency in pi units
1
Group Delay
0
15
10
5
−40
0
0.25 0.4
0.7 0.8
Digital frequency in pi units
FIGURE 8.24
374
1
0
0
0.25 0.4
0.7 0.8
Digital frequency in pi units
1
Digital Chebyshev-II bandstop filter in Example 8.30
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
COMPARISON OF FIR VS. IIR FILTERS
So far we have seen many techniques for designing both FIR and IIR
filters. In practice one wonders about which filter (FIR or IIR) should be
chosen for a given application and which method should be used to design
it. Because these design techniques involve different methodologies, it is
difficult to compare them. However, some meaningful comparisons can be
attempted if we focus on the minimax optimal (or equiripple) filters. In the
case of FIR filters these optimal filters are the equiripple filters designed
via the Parks-McClellan algorithm (or Remez Exchange Algorithm), while
in the case of IIR filters these are the elliptic filters.
One basis of comparison is the number of multiplications required to
compute one output sample in the standard realization of these filters. For
FIR filters the standard realization is the linear-phase direct form, while
for elliptic filters cascade forms are widely used. Let M be the length of a
linear phase FIR filter (assume M odd). Then we need
M +1
M
2
2
for large M
multiplications per output sample. Let N (assume N even) be the order
of an elliptic filter with the cascade form realization. Then there are N/2
second-order sections, each requiring 3 multiplications (in the most efficient implementation). There are an additional three multiplications in
the overall structure for a total of
3
3N
N
+3
2
2
(for large N )
multiplications per output sample.
Now if we assume that each filter meets exactly the same specifications: (e.g., ωp , ωs , δ1 (or passband ripple Rp ), and δ2 (or stopband
attenuation As ) for a lowpass filter), then these two filters are equivalent
if
M +1
3N + 3
M
1
=
=⇒
=3+
3 for large N
2
2
N
N
This means that if the ratio M/N = 3, then two filters are roughly efficient. However, an equiripple FIR filter is more efficient if M/N < 3, or
an elliptic IIR filter is more efficient if M/N > 3.
It has been shown experimentally that [23]
• for ωp ≥ 0.3, M/N ≥ 3 for all δ1 , δ2 , N
• for N ≥ 10, M/N ≥ 3 for all δ1 , δ2 , N
• for large N , M/N ≈ in 100’s
Comparison of FIR vs. IIR Filters
375
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
This shows that for most applications IIR elliptic filters are desirable from
the computational point of view. The most favorable conditions for FIR
filters are
• large values of δ1 ,
• small values of δ2 , and
• large transition width.
Furthermore, if we take into account the phase equalizers (which are
all-pass filters) connected in cascade with elliptic filters that are needed for
linear-phase characteristics, then FIR equiripple filter designs look good
because of their exact linear-phase characteristics.
PROBLEMS
P8.1 Design an analog Butterworth lowpass filter that has a 0.25 dB or better ripple at
500 rad/sec and at least 50 dB of attenuation at 2000 rad/sec. Determine the system
function in a rational function form. Plot the magnitude response, the log-magnitude
response in dB, the phase response, and the impulse response of the filter.
P8.2 Design an analog Butterworth lowpass filter that has a 0.5 dB or better ripple at 10 kHz
and at least 45 dB of attenuation at 20 kHz. Determine the system function in a cascade
form. Plot the magnitude response, the log-magnitude response in dB, the group-delay, and
the impulse response of the filter.
P8.3 Design a lowpass analog Chebyshev-I filter with an acceptable ripple of 1 dB for |Ω| ≤ 10
and an attenuation of 50 dB or greater beyond |Ω| = 15 rad/sec. Determine the system
function in a rational function form. Plot the magnitude response, the log-magnitude
response in dB, the group-delay, and the impulse response of the filter.
P8.4 Design a lowpass analog Chebyshev-I filter with the following characteristics:
• A passband ripple of .5 dB,
• passband cutoff frequency of 4 kHz, and
• stopband attenuation of 45 dB or greater beyond 20 kHz.
Determine the system function in a cascade form. Plot the magnitude response, the
log-magnitude response in dB, the phase response, and the impulse response of the filter.
P8.5 A signal xa (t) contains two frequencies, 10 kHz and 15 kHz. We want to suppress the 15
kHz component to 50 dB attenuation while passing the 10 kHz component with less than
0.25 dB attenuation. Design a minimum order Chebyshev-II analog filter to perform this
filtering operation. Plot the log-magnitude response and verify the design.
P8.6 Design an analog Chebyshev-II lowpass filter that has a 0.25 dB or better ripple at 250 Hz
and at least 40 dB of attenuation at 400 Hz. Plot the magnitude response, the
log-magnitude response in dB, the group-delay, and the impulse response of the filter.
P8.7 A signal xa (t) contains two frequencies, 10 kHz and 15 kHz. We want to suppress the
15 kHz component to 50 dB attenuation while passing the 10 kHz component with less than
0.25 dB attenuation. Design a minimum order elliptic analog filter to perform this filtering
376
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
operation. Plot the log-magnitude response and verify the design. Compare your design
with the Chebyshev-II design in Problem P8.5.
P8.8 Design an analog elliptic lowpass filter that has a 0.25 dB or better ripple at 500 rad/sec
and at least 50 dB of attenuation at 2000 rad/sec. Determine the system function in a
rational function form. Plot the magnitude response, the log-magnitude response in dB, the
phase response, and the impulse response of the filter. Compare your design with the
Butterworth design in Problem P8.1.
P8.9 Write a MATLAB function to design analog lowpass filters. The format of this function
should be
function [b,a] =afd(type,Fp,Fs,Rp,As)
%
% function [b,a] =afd(type,Fp,Fs,Rp,As)
%
Designs analog lowpass filters
% type = ’butter’ or ’cheby1’ or ’cheby2’ or ’ellip’
%
Fp = passband cutoff in Hz
%
Fs = stopband cutoff in Hz
%
Rp = passband ripple in dB
%
As = stopband attenuation in dB
Use the afd butt, afd chb1, afd chb2, and afd elip functions developed in this chapter.
Check your function using specifications given in Problems P8.1 through P8.6.
P8.10 We want to design a Chebyshev-I prototype lowpass digital filter operating at a sampling
rate of 8 kHz with a passband edge of 3.2 kHz, a passband ripple of 0.5 dB, and a minimum
stopband attenuation of 45 dB at 3.8 kHz.
1. Using the impulse invariance transformation with T = 1 sec, design the digital filter. Plot
the magnitude and the log-magnitude responses as functions of analog frequency in kHz.
2. Repeat the above part using T = 1/8000 sec.
3. Compare the above two designs in terms of their frequency responses. Comment on the
effect of T on the impulse invariance design.
P8.11 Repeat Problem P8.10 using the Butterworth prototype.
P8.12 Design a Butterworth digital lowpass filter to satisfy the specifications:
passband edge:
0.4π,
Rp = 0.5 dB
stopband edge:
0.6π,
As = 50 dB
Use the impulse invariance method with T = 2. Determine the system function in the
rational form and plot the log-magnitude response in dB. Plot the impulse response h(n)
and the impulse response ha (t) of the analog prototype and compare their shapes.
P8.13 Write a MATLAB function to design digital lowpass filters based on the impulse invariance
transformation. The format of this function should be
Problems
377
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
function [b,a] =dlpfd_ii(type,wp,ws,Rp,As,T)
%
% function [b,a] =dlpfd_ii(type,wp,ws,Rp,As,T)
%
Designs digital lowpass filters using impulse invariance
% type = ’butter’ or ’cheby1’
%
wp = passband cutoff in Hz
%
ws = stopband cutoff in Hz
%
Rp = passband ripple in dB
%
As = stopband attenuation in dB
%
T = sampling interval
Use the afd function developed in Problem P8.9. Check your function on specifications
given in Problems P8.10 and P8.12.
P8.14 In this problem we will develop a technique called the step invariance transformation. In
this technique, the step response of an analog prototype filter is preserved in the resulting
digital filter; i.e., if va (t) is the step response of the prototype and if v(n) is the step
response of the digital filter, then
v(n) = va (t)|t=nT ,
T : sampling interval
Note that the frequency-domain quantities are related by
Va (s) = L [va (t)] = Ha (s)/s
and
V (z) = Z [v(n)] = H(z)
1
1 − z −1
Hence the step invariance transformation steps are: Given Ha (s)
•
•
•
•
•
divide Ha (s) by s to obtain Va (s),
find residues {Rk } and poles {pk } of Va (s), +
,
transform analog poles {pk } into digital poles epk T where T is arbitrary,
+
,
determine V (z) from residues {Rk } and poles epk T , and finally
determine H(z) by multiplying V (z) by 1 − z −1 .
Use the above procedure to develop a MATLAB function to implement the step invariance
transformation. The format of this function should be
function [b,a] =stp_invr(c,d,T)
% Step Invariance Transformation from Analog to Digital Filter
% [b,a] =stp_invr(c,d,T)
% b = Numerator polynomial in z^(-1) of the digital filter
% a = Denominator polynomial in z^(-1) of the digital filter
% c = Numerator polynomial in s of the analog filter
% d = Denominator polynomial in s of the analog filter
% T = Sampling (transformation) parameter
378
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P8.15 Design the lowpass Butterworth digital filter of Problem P8.12 using the step invariance
method. Plot the log-magnitude response in dB and compare it with that in Problem P8.12.
Plot the step response v(n) and the impulse response va (t) of the analog prototype and
compare their shapes.
P8.16 In this chapter we discussed a filter transformation technique called the matched-z
transformation. Using (8.30) write a MATLAB function called mzt that maps the analog
system function Ha (s) into the digital system function H(z). The format of the function
should be
function [b,a] = mzt(c,d,T)
% Matched-Z Transformation from Analog to Digital Filter
% [b,a] = MZT(c,d,T)
% b = Numerator polynomial in z^(-1) of the digital filter
% a = Denominator polynomial in z^(-1) of the digital filter
% c = Numerator polynomial in s of the analog filter
% d = Denominator polynomial in s of the analog filter
% T = Sampling interval (transformation parameter)
Using this function, transform
Ha (s) =
s+1
s2 + 5s + 6
into a digital filter H(z) for the sampling intervals (in seconds): T = 0.05, T = 0.1, and
T = 0.2. In each case obtain a plot similar to that in Figure 8.10 and comment on the
performance of this technique.
P8.17 Consider an analog Butterworth lowpass filter that has a 1 dB or better ripple at 100 Hz
and at least 30 dB of attenuation at 150 Hz. Transform this filter into a digital filter using
the matched-z transformation technique in which Fs = 1000 Hz. Plot the magnitude and
phase response of the resulting digital filter and determine the exact band-edge frequencies
for the given dB specifications. Comment on the results.
P8.18 Consider an analog Chebyshev-I lowpass filter that has a 0.5 dB or better ripple at 500 Hz
and at least 40 dB of attenuation at 700 Hz. Transform this filter into a digital filter using
the matched-z transformation technique in which Fs = 2000 Hz. Plot the magnitude and
phase response of the resulting digital filter and determine the exact band-edge frequencies
for the given dB specifications. Comment on the results.
P8.19 Consider an analog Chebyshev-II lowpass filter that has a 0.25 dB or better ripple at
1500 Hz and at least 80 dB of attenuation at 2000 Hz. Transform this filter into a digital
filter using the matched-z transformation technique in which Fs = 8000 Hz. Plot the
magnitude and phase response of the resulting digital filter and determine the exact
band-edge frequencies for the given dB specifications. Comment on the results. Is this a
satisfactory design?
P8.20 Consider the design of the lowpass Butterworth filter of Problem P8.12.
1. Use the bilinear transformation technique outlined in this chapter and the bilinear
function. Plot the log-magnitude response in dB. Compare the impulse responses of the
analog prototype and the digital filter.
2. Use the butter function and compare this design with the one above.
Problems
379
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P8.21 Consider the design of the digital Chebyshev-1 filter of Problem P8.10.
1. Use the bilinear transformation technique outlined in this chapter and the bilinear
function. Plot the log-magnitude response in dB. Compare the impulse responses of the
analog prototype and the digital filter.
2. Use the butter function and compare this design with the one above.
P8.22 Design a digital lowpass filter using elliptic prototype to satisfy the requirements:
passband edge:
0.3π,
Rp = 0.25 dB
stopband edge:
0.4π,
As = 50 dB
Use the bilinear as well as the ellip function and compare your designs.
P8.23 Design a digital lowpass filter to satisfy the specifications:
passband edge:
0.45π,
Rp = 0.5 dB
stopband edge:
0.5π,
As = 60 dB
1. Use the butter function and determine the order N and the actual minimum stopband
attenuation in dB.
2. Use the cheby1 function and determine the order N and the actual minimum stopband
attenuation in dB.
3. Use the cheby2 function and determine the order N and the actual minimum stopband
attenuation in dB.
4. Use the ellip function and determine the order N and the actual minimum stopband
attenuation in dB.
5. Compare the orders, the actual minimum stopband attenuations, and the group delays
in each of the above designs.
P8.24 Write a MATLAB function to determine the lowpass prototype digital filter frequencies
from an highpass digital filter specifications using the procedure outlined in this chapter.
The format of this function should be
function [wpLP,wsLP,alpha] = hp2lpfre(wphp,wshp)
% Band-edge frequency conversion from highpass to lowpass digital filter
% [wpLP,wsLP,a] = hp2lpfre(wphp,wshp)
% wpLP = passband egde for the lowpass prototype
% wsLP = stopband egde for the lowpass prototype
% alpha = lowpass to highpass transformation parameter
% wphp = passband egde for the highpass
% wshp = passband egde for the highpass
Using this function develop a MATLAB function to design a highpass digital filter using the
bilinear transformation. The format of this function should be
380
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
function [b,a] = dhpfd_bl(type,wp,ws,Rp,As)
% IIR Highpass filter design using bilinear transformation
% [b,a] = dhpfd_bl(type,wp,ws,Rp,As)
% type = ’butter’ or ’cheby1’ or ’chevy2’ or ’ellip’
%
b = Numerator polynomial of the highpass filter
%
a = Denominator polynomial of the highpass filter
%
wp = Passband frequency in radians
%
ws = Stopband frequency in radians (wp < ws)
%
Rp = Passband ripple in dB
%
As = Stopband attenuation in dB
Verify your function using the specifications in Example 8.27.
P8.25 Design a highpass filter to satisfy the specifications:
stopband edge:
passband edge:
0.4π,
0.6π,
As = 60 dB
Rp = 0.5 dB
1. Use the dhpfd bl function of Problem P8.24 and the Chebyshev-I prototype to design
this filter. Plot the log-magnitude response in dB of the designed filter.
2. Use the cheby1 function for design and plot the log-magnitude response in dB. Compare
these two designs.
P8.26 Write a MATLAB function to determine the lowpass prototype digital filter frequencies
from an arbitrary lowpass digital filter specifications using the functions given in Table 8.2
and the procedure outlined for highpass filters. The format of this function should be
function [wpLP,wsLP,alpha] = lp2lpfre(wplp,wslp)
% Band-edge frequency conversion from lowpass to lowpass digital filter
% [wpLP,wsLP,a] = lp2lpfre(wplp,wslp)
% wpLP = passband egde for the lowpass prototype
% wsLP = stopband egde for the lowpass prototype
% alpha = lowpass to highpass transformation parameter
% wplp = passband egde for the given lowpass
% wslp = passband egde for the given lowpass
Using this function, develop a MATLAB function to design a lowpass filter from a
prototype lowpass digital filter using the bilinear transformation. The format of this
function should be
function [b,a] = dlpfd_bl(type,wp,ws,Rp,As)
% IIR lowpass filter design using bilinear transformation
% [b,a] = dlpfd_bl(type,wp,ws,Rp,As)
% type = ’butter’ or ’cheby1’ or ’chevy2’ or ’ellip’
%
b = Numerator polynomial of the bandpass filter
%
a = Denominator polynomial of the bandpass filter
%
wp = Passband frequency in radians
%
ws = Stopband frequency in radians
%
Rp = Passband ripple in dB
%
As = Stopband attenuation in dB
Verify your function using the designs in Problem P8.23.
Problems
381
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P8.27 Design a bandpass digital filter using the Cheby2 function. The specifications are:
lower stopband edge:
upper stopband edge:
lower passband edge:
upper passband edge:
0.3π
0.6π
0.4π
0.5π
As = 50 dB
Rp = 0.5 dB
Plot the impulse response and the log-magnitude response in dB of the designed filter.
P8.28 Write a MATLAB function to determine the lowpass prototype digital filter frequencies
from a bandpass digital filter specifications using the functions given in Table 8.2 and the
procedure outlined for highpass filters. The format of this function should be
function [wpLP,wsLP,alpha] = bp2lpfre(wpbp,wsblp)
% Band-edge frequency conversion from bandpass to lowpass digital filter
% [wpLP,wsLP,a] = bp2lpfre(wpbp,wsbp)
% wpLP = passband egde for the lowpass prototype
% wsLP = stopband egde for the lowpass prototype
% alpha = lowpass to highpass transformation parameter
% wpbp = passband egde frequency array [wp_lower, wp_upper] for the bandpass
% wsbp = passband egde frequency array [ws_lower, ws_upper] for the bandpass
Using this function, develop a MATLAB function to design a bandpass filter from a
prototype lowpass digital filter using the bilinear transformation. The format of this
function should be
function [b,a] = dbpfd_bl(type,wp,ws,Rp,As)
% IIR bandpass filter design using bilinear transformation
% [b,a] = dbpfd_bl(type,wp,ws,Rp,As)
% type = ’butter’ or ’cheby1’ or ’chevy2’ or ’ellip’
%
b = Numerator polynomial of the bandpass filter
%
a = Denominator polynomial of the bandpass filter
%
wp = Passband frequency array [wp_lower, wp_upper] in radians
%
ws = Stopband frequency array [wp_lower, wp_upper] in radians
%
Rp = Passband ripple in dB
%
As = Stopband attenuation in dB
Verify your function using the design in Problem P8.27.
P8.29 We wish to use the Chebyshev-I prototype to design a bandstop digital IIR digital filter
that meets the following specifications:
0.95
0
0.95
≤
≤
≤
|H(ejω )|
|H(ejω )|
|H(ejω )|
≤
≤
≤
1.05,
0.01,
1.05,
0
0.35π
0.75π
≤
≤
≤
|ω|
|ω|
|ω|
≤
≤
≤
0.25π
0.65π
π
Use the cheby1 function and determine the system function H(z) of such a filter. Provide a
plot containing subplots of the log-magnitude response in dB and the impulse response.
P8.30 Write a MATLAB function to determine the lowpass prototype digital filter frequencies
from a bandstop digital filter specifications using the functions given in Table 8.2 and the
procedure outlined for highpass filters. The format of this function should be
382
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
function [wpLP,wsLP,alpha] = bs2lpfre(wpbp,wsblp)
% Band-edge frequency conversion from bandstop to lowpass digital filter
% [wpLP,wsLP,a] = bs2lpfre(wpbp,wsbp)
% wpLP = passband egde for the lowpass prototype
% wsLP = stopband egde for the lowpass prototype
% alpha = lowpass to highpass transformation parameter
% wpbp = passband egde frequency array [wp_lower, wp_upper] for the bandstop
% wsbp = passband egde frequency array [ws_lower, ws_upper] for the bandstop
Using this function, develop a MATLAB function to design a bandstop filter from a
prototype lowpass digital filter using the bilinear transformation. The format of this
function should be
function [b,a] = dbsfd_bl(type,wp,ws,Rp,As)
% IIR bandstop filter design using bilinear transformation
% [b,a] = dbsfd_bl(type,wp,ws,Rp,As)
% type = ’butter’ or ’cheby1’ or ’chevy2’ or ’ellip’
%
b = Numerator polynomial of the bandstop filter
%
a = Denominator polynomial of the bandstop filter
%
wp = Passband frequency array [wp_lower, wp_upper] in radians
%
ws = Stopband frequency array [wp_lower, wp_upper] in radians
%
Rp = Passband ripple in dB
%
As = Stopband attenuation in dB
Verify your function using the design in Problem P8.29.
P8.31 An analog signal
xa (t) = 3 sin(40πt) + 3 cos(50πt)
is to be processed by a
xa (t) −→ A/D −→ H(z) −→ D/A −→ ya (t)
system in which the sampling interval is 100 sam/sec
1. Design a minimum order IIR digital filter that will pass the first component of xa (t)
with attenuation of less than 1 dB and suppress the second component to at least 50 dB.
The filter should have a monotone passband and an equiripple stopband. Determine the
system function in rational function form and plot the log-magnitude response.
2. Generate 500 samples (sampled at 100 sam/sec) of the signal xa (t) and process through
the designed filter to obtain the output sequence. Interpolate this sequence (using any
one of the interpolating techniques discussed in Chapter 3) to obtain ya (t). Plot the
input and the output signals and comment on your results.
P8.32 Using the bilinear transformation method, design a tenth-order elliptic bandstop filter to
remove the digital frequency ω = 0.44π with bandwidth of 0.08π. Choose a reasonable value
for the stopband attenuation. Plot the magnitude response. Generate 201 samples of the
sequence
x(n) = sin [0.44πn] ,
n = 0, . . . , 200
and process thorough the bandstop filter. Comment on your results.
Problems
383
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P8.33 Design a digital highpass filter H(z) to be used in a
xa (t) −→ A/D −→ H(z) −→ D/A −→ ya (t)
structure to satisfy the following requirements:
•
•
•
•
•
sampling rate of 10 Khz,
stopband edge of 1.5 Khz with attenuation of 40 dB,
passband edge of 2 Khz with ripple of 1dB,
equiripple passband and stopband, and
impulse invariance transformation method.
1.
2.
3.
4.
Plot magnitude response of the overall analog filter over the [0, 5 Khz] interval.
Plot the magnitude response of the digital lowpass prototype.
Plot the magnitude response of the analog lowpass prototype.
What limitations must be placed on the input signals so that the above structure truly
acts like a highpass filter to them?
P8.34 The filter specifications shown in Figure P8.1 can be considered as a combination of a
bandpass and a highpass specifications. Design a minimum-order IIR digital filter to satisfy
these specifications. Provide a plot of the magnitude response with grid-lines as shown in
Figure P8.1. From your design and plot determine the order of the filter and the exact
band-edge frequencies.
P8.35 The filter specifications shown in Figure P8.2 can be considered as a combination of a
lowpass and a bandstop specifications. Design a minimum-order IIR digital filter to satisfy
these specifications. Provide a plot of the magnitude response with grid-lines as shown in
Figure P8.2. From your design and plot determine the order of the filter and the exact
band-edge frequencies.
|H (e jw )|
EQUIRIPPLE
1
0.9
EQUIRIPPLE
0.5
0.45
MONOTONE
0.01
0
0
0.1
FIGURE P8.1
384
MONOTONE
0.2
0.5
0.6
0.7
0.8
1
w
p
Filter specifications for Problem P8.34
Chapter 8
IIR FILTER DESIGN
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
|H (e jw )|
EQUIRIPPLE
1
0.9
EQUIRIPPLE
0.5
0.45
MONOTONE
0.01
0
0
0.1
FIGURE P8.2
MONOTONE
0.2
0.5
0.6
0.7
0.8
1
w
p
Filter specifications for Problem P8.35
P8.36 Design a minimum order IIR digital filter to satisfy the following specifications:
•
•
•
•
•
A passband over the [0.35π, 0.5π] interval
Stopbands over the [0, 0.3π] and [0.6π, π] intervals
Passband ripple of 1 dB
Stopband attenuation of 40 db
Equiripple passbands and stopband
Determine the system function H(z) of the designed filter in the rational function form.
Provide a plot of the log-magnitude response in dB. From your design and plot, answer the
following questions:
1. What is the order of the filter?
2. From your plot what are the exact band edge frequencies for the given passband and
stopband attenuations?
3. Why is there a discrepancy between the specification frequencies and the exact
frequencies determined above?
Problems
385
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
9
Finite
Word-Length
Effects
Until now we have considered digital filter designs and implementations
in which both the filter coefficients and the filter operations such as additions and multiplications were expressed using infinite-precision numbers. Digital hardware, on the other hand, contains processing registers
that have finite word lengths (or finite precision). When filters are implemented either in hardware or in software, filter coefficients as well as
filter operations are subjected to the effects of these finite register lengths.
This makes digital-filter realizations inherently nonlinear when we have
analyzed digital filters as linear systems. In this chapter we will study and
analyze the effects of finite register length in the design and implementation of digital filters.
OVERVIEW
Consider a typical digital filter implemented as a direct-form II structure,
which is shown in Figure 9.1(a). When finite-precision representation is
used in its implementation, there are three possible considerations that
affect the overall quality of its output. We have to
1. quantize filter coefficients, {ak , bk }, to obtain their finite word-length
representations, {âk , b̂k },
386
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x (n)
y (n)
H (z)
x(n)
b0
a1
a2
a3
z −1
z −1
z −1
Hˆ (z)
xˆ(n)
y(n)
bˆ 0
xˆ(n)
b1
aˆ1
b2
aˆ2
b3
aˆ 3
(a)
yˆ ( n)
yˆ(n)
z −1 ˆ
b1
z −1
bˆ 2
z −1 ˆ
b3
(b)
FIGURE 9.1 Direct-form II digital filter implementation: (a) Infinite precision,
(b) Finite precision
2. quantize the input sequence, x(n) to obtain x̂(n), and
3. consider all internal arithmetic that must be converted to their next
best representations.
Thus, the output, y(n), is also a quantized value ŷ(n). This gives us a
new filter realization, Ĥ(z), which is shown in Figure 9.1(b). We hope
that this new filter Ĥ(z) and its output ŷ(n) are as close as possible to
the original filter H(z) and the original output y(n).
Since the quantization operation is a nonlinear operation, the overall
analysis that takes into account all three effects described above is very
difficult and tedious. Therefore, in this chapter we will study each of these
effects separately as through it were the only one acting at the time. This
makes the analysis easier and the results more interpretable.
We begin by discussing the number representation in a computer—
more accurately, a central processing unit (CPU). This leads to signal
quantization and analog-to-digital (A/D) conversion noise. We then analyze the effects of filter coefficient quantization on filter design and
responses. The effects of multiplication and addition quantization (collectively known as arithmetic round-off errors) on filter output are discussed as two topics: correlated errors called limit cycles and uncorrelated
round-off noise.
REPRESENTATION OF NUMBERS
In computers, numbers (real-valued or complex-valued, integers or fractions) are represented using binary digits (bits), which take the value of
either a 0 or a 1. The finite word-length arithmetic needed for processing
Representation of Numbers
387
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
these numbers is implemented using two different approaches, depending
upon the ease of implementation and the accuracy as well as dynamic
range needed in processing. The fixed-point arithmetic is easy to implement but has only a fixed dynamic range and accuracy (i.e., very large
numbers or very small numbers). The floating-point arithmetic, on the
other hand, has a wide dynamic range and a variable accuracy (relative
to the magnitude of a number) but is more complicated to implement and
analyze.
Since a computer can operate only on a binary variable (e.g., a 1 or
a 0), positive numbers can straightforwardly be represented using binary
numbers. The problem arises as to how to represent the negative numbers.
There are three different formats used in each of the above arithmetics:
sign-magnitude format, one’s-complement format, and two’s-complement
format. In discussing and analyzing these representations, we will mostly
consider a binary number system containing bits. However, this discussion
and analysis is also valid for any radix numbering system—for example,
the hexadecimal, octal, or decimal system.
In the following discussion, we will first begin with fixed-point signed
integer arithmetic. A B-bit binary representation of an integer x is given
by1
x ≡ bB−1 bB−2 . . . b0 = bB−1 × 2B−1 + bB−2 × 2B−2 + · · · + b0 × 20
(9.1)
where each bit bi represents either a 0 or a 1. This representation will
help us to understand the advantages and disadvantages of each signed
format and to develop simple MATLAB functions. We will then extend
these concepts to fractional real numbers for both fixed-point and floatingpoint arithmetic.
FIXED-POINT
SIGNED INTEGER ARITHMETIC
In this arithmetic, positive numbers are coded using their binary representation. For example, using 3 bits, we can represent numbers from 0 to
7 as
0
1
2
3
4
5
6
7
-+----+----+----+----+----+----+----+000 001 010 011 100 101 110 111
Thus, with 8 bits the numbers represented can be 0 to 255, with 10
bits we can represent the numbers from 0 to 1023, and with 16 bits the
range covered is 0 to 65535. For negative numbers, the following three
formats are used.
1 Here the letter b is used to represent a binary bit. It is also used for filter coefficients
{bk }. Its use in the text should be clear from the context.
388
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Sign-magnitude format In this format, positive numbers are represented using bits as before. However, the leftmost bit (also known as the
most-significant bit or MSB) is used as the sign bit (0 is +, and 1 is −),
and the remaining bits hold the absolute magnitude of the number as
given below:
sign bit
-+
absolute magnitude
+---+----------------------+
|
|
|
+---+----------------------+
This system has thus two different codes for 0, one for the positive 0, the
other one for the negative 0. For example, using 3 bits, we can represent
numbers from −3 to 3 as
-3
-2
-1
-0
0
1
2
3
-+----+----+----+----+----+----+----+111 110 101 100 000 001 010 011
Thus, 8 bits cover the interval [−127, +127], while 16 bits cover [−32, 767,
+32, 767]. If we use B bits in the sign-magnitude format, then we can
represent integers from −(2B−1 − 1) to +(2B−1 − 1) only.
This format has two drawbacks. First, there are two representations
for 0. Second, the arithmetic using sign-magnitude format requires one
rule to compute addition, another rule to compute subtraction, and a
way to compare two magnitudes to determine their relative value before
subtraction.
MATLAB Implementation MATLAB is a 64-bit floating-point computation engine that provides results in decimal numbers. Therefore,
fixed-point binary operations must be simulated in MATLAB. It provides
a function, dec2bin, to convert a positive decimal integer into a B-bit
representation, which is a symbol (or a code) and not a number. Hence
it cannot be used in computation. Similarly, the function bin2dec converts a B-bit binary character code into a decimal integer. For example,
dec2bin(3,3) gives 011 and bin2dec(’111’) results in 7. To obtain a
sign-magnitude format, a sign-bit must be prefixed. Similarly, to convert a
sign-magnitude format, the leading bit must be used to impart a positive
or negative value. These functions are explored in Problem P9.1.
One’s-complement format In this format, the negation (or complementation) of an integer x is obtained by complementing every bit (i.e., a
0 is replaced by 1 and a 1 by 0) in the binary representation of x. Suppose
Representation of Numbers
389
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
the B-bit binary representation of x is bB−1 bB−2 · · · b0 ; then the B-bit
one’s-complement, x̄, of x is given by
x̄ = b̄B−1 b̄B−2 · · · b̄0
where each bit b̄i is a complement of bit bi . Clearly then
x + x̄ ≡ 1 1 . . . 1 = 2B − 1
(9.2)
The MSB of the representation once again represents the sign bit,
because the positive integer has the MSB of 0 so its negation (or a negative
integer) has the MSB of 1. The remaining bits represent either the number
x (if positive) or its one’s-complement (if negative). Thus, using (9.2) the
one’s-complement format representation2 is given by


x,
x
≥
0
x,
x≥0
x,
x≥0
∆
=
x(1) =
=
2B − 1 − |x|, x < 0  2B − 1 + x, x < 0
|x|, x < 0
(9.3)
Clearly, if B bits are available, then we can represent only integers from
(−2B−1 +1) to (+2B−1 −1), which is similar to the sign-magnitude format.
For example, using 3 bits, we can represent numbers from −3 to 3 as
-3
-2
-1
-0
0
1
2
3
-+----+----+----+----+----+----+----+100 101 110 111 000 001 010 011
which is a different bit arrangement for negative numbers compared to
the sign-magnitude format.
The advantage of this format is that subtraction can be achieved by
adding the complement, which is very easy to obtain by simply complementing a number’s bits. However, there are many drawbacks. There are
still two different codes for 0. The addition is a bit tricky to implement,
and overflow management requires addition of the overflow bit to the least
significant bit (or 20 ).
MATLAB Implementation The one’s-complement of a positive integer x using B bits can be obtained by using the built-in function
bitcmp(x,B), which complements the number’s bits. The result is a decimal number between 0 and 2B − 1. As before, the dec2bin can be used
to obtain the binary code. Using (9.3), we can develop the MATLAB
function, OnesComplement, which obtains the one’s-complement format
representation. It uses the sign of a number to determine when to use
2 The one’s-complement format refers to the representation of positive and negative
numbers, whereas the one’s-complement of a number refers to the negation of that
number.
390
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
one’s-complement and can use scalar as well as vector values. The result
is a decimal equivalent of the representation.
function y = OnesComplement(x,B)
% y = OnesComplement(x,B)
% --------------% Decimal equivalent of
% Sign-Magnitude format integer to b-bit Ones’-Complement format conversion
%
%
x: integer between -2^(b-1) < x < 2^(b-1) (sign-magnitude)
%
y: integer between
0 <= y <= 2^b-1
(1’s-complement)
if any((x <= -2^(B-1) | (x >= 2^(B-1))))
error(’Numbers must satisfy -2^(B-1) < x < 2^(B-1)’)
end
s = sign(x); % sign of x (-1 if x<0, 0 if x=0, 1 if x>0)
sb = (s < 0); % sign-bit (0 if x>=0, 1 if x<0));
y = (1-sb).*x + sb.*bitcmp(abs(x),B);
EXAMPLE 9.1
Solution
Using the function OnesComplement, obtain one’s-complement format representation of integers from −7 to 7 using 4 bits.
MATLAB Script:
>> x = -7:7
x =
-7
-6
-5
-4
-3
>> y = OnesComplement(x,4)
y =
8
9
10
11
12
-2
-1
0
1
2
3
4
5
6
7
13
14
0
1
2
3
4
5
6
7
Note that the number 15 is missing, since we do not have −0 in our original
array.
Two’s-complement format The disadvantage of having two codes for
the number 0 is eliminated in this format. Positive numbers are coded as
usual. The B-bit two’s-complement, x̃, of a positive integer x is given by
x̃ = x̄ + 1 = 2B − x or
x + x̃ = 2B
(9.4)
where the second equality is obtained from (9.3). Once again, the MSB
of the representation provides the sign bit. Thus, using (9.4) the two’scomplement format representation3 is given by
x,
x≥0
x,
x≥0
x,
x≥0
=
(9.5)
x(2) =
=
2B + x, x < 0
|x̃|, x < 0
2B − |x|, x < 0
3 Again, the two’s-complement format refers to the representation of positive and negative numbers, whereas the two’s-complement of a number refers to the negation of
that number.
Representation of Numbers
391
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Thus, in B-bit two’s-complement format negative numbers are obtained
by adding 2B to them. Clearly, if B bits are available, then we can represent 2B integers from (−2B−1 ) to (+2B−1 − 1). For example, using 3 bits,
we can represent numbers from −4 to 3 as
-4
-3
-2
-1
0
1
2
3
-+----+----+----+----+----+----+----+100 101 110 111 000 001 010 011
This format, by shifting to the right (e.g., by incrementing) the code
of the negative numbers, straightforwardly removes the problem of having
two codes for 0 and gives access to an additional negative number at the
left of the line. Thus, 4 bits go from −8 to +7, 8 bits cover the interval
[−127, +127] and 16 bits cover [−32768, +32767].
MATLAB Implementation Using (9.5), we can develop the MATLAB function, TwosComplement, which obtains the two’s-complement format representation. We can use the bitcmp function and then add one
to the result to obtain the two’s-complement. However, we will use the
last equality in (9.5) to obtain the two’s-complement since this approach
will also be useful for fractional numbers. The function can use scalar
as well as vector values. The result is a decimal equivalent of the two’scomplement representation. As before, the dec2bin can be used to obtain
the binary code.
function y = TwosComplement(x,b)
% y = TwosComplement(x,b)
% --------------% Decimal equivalent of
% Sign-Magnitude format integer to b-bit Ones’-Complement format conversion
%
%
x: integer between -2^(b-1) <= x < 2^(b-1) (sign-magnitude)
%
y: integer between
0 <= y <= 2^b-1
(2’s-complement)
if any((x < -2^(b-1) | (x >= 2^(b-1))))
error(’Numbers must satisfy -2^(b-1) <= x < 2^(b-1)’)
end
s = sign(x); % sign of x (-1 if x<0, 0 if x=0, 1 if x>0)
sb = (s < 0); % sign-bit (0 if x>=0, 1 if x<0));
y = (1-sb).*x + sb.*(2^b+x); % or y = (1-sb).*x + sb.*(bitcmp(abs(x),b)+1);
392
EXAMPLE 9.2
Using the function TwosComplement, obtain the two’s-complement format representation of integers from −8 to 7 using 4 bits.
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
MATLAB Script:
>> x = -8:7
x =
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
>> y = TwosComplement(x,4)
y =
8
9
10
11
12
13
14
15
0
1
2
3
4
5
6
7
>> y = dec2bin(y,4); disp(sprintf(’%s’,[y’;char(ones(1,16)*32)]))
1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111
The two’s-complement format has many interesting characteristics
and advantages. These will be given after we discuss the next format,
namely the ten’s-complement.
Ten’s-complement format This is a representation for decimal integers. We will describe it so that we can explore characteristics of two’scomplement through decimal integers, which is much easier to understand.
Following (9.4), the N -digit ten’s-complement of a positive integer x is
given by
x̃ = 10N − x or x + x̃ = 10N
(9.6)
Using (9.6), the N -digit ten’s-complement format representation is given
by
x,
x≥0
x,
x≥0
x,
x≥0
∆
=
x(10N ) =
=
10N + x, x < 0
|x̃|, x < 0
10N − |x|, x < 0
(9.7)
Thus, in N -digit ten’s-complement format (which is sometimes referred to as 10N -complement format), negative numbers are obtained by
adding 10N to them. Clearly, when N digits are available, we can represent 10N integers from (−10N −1 ) to (+10N −1 − 1). For example, using
one-digit, we can represent numbers from −5 to 4 as
-5
-4
-3
-2
-1
0
1
2
3
4
-+----+----+----+----+----+----+----+----+----+
5
6
7
8
9
0
1
2
3
4
EXAMPLE 9.3
Solution
Using the 2-digit ten’s-complement, i.e., 100’s-complement format, perform the
following operations:
1. 16 − 32, 2. 32 − 16, 3. −30 − 40, 4. 40 + 20 − 30, 5. −40 − 20 + 30.
1. 16 − 32
First we note that 16 − 32 = −16. If we use the usual subtraction rule
to proceed from right to left generating carries in the process, we cannot
Representation of Numbers
393
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
complete the operation. To use the 100’s-complement format, we first note
that in the 100’s-complement format we have
16(100) = 16,
−16(100) = 100 − 16 = 84,
and
− 32(100) = 100 − 32 = 68
Hence 16 − 32 ≡ 16 + 68 = 84 ≡ −16 in the sign-magnitude format as
expected.
2. 32 − 16
In this case the 100’s-complement format gives
32 + 84 = 116 ≡ 16
in the sign-magnitude format by ignoring the generated carry digit. This is
because the sign-bits were different; therefore, the operation cannot generate
an overflow. Hence, we check for overflow only if the sign-bits are same.
3. −30 − 40
In this case the 100’s-complement format gives
(100 − 30) + (100 − 40) = 70 + 60 = 130
Since the sign-bits were the same, an overflow is generated and the result is
invalid.
4. 40 + 20 − 30
This is an example of more than one addition or subtraction. Since the final
result is well within the range, the overflow can be ignored—that is,
40 + 20 + (100 − 30) = 40 + 20 + 70 = 130 ≡ 30
which is a correct result.
5. −40 − 20 + 30
In this case, we have
(100 − 40) + (100 − 20) + 30 = 60 + 80 + 30 = 170 ≡ −30
in the sign-magnitude format, which is, again, a correct result.
MATLAB Implementation Using (9.7), one can develop the
MATLAB function, TensComplement, which obtains ten’s-complement
format representation. It is similar to the TwosComplement function and
is explored in Problem P9.2.
Advantages of two’s-complement format Using the results of the
above example, we now state the benefits of the two’s-complement format.
These also hold (with obvious modifications) for the ten’s-complement
format.
1. It provides for all 2B+1 distinct representations for a B-bit fractional
representation. There is only one representation for zero.
2. This complement is compatible with our notion of negation: the complement of a complement is the number itself.
394
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
3. It unifies the subtraction and addition operations (subtractions are
essentially additions).
4. In a sum of more than two numbers, the internal overflows do not affect
the final result so long as the result is within the range (i.e., adding
two positive numbers gives a positive result, and adding two negative
numbers gives a negative result).
Hence in most A/D converters and processors, negative numbers are represented using two’s-complement format. Almost all current processors
implement signed arithmetic using this format and provide special functions (e.g., an overflow flag) to support it.
Excess-2B−1 format This format is used in describing the exponent
of floating-point arithmetic; hence it is briefly discussed here. In excess2B−1 signed format (also known as a biased format), all positive and
negative integers between −2B−1 and 2B−1 − 1 are given by
∆
x(e) = 2B−1 + x
(9.8)
For example, using 3 bits, we can represent the numbers from −4 to
3 as
-4
-3
-2
-1
0
1
2
3
-+----+----+----+----+----+----+----+000 001 010 011 100 101 110 111
It may be noticed that this format is very similar to the two’s-complement
format, but the sign bit is complemented. The arithmetic for this format is
similar to that of the two’s-complement format. It is used in the exponent
of floating-point number representation.
GENERAL
FIXED-POINT
ARITHMETIC
Using the discussion of integer arithmetic from the last section as a guide,
we can extend the fixed-point representation to arbitrary real (integer
and fractional) numbers. We assume that a given infinite-precision real
number, x, is approximated by a binary number, x̂, with the following bit
arrangement:
· · · x xx
···x
(9.9)
x̂ = ± xx
↑
Sign bit
“L”
“B ”
Integer bits
Fraction bits
where the sign bit ± is 0 for positive numbers and 1 for negative numbers,
“x” represents either a “0” or a “1,” and “ ” represents the binary point.
This representation is in fact the sign-magnitude format for real numbers,
as we will see below. The total word length of the number x̂ is then equal
to L + B + 1 bits.
Representation of Numbers
395
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 9.4
Let L = 4 and B = 5, which means x̂ is a 10-bit number. Represent 11010 01110
in decimal.
Solution
x̂ = −(1 × 23 + 0 × 22 + 1 × 21 + 0 × 20 + 0 × 2−1 + 1 × 2−2 + 1 × 2−3 + 1 × 2−4 + 0 × 2−5 )
= −10.4375
in decimal.
In many A/D converters and processors, the real numbers are scaled
so that the fixed-point representation is in the (−1, 1) range. This has
the advantage that the multiplication of two fractions is always a fraction
and, as such, there is no overflow. Hence we will consider the following
representation:
(9.10)
x̂ = A(± xxxxxx
· · · x )
“B ”Fraction
bits
where A is a positive scaling factor.
EXAMPLE 9.5
Represent the number x̂ = −10.4375 in Example 9.4 using a fraction-only
arrangement.
Choose A = 24 = 16 and B = 9 Then
Solution
x̂ = −10.4375 = 16 (1 101001110)
Hence by properly choosing A and B one can obtain any fraction-only representation.
Note:
The scalar A need not be a power of 2. In fact, by choosing any real number A
we can obtain an arbitrary range. The power-of-2 choice for A, however, makes
hardware implementation a little easier.
As discussed in the previous section, there are three main formats
for fixed-point arithmetic, depending upon how negative numbers are obtained. For all these formats, positive numbers have exactly the same
representation. In the following we assume the fraction-only arrangement.
Sign-magnitude format As the name suggests, the magnitude is
given by the B-bit fraction, and the sign is given by the MSB. Thus,
0 x1 x2 · · · xB if x ≥ 0
(9.11)
x̂ =
1 x1 x2 · · · xB if x < 0
For example, when B = 2, x̂ = +1/4 is represented by x̂ = 0 01, and
x̂ = −1/4 is represented by x̂ = 1 01.
396
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
One’s-complement format In this format, the positive numbers have
the same representation as the sign-magnitude format. When the number
is negative, then its magnitude is given by its bit-complement arrangement. Thus,
0 x1 x2 · · · xB if x ≥ 0
(9.12)
x̂ =
1 x̄1 x̄2 · · · x̄B if x < 0
For example, when B = 2, x̂ = +1/4 is represented by x̂ = 0 01, and
x̂ = −1/4 is represented by x̂ = 1 10.
Two’s-complement format Once again, the positive numbers have
the same representation. Negative numbers are obtained by first complementing the magnitude and then modulo-2 adding one to the last bit
or the least significant bit (LSB). Stated differently, two’s-complement is
formed by subtracting the magnitude of the number from 2. Thus


0 x1 x2 · · · xB
if x ≥ 0
x̂ =
 2 − |x| = 1 x̄1 x̄2 · · · x̄B ⊕ 0 00 · · · 1 = 1 y1 y2 · · · yB if x < 0
(9.13)
where ⊕ represents modulo-2 addition and bit y is, in general, different
from bit x̄. For example, when B = 2, x̂ = +1/4 is represented by x̂ =
0 01, while x̂ = −1/4 is represented by x̂ = 1 10 ⊕ 0 01 = 1 11.
EXAMPLE 9.6
Solution
Let B = 3; then x̂ is a 4-bit number (sign plus 3 bits). Provide all possible
values that x̂ can take in each of the three formats.
There are 24 = 16 possible values that x̂ can take for each of the three formats,
as shown in the following table.
Representation of Numbers
Binary
Sign-Mag
one’s
two’s
0 111
0 110
0 101
0 100
0 011
0 010
0 001
0 000
1 111
1 110
1 101
1 100
1 011
1 010
1 001
1 000
7/8
6/8
5/8
4/8
3/8
2/8
1/8
0
−0
−1/8
−2/8
−3/8
−4/8
−5/8
−6/8
−7/8
7/8
6/8
5/8
4/8
3/8
2/8
1/8
0
−7/8
−6/8
−5/8
−4/8
−3/8
−2/8
−1/8
−0
7/8
6/8
5/8
4/8
3/8
2/8
1/8
0
−1
−7/8
−6/8
−5/8
−4/8
−3/8
−2/8
−1/8
397
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In the above example, observe that the bit arrangement is exactly
same as in the integer case for 4 bits. The only difference is in the position
of the binary point. Thus the MATLAB programs developed in the previous section can easily be used with proper modifications. The MATLAB
function sm2oc converts a decimal sign-magnitude fraction into its one’scomplement format, while the function oc2sm performs the inverse operation. These functions are explored in Problem P9.3. Similarly, MATLAB
functions sm2tc and tc2sm convert a decimal sign-magnitude fraction
into its two’s-complement format and vice versa, respectively; they are
explored in Problem P9.4.
FLOATINGPOINT
ARITHMETIC
In many applications, the range of numbers needed is very large. For
example, in physics one might need, at the same time, the mass of the sun
(e.g., 2.1030 kg) and the mass of the electron (e.g., 9.10−31 kg). These two
numbers cover a range of over 1060 . For fixed-point arithmetic, we would
need 62-digit numbers (or 62-digit precision). However, even the mass of
the sun is not accurately known with a precision of five digits, and there is
almost no measurement in physics that could be made with a precision of
62 digits. One could then imagine making all calculations with a precision
of 62 digits and throwing away 50 or 60 of them before printing out the
final results. This would be wasteful of both CPU time and memory space.
So what is needed is a system for representing numbers in which the
range of expressible numbers is independent of the number of significant
digits.
Decimal numbers The floating-point representation for a decimal
number x is based on expressing the number in the scientific notation:
x = ±M × 10±E
where M is called the mantissa and E is the exponent. However, there
are different possible representations of the same number, depending on
the actual position of the decimal point—for example,
1234 = 0.1234 × 104 = 1.234 × 103 = 12.34 × 102 = · · ·
To fix this problem, a floating point-number is always stored using a
unique representation, which has only one non-zero digit to the left of the
decimal point. This representation of a floating-point number is called a
normalized form. The normalized form of the number above is 1.234×103 ,
because it is the only representation resulting in a unique non-zero digit
to the left of the decimal point. The digit arrangement for the normalized
398
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
form is given by
sign of
x̂ =
↓
±
sign of
M
↓
x xx
···x
“N ”-bit M
±
E
xx
···x
“L”-bit E
(9.14)
For the negative numbers we have the same formats as the fixed-point
representations, including the ten’s-complement format.
The number of digits used in the exponent determine the range of
representable numbers, whereas the number of digits used in the mantissa
determine the precision of the numbers. For example, if the mantissa is
expressed using 2 digits plus the sign, and the exponent using 2 digits
plus the sign, then the real number line will be covered as:
99
-99
-99
99
-9.99x10
-1.0x10
0
1.0x10
9.99x10
----------+-------------+-----------+-----------+-------------+----------->
| accessible |
0
| accessible |
negative |
negative | negative | positive |
positive | positive
overflow |
numbers | underflow | underflow |
numbers | overflow
The range of accessible floating point numbers with a given representation
can be large, but it is still finite. In the above example (e.g., with 2 digits
for the mantissa and 2 digits for the exponent), there are only 9×10×10×
199 = 179, 100 positive numbers, and as many negative numbers, plus the
number zero for a total of 358,201 numbers that can be represented.
Binary numbers Although the fraction-only fixed-point arithmetic
does not have any overflow problems when two numbers are multiplied, it
does suffer from overflow problems when two numbers are added. Also, the
fixed-point numbers have limited dynamic range. Both of these aspects
are unacceptable for an intensive computational job. These limitations
can be removed by making the binary point ‘ ’ floating rather than fixed.
The floating-point bit arrangement for binary-number representation
is similar to that for the decimal numbers. In practice, however, two exceptions are made. The exponent is expressed using L-bit excess-2L−1
format, and the B-bit normalized mantissa is a fractional number with
a 1 following the binary-point. Note that the sign bit is the MSB of the
bit pattern. Thus the B-bit mantissa and L-bit exponent (for a total of
B + L + 1 word length) bit pattern is given by (note the reversal of the
mantissa exponent places)
sign of M
x̂ =
↓
±
xx
···x
“L”-bit E
1x
···x
“B ”-bit M
(9.15)
where exponent E is adjusted so that we have a normalized mantissa—
that is, 1/2 ≤ M < 1. Hence the first bit after the binary point is always 1.
Representation of Numbers
399
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The decimal equivalent of x̂ is given by
x̂ = ±M × 2E
(9.16)
For the negative numbers we can have the same formats as the fixed-point
representations for the mantissa including two’s-complement format.
However, the most widely used format for the mantissa is the signmagnitude one.
EXAMPLE 9.7
Consider a 32-bit floating-point word with the following arrangement:
x̂ = ± xx
···x
8−bit E
1x
···x
23−bit M
Determine the decimal equivalent of
01000001111000000000000000000000
Solution
Since the exponent is 8-bit, it is expressed in excess-27 or in excess-128 format.
Then the bit pattern can be partitioned into
Sign
↓
x̂ = 0 10000011
11000000000000000000000
M =2−1 +2−2
E=131
The sign bit is 0, which means that the number is positive. The exponent code is
131, which means that its decimal value is 131 − 128 = 3. Thus, the bit pattern
represents the decimal number x̂ = + 2−1 + 2−2 (23 ) = 22 + 21 = 6.
EXAMPLE 9.8
Solution
Let x̂ = −0.1875. Represent x̂ using the format given in (9.15), in which B = 11,
L = 4 (for a total of 16 bits), and sign-magnitude format used for the mantissa.
We can write
x̂ = −0.1875 = −0.75 × 2−2
Hence the exponent is −2, the mantissa is 0.75, and the sign is negative. The
4-bit exponent, in excess-8 format, is expressed as 8 − 2 = 6 or with bit pattern
0110. The mantissa is expressed as 11000000000. Since x̂ is negative, the bit
pattern is
x̂ ≡ 1011011000000000
The advantages of the floating-point representation are that it has
a large dynamic range and that its resolution, defined as the interval
between two consecutive representable levels, is proportional to the magnitude. The disadvantages include no representation for the number 0 and
the fact that the arithmetic operations are more complicated than their
fixed-point representations.
400
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
IEEE 754 standard In the early days of the digital computer revolution, each processor design had its own internal representation for floatingpoint numbers. Since floating-point arithmetic is more complicated to
implement, some of these designs did incorrect arithmetic. Therefore, in
1985 IEEE issued a standard (IEEE standard 754-1985 or IEEE-754 for
short) to allow floating-point data exchange among different computers
and to provide hardware designers with a model known to be correct. Currently, almost all manufacturers design main processors or a dedicated
coprocessor for floating-point operations using the IEEE-754 standard
representation.
The IEEE 754 standard defines three formats for binary numbers: a
32-bit simple precision format, a 64-bit double precision format, and an
80-bit temporary format (which is used internally by the processors or
arithmetic coprocessors to minimize rounding errors).
We will briefly describe the 32-bit single precision standard. This
standard has many similarities with the floating-point representation discussed above, but there are also differences. Remember, this is another
model advocated by IEEE. The form of this model is
sign of M
x̂ =
↓
±
xx
···x
8−bit E
xx
···x
(9.17)
23−bit M
The mantissa’s value is called the significand in this standard. Features
of this model are as follows:
• If the sign bit is 0, the number is positive; if the sign bit is 1, the
number is negative.
• The exponent is coded in 8-bit excess-127 (and not 128) format. Hence
the uncoded exponents are between −127 and 128.
• The mantissa is in 23-bit binary. A normalized mantissa always starts
with a bit 1, followed by the binary point, followed by the rest of the
23-bit mantissa. However, the leading bit 1, which is always present in a
normalized mantissa, is hidden (not stored) and needs to be restored for
computation. Again, note that this is different from the usual definition
of the normalized mantissa. If all the 23 bits representing the mantissa
are set to 0, the significand is 1 (remember the implicit leading 1). If
all 23 bits are set to 1, the significand is almost 2 (in fact 2 − 2−23 ). All
IEEE 754 normalized numbers have a significand that is in the interval
1 ≤ M < 2.
• The smallest normalized number is 2−126 , and the greatest normalized
number is almost 2128 . The resulting positive decimal range is roughly
10−38 to 1038 with a similar negative range.
• If E = 0 and M = 0, then the representation is interpreted as a denormalized number (i.e., the hidden bit is 0) and is assigned a value of
Representation of Numbers
401
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
±0, depending on the sign bit (called the soft zero). Thus 0 has two
representations.
• If E = 255 and M = 0, then the representation is interpreted as a
not-a-number (abbreviated as NaN). MATLAB assigns a variable NaN
when this happens—e.g., 0/0.
• If E = 255 and M = 0, then the representation is interpreted as ±∞.
MATLAB assigns a variable inf when this happens—e.g., 1/0.
EXAMPLE 9.9
Solution
Consider the bit pattern given in Example 9.7. Assuming IEEE-754 format,
determine its decimal equivalent.
The sign bit is 0 and the exponent code is 131, which means that the exponent
is 131 − 127 = 4. The significand is 1 + 2−1 + 2−2 = 1.75. Hence the bit pattern
represents
x̂ = +(1 + 2−1 + 2−2 )(24 ) = 24 + 23 + 22 = 28
which is different from the number in Example 9.7.
MATLAB employs the 64-bit double precision IEEE-754 format for
all its number representations and the 80-bit temporary format for its internal computations. Hence all calculations that we perform in MATLAB
are in fact floating-point computations. Simulating a different floatingpoint format in MATLAB would be much more complicated and would
not add any more insight to our understanding than the native format.
Hence we will not consider a MATLAB simulation of floating-point arithmetic as we did for fixed-point.
THE PROCESS OF QUANTIZATION AND ERROR
CHARACTERIZATIONS
From the discussion of number representations in the previous section, it
should be clear that a general infinite-precision real number must be assigned to one of the finite representable number, given a specific structure
for the finite-length register (that is, the arithmetic as well as the format).
Usually in practice, there are two different operations by which this assignment is made to the nearest number or level: the truncation operation
and the rounding operation. These operations affect the accuracy as well
as general characteristics of digital filters and DSP operations.
We assume, without loss of generality, that there are ‘B + 1’ bits in
the fixed-point (fractional) arithmetic or in the mantissa of floating-point
arithmetic including the sign-bit. Then the resolution, ∆, is given by
absolute in the case of fixed-point arithmetic
∆ = 2−B
(9.18)
relative in the case of floating-point arithmetic
402
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIXED-POINT
ARITHMETIC
The quantizer block diagram in this case is given by
x
Infinite−precision
−→ Quantizer Q[·] −→
Q[x]
B, ∆
Finite−precision
where B, the number of fractional bits, and ∆, the resolution, are the parameters of the quantizer. We will denote the finite word-length number,
after quantization, by Q[x] for an input number x. Let the quantization
error be given by
e = Q[x] − x
(9.19)
We will analyze this error for both the truncation and the rounding
operations.
Truncation operation In this operation, the number x is truncated
beyond B significant bits (that is, the rest of the bits are eliminated)
to obtain QT [x]. In MATLAB, to obtain a B-bit truncation, we have to
first scale the number x upwards by 2B , then use the fix function on
the scaled number, and finally scale the result down by 2−B . Thus, the
MATLAB statement xhat = fix(x*2^B)/2^B; implements the desired
operation. We will now consider each of the three formats.
Sign-magnitude format If the number x is positive, then after truncation QT [x] ≤ x since some value in x is lost. Hence quantizer error for
truncation denoted by eT is less than or equal to 0 or eT ≤ 0. However,
since there are B bits in the quantizer, the maximum error in terms of
magnitude is
· · · 0 111 · · · = 2−B (decimal)
|eT | = 0 00
(9.20)
B bits
or
−2−B ≤ eT ≤ 0,
for x ≥ 0
(9.21)
Similarly, if the x < 0 then after truncation QT [x] ≥ x since QT [x] is less
negative, or eT ≥ 0. The largest magnitude of this error is again 2−B or
0 ≤ eT ≤ 2−B ,
EXAMPLE 9.10
Solution
for x < 0
(9.22)
Let −1 < x < 1 and B = 2. Using MATLAB verify the truncation error
characteristics.
The resolution is ∆ = 2−2 = 0.25. Using the following MATLAB script we can
verify the truncation error eT relations given in (9.21) and (9.22).
The Process of Quantization and Error Characterizations
403
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1
x
xhat
0.75
0.5
xhat
0.25
0
−0.25
−0.5
−0.75
−1
−1 −0.75 −0.5 −0.25
0
0.25
0.5
0.75
1
x
FIGURE 9.2
Truncation error characteristics in the sign-magnitude format
x = [-1+2^(-10):2^(-10):1-2^(-10)];
B = 2;
xhat = fix(x*2^B)/2^B
plot(x,x,’g’,x,xhat,’r’,’linewidth’,1);
%
%
%
%
Sign-Mag numbers between -1 and 1
Number of bits for Truncation
Truncation
Plot
The resulting plots of x and x̂ are shown in Figure 9.2. Note that the plot of x̂
has a staircase shape and that it satisfies (9.21) and (9.22).
One’s-complement format For x ≥ 0, we have the same characteristics for eT as in sign-magnitude format—that is,
−2−B ≤ eT ≤ 0,
for x ≥ 0
(9.23)
For x < 0, the representation is obtained by complementing all bits including sign bit. To compute maximum error, let
x = 1 b1 b2 · · · bB 000 · · · = − { (1 − b1 ) (1 − b2 ) · · · (1 − bB ) 111 · · ·}
After truncation, we obtain
QT [x] = 1 b1 b2 · · · bB = − { (1 − b1 ) (1 − b2 ) · · · (1 − bB )}
Clearly, x is more negative than QT [x] or x ≤ QT [x] or eT ≥ 0. In fact,
the maximum truncation error is
eTmax = 0 00 · · · 0111 · · · = 2−B (decimal)
Hence
404
0 ≤ eT ≤ 2−B ,
Chapter 9
for x < 0
(9.24)
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 9.11
Solution
Again let −1 < x < 1 and B = 2 with the resolution ∆ = 2−2 = 0.25. Using
MATLAB script verify the truncation error eT relations given in (9.23) and
(9.24).
The MATLAB script uses functions sm2oc and oc2sm, which are explored in
Problem P9.3.
x = [-1+2^(-10):2^(-10):1-2^(-10)];
B = 2;
y = sm2oc(x,B);
yhat = fix(y*2^B)/2^B;
xhat = oc2sm(yhat,B);
plot(x,x,’g’,x,xhat,’r’,’linewidth’,1);
%
%
%
%
%
%
Sign-Magnitude numbers between -1 and 1
Select bits for Truncation
Sign-Mag to One’s Complement
Truncation
Ones’-Complement to Sign-Mag
Plot
The resulting plots of x and x̂ are shown in Figure 9.3. Note that the plot of x̂
is identical to the plot in Figure 9.2 and that it satisfies (9.23) and (9.24). Once again, for x ≥ 0, we have
Two’s-complement format
−2−B ≤ eT ≤ 0,
for x ≥ 0
(9.25)
For x < 0, the representation is given by 2 − |x| where |x| is the magnitude.
Hence the magnitude of x is given by
|x| = 2 − x
(9.26)
1
0.75
x
xhat
0.5
xhat
0.25
0
−0.25
−0.5
−0.75
−1
−1 −0.75 −0.5 −0.25
FIGURE 9.3
0
x
0.25
0.5
0.75
1
Truncation error characteristics in the one’s-complement format
The Process of Quantization and Error Characterizations
405
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
with x = 1 b1 b2 · · · bB bB+1 · · ·. After truncation to B bits, we obtain
QT [x] = 1 b1 b2 · · · bB the magnitude of which is
|QT [x]| = 2 − QT [x]
(9.27)
From (9.26) and (9.27)
|QT [x]| − |x| = x − QT [x] = 1 b1 b2 · · · bB bB+1 · · · − 1 b1 b2 · · · bB
= 0 00 · · · 0bB+1 · · ·
(9.28)
The largest change in magnitude from (9.28) is
0 00 · · · 0111 · · · = 2−B (decimal)
(9.29)
Since the change in the magnitude is positive, then after truncation QT [x]
becomes more negative, which means that QT [x] ≤ x. Hence
−2−B ≤ eT ≤ 0,
EXAMPLE 9.12
Solution
for x < 0
(9.30)
Again consider −1 < x < 1 and B = 2 with the resolution ∆ = 2−2 = 0.25.
Using MATLAB, verify the truncation error eT relations given in (9.25) and
(9.30).
The MATLAB script uses functions sm2tc and tc2sm, which are explored in
Problem P9.4.
x = [-1+2^(-10):2^(-10):1-2^(-10)]; % Sign-Magnitude numbers between -1 and 1
B = 2;
% Select bits for Truncation
y = sm2tc(x);
% Sign-Mag to Two’s Complement
yhat = fix(y*2^B)/2^B;
% Truncation
xq = tc2sm(yq );
% Two’s-Complement to Sign-Mag
plot(x,x,’g’,x,xhat,’r’,’linewidth’,1); % Plot
The resulting plots of x and x̂ are shown in Figure 9.4. Note that the plot of
x̂ is also a staircase graph but is below the x graph and that it satisfies (9.25)
and (9.30).
Collecting results (9.21)–(9.25), and (9.30) along with in Figures 9.2–
9.4, we conclude that the truncation characteristics for fixed-point arithmetic are the same for the sign-magnitude and the one’s-complement
formats but are different for the two’s-complement format.
Rounding operation In this operation, the real number x is rounded
to the nearest representable level, which we will refer to as QR [x]. In
MATLAB, to obtain a B-bit rounding approximation, we have to first
scale the number x up by 2B , then use the round function on the scaled
406
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1
x
xhat
0.75
0.5
xhat
0.25
0
−0.25
−0.5
−0.75
−1
−1
FIGURE 9.4
−0.75 −0.5 −0.25
0
x
0.25
0.5
0.75
1
Truncation error characteristics in the two’s-complement format
number, and finally scale the result down by 2−B . Thus the MATLAB
statement xhat = round(x*2^B)/2^B; implements the desired operation.
Since the quantization step or resolution is ∆ = 2−B , the magnitude
of the maximum error is
1
∆
= 2−B
(9.31)
|eR |max =
2
2
Hence for all three formats, the quantizer error due to rounding, denoted
by eR , satisfies
1
1
− 2−B ≤ eR ≤ 2−B
(9.32)
2
2
EXAMPLE 9.13
Solution
Demonstrate the rounding operations and the corresponding error characteristics on the signal of examples 9.10–9.12 using the three formats.
Since the rounding operation assigns values that can be larger than the unquantized values, which can create problems for the two’s- and one’s-complement
format, we will restrict the signal over the interval [−1, 1 − 2−B−1 ]. The following MATLAB script shows the two’s-complement format rounding, but other
scripts are similar (readers are encouraged to verify).
B = 2;
x = [-1:2^(-10):1-2^(-B-1)];
y = sm2tc(x);
yq = round(y*2^B)/2^B;
xq = tc2sm(yq);
The Process of Quantization and Error Characterizations
%
%
%
%
%
Select bits for Rounding
Sign-Magnitude numbers between -1 and 1
Sign-Mag to Two’s Complement
Rounding
Two’-Complement to Sign-Mag
407
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
(b) Sign-Magnitude Format
0.75
(b) Ones-Complement Format
0.75
x
xhat
(b) Two-Complement Format
0.75
x
xhat
0.25
0.25
0.25
0
xhat
0.5
xhat
0.5
xhat
0.5
0
0
−0.25
−0.25
−0.25
−0.5
−0.5
−0.5
−0.75
−0.75
−0.75
−1
−1
−1 −0.75 −0.5 −0.25 0
x
0.25 0.5 0.75
FIGURE 9.5
−1 −0.75 −0.5 −0.25 0
x
0.25 0.5 0.75
x
xhat
−1
−1 −0.75 −0.5 −0.25 0
x
0.25 0.5 0.75
Rounding error characteristics in the fixed-point representation
The resulting plots for the sign-magnitude, ones’-, and two’s-complement
formats are shown in Figure 9.5. These plots do satisfy (9.32).
Comparing the error characteristics of the truncation and rounding
operations given in Figures 9.2 through 9.5, it is clear that the rounding
operation is a superior one for the quantization error. This is because the
error is symmetric with respect to zero (or equal positive and negative
distribution) and because the error is the same across all three formats.
Hence we will mostly consider the rounding operation for the floatingpoint arithmetic as well as for further analysis.
FLOATINGPOINT
ARITHMETIC
In this arithmetic, the quantizer affects only the mantissa M . However,
the number x is represented by M × 2E where E is the exponent. Hence
the quantizer errors are multiplicative and depend on the magnitude of
x. Therefore, the more appropriate measure of error is the relative error
rather than the absolute error, (Q[x] − x). Let us define the relative error,
ε, as
Q[x] − x
(9.33)
ε=
x
Then the quantized value Q[x] can be written as
Q[x] = x + εx = x (1 + ε)
(9.34)
When Q[x] is due to the rounding operation, then the error in the mantissa is between [− 12 2−B , 12 2−B ]. In this case we will denote the relative
error by εR . Then from (9.16), the absolute error, QR [x] − x = εR x, is
between
1 −B E
1
2
2
(9.35)
− 2−B 2E ≤ εR x ≤
2
2
408
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Now for a given E, and since the mantissa is between
not the IEEE-754 model), the number x is between
2E−1 ≤ x < 2E
1
2
≤ M < 1 (this is
(9.36)
Hence from (9.35) and using the smallest value in (9.36), we obtain
−2−B ≤ εR ≤ 2−B
(9.37)
This relative error relation, (9.37), will be used in subsequent analysis.
QUANTIZATION OF FILTER COEFFICIENTS
We now study the finite word-length effects on the filter responses, polezero locations, and stability when the filter coefficients are quantized. We
will separately discuss the issues relating to IIR and FIR filters since we
can obtain simpler results for FIR filters. We begin with the case of IIR
filters.
IIR FILTERS
Consider a general IIR filter described by
M
−k
k=0 bk z
H(z) =
N
1 + k=1 ak z −k
(9.38)
where ak ’s and bk ’s are the filter coefficients. Now assume that these
coefficients are represented by their finite precision numbers âk ’s and b̂k ’s.
Then we get a new filter system function
M
−k
k=0 b̂k z
H(z) → Ĥ(z) =
(9.39)
N
1 + k=1 âk z −k
Since this is a new filter, we want to know how “different” this filter is from the original one H(z). There are various aspects that can be
compared; for example, we may want to compare their magnitude responses, or phase responses, or change in their pole-zero locations, and
so on. A general analytical expression to compute this change in all the
above aspects is difficult to derive. This is where MATLAB can be used to
investigate this change and its overall effect on the usability of the filter.
EFFECT ON
POLE-ZERO
LOCATIONS
There is one aspect that can be reasonably analyzed, which is the movement of filter poles when ak is changed to âk . This can be used to check
the stability of IIR filters. A similar movement of zeros to changes in
numerator coefficients can also be analyzed.
Quantization of Filter Coefficients
409
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
To evaluate this movement, consider the denominator polynomial of
H(z) in (9.38)
D(z) = 1 +
N
ak z −k =
k=1
N
1 − p z −1
(9.40)
=1
where {p }’s are the poles of H(z). We will regard D(z) as a function
D(p1 , . . . , pN ) of poles {p1 , . . . , pN } where each pole p is a function of the
filter coefficients {a1 , . . . , aN }—that is, p = f (a1 , . . . , aN ), = 1, . . . N .
Then the change in the denominator D(z) due to a change in the k th
coefficient ak is given by
∂D(z)
∂D(z)
=
∂ak
∂p1
∂p1
∂D(z)
+
∂ak
∂p2
∂p2
∂D(z)
+· · ·+
∂ak
∂pN
∂pN
∂ak
(9.41)
where from (9.40)
N
∂D(z)
∂ −1
=
1−p z
= −z −1
1 − p z −1
∂pi
∂pi
From (9.42) note that
∂D(z)
∂pi
= 0 for = i. Hence from (9.41) we
z=p
obtain
∂D(z) =
∂ak z=p
(9.42)
=i
=1
z=p
=
∂D(z) ∂p
∂D(z) ∂p
z=p
∂p
∂ak
or
∂p
∂ak
∂D(z)
∂ak
z=p
(9.43)
Now
∂D(z)
∂ak
z=p
∂
=
∂ak
1+
N
i=1
ai z −i = z −k z=p = p−k (9.44)
z=p
From (9.42), (9.43) and (9.44) we obtain
∂p
∂ak
=
−z
−1
i=
p−k
pN −k
=
−
(1 − pi z −1 )z=p
i= (p − pi )
(9.45)
Finally, the total perturbation error p can be expressed as
p =
N
∂p
ak
∂ak
(9.46)
k=1
This formula measures the movement of the th pole, p , to changes in
each of the coefficient {ak }; hence it is known as a sensitivity formula.
410
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Im{z}
z3
z2
z1
0
z*1
z*2
Re{z}
z1
z*1
0
0
z*3
(a) Direct-form arrangement
FIGURE 9.6
z3
z2
z*2
0
z*3
(b) Cascade- or parallel-form arrangement
z-plane plots of tightly clustered poles of a digital filter
It shows that if the coefficients {ak } are such that if the poles p and pi are
very close for some , i, then (p −pi ) is very small and as a result the filter
is very sensitive to the changes in filter coefficients. A similar result can
be obtained for the sensitivity of zeros to changes in the parameters {bk }.
To investigate this further in the light of various filter realizations,
consider the z-plane plot shown in Figure 9.6(a) where poles are tightly
clustered. This situation arises in wideband frequency selective filters such
as lowpass or highpass filters. Now if we were to realize this filter using the
direct form (either I or II), then the filter has all these tightly clustered
poles, which makes the direct-form realization very sensitive to coefficient
changes due to finite word length. Thus, the direct-form realizations will
suffer severely from parameter quantization effects.
On the other hand, if we were to use either the cascade or the parallel forms, then we would realize the filter using second-order sections
containing widely separated poles, as shown in Figure 9.6(b). Thus, each
second-order section will have low sensitivity in that its pole locations
will be perturbed only slightly. Consequently, we expect that the overall
system function H(z) will be perturbed only slightly. Thus, the cascade
or the parallel forms, when realized properly, will have low sensitivity to
the changes or errors in filter coefficients.
EXAMPLE 9.14
Consider a digital resonator that is a second-order IIR filter given by
H(z) =
1
1 − (2r cos θ) z −1 + r2 z −2
(9.47)
Analyze its sensitivity to pole locations when a 3-bit sign-magnitude format is
used for the coefficient representation.
Solution
The filter has two complex-conjugate poles at
p1 = rejθ
and
p2 = re−jθ = p∗1
For a proper operation as a resonator, the poles must be close to the unit
circle—that is, r 1 (but r < 1). Then the resonant frequency ωr θ.
Quantization of Filter Coefficients
411
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Im{z}
UC
x{n}
r
y {n}
z
Re{z}
0
z −1
−r 2
r
(a)
FIGURE 9.7
−1
(b)
Digital filter in Example 9.14 (a) Pole-zero plot, (b) Filter
realization
The zero-pole diagram is shown in Figure 9.7 along with the filter realization.
Let r = 0.9 and θ = π/3. Then from (9.47),
a1 = −2r cos θ = −0.9
and
a2 = r2 = 0.81
We now represent a1 and a2 each using 3-bit sign-magnitude format
representation—that is,
ak = ± b1 b2 b3 = ± b1 2−1 + b2 2−2 + b3 2−3 ,
k = 1, 2
where bj represents the jth bit and represents the binary point. Then for the
closest representation, we must have
â1 = 1 1 1 1 = −0.875, and
â2 = 0 1 1 0 = +0.75
Hence |a1 | = 0.025 and |a2 | = 0.06. Consider the sensitivity formula (9.46)
in which
p2−1
∂p1
−p1
−rejθ
ejπ/3
1
= −
=
=
= √ , and
∗
∂a1
(p1 − p1 )
2 Im {p1 }
2r (sin θ)
3
p2−2
−1
1
∂p1
1
√
= −
=
=
∂a2
(p1 − p∗1 )
2 Im {p1 }
0.9 3
Using (9.46), we obtain
∂p1 ∂p1 |a1 | + |a2 |
|p1 | ≤ ∂a1
∂a2
1
1
√ (0.06) = 0.0529
= √ (0.025) +
3
0.9 3
(9.48)
To determine the exact locations of the changed poles, consider the changed
denominator
D̂ (z) = 1−0.875z −1 + 0.75z −2 = 1 − 0.866ej0.331π z −1
1 − 0.866e−j0.331π z −1
Thus,
the changed pole locations are p̂1 = 0.866ej0.331π = p̂∗2 . Then |p1 | =
0.9eiπ/3 − 0.866ei0.331π = 0.0344, which agrees with (9.48).
412
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Analysis using MATLAB To investigate the effect of coefficient
quantization on filter behavior, MATLAB is an ideal vehicle. Using functions developed in previous sections, we can obtain quantized coefficients
and then study such aspects as pole-zero movements, frequency response,
or impulse response. We will have to represent all filter coefficients using
the same number of integer and fraction bits. Hence instead of quantizing each coefficient separately, we will develop the function, QCoeff,
for coefficient quantization. This function implements quantization using
rounding operation on sign-magnitude format. Although similar functions
can be written for truncation as well as for other formats, we will analyze
the effects using the Qcoeff function as explained previously.
function [y,L,B] = QCoeff(x,N)
% [y,L,B] = QCoeff(x,N)
%
Coefficient Quantization using N=1+L+B bit Representation
%
with Rounding operation
%
y: quantized array (same dim as x)
%
L: number of integer bits
%
B: number of fractional bits
%
x: a scalar, vector, or matrix
%
N: total number of bits
xm = abs(x);
L = max(max(0,fix(log2(xm(:)+eps)+1))); % Integer bits
if (L > N)
errmsg = [’ *** N must be at least ’,num2str(L),’ ***’]; error(errmsg);
end
B = N-L;
% Fractional bits
y = xm./(2^L); y = round(y.*(2^N)); % Rounding to N bits
y = sign(x).*y*(2^(-B));
% L+B+1 bit representation
The Qcoeff function represents each coefficient in the x array using
N+1-bit (including the sign bit) representation. First, it determines the
number of bits, L, needed for integer representation for the magnitudewise largest coefficient, and then it assigns N-L bits to the fraction part.
The resulting number is returned in B. Thus all coefficients have the same,
L+B+1, bit pattern. Clearly, N ≥ L.
EXAMPLE 9.15
Solution
Consider the digital resonator in Example 9.14. Determine the change in the
pole locations using MATLAB.
The filter coefficients, a1 = −0.9 and a2 = 0.81 can be quantized using
>> x = [-0.9,0.81]; [y,L,B] = Qcoeff(x,3)
y = -0.8750
0.7500
L = 0
B = 3
Quantization of Filter Coefficients
413
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
as expected. Now using the following MATLAB script, we can determine the
change in the location of the poles:
% Unquantized parameters
r = 0.9; theta = pi/3; a1 = -2*r*cos(theta); a2 = r*r;
p1 = r*exp(j*theta); p2 = p1’;
% Quantized parameters: N = 3;
[ahat,L,B] = Qcoeff([a1,a2],3); rhat = sqrt(ahat(2));
thetahat = acos(-ahat(1)/(2*rhat)); p1hat = rhat*exp(j*thetahat); p2 = p1’;
% Changes in pole locations
Dp1 = abs(p1-p1hat)
Dp1 = 0.0344
which is the same as before.
EXAMPLE 9.16
Consider the following IIR filter with 10 poles closely packed at a radius of
r = 0.9 around angles ±45◦ with a separation of 5◦ . Due to large number of
poles, the denominator coefficients have values that require 6 bits for the integer
part. Using 9 bits for the fractional part for a total of 16-bit representation, we
compute and plot the new locations of poles:
r = 0.9; theta = (pi/180)*[-55:5:-35,35:5:55]’;
p = r*exp(j*theta); a = poly(p); b = 1;
% Direct form: quantized coefficients
N = 15; [ahat,L,B] = Qcoeff(a,N);
TITLE = sprintf(’%i-bit (1+%i+%i) Precision’,N+1,L,B);
% Comparison of Pole-Zero Plots
subplot(1,2,1); [HZ,HP,Hl] = zplane(1,a);
set(HZ,’color’,’g’,’linewidth’,1); set(HP,’color’,’g’,’linewidth’,1);
set(Hl,’color’,’w’); axis([-1.1,1.1,-1.1,1.1]);
title(’Infinite Precision’,’fontsize’,10,’fontweight’,’bold’);
subplot(1,2,2); [HZhat,HPhat,Hlhat] = zplane(1,ahat);
set(HZhat,’color’,’r’,’linewidth’,1); set(HPhat,’color’,’r’,’linewidth’,1);
set(Hlhat,’color’,’w’); title(TITLE,’fontsize’,10,’fontweight’,’bold’);
axis([-1.1,1.1,-1.1,1.1]);
Figure 9.8 shows the pole-zero plots for filters with both infinite and 16bit precision coefficients. Clearly, with 16-bit word length, the resulting filter is
completely different from the original one and is unstable. To investigate finite
word-length effect on the cascade-form structure, we first converted the directform coefficients into the cascade-form coefficients using the dir2cas function,
quantized the resulting set of coefficients, and then converted back to the directform for pole-zero plotting. We show results for two different word lengths. In the
first case, we used the same 16-bit word length. Since the cascade coefficients
414
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
16–bit (1+6+9) Precision
1
1
0.5
0.5
Imaginary Part
Imaginary Part
Infinite Precision
10
0
−0.5
10
0
−0.5
−1
−1
−1
FIGURE 9.8
0
0.5
−0.5
Real Part
1
−1
−0.5
0
0.5
Real Part
1
Pole-zero plots for direct-form structure in Example 9.16
have smaller integer parts that require only one integer bit, the number of
fractional bits is 14. In the second case we used 9 fractional bits (same as those
in the direct-form) for a total word length of 11 bits.
% Cascade form: quantized coefficients: Same N
[b0,B0,A0] = dir2cas(b,a); [BAhat1,L1,B1] = Qcoeff([B0,A0],N);
TITLE1 = sprintf(’%i-bit (1+%i+%i) Precision’,N+1,L1,B1);
Bhat1 = BAhat1(:,1:3); Ahat1 = BAhat1(:,4:6);
[bhat1,ahat1] = cas2dir(b0,Bhat1,Ahat1);
subplot(1,2,1); [HZhat1,HPhat1,Hlhat1] = zplane(bhat1,ahat1);
set(HZhat1,’color’,’g’,’linewidth’,1); set(HPhat1,’color’,’g’,’linewidth’,1);
set(Hlhat1,’color’,’w’); axis([-1.1,1.1,-1.1,1.1]);
title(TITLE1,’fontsize’,10,’fontweight’,’bold’);
% Cascade form: quantized coefficients: Same B (N=L1+B)
N1 = L1+B; [BAhat2,L2,B2] = Qcoeff([B0,A0],N1);
TITLE2 = sprintf(’%i-bit (1+%i+%i) Precision’,N1+1,L2,B2);
Bhat2 = BAhat2(:,1:3); Ahat2 = BAhat2(:,4:6);
[bhat2,ahat2] = cas2dir(b0,Bhat2,Ahat2);
subplot(1,2,2); [HZhat2,HPhat2,Hlhat2] = zplane(bhat2,ahat2);
set(HZhat2,’color’,’r’,’linewidth’,1); set(HPhat2,’color’,’r’,’linewidth’,1);
set(Hlhat2,’color’,’w’);title(TITLE2,’fontsize’,10,’fontweight’,’bold’);
axis([-1.1,1.1,-1.1,1.1]);
The results are shown in Figure 9.9. We observe that not only for 16-bit representation but also for 11-bit representation, the resulting filter is essentially
same as the original one and is stable. Clearly, the cascade-form structure has
better finite word-length properties than the direct-form structure.
Quantization of Filter Coefficients
415
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
11–bit (1+1+9) Precision
1
1
0.5
0.5
Imaginary Part
Imaginary Part
16–bit (1+1+14) Precision
10
0
−0.5
FIGURE 9.9
EFFECTS ON
FREQUENCY
RESPONSE
−0.5
−1
−1
−1
10
0
−0.5
0
0.5
Real Part
−1
1
−0.5
0
0.5
Real Part
1
Pole-zero plots for cascade-form structure in Example 9.16
The frequency response of the IIR filter in (9.21) is given by
M
k=0 bk
H(eω ) =
1+
N
k=1
e−ωk
ak e−ωk
(9.49)
When the coefficients {ak } and {bk } are quantized to {âk } and {b̂k },
respectively, the new frequency response is given by
M
k=0 b̂k
ω
Ĥ(e ) =
1+
N
k=1
e−ωk
âk e−ωk
(9.50)
One can perform analysis similar to that for the movement of poles to
obtain maximum change in the magnitude or phase responses due to
changes in filter coefficients. However, such an analysis is very complicated
and may not add any new insight. Hence we will study these effects using
MATLAB. We provide the following two examples.
EXAMPLE 9.17
Solution
416
Compute and plot magnitude responses of filter structures given for the filter
in Example 9.16.
The filter is a bandpass filter with 10 tightly clustered poles implemented using
the direct and the cascade forms. For the direct-form structure, we compute the
magnitude response for infinite precision as well as for 16-bit quantization. For
the cascade-form structure, we use 16-bit and 11-bit representations.
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
r = 0.9; theta = (pi/180)*[-55:5:-35,35:5:55]’;
p = r*exp(j*theta); a = poly(p); b = 1;
w = [0:500]*pi/500; H = freqz(b*1e-4,a,w);
magH = abs(H); magHdb = 20*log10(magH);
% Direct form: quantized coefficients
N = 15; [ahat,L,B] = Qcoeff(a,N);
TITLE = sprintf(’%i-bit (1+%i+%i) Precision (DF)’,N+1,L,B);
Hhat = freqz(b*1e-4,ahat,w); magHhat = abs(Hhat);
% Cascade form: quantized coefficients: Same N
[b0,B0,A0] = dir2cas(b,a);
[BAhat1,L1,B1] = Qcoeff([B0,A0],N);
TITLE1 = sprintf(’%i-bit (1+%i+%i) Precision (CF)’,N+1,L1,B1);
Bhat1 = BAhat1(:,1:3); Ahat1 = BAhat1(:,4:6);
[bhat1,ahat1] = cas2dir(b0,Bhat1,Ahat1);
Hhat1 = freqz(b*1e-4,ahat1,w); magHhat1 = abs(Hhat1);
% Cascade form: quantized coefficients: Same B (N=L1+B)
N1 = L1+B; [BAhat2,L2,B2] = Qcoeff([B0,A0],N1);
TITLE2 = sprintf(’%i-bit (1+%i+%i) Precision (CF)’,N1+1,L2,B2);
Bhat2 = BAhat2(:,1:3); Ahat2 = BAhat2(:,4:6);
[bhat2,ahat2] = cas2dir(b0,Bhat2,Ahat2);
Hhat2 = freqz(b*1e-4,ahat2,w); magHhat2 = abs(Hhat2);
% Comparison of Magnitude Plots
Hf_1 = figure(’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
subplot(2,2,1); plot(w/pi,magH,’g’,’linewidth’,2); axis([0,1,0,0.7]);
%xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Magnitude Response’,’fontsize’,10);
title(’Infinite Precision (DF)’,’fontsize’,10,’fontweight’,’bold’);
subplot(2,2,2); plot(w/pi,magHhat,’r’,’linewidth’,2); axis([0,1,0,0.7]);
%xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Magnitude Response’,’fontsize’,10);
title(TITLE,’fontsize’,10,’fontweight’,’bold’);
subplot(2,2,3); plot(w/pi,magHhat1,’r’,’linewidth’,2); axis([0,1,0,0.7]);
xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Magnitude Response’,’fontsize’,10);
title(TITLE1,’fontsize’,10,’fontweight’,’bold’);
subplot(2,2,4); plot(w/pi,magHhat2,’r’,’linewidth’,2); axis([0,1,0,0.7]);
xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Magnitude Response’,’fontsize’,10);
title(TITLE2,’fontsize’,10,’fontweight’,’bold’);
The plots are shown in Figure 9.10. The top row shows plots for the direct
form, and the bottom row shows those for the cascade form. As expected, the
magnitude plot of the direct form is severely distorted for 16-bit representation,
while those for the cascade form are preserved even for 11-bit word length. Quantization of Filter Coefficients
417
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
16–bit (1+6+9) Precision (DF)
0.6
Magnitude Response
Magnitude Response
Infinite Precision (DF)
0.5
0.4
0.3
0.2
0.1
0
0
0.2
0.4
0.6
0.8
0.6
0.5
0.4
0.3
0.2
0.1
0
1
0
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.2
0.4
0.6
0.8
Digital Frequency in
π units
FIGURE 9.10
0.4
0.6
0.8
1
11–bit (1+1+9) Precision (CF)
Magnitude Response
Magnitude Response
16–bit (1+1+14) Precision (CF)
0.2
1
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.6
0.8
Digital Frequency in
0.2
0.4
π units
1
Magnitude plots for direct- and cascade-form structures in Exam-
ple 9.17
EXAMPLE 9.18
Design a bandpass elliptic filter that has the following specification:
• passband between 0.35π and 0.65π,
• the lower stopband edge of 0.25π and the upper stopband edge of 0, 75π, and
• the passband ripple of 1 db and the stopband attenuation of 50 db.
Represent the resulting filter coefficients using 16-bit and 8-bit word lengths.
Plot the filter log-magnitude responses and pole-zero locations for both the
infinite and finite word-length coefficients.
Solution
Unlike the previous example, some of the filter coefficient values (specifically
those of the auto-regressive part) are greater than one and hence require bits
for the integer part. This assignment is done for all coefficients since in practice,
the same bit-pattern is used for the filter representation. These and other steps
are given in the following MATLAB script.
% Design a bandpass elliptic filter
wp = [0.35,0.65]; ws = [0.25,0.75]; Rp = 1; As = 50;
[N, wn] = ellipord(wp, ws, Rp, As);
[b,a] = ellip(N,Rp,As,wn);
w = [0:500]*pi/500; H = freqz(b,a,w); magH = abs(H);
418
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
magHdb = 20*log10(magH);
% 16-bit word-length quantization
N1 = 15; [bahat,L1,B1] = QCoeff([b;a],N1);
TITLE1 = sprintf(’%i-bits (1+%i+%i)’,N1+1,L1,B1);
bhat1 = bahat(1,:); ahat1 = bahat(2,:);
Hhat1 = freqz(bhat1,ahat1,w); magHhat1 = abs(Hhat1);
magHhat1db = 20*log10(magHhat1); zhat1 = roots(bhat1);
% 8-bit word-length quantization
N2 = 7; [bahat,L2,B2] = QCoeff([b;a],N2);
TITLE2 = sprintf(’%i-bits (1+%i+%i)’,N2+1,L2,B2);
bhat2 = bahat(1,:); ahat2 = bahat(2,:);
Hhat2 = freqz(bhat2,ahat2,w); magHhat2 = abs(Hhat2);
magHhat2db = 20*log10(magHhat2); zhat2 = roots(bhat2);
% Plots
Hf_1 = figure(’paperunits’,’inches’,’paperposition’,[0,0,6,5]);
% Comparison of Log-Magnitude Responses: 16 bits
subplot(2,2,1); plot(w/pi,magHdb,’g’,’linewidth’,1.5); axis([0,1,-80,5]);
hold on; plot(w/pi,magHhat1db,’r’,’linewidth’,1); hold off;
xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Decibels’,’fontsize’,10);
title([’Log-Mag plot: ’,TITLE1],’fontsize’,10,’fontweight’,’bold’);
% Comparison of Pole-Zero Plots: 16 bits
subplot(2,2,3); [HZ,HP,Hl] = zplane([b],[a]); axis([-2,2,-2,2]); hold on;
set(HZ,’color’,’g’,’linewidth’,1,’markersize’,4);
set(HP,’color’,’g’,’linewidth’,1,’markersize’,4);
plot(real(zhat1),imag(zhat1),’r+’,’linewidth’,1);
title([’PZ Plot: ’,TITLE1],’fontsize’,10,’fontweight’,’bold’);
hold off;
% Comparison of Log-Magnitude Responses: 8 bits
subplot(2,2,2); plot(w/pi,magHdb,’g’,’linewidth’,1.5); axis([0,1,-80,5]);
hold on; plot(w/pi,magHhat2db,’r’,’linewidth’,1); hold off;
xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Decibels’,’fontsize’,10);
title([’Log-Mag plot: ’,TITLE2],’fontsize’,10,’fontweight’,’bold’);
% Comparison of Pole-Zero Plots: 8 bits
subplot(2,2,4); [HZ,HP,Hl] = zplane([b],[a]); axis([-2,2,-2,2]); hold on;
set(HZ,’color’,’g’,’linewidth’,1,’markersize’,4);
set(HP,’color’,’g’,’linewidth’,1,’markersize’,4);
plot(real(zhat2),imag(zhat2),’r+’,’linewidth’,1);
title([’PZ Plot: ’,TITLE2],’fontsize’,10,’fontweight’,’bold’);
hold off;
Quantization of Filter Coefficients
419
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Log-Mag Plot: 8-bits (1+2+13)
0
0
−20
−20
Decibels
Decibels
Log-Mag Plot: 16-bits (1+2+13)
−40
−60
−80
−60
True
16-bit
0
−40
0.2
0.4
0.6
0.8
Digital Frequency in π units
1
−80
True
8-bit
0.2
0.4
0.6
0.8
Digital Frequency in π units
0
PZ Plot: 8-bits (1+2+5)
PZ Plot: 16-bits (1+2+13)
1
0.5
Imaginary Part
1
Imaginary Part
1
16-bit zero
16-bit pole
0
True zero
True pole
−0.5
0.5
8-bit zero
8-bit pole
0
True zero
True pole
−0.5
−1
−1
−1
FIGURE 9.11
0
0.5
−0.5
Real Part
−1
1
0
0.5
−0.5
Real Part
1
Plots for the IIR filter in Example 9.18
The log-magnitude responses and zero-pole locations of the resulting filters are
plotted in Figure 9.11 along with those of the original filter. When 16 bits are
used, the resulting filter is virtually indistinguishable from the original one.
However, when 8 bits are used, the filter behavior is severely distorted. The
filter is still stable, but it does not satisfy the design specifications.
FIR FILTERS
A similar analysis can be done for FIR filters. Let the impulse response
of an FIR filter be h(n) with system response
H(z) =
M
−1
h(n)z −1
(9.51)
∆h(n)z −1
(9.52)
n=0
Then,
∆H(z) =
M
−1
n=0
420
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where ∆H(z) is the change due to change in the impulse response h(n).
Hence
∆H (e ω ) =
M
−1
∆h(n) e−ωn
or
|∆H(e ω )| ≤
n=0
M
−1
|∆h(n)|
(9.53)
n=0
Now, if each coefficient is quantized to B fraction bits (i.e., total register
length is B + 1), then,
|∆h(n)| ≤
1 −B
2
2
Therefore,
|∆H(eω )| ≤
1 −B
M −B
2 M=
2
2
2
(9.54)
Thus, the change in frequency response depends not only on the number
of bits used but also on the length M of the filter. For large M and small b,
this difference can be significant and can destroy the equiripple behavior
of the filter, as we see in the following example.
EXAMPLE 9.19
Consider an order-30 equiripple lowpass FIR filter designed using the remez
function. The passband edge is ωp = 0.3π, and the stopband edge is ωs = 0.5π.
The resulting stopband attenuation is about 55 dB. The coefficients are quantized to 16 bits (15 fractional bits plus one sign bit) and to 8 bits (7 fractional
bits plus one sign bit). These steps are shown in the following MATLAB script.
b = remez(30,[0,0.3,0.5,1],[1,1,0,0]);
w = [0:500]*pi/500; H = freqz(b,1,w); magH = abs(H);
magHdb = 20*log10(magH);
N1 = 15; [bhat1,L1,B1] = Qcoeff(b,N1);
TITLE1 = sprintf(’%i-bits (1+%i+%i)’,N1+1,L1,B1);
Hhat1 = freqz(bhat1,1,w); magHhat1 = abs(Hhat1);
magHhat1db = 20*log10(magHhat1);
zhat1 = roots(bhat1);
N2 = 7; [bhat2,L2,B2] = Qcoeff(b,N2);
TITLE2 = sprintf(’%i-bits (1+%i+%i)’,N2+1,L2,B2);
Hhat2 = freqz(bhat2,1,w); magHhat2 = abs(Hhat2);
magHhat2db = 20*log10(magHhat2);
zhat2 = roots(bhat2);
% Plots
Hf_1 = figure(’paperunits’,’inches’,’paperposition’,[0,0,6,5]);
Quantization of Filter Coefficients
421
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Comparison of Log-Magnitude Responses: 16 bits
subplot(2,2,1); plot(w/pi,magHdb,’g’,’linewidth’,1.5); axis([0,1,-80,5]);
hold on; plot(w/pi,magHhat1db,’r’,’linewidth’,1); hold off;
xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Decibels’,’fontsize’,10);
title([’Log-Mag plot: ’,TITLE1],’fontsize’,10,’fontweight’,’bold’);
% Comparison of Pole-Zero Plots: 16 bits
subplot(2,2,3); [HZ,HP,Hl] = zplane([b],[1]); axis([-2,2,-2,2]); hold on;
set(HZ,’color’,’g’,’linewidth’,1,’markersize’,4);
set(HP,’color’,’g’,’linewidth’,1,’markersize’,4);
plot(real(zhat1),imag(zhat1),’r+’,’linewidth’,1);
title([’PZ Plot: ’,TITLE1],’fontsize’,10,’fontweight’,’bold’);
hold off;
% Comparison of Log-Magnitude Responses: 8 bits
subplot(2,2,2); plot(w/pi,magHdb,’g’,’linewidth’,1.5); axis([0,1,-80,5]);
hold on; plot(w/pi,magHhat2db,’r’,’linewidth’,1); hold off;
xlabel(’Digital Frequency in \pi units’,’fontsize’,10);
ylabel(’Decibels’,’fontsize’,10);
title([’Log-Mag plot: ’,TITLE2],’fontsize’,10,’fontweight’,’bold’);
% Comparison of Pole-Zero Plots: 8 bits
subplot(2,2,4); [HZ,HP,Hl] = zplane([b],[1]); axis([-2,2,-2,2]); hold on;
set(HZ,’color’,’g’,’linewidth’,1,’markersize’,4);
set(HP,’color’,’g’,’linewidth’,1,’markersize’,4);
plot(real(zhat2),imag(zhat2),’r+’,’linewidth’,1);
title([’PZ Plot: ’,TITLE2],’fontsize’,10,’fontweight’,’bold’);
hold off;
The log-magnitude responses and zero-pole locations of the resulting filters are
computed and plotted in Figure 9.12 along with those of the original filter.
When 16 bits are used, the resulting filter is virtually indistinguishable from
the original one. However, when 8 bits are used, the filter behavior is severely
distorted and the filter does not satisfy the design specifications.
ANALYSIS OF A/D QUANTIZATION NOISE
From the quantizer characteristics obtained in the previous section, it
is obvious that the quantized value Q[x] is a nonlinear operation on the
value x. Hence the exact analysis of the finite word-length effects in digital
filters is generally difficult and one has to consider less ideal analysis
techniques that work well in practice.
One such technique is the statistical modeling technique. It converts
the nonlinear analysis problem into a linear one and allows us to examine
422
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Log-Mag Plot: 8-bits (1+0+7)
Log-Mag Plot: 16-bits (1+0+15)
0
True
16-bit
−20
−20
−40
−40
−60
−60
−80
True
8-bit
Decibels
Decibels
0
0
0.2
0.4
0.6
0.8
Digital Frequency in π units
1
−80
0
0.2
0.4
0.6
0.8
Digital Frequency in π units
PZ Plot: 8-bits (1+0+7)
PZ Plot: 16-bits (1+0+15)
2
2
8-bit zero
True zero
1
Imaginary Part
Imaginary Part
16-bit zero
True zero
30
0
−1
−2
−2
FIGURE 9.12
1
−1
1
0
Real Part
2
1
30
0
−1
−2
−2
−1
1
0
Real Part
2
Plots for the FIR filter in Example 9.19
output-error characteristics. In this technique, we assume that the quantized value Q[x] is a sum of the exact value x and the quantization error e,
which is assumed to be a random variable. When x(n) is applied as an
input sequence to the quantizer, the error e(n) is assumed to be a random
sequence. We then develop a statistical model for this random sequence
to analyze its effects through a digital filter.
For the purpose of analysis, we assume that the quantizer employs
fixed-point two’s-complement number format representation. Using the
results given previously, we can extend this analysis to other formats as
well.
STATISTICAL
MODEL
We model the quantizer block on the input as a signal-plus-noise
operation—that is, from (9.19)
Q[x(n)] = x(n) + e(n)
(9.55)
where e(n) is a random sequence that describes the quantization error sequence and is termed the quantization noise. This is shown in Figure 9.13.
Analysis of A/D Quantization Noise
423
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x(n)
QUANTIZER
Q[x (n)] ⇒ x(n)
x(n) + e(n)
e(n)
FIGURE 9.13
Statistical model of a quantizer
Model assumptions For the model in (9.55) to be mathematically
convenient and hence practically useful, we have to assume reasonable
statistical properties for the sequences involved. That these assumptions
are practically reasonable can be ascertained using simple MATLAB examples, as we shall see. We assume that the error sequence, e(n) has the
following characteristics4 :
1. The sequence e(n) is a sample sequence from a stationary random
process {e(n},
2. this random process {e(n)} is uncorrelated with sequence x(n),
3. the process {e(n)} is an independent process (i.e., the samples are
independent of each other) and
4. the probability density function (pdf), fE (e), of sample e(n) for each
n is uniformly distributed over the interval of width ∆ = 2−B , which
is the quantizer resolution.
These assumptions are reasonable in practice if the sequence x(n) is sufficiently random to traverse many quantization steps in going from time
n to n + 1.
ANALYSIS
USING
MATLAB
To investigate the statistical properties of the error samples, we will have
to generate a large number of these samples and plot their distribution
using a histogram (or a probability bar graph). Furthermore, we have to
design the sequence x(n) so that its samples do not repeat; otherwise, the
error samples will also repeat, which will result in an inaccurate analysis. This can be guaranteed either by choosing a well-defined aperiodic
sequence or a random sequence.
We will quantize x(n) using B-bit rounding operation. A similar implementation can be developed for the truncation operation. Since all
three error characteristics are exactly the same under the rounding operation, we will choose the sign-magnitude format for ease in implementation. After quantization, the resulting error samples e(n) uniformly are
4 We assume that the reader is familiar with the topic of random variables and processes
and the terminology associated with it.
424
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1
−12
FIGURE 9.14
f1(n)
2
12
e1(n)
−12
f2(n)
12
e 2(n)
Probability distributions of the normalized errors e1 (n) and e2 (n)
∆
distributed over the [− ∆
2 , 2 ] interval. Let e1 (n) be the normalized error
given by
e1 (n) =
e(n)
= e(n) 2B
∆
⇒
e1 (n) ∈ [−1/2, 1/2]
(9.56)
Then e1 (n) is uniform over the interval [− 12 , + 12 ], as shown in Figure 9.14(a). Thus the histogram interval will be uniform across all B-bit
values, which will make its computation and plotting easier. This interval
will be divided into 128 bins for the purpose of plotting.
To determine the sample independence we consider the histogram of
the sequence
e2 (n) =
e1 (n) + e1 (n − 1)
2
(9.57)
which is the average of two consecutive normalized error samples. If
e1 (n) is uniformly distributed between [−1/2, 1/2], then, for sample
independence, e2 (n) must have a triangle-shaped distribution between
[−1/2, 1/2], as shown in Figure 9.14(b). We will again generate a 128-bin
histogram for e2 (n). These steps are implemented in the following
MATLAB function.
function [H1,H2,Q, estat] = StatModelR(xn,B,N);
% Statistical Model (Rounding) for A/D Quantization error and its Distribution
% ------------- ------------------------------------------------------------% [H1,H2,Q] = StatModelR(xn,B,N);
%
OUT: H1 = Normalized histogram of e1
%
H2 = Normalized histogram of e2
%
Q = Normalized histogram bins
%
estat = row vector: [[e1avg,e1std,e2avg,e2std]
%
IN: D = decimals to quantize
%
N = number of samples of x(n)
%
xn = samples of the sequence
Analysis of A/D Quantization Noise
425
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Plot variables
bM = 7; DbM = 2^bM;
M = round((DbM)/2);
bins = [-M+0.5:1:M-0.5];
Q = bins/(DbM);
% Quantization error analysis
xq = (round(xn*(2^B)))/(2^B);
e1 = xq-xn; clear xn xq;
e2 = 0.5*(e1(1:N-1)+e1(2:N));
e1avg = mean(e1); e1std = std(e1);
e2avg = mean(e2); e2std = std(e2);
estat = [e1avg,e1std,e2avg,e2std];
% Probability distribution of e1
e1 = floor(e1*(2^(B+bM)));
e1 = sort([e1,-M-1:1:M]);
H1 = diff(find(diff(e1)))-1; clear e1;
if length(H1) == DbM+1
H1(DbM) = H1(DbM)+H1(DbM+1);
H1 = H1(1:DbM);
end
H1 = H1/N;
% Probability distribution of e2
e2 = floor(e2*(2^(B+bM)));
e2 = sort([e2,-M-1:1:M]);
H2 = diff(find(diff(e2)))-1; clear e2;
if length(H2) == DbM+1
H2(DbM) = H2(DbM)+H2(DbM+1);
H2 = H2(1:DbM);
end
H2 = H2/N;
%
%
%
%
bin parameter
Half number of bins
Bin values from -M to M
Normalized bins
%
%
%
%
%
Quantized to B bits
Quantization error
Average of two adj errors
Mean & std dev of the error e1
Mean & std dev of the error e2
% Normalized e1 (int between -M & M)
%
% Error histogram
% Normalized histogram
% Normalized e2 (int between -M & M)
%
% Error histogram
% Normalized histogram
To validate the model assumptions we consider the following two examples. In the first example an aperiodic sinusoidal sequence is quantized
to B bits, and in the second example a random sequence is quantized to
B bits. The resulting quantization errors are analyzed for their distribution properties and for their sample independence for various values of
B. Through these examples we hope to learn how small error e must be
(or equivalently, how large B must be) for the above assumptions to be
valid.
426
EXAMPLE 9.20
Let x(n) = 13 {sin(n/11) + sin(n/31) + cos(n/67)}. This sequence is not periodic, and hence its samples never repeat using infinite-precision representation.
However, since the sequence is of sinusoidal nature, its continuous envelope
is periodic and the samples are continuously distributed over the fundamental period of this envelope. Determine the error distributions for B = 2 and
6 bits.
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Distribution of e1
4128
3128
2128
SAMPLE SIZE N = 500000
ROUNDED T0 B = 2 BITS
MEAN = 3.4239e–005
1128
0
−0.5
4128
Distribution of e2
MIN PROB BAR HEIGHT = 0.007446
MAX PROB BAR HEIGHT = 0.00828
SIGMA = 0.072073
3128
2128
−0.375
−0.25
−0.125
0
0.125
Normalized error e1
SAMPLE SIZE N = 500000
ROUNDED T0 B = 2 BITS
MEAN = 3.4396e–005
0.25
0.375
0.5
MIN PROB BAR HEIGHT = 0.000334
MAX PROB BAR HEIGHT = 0.015212
SIGMA = 0.063851
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
FIGURE 9.15 A/D quantization error distribution for the sinusoidal signal in
Example 9.20, B = 2 bits
Solution
To minimize statistical variations, the sample size must be large. We choose
500,000 samples. The following MATLAB script computes the distributions for
B = 2 bits.
clear; close all;
% Example parameters
B = 2; N = 500000; n = [1:N];
xn = (1/3)*(sin(n/11)+sin(n/31)+cos(n/67)); clear n;
% Quantization error analysis
[H1,H2,Q, estat]] = StatModelR(xn,B,N);
% Compute histograms
H1max = max(H1); H1min = min(H1); % Max and Min of H1
H2max = max(H2); H2min = min(H2); % Max and Min of H2
The plots of the resulting histogram are shown in Figure 9.15. Clearly, even
though the error samples appear to be uniformly distributed, the samples
are not independent. The corresponding plots for B = 6 bits are shown in
Figure 9.16, from which we observe that the quantization error sequence appears to satisfy the model assumptions for B ≥ 6 bits.
EXAMPLE 9.21
Let x(n) be an independent and identically distributed random sequence whose
samples are uniformly distributed over the [−1, 1] interval. Determine the error
distributions for B = 2 and 6 bits.
Analysis of A/D Quantization Noise
427
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Distribution of e1
4128
3128
2128
SAMPLE SIZE N = 500000
ROUNDED T0 B = 6 BITS
MEAN = −4.1044e–006
1128
0
−0.5
4128
Distribution of e2
MIN PROB BAR HEIGHT = 0.007478
MAX PROB BAR HEIGHT = 0.00814
SIGMA = 0.0045076
3128
2128
−0.375
−0.25
−0.125
0
0.125
Normalized error e1
SAMPLE SIZE N = 500000
ROUNDED T0 B = 6 BITS
MEAN = −4.1044e–006
0.25
0.375
0.5
MIN PROB BAR HEIGHT = 0.000112
MAX PROB BAR HEIGHT = 0.01572
SIGMA = 0.0031818
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
FIGURE 9.16 Quantization error distribution for the sinusoidal signal in
Example 9.20, B = 6 bits
Solution
We again choose 500,000 samples to minimize any statistical variations. The
following MATLAB fragment computes the distributions for B = 2 bits.
clear; close all;
% Example parameters
B = 2; N = 500000; xn = (2*rand(1,N)-1);
% Quantization error analysis
[H1,H2,Q, estat]] = StatModelR(xn,B,N);
% Compute histograms
H1max = max(H1); H1min = min(H1); % Max and Min of H1
H2max = max(H2); H2min = min(H2); % Max and Min of H2
The plots of the resulting histogram are shown in Figure 9.17. The corresponding plots for B = 6 bits are shown in Figure 9.18. From these plots we observe
that even for B = 2 bits the quantization error samples are independent and
uniformly distributed.
Since practical signals processed using a DSP chip are typically random in nature (or can be modeled as such), we conclude from these two
examples that the statistical model, with its stated assumptions, is a very
good model.
428
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Distribution of e1
4128
SAMPLE SIZE N = 500000
ROUNDED T0 B = 2 BITS
MEAN = –8.7384e–005
3128
2128
1128
0
−0.5
−0.375
4128
Distribution of e2
MIN PROB BAR HEIGHT = 0.007522
MAX PROB BAR HEIGHT = 0.008134
SIGMA = 0.072111
−0.25
−0.125
0
0.125
Normalized error e1
SAMPLE SIZE N = 500000
ROUNDED T0 B = 2 BITS
MEAN = –8.7435e–005
3128
0.25
0.375
0.5
MIN PROB BAR HEIGHT = 0.000116
MAX PROB BAR HEIGHT = 0.015504
SIGMA = 0.050983
2128
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
A/D quantization error distribution for the random signal in Example 9.21, B = 2 bits
FIGURE 9.17
Distribution of e1
4128
3128
2128
SAMPLE SIZE N = 500000
ROUNDED T0 B = 6 BITS
MEAN = –7.3429e–006
1128
0
−0.5
4128
Distribution of e2
MIN PROB BAR HEIGHT = 0.00745
MAX PROB BAR HEIGHT = 0.008136
SIGMA = 0.0045103
3128
2128
−0.375
−0.25
−0.125
0
0.125
Normalized error e1
SAMPLE SIZE N = 500000
ROUNDED T0 B = 6 BITS
MEAN = –7.3519e–006
0.25
0.375
0.5
MIN PROB BAR HEIGHT = 0.000122
MAX PROB BAR HEIGHT = 0.015664
SIGMA = 0.003197
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
FIGURE 9.18 Quantization error distribution for the random signal in Example 9.21, B = 6 bits
STATISTICS OF
A/D QUANTIZATION NOISE
We now develop a second-order statistical description of the error sequence
e(n) for both the truncation and rounding operations.
Analysis of A/D Quantization Noise
429
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
fT (e)
1∆
1∆
e
−∆2
−∆
−∆2
0
(a)
FIGURE 9.19
TRUNCATION
fR (e)
∆2
0
e
(b)
Probability density functions: (a) Truncation and (b) Rounding
From (9.30), the pdf fET (e) of eT (n) is uniform over [−∆, 0], as shown in
Figure 9.19(a). Then the average of eT (n) is given by
meT = E[eT (n)] = −∆/2
and the variance is
2
σe2T = E (eT (n) − meT ) =
0
−∆
(9.58)
∆/2
2
(e − ∆/2) fET (e) de =
e2
−∆/2
∆2
12
Using ∆ = 2−B , we obtain
de
(9.59)
=
σe2T =
1
∆
2−2B
12
or
2−B
σe T = √
2 3
(9.60)
Rounding From (9.32), the pdf fER (e) of eR (n) is uniform over
[−∆/2, ∆/2], as shown in Figure 9.19(b). Then the average of eR (n)
is given by
(9.61)
meR = [EeR ] = 0
and the variance is
∆/2
∆/2
1
2
2 2
de
e fER (e) de =
e2
σeR = E (eR (n) − meR ) =
∆
−∆/2
−∆/2
∆2
12
Using (9.18), we obtain
(9.62)
=
σe2R =
2−2B
12
or
2−B
σe R = √
2 3
Since the samples of the sequence eR (n) are assumed to be
of each other, the variance of [eR (n) + eR (n − 1)]/2 is given
eR (n) + eR (n − 1)
1 2−2B
2−2B
2−2B
=
+
=
=
var
2
4
12
12
24
√
or the standard deviation is σeR / 2.
430
Chapter 9
(9.63)
independent
by
1 2
σ
(9.64)
2 eR
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
From the model assumptions and (9.60) or (9.63), the covariance of
the error sequence (which is an independent sequence) is given by
E[e(m)e(n)] = Ce (m − n) = Ce () =
2−2B
δ ()
12
(9.65)
where = m − n is called the lag variable. Such an error sequence is also
known as a white noise sequence.
MATLAB
IMPLEMENTATION
In MATLAB, the sample mean and standard deviation are computed
using the functions mean and std, respectively. The last argument of the
function StatModelR is a vector containing sample means and standard
deviations of unnormalized errors e(n) and [e(n) + e(n − 1)]/2. Thus,
these values can be compared with the theoretical values obtained from
the statistical model.
The plots in Example 9.20 also indicate the sample means and standard deviations of the errors e(n) and [e(n) + e(n − 1)]/2. For B = 2, these computed
values are shown in Figure 9.15. Since e(n) is uniformly distributed over the
interval [−2−3 , 2−3 ], its mean value is 0, and so is the mean of [e(n)+e(n−1)]/2.
The computed values are 3.4239 × 10−5 and 3.4396 × 10−5 , respectively, which
agree fairly well with the model. The standard deviation of e(n), from (9.63), is
0.072169, while that from the top plot in Figure 9.15 is 0.072073, which again
agrees closely with the model. The standard deviation of the average of the
two consecutive samples, from (9.64), is 0.051031, and from the bottom plot in
Figure 9.15 it is 0.063851, which clearly does not agree with the model. Hence
the samples of e(n) for B = 2 are not independent. This was confirmed by the
bottom plot in Figure 9.15.
Similarly, for B = 6 computed statistical values are shown in Figure 9.16.
The computed values of the two means are −4.1044 × 10−6 , which agree very
well with the model. The standard deviation of e(n), from (9.63), is 0.0045105,
while that from the top plot in Figure 9.16 is 0.0045076, which again agrees
closely with the model. The standard deviation of the average of the two
consecutive samples, from (9.64), is 0.0031894, while from the bottom plot in
Figure 9.16 it is 0.00318181, which clearly agrees with the model. Hence the
samples of e(n) for B = 6 are independent. This was also confirmed by the
bottom plot in Figure 9.16.
EXAMPLE 9.22
Similar calculations can be carried out for the signal in Example 9.21.
The details are left to the reader.
A/D QUANTIZATION NOISE
THROUGH
DIGITAL
FILTERS
Let a digital filter be described by the impulse response, h(n), or the frequency response, H(eω ). When a quantized input, Q[x(n)] = x(n)+e(n),
is applied to this system, we can determine the effects of the error sequence
e(n) on the filter output as it propagates through the filter, assuming
infinite-precision arithmetic implementation in the filter. We are generally
Analysis of A/D Quantization Noise
431
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ˆ
x(n)
= x(n) + e(n)
FIGURE 9.20
ˆ
y(n)
= y(n) + q(n)
h(n), H(e jw )
Noise through digital filter
interested in the mean and variance of this output-noise sequence, which
we can obtain using linear system theory concepts. Details of these results
can be found in many introductory texts on random processes, including
[26].
Referring to Figure 9.20, let the output of the filter be ŷ(n). Using
LTI properties and the statistical independence between x(n) and e(n),
the output ŷ(n) can be expressed as the sum of two components. Let y(n)
be the (true) output due to x(n) and q(n) the response due to e(n). Then
we can show that q(n) is also a random sequence with mean
mq = E[q(n)] = me
∞
h(n) = me H(e0 )
(9.66)
−∞
where the term H(e0 ) is termed the DC gain of the filter. For truncation,
meT = −∆/2, which gives
mqT = −
∆
H(e0 )
2
(9.67)
For rounding, meR = 0 or
(9.68)
mqR = 0
We can also show that the variance of q(n), for both the truncation or
rounding, is given by
σq2 = σe2
∞
π
2
2
|h(n)| = σe2
−π
−∞
|H(eω )| dω
(9.69)
The variance gain from the input to the output (also known as the normalized output variance) is the ratio
∞
σq2
2
=
|h(n)| =
σe2
−∞
π
2
−π
|H(eω )| dω
(9.70)
For a real and stable filter, using the substitution z = eω , the integral in
(9.70) can be further expressed as a complex contour integral
π
2
−π
432
|H(eω )| dω =
1
2π
H(z)H(z −1 )z −1 dz
(9.71)
UC
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where UC is the unit circle and can be computed using residues (or the
inverse Z-transform) as
π
2
|H(eω )| dω =
[Residues of H(z)H(z −1 )z −1 inside UC] (9.72a)
−π
(9.72b)
= Z −1 H(z)H(z −1 ) n=0
MATLAB
IMPLEMENTATION
Computation of the variance-gain for the A/D quantization noise can be
carried out in MATLAB using (9.70) and (9.72). For FIR filters, we can
perform exact calculations using the time-domain expression in (9.70). In
the case of IIR filters, exact calculations can only be done using (9.72)
in special cases, as we shall see below (fortunately, this works for most
practical filters). The approximate computations can always be done using
the time-domain expression.
−1
. Then using
Let the FIR filter be given by the coefficients {bk }M
0
the time-domain expression in (9.70), the variance-gain is given by
M
−1
σq2
2
=
|bk |
σe2
(9.73)
k=0
Let an IIR filter be given by the system function
N −1
−
=0 b z
H(z) =
N −1
1 + k=1 ak z −k
(9.74)
with impulse response h(n). If we assume that the filter is real, causal, and
stable and has only simple poles, then using the partial fraction expansion,
we can write
N
−1
Rk
H(z) = R0 +
(9.75)
z − pk
k=1
where R0 is the constant term and Rk ’s are the residues at the pole
locations pk . This expansion can be computed using the residue function.
Note that both poles and the corresponding residues are either real-valued
or occur in complex-conjugate pairs. Then using (9.72a), we can show that
(see [17] and also Problem P9.23)
−1
N
−1 N
σq2
Rk R ∗
2
=
R
+
0
2
σe
1 − p k p∗
k=1
(9.76)
=1
The variance-gain expression in (9.76) is applicable for most practical
filters since rarely do they have multiple poles. The approximate value of
the variance-gain for IIR filters is given by
K−1
σq2
2
|h(n)| ,
2
σe
K1
(9.77)
k=0
Analysis of A/D Quantization Noise
433
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where K is chosen so that the impulse response values (magnitudewise)
are almost zero beyond K samples. The following MATLAB function,
VarGain, computes variance-gain using (9.73) or (9.76).
function Gv = VarGain(b,a)
% Computation of variance-gain for the output noise process
% of digital filter described by b(z)/a(z)
% Gv = VarGain(b,a)
a0 = a(1); a = a/a0; b = b/a0; M = length(b); N = length(a);
if N == 1
% FIR Filter
Gv = sum(b.*b);
return
else
% IIR Filter
[R,p,P] = residue(b,a);
if length(P) > 1
error(’*** Variance Gain Not computable ***’);
elseif length(P) == 1
Gv = P*P;
else
Gv = 0;
end
Rnum = R*R’; pden = 1-p*p’;
H = Rnum./pden; Gv = Gv + real(sum(H(:)));
end
It should be noted that the actual output noise variance is obtained by
multiplying the A/D quantization noise variance by the variance-gain.
EXAMPLE 9.23
Solution
Consider an eighth-order IIR filter with poles at pk = r e2πk/8 , k = 0, . . . , 7.
If r is close to 1, then the filter has four narrowband peaks. Determine the
variance-gain for this filter when r = 0.9 and r = 0.99.
The following MATLAB script illustrates calculations for r = 0.9, which implements exact as well as approximate approaches.
% Filter Parameters
N = 8; r = 0.9; b = 1; pl = r*exp(j*2*pi*[0:N-1]/N); a = real(poly(pl));
% Variance-gain (Exact)
Vg = VarGain(b,a)
Vg =
1.02896272593178
% Variance-Gain (approximate)
x = [1,zeros(1,10000)]; % Unit sample sequence
h = filter(b,a,x);
% Impulse response
VgCheck = sum(h.*h)
VgCheck =
1.02896272593178
434
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Clearly, both approaches give the same variance-gain, which for r = 0.9 is about
3% above unity. For r = 0.99 the calculations are:
% Filter Parameters
N = 8; r = 0.99; b = 1; pl = r*exp(j*2*pi*[0:N-1]/N); a = real(poly(pl));
% Variance-gain (Exact)
Vg = VarGain(b,a)
Vg =
6.73209233071894
The variance-gain is more than 673%, which means that when poles are close
to the unit circle, the filter output can be very noisy.
ROUND-OFF EFFECTS IN IIR DIGITAL FILTERS
With our insight into the quantizer operation and its simpler statistical
model, we are now ready to delve into the analysis of finite word-length
effects in both IIR and FIR digital filters. We have already studied the
effects of input signal quantization and filter coefficient quantization on
filter behavior. We will now turn our attention to the effects of arithmetic
operation quantization on filter output responses (in terms of signal-tonoise ratios). For this study we will consider both fixed-point and floatingpoint arithmetic. We first consider the effects on IIR filters since, due to
feedback paths, the results are more complicated—yet move interesting—
than those in FIR filters. The effects on FIR filters are studied in the next
section.
We will restrict ourselves to the rounding operation of the quantizer due to its superior statistical qualities (no bias or average value).
From (9.32), we know that, for the rounding operation, the quantizer
error, eR , has the same characteristics across all three number representation formats. Hence for MATLAB simulation purposes, we will consider
the sign-magnitude format because it is easy to program and simulate
for arithmetic operation. However, in practice, two’s-complement format
number representation has advantages over the others in terms of hardware implementation.
Digital filter implementation requires arithmetic operations of multiplication and addition. If two B-bit fractional numbers are multiplied,
the result is a 2B-bit fractional number that must be quantized to B bits.
Similarly, if two B-bit fractional numbers are added, the sum could be
more than one, which results in an overflow, which in itself is a nonlinear
characteristic; or the sum must be corrected using a saturation strategy,
which is also nonlinear. Thus, a finite word-length implementation of the
Round-off Effects in IIR Digital Filters
435
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
filter is a highly nonlinear filter and hence must be analyzed carefully for
any meaningful results.
In this section, we will consider two approaches to deal with errors due
to finite word-length representation. The first type of error can occur when
error samples become correlated with each other due to the nonlinearity
of the quantizer. This is called limit-cycle behavior, and it can exist only
in IIR filters. We will analyze this problem using the nonlinear quantizer
model rather than the statistical model of the quantizer. In the second
type of error we assume that more nonlinear effects in the quantizer have
been suppressed. Then, using the statistical model of the quantizer, we
develop a quantization noise model for IIR filters that is more useful in
predicting the finite word-length effects.
LIMIT CYCLES
DEFINITION 1
Digital filters are linear systems, but when quantizers are incorporated
in their implementation, they become nonlinear systems. For nonlinear
systems it is possible to have an output sequence even when there is no
input. Limit cycles is one such behavior that creates an oscillatory periodic
output that is highly undesirable.
Limit cycle
A zero-input limit cycle is a non-zero periodic output sequence produced by nonlinear elements or quantizers in the feedback loop of a digital
filter.
There are two types of limit cycles. The granular limit cycles are due
to nonlinearities in multiplication quantization and are of low amplitude.
The overflow limit cycles are a result of overflow in addition and can have
large amplitudes.
GRANULAR
LIMIT CYCLES
This type of limit cycle can easily be demonstrated with a simple rounding quantizer following a multiplication. We illustrate with the following
example.
Consider a simple first-order IIR filter given by
EXAMPLE 9.24
y(n) = α y(n − 1) + x(n);
y(−1) = 0,
n≥0
(9.78)
− 12 ;
Let α =
then this is a highpass filter, since its pole is near z = −1.
Determine the output y(n) when x(n) = 78 δ(n), assuming a 3-bit quantizer in
the multiplier.
Solution
After multiplication by α, we have to quantize the result. Let the output due
to this quantization be ŷ(n). Then the actual implementable digital filter is
1
ŷ(n) = Q − ŷ(n − 1) + x(n);
2
436
Chapter 9
ŷ(−1) = 0,
n≥0
(9.79)
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
We assume that the input in (9.78) is quantized and that there is no overflow
due to addition. Let B = 3 (that is, we have 3 fraction bits and one sign bit) and
let x(n) = 78 δ(n). Now α = − 12 is represented by 1 110 in two’s-complement
format. Hence the output sequence is obtained as:
ŷ(0)
=
x(0)
ŷ(1)
=
Q [α ŷ(0)]
=
Q −
ŷ(2)
=
Q [α ŷ(1)]
=
Q −
ŷ(3)
=
Q [α ŷ(2)]
=
Q −
ŷ(4)
=
Q [α ŷ(3)]
=
Q −
ŷ(5)
=
Q [α ŷ(4)]
=
Q −
..
.
..
.
..
.
1
7
+
2
8
1
1
−
2
2
1
1
+
2
4
1
1
−
2
8
1
1
+
2
8
=
Q −
=
Q +
=
Q −
=
Q +
=
Q −
..
.
7
16
1
4
1
8
=
+
7
8
: 0 111
=
−
1
2
: 1 100
=
+
1
4
: 0 010
=
−
1
8
: 1 111
=
+
1
8
: 0 001
=
−
1
8
: 1 111
1
16
1
16
..
.
(9.80)
Thus ŷ(n) = ± 18 for n ≥ 5. The desired output y(n) is
!
y(n) =
"
7 7
7 7
7
,− , ,− ,
,···,→ 0
8
16 32
64 128
(9.81)
Hence the error sequence is
e(n) = ŷ(n) − y(n) =
!
0, −
1 1
1 9
1
, ,− ,
,···,→ ±
16 32
64 128
8
"
(9.82)
This shows that the error e(n) slowly builds up to ± 18 . Hence the error is
asymptotically periodic with period 2.
From the above example it is clear that, in the steady state, the
system has poles on the unit circle and hence the nonlinear system has
effectively become a linear system [12]. This implies that, effectively, for
the system in (9.78)
Q [αŷ(n − 1)] =
ŷ(n − 1),
α > 0,
−ŷ(n − 1), α < 0.
(9.83)
Also due to the rounding operation, the quantization error is bounded by
±∆/2 where ∆ = 2−B is the quantization step, or
|Q [αŷ(n − 1)] − αŷ(n − 1)| ≤
Round-off Effects in IIR Digital Filters
∆
2
(9.84)
437
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1
y
1
−1
−2
2
−1
x
x
1
−1
−1
(a) Two’s-complement overflow
FIGURE 9.21
y
(b) Saturation
Overflow characteristics used in Qfix
From (9.83) and (9.84), we conclude that
|ŷ(n − 1)| ≤
∆
2(1 − |α|)
(9.85)
which is the amplitude range of limit-cycle oscillations and is called a dead
band. For the system in Example 9.24, B = 3 and α = − 12 . Hence the
dead-band range is ± 18 , which agrees with (9.85). If the output ŷ(n − 1)
gets trapped in this band when the input is zero, the filter exhibits the
granular limit cycle. From (9.83), the period of the oscillation is either
1 or 2.
Analysis using MATLAB In our previous MATLAB simulations,
we did not worry about the quantization in multiplication or addition
operations because the emphasis was on either signal quantization or on
filter coefficient quantization. The important operation that we have to
consider is the arithmetic overflow characteristics. We assume that the
represented numbers are in fractional two’s-complement format. Then in
practice, two overflow characteristics are used: a two’s-complement overflow, which is a modulo (periodic) function, and a saturation, which is a
limiting function. These characteristics are shown in Figure 9.21.
To simulate these two effects, we provide the function y = Qfix(x,B,
’Qmode’,’Omode’). This function performs a fixed-point two’s-complement format quantization using (B+1)-bit representation so that the
resulting number y is between −1 ≤ y < 1. The quantization mode,
Qmode, is either a rounding or a truncation operation. The overflow characteristic is provided in Omode. Using this function, we can study both
types of limit cycles.
function [y] = QFix(x,B,Qmode,Omode)
% Fixed-point Arithmetic using (B+1)-bit Representation
% ----------------------------------------------------%
[y] = QFix(x,B,Qmode,Omode)
%
y: Decimal equivalent of quantized x with values in [-1,1)
%
x: a real number array
%
B: Number of fractional bits
438
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Qmode: Quantizer mode
%
’round’: two’s-complement rounding characteristics
%
’trunc’: Two’s complement truncation characteristics
% Omode: Overflow mode
%
’satur’: Saturation limiter
%
’twosc’: Two’s-complement overflow
% Quantization operation
if strcmp(lower(Qmode), ’round’);
y = round(x.*(2^B));
elseif strcmp(lower(Qmode), ’trunc’);
y = floor(x.*(2^B));
else
error(’Use Qmode = "round" or "trunc"’);
end;
y = y*(2^(-B)); % (B+1)-bit representation
% Overflow operation
if strcmp(lower(Omode), ’satur’);
y = min(y,1-2^(-B)); y = max(-1,y); % Saturation
elseif strcmp(lower(Omode), ’twosc’);
y = 2*(mod(y/2-0.5,1)-0.5);
% Overflow
else error(’Use Omode = "satur" or "twosc"’);
end;
EXAMPLE 9.25
Solution
In this example simulate the results for the system given in Example 9.24 using
the Qfix function with B = 3 bits. In addition, also examine limit-cycle behavior
for the truncation operation in the multiplier and for the case when the system
is a lowpass filter with coefficient α = 0.5.
The MATLAB script is:
% Highpass filter, rounding operation in multiplier
a = -0.5; yn1 = 0; m = 0:10; y = [yn1, zeros(1,length(m))];
x = 0.875*impseq(m(1),m(1)-1,m(end));
for n = m+2
yn1 = y(n-1);
y(n) = QFix(a*yn1,3,’round’,’satur’) + x(n);
end
subplot(’position’,[0.08,0.2,0.24,0.6]);
plot([-1,20],[0,0],’w’); axis([-1,10,-1,1]); hold on;
Hs_1 = stem([-1,m],y,’filled’);set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-1:0.25:1],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’\alpha = -0.5, Rounding’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
Round-off Effects in IIR Digital Filters
439
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Lowpass filter, rounding operation in multiplier
a = 0.5; yn1 = 0; m = 0:10; y = [yn1, zeros(1,length(m))];
x = 0.875*impseq(m(1),m(1)-1,m(end));
for n = m+2
yn1 = y(n-1);
y(n) = QFix(a*yn1,3,’round’,’satur’) + x(n);
end
subplot(’position’,[0.42,0.2,0.24,0.6]);
plot([-1,20],[0,0],’w’); axis([-1,10,-1,1]); hold on;
Hs_1 = stem([-1,m],y,’filled’);set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-1:0.25:1],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’\alpha = 0.5, Rounding’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
% Highpass filter, Truncation operation in multiplier
a = -0.5; yn1 = 0; m = 0:10; y = [yn1, zeros(1,length(m))];
x = 0.875*impseq(m(1),m(1)-1,m(end));
for n = m+2
yn1 = y(n-1);
y(n) = QFix(a*yn1,3,’trunc’,’satur’) + x(n);
end
subplot(’position’,[0.76,0.2,0.24,0.6]);
plot([-1,20],[0,0],’w’); axis([-1,10,-1,1]); hold on;
Hs_1 = stem([-1,m],y,’filled’);set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-1:0.25:1],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’\alpha = -0.5, Truncation’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
The resulting plots are shown in Figure 9.22. The output signal in the left plot
agrees with that in Example 9.24 and has an asymptotic period of two samples.
The middle plot for α = 0.5 (lowpass filter) shows that the limit cycle has a
period of one sample with amplitude of 18 . Finally, the right plot shows that the
limit cycles vanish for the truncation operation. This behavior for the truncation
operation is also exhibited for lowpass filters.
0
5
10
Sample index n
FIGURE 9.22
440
α = −0.5, Truncation
1
0.75
0.5
0.25
0
−0.25
−0.5
−0.75
−1
Amplitude
α = 0.5, Rounding
Amplitude
Amplitude
α = −0.5, Rounding
1
0.75
0.5
0.25
0
−0.25
−0.5
−0.75
−1
0
5
10
1
0.75
0.5
0.25
0
−0.25
−0.5
−0.75
−1
0
5
10
Sample index n
Sample index n
Granular limit cycles in Example 9.25
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In the case of second-order and higher-order digital filters, granular
limit cycles not only exist but also are of various types. These cycles in
second-order filters can be analyzed, and dead-band as well as frequency
of oscillations can be estimated. For example, if the recursive all-pole filter
is implemented with rounding quantizers in the multipliers as
ŷ(n) = Q[a1 ŷ(n − 1)] + Q[a2 ŷ(n − 2)] + x(n)
(9.86)
where ŷ(n) is the quantized output, then using the analysis similar to that
of the first-order case, the dead-band region is given by
ŷ(n − 2) ≤
∆
2(1 − |a2 |)
(9.87)
with a1 determining the frequency of oscillations. For more details see
[12]. We provide the following example to illustrate granular limit cycles
in second-order filters using 3-bit quantizers.
EXAMPLE 9.26
Consider the second-order recursive filter
y(n) = 0.875y(n − 1) − 0.75y(n − 2) + x(n)
(9.88)
with zero initial conditions. This filter has two complex-conjugate poles and
hence is a bandpass filter. Let the input be x(n) = 0.375δ(n). Analyze the limit
cycle behavior using a 3-bit quantizer.
Solution
In the filter implementation the coefficient products are quantized, which
results in
ŷ(n) = Q[0.875ŷ(n − 1)] − Q[0.75ŷ(n − 2)] + x(n)
(9.89)
where ŷ(n) is the quantized output. We simulate (9.89) in MATLAB using both
the rounding and truncation operations.
% Bandpass filter
a1 = 0.875; a2 = -0.75;
% Rounding operation in multipliers
yn1 = 0; yn2 = 0;
m = 0:20; y = [yn2,yn1,zeros(1,length(m))];
x = 0.375*impseq(m(1),m(1)-2,m(end));
for n = m+3
yn1 = y(n-1); yn2 = y(n-2);
y(n) = QFix(a1*yn1,3,’round’,’satur’)+QFix(a2*yn2,3,’round’,’satur’)+x(n);
end
Round-off Effects in IIR Digital Filters
441
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
subplot(’position’,[0.1,0.2,0.39,0.6]);
plot([-1,20],[0,0],’w’); axis([-1,20,-0.5,0.5]); hold on;
Hs_1 = stem([-2,-1,m],y,’filled’); set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-0.5:0.25:0.5],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’Rounding Operation’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
% Truncation operation in multipliers
yn1 = 0; yn2 = 0;
m = 0:20; y = [yn2,yn1,zeros(1,length(m))];
x = 0.375*impseq(m(1),m(1)-2,m(end));
for n = m+3
yn1 = y(n-1); yn2 = y(n-2);
y(n) = QFix(a1*yn1,3,’trunc’,’satur’)+QFix(a2*yn2,3,’trunc’,’satur’)+x(n);
end
subplot(’position’,[0.59,0.2,0.39,0.6]);
plot([-1,20],[0,0],’w’); axis([-1,20,-0.5,0.5]); hold on;
Hs_1 = stem([-2,-1,m],y,’filled’); set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-0.5:0.25:0.5],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’Truncation Operation’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
The resulting plots are shown in Figure 9.23. The round-off limit cycles have a
period of six samples and amplitude of 0.25, which agrees with (9.87). Unlike
in the case of first-order filters, the limit cycles for the second-order exist even
when truncation is used in the quantizer.
OVERFLOW
LIMIT CYCLES
This type of limit cycle is also a zero-input behavior that gives an oscillatory output. It is due to overflow in the addition even if we ignore
multiplication or product quantization in the filter implementation. This
is a more serious limit cycle because the oscillations can cover the entire
dynamic range of the quantizer. It can be avoided in practice by using
Truncation Operation
0.5
0.25
0.25
Amplitude
Amplitude
Rounding Operation
0.5
0
−0.25
−0.5
0
5
10
15
20
0
−0.25
−0.5
0
5
Sample index n
FIGURE 9.23
442
10
15
20
Sample index n
Granular limit cycles in Example 9.26
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
the saturation characteristics instead of overflow in the quantizer. In the
following example, we simulate both granular and overflow limit cycles in
a second-order filter, in addition to infinite precision implementation.
EXAMPLE 9.27
To obtain overflow in addition we will consider the second-order filter with large
coefficient values and initial conditions (magnitudewise) excited by a zero input:
y(n) = 0.875y(n−1)−0.875y(n−1);
y(−1) = −0.875, y(−2) = 0.875
(9.90)
The overflow in the addition is obtained by placing the quantizer after the
additions as
ŷ(n) = Q[0.875ŷ(n − 1) − 0.875ŷ(n − 1)];
ŷ(−1) = −0.875, ŷ(−2) = 0.875
(9.91)
where ŷ(n) is the quantized output. We first simulate the infinite-precision operation of (9.90) and compare its output with the granular limit-cycle implementation in (9.89) and with the overflow limit-cycle in (9.91). We use the rounding
operation. The details are in the MATLAB script:
M = 100; B = 3; A = 1-2^(-B);
a1 = A; a2 = -A; yn1 = -A; yn2 = A;
m = 0:M; y = [yn2,yn1,zeros(1,length(m))];
% Infinite precision
for n = m+3
yn1 = y(n-1); yn2 = y(n-2);
y(n) = a1*yn1 + a2*yn2;
end
subplot(’position’,[0.08,0.2,0.24,0.6]);
plot([-1,100],[0,0],’w’); axis([-1,80,-1,1]); hold on;
Hs_1 = stem([-2,-1,m],y,’filled’);set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-1:0.25:1],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’No Limit Cycles’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
% Granular limit cycle
for n = m+3
yn1 = y(n-1); yn2 = y(n-2);
y(n) = QFix(a1*yn1,B,’round’,’satur’)+QFix(a2*yn2,B,’round’,’satur’);
y(n) = QFix(y(n),B,’round’,’satur’);
end
subplot(’position’,[0.42,0.2,0.24,0.6]);
plot([-1,100],[0,0],’w’); axis([-1,80,-1,1]); hold on;
Hs_1 = stem([-2,-1,m],y,’filled’);set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-1:0.25:1],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’Granular Limit Cycles’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
Round-off Effects in IIR Digital Filters
443
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Overflow limit cycle
for n = m+3
yn1 = y(n-1); yn2 = y(n-2);
y(n) = a1*yn1 + a2*yn2;
y(n) = QFix(y(n),B,’round’,’twosc’);
end
subplot(’position’,[0.76,0.2,0.23,0.6]);
plot([-1,100],[0,0],’w’); axis([-1,80,-1,1]); hold on;
Hs_1 = stem([-2,-1,m],y,’filled’);set(Hs_1,’markersize’,3,’color’,[0,1,0]);
set(gca,’ytick’,[-1:0.25:1],’fontsize’,6); ylabel(’Amplitude’,’fontsize’,8);
title(’Overflow Limit Cycles’,’fontsize’,10);
xlabel(’Sample index n’,’fontsize’,8);
The resulting plots are shown in Figure 9.24. As expected, the infinite-precision
implementation has no limit cycles. The granular limit cycles are of smaller
amplitudes. Clearly, the overflow limit cycles have large amplitudes spanning
the −1 to 1 range of the quantizers.
0
20
40
60
80
Sample index n
FIGURE 9.24
1
0.75
0.5
0.25
0
−0.25
−0.5
−0.75
−1
Overflow Limit Cycles
Amplitude
Granular Limit Cycles
Amplitude
Amplitude
No Limit Cycles
1
0.75
0.5
0.25
0
−0.25
−0.5
−0.75
−1
0
20
40
60
80
1
0.75
0.5
0.25
0
−0.25
−0.5
−0.75
−1
0
Sample index n
20
40
60
80
Sample index n
Comparison of limit cycles in Example 9.27
As shown in these examples, the limit-cycle behaviors of many different filters can be studied for different quantizer characteristics using the
MATLAB function QFix.
MULTIPLICATION
QUANTIZATION
ERROR
A multiplier element in the filter implementation can introduce additional
quantization errors since multiplication of two B-bit fractional numbers
results in a 2B-bit fraction and must be quantized to a B-bit fraction.
Consider a multiplier in fixed-point arithmetic with B = 8. The number
√1 is represented as 0.578125 in decimal. The square of 0.578125 rounded
3
to 8 bits is 0.3359375 (which should not be confused with 1/3 rounded to
8 bits, which is 0.33203125). The additional error in the squaring operation is
0.3359375 − (0.578125)2 = 0.001708984375
This additional error is termed as the multiplication quantization error. Its
statistically equivalent model is similar to that of the A/D quantization
error model, as shown in Figure 9.25.
444
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x(n)
c
Q
Q[c x (n)] ⇒ x(n)
c
cx(n) + e(n)
e(n)
(a) Quantizer
FIGURE 9.25
(b) Linear system model
Linear system model for multiplication quantization error
Statistical model Consider the B-bit quantizer block following the
multiplier element shown in Figure 9.25(a). The sequence x(n) and the
constant c are quantized to B fractional bits prior to multiplication (as
would be the case in a typical implementation). The multiplied sequence
{c x(n)} is quantized to obtain y(n). We want to replace the quantizer by
a simpler linear system model shown in Figure 9.25(b) in which y(n) =
c x(n) + e(n), where e(n) is a multiplication quantization error. For analysis purposes we assume that the conditions on e(n) are similar to those
for the A/D quantization error—that is,
1. the random signal e(n) is uncorrelated with the sequence x(n) for
rounding operation (or two’s-complement truncation operation) in the
quantizer,
2. the signal e(n) is an independent process (i.e., the samples are independent of each other), and
3. the probability density function (pdf) fE (e) of e(n) for each n is uniformly distributed over the interval of width ∆ = 2−B , which is the
quantizer resolution.
We will emphasize the rounding operation for the rest of this section.
Based on the above model assumptions, the results given in (9.61), (9.63),
and (9.64) are also applicable for the multiplication quantization error
e(n).
We offer the following two MATLAB examples to illustrate the above
model. A more thorough investigation of this error can be found in [25].
EXAMPLE 9.28
Consider the sequence given in Example 9.20 which is repeated below.
x(n) =
1
[sin(n/11) + sin(n/31) + cos(n/67)]
3
#
This signal is multiplied by c = 1/ (2), quantized to B bits and the resulting
multiplication is quantized to B bits with rounding. Using the StatModelR
function and 500,000 samples, compute and analyze normalized errors e1 (n)
and e2 (n), defined in (9.56) and (9.57), respectively.
Solution
The following MATLAB script computes error distribution, for B = 6 bits.
Round-off Effects in IIR Digital Filters
445
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
clear; close all;
% Example parameters
B = 6; N = 500000; n = [1:N]; bM = 7;
xn = (1/3)*(sin(n/11)+sin(n/31)+cos(n/67)); clear n;
c = 1/sqrt(2);
% Signal and Coefficient Quantization
xq = (round(xn*(2^B)))/(2^B); c = (round(c*(2^B)))/(2^B);
cxq = c*xq;
% Multiplication of constant and signal
% Quantization error analysis
[H1,H2,Q, estat] = StatModelR(cxq,B,N);
H1max = max(H1); H1min = min(H1);
% Max and Min of H1
H2max = max(H2); H2min = min(H2);
% Max and Min of H2
The plots of the resulting histogram are shown in Figure 9.26. For the sinusoidal
signal, when B = 6 bits, the error samples are not uniformly distributed and the
samples are not independent. The means of e(n) and [e(n)+e(n−1)]/2 are small.
Their standard deviations are 0.0045105 and 0.0031059, which do not agree with
(9.64). The corresponding plots for B = 12 bits are shown in Figure 9.27 from
which we observe that the quantization error sequence appears to satisfy the
model assumptions for B ≥ 12 bits. The means of e(n) and [e(n) + e(n − 1)]/2
are very small, and their standard deviations agree closely with (9.64).
EXAMPLE 9.29
Distribution of e1
4128
3128
2128
SAMPLE SIZE N = 500000
ROUNDED TO B = 6 BITS
MEAN = 1.7026e–006
MIN PROB BAR HEIGHT = 0
MAX PROB BAR HEIGHT = 0.017902
SIGMA = 0.0045105
1128
0
−0.5
4128
Distribution of e2
Let x(n) be an independent and identically distributed random sequence whose
samples are uniformly distributed over the [−1, 1] interval. Using 500,000 samples to minimize any statistical variations analyze normalized errors.
3128
2128
−0.375
−0.25
−0.125
0
0.125
Normalized error e1
SAMPLE SIZE N = 500000
ROUNDED TO B = 6 BITS
MEAN = 1.6953e–006
0.25
0.375
0.5
MIN PROB BAR HEIGHT = 0
MAX PROB BAR HEIGHT = 0.017606
SIGMA = 0.0031059
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
FIGURE 9.26 Multiplication quantization error distribution for the sinusoidal
signal in Example 9.28, B = 6 bits
446
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Distribution of e1
4128
3128
2128
MIN PROB BAR HEIGHT = 0.005792
MAX PROB BAR HEIGHT = 0.008184
SIGMA = 7.0526e–005
1128
0
−0.5
4128
Distribution of e2
SAMPLE SIZE N = 500000
ROUNDED TO B = 12 BITS
MEAN = –9.0218e–008
3128
2128
−0.375
−0.25
−0.125
0
0.125
Normalized error e1
SAMPLE SIZE N = 500000
ROUNDED TO B = 12 BITS
MEAN = –9.034e–008
0.25
0.375
0.5
MIN PROB BAR HEIGHT = 9.2e 005
MAX PROB BAR HEIGHT = 0.01578
SIGMA = 4.9902e–005
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
FIGURE 9.27 Multiplication quantization error distribution for the sinusoidal
signal in Example 9.28, B = 12 bits
Solution
The following MATLAB script computes the distributions for B = 6 bits.
clear; close all;
% Example parameters
B = 6; N = 500000; xn = (2*rand(1,N)-1); bM = 7; c = 1/sqrt(2);
% Signal and Coefficient Quantization
xq = (round(xn*(2^B)))/(2^B); c = (round(c*(2^B)))/(2^B);
cxq = c*xq;
% Multiplication of constant and signal
% Quantization error analysis
[H1,H2,Q, estat] = StatModelR(cxq,B,N);
H1max = max(H1); H1min = min(H1);
% Max and Min of H1
H2max = max(H2); H2min = min(H2);
% Max and Min of H2
The plots of the resulting histogram are shown in Figure 9.28. Even for B = 6
bits, the error samples appear to be uniformly distributed (albeit in discrete
fashion) and are independent of each other. The corresponding plots for B = 12
bits are shown in Figure 9.29. It is clear for B = 12 bits that the quantization
error samples are independent and uniformly distributed. Readers should verify
the statistics of these errors given in (9.61), (9.63), and (9.64).
From these two examples, we conclude that the statistical model for
the multiplication quantization error, with its stated assumptions, is a
very good model for random signals when the number of bits in the quantizer is large enough.
Round-off Effects in IIR Digital Filters
447
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Distribution of e1
4128
3128
2128
SAMPLE SIZE N = 500000
ROUNDED T0 B = 6 BITS
MEAN = 9.606e–006
MIN PROB BAR HEIGHT = 0
MAX PROB BAR HEIGHT = 0.015984
SIGMA = 0.0045115
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
0.25
0.375
0.5
Normalized error e1
Distribution of e2
4128
3128
2128
SAMPLE SIZE N = 500000
ROUNDED T0 B = 6 BITS
MEAN = 9.6153e–006
MIN PROB BAR HEIGHT = 4.4e 005
MAX PROB BAR HEIGHT = 0.015656
SIGMA = 0.0031915
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
FIGURE 9.28 Multiplication quantization error distribution for the random
signal in Example 9.29, B = 6 bits
Distribution of e1
4128
3128
2128
MIN PROB BAR HEIGHT = 0.005692
MAX PROB BAR HEIGHT = 0.008254
SIGMA = 7.0449e–005
1128
0
−0.5
4128
Distribution of e2
SAMPLE SIZE N = 500000
ROUNDED TO B = 12 BITS
MEAN = 3.3451e–008
3128
2128
−0.375
−0.25
−0.125
0
0.125
Normalized error e1
SAMPLE SIZE N = 500000
ROUNDED TO B = 12 BITS
MEAN = 3.3403e–008
0.25
0.375
0.5
MIN PROB BAR HEIGHT = 8.4e–005
MAX PROB BAR HEIGHT = 0.015436
SIGMA = 4.9859e–005
1128
0
−0.5
−0.375
−0.25
−0.125
0
0.125
Normalized error e2
0.25
0.375
0.5
FIGURE 9.29 Multiplication quantization error distribution for the random
signal in Example 9.29, B = 12 bits
448
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x(n)
y1(n)
y(n)
x(n)
yˆ1(n)
z −1
Y
x(n)
yˆ1(n)
z −1
a
(a)
z −1
a
Q
y(n) + q(n)
e(n)
(b)
a
(c)
FIGURE 9.30 First-order IIR filter: (a) Structure, (b) Structure with quantizer
(c) Round-off noise model
STATISTICAL
ROUND-OFF
NOISE—
FIXED-POINT
ARITHMETIC
In this and the next section, we will consider the round-off effects on IIR
filters using the multiplication quantization error model developed in the
previous section. Since we emphasize the rounding operation, this model
is also known as a round-off noise model. We will limit ourselves to the
first- and second-order filters since practical realizations involve first- or
second-order sections.
First-order filter Consider the first-order filter shown in Figure 9.30(a).
When a quantizer Q[·] is introduced after the multiplier, the resulting filter
model is shown in Figure 9.30(b), which is a nonlinear system. When Q [·]
is a quantizer based on the round-off characteristics, then its effect is to
add a zero-mean, stationary white noise sequence e(n) at the multiplier
output as shown in Figure 9.30(c).
Let q(n) be the response due to e(n) and let he (n) be the noise impulse
response (i.e., between e(n) and q(n)). For the system in Figure 9.30(c)
he (n) = h(n) = αn u(n)
(9.92)
Using (9.66) and (9.61), the mean of q(n) is
∞
he (n) = 0
(9.93)
Similarly, using (9.69), the variance of q(n) is
∞
2
2
2
|he (n)|
σ q = σe
(9.94)
mq = me
0
0
Substituting σe2 = 2−2B /12 for rounding and he (n) from (9.92), we obtain
∞
∞
2−2B 2−2B n 2
2−2B
n
2
(9.95)
=
|α |
|α|2 =
σq =
12
12 0
12 (1 − |α|2 )
0
which is the output noise power due to rounding following the multiplication.
Round-off Effects in IIR Digital Filters
449
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x(n)
Xmax
yˆ1(n)
ˆ
y(n)
Xmax
x(n)
yˆ1(n)
z −1
z −1
a
Q
y(n) + q(n)
a
e(n)
(a)
(b)
FIGURE 9.31 Scaled first-order IIR filter: (a) Structure with quantizer, (b)
Round-off noise model
However, we also have to prevent a possible overflow following the
adder. Let y1 (n) be the signal at the output of the adder in Figure 9.30(a),
which in this case is equal to y(n). Now the upper bound on y1 (n) is
∞
∞
|y1 (n)| = |y(n)| = h(k) x(n − k) ≤
|h(k)| |x(n − k)|
(9.96)
0
0
Let the input sequence be bounded by Xmax (i.e., |x(n)| ≤ Xmax ). Then
|y1 (n)| ≤ Xmax
∞
|h(k)|
(9.97)
0
Since y1 (n) is represented by B fraction bits, we have |y1 (n)| ≤ 1. The
condition (9.97) can be satisfied by requiring
Xmax = ∞
0
1
1
= 1 − |α|
=
1/ (1 − |α|)
|h(k)|
(9.98)
Thus, to prevent overflow x(n) must satisfy
− (1 − |α|) ≤ x(n) ≤ (1 − |α|)
(9.99)
Thus, the input must be scaled before it is applied to the filter as shown
in Figure 9.31.
Signal-to-noise ratio We will now compute the finite word-length
effect in terms of the output signal-to-noise ratio (SNR). We assume
that there is no overflow at the output by properly scaling x(n). Let
x(n) be a stationary white sequence, uniformly distributed between
[− (1 − |α|) , (1 − |α|)]. Then
2
mx = 0
and σx2 =
(1 − |α|)
3
(9.100)
Therefore, y(n) is also a stationary random sequence with mean my = 0
and
∞
2
2
1
(1 − |α|)
(1 − |α|)
2
(9.101)
|h(n)| =
=
σy2 = σx2
2
2
3
1 − |α|
3 (1 − |α| )
0
450
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Using (9.95) and (9.101), the output SNR is
SNR =
2
σy2
(1 − |α|) 12 1 − |α|2
2
2
=
= 4 22B (1 − |α|) = 22(B+1) (1 − |α|)
σq2
3 (1 − |α|2 )
2−2B
(9.102)
or the SNR in dB is
SNRdB = 10 log10 (SNR) = 6.02 + 6.02B + 20 log10 (1 − |α|)
(9.103)
Let δ = 1 − |α|, which is the distance of the pole from the unit circle.
Then
SNRdB = 6.02 + 6.02B + 20 log10 (δ)
(9.104)
which is a very informative result. First, it shows that the SNR is directly
proportional to B and increases by about 6 dB for each additional bit
added to the word length. Second, the SNR is also directly proportional
to the distance δ. The smaller the δ (or nearer the pole to the unit circle),
the smaller is the SNR, which is a consequence of the filter characteristics.
As an example, if B = 6 and δ = 0.05, then SNR = 16.12 dB and if B = 12
and δ = 0.1, then SNR = 58.26 dB.
ANALYSIS
USING
MATLAB
In order to analyze the properties of the round-off errors in IIR filters we
will simulate them using the MATLAB function QFix with quantization
mode ’round’ and overflow mode ’satur’. If proper scaling to avoid
overflow is performed, then only the multiplier output needs to be quantized at each n without worrying about the overflow. However, we will
still saturate the final sum to avoid any unforeseen problems. In previous
simulations, we could perform the quantization operations on vectors (i.e.,
perform parallel processing). Since IIR filters are recursive filters and since
each error is fed back into the system, vector operation is generally not
possible. Hence the filter output will be computed sequentially from the
first to the last sample. For a large number of samples this implementation
will slow the execution speed in MATLAB since MATLAB is optimized
for vector calculations. However, for newer fast processors, the execution
time is within a few seconds. These simulation steps are detailed in the
following example.
Consider the model given in Figure 9.31(b). We will simulate this model in
MATLAB and investigate its output error characteristics. Let a = 0.9, which
will be quantized to B bits. The input signal is uniformly distributed over
the [−1, +1] interval and is also quantized to B bits prior to filtering. The
scaling factor Xmax is computed from (9.98). Using 100, 000 signal samples and
B = 6 bits, the following MATLAB script computes the true output y(n), the
quantized output ŷ(n), the output error q(n), and the output SNR.
EXAMPLE 9.30
Round-off Effects in IIR Digital Filters
451
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
close all; clc;
% Example Parameters
B = 6;
N = 100000;
xn = (2*rand(1,N)-1);
a = 0.9;
Xm = 1-abs(a);
%
%
%
%
%
% Local variables
bM = 7; DbM = 2^bM;
BB = 2^B;
M = round(DbM/2);
bins = [-M+0.5:1:M-0.5];
Q = bins/DbM;
YTN = 2^(-bM);
YLM = 4*YTN;
# of fractional bits
# of samples
Input sequence - Uniform Distribution
Filter parameter
Scaling factor
%
%
%
%
%
%
%
bin parameter
useful factor in quantization
Half number of bins
Bin values from -M to M
Normalized bins
Ytick marks interval
Yaxis limit
% Quantize the input and the filter coefficients
xn = QFix(Xm*xn,B,’round’,’satur’); % Scaled Input quant to B bits
a = QFix(a,B,’round’,’satur’);
% a quantized to B bits
% Filter output without multiplication quantization
yn = filter(1,[1,-a],xn); % output using filter routine
% Filter output with multiplication quantization
yq = zeros(1,N);
% Initialize quantized output array
yq(1) = xn(1);
% Calculation of the first sample yq(1)
for I = 2:N;
A1Y = QFix(a*yq(I-1),B,’round’,’satur’); % Quantization of a*y(n-1)
yq(I) = QFix(A1Y+xn(I),B,’round’,’satur’); % I-th sample yq(I)
end
% Output Error Analysis
en = yn-yq;
varyn = var(yn); varen = var(en);
eemax = max(en); eemin = min(en);
enmax = max(abs([eemax,eemin]));
enavg = mean(en); enstd = std(en);
en = round(en*(2^bM)/(2*enmax)+0.5);
en = sort([en,-M:1:(M+1)]);
H = diff(find(diff(en)))-1;
H = H/N;
Hmax = max(H); Hmin = min(H);
%
%
%
%
%
%
%
%
%
%
Output error sequence
Signal and noise power
Maximum and minimum of the error
Absolute maximum range of the error
Mean and std dev of the error
Normalized en (integer between -M & M)
Error histogram
Normalized histogram
Max and Min of the normalized histogram
% Output SNRs
SNR_C = 10*log10(varyn/varen); % Computed SNR
SNR_T = 6.02 + 6.02*B + 20*log10(Xm); % Theoretical SNR
452
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
0.0313
Distribution of output error
SAMPLE SIZE N = 100000
PARAMETER a = 0.90625
SNR(THEORY) = 22.14
ROUNDED T0 B = 6 BITS
ERROR MEAN = –3.2612e–005
SNR(COMPUTED) = 22.2105
0.0234
0.0156
0.0078
0
−0.5
−0.4
−0.3
−0.2
0
0. 1
−0.1
Normalized error
0. 2
0. 3
0. 4
0. 5
FIGURE 9.32 Multiplication quantization effects in the first-order IIR filter in
Example 9.30, B = 6 bits
The part of the script not shown above also computes and plots the normalized histogram of the output error and prints the statistical values in the
plot, as shown in Figure 9.32. The error appears to have a Gaussian distribution, which is to be expected. The exact value of the output SNR is 22.14 dB,
which agrees with the computed value of 22.21 dB. Similar results done for
B = 12 bits are shown in Figure 9.33. Again, the simulation results agree with
the model results.
Second-Order filter Similar analysis can be done for second-order filters with poles near the unit circle. Let the two poles be at complex locations reθ and re−θ . Then the system function of the filter is given by
H(z) =
1
1
=
(1 − reθ z −1 )(1 − re−θ z −1 )
1 − 2r cos(θ) z −1 + r2 z −2
(9.105)
with impulse response
h(n) =
rn sin{(n + 1)θ}
u(n)
sin(θ)
(9.106)
The difference equation from (9.105) is given by
y(n) = x(n)−a1 y(n−1)−a2 y(n−2);
Round-off Effects in IIR Digital Filters
a1 = −2r cos(θ), a2 = r2
(9.107)
453
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Distribution of output error
0.0313
SAMPLE SIZE N = 100000
PARAMETER a = 0.8999
SNR(THEORY) = 58.26
ROUNDED TO B = 12 BITS
ERROR MEAN = –1.282e–007
SNR(COMPUTED) = 58.134
0.0234
0.0156
0.0078
0.0
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
Normalized error
FIGURE 9.33 Multiplication quantization effects in the first-order IIR filter in
Example 9.30, B = 12 bits
which requires two multiplications and two additions, as shown in
Figure 9.34(a). Thus, there are two noise sources and two possible locations for overflow. The round-off noise model for quantization following
the two multipliers is shown in Figure 9.34(b), where the responses q1 (n)
and q2 (n) are due to noise sources e1 (n) and e2 (n), respectively. We can
combine two noise sources into one. However, to avoid overflow we have
to scale signals at the input of each adder, which can complicate this
consolidation of sources.
In modern DSP chips, the intermediate results of multiply-add operations are stored in a multiply-accumulate or MAC unit that has
a double precision register to accumulate sums. The final sum [which
for Figure 9.34(b) is at the output of the top adder] is quantized to
obtain ŷ(n). This implementation not only reduces the total multiplication quantization noise but also makes the resulting analysis easier.
Assuming this modern implementation, the resulting simplified model is
shown in Figure 9.34(c), where e(n) is the single noise source that is uniformly distributed between [−2−(B+1) , 2−(B+1) ] and q(n) is the response
due to e(n). Note that e(n) = e1 (n)+e2 (n) and that q(n) = q1 (n)+q2 (n).
The only overflow that we have to worry about is at the output of the
top adder, which can be controlled by scaling the input sequence x(n)
as shown in Figure 9.34(d). Now the round-off noise analysis can be
carried out in a fashion similar to that of the first-order filter. The
details, however, are more involved due to the impulse response in
(9.106).
454
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
-a1
-a2
yˆ (n)
= y(n) + q1(n) + q2(n)
x(n)
y (n)
x(n)
z −1
z −1
-a1
y(n − 1)
ˆ − 1)
y(n
e1(n)
z −1
z −1
-a2
y(n − 2)
ˆ − 2)
y(n
e2(n)
(a)
(b)
e(n)
e(n)
x(n)
z−1
-a1
yˆ (n)
= y(n) + q(n)
x(n)
Xmax
z −1
-a1
yˆ (n − 1)
z−1
-a2
yˆ (n)
= y(n) + q(n)
yˆ(n − 1)
z −1
-a2
yˆ(n − 2)
(c)
ˆ − 2)
y(n
(d)
FIGURE 9.34 Second-order IIR filter: (a) Structure, (b) Round-off noise model,
(c) Simplified model, (d) Scaled simplified model
Signal-to-noise ratio Referring to Figure 9.34(d), the noise impulse
response he (n) is equal to h(n). Hence the output round-off noise power
is given by
∞
∞
2−2B σq2 = σe2
|h(n)|2 =
|h(n)|2
(9.108)
12
n=0
n=0
Since the x(n) is quantized, we have |x(n)| ≤ 1. It is then scaled by Xmax
to avoid overflow in the adder. Hence the output signal power is given by
2
σx2
σy2 = Xmax
∞
n=0
|h(n)|2 =
∞
2
Xmax
|h(n)|2
3 n=0
(9.109)
assuming that x(n) is uniformly distributed over [−1, +1]. Hence the output SNR is given by
SNR =
σy2
2
2
= 4 22B Xmax
= 22(B+1) Xmax
σq2
(9.110)
or
SNRdB = 6.02 + 6.02B + 20 log10 Xmax
Round-off Effects in IIR Digital Filters
(9.111)
455
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Following (9.97), (9.98), and (9.99), the scaling factor Xmax is given by
1
n=0 |h(n)|
Xmax = ∞
(9.112)
which is not easy to compute. However, lower and upper bounds on Xmax
are easy to obtain. From (9.106), the upper bound on the denominator of
(9.112) is given by
∞
|h(n)| =
n=0
∞
∞
1 n
1 n
1
r | sin[(n + 1)θ]| ≤
r =
sin θ n=0
sin θ n=0
(1 − r) sin θ
(9.113)
or the lower bound on Xmax is given by
Xmax ≥ (1 − r) sin θ
(9.114)
The lower bound on the denominator of (9.112) is obtained by noting that
∞
∞
ω
−ω ≤
h(n)e
|h(n)|
|H(e )| = n=0
n=0
Now from (9.105), the magnitude |H(eω )| is given by
1
|H(eω )| = −ω
2
−2ω
1 − 2r cos(θ)e
+r e
which has the maximum value at the resonant frequency ω = θ, which
can be easily obtained. Hence
∞
n=0
|h(n)| ≥ H(eθ ) =
1
#
(1 − r) 1 + r2 − 2r cos(2θ)
or the upper bound on Xmax is given by
#
Xmax ≤ (1 − r) 1 + r2 − 2r cos(2θ)
(9.115)
(9.116)
Substituting (9.114) and (9.116) in (9.110), the output SNR is upper and
lower bounded by
22(B+1) (1 − r)2 sin2 θ ≤ SNR ≤ 22(B+1) (1 − r)2 (1 + r2 − 2r cos 2θ)
(9.117)
Substituting 1 − r = δ 1 and after some simplification, we obtain
22(B+1) δ 2 sin2 θ ≤ SNR ≤ 4 22(B+1) δ 2 sin2 θ
(9.118)
or the difference between the upper and lower SNR bounds is about 6 dB.
Once again the output SNR is directly proportional to B and δ. Furthermore, it also depends on the angle θ. Some of these observations are
investigated in Example 9.31.
456
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ANALYSIS
USING
MATLAB
We will again simulate round-off errors using the MATLAB function QFix
with quantization mode ’round’ and overflow mode ’satur’. Since a
MAC architecture is assumed, we do not have to quantize the intermediate
results and worry about overflow. Only the final sum needs to be quantized
with saturation. These operations are also simulated in sequential fashion,
which has an impact on execution speed. The simulation steps for the
second-order filter are detailed in the following example.
Consider the model given in Figure 9.34(d). We will simulate this model in
MATLAB and investigate its output error characteristics. Let r = 0.9 and
θ = π/3, from which filter parameters are computed and quantized to B bits.
The input signal is uniformly distributed over the [−1, +1] interval and is also
quantized to B bits prior to filtering. The scaling factor Xmax is determined
using (9.112), which can be obtained in MATLAB by computing the impulse
response for a sufficiently large number of samples. Using 100, 000 signal samples
and B = 6 bits, the following MATLAB script computes the true output SNR,
the computed SNR, and the lower and upper bounds of the SNR.
EXAMPLE 9.31
close all; clc;
% Example Parameters
B = 12;
% # of fractional bits
N = 100000;
% # of samples
xn = (2*rand(1,N)-1); % Input sequence - Uniform
r = 0.9; theta = pi/3;% Pole locations
% Computed Parameters
p1 = r*exp(j*theta); % Poles
p2 = conj(p1);
%
a = poly([p1,p2]);
% Filter parameters
hn = filter(1,a,[1,zeros(1,1000)]); % Imp res
Xm = 1/sum(abs(hn)); % Scaling factor
Xm_L = (1-r)*sin(theta); % Lower bound
Xm_U = (1-r)*sqrt(1+r*r-2*r*cos(2*theta)); % Upper bound
% Local variables
bM = 7; DbM = 2^bM;
BB = 2^B;
M = round(DbM/2);
bins = [-M+0.5:1:M-0.5];
Q = bins/DbM;
YTN = 2^(-bM);
YLM = 4*YTN;
%
%
%
%
%
%
%
bin parameter
useful factor in quantization
Half number of bins
Bin values from -M to M
Normalized bins
Ytick marks interval
Yaxis limit
% Quantize the input and the filter coefficients
xn = QFix(Xm*xn,B,’round’,’satur’); % Scaled Input quant B bits
a = QFix(a,B,’round’,’satur’);
% a quantized to B bits
a1 = a(2); a2 = a(3);
Round-off Effects in IIR Digital Filters
457
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Filter output without multiplication quantization
yn = filter(1,a,xn); % output using filter routine
% Filter output with multiplication quantization
yq = zeros(1,N); % Initialize quantized output array
yq(1) = xn(1);
% sample yq(1)
yq(2) = QFix((xn(2)-a1*yq(1)),B,’round’,’satur’); % sample yq(2)
for I = 3:N;
yq(I) = xn(I)-a1*yq(I-1)-a2*yq(I-2); % Unquantized sample
yq(I) = QFix(yq(I),B,’round’,’satur’); % Quantized sample
end
% Output Error Analysis
en = yn-yq;
varyn = var(yn); varen = var(en);
eemax = max(en); eemin = min(en);
enmax = max(abs([eemax,eemin]));
enavg = mean(en); enstd = std(en);
en = round(en*(2^bM)/(2*enmax)+0.5);
en = sort([en,-M:1:(M+1)]);
H = diff(find(diff(en)))-1;
H = H/N;
Hmax = max(H); Hmin = min(H);
%
%
%
%
%
%
%
%
%
%
Output error sequence
Signal and noise power
Maximum and minimum of the error
Absolute maximum range of the error
Mean and std dev of the error
Normalized en (integer between -M & M)
% Output SNRs
SNR_C = 10*log10(varyn/varen);
SNR_T = 6.02 + 6.02*B + 20*log10(Xm);
SNR_L = 6.02 + 6.02*B + 20*log10(Xm_L);
SNR_U = 6.02 + 6.02*B + 20*log10(Xm_U);
%
%
%
%
Computed SNR
Theoretical SNR
Lower SNR bound
Upper SNR bound
Error histogram
Normalized histogram
Max and Min of the normalized histogram
The part of the script not shown above also computes and plots the normalized
histogram of the output error and prints the statistical values in the plot, as
shown in Figure 9.35. The error again has a Gaussian distribution. The exact
value of the output SNR is 25.22 dB, which agrees with the computed value of
25.11 dB and lies between the lower bound of 20.89 dB and the upper bound of
26.47 dB. Similar results done for B = 12 bits are shown in Figure 9.36. Again,
the simulation results agree with the model results.
HIGHERORDER
FILTERS
458
The analysis of the quantization effects in a second-order filter can be
applied directly to higher-order filters based on a parallel realization. In
this case each second-order filter section is independent of all the other
sections, and therefore the total quantization noise power at the output
of the parallel structure is simply the linear sum of the quantization noise
powers of each of the individual sections. On the other hand, the cascade
realization is more difficult to analyze because the noise generated in
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
0.0313
Distribution of output error
SAMPLE SIZE N
RADIAL r
SNR(THEORY)
SNR(LOWER)
=
=
=
=
100000
0.9
25.2243
20.8906
ROUNDED TO B
ANGLE THETA
SNR(COMPUTED)
SNR(UPPER)
=
=
=
=
6 BITS
60 DEG
25.1065
26.4697
0.0234
0.0156
0.0078
0
−0.5
−0.4
−0.3
−0.2
0
0.1
−0.1
Normalized error
0.2
0.3
0.4
0.5
FIGURE 9.35 Multiplication quantization effects in the first-order IIR filter in
Example 9.31, B = 6 bits
any second-order filter section is filtered by the succeeding sections. To
minimize the total noise power at the output of the high-order filter, a
reasonable strategy is to place the sections in the order of decreasing
maximum frequency gain. In this case the noise power generated in the
0.0313
Distribution of output error
SAMPLE SIZE N
RADIAL r
SNR(THEORY)
SNR(LOWER)
=
=
=
=
100000
0.9
61.3443
57.0106
ROUNDED TO B
ANGLE THETA
SNR(COMPUTED)
SNR(UPPER)
=
=
=
=
12 BITS
60 DEG
61.3968
62.5897
0.0234
0.0156
0.0078
0
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
Normalized error
0.2
0.3
0.4
0.5
FIGURE 9.36 Multiplication quantization effects in the first-order IIR filter in
Example 9.31, B = 12 bits
Round-off Effects in IIR Digital Filters
459
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
early high-gain section is not boosted significantly by the latter sections.
Using the MATLAB techniques developed in the previous sections, it is
easier to simulate finite word-length implementations and determine the
output SNR for a given cascade structure.
STATISTICAL
ROUND-OFF
NOISE—
FLOATINGPOINT
ARITHMETIC
As discussed before, the floating-point arithmetic gives an error that is
relative to the magnitude rather than an absolute error. This results in a
multiplicative noise rather than additive noise—that is, from (9.34)
Q[x(n)] = x(n) + ε(n)x(n) = x(n) {1 + ε(n)}
(9.119)
−2−B < ε(n) ≤ 2−B
(9.120)
with
for a (B + 1)-bit mantissa. Hence the mean of the relative error is mε = 0
and its variance is
2−2B
(9.121)
σε2 =
3
Since MATLAB is implemented in IEEE-754 floating-point arithmetic,
all simulations that we perform are IEEE-754 floating-point calculations.
It is difficult (if not impossible) to simulate an arbitrary floating-point
arithmetic in MATLAB. Therefore, we give theoretical results only.
First-order filter Consider a first-order filter as before and shown
in Figure 9.37(a). For the finite word-length analysis with floating-point
arithmetic we need quantizers after both multiplication and addition to
account for rounding off in the mantissa, as shown in Figure 9.37(b).
Hence there are two noise sources in the the statistical model as shown in
Figure 9.37(c), where e1 (n) is the noise source in the multiplier, e2 (n) is
the noise source in the adder, ĝ(n) is an adder sequence prior to quantization, and ŷ(n) is the quantized output. Now
e1 (n) = ε1 (n) α ŷ(n − 1)
(9.122a)
e2 (n) = ε2 (n) ĝ(n)
(9.122b)
e2(n)
x(n)
g(n)
y(n)
x(n)
ˆ
g(n)
ˆ
y(n)
x(n)
ˆ
g(n)
y(n) + q(n)
Q
z −1
a
z −1
y(n − 1)
(a)
Q
a
yˆ (n − 1)
(b)
z −1
e1(n)
a
ˆ − 1)
y(n
(c)
First-order IIR filter: (a) Structure, (b) Finite word-length model
for floating-point arithmetic, (c) Statistical model for floating-point arithmetic
FIGURE 9.37
460
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where ε1 (n) and ε2 (n) are the relative errors in the corresponding quantizers. The exact analysis even for the first-order case is tedious; hence we
make a few practically reasonable approximations. If the absolute values
of the errors are small, then we have ŷ(n − 1) ≈ y(n − 1) and ĝ(n) ≈ y(n);
hence from (9.122a) we obtain
e1 (n) ≈ α ε1 (n) y(n − 1)
(9.123a)
e2 (n) ≈ ε2 (n) y(n)
(9.123b)
Furthermore, we make the following assumption about the noise sources:
1.
2.
3.
4.
ε1 (n)
ε1 (n)
ε1 (n)
ε1 (n)
and
and
and
and
ε2 (n)
ε2 (n)
ε2 (n)
ε2 (n)
are
are
are
are
white noise sources;
uncorrelated with each other;
uncorrelated with the input x(n); and
uniformly distributed between −2−B and 2−B .
Let x(n) be a zero-mean, stationary random sequence. Then y(n) is
also a zero-mean, stationary sequence. Hence from (9.123)
σe21 = |α|2 σε21 σy2
(9.124a)
σe22 = σε22 σy2
(9.124b)
Let the error in the output due e1 (n) be q1 (n) and that due to e2 (n) be
q2 (n). Let h1 (n) and h2 (n) be the corresponding noise impulse responses.
Note that h1 (n) = h2 (n) = h(n) = αn u(n). Then the total error q(n) is
q(n) = q1 (n) + q2 (n)
(9.125)
σq2 = σq21 + σq22
(9.126)
with
where
σq21 = σe21
∞
2
|h1 (n)|
and σq22 = σe22
0
∞
2
|h2 (n)|
(9.127)
0
Hence using (9.126), (9.127), and (9.124),
σq2 = σe21 + σe22
1
1 − |α|2
= σy2
1
1 − |α|2
|α|2 σε21 + σε22
(9.128)
Using σε21 = σε22 = 2−2B /3, we obtain
σq2 = σy2
2−2B
3
1 + |α|2
1 − |α|2
(9.129)
Therefore,
SNR =
Round-off Effects in IIR Digital Filters
σy2
= 3 22B
σq2
1 − |α|2
1 + |α|2
(9.130)
461
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
or
SNRdB = 4.77 + 6.02B + 10 log10 (1 − |α|2 ) − 10 log10 (1 + |α|2 ) (9.131)
which is also a very informative result. Some comments are in order.
1. The SNR in (9.130) was derived without assuming any input statistics,
Hence the result is valid for a large class of inputs including white-noise,
narrow-band, or wide-band signals. The floating-point arithmetic does
not have to worry about the scaling or limiting input values since it
can handle a large dynamic range.
2. Using 0 < δ = 1 − |α| 1, the SNR in (9.131) can be put in the form
SNRdB ≈ 4.77 + 6.02B + 10 log10 (δ) = O(δ)
(9.132)
This is to be compared with the fixed-point result (9.104) where SNR ≈
O(δ 2 ). Thus, the floating-point result is less sensitive to the distance
of the pole to the unit circle.
3. In floating-point arithmetic, the output noise variance, σq2 , in (9.129) is
proportional to σy2 . Thus, if the input signal is scaled up, so is the noise
variance since σy2 is also scaled up. Hence the SNR remains constant.
This again should be compared with the fixed-point case (9.95), in
which σq2 is independent of the input signal. Hence if the signal level
increases, then σy2 , increases, which increases the SNR.
Second-Order filter Similar analysis can be done for the second-order
filter with poles close to the unit circle. If the poles are given by re±jθ ,
then we can show that (see [18])
SNR =
σy2
4δ sin2θ
≈ 3 22B
≈ O (δ)
2
σq
3 + 4 cos θ
(9.133)
where δ = 1 − r. This again is an approximate result that works very well
in practice. In this case again, the SNR depends on δ rather than on δ 2
as in the fixed-point case.
ROUND-OFF NOISE IN FIR FILTER REALIZATIONS
We will now turn our attention to the finite word-length effects in FIR
digital filters. As before, we will consider the fixed-point and floating-point
cases separately. We will then conclude this section with some representative examples.
462
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIXED-POINT
ARITHMETIC
We will consider the effects on two realizations: direct-form and cascadeform. There is no parallel-form realization for FIR filters since we do
not have a partial fraction expansion, except for the frequency sampling
realization, which can be analyzed using IIR filter techniques. The analysis
of FIR filters is much simpler than that for IIR because there are no
feedback paths. One consequence of this is the absence of limit cycles.
Direct-form realization Consider an FIR filter of length M (i.e.,
there are M samples in the impulse response), which is realized using the
direct form as shown in Figure 9.38(a). The filter coefficients are the samples of the impulse response h(n). We have to introduce quantizers in the
vertical branches. If we use the implementation in which each multiplier
output is quantized, then we obtain the model shown in Figure 9.38(b).
z −1
z −1
z −1
x(n)
h(0)
h(1)
h(M − 1)
h(2)
h(M − 2)
y (n)
(a)
z −1
x(n)
h(0)
h(1)
Q
e0(n)
z −1
z −1
h(M − 1)
h(2)
Q
e1(n)
Q
Q
Q
eM−1(n)
e2(n)
h(M − 2)
eM−1(n)
(b)
z −1
x(n)
h(0)
h(1)
z −1
z −1
h(M − 1)
h (2)
h(M − 2)
yˆ (n)
= y (n) + q(n)
Q
(c)
e (n)
FIGURE 9.38 Direct-form FIR filter: (a) Structure, (b) Round-off noise model
with quantizers after each multiplier, (c) Round-off noise mode with one quantizer after the final sum
Round-off Noise in FIR Filter Realizations
463
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
On the other hand if we implement the filter in a typical DSP chip, then
the final sum is quantized as shown in Figure 9.38(c). We will separately
consider the effects of round-off noise and scaling (to avoid overflow).
Round-off noise Let the output of the filter in Figure 9.38(b) due to
round-off errors be ŷ(n) = y(n) + q(n). Then
q(n) =
M
−1
(9.134)
ek (n)
k=0
where ek (n) are the noise sources introduced in each vertical branch to
account for the rounding operations. Since these noise sources are all
identical, the noise power in q(n) is given by
σq2 =
M
−1
σe2k = M σe2 = M
0
2−2B
12
=
M −2(B+1)
2
3
(9.135)
In Figure 9.38(c) the output due to the rounding operation is ŷ(n) =
y(n) + e(n). Hence the noise power in this case is given by
σq2 = σe2 =
1 −2(B+1)
2
3
(9.136)
which is smaller by a factor of M compared to (9.135) as expected.
Scaling to avoid overflow We assume that the fixed-point numbers
have the two’s-complement form representation, which is a reasonable
assumption. Then we will have to check only the overflow of the total sum.
Thus, this analysis is the same for both implementations in Figure 9.38
and is similar to that for the IIR filter in (9.96)–(9.98). The upper-bound
on y(n) is obtained as
|y(n)| = h(k) x(n − k) ≤ Xmax
|h(n)|
(9.137)
where Xmax is the upper-bound on x(n). To guarantee that |y(n)| ≤ 1,
we need the scaling factor Xmax on x(n) as
Xmax ≤ 1
|h(n)|
(9.138)
which is the most conservative scaling factor. There are other scaling factors, depending on the applications—for example, the narrowband signals
use
1
Xmax ≤
max |H(eω )|
464
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
and wideband random signals use
Xmax ≤
4σx
1
#
|h(n)|2
.
Using (9.138) and assuming that x(n) is uniformly distributed over
[−Xmax , +Xmax ], the input signal power is given by
σx2 =
2
Xmax
1
= 2
3
3 ( |h(n)|)
(9.139)
Furthermore, assuming that x(n) is also a white sequence, the output
signal power is given by
1
|h(n)|2
2
2
2
σy = σx
|h(n)| =
(9.140)
3 ( |h(n)|)2
Thus, the output SNR is
σy2
22(B+1)
SNR = 2 =
σq
A
(
|h(n)|2
2
|h(n)|)
(9.141)
where A = M for the model in Figure 9.38(b) or A = 1 for the model in
Figure 9.38(c). The corresponding SNR in dB is
|h(n)|2
SNRdB = 6.02 + 6.02B + 10 log10
− 10 log10 A (9.142)
2
( |h(n)|)
ANALYSIS
USING
MATLAB
This simulation in MATLAB can be done in parallel fashion since there
is no feedback path for the multiplication quantization errors. Using the
function Qfix function with ’round’ mode, we will compute the quantized multiplier output. In the case of M quantizers, assuming two’scomplement format, we will use the ’twosc’ mode for each quantizer.
Only the final sum will be quantized and saturated. In the case of one
quantizer, we need the ’satur’ mode. These simulation steps are detailed
in the following example.
Let a fourth-order (M = 5) FIR filter be given by
EXAMPLE 9.32
H(z) = 0.1 + 0.2z −1 + 0.4z −2 + 0.2z −3 + 0.1z −4
(9.143)
which is implemented as a direct form with B = 12 fractional bit quantizers.
Compute SNRs for models in Figure 9.38(b) and (c) and verify them using
MATLAB simulations.
Round-off Noise in FIR Filter Realizations
465
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Solution
We will need the quantities
|h(n)|2 and ( |h(n)|)2 . These quantities should
be computed using 12-bit quantization
of the filter coefficients.
These values
using the quantized numbers are
|h(n)|2 = 0.2599 and ( |h(n)|)2 = 1. Using (9.142), the output SNR is 65.42 dB for five multipliers and is 72.41 dB
for one multiplier. The following MATLAB script evaluates these and other
quantities.
% Example Parameters
B = 12;
N = 100000;
xn = (2*rand(1,N)-1);
h = [0.1,0.2,0.4,0.2,0.1];
M = length(h);
% Local variables
bM = 7; DbM = 2^bM;
BB = 2^B;
K = round(DbM/2);
bins = [-K+0.5:1:K-0.5];
Q = bins/DbM;
YTN = 2^(-bM);
YLM = 4*YTN;
%
%
%
%
%
%
%
%
%
%
%
# of fractional bits
# of samples
Input sequence - Uniform Distribution
Filter parameters
bin parameter
useful factor in quantization
Half number of bins
Bin values from -K to K
Normalized bins
Ytick marks interval
Yaxis limit
% Quantize the input and the filter coefficients
h = QFix(h,B,’round’,’satur’); % h quantized to B bits
Xm = 1/sum(abs(h));
% Scaling factor
xn = QFix(Xm*xn,B,’round’,’satur’);% Scaled Input quant to B bits
% Filter output without multiplication quantization
yn = filter(h,1,xn);
% output using filter routine
% Filter output with multi quant (5 multipliers)
x1 = [zeros(1,1),xn(1:N-1)]; x2 = [zeros(1,2),xn(1:N-2)];
x3 = [zeros(1,3),xn(1:N-3)]; x4 = [zeros(1,4),xn(1:N-4)];
h0x0 = QFix(h(1)*xn,B,’round’,’twosc’);
h1x1 = QFix(h(2)*x1,B,’round’,’twosc’);
h2x2 = QFix(h(3)*x2,B,’round’,’twosc’);
h3x3 = QFix(h(4)*x3,B,’round’,’twosc’);
h4x4 = QFix(h(5)*x4,B,’round’,’twosc’);
yq = h0x0+h1x1+h2x2+h3x3+h4x4;
yq = QFix(yq,B,’round’,’satur’);
% Output Error Analysis
qn = yn-yq;
varyn = var(yn); varqn = var(qn);
qqmax = max(qn); qqmin = min(qn);
qnmax = max(abs([qqmax,qqmin]));
qnavg = mean(qn); qnstd = std(qn);
466
%
%
%
%
%
Outout error sequence
Signal and noise power
Maximun and minimum of the error
Absolute maximum range of the error
Mean and std dev of the error
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
qn
qn
H
H
Hmax
=
=
=
=
=
round(qn*(2^bM)/(2*qnmax)+0.5);
sort([qn,-K:1:(K+1)]);
diff(find(diff(qn)))-1;
H/N;
max(H); Hmin = min(H);
%
%
%
%
%
Normalized en (interger between -K & K)
Error histogram
Normalized histogram
Max and Min of the normalized histogram
% Output SNRs
SNR_C = 10*log10(varyn/varqn); % Computed SNR
SNR_T = 6.02 + 6.02*B + 10*log10(sum(h.*h)/Xm^2) - 10*log10(M); % Theoretical SNR
% Filter output with multi quant (1 multiplier)
yq = QFix(yn,B,’round’,’satur’);
% Output Error Analysis
qn = yn-yq;
varyn = var(yn); varqn = var(qn);
qqmax = max(qn); qqmin = min(qn);
qnmax = max(abs([qqmax,qqmin]));
qnavg = mean(qn); qnstd = std(qn);
qn = round(qn*(2^bM)/(2*qnmax)+0.5);
qn = sort([qn,-K:1:(K+1)]);
H = diff(find(diff(qn)))-1;
H = H/N;
Hmax = max(H); Hmin = min(H);
%
%
%
%
%
%
%
%
%
%
Outout error sequence
Signal and noise power
Maximun and minimum of the error
Absolute maximum range of the error
Mean and std dev of the error
Normalized en (interger between -K & K)
Error histogram
Normalized histogram
Max and Min of the normalized histogram
% Output SNRs
SNR_C = 10*log10(varyn/varqn); % Computed SNR
SNR_T = 6.02 + 6.02*B + 10*log10(sum(h.*h)/Xm^2); % Theoretical SNR
The computed and theoretical SNRs as well as output error histograms for the
two models are shown in Figure 9.39. The top plot shows the histogram when
five multipliers are used. The output error has Gaussian-like distribution with
SNR equal to 65.42 dB, which agrees with the theoretical value. The bottom
plot show the histogram when one multiplier is used. As expected, the error is
uniformly distributed with SNR equal to 72.43 dB, which also agrees with the
theoretical one.
Cascade-form realization Let the filter be realized by a cascade of
K, second-order (M = 3) sections given by
H(z) =
K
Hi (z) where Hi (z) = β0i + β1i z −1 + β2i z −2
(9.144)
i=1
as shown in Figure 9.40. The overall length of the filter is M = 2K + 1.
Figure 9.40 also shows the finite word-length model for the cascade form,
in which quantization noise sources, ei (n) 1 ≤ i ≤ K, at each section’s
Round-off Noise in FIR Filter Realizations
467
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Distribution of output error
Five Multipliers
0.0313
0.0234
SAMPLE SIZE N = 100000
FILT LENGTH M = 5
SNR(THEORY) = 65.4187
ROUNDED TO B = 12 BITS
ERROR MEAN = 1.9514e–007
SNR(COMPUTED) = 65.4241
0.0156
0.0078
0
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
Distribution of output error
One Multiplier
0.0313
0.0234
SAMPLE SIZE N = 100000
FILT LENGTH M = 5
SNR(THEORY) = 72.4084
ROUNDED TO B = 12 BITS
ERROR MEAN = 1.9514e–007
SNR(COMPUTED) = 72.4324
0.0156
0.0078
0
−0.5
−0.4
−0.3
−0.2
0
0.1
−0.1
Normalized error
0.2
0.3
0.4
0.5
FIGURE 9.39 Multiplication quantization effects for the direct-form FIR filter
in Example 9.32
output are incorporated. Let y(n) be the output due to input x(n), and
let q(n) be the output due to all noise sources. We make the following
reasonable assumptions:
1. The sections are implemented using the MAC (multiply-accumulate)
architecture so that there is only one independent noise source in each
section that contributes to ei (n). The other possibility of three multipliers in each section is straightforward.
2. The noise sources are independent of each other—that is,
ei (n) ⊥ ej (n)
for i = j
3. Each noise source is white with σe2i = 2−2B /12.
x (n)
H1(z)
H2(z)
e1(n)
yˆ (n) = y (n) + q (n)
HK (z)
e2(n)
eK−1(n)
eK (n)
FIGURE 9.40 Cascade form FIR filter structure with noise sources inserted for
multiplication quantization
468
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
We will now consider the issues of round-off noise and scaling (to prevent
overflow) for the cascade-form realization.
Round-off noise Let the noise impulse response at the output from
the ei (n) node be denoted by gi (n). Then the length of gi (n) is equal to
(M − 2i). Let qi (n) be the output noise due to ei (n). Then its power is
given by
M
−2i
M −2i
2−2B |gi (n)|2 =
|gi (n)|2
(9.145)
σq2i = σe2i
12
0
0
K
Since q(n) = i=1 qi (n) we obtain the total noise power as
K M −2i
K
−2B
2
σq2 =
(9.146)
σq2i =
|gi (n)|2
12
i=1
i=1 n=1
K M −2i
The expression i=1 n=1 |gi (n)|2 shows that the error power depends
on the order of the cascade connections. It has been shown that for the
majority of the orderings the noise power is approximately the same.
Scaling to prevent overflow From Figure 9.40 we note that one must
prevent overflow at each node. Let hk (n) be the impulse response at each
node k; then we need a scaling constant Xmax as
Xmax =
maxk
1
|hk (n)|
so that |y(n)| ≤ 1. Clearly, this is a very conservative value. A better
approach
is to scale the impulse responses of every section {hi (n)} so
that
|hi | = 1 for each i. Hence the output of every section is limited
between −1 and +1 if the input x(n) is distributed over the same interval.
Assuming that x(n) is uniformly distributed over [−1, +1] and is white,
the output signal power is
σy2 = σx2
M
−1
|h(n)|2 =
0
M −1
1 |h(n)|2
3 0
(9.147)
where h(n) is the overall impulse response of the filter. Let ĝi be the
corresponding scaled impulse responses in (9.146). Now the output SNR
can be computed as
M −1
σy2
|h(n)|2
2(B+1) 0
SNR = 2 = 2
(9.148)
K M −2i
σq
2
i=1
n=1 |ĝi (n)|
or
SNRdB = 6.02(B+1)+10 log10
M −1
0
|h(n)|
2
−10 log10
K M −2i
|ĝi (n)|
2
i=1 n=1
(9.149)
Round-off Noise in FIR Filter Realizations
469
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ANALYSIS
USING
MATLAB
Using the casfiltr function, we can compute the output of the infiniteprecision cascade structure. Using the scaling approach outlined above,
each second-order section can be scaled and used in the simulation of
quantized outputs. Again, all calculations can be done in vector fashion,
which improves the execution speed. These and other simulation steps are
detailed in the following example.
Consider the fourth-order FIR filter given in Example 9.32. Its cascade-form
realization has two sections along with a gain constant b0 , which can be obtained
using the dir2cas function:
EXAMPLE 9.33
H1 (z) = 1+1.4859z −1 +2.8901z −2 ,
H2 (z) = 1+0.5141z −1 +0.3460z −2 , and b0 = 0.1
(9.150)
Note that some of the above coefficients are greater than 1, which will cause
problems with coefficient quantization when only B fractional bits are used.
Hence we need to scale each section as explained above. The scaled values are
Ĥ1 (z) = 0.1860 + 0.2764z −1 + 0.5376z −2 ,
Ĥ2 (z) = 0.5376 + 0.2764z −1 + 0.1860z −2
(9.151)
and b̂0 = 1. Thus we do not need to scale the input. Now ĝ1 (n) = ĥ2 (n) and
ĝ2 (n) = 1 in (9.148). Thus, from (9.149) the output SNR is 70.96 dB, which
compares well with the one-multiplier direct-form implementation (72.41 dB).
These calculations and error histogram plotting are illustrated in the following
MATLAB script.
% Example Parameters
B = 12;
% # of fractional bits
N = 100000;
% # of samples
xn = (2*rand(1,N)-1);
% Input sequence - Uniform Distribution
h = [0.1,0.2,0.4,0.2,0.1]; % Filter parameters
M = length(h);
% Filter length
[b0,Bh,Ah] = dir2cas(h,1); % Cascade sections
h1 = Bh(1,:);
% Section-1
h2 = Bh(2,:);
% Section-2
h1 = h1/sum(h1);
% Scaled so Gain=1
h2 = h2/sum(h2);
% Scaled so Gain=1
% Local variables
bM = 7; DbM = 2^bM;
% bin parameter
BB = 2^B;
% useful factor in quantization
K = round(DbM/2);
% Half number of bins
bins = [-K+0.5:1:K-0.5]; % Bin values from -K to K
Q = bins/DbM;
% Normalized bins
YTN = 2^(-bM);
% Ytick marks interval
YLM = 20*YTN;
% Yaxis limit
% Quantize the input and the filter coefficients
h1 = QFix(h1,B,’round’,’satur’); % h1 quantized to B bits
h2 = QFix(h2,B,’round’,’satur’); % h1 quantized to B bits
xn = QFix(xn,B,’round’,’satur’); % Input quantized to B bits
470
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Filter output without multiplication quantization
yn = casfiltr(b0,Bh,Ah,xn); % output using Casfiltr routine
% Filter output with multi quant (1 multiplier/section)
xq = QFix(xn,B,’round’,’satur’); % Section-1 scaled input
wn = filter(h1,1,xq);
% Sec-1 unquantized output
wq = QFix(wn,B,’round’,’satur’); % Sec-1 quantized output
wq = QFix(wq,B,’round’,’satur’); % Section-2 scaled input
yq = filter(h2,1,wq);
% Sec-2 unquantized output
yq = QFix(yq,B,’round’,’satur’); % Sec-2 quantized output
% Output Error Analysis
qn = yn-yq;
% Outout error sequence
varyn = var(yn); varqn = var(qn);
% Signal and noise power
qqmax = max(qn); qqmin = min(qn);
% Maximun and minimum of the error
qnmax = max(abs([qqmax,qqmin]));
% Absolute maximum range of the error
qnavg = mean(qn); qnstd = std(qn);
% Mean and std dev of the error
qn = round(qn*(2^bM)/(2*qnmax)+0.5); % Normalized en (interger between -K & K)
qn = sort([qn,-K:1:(K+1)]);
%
H = diff(find(diff(qn)))-1;
% Error histogram
H = H/N;
% Normalized histogram
Hmax = max(H); Hmin = min(H);
% Max and Min of the normalized histogram
% Output SNRs
SNR_C = 10*log10(varyn/varqn); % Computed SNR
SNR_T = 6.02*(B+1) + 10*log10(sum(h.*h)) ...
- 10*log10(1+sum(h2.*h2)); % Theoretical SNR
The plot is shown in Figure 9.41. The error distribution appears to have a
Gaussian envelope, but the error is not continuously distributed. This behavior
Cascade Structure
Distribution of output error
0.1563
SAMPLE SIZE N = 100000
FILT LENGTH M = 5
SNR(THEORY) = 70.9563
ROUNDED TO B = 12 BITS
ERROR MEAN = 1.9514e–007
SNR(COMPUTED) = 70.8517
0.1172
0.0781
0.0391
0
−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
Normalized error
FIGURE 9.41 Multiplication quantization effects for the cascade-form FIR filter
in Example 9.33
Round-off Noise in FIR Filter Realizations
471
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
indicates that the output error takes only a fixed set of values, which is due
to a particular set of coefficient values. The computed SNR is 70.85 dB,
which agrees with the above theoretical value. Thus, our assumptions are
reasonable.
FLOATINGPOINT
ARITHMETIC
Analysis for the floating-point arithmetic is more complicated and tedious.
Hence we will consider only the direct-form realization with simplified
assumptions. Figure 9.42 shows a direct-form realization with a floatingpoint arithmetic model. In this realization, {ηi (n)}, 1 ≤ i ≤ M − 1 are
the relative errors in adders and {εi (n)}, 0 ≤ i ≤ M − 1 are the relative
errors in multipliers, with |ηi | ≤ 2−2B and |εi | ≤ 2−2B .
Let A(n, k) be the gain from the k-th multiplier to the output node,
which is given by

M −1
 (1 + εk (n)) r=k (1 + ηr (n)) ,
A(n, k) =

(1 + ε0 (n))
M −1
r=k
k = 0;
(9.152)
(1 + ηr (n)) ,
k = 0.
Let ŷ(n) = y(n) + q(n) be the overall output where y(n) is the output
due to the input x(n) and q(n) is the output due to noise sources. Then
M
−1
ŷ(n) =
A(n, k) h(k) x(n − k)
(9.153)
k=0
Subtracting y(n) =
M −1
k=0
h(k) x(n − k) from (9.153), we obtain
M
−1
q(n) =
{A(n, k) − 1} h(k) x(n − k)
(9.154)
k=0
z −1
x(n)
z −1
z −1
h(0)
h(1)
h(2)
h(3)
1 + e0(n)
1 + e1(n)
1 + e2(n)
1 + e3(n)
1
1 + h1(n)
z −1
1 + h2(n)
h(M − 2)
h(M − 1)
1 + eM−2(n)
1 + eM−1(n)
1 + hM−2(n)
1 + hM−1(n)
y(n) + q(n)
FIGURE 9.42 Multiplication quantization model for direct-form floating-point
implementation of an FIR filter
472
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Now from (9.152), the average value of A(n, k) is EA(n, k) = 1 and the
average power of A(n, k) is
E[A2 (n, k)] =
1+
1 −2B
2
3
M +1−k
≈ 1 + (M + 1 − k)
2−2B
3
for small 2−2B
(9.155)
Assuming that the input signal x(n) is also a white sequence with variance
σx2 , then from (9.155) the noise power is given by
σq2 =
M −1
k
(M + 1)2−2B 2 σx
|h(k)|2 1 −
3
M +1
(9.156)
k=0
Since (1 − Mk+1 ) ≤ 1 and using σy2 = σx2
is upper bounded by
σq2 ≤ (M + 1)
M −1
k=0
|h(k)|2 the noise power σq2
2−2B 2
σy
3
(9.157)
or the SNR is lower bounded by
SNR ≥
3
22B
M +1
(9.158)
Equation (9.158) shows that it is best to compute products in order of
increasing magnitude.
EXAMPLE 9.34
Again consider the fourth-order FIR filter given in Example 9.32 in which
M = 5, B = 12, and h(n) = {0.1, 0.2, 0.4, 0.2, 0.1}. From (9.158), the SNR
is lower bounded by
SNRdB ≥ 10 log10
3
224
M +1
= 69.24 dB
and the approximate value from (9.156) is 71 dB, which is comparable to the
fixed-point value of 72 dB. Note that the fixed-point results would degrade with
less than optimum scaling (e.g., if signal amplitude were 10 dB down), whereas
the floating point SNR would remain the same. To counter this, one could put a
variable scaling factor A on the fixed-point system, which is then getting close to
the full floating-point system. In fact, floating-point is nothing but fixed-point
with variable scaling—that is, a scaling by a power of two (or shifting) at each
multiplication and addition.
Round-off Noise in FIR Filter Realizations
473
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
PROBLEMS
P9.1 MATLAB provides the built-in functions dec2bin and bin2dec to convert non-negative
decimal integers into binary codes and vice versa, respectively.
1. Develop a function B = sm2bin(D) to convert a sign-magnitude format decimal integer D
into its binary representation B. Verify your function on the following numbers:
(a) D = 1001
(b) D = −63
(c) D = −449
(d) D = 978
(e) D = −205
2. Develop a function D = bin2sm(B) to convert a binary representation B into its signmagnitude format decimal integer D. Verify your function on the following
representations:
(a) B = 1010
(d) B = 1010101
(b) B = 011011011
(e) B = 011011
(c) B = 11001
P9.2 Using the function TwosComplement as a model, develop a function y = TensComplement
(x,N) that converts a sign-magnitude format integer x into the N -digit ten’s-complement
integer y.
1. Verify your function using the following integers:
(a) x = 1234, N = 6
(d) x = −1978, N = 6
(b) x = −603, N = 4
(e) x = 50, N = 3
(c) x = −843, N = 5
2. Using the ten’s-complement format, perform the following arithmetic operations. In each
case, choose an appropriate value on N for the meaningful result.
(a) 123 + 456 − 789
(d) −968 + 4539
(b) 648 + 836 − 452
(e) 888 − 666 + 777
(c) 2001 + 3756
Verify your results using decimal operations.
P9.3 The function OnesComplement developed in this chapter converts signed integers into one’scomplement format decimal representations. In this problem we will develop functions that
will operate on fractional numbers.
1. Develop a MATLAB function y = sm2oc(x, B) that converts the sign-magnitude format
fraction x into the B-bit one’s-complement format decimal equivalent number y. Verify
your function on the following numbers. In each case the numbers to be considered are
both positive and negative. Also, in each case select the appropriate number of bits B.
(a) x = ±0.5625
(d) x = ±0.1328125
(b) x = ±0.40625
(e) x = ±0.7314453125
(c) x = ±0.953125
2. Develop a MATLAB function x = oc2sm(y, B) that converts the B-bit one’s-complement
format decimal equivalent number y into the sign-magnitude format fraction x. Verify
your function on the following fractional binary representations:
(a) y = 1 10110
(d) y = 1 11101110
(b) y = 0. 011001
(e) y = 0 00010001
(c) y = 1 00110011
P9.4 The function TwosComplement developed in this chapter converts signed integers into two’scomplement format decimal representations. In this problem we will develop functions that
will operate on fractional numbers.
474
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1. Develop a MATLAB function y = sm2tc(x, B) that converts the sign-magnitude format
fraction x into the B-bit two’s-complement format decimal equivalent number y. Verify
your function on the following numbers. In each case the numbers to be considered are
both positive and negative. Also, in each case select the appropriate number of bits B.
(a) x = ±0.5625
(d) x = ±0.1328125
(b) x = ±0.40625
(f) x = ±0.7314453125
(c) x = ±0.953125
Compare your representations with those in Problem P9.3 part 1.
2. Develop a MATLAB function x = tc2sm(y, B) that converts the B-bit two’s-complement
format decimal equivalent number y into the sign-magnitude format fraction x. Verify
your function on the following fractional binary representations:
(a) y = 1 10110
(d) y = 1 11101110
(b) y = 0. 011001
(e) y = 0 00010001
(c) y = 1 00110011
Compare your representations with those in Problem P9.3 part 2.
P9.5 Determine the 10-bit sign-magnitude, one’s-complement, and two’s-complement
representation of the following decimal numbers:
(a) 0.12345
(b) −0.56789
(c) 0.38452386
(d) −0.762349
(e) −0.90625
P9.6 Consider a 32-bit floating-point number representation with a 6-bit exponent and a 25-bit
mantissa.
1. Determine the value of the smallest number that can be represented.
2. Determine the value of the largest number that can be represented.
3. Determine the dynamic range of this floating-point representation and compare it with
the dynamic range of a 32-bit fixed-point signed integer representation.
P9.7 Show that the magnitudes of floating-point numbers in a 32-bit IEEE standard range from
1.18 × 10−38 to 3.4 × 1038 .
P9.8 Let
H(z) =
b0
b0
=
(1 − r ejθ z −1 ) (1 − r e−jθ z −1 )
(1 + a1 z −1 + a2 z −2 )
be a second-order filter implemented in a direct-form structure where a1 = −2r cos θ and
a2 = r 2 .
1. Assume that the coefficients a1 and a2 are represented in sign-magnitude format with
4 bits. Then there are 15 non-zero values for a1 and a2 each in the first quadrant of the
z-plane. Using MATLAB, plot the pole distribution of a stable second-order structure in
the first quadrant.
2. Assume that r is represented in sign-magnitude format with 4 bits and that the angle θ
is represented using 16 uniform levels between 0◦ and 90◦ (i.e., θk = 5.625k,
k = 0, 1, . . . , 16). Using MATLAB, plot the pole distribution in the first quadrant.
3. Compare the number of possible pole positions in each case above.
P9.9 Compute and plot the truncation error characteristics when B = 4 for the sign-magnitude,
one’s-complement, and two’s-complement formats.
P9.10 Consider the third-order elliptic lowpass filter designed in Example 8.20:
H(z) =
Problems
0.1214 1 − 1.4211z −1 + z −2
(1 −
1.4928z −1
+
0.8612z −2 ) (1
1 + z −1
− 0.6183z −1 )
475
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
1. If the filter is realized using a direct-form structure, determine its pole sensitivity.
2. If the filter is realized using a cascade-form structure, determine its pole sensitivity.
P9.11 Consider the filter described by the difference equation
√
1
y(n) = √ y(n − 1) − x(n) + 2x(n − 1)
2
(9.159)
1. Show that this filter is an all-pass filter (i.e., |H(ejω )|) is a constant over the entire
frequency range −π ≤ ω ≤ π. Verify your answer by plotting the magnitude response
|H(ejω )| over the normalized frequency range 0 ≤ ω/π ≤ 1. Use subplot(3,1,1).
2. Round the coefficients of the difference equation in (9.159) to 3 decimals. Is the filter
still all-pass? Verify your answer by plotting the resulting magnitude response, |Ĥ1 (ejω )|,
over the normalized frequency range 0 ≤ ω/π ≤ 1. Use subplot(3,1,2).
3. Round the coefficients of the difference equation in (9.159) to 2 decimals. Is the filter
still all-pass? Verify your answer by plotting the resulting magnitude response, |Ĥ2 (ejω )|,
over the normalized frequency range 0 ≤ ω/π ≤ 1. Use subplot(3,1,3).
4. Explain why the magnitude |Ĥ1 (ejω )| is “different” from the magnitude |Ĥ2 (ejω )|.
P9.12 Using an elliptic prototype, design a digital lowpass filter to meet the specifications of
0.5-dB ripple in the passband, 60-dB ripple in the stopband, a passband edge-frequency
ωp = 0.25π, and a stopband edge-frequency ωs = 0.3π.
1. Using infinite precision, plot the log-magnitude and phase responses of the designed
filter. Use two rows and one column of subplots.
2. Quantize the direct-form coefficients to 4 decimals (by rounding). Now plot the
log-magnitude and phase responses of the resulting filter. Use two rows and one column
of subplots.
3. Quantize the direct form coefficients to 3 decimals (by rounding). Now plot the
log-magnitude and phase responses of the resulting filter. Use two rows and one column
of subplots.
4. Comment on the plots in the above three parts.
P9.13 Consider the digital lowpass filter design in Problem P9.12 above.
1. Using infinite precision and cascade-form realization, plot the log-magnitude and phase
responses of the designed filter. Use two rows and one column of subplots.
2. Quantize the cascade-form coefficients to 4 decimals (by rounding). Now plot the
log-magnitude and phase responses of the resulting filter. Use two rows and one column
of subplots.
3. Quantize the cascade-form coefficients to 3 decimals (by rounding). Now plot the
log-magnitude and phase responses of the resulting filter. Use two rows and one column
of subplots.
4. Comment on the plots in the above three parts and compare them with the similar plots
in Problem P9.12.
P9.14 Using the Parks-McClellan algorithm, design a 32-length linear-phase bandpass filter to
satisfy the requirements of 60-dB stopband attenuation, lower stopband edge-frequency
ωs1 = 0.2π, and upper stopband edge-frequency ωs2 = 0.8π. Since no other requirements are
given, you are free to choose any additional needed parameters.
1. Using infinite precision, plot the log-magnitude and amplitude responses of the designed
filter. Use two rows and one column of subplots.
476
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4.0635
4.0635
−0.0793
−1.6
−0.63
z −1
−0.0815
z −1
−2.8255
z −1
0.4
−0.03
0.7747
z −1
−0.2076
−0.5502
x(n)
−0.8
−0.15
z −1
−0.2245
y (n)
z −1
1.2
z −1
0.1319
z −1
−0.35
−0.0304
−2.4609
z −1
−0.1
FIGURE P9.1
−0.9
z −1
Structure for Problem P9.15
2. Quantize the direct-form coefficients to 4 decimals (by rounding). Now plot the
log-magnitude and amplitude responses of the resulting filter. Use two rows and one
column of subplots.
3. Quantize the direct-form coefficients to 3 decimals (by rounding). Now plot the
log-magnitude and amplitude responses of the resulting filter. Use two rows and one
column of subplots.
4. Comment on the plots in the above three parts.
5. Based on the results of this problem determine how many significant bits (and not
decimals) are needed in practice to represent FIR direct-form realizations.
P9.15 The digital filter structure shown in Figure P9.1 is a cascade of two parallel sections and
corresponds to a 10th -order IIR digital filter system function
H(z) =
1 − 2.2z −2 + 1.6368z −4 − 0.48928z −6 + 5395456 × 10−8 z −8 − 147456 × 10−8 z −10
1 − 1.65z −2 + 0.8778z −4 − 0.17281z −6 + 1057221 × 10−8 z −8 − 893025 × 10−10 z −10
1. Due to an error in labeling, two of the multiplier coefficients (rounded to 4 decimals) in
this structure have incorrect values. Locate these two multipliers and determine their
correct values.
2. By inspecting the pole locations of the system function H(z) you should realize that the
above structure is sensitive to the coefficient quantization. Suggest, with justification, an
alternative structure that in your opinion is least sensitive to coefficient quantization.
Problems
477
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P9.16 Design a Chebyshev-II bandstop digital filter that satisfies the following requirements:
0.95
0
0.95
≤
≤
≤
|H(ejω )|
|H(ejω )|
|H(ejω )|
≤
≤
≤
1.05,
0.01,
1.05,
≤
≤
≤
0
0.35π
0.75π
|ω|
|ω|
|ω|
≤
≤
≤
0.25π
0.65π
π
1. Using infinite precision, provide the log-magnitude response plot and the pole-zero plot
of the designed filter.
2. Assuming direct-form structure and a 12-bit representation for filter coefficients, provide
the log-magnitude response plot and the pole-zero plot of the designed filter. Use the
Qcoeff function.
3. Assuming cascade-form structure and a 12-bit representation for filter coefficients,
provide the log-magnitude response plot and the pole-zero plot of the designed filter. Use
the Qcoeff function.
P9.17 Design a Butterworth digital lowpass filter to satisfy the following specifications:
passband edge:
stopband edge:
0.4π,
0.6π,
Rp = 0.5 dB
As = 50 dB
1. Using infinite precision, provide the magnitude response plot and the pole-zero plot of
the designed filter.
2. Assuming direct-form structure and a 10-bit representation for filter coefficients, provide
the magnitude response plot and the pole-zero plot of the designed filter. Use the Qcoeff
function.
3. Assuming cascade-form structure and a 10-bit representation for filter coefficients,
provide the magnitude response plot and the pole-zero plot of the designed filter. Use
the Qcoeff function.
P9.18 Design an elliptic highpass filter to satisfy the following specifications:
stopband edge:
passband edge:
0.4π,
0.6π,
As = 60 dB
Rp = 0.5 dB
1. Using infinite precision, provide the magnitude response plot and the pole-zero plot of
the designed filter.
2. Assuming direct-form structure and a 10-bit representation for filter coefficients, provide
the magnitude response plot and the pole-zero plot of the designed filter. Use the Qcoeff
function.
3. Assuming parallel-form structure and a 10-bit representation for filter coefficients,
provide the magnitude response plot and the pole-zero plot of the designed filter. Use
the Qcoeff function.
P9.19 Design a bandstop filter using the Parks-McClellan algorithm. The specifications are as
follows:
lower stopband edge:
upper stopband edge:
lower passband edge:
upper passband edge:
0.4π
0.6π
0.3π
0.7π
As = 50 dB
Rp = 0.2 dB
1. Using infinite precision, provide the magnitude response plot and the pole-zero plot of
the designed filter.
478
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
2. Assuming direct-form structure and a 14-bit representation for filter coefficients, provide
the magnitude response plot and the pole-zero plot of the designed filter. Use the Qcoeff
function.
3. Assuming cascade-form structure and a 14-bit representation for filter coefficients,
provide the magnitude response plot and the pole-zero plot of the designed filter. Use
the Qcoeff function.
P9.20 Design a linear-phase FIR digital filter, using the Kaiser window technique, that meets the
following specifications:
0
0.95
0
≤
≤
≤
|H(ejω )|
|H(ejω )|
|H(ejω )|
≤
≤
≤
0.01,
1.05,
0.01,
0
0.35π
0.75π
≤
≤
≤
ω
ω
ω
≤
≤
≤
0.25π
0.65π
π
1. Using infinite precision, provide the magnitude response plot and the pole-zero plot of
the designed filter.
2. Assuming direct-form structure and a 10-bit representation for filter coefficients, provide
the magnitude response plot and the pole-zero plot of the designed filter. Use the Qcoeff
function.
3. Assuming cascade-form structure and a 10-bit representation for filter coefficients,
provide the magnitude response plot and the pole-zero plot of the designed filter. Use
the Qcoeff function.
P9.21 Let x(n) = 0.5[cos(n/17) + sin(n/23)]. For the following parts, use 500, 000 samples of x(n)
and the StatModelR function.
1. Quantize x(n) to B = 2 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
2. Quantize x(n) to B = 4 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
3. Quantize x(n) to B = 6 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
P9.22 Let x(n) = 13 [cos(0.1πn) + sin(0.2πn) + sin(0.4πn)]. For the following parts use 500, 000
samples of x(n) and the StatModelR function.
1. Quantize x(n) to B = 2 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
2. Quantize x(n) to B = 4 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
3. Quantize x(n) to B = 6 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
P9.23 Let a real, causal, and stable IIR filter be given by
N −1
H(z) = R0 +
k=1
Rk
z − pk
(9.160)
where all poles are distinct. Using (9.70), (9.72a), and (9.160) show that
−1
N
−1 N
σq2
Rk R∗
2
=
R
+
0
1 − pk p∗
σe2
k=1 =1
Problems
479
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P9.24 Consider the lowpass digital filter designed in Problem P9.17. The input to this filter is an
independent and identically distributed Gaussian sequence with zero-mean and variance
equal to 0.1.
1. Determine the variance of the filter output process using the VarGain function.
2. Determine numerically the variance of the output process by generating 500,000 samples
of the input sequence. Comment on your results.
P9.25 Design an elliptic bandpass digital filter that has a lower stopband of 0.3π, a lower passband
of 0.4π, an upper passband of 0.5π, and an upper stopband of 0.65π. The passband ripple is
0.1 dB and the stopband attenuation is 50 dB. The input signal is a random sequence
whose components are independent and uniformly distributed between −1 and 1.
1. Determine the variance of the filter output process using the VarGain function.
2. Determine numerically the variance of the output process by generating 500,000 samples
of the input sequence. Comment on your results.
P9.26 Consider the first-order recursive system y(n) = 0.75 y(n − 1) + 0.1δ(n) with zero initial
conditions. The filter is implemented in 4-bit (including sign) fixed-point two’s-complement
fractional arithmetic. Products are rounded to 4-bits.
1. Determine and plot the first 20 samples of the output using saturation limiter for the
addition. Does the filter go into a limit cycle?
2. Determine and plot the first 20 samples of the output using two’s-complement overflow
for the addition. Does the filter go into a limit cycle?
P9.27 Repeat Problem P9.26 when products are truncated to 4 bits.
P9.28 Consider the second-order recursive system y(n) = 0.1δ(n) − 0.875 y(n − 2) with zero initial
conditions. The filter is implemented in 5-bit (including sign) fixed-point two’s-complement
fractional arithmetic. Products are rounded to 4-bits.
1. Determine and plot the first 30 samples of the output using a saturation limiter for the
addition. Does the filter go into a limit cycle?
2. Determine and plot the first 30 samples of the output using two’s-complement overflow
for the addition. Does the filter go into a limit cycle?
P9.29 Repeat Problem P9.28 when products are truncated to 5 bits.
P9.30 Let x(n) = 14 [sin(n/11) + cos(n/13) + sin(n/17) + cos(n/19)] and c = 0.7777. For the
following parts use 500, 000 samples of x(n) and the StatModelR function.
1. Quantize c x(n) to B = 4 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
2. Quantize c, x(n) to B = 8 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
3. Quantize c, x(n) to B = 12 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
P9.31 Let x(n) = be a random sequence unformly distributed between −1 and 1, and let
c = 0.7777. For the following parts use 500, 000 samples of x(n) and the StatModelR
function.
1. Quantize c x(n) to B = 4 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
480
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
2. Quantize c, x(n) to B = 8 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
3. Quantize c, x(n) to B = 12 bits and plot the resulting distributions for the error signals
e1 (n) and e2 (n). Comment on these plots.
P9.32 Consider an LTI system with the input x(n) and output y(n)
y(n) = b0 x(n) + b1 x(n − 1) + a1 y(n − 1)
(9.161)
1. Draw the direct-form I structure for the above system.
2. Let eb0 (n) denote the multiplication quantization error resulting from the product
b0 x(n), eb1 (n − 1) from the product b1 x(n − 1), and ea1 (n − 1) from the product
a1 y(n − 1) in the direct-form I realization. Draw an equivalent structure that contains
only one noise source.
3. Draw an equivalent system that can be used to study multiplication quantization error
for the system in (9.161). The input to this system should be the noise source in part 2
above, and the output should be the overall output error e(n).
4. Using the model in part 3 above, determine an expression for the variance of the output
error e(n).
P9.33 Let the system be given by y(n) = a y(n − 1) + x(n). Let a = 0.7, which is quantized to B
(fractional) bits in the filter realization. Let the input sequence be x(n) = sin(n/11), which
is properly scaled to avoid overflow in the adder and quantized to B bits prior to filtering.
The multiplications in the filtering operations are also quantized to B bits.
1. Let B = 5. Generate 100,000 samples of x(n) and filter through the system with
multiplication quantization. Compute the true output, the quantized output, the output
error, and the output SNR. Provide a plot of normalized histogram and comment on the
results.
2. Let B = 10. Generate 100,000 samples of x(n) and filter through the system with
multiplication quantization. Compute the true output, the quantized output, the output
error, and the output SNR. Provide a plot of normalized histogram and comment on the
results.
P9.34 Let the system be given by y(n) = a y(n − 1) + x(n). Let a = 0.333, which is quantized to B
(fractional) bits in the filter realization. Let the input sequence be x(n) = sin(n/11), which
is properly scaled to avoid overflow in the adder and quantized to B bits prior to filtering.
The multiplications in the filtering operations are also quantized to B bits.
1. Let B = 5. Generate 100,000 samples of x(n) and filter through the system with
multiplication quantization. Compute the true output, the quantized output, the output
error, and the output SNR. Provide a plot of normalized histogram and comment on the
results.
2. Let B = 10. Generate 100,000 samples of x(n) and filter through the system with
multiplication quantization. Compute the true output, the quantized output, the output
error, and the output SNR. Provide a plot of normalized histogram and comment on the
results.
P9.35 Consider the second-order IIR filter given in (9.105) with r = 0.8 and θ = π/4. The input to
this filter is x(n) = sin(n/23).
1. Investigate the multiplication quantization error behavior of this filter for B = 5 bits.
Determine the true output SNR, the computed output SNR, and the upper and lower
Problems
481
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
bounds of the SNR. Plot the normalized histogram of the output error.
2. Investigate the multiplication quantization error behavior of this filter for B = 10 bits.
Determine the true output SNR, the computed output SNR, and the upper and lower
bounds of the SNR. Plot the normalized histogram of the output error.
P9.36 Consider the second-order IIR filter given in (9.105) with r = 0. − 8 and θ = 2π/3. The
input to this filter is x(n) = sin(n/23).
1. Investigate the multiplication quantization error behavior of this filter for B = 5 bits.
Determine the true output SNR, the computed output SNR, and the upper and lower
bounds of the SNR. Plot the normalized histogram of the output error.
2. Investigate the multiplication quantization error behavior of this filter for B = 10 bits.
Determine the true output SNR, the computed output SNR, and the upper and lower
bounds of the SNR. Plot the normalized histogram of the output error.
P9.37 Consider a fifth-order FIR system given by
H(z) = 0.1 + 0.2z −1 + 0.3z −2 + 0.3z −3 + 0.2z −4 + 0.1z −5
which is implemented in a direct form using B = 10 bits.
1. Investigate the multiplication quantization errors when all six multipliers are used in the
implementation. Provide a plot of the normalized histogram of the output error.
2. Investigate the multiplication quantization errors when one multiplier is used in the
implementation. Provide a plot of the normalized histogram of the output error.
P9.38 Consider a fourth-order FIR system given by
H(z) = 0.1 + 0.2z −1 + 0.3z −2 + 0.2z −3 + 0.1z −4
which is implemented in a cascade form containing second-0rder sections.
1. Investigate the multiplication quantization errors when B = 6 bits is used in the
implementation. Provide a plot of the normalized histogram of the output error.
2. Investigate the multiplication quantization errors when B = 12 bits is used in the
implementation. Provide a plot of the normalized histogram of the output error.
482
Chapter 9
FINITE WORD-LENGTH EFFECTS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
10
Sampling Rate
Conversion
In many practical applications of digital signal processing, one is faced
with the problem of changing the sampling rate of a signal, either increasing it or decreasing it by some amount. The process of converting a signal
from a given rate to a different rate is called sampling rate conversion.
In turn, systems that employ multiple sampling rates in the processing
of digital signals are called multirate digital signal processing systems. In
this chapter we describe sampling rate conversion and multirate signal
processing in the digital domain.
As an example, consider the system shown in Figure 10.1 in which
an analog signal xa (t) is sampled using the sampling rate of Fs = T1
samples/second. The resulting digital signal x(n) is subsequently filtered
using a lowpass filter (LPF) with a cutoff frequency of ωc .
Thus, the output signal y(n) has all its energy in the band 0 ≤ ω ≤
ωc = 2πfc . According to the sampling theorem, such a signal may be represented by the rate of 2fc /T samples/second instead of its existing rate
of Fs = 1/T . Note that |fc | ≤ 0.5. However, if fc 0.5, then 2fc /T Fs .
Hence it would seem more advantageous to lower the sampling frequency
to a value closer to 2fc /T and perform signal processing operations at
this lower rate.
Other applications include the need for an optimal interpolation in
computer tomography and efficient multistage designs of narrowband lowpass filters.
483
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ADC
Fs = 1
T
xa(t )
Xa(Ω)
−p /T
0
FIGURE 10.1
Lowpass
Filter
wc
x (n)
y (n)
H (w)
p /T
Ω
−p
Y (w)
-w c 0 w c
p
w
−p
−w c 0 w c
p
w
A typical signal processing system
INTRODUCTION
The idea of interpolation is a very familiar concept to most of us and has
its origin in numerical analysis. Typically, interpolation is performed on a
table of numbers representing a mathematical function. Such a table may
be printed in a handbook or stored in a computer memory device. The
interpolation, often simply linear (or straight line) approximation, creates an error called the interpolation error. The main difference between
interpolation in digital signal processing and interpolation in numerical
analysis is that we will assume that the given data is bandlimited to some
band of frequencies and develop schemes that are optimal on this basis, whereas a numerical analyst typically assumes that the data consists
of samples of polynomials (or very nearly so) and develops schemes to
minimize the resulting error.
To motivate this concept of interpolation in signal processing, it is
helpful to think of an underlying (or original) analog signal xa (t) that
was sampled to produce the given discrete signal x(n). If the xa (t) was
sampled at the minimum required rate, then, according to the sampling
theorem, it can be recovered completely from the samples x(n). If we now
sample this recovered analog signal, at say twice the old rate, we have
succeeded in doubling the sampling rate or interpolating by a factor of 2
with zero interpolation error. Specifically, we have:
(10.1)
Original discrete signal: x(n) = xa (nT )
Reconstructed analog signal:
484
xa (t) =
k
xa (kT )
Chapter 10
sin[π(t − kT )/T ]
(10.2)
π(t − kT )/T
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
sin π m T2 − kT /T
T
T
=
Resampled analog signal: xa m
xa (kT )
2
π m 2 − kT /T
k
=
k
−k
sin π m
2
xa (kT )
π m
2 −k
resulting in high-rate discrete signal :
(10.3)
T
y(m)=xa m
2
(10.4)
In the above formulation of ideal interpolation, the discrete signal was
converted to the analog signal and then back to the discrete signal at
twice the rate. In the subsequent sections we will study how to avoid this
roundabout approach and perform sampling rate conversion completely
in the digital domain.
The process of sampling rate conversion in the digital domain can
be viewed as a linear filtering operation, as illustrated in Figure 10.2(a).
The input signal x(n) is characterized by the sampling rate Fx = 1/Tx ,
and the output signal y(m) is characterized by the sampling rate Fy =
1/Ty , where Tx and Ty are the corresponding sampling intervals. In our
treatment, the ratio Fy /Fx is constrained to be rational
Fy
I
=
Fx
D
(10.5)
where D and I are relatively prime integers. We shall show that the
linear filter is characterized by a time-variant impulse response, denoted
x (n)
Rate Fx =
Linear Filter
h(n, m)
1
Ty
y (m)
Fy =
(a)
1
Ty
y (m)
y (m + 1)
ti
x (n + 2)
x (n)
x (n + 3)
x (n + 4)
x (n + 5)
x (n + 1)
y (m + 2)
y (m + 3)
y (m + 4)
y (m + 5) y (m + 6)
(b)
FIGURE 10.2
Introduction
Sampling rate conversion viewed as a linear filtering process
485
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
as h(n, m). Hence the input x(n) and the output y(m) are related by the
superposition summation for time-variant systems.
The sampling rate conversion process can also be understood from the
point of view of digital resampling of the same analog signal. Let xa (t) be
the analog signal that is sampled at the first rate Fx to generate x(n). The
goal of rate conversion is to obtain another sequence y(m) directly from
x(n), which is equal to the sampled values of xa (t) at a second rate Fy .
As is depicted in Figure 10.2(b), y(m) is a time-shifted version of x(n).
Such a time shift can be realized by using a linear filter that has a flat
magnitude response and a linear phase response (i.e., it has a frequency
response of e−ωτi , where τi is the time delay generated by the filter). If
the two sampling rates are not equal, the required amount of time shifting
will vary from sample to sample, as shown in Figure 10.2(b). Thus, the
rate converter can be implemented using a set of linear filters that have
the same flat magnitude response but generate different time delays.
Before considering the general case of sampling rate conversion, we
shall consider two special cases. One is the case of sampling rate reduction
by an integer factor D, and the second is the case of a sampling rate
increase by an integer factor I. The process of reducing the sampling rate
by a factor D (downsampling by D) is called decimation. The process of
increasing the sampling rate by an integer factor I (upsampling by I) is
called interpolation.
DECIMATION BY A FACTOR D
The basic operation required in decimation is the downsampling of the
high-rate signal x(n) into a low-rate signal y(m). We will develop the
time- and frequency-domain relationships between these two signals to
understand the frequency-domain aliasing in y(m). We will then study
the condition needed for error-free decimation and the system structure
required for its implementation.
THE DOWNSAMPLER
Note that the downsampled signal y(m) is obtained by selecting one out
of D samples of x(n) and throwing away the other (D − 1) samples out
of every D samples—i.e.,
y(m) = x(n)|n=mD = x(mD);
n, m, D ∈ {integers}
(10.6)
The block diagram representation of (10.6) is shown in Figure 10.3. This
downsampling element changes the rate of processing and thus is fundamentally different from other block diagram elements that we have used
486
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
↓D
x(n)
Rate Fx
FIGURE 10.3
y(m)
Fx
Rate Fy =
D
A downsampling element
previously. In fact, we can show that a system containing a downsampling element is shift varying. However, this fact does not prohibit the
frequency-domain analysis of y(m) in terms of x(n) as we shall see later.
EXAMPLE 10.1
Using D = 2 and x(n) = {1, 2, 3, 4, 3, 2, 1} verify that the downsampler is time
↑
varying.
Solution
The downsampled signal is y(m) = {1, 3, 3, 1}. If we now delay x(n) by one
↑
sample, we get x(n − 1) = {0, 1, 2, 3, 4, 3, 2, 1}. The corresponding downsampled
↑
signal is y1 (m) = {0, 2, 4, 2}, which is different from y(m − 1).
↑
MATLAB Implementation MATLAB provides the function [y] =
downsample(x,D) that downsamples input array x into output array y
by keeping every D-th sample starting with the first sample. An optional
third parameter “phase” specifies the sample offset which must be an
integer between 0 and (D-1). For example,
>> x = [1,2,3,4,3,2,1]; y = downsample(x,2)
y =
1
3
3
1
downsamples by a factor of 2 starting with the first sample. However,
>> x = [1,2,3,4,3,2,1]; y = downsample(x,2,1)
y =
2
4
2
produces an entirely different sequence by downsampling, starting with
the second sample (i.e., offset by 1).
The frequency-domain representation of the downsampled signal y(m) We now express Y (ω) in terms of X(ω) using z-transform
relations. Towards this we introduce a high-rate sequence x̄(n), which is
given by
x(n), n = 0, ±D, ±2D, . . .
(10.7)
x̄(n) =
0,
elsewhere.
Decimation by a Factor
D
487
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Clearly, x̄(n) can be viewed as a sequence obtained by multiplying x(n)
with a periodic train of impulses p(n), with period D, as illustrated in
Figure 10.4. The discrete Fourier series representation of p(n) is
p(n) =
1, n = 0, ±D, ±2D, . . .
0,
elsewhere.
=
D−1
1  2π
e D
D
n
(10.8)
=0
Hence we can write
x̄(n) = x(n)p(n)
(10.9)
y(m) = x̄(mD) = x(mD)p(mD) = x(mD)
(10.10)
and
as shown in (10.6). Figure 10.4 shows an example of sequences x(n), x̄(n),
and y(m) defined in (10.7)–(10.10).
x (n)
(a)
−9 −8 −7 −6 −5 −4 −3 −2 −1
0
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
n
p (n )
(b)
−9 −8 −7 −6 −5 −4 −3 −2 −1
n
0
x (n)
(c)
−9 −8 −7 −6 −5 −4 −3 −2 −1
n
0
y (m)
(d)
−3
−2
−1
0
1
2
3
m
FIGURE 10.4 Operation of downsampling: (a) Original signal x(n), (b) Periodic
impulse train p(n) with period D = 3, (c) Multiplication of x(n) with p(n), and
(d) Downsampled signal y(n)
488
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Now the z-transform of the output sequence y(m) is
Y (z) =
∞
m=−∞
Y (z) =
∞
y(m)z −m =
x̄(mD)z −m
m=−∞
(10.11)
∞
x̄(m)z
−m/D
m=−∞
where the last step follows from the fact that x̄(m) = 0, except at multiples of D. By making use of the relations in (10.7) and (10.8) in (10.11),
we obtain
Y (z) =
∞
x(m)
m=−∞
=
D−1
1 2πmk/D −m/D
z
e
D
k=0
D−1
∞
−m
1 x(m) e−2πk/D z 1/D
D
m=−∞
k=0
=
D−1
1 −2πk/D 1/D X e
z
D
(10.12)
k=0
The key steps in obtaining the z-transform representation (10.12), for the
(D ↓ 1) downsampler, are as follows:
• the introduction of the high-rate sequence x̄(n), which has (D−1) zeros
in between the retained values x(nD), and
• the impulse-train representation (10.8) for the periodic sampling series
that relates x(n) to x̄(n).
By evaluating Y (z) on the unit circle, we obtain the spectrum of the
output signal y(m). Since the rate of y(m) is Fy = 1/T y, the frequency
variable, which we denote as ωy , is in radians and is relative to the sampling rate Fy ,
ωy =
2πF
= 2πF Ty
Fy
(10.13)
Since the sampling rates are related by the expression
Fy =
Fx
D
(10.14)
it follows that the frequency variables ωy and
ωx =
Decimation by a Factor
D
2πF
2πF Tx
Fx
(10.15)
489
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
|X(wx)|
A
−p
−p3
0
p 3
p
wx
|Y(wy)|
A3
−3p
FIGURE 10.5
−2p
−p
p
0
2p
3p
wy
Spectra of x(n) and y(m) in no-aliasing case
are related by
(10.16)
ωy = Dωx
Thus, as expected, the frequency range 0 ≤ |ωx | ≤ π/D is stretched into
the corresponding frequency range 0 ≤ |ωy | ≤ π by the downsampling
process.
We conclude that the spectrum Y (ωy ), which is obtained by evaluating (10.12) on the unit circle, can be expressed as1
Y (ωy ) =
D−1
ωy − 2πk
1 X
D
D
(10.17)
k=0
which is an aliased version of the spectrum X(ωx ) of x(n). To avoid aliasing error, one needs the spectrum X(ωx ) to be less than full band or
bandlimited (note that this bandlimitedness is in the digital frequency
domain). In fact we must have
X(ωx ) = 0
for
π
≤ |ωx | ≤ π
D
(10.18)
Then,
ωy
1
(10.19)
X
, |ωy | ≤ π
D
D
and no aliasing error is present. An example of this for D = 3 is shown in
Figure 10.5.
Y (ωy ) =
1 In this chapter, we will make a slight change in our notation for the DTFT. We will use
X(ω) to denote the spectrum of x(n) instead of the previously used notation X(ejω ).
Although this change does conflict with the z-transform notation, the meaning should
be clear from the context. This change is made for the sake of clarity and visibility of
variables.
490
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Comments:
1. The sampling theorem interpretation for (10.19) is that the sequence
x(n) was originally sampled at D times higher rate than required; therefore, downsampling by D simply reduces the effective sampling rate to
the minimum required to prevent aliasing.
2. Equation (10.18) expresses the requirement for zero decimation error
in the sense that no information is lost—i.e., there is no irreversible
aliasing error in the frequency domain.
ω
3. The argument Dy occurs because in our notation ω is expressed in
rad/sample. Thus the frequency of y(m) expressed in terms of the
higher-rate sequence x(n) must be divided by D to account for the
slower rate of y(m).
1
4. Note that there is a factor D
in (10.19). This factor is required to
make the inverse Fourier transform work out properly and is entirely
consistent with the spectra of the sampled analog signals.
THE IDEAL
DECIMATOR
In general, (10.18) won’t be exactly true, and the (D ↓ 1) downsampler
would cause irreversible aliasing error. To avoid aliasing, we must first
reduce the bandwidth of x(n) to Fx,max = Fx /2D or, equivalently, to
ωx,max = π/D. Then we may downsample by D and thus avoid aliasing.
The decimation process is illustrated in Figure 10.6. The input sequence x(n) is passed through a lowpass filter, characterized by the
impulse response h(n) and a frequency response HD (ωx ), which ideally
satisfies the condition
1, |ωx | ≤ π/D
0, otherwise
HD (ωx ) =
(10.20)
Thus, the filter eliminates the spectrum of X(ωx ) in the range π/D <
ωx < π. Of course, the implication is that only the frequency components
of x(n) in the range |ωx | ≤ π/D are of interest in further processing of
the signal.
The output of the filter is a sequence v(n) given as
∞
v(n) =
h(k)x(n − k)
(10.21)
k=0
Ideal Decimator
x(n)
Rate: Fx
FIGURE 10.6
Decimation by a Factor
D
IDEAL
LPF
v (n)
↓D
Fx
y (m )
Fx
= Fy
D
Ideal decimation by a factor D
491
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
which is then downsampled by the factor D to produce y(m). Thus,
y(m) = v(mD) =
∞
h(k)x(mD − k)
(10.22)
k=0
Although the filtering operation on x(n) is linear and time invariant, the
downsampling operation in combination with the filtering results also in
a time-variant system.
The frequency-domain characteristics of the output sequence y(m) obtained through the filtered signal v(n) can be determined by following the
analysis steps given before—i.e., by relating the spectrum of y(m) to the
spectrum of the input sequence x(n). Using these steps, we can show that
Y (z) =
D−1
1 −2πk/D 1/D −2πk/D 1/D X e
H e
z
z
D
(10.23)
k=0
or that
Y (ωy ) =
D−1
ωy − 2πk
1 ωy − 2πk
X
H
D
D
D
(10.24)
k=0
With a properly designed filter HD (ω), the aliasing is eliminated and,
consequently, all but the first term in (10.24) vanish. Hence,
Y (ωy ) =
ωy
ωy
1
HD
X
D
D
D
=
ωy
1
X
D
D
(10.25)
for 0 ≤ |ωy | ≤ π. The spectra for the sequences x(n), h(n), v(n), and
y(m) are illustrated in Figure 10.7.
|X(wx)|
-p
|V(wx)|
p
0
wx
-
H(wx)
FIGURE 10.7
492
p
D
0
p
D
0
wx
p
D
|Y(wy)|
p
D
wx
-p
0
p
wy
Spectra of signals in the decimation of x(n) by a factor D
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
MATLAB Implementation MATLAB provides the function y =
decimate(x,D) that resamples the sequence in array x at 1/D times
the original sampling rate. The resulting resampled array y is D times
shorter—i.e., length(y) = length(x)/D. An ideal lowpass filter given in
(10.20) is not possible in the MATLAB implementation; however, fairly
accurate approximations are used. The default lowpass filter used in the
function is an 8th-order Chebyshev type-I lowpass filter with the cutoff
frequency of 0.8π/D. Using additional optional arguments, the filter order
can be changed or an FIR filter of specified order and cutoff frequency
can be used.
EXAMPLE 10.2
Solution
Let x(n) = cos(0.125πn). Generate a large number of samples of x(n) and
decimate them using D = 2, 4, and 8 to show the results of decimation.
We will plot the middle segments of the signals to avoid end-effects due to
the default lowpass filter in the decimate function. The following MATLAB
script shows details of these operations, and Figure 10.7 shows the plots of the
sequences.
n = 0:2048; k1 = 256; k2 = k1+32; m = 0:(k2-k1);
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
% (a) Original signal
x = cos(0.125*pi*n); subplot(2,2,1);
Ha = stem(m,x(m+k1+1),’g’,’filled’); axis([-1,33,-1.1,1.1]);
set(Ha,’markersize’,2); ylabel(’Amplitude’);
title(’Original Sequence x(n)’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
% (b) Decimation by D = 2
D = 2; y = decimate(x,D); subplot(2,2,2);
Hb = stem(m,y(m+k1/D+1),’c’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hb,’markersize’,2); ylabel(’Amplitude’);
title(’Decimated by D = 2’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
% (c) Decimation by D = 4
D = 4; y = decimate(x,D); subplot(2,2,3);
Hc = stem(m,y(m+k1/D+1),’r’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hc,’markersize’,2); ylabel(’Amplitude’);
title(’Decimated by D = 4’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
xlabel(’n’);
Decimation by a Factor D
493
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% (d) Decimation by D = 8
D = 8; y = decimate(x,D); subplot(2,2,4);
Hd = stem(m,y(m+k1/D+1),’m’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hd,’markersize’,2); ylabel(’Amplitude’);
title(’Decimated by D = 8’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
xlabel(’n’);
From Figure 10.8, we observe that the decimated sequences for D = 2 and
D = 4 are correct and represent the original sinusoidal sequence x(n) at lower
sampling rates. However, the sequence for D = 8 is almost zero because the
lowpass filter has attenuated x(n) prior to downsampling. Recall that the cutoff
frequency of the lowpass filter is set to 0.8π/D = 0.1π which eliminates x(n).
If we had used the downsampling operation on x(n) instead of decimation, the
resulting sequence would be y(m) = 1, which is an aliased signal. Thus, the
lowpass filtering is necessary.
Original Sequence x(n)
Decimated by D = 2
1
Amplitude
Amplitude
1
0
−1
0
−1
0
16
32
0
Decimated by D = 4
1
Amplitude
Amplitude
32
Decimated by D = 8
1
0
−1
0
−1
0
16
n
FIGURE 10.8
494
16
32
0
16
n
32
Original and decimated signals in Example 10.2
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
INTERPOLATION BY A FACTOR I
An increase in the sampling rate by an integer factor of I—i.e., Fy =
IFx —can be accomplished by interpolating I − 1 new samples between
successive values of the signal. The interpolation process can be accomplished in a variety of ways. We shall describe a process that preserves
the spectral shape of the signal sequence x(n). This process can be accomplished in two steps. The first step creates an intermediate signal at
the high rate Fy by interlacing zeros in between non-zero samples in an
operation called upsampling. In the second step, the intermediate signal
is filtered to “fill-in” zero-interlaced samples to create the interpolated
high-rate signal. As before, we will first study the time- and frequencydomain characteristics of the upsampled signal and then introduce the
interpolation system.
THE
UPSAMPLER
Let v(m) denote the intermediate sequence with a rate Fy = IFx , which
is obtained from x(n) by adding I − 1 zeros between successive values of
x(n). Thus,
v(m) =
x(m/I), m = 0, ±I, ±2I, . . .
0,
otherwise
(10.26)
and its sampling rate is identical to the rate of y(m). The block diagram
of the upsampler is shown in Figure 10.9. Again, any system containing
the upsampler is a time-varying system (Problem P10.1).
↑I
x(n)
Rate Fx
An upsampling element
FIGURE 10.9
EXAMPLE 10.3
Solution
v(m)
Rate IFx = Fy
Let I = 2 and x(n) = {1, 2, 3, 4}. Verify that the upsampler is time varying.
↑
The upsampled signal is v(m) = {1, 0, 2, 0, 3, 0, 4, 0}. If we now delay x(n) by
↑
one sample, we get x(n−1) = {0, 1, 2, 3, 4}. The corresponding upsampled signal
↑
is v1 (m) = {0, 0, 1, 0, 2, 0, 3, 0, 4, 0} = v(m − 2) and not v(m − 1).
↑
MATLAB Implementation MATLAB provides the function [v] =
upsample(x,I) that upsamples input array x into output y by inserting (I-1) zeros between input samples. An optional third parameter,
Interpolation by a Factor
I
495
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
“phase,” specifies the sample offset, which must be an integer between
0 and (I-1). For example,
>> x = [1,2,3,4]; v = upsample(x,3)
v =
1
0
0
2
0
0
3
0
0
4
0
0
upsamples by a factor of 2 starting with the first sample. However,
>> v = upsample(x,3,1)
v =
0
1
0
0
>> v = upsample(x,3,2)
v =
0
0
1
0
2
0
0
3
0
0
4
0
0
2
0
0
3
0
0
4
produces two different signals by upsampling, starting with the second
and the third sample (i.e., offset by 1), respectively. Note that the lengths
of the upsampled signals are I times the length of the original signal.
The frequency-domain representation of the upsampled signal
y(m) The sequence v(m) has a z-transform
V (z) =
∞
m=−∞
v(m)z −m =
∞
v(m)z −mI = X(z I )
(10.27)
m=−∞
The corresponding spectrum of v(m) is obtained by evaluating (10.27) on
the unit circle. Thus
(10.28)
V (ωy ) = X(ωy I)
where ωy denotes the frequency variable relative to the new sampling rate
Fy (i.e., ωy = 2πF/Fy ). Now the relationship between sampling rates
is Fy = IFx , and hence the frequency variables ωx and ωy are related
according to the formula
ωx
ωy =
(10.29)
I
The spectra X(ωx ) and V (ωy ) are illustrated in Figure 10.10. We observe
that the sampling rate increase, obtained by the addition of I − 1 zero
samples between successive values of x(n), results in a signal whose spectrum V (ωy ) is an I-fold periodic repetition of the input signal spectrum
X(ωx ).
THE IDEAL INTERPOLATOR
496
Since only the frequency components of x(n) in the range 0 ≤ ωy ≤
π/I are unique, the images of X(ω) above ωy = π/I should be rejected
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
|X(wx)|
−p
0
FIGURE 10.10
|V (wx)|
p
wx
−
3p
I
−
2p
I
p 0
−
I
p
I
2p
I
3p
I
wy =
wx
I
Spectra of x(n) and v(m) where V (ωy ) = X(ωy I)
by passing the sequence v(m) through a lowpass filter with a frequency
response HI (ωy ) that ideally has the characteristic
C, 0 ≤ |ωy | ≤ π/I
0, otherwise
HI (ωy ) =
(10.30)
where C is a scale factor required to properly normalize the output
sequence y(m). Consequently, the output spectrum is
Y (ωy ) =
CX(ωy I), 0 ≤ |ωy | ≤ π/I
0,
otherwise
(10.31)
The scale factor C is selected so that the output y(m) = x(m/I) for
m = 0, ±I, ±2I, . . . . For mathematical convenience, we select the point
m = 0. Thus,
π
π/I
1
C
y(0) =
Y (ωy )dωy =
X(ωy I)dωy
(10.32)
2π −π
2π −π/I
Since ωy = ωx /I, (10.32) can be expressed as
π
C
C 1
X(ωx )dωx = x(0)
y(0) =
I 2π −π
I
(10.33)
therefore, C = I is the desired normalization factor.
Finally, we indicate that the output sequence y(m) can be expressed
as a convolution of the sequence v(n) with the unit sample response h(n)
of the lowpass filter. Thus
y(m) =
∞
h(m − k)v(k)
(10.34)
k=−∞
Since v(k) = 0 except at multiples of I, where v(kI) = x(k), (10.34)
becomes
∞
h(m − kI)x(k)
(10.35)
y(m) =
k=−∞
The ideal interpolator is shown in Figure 10.11.
Interpolation by a Factor
I
497
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Ideal Interpolator
x(n)
Rate: Fx
FIGURE 10.11
↑I
v (m) IDEAL
LPF
IFx
y(m)
IFx
Ideal interpolation by a factor I
MATLAB Implementation MATLAB provides the function [y,h] =
interp(x,I) that resamples the signal in array x at I times the original
sampling rate. The resulting resampled array y is I times longer—i.e.,
length(y) = I*length(x). The ideal lowpass filter given in (10.30) is
approximated by a symmetric filter impulse response, h, which is designed
internally. It allows the original samples to pass through unchanged and
interpolates between so that the mean square error between them and
their ideal values is minimized. The third optional parameter L specifies
the length of the symmetric filter as 2*L*I+1, and the fourth optional
parameter cutoff specifies the cutoff frequency of the input signal in π
units. The default values are L = 5 and cutoff = 0.5. Thus, if I = 2,
then the length of the symmetric filter is 21 for the default L = 5.
EXAMPLE 10.4
Solution
Let x(n) = cos(πn). Generate samples of x(n) and interpolate them using I = 2,
4, and 8 to show the results of interpolation.
We will plot the middle segments of the signals to avoid end-effects due to the
default lowpass filter in the interp function. The following MATLAB script
shows details of these operations, and Figure 10.12 shows the plots of the
sequences.
n = 0:256; k1 = 64; k2 = k1+32; m = 0:(k2-k1);
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
% (a) Original signal
x = cos(pi*n); subplot(2,2,1);
Ha = stem(m,x(m+k1+1),’g’,’filled’); axis([-1,33,-1.1,1.1]);
set(Ha,’markersize’,2); ylabel(’Amplitude’);
title(’Original Sequence x(n)’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
% (b) Interpolation by I = 2
I = 2; y = interp(x,I); subplot(2,2,2);
Hb = stem(m,y(m+k1*I+1),’c’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hb,’markersize’,2); ylabel(’Amplitude’);
title(’Interpolated by I = 2’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
498
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Interpolated by I = 2
Original Sequence x(n)
1
Amplitude
Amplitude
1
0
−1
0
−1
0
16
0
32
Interpolated by I = 4
32
Interpolated by I = 8
1
Amplitude
1
Amplitude
16
0
0
−1
−1
0
16
n
FIGURE 10.12
32
0
16
n
32
Original and interpolated signals in Example 10.4
% (c) Interpolation by I = 4
I = 4; y = interp(x,I); subplot(2,2,3);
Hc = stem(m,y(m+k1*I+1),’r’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hc,’markersize’,2); ylabel(’Amplitude’);
title(’Interpolated by I = 4’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
xlabel(’n’);
% (d) Interpolation by I = 8
I = 8; y = interp(x,I); subplot(2,2,4);
Hd = stem(m,y(m+k1*I+1),’m’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hd,’markersize’,2); ylabel(’Amplitude’);
title(’Interpolated by I = 8’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
xlabel(’n’);
From Figure 10.11, we observe that the interpolated sequences for all three
values of I are appropriate and represent the original sinusoidal signal x(n)
Interpolation by a Factor I
499
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
at higher sampling rates. In the case of I = 8, the resulting sequence does not
appear to be perfectly sinusoidal in shape. This may be due the fact the lowpass
filter is not close to an ideal filter.
EXAMPLE 10.5
Solution
Examine the frequency response of the lowpass filter used in the interpolation
of the signal in Example 10.4.
The second optional argument in the interp function provides the impulse
response from which we can compute the frequency response, as shown in the
following MATLAB script.
n = 0:256; x = cos(pi*n); w = [0:100]*pi/100;
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
% (a) Interpolation by I = 2, L = 5;
I = 2; [y,h] = interp(x,I); H = freqz(h,1,w); H = abs(H);
subplot(2,2,1); plot(w/pi,H,’g’); axis([0,1,0,I+0.1]); ylabel(’Magnitude’);
title(’I = 2, L = 5’,’fontsize’,TF);
set(gca,’xtick’,[0,0.5,1]); set(gca,’ytick’,[0:1:I]);
% (b) Interpolation by I = 4, L = 5;
I = 4; [y,h] = interp(x,I); H = freqz(h,1,w); H = abs(H);
subplot(2,2,2); plot(w/pi,H,’g’); axis([0,1,0,I+0.2]); ylabel(’Magnitude’);
title(’I = 4, L = 5’,’fontsize’,TF);
set(gca,’xtick’,[0,0.25,1]); set(gca,’ytick’,[0:1:I]);
% (c) Interpolation by I = 8, L = 5;
I = 8; [y,h] = interp(x,I); H = freqz(h,1,w); H = abs(H);
subplot(2,2,3); plot(w/pi,H,’g’); axis([0,1,0,I+0.4]); ylabel(’Magnitude’);
title(’I = 8, L = 5’,’fontsize’,TF); xlabel(’\omega/\pi’,’fontsize’,10)
set(gca,’xtick’,[0,0.125,1]); set(gca,’ytick’,[0:2:I]);
% (d) Interpolation by I = 8, L = 10;
I = 8; [y,h] = interp(x,I,10); H = freqz(h,1,w); H = abs(H);
subplot(2,2,4); plot(w/pi,H,’g’); axis([0,1,0,I+0.4]); ylabel(’Magnitude’);
title(’I = 8, L = 10’,’fontsize’,TF); xlabel(’\omega/\pi’,’fontsize’,10)
set(gca,’xtick’,[0,0.125,1]); set(gca,’ytick’,[0:2:I]);
The frequency response plots are shown in Figure 10.13. The first three plots
are for L = 5 and, as expected, the filters are all lowpass with passband edges
approximately around π/I frequencies and the gain of I. Also note that the
filters do not have sharp transitions and thus are not good approximations to
the ideal filter. The last plot shows the response for L = 10, which indicates
a more sharp transition, which is to be expected. Any value beyond L = 10
results in an unstable filter design and hence should be avoided.
500
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
I = 2, L = 5
I = 4, L = 5
4
Magnitude
Magnitude
2
1
3
2
1
0
0
0.5
0
1
0
0.25
I = 8, L = 10
8
8
6
6
Magnitude
Magnitude
I = 8, L = 5
4
4
2
2
0
1
0 0.125
1
0
0 0.125
wp
FIGURE 10.13
1
wp
Filter frequency responses in Example 10.5
SAMPLING RATE CONVERSION BY A RATIONAL FACTOR I/D
Having discussed the special cases of decimation (downsampling by a factor D) and interpolation (upsampling by a factor I), we now consider
the general case of sampling rate conversion by a rational factor I/D.
Basically, we can achieve this sampling rate conversion by first performing interpolation by the factor I and then decimating the output of the
interpolator by the factor D. In other words, a sampling rate conversion
by the rational factor I/D is accomplished by cascading an interpolator
with a decimator, as illustrated in Figure 10.14.
We emphasize that the importance of performing the interpolation
first and the decimation second is to preserve the desired spectral characteristics of x(n). Furthermore, with the cascade configuration illustrated
in Figure 10.14, the two filters with impulse response {hu (k)} and {hd (k)}
are operated at the same rate, namely IFx , and hence can be combined
into a single lowpass filter with impulse response h(k), as illustrated in
Sampling Rate Conversion by a Rational Factor
I/D
501
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Interpolator
↑I
x(n)
Rate: Fx
Decimator
IDEAL
LPF
h u (k )
v (k)
IDEAL w (k)
LPF
h d (k )
IFx
IFx
↓D
y (m)
I
Fx = Fy
D
IFx
Cascade of interpolator and decimator for sampling rate conversion by a factor I/D
FIGURE 10.14
Figure 10.15. The frequency response H(ωv ) of the combined filter must
incorporate the filtering operations for both interpolation and decimation,
and hence it should ideally possess the frequency-response characteristic
H(ωv ) =
I, 0 ≤ |ωv | ≤ min(π/D, π/I)
0,
(10.36)
otherwise
where ωv = 2πF/Fv = 2πF/IFx = ωx /I.
Explanation of (10.36): Note that V (ωv ) and hence W (ωv ) in Figure 10.15 are periodic with period 2π/I. Thus, if
• D < I, then filter H(ωv ) allows a full period through and there is no
net lowpass filtering.
• D > I, then filter must first truncate the fundamental period of W (ωv )
to avoid aliasing error in the (D ↓ 1) decimation stage to follow.
Putting these two observations together, we can state that when
D/I < 1, we have net interpolation and no smoothing is required by
H(ωv ) other than to extract the fundamental period of W (ωv ). In this
respect, H(ωv ) acts as a lowpass filter as in the ideal interpolator. On
the other hand, if D/I > 1, then we have net decimation. Hence it is
necessary to first truncate even the fundamental period of W (ωv ) to get
the frequency band down to [−π/D, π/D] and to avoid aliasing in the
decimation that follows. In this respect, H(ωv ) acts as a smoothing filter
in the ideal decimator. When D or I is equal to 1, the general decimator/interpolator in Figure 10.15 along with (10.36) reduces to the ideal
interpolator or decimator as special case, respectively.
Ideal Resampler
↑I
x (n)
Rate: Fx
FIGURE 10.15
502
v (k)
IFx
IDEAL w (k)
LPF
h (k )
IFx
↓D
y (m )
I
Fx = Fy
D
Method for sampling rate conversion by a factor I/D
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In the time domain, the output of the upsampler is the sequence
v(k) =
x(k/I), k = 0, ±I, ±2I, . . .
0,
otherwise
(10.37)
and the output of the linear time-invariant filter is
w(k) =
∞
h(k − )v( ) =
=−∞
∞
h(k − I)x( )
(10.38)
=−∞
Finally, the output of the sampling rate converter is the sequence {y(m)},
which is obtained by downsampling the sequence {w(k)} by a factor of
D. Thus
∞
y(m) = w(mD) =
h(mD − I)x( )
(10.39)
=−∞
It is illuminating to express (10.39) in a different form by making a
change in variable. Let
mD
=
−n
(10.40)
I
where the notation r denotes the largest integer contained in r. With
this change in variable, (10.39) becomes
mD
mD
I + nI x
−n
y(m) =
h mD −
I
I
n=−∞
∞
(10.41)
We note that
mD −
mD
I = (mD) modulo I = ((mD))I
I
Consequently, (10.41) can be expressed as
y(m) =
∞
h[nI + ((mD))I ] x
n=−∞
mD
−n
I
(10.42)
These operations are shown in Figure 10.16 for I = 3 and D = 2.
It is apparent from (10.41) and Figure 10.16 that the output y(m) is
obtained by passing the input sequence x(n) through a time-variant filter
with impulse response
g(n, m) = h[nI + ((mD))I ]
Sampling Rate Conversion by a Rational Factor
I/D
− ∞ < m, n < ∞
(10.43)
503
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x (n)
−3
−2
−1
0
1
2
3
n
v (k)
I=3
−9
−8
−7
−6
−5
−4
−3
−2
−1
k
0
1
2
3
4
5
6
7
8
9
w (k)
I=3
−9
−8
−7
−6
−5
−4
−3
−2
−1
0
1
2
3
4
5
6
7
8
9
k
y (m)
D=2
−4
−3
−2
−1
0
1
2
3
4
m
Examples of signals x(n), v(k), w(k), and y(m) in the sampling
rate converter of Figure 10.15 for I = 3 and D = 2
FIGURE 10.16
where h(k) is the impulse response of the time-invariant lowpass filter
operating at the sampling rate IFx . We further observe that for any
integer k,
g(n, m + kI) = h[nI + ((mD + kDI))I ] = h[nI + ((mD))I ]
= g(n, m)
(10.44)
Hence g(n, m) is periodic in the variable m with period I.
Regarding the computational complexity of the lowpass filter in the
general resampler, we note that it has a non-zero input only every I samples and the output is required only every D samples. If we use an FIR implementation for this lowpass filter, we need only compute its output one
out of every D samples. However, if we instead use IIR implementation,
504
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
we would generally have to compute intermediate outputs also because
of the recursive nature of the filter. However, both types of filter benefit
from the computational savings due to their sparse input.
The frequency-domain representation of the resampled signal
y(m) The frequency-domain relationships can be obtained by combining the results of the interpolation and decimation process. Thus, the
spectrum at the output of the linear filter with impulse response h(k) is
V (ωv ) = H(ωv )X(ωv I)
IX(ωv I),
=
0,
0 ≤ |ωv | ≤ min(π/D, π/I)
otherwise
(10.45)
The spectrum of the output sequence y(m), obtained by decimating the
sequence v(n) by a factor of D, is
Y (ωy ) =
D−1
1 ωy − 2πk
V
D
D
(10.46)
k=0
where ωy = Dωv . Since the linear filter prevents aliasing as implied by
(10.45), the spectrum of the output sequence given by (10.46) reduces to

ωy
I


X
, 0 ≤ |ωy | ≤ min π, πD
I
D
D
(10.47)
Y (ωy ) =


0,
otherwise
MATLAB Implementation MATLAB provides the function [y,h]
= resample(x,I,D) that resamples the signal in array x at I/D times
the original sampling rate. The resulting resampled array y is I/D times
longer (or the ceiling of it if the ratio is not an integer)—i.e., length(y) =
ceil(I/D)*length(x). The function approximates the anti-aliasing (lowpass) filter given in (10.36) by an FIR filter, h, designed (internally) using
the Kaiser window. It also compensates for the filter’s delay.
The length of the FIR filter h that resample uses is proportional to
the fourth (optional) parameter L that has the default value of 10. For
L = 0, resample performs a nearest-neighbor interpolation. The fifth optional parameter beta (default value 5) can be used to specify the Kaiser
window stopband attenuation parameter β. The filter characteristics can
be studied using the impulse response h.
EXAMPLE 10.6
Solution
Consider the sequence x(n) = cos(0.125πn) discussed in Example 10.2. Change
its sampling rate by 3/2, 3/4, and 5/8.
The following MATLAB script shows the details.
Sampling Rate Conversion by a Rational Factor I/D
505
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
n = 0:2048; k1 = 256; k2 = k1+32; m = 0:(k2-k1);
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
% (a) Original signal
x = cos(0.125*pi*n); subplot(2,2,1);
Ha = stem(m,x(m+k1+1),’g’,’filled’); axis([-1,33,-1.1,1.1]);
set(Ha,’markersize’,2); ylabel(’Amplitude’);
title(’Original Sequence x(n)’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
% (b) Sample rate Conversion by 3/2: I= 3, D = 2
I = 3; D = 2; y = resample(x,I,D); subplot(2,2,2);
Hb = stem(m,y(m+k1*I/D+1),’c’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hb,’markersize’,2); ylabel(’Amplitude’);
title(’Sample Rate I/D: I = 3, D = 2’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
% (c) Sample rate Conversion by 3/4: I= 3, D = 4
I = 3; D = 4; y = resample(x,I,D); subplot(2,2,3);
Hc = stem(m,y(m+k1*I/D+1),’r’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hc,’markersize’,2); ylabel(’Amplitude’);
title(’Sample Rate I/D: I = 3, D = 4’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
xlabel(’n’, ’fontsize’,LF);
% (d) Sample rate Conversion by 5/8: I= 5, D = 8
I = 5; D = 8; y = resample(x,I,D); subplot(2,2,4);
Hd = stem(m,y(m+k1*I/D+1),’m’,’filled’); axis([-1,33,-1.1,1.1]);
set(Hd,’markersize’,2); ylabel(’Amplitude’);
title(’Sample Rate I/D: I = 5, D = 8’,’fontsize’,TF);
set(gca,’xtick’,[0,16,32]); set(gca,’ytick’,[-1,0,1]);
xlabel(’n’, ’fontsize’,LF);
The resulting plots are shown in Figure 10.17. The original x(n) signal has
16 samples in one period of the cosine waveform. Since the first sampling rate
conversion by 3/2 is greater than one, the overall effect is to interpolate x(n).
The resulting signal has 16 × 3/2 = 24 samples in one period. The other two
sampling rate conversion factors are less than one; thus, overall effect is to
decimate x(n). The resulting signals have 16 × 3/4 = 12 and 16 × 5/8 = 10
samples per period, respectively.
FIR FILTER DESIGNS FOR SAMPLING RATE CONVERSION
In practical implementation of sampling rate converters we must replace
the ideal lowpass filters of equations (10.20), (10.30), and (10.36) by a
practical finite-order filter. The lowpass filter can be designed to have
506
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Original Sequence x(n)
Sample Rate I/D: I = 3, D = 2
1
Amplitude
Amplitude
1
0
−1
0
−1
0
16
32
0
Sample Rate I/D: I = 3, D = 4
32
Sample Rate I/D: I = 5, D = 8
1
Amplitude
1
Amplitude
16
0
−1
0
−1
0
16
n
FIGURE 10.17
32
0
16
n
32
Original and resampled signals in Example 10.6
linear phase, a specified passband ripple, and stopband attenuation. Any
of the standard, well-known FIR filter design techniques (e.g., window
method, frequency sampling method) can be used to carry out this design.
We consider linear-phase FIR filters for this purpose because of their ease
of design and because they fit very nicely into a decimator stage where
only one of D outputs is required [see the discussion following (10.44) on
page 504]. We will first discuss integer interpolators, followed by integer
decimators and then the rational resamplers. The main emphasis will be
on the specifications of these FIR lowpass filters, since the design problem
has already been considered in Chapter 7.
FIR INTEGER
INTERPOLATION
Replacing the ideal filter of the system given on page 498 with an FIR
filter, we obtain the system shown in Figure 10.18. The relevant equation
that relates the Fourier transforms V (ω) and X(ω) is (10.28), repeated
below for convenience.
V (ω) = X(ωI)
FIR Filter Designs for Sampling Rate Conversion
(10.48)
507
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIR Interpolator
x(n)
Rate: Fx
FIGURE 10.18
↑I
v (m) FIR LPF
H(w)
IFx
y (m)
IFx
An FIR integer interpolator
Considering the frequency compression by I and the required amplitude
scale factor of I, the ideal lowpass filter was determined in (10.30) and
(10.33) to be
I, |ω| < π/I;
HI (ω) =
(10.49)
0, otherwise.
MATLAB Implementation To design a linear-phase FIR filter for
use in interpolation (and as we shall see later for decimation) operation,
MATLAB provides the function h = intfilt(I,L,alpha). When used
on a sequence interspersed with I-1 consecutive zeros between every I
samples, the function performs ideal bandlimited interpolation using the
nearest 2*L non-zero samples. It assumes that the bandwidth of the signal
x(n) is alpha times π radians/sample—i.e., alpha=1 means the full signal
bandwidth. The length of the filter impulse response array h is 2*I*L-1.
The designed filter is identical to that used by the interp function. Therefore, the parameter L should be chosen carefully to avoid numerical instability. It should be a smaller value for higher I value but no more than ten.
EXAMPLE 10.7
Solution
Design a linear-phase FIR interpolation filter to interpolate a signal by a factor
of 4, using the bandlimited method.
We will explore the intfilt function for the design using L = 5 and study the
effect of alpha on the filter design. The following MATLAB script provides the
detail.
I = 4; L = 5;
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
% (a) Full signal bandwidth: alpha = 1
alpha = 1; h = intfilt(I,L,alpha);
[Hr,w,a,L] = Hr_Type1(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
subplot(2,2,1); plot(ww/pi,Hr,’g’,’linewidth’,1.0); axis([0,1,-1,5]);
set(gca,’xtick’,[0,1/I,1],’ytick’,[0,I]); grid; ylabel(’Amplitude’);
title(’Amplitude Response: alpha = 1’,’fontsize’,TF)
subplot(2,2,3); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-50,10]);
set(gca,’xtick’,[0,1/I,1],’ytick’,[-50,round(min_attn),0]); grid
508
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ylabel(’Decibels’); xlabel(’\omega/\pi’, ’fontsize’,10);
title(’Log-mag Response: alpha = 1’,’fontsize’,TF)
% (b) Partial signal bandwidth: alpha = 0.75
alpha = 0.75; h = intfilt(I,L,alpha);
[Hr,w,a,L] = Hr_Type1(h); Hr_min = max(Hr(end/2:end)); w_min = find(Hr == Hr_min);
H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
subplot(2,2,2); plot(ww/pi,Hr,’g’,’linewidth’,1.0); axis([0,1,-1,5]);
set(gca,’xtick’,[0,1/I,1],’ytick’,[0,I]); grid; ylabel(’Amplitude’);
title(’Amplitude Response: alpha = 0.75’,’fontsize’,TF)
subplot(2,2,4); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-50,10]);
set(gca,’xtick’,[0,1/I,1],’ytick’,[-50,round(min_attn),0]); grid
ylabel(’Decibels’); xlabel(’\omega/\pi’, ’fontsize’,10);
title(’Log-mag Response: alpha = 0.75’,’fontsize’,TF)
The plots are shown in Figure 10.19. For the full bandwidth case of alpha = 1,
the filter has more ripple in both the passband and the stopband with the
minimum stopband attenuation of 22 DB. This is because the filter transition
Amplitude Response: alpha = 1
Amplitude Response: alpha = 0.75
4
Amplitude
Amplitude
4
0
0
0
0.25
Frequency in π units
0
1
Log–mag Response: alpha = 1
Log–mag Response: alpha = 0.75
0
Decibels
0
Decibels
1
0.25
Frequency in π units
−22
−40
−50
0
0.25
Frequency in π units
FIGURE 10.19
1
−50
0
0.25
Frequency in π units
1
FIR interpolation filter design plots for I = 4 and L = 5
FIR Filter Designs for Sampling Rate Conversion
509
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
band is very narrow. For alpha = 0.75, the filter specifications are more lenient,
and hence its response is well behaved with minimum stopband attenuation of
40 DB. Note that we do not have complete control over other design parameters.
These issues are discussed in more detail further along in this section.
In the following example we design a linear-phase equiripple FIR interpolation filter using the Parks-McClellen algorithm.
EXAMPLE 10.8
Solution
Design an interpolator that increases the input sampling rate by a factor of
I = 5. Use the firpm algorithm to determine the coefficients of the FIR filter
that has 0.1 dB ripple in the passband and is down by at least 30 dB in the
stopband. Choose reasonable values for band-edge frequencies.
The passband cutoff frequency should be ωp = π/I = 0.2π. To get a reasonable
value for the filter length we choose the transition width of 0.12π, which gives
stopband cutoff frequency of ωs = 0.32π. Note that the nominal gain of the
filter in the passband should be equal to I = 5, which means that the ripple
values computed using the decibel values are scaled by 5. A filter of length
M = 31 achieves the design specifications given above. The details are given in
the following MATLAB script.
I = 5; Rp = 0.1; As = 30; wp = pi/I; ws = wp+pi*0.12;
[delta1,delta2] = db2delta(Rp,As); weights = [delta2/delta1,1];
F = [0,wp,ws,pi]/pi; A = [I,I,0,0];
h = firpm(30,F,A,weights); n = [0:length(h)-1];
[Hr,w,a,L] = Hr_Type1(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
subplot(2,2,1); Hs1 = stem(n,h,’filled’); set(Hs1,’markersize’,2);
axis([-1,length(n),-0.5,1.5]); ylabel(’Amplitude’); xlabel(’n’,’vertical’,’bottom’);
Title(’Impulse Response’,’fontsize’,TF);
subplot(2,2,3); plot(ww/pi,Hr,’m’,’linewidth’,1.0); axis([0,1,-1,6]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[0,I]); grid; ylabel(’Amplitude’);
title(’Amplitude Response’,’fontsize’,TF); xlabel(’Frequency in \pi units’);
subplot(2,2,2); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-50,10]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-50,round(min_attn),0]); grid
ylabel(’Decibels’);
title(’Log-magnitude Response’,’fontsize’,TF);
subplot(2,2,4);
lw = length(w)-1; PB = [0:floor(wp/pi*lw)]; HrPB = Hr(PB+1)-I;
SB = [ceil(ws/pi*lw):lw]; HrSB = Hr(SB+1);
[AX,H1,H2] = plotyy(PB/lw,HrPB,SB/lw,HrSB);
510
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
delta1 = round(delta1*I*100)/100; delta2 = round(delta2*I*100)/100;
set(AX(1),’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-delta1,0,delta1],’Ycolor’,’g’);
set(AX(2),’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-delta2,0,delta2],’Ycolor’,’r’);
set(H1,’color’,’g’,’linewidth’,1); set(H2,’color’,’r’,’linewidth’,1);
title(’Scaled Ripples’,’fontsize’,TF); xlabel(’Frequency in \pi units’);
The responses of the designed FIR filter are given in Figure 10.20. Even
though this filter passes the original signal, it is possible that some of the neighboring spectral energy may also leak through if the signal is of full bandwidth
of π radians. Hence we need better design specifications, which are discussed
further along in this section.
Log–magnitude Response
Impulse Response
1.5
0
Decibels
Amplitude
1
0.5
0
−0.5
0
10
20
−30
−50
30
0
n
Amplitude Response
0.2 0.32
Frequency in π units
1
Scaled Ripples
0.16
0.03
Amplitude
Amplitude
5
0
0
−0.03
0
0
0.2 0.32
Frequency in π units
FIGURE 10.20
1
−0.16
0
0.2 0.32
Frequency in π units
1
Responses of the FIR interpolation filter in Example 10.8
MATLAB Implementation To use the FIR filter for interpolation
purposes (such as the one designed in the above example), MATLAB has
provided a general function, upfirdn, that can be used for interpolation
and decimation as well as for resampling purposes. Unlike other functions
discussed in this chapter, upfirdn incorporates the user-defined FIR filter (which need not be linear phase) in the operation. When invoked as
y = upfirdn(x,h,I), the function upsamples the input data in the array
FIR Filter Designs for Sampling Rate Conversion
511
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x by a factor of the integer I and then filters the upsampled signal data
with the impulse response sequence given in the array h to produce the
output array y, thus implementing the system in Figure 10.18.
EXAMPLE 10.9
Solution
Let x(n) = cos(0.5πn). Increase the input sampling rate by a factor of I = 5,
using the filter designed in Example 10.8.
The steps are given in the following MATLAB script.
% Given Parameters:
I = 5; Rp = 0.1; As = 30; wp = pi/I; ws = 0.32*pi;
[delta1,delta2] = db2delta(Rp,As); weights = [delta2/delta1,1];
n = [0:50]; x = cos(0.5*pi*n);
n1 = n(1:17); x1 = x(17:33); % for plotting purposes
% Input signal
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
subplot(2,2,1); Hs1 = stem(n1,x1,’filled’); set(Hs1,’markersize’,2,’color’,’g’);
set(gca,’xtick’,[0:4:16],’ytick’,[-1,0,1]);
axis([-1,17,-1.2,1.2]); ylabel(’Amplitude’); xlabel(’n’,’vertical’,’middle’);
Title(’Input Signal x(n)’,’fontsize’,TF);
% Interpolation with Filter Design: Length M = 31
M = 31; F = [0,wp,ws,pi]/pi; A = [I,I,0,0];
h = firpm(M-1,F,A,weights); y = upfirdn(x,h,I);
delay = (M-1)/2; % Delay imparted by the filter
m = delay+1:1:50*I+delay+1; y = y(m); m = 1:81; y = y(81:161); % for plotting
subplot(2,2,2); Hs2 = stem(m,y,’filled’); set(Hs2,’markersize’,2,’color’,’m’);
axis([-5,85,-1.2,1.2]); set(gca,’xtick’,[0:4:16]*I,’ytick’,[-1,0,1]);
title(’Output y(n): Filter length=31’,’fontsize’,TF);
xlabel(’n’,’vertical’,’middle’); ylabel(’Amplitude’);
The signal stem plots are shown in Figure 10.21. The upper left-hand plot shows
a segment of the input signal x(n), and the upper right-hand plot shows the
interpolated signal y(n) using the filter of length 31. The plot is corrected for
filter delay and the effect of its transient response. It is somewhat surprising that
the interpolated signal is not what it should be. The signal peak is more than
one, and the shape is distorted. A careful observation of the filter response plot
in Figure 10.20 reveals that the broad transition width and a smaller attenuation
has allowed some of the spectral energy to leak, creating a distortion.
To investigate this further, we designed filters with larger orders of 51 and
81 as detailed in the following MATLAB script.
% Interpolation with Filter Design: Length M = 51
M = 51; F = [0,wp,ws,pi]/pi; A = [I,I,0,0];
h = firpm(M-1,F,A,weights); y = upfirdn(x,h,I);
512
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
delay = (M-1)/2; % Delay imparted by the filter
m = delay+1:1:50*I+delay+1; y = y(m); m = 1:81; y = y(81:161);
subplot(2,2,3); Hs3 = stem(m,y,’filled’); set(Hs3,’markersize’,2,’color’,’m’);
axis([-5,85,-1.2,1.2]); set(gca,’xtick’,[0:4:16]*I,’ytick’,[-1,0,1]);
title(’Output y(n): Filter length=51’,’fontsize’,TF);
xlabel(’n’,’vertical’,’middle’); ylabel(’Amplitude’);
% Interpolation with Filter Design: Length M = 81
M = 81; F = [0,wp,ws,pi]/pi; A = [I,I,0,0];
h = firpm(M-1,F,A,weights); y = upfirdn(x,h,I);
delay = (M-1)/2; % Delay imparted by the filter
m = delay+1:1:50*I+delay+1; y = y(m); m = 1:81; y = y(81:161);
subplot(2,2,4); Hs3 = stem(m,y,’filled’); set(Hs3,’markersize’,2,’color’,’m’);
axis([-5,85,-1.2,1.2]); set(gca,’xtick’,[0:4:16]*I,’ytick’,[-1,0,1]);
title(’Output y(n): Filter length=81’,’fontsize’,TF);
xlabel(’n’,’vertical’,’middle’); ylabel(’Amplitude’);
The resulting signals are also shown in lower plots in Figure 10.21. Clearly, for
large orders, the filter has better lowpass characteristics. The signal peak value
Input Signal x(n)
Output y(n): I = 5, Filter length = 31
1
Amplitude
Amplitude
1
0
−1
0
−1
0
4
8
n
12
16
0
Output y(n): I = 5, Filter length = 51
40
m
60
80
Output y(n): I = 5, Filter length = 81
1
Amplitude
1
Amplitude
20
0
0
−1
−1
0
20
40
m
FIGURE 10.21
60
80
0
20
40
m
60
80
Signal plots in Example 10.9
FIR Filter Designs for Sampling Rate Conversion
513
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
approaches 1, and its shape approaches the cosine waveform. Thus, a good filter
design is critical even in a simple signal case.
DESIGN SPECIFICATIONS
When we replace HI (ω) by a finite-order FIR filter H(ω), we must allow
for a transition band; thus, the filter cannot have a passband edge up to
π/I. Towards this, we define
• ωx,p as the highest frequency of the signal x(n) that we want to preserve, and
• ωx,s as the full signal bandwidth of x(n),—i.e., there is no energy in
x(n) above the frequency ωx,s .
Thus, we have 0 < ωx,p < ωx,s < π. Note that the parameters ωx,p and
ωx,s , as defined above, are signal parameters, not filter parameters; they
are shown in Figure 10.22(a). The filter parameters will be defined based
on ωx,p and ωx,s .
From equation (10.48), these signal parameter frequencies for v(m)
become ωx,p /I and ωx,s /I, respectively, because the frequency scale
is compressed by the factor I. This is shown in Figure 10.22(b). A
X(wx)
−p
−w
−w x,s x,p
We will allow filter to
substantially change
this band
0
w x,p
w x,s
p
wx
(a)
V (wy)
−p
−
2p
I
−
p
I
2p
0 w x,p p
I
I I
w x,s 2p - w x,s
I
I
p
wy
(b)
FIGURE 10.22
514
Frequency parameters: (a) Signal, (b) Filter
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
linear-phase FIR filter can now be designed to pass frequencies up to
ωx,p /I and to suppress frequencies starting at (2π − ωx,s )/I. Let
ωx,p
ωp =
I
and
ωs =
2π − ωx,s
I
(10.50)
be the passband and stopband edge frequencies, respectively, of the lowpass linear-phase FIR filter given by
H(ω) = Hr (ω)eθ(ω)
(10.51)
where Hr (ω) is the real-valued amplitude response and θ(ω) is the unwrapped phase response. Then we have the following filter design specifications:
1
Hr (ω)
I
≤
1
Hr (ω)
I
≤
1 ± δ1
for |ω| ∈ [0, ωp ]
(10.52)
±δ2
for |ω| ∈ [ωs , π]
where ωp and ωs are as given in (10.50) and δ1 and δ2 are the passband
and stopband ripple parameters, respectively, of the lowpass FIR filter.
Comment Instead of beginning the stopband at π/I, we were able to shift
it to (2π − ωs ) /I. If ωx,s π, then this will be an important consideration
to lower filter order. However, in the worst-case scenario of ωx,s = π, the
stopband will begin at πI , which is the same as in the ideal lowpass filter
of (10.49). Almost always ωx,s < π, and we can then choose ωx,p as close
to ωx,s as we want. However, this will reduce the size of the transition
band, which means a higher filter order.
EXAMPLE 10.10
Design a better FIR lowpass filter for sampling rate increase by a factor of I = 5
for the signal in Example 10.9.
Solution
Since x(n) = cos(0.5πn), the signal bandwidth and bandwidth to be preserved
are the same—i.e., ωx,p = ωx,s = 0.5π. Thus, from (10.50), ωp = 0.5π/5 = 0.1π
and ωs = (2π − 0.5π)/5 = 0.3π. We will design the filter for Rp = 0.01 and
As = 50 dB. The resulting filter order is 32, which is 2 higher than the one
in Example 10.9 but with much superior attenuation. The details are given
below.
FIR Filter Designs for Sampling Rate Conversion
515
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
% Given Parameters:
n = [0:50]; wxp = 0.5*pi; x = cos(wxp*n);
n1 = n(1:9); x1 = x(9:17); % for plotting purposes
I = 5; I = 5; Rp = 0.01; As = 50; wp = wxp/I; ws = (2*pi-wxp)/I;
[delta1,delta2] = db2delta(Rp,As); weights = [delta2/delta1,1];
[N,Fo,Ao,weights] = firpmord([wp,ws]/pi,[1,0],[delta1,delta2],2);N = N+2;
% Input signal
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
subplot(2,2,1); Hs1 = stem(n1,x1,’filled’); set(Hs1,’markersize’,2,’color’,’g’);
set(gca,’xtick’,[0:4:16],’ytick’,[-1,0,1]);
axis([-1,9,-1.2,1.2]); ylabel(’Amplitude’); xlabel(’n’,’vertical’,’middle’);
Title(’Input Signal x(n)’,’fontsize’,TF);
% Interpolation with Filter Design: Length M = 31
h = firpm(N,Fo,I*Ao,weights); y = upfirdn(x,h,I);
delay = (N)/2; % Delay imparted by the filter
m = delay+1:1:50*I+delay+1; y = y(m); m = 0:40; y = y(81:121);
subplot(2,2,3); Hs2 = stem(m,y,’filled’); set(Hs2,’markersize’,2,’color’,’m’);
axis([-5,45,-1.2,1.2]); set(gca,’xtick’,[0:4:16]*I,’ytick’,[-1,0,1]);
title(’Output Signal y(n): I=5’,’fontsize’,TF);
xlabel(’m’,’vertical’,’middle’); ylabel(’Amplitude’);
% Filter Design Plots
[Hr,w,a,L] = Hr_Type1(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
subplot(2,2,2); plot(ww/pi,Hr,’m’,’linewidth’,1.0); axis([0,1,-1,6]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[0,I]); grid; ylabel(’Amplitude’);
title(’Amplitude Response’,’fontsize’,TF);
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
subplot(2,2,4); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-60,10]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-60,round(min_attn),0]); grid
ylabel(’Decibels’); xlabel(’Frequency in \pi units’,’vertical’,’middle’);
title(’Log-magnitude Response’,’fontsize’,TF);
The signal stem plots and filter design plots are shown in Figure 10.23. The
designed filter has a minimum stopband attenuation of 53 dB, and the resulting
interpolation is accurate even with the filter order of 32.
FIR INTEGER
DECIMATION
Consider the system in Figure 10.5 on page 490 in which the ideal lowpass
filter is replaced by an FIR filter H(ω), which then results in the system
shown in Figure 10.24. The relationship between Y (ωy ) and X(ω) is given
by (10.24), which is repeated below for convenience
D−1
1 2πk
2πk
ωy
Y (ωy ) =
H ω−
X ω−
; ω=
(10.53)
D
D
D
D
k=0
516
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Input Signal x(n)
Amplitude Response
5
Amplitude
Amplitude
1
0
0
−1
0
4
n
8
0 0.1
Output Signal y(n): I = 5
1
Log–magnitude Response
1
0
Decibels
Amplitude
0.3
Frequency in π units
0
−53
−60
−1
0
20
m
FIGURE 10.23
40
0 0.1
0.3
Frequency in π units
1
Signal plots and filter design plots in Example 10.10
which is nothing but the aliased sum of the H(ω)X(ω). Thus, the condition necessary to avoid aliasing is
H(ω)X(ω) = 0
π
≤ |ω| ≤ π
D
for
(10.54)
Then,
Y (ωy ) =
1
X(ω)H(ω)
D
(10.55)
FIR Decimator
x (n)
Rate: Fx
FIGURE 10.24
FIR LPF v (n)
H (w)
Fx
↓D
y (m )
Fx
= Fy
D
An FIR integer decimator
FIR Filter Designs for Sampling Rate Conversion
517
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
as in (10.25), where the ideal filtering was accomplished with HD (ω) as
given in (10.20).
EXAMPLE 10.11
Design a decimator that downsamples an input signal x(n) by a factor D = 2.
Use the firpm algorithm to determine the coefficients of the FIR filter that has
a 0.1 dB ripple in the passband and is down by at least 30 dB in the stopband.
Choose reasonable values for band-edge frequencies.
Solution
The passband cutoff frequency should be ωp = π/D = 0.5π. To get a reasonable
value for the filter length we choose the transition width of 0.1π, which gives
stopband a cutoff frequency of ωs = 0.3π. A filter of length M = 37 achieves
the design specifications given above. The details are given in the following
MATLAB script.
% Filter Design
D = 2; Rp = 0.1; As = 30; wp = pi/D; ws = wp+0.1*pi;
[delta1,delta2] = db2delta(Rp,As);
[N,F,A,weights] = firpmord([wp,ws]/pi,[1,0],[delta1,delta2],2);
h = firpm(N,F,A,weights); n = [0:length(h)-1];
[Hr,w,a,L] = Hr_Type1(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
subplot(2,2,1); Hs1 = stem(n,h,’filled’); set(Hs1,’markersize’,2);
axis([-1,length(n),-0.15,0.6]); ylabel(’Amplitude’,’vertical’,’cap’);
xlabel(’n’,’vertical’,’bottom’);set(gca,’xtick’,[n(1),n(end)],’ytick’,[0,0.5]);
Title(’Impulse Response’,’fontsize’,TF,’vertical’,’baseline’);
subplot(2,2,3); plot(w/pi,Hr,’m’,’linewidth’,1.0); axis([0,1,-0.1,1.1]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[0,1]); grid;
ylabel(’Amplitude’,’vertical’,’cap’);
title(’Amplitude Response’,’fontsize’,TF,’vertical’,’baseline’);
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
subplot(2,2,2); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-50,10]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-50,round(min_attn),0]); grid
ylabel(’Decibels’,’vertical’,’cap’);
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
title(’Log-magnitude Response’,’fontsize’,TF,’vertical’,’baseline’);
subplot(2,2,4);
lw = length(w)-1; PB = [0:floor(wp/pi*lw)]; HrPB = Hr(PB+1)-1;
SB = [ceil(ws/pi*lw):lw]; HrSB = Hr(SB+1);
[AX,H1,H2] = plotyy(PB/lw,HrPB,SB/lw,HrSB);
delta1 = round(delta1*1000)/1000; delta2 = round(delta2*100)/100;
set(AX(1),’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-delta1,0,delta1],’Ycolor’,’g’);
518
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Impulse Response
Log–magnitude Response
0.5
Decibels
Amplitude
0
−31
0
0
−50
0
36
n
0.5 0.6
Frequency in π units
Amplitude Response
Unweighted Ripples
1
1
0.03
Amplitude
Amplitude
0.006
0
0
−0.006
−0.03
0
0
0.5 0.6
Frequency in π units
FIGURE 10.25
1
0
0.5 0.6
1
Frequency in π units
Responses of the FIR decimation filter in Example 10.11
set(AX(2),’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-delta2,0,delta2],’Ycolor’,’r’);
set(H1,’color’,’g’,’linewidth’,1); set(H2,’color’,’r’,’linewidth’,1);
title(’Unweighted Ripples’,’fontsize’,TF,’vertical’,’baseline’);
ylabel(’Amplitude’,’vertical’,’cap’)
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
The responses of the designed FIR filter are given in Figure 10.25. This filter
passes the signal spectrum over the passband [0, π/2] without any distortion.
However, since the transition width is not very narrow, it is possible that some
of the signal over the transition band may alias into the band of interest. Also
the 30-db attenuation may allow a small fraction of the signal spectrum from the
stopband into the passband after downsampling. Therefore, we need a better
approach for filter specifications, as discussed further along in this section. MATLAB Implementation As discussed before, the upfirdn function can also be used for implementing the user-designed FIR filter in
the decimation operation. When invoked as y = upfirdn(x,h,1,D), the
function filters the signal data in the array x with the impulse response
given in the array h and then downsamples the filtered data by the integer
factor D to produce the output array y, thus implementing the system in
Figure 10.24.
FIR Filter Designs for Sampling Rate Conversion
519
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXAMPLE 10.12
Using the filter designed in Example 10.11 decimate sinusoidal signals x1 (n) =
cos(πn/8) and x2 (n) = cos(πn/2) with frequencies within the passband of the
filter. Verify the performance of the FIR filter and the results of the decimation.
Solution
The following MATLAB script provides the details.
% Given Parameters:
D = 2; Rp = 0.1; As = 30; wp = pi/D; ws = wp+0.1*pi;
% Filter Design
[delta1,delta2] = db2delta(Rp,As);
[N,F,A,weights] = firpmord([wp,ws]/pi,[1,0],[delta1,delta2],2);
h = firpm(N,F,A,weights); delay = N/2; % Delay imparted by the filter
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
% Input signal x1(n) = cos(2*pi*n/16)
n = [0:256]; x = cos(pi*n/8);
n1 = n(1:33); x1 = x(33:65); % for plotting purposes
subplot(2,2,1); Hs1 = stem(n1,x1,’filled’); set(Hs1,’markersize’,2,’color’,’g’);
set(gca,’xtick’,[0:8:32],’ytick’,[-1,0,1]);
axis([-2,34,-1.2,1.2]); ylabel(’Amplitude’); xlabel(’n’,’vertical’,’middle’);
Title(’Input Signal: x1(n) = cos(\pin/8)’,’fontsize’,TF,’vertical’,’baseline’);
% Decimation of x1(n): D = 2
y = upfirdn(x,h,1,D);
m = delay+1:1:128/D+delay+1; y = y(m); m = 0:16; y = y(16:32);
subplot(2,2,3); Hs2 = stem(m,y,’filled’); set(Hs2,’markersize’,2,’color’,’m’);
axis([-1,17,-1.2,1.2]); set(gca,’xtick’,[0:8:32]/D,’ytick’,[-1,0,1]);
title(’Output signal: y1(n): D=2’,’fontsize’,TF,’vertical’,’baseline’);
xlabel(’m’,’vertical’,’middle’); ylabel(’Amplitude’);
% Input signal x2(n) = cos(8*pi*n/16)
n = [0:256]; x = cos(8*pi*n/(16));
n1 = n(1:33); x1 = x(33:65); % for plotting purposes
subplot(2,2,2); Hs1 = stem(n1,x1,’filled’); set(Hs1,’markersize’,2,’color’,’g’);
set(gca,’xtick’,[0:8:32],’ytick’,[-1,0,1]);
axis([-2,34,-1.2,1.2]); ylabel(’Amplitude’); xlabel(’n’,’vertical’,’middle’);
Title(’Input Signal: x2(n) = cos(\pin/2)’,’fontsize’,TF,’vertical’,’baseline’);
% Decimation of x2(n): D = 2
y = upfirdn(x,[h],1,D); %y = downsample(conv(x,h),2);
m = delay+1:1:128/D+delay+1; y = y(m); m = 0:16; y = y(16:32);
subplot(2,2,4); Hs2 = stem(m,y,’filled’); set(Hs2,’markersize’,2,’color’,’m’);
axis([-1,17,-1.2,1.2]); set(gca,’xtick’,[0:8:32]/D,’ytick’,[-1,0,1]);
title(’Output signal: y2(n): D=2’,’fontsize’,TF,’vertical’,’baseline’);
xlabel(’m’,’vertical’,’middle’); ylabel(’Amplitude’);
520
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Input Signal: x1(n) = cos(πn/8)
Input Signal: x2(n) = cos(πn/2)
1
Amplitude
Amplitude
1
0
−1
0
−1
0
8
16
n
24
32
0
Output signal: y1(n): D = 2
16
n
24
32
Output signal: y2(n): D = 2
1
1
Amplitude
Amplitude
8
0
−1
0
−1
0
4
8
m
FIGURE 10.26
12
16
0
4
8
m
12
16
Signal plots in Example 10.12
The signal stem plots are shown in Figure 10.26. The left-side plots show the
signal x1 (n) and the corresponding decimated signal y1 (n), and the right-side
plots show the same for x2 (n) and y2 (n). In both cases the decimation appears
to be correct. If we had chosen any frequency above π/2, then the filter would
have attenuated or eliminated the signal.
DESIGN SPECIFICATIONS
When we replace the ideal lowpass filter HD (ω) by a finite-order FIR filter
H(ω), we must allow for a transition band. Again we define
• ωx,p as the signal bandwidth to be preserved, and
• ωx,s as the frequency above which aliasing error is tolerated.
Then we have 0 < ωx,p ≤ ωx,s ≤ π/D. If we choose ωx,s = π/D, then the
decimator will give no aliasing error. If we choose ωx,s = ωx,p , then the
band above the signal band will contain aliasing errors. With these definitions and observations we can now specify the desired filter specifications.
The filter must
pass frequencies up to ωx,p , and its stopband must begin
at 2π
−
ω
x,s and continue up to π. Then, none of the k = 0 terms in
D
FIR Filter Designs for Sampling Rate Conversion
521
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
(10.53)—i.e., the “aliases”, will cause appreciable distortion in the band
up to ωx,s . Let
2π
− ωx,s
ωp = ωx,p and ωs =
(10.56)
D
be the passband and stopband edge frequencies, respectively, of the lowpass linear-phase FIR filter given in (10.51). Then we have the following
filter design specifications:
Hr (ω)
≤
1 ± δ1
for |ω| ∈ [0, ωp ]
Hr (ω)
≤
±δ2
for |ω| ∈ [ωs , π]
(10.57)
where ωp and ωs are as given in (10.56) and δ1 and δ2 are the passband and
stopband ripple parameters of the lowpass FIR filter, respectively. Note
that it does not matter what the spectrum X(ω) is. We simply require
that the product X(ω)H(ω) be very small beginning at ω| = 2π/D − ωx,s
so that k = 0 terms in (10.53) do not provide significant contribution in
the band [−ωx,s , ωx,s ], which is required to be free of aliasing.
Significance of δ1 and δ2 The filter ripple parameters δ1 and δ2 have
the following significance, which must be taken into consideration while
specifying their values:
• the passband ripple δ1 measures the ripple in the passband and hence
controls the distortion in the signal bandwidth ωp , and
• the stopband ripple δ2 controls the amount of aliased energy (also called
leakage) that gets into the band up to ωx,s .
There are (D − 1) contributions due to k = 0 terms in (10.53). These
are expected to add incoherently (i.e., have peaks at different locations),
so the overall peak error should be about δ2 . The actual error depends
on how X(ω) varies over the rest of the band |ω| > ωx,p . Clearly, the
filter stopband ripple δ2 controls the aliasing error in the signal passband.
Therefore, both δ1 and δ2 affect the decimated signal in its passband.
Comment Comparing the FIR decimator filter specifications (10.57) to
those for the FIR interpolator in (10.52), we see a high degree of similarity.
In fact, a filter designed to decimate by factor D can also be used to
interpolate by the factor I = D, as we see from the following example.
This means that the function intfilt can also be used to design FIR
filters for decimation.
EXAMPLE 10.13
522
To design a decimate by D stage we need values for ωx,p and ωx,s (remember
that these are signal parameters). Assume ωx,p = π/(2D), which satisfies the
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
constraint ωx,p ≤ π/D and is exactly half the decimated bandwidth. Let ωx,s =
ωx,p . Then the FIR lowpass filter must pass frequencies up to ωp = π/(2D) and
stop frequencies above ωs = 2π/D − π/(2D) = 3π/(2D).
Now consider the corresponding interpolation problem. We want to interpolate by I. We again choose ωx,s = ωx,p , but now the range is ωx,p < π. If we
take exactly half this band, we get ωx,p = π/2. Then according to the specifications (10.52) for the interpolation, we want the filter to pass frequencies up to
π/2I and to stop above 3π/2I. Thus, for I = D, we have the same filter specifications, so the same filter could serve both the decimation and interpolation
problems.
EXAMPLE 10.14
Design a decimation FIR filter for the signal x1 (n) in Example 10.12 that has
a better stopband attenuation of As = 50 dB and a lower filter order.
Solution
The signal bandwidth is ωx,p = π/8, and we will choose ωx,s = π/D = π/2.
Then ωp = π/8 and ωs = (2π/D) − ωx,s = π/2. With these parameters the
optimum FIR filter length is 13, which is much lower than the previous one of
37 with a higher attenuation.
MATLAB Script:
% Given Parameters:
D = 2; Rp = 0.1; As = 50; wxp = pi/8; wxs = pi/D; wp = wxp; ws = (2*pi/D)-wxs;
% Filter Design
[delta1,delta2] = db2delta(Rp,As);
[N,F,A,weights] = firpmord([wp,ws]/pi,[1,0],[delta1,delta2],2); N = ceil(N/2)*2;
h = firpm(N,F,A,weights); delay = N/2; % Delay imparted by the filter
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
% Input signal x(n) = cos(2*pi*n/16)
n = [0:256]; x = cos(pi*n/8);
n1 = n(1:33); x1 = x(33:65); % for plotting purposes
subplot(2,2,1); Hs1 = stem(n1,x1,’filled’); set(Hs1,’markersize’,2,’color’,’g’);
set(gca,’xtick’,[0:8:32],’ytick’,[-1,0,1]);
axis([-2,34,-1.2,1.2]); ylabel(’Amplitude’,’vertical’,’cap’);
xlabel(’n’,’vertical’,’middle’);
Title(’Input Signal: x(n) = cos(\pin/8)’,’fontsize’,TF,’vertical’,’baseline’);
% Decimation of x(n): D = 2
y = upfirdn(x,h,1,D);
m = delay+1:1:128/D+delay+1; y1 = y(m); m = 0:16; y1 = y1(14:30);
subplot(2,2,3); Hs2 = stem(m,y1,’filled’); set(Hs2,’markersize’,2,’color’,’m’);
axis([-1,17,-1.2,1.2]); set(gca,’xtick’,[0:8:32]/D,’ytick’,[-1,0,1]);
title(’Output signal y(n): D=2’,’fontsize’,TF,’vertical’,’baseline’);
xlabel(’m’,’vertical’,’middle’); ylabel(’Amplitude’,’vertical’,’cap’);
FIR Filter Designs for Sampling Rate Conversion
523
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Input Signal: x(n) = cos(πn8)
Amplitude Response
1
Amplitude
Amplitude
1
0
−1
0
0
8
16
n
24
32
0 0.125
Output signal y(n): D = 2
1
Log–magnitude Response
1
0
Decibels
Amplitude
0.5
Frequency in π units
0
−51
−1
0
4
8
m
FIGURE 10.27
12
16
−60
0 0.125
0.5
1
Frequency in π units
Signal plots and filter design plots in Example 10.14
% Filter Design Plots
[Hr,w,a,L] = Hr_Type1(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
subplot(2,2,2); plot(w/pi,Hr,’m’,’linewidth’,1.0); axis([0,1,-0.1,1.1]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[0,1]); grid;
ylabel(’Amplitude’,’vertical’,’cap’);
title(’Amplitude Response’,’fontsize’,TF,’vertical’,’baseline’);
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
subplot(2,2,4); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-60,10]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-60,round(min_attn),0]); grid
ylabel(’Decibels’,’vertical’,’cap’);
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
title(’Log-magnitude Response’,’fontsize’,TF,’vertical’,’baseline’);
The signal stem plots and the filter responses are shown in Figure 10.27. The
designed filter achieves an attenuation of 51 db, and the decimated signal is
correct.
524
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIR RATIONALFACTOR RATE
CONVERSION
Replacing the ideal filter of the system given on page 502 with an FIR
filter H(ω), we obtain the system shown in Figure 10.28. In this case the
relevant ideal lowpass filter is given by (10.36), which is repeated below
for convenience.
H(ω) =
I, 0 ≤ |ω| ≤ min(π/D, π/I)
0,
otherwise
(10.58)
For the signal x(n) we define
• ωx,p as the signal bandwidth that should be preserved,
• ωx,s1 as the overall signal bandwidth, and
• ωx,s2 as the signal bandwidth that is required to be free of aliasing error
after resampling.
Then we have
Iπ
and ωx,s1 ≤ π
(10.59)
D
Now for the interpolation part, the lowpass filter must pass frequencies
up to ωx,p /I and attenuate frequencies starting at (2π/I − ωx,s1 /I). The
decimation part of the filter must again pass frequencies up to ωx,p /I
but attenuate frequencies above (2π/D − ωx,s2 /I). Therefore, the stopband must start at the lower of these two values. Defining filter cutoff
frequencies as
ωx,p
2π ωx,s1 2π ωx,s2
and ωs = min
−
,
−
(10.60)
ωp =
I
I
I
D
I
0 < ωx,p ≤ ωx,s2 ≤
and the corresponding ripple parameters as δ1 and δ2 , we have the following filter specifications:
1
Hr (ω)
I
≤
1
Hr (ω)
I
≤
1 ± δ1
for |ω| ∈ [0, ωp ]
(10.61)
±δ2
for |ω| ∈ [ωs , π]
where Hr (ω) is the amplitude response. Note that if we set ωx,s1 = π and
ωx,s2 = Iπ/D, which are their maximum values, then we get the ideal
cutoff frequency max[π/I, π/D], as given before in (10.36).
MATLAB Implementation Clearly, the upfirdn function implements
all the necessary operations needed in the rational sampling rate conversion system shown in Figure 10.28. When invoked as y = upfirdn(x,h,
I,D), it performs a cascade of three operations: upsampling the input data
array x by a factor of the integer I, FIR filtering the upsampled signal data
with the impulse response sequence given in the array h, and finally downsampling the result by a factor of the integer D. Using a well-designed filter,
we have a complete control over the sampling rate conversion operation.
FIR Filter Designs for Sampling Rate Conversion
525
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIR Resampler
Rate: Fx
FIGURE 10.28
FIR LPF
H(w)
↑I
x(n)
IFx
↓D
IFx
y (m)
I
Fx = Fy
D
An FIR rational-factor resampler
EXAMPLE 10.15
Design a sampling rate converter that increases the sampling rate by a factor of
2.5. Use the firpm algorithm to determine the coefficients of the FIR filter that
has 0.1 dB ripple in the passband and is down by at least 30 dB in the stopband.
Solution
The FIR filter that meets the specifications of this problem is exactly the same
as the filter designed in Example 10.8. Its bandwidth is π/5.
EXAMPLE 10.16
A signal x(n) has a total bandwidth of 0.9π. It is resampled by a factor of
4/3 to obtain y(m). We want to preserve the frequency band up to 0.8π and
require that the band up to 0.7π be free of aliasing. Using the Parks-McClellan
algorithm, determine the coefficients of the FIR filter that has 0.1 dB ripple in
the passband and 40 dB attenuation in the stopband.
Solution
The overall signal bandwidth is ωx,s1 = 0.9π, the bandwidth to be preserved is
ωx,p = 0.8π, and the bandwidth above which aliasing is tolerated is ωx,s2 = 0.7π.
From (10.60) and using I = 4 and D = 3, the FIR filter design parameters are
ωp = 0.2π and ωs = 0.275π. With these parameters, along with the passband
ripple of 0.1 dB and stopband attenuation of 40 dB, the optimum FIR filter
length is 58. The details and computation of design plots are given below.
% Given Parameters:
I = 4; D = 3; Rp = 0.1; As = 40;
wxp = 0.8*pi; wxs1 = 0.9*pi; wxs2 = 0.7*pi;
% Computed Filter Parameters
wp = wxp/I; ws = min((2*pi/I-wxs1/I),(2*pi/D-wxs2/I));
% Filter Design
[delta1,delta2] = db2delta(Rp,As);
[N,F,A,weights] = firpmord([wp,ws]/pi,[1,0],[delta1,delta2],2);
N = ceil(N/2)*2+1; h = firpm(N,F,I*A,weights);
Hf1 = figure(’units’,’inches’,’position’,[1,1,6,3],...
’paperunits’,’inches’,’paperposition’,[0,0,6,3]);
% Filter Design Plots
[Hr,w,a,L] = Ampl_res(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
subplot(2,1,1); plot(w/pi,Hr,’m’,’linewidth’,1.0); axis([0,1,-0.1,I+0.1]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[0,I]); grid;
ylabel(’Amplitude’,’vertical’,’cap’);
title(’Amplitude Response’,’fontsize’,TF,’vertical’,’baseline’);
526
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
subplot(2,1,2); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-60,10]);
set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-60,round(min_attn),0]); grid
ylabel(’Decibels’,’vertical’,’cap’);
xlabel(’Frequency in \pi units’,’vertical’,’middle’);
title(’Log-magnitude Response’,’fontsize’,TF,’vertical’,’baseline’);
The filter responses are shown in Figure 10.29, which shows that the designed
filter achieves the attenuation of 40 db.
Amplitude Response
Amplitude
4
0
0
0.2
0.275
1
Frequency in π units
Log–magnitude Response
Decibels
0
−40
−60
0
0.2
1
0.275
Frequency in π units
FIGURE 10.29
FIR FILTERS
WITH MULTIPLE STOPBANDS
The filter design plots in Example 10.16
We now discuss the use of multiple stopbands in the design of FIR integer
interpolators when the low sampling rate is more than two times that
required. Let us refer back to the Figure 10.22(b) on page 514, which
illustrates a typical spectrum V (ω) in integer interpolators. We could use
a lowpass filter with multiple stopbands of bandwidth ωs /I centered at
2πk/I for k = 0. For I = 4 such a spectrum is shown in Figure 10.30(a),
and the corresponding filter specifications are shown in Figure 10.30(b).
Clearly, these filter specifications differ from those given in (10.52) on
page 515 in that the stopband is no longer one contiguous interval. Now
if ωs < π/2, then there is a practical advantage to using this multiband
design because it results in a lower order filter [2]. For π ≥ ωs > π/2, the
single-band lowpass filter specification (10.52) is easier and works as well.
FIR Filter Designs for Sampling Rate Conversion
527
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
V(w)
0
1 + d1
1 − d1
1
H(w)
I
p
w x,p p
2p
3p
I
I
I
I
w x,s 2p − w x,s 2p + w x,s 4p − w x,s
I
I
I
I
w
(a)
2w x,s
I
1
(b)
d2
0
FIGURE 10.30
w x,p 2p − w x,s
I
I
2p + w x,s 4p − wx,s p
I
I
w
Multiple stopband design: (a) Signal spectrum, (b) Filter speci-
fications
Similar advantages can be obtained for FIR integer decimators. We
again find that we can substitute a multiple stopband lowpass filter for the
single stopband design given in (10.57). With reference to the signal specifications on page 522, we note that only part of the bands [π/D, 3π/D],
[3π/D, 5π/D], . . . etc. will get aliased into [−ωs , +ωs ]. Therefore, the multiple stopbands are given by [(2π/D) − ωs , (2π/D) + ωs ], [(4π/D) − ωs ,
(4π/D) + ωs ], etc., centered at 2πk/D, k = 0. Once again there are practical advantages when ωs < π/2M .
FIR FILTER STRUCTURES FOR SAMPLING RATE CONVERSION
As indicated in the discussion in section 10, sampling rate conversion by
a factor I/D can be achieved by first increasing the sampling rate by I,
accomplished by inserting I − 1 zeros between successive values of the
input signal x(n), followed by linear filtering of the resulting sequence to
eliminate the unwanted images of X(ω), and finally by downsampling the
filtered signal by the factor D. In this section we consider the design and
implementation of the linear filter. We begin with the simplest structure,
which is the direct-form FIR filter structure, and develop its computationally efficient implementation. We then consider another computationally
efficient structure called the polyphase structure, which is used in the implementation of the MATLAB functions resample and upfirdn. Finally,
528
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x (n)
1
2
h(0)
3
z −1
I
Upsampler
↓D
y (m)
Downsampler
h(1)
h(M − 2)
z −1
h(M − 1)
FIGURE 10.31 Direct-form realization of FIR filter in sampling rate conversion
by a factor I/D
we close this section by discussing the time-variant filter structures for
the general case of sampling rate conversion.
DIRECT-FORM
FIR FILTER
STRUCTURES
In principle, the simplest realization of the filter is the direct-form FIR
structure with system function
H(z) =
M
−1
h(k)z −k
(10.62)
k=0
where h(k) is the unit sample response of the FIR filter. After designing the filter as discussed in the previous section, we will have the filter
parameters h(k), which allow us to implement the FIR filter directly, as
shown in Figure 10.31.
Although the direct-form FIR filter realization illustrated in Figure 10.31 is simple, it is also very inefficient. The inefficiency results from
the fact that the upsampling process introduces I −1 zeros between successive points of the input signal. If I is large, most of the signal components
in the FIR filter are zero. Consequently, most of the multiplications and
additions result in zeros. Furthermore, the downsampling process at the
output of the filter implies that only one out of every D output samples
is required at the output of the filter. Consequently, only one out of every
D possible values at the output of the filter should be computed.
To develop a more efficient filter structure, let us begin with a decimator that reduces the sampling rate by an integer factor D. From our
FIR Filter Structures for Sampling Rate Conversion
529
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
h(0)
x (n)
↓D
y (m)
x (n)
↓D
h(0)
y (m)
z −1
z −1
h(1)
↓D
h(M − 2)
↓D
h(1)
h(M − 2)
z −1
z −1
h(M − 1)
↓D
(a)
FIGURE 10.32
h(M − 1)
(b)
Decimation by a factor D: (a) Standard realization, (b) Efficient
realization
previous discussion, the decimator is obtained by passing the input sequence x(n) through an FIR filter and then downsampling the filter output by a factor D, as illustrated in Figure 10.32(a). In this configuration,
the filter is operating at the high sampling rate Fx , while only one out of
every D output samples is actually needed. The logical solution to this
inefficiency problem is to embed the downsampling operation within the
filter, as illustrated in the filter realization given in Figure 10.32(b). In this
filter structure, all the multiplications and additions are performed at the
lower sampling rate Fx /D. Thus, we have achieved the desired efficiency.
Additional reduction in computation can be achieved by exploiting the
symmetry characteristics of {h(k)}. Figure 10.33 illustrates an efficient
realization of the decimator in which the FIR filter has linear phase and
hence {h(k)} is symmetric.
Next, let us consider the efficient implementation of an interpolator,
which is realized by first inserting I − 1 zeros between samples of x(n)
and then filtering the resulting sequence. The direct-form realization is
illustrated in Figure 10.34. The major problem with this structure is that
the filter computations are performed at the high sampling rate of IFx .
The desired simplification is achieved by first using the transposed form of
the FIR filter, as illustrated in Figure 10.35(a), and then embedding the
upsampler within the filter, as shown in Figure 10.35(b). Thus, all the filter
multiplications are performed at the low rate Fx , while the upsampling
process introduces I −1 zeros in each of the filter branches of the structure
shown in Figure 10.35(b). The reader can easily verify that the two filter
structures in Figure 10.35 are equivalent.
530
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x (n)
↓D
↓D
z −1
h(0)
z −1
↓D
y (m)
↓D
h(1)
↓D
↓D
h(M − 2)
z −1
z−1
↓D
↓D
h(M − 1)
z −1
FIGURE 10.33 Efficient realization of a decimator that exploits the symmetry
in the FIR filter
x (n)
↑I
v (n)
h(0)
y (m)
z −1
h(1)
h(M − 2)
z −1
h(M − 1)
FIGURE 10.34
Direct-form realization of FIR filter in interpolation by a factor I
FIR Filter Structures for Sampling Rate Conversion
531
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x (n)
↑I
v (n)
h(0)
y (m)
h(0)
x (n)
z −1
z −1
h(1)
h(1)
h(M − 2)
h(M − 2)
↑I
↑I
z −1
z −1
h(M − 1)
h(M − 1)
(a)
FIGURE 10.35
y (m)
↑I
↑I
(b)
Efficient realization of an interpolator
It is interesting to note that the structure of the interpolator, shown
in Figure 10.35(b), can be obtained by transposing the structure of the
decimator shown in Figure 10.32. We observe that the transpose of a
decimator is an interpolator, and vice versa. These relationships are illustrated in Figure 10.36, where (b) is obtained by transposing (a) and (d) is
obtained by transposing (c). Consequently, a decimator is the dual of an
interpolator, and vice versa. From these relationships, it follows that there
is an interpolator whose structure is the dual of the decimator shown in
Figure 10.33, which exploits the symmetry in h(n).
POLYPHASE
FILTER STRUCTURE
The computational efficiency of the filter structure shown in Figure 10.35
can also be achieved by reducing the large FIR filter of length M into
a set of smaller filters of length K = M/I, where M is selected to be a
x (n)
↓D
Input
y (m)
x (n)
Output
Output
(a)
x (n)
↑I
Input
532
y (m)
Input
(b)
y (m)
x(n)
Output
Output
(c)
FIGURE 10.36
↑D
↓I
y(m)
Input
(d)
Duality relationships obtained through transpositions
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
p0(n)
Rate: Fy = IFx
p1(n)
x(n)
y(m)
Rate:
Fy = IFx
pI − 1(n)
Rate: Fx
FIGURE 10.37
Rate: Fx
Interpolation by use of polyphase filters
multiple of I. To demonstrate this point, let us consider the interpolator
given in Figure 10.34. Since the upsampling process inserts I − 1 zeros
between successive values of x(n), only K out of the M input values
stored in the FIR filter at any one time are non-zero. At one time-instant,
these non-zero values coincide and are multiplied by the filter coefficients
h(0), h(I), h(2I), . . . , h(M − I). In the following time instant, the nonzero values of the input sequence coincide and are multiplied by the filter
coefficients h(1), h(I + 1), h(2I + 1), and so on. This observation leads us
to define a set of smaller filters, called polyphase filters, with unit sample
responses
pk (n) = h(k + nI);
k = 0, 1, . . . , I − 1,
n = 0, 1, . . . , K − 1
(10.63)
where K = M/I is an integer.
From this discussion it follows that the set of I polyphase filters can
be arranged as a parallel realization, and the output of each filter can be
selected by a commutator, as illustrated in Figure 10.37. The rotation of
the commutator is in the counterclockwise direction beginning with the
point at m = 0. Thus, the polyphase filters perform the computations at
the low sampling rate Fx , and the rate conversion results from the fact
that I output samples are generated, one from each of the filters, for each
input sample.
The decomposition of {h(k)} into the set of I subfilters with impulse
response pk (n), k = 0, 1, . . . , I − 1 is consistent with our previous observation that the input signal was being filtered by a periodically time-variant
linear filter with impulse response
g(n, m) = h(nI + (mD)I )
FIR Filter Structures for Sampling Rate Conversion
(10.64)
533
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where D = 1 in the case of the interpolator. We noted previously that
g(n, m) varies periodically with period I. Consequently, a different set of
coefficients is used to generate the set of I output samples y(m), m =
0, 1, . . . , I − 1.
Additional insight can be gained about the characteristics of the set
of polyphase subfilters by noting that pk (n) is obtained from h(n) by
decimation with a factor I. Consequently, if the original filter frequency
response H(ω) is flat over the range 0 ≤ |ω| ≤ ω/I, each of the polyphase
subfilters possesses a relatively flat response over the range 0 ≤ |ω| ≤
π (i.e., the polyphase subfilters are basically all-pass filters and differ
primarily in their phase characteristics). This explains the reason for using
the term “polyphase” in describing these filters.
The polyphase filter can also be viewed as a set of I subfilters connected to a common delay line. Ideally, the kth subfilter will generate a
forward time shift of (k/I)Tx , for k = 0, 1, 2, . . . , I − 1, relative to the
zeroth subfilter. Therefore, if the zeroth filter generates zero delay, the
frequency response of the kth subfilter is
pk (ω) = ejωk/I
A time shift of an integer number of input sampling intervals (e.g., kTx )
can be generated by shifting the input data in the delay line by I samples
and using the same subfilters. By combining these two methods, we can
generate an output that is shifted forward by an amount (k + i/I)Tx
relative to the previous output.
By transposing the interpolator structure in Figure 10.37, we obtain
a commutator structure for a decimator based on the parallel bank of
polyphase filters, as illustrated in Figure 10.38. The unit sample responses
of the polyphase filters are now defined as
pk (n) = h(k + nD);
k = 0, 1, . . . , D − 1,
n = 0, 1, . . . , K − 1 (10.65)
where K = M/D is an integer when M is selected to be a multiple of
D. The commutator rotates in a counterclockwise direction, starting with
the filter p0 (n) at m = 0.
Although the two commutator structures for the interpolator and the
decimator just described rotate in a counterclockwise direction, it is also
possible to derive an equivalent pair of commutator structures having a
clockwise rotation. In this alternative formulation, the sets of polyphase
filters are defined to have impulse responses
pk (n) = h(nI − k),
k = 0, 1, . . . , I − 1
(10.66)
pk (n) = h(nD − k),
k = 0, 1, . . . , D − 1
(10.67)
and
for the interpolator and decimator, respectively,
534
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
p0(n)
y(m)
Rate: Fy =
Fx
D
p1(n)
x(n)
Rate: Fx
pI − 1(n)
Rate: Fy
FIGURE 10.38
Decimation by use of polyphase filters
EXAMPLE 10.17
For the decimation filter designed in Example 10.11, determine the polyphase
filter coefficients {pk (n)} in terms of the FIR filter coefficients {h(n)}
Solution
The polyphase filters obtained from h(n) have impulse responses
pk (n) = h(2n + k)
k = 0, 1;
n = 0, 1, . . . , 14
Note that p0 (n) = h(2n) and p1 (n) = h(2n + 1). Hence one filter consists of
the even-numbered samples of h(n), and the other filter consists of the oddnumbered samples of h(n).
EXAMPLE 10.18
For the interpolation filter designed in Example 10.8, determine the polyphase
filter coefficients {pk (n)} in terms of the filter coefficients {h(n)}.
Solution
The polyphase filters obtained from h(n) have impulse responses
pk (n) = h(5n + k)
k = 0, 1, 2, 3, 4
Consequently, each filter has length 6.
TIME-VARIANT
FILTER STRUCTURES
Having described the filter implementation for a decimator and an interpolator, let us now consider the general problem of sampling rate conversion by the factor I/D. In the general case of sampling rate conversion
by a factor I/D, the filtering can be accomplished by means of the linear
time-variant filter described by the response function
g(n, m) = h[nI − ((mD))I ]
FIR Filter Structures for Sampling Rate Conversion
(10.68)
535
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where h(n) is the impulse response of the low-pass FIR filter, which ideally, has the frequency response specified by (10.36). For convenience
we select the length of the FIR filter {h(n)} to a multiple of I (i.e.,
M = KI). As a consequence, the set of coefficients {g(n, m)} for each
m = 0, 1, 2, . . . , I − 1, contains K elements. Since g(n, m) is also periodic
with period I, as demonstrated in (10.44), it follows that the output y(m)
can be expressed as
y(m) =
K−1
g n, m −
m
n=0
I
I x
mD
−n
I
(10.69)
Conceptually, we can think of performing the computations specified
by (10.69) by processing blocks of data of length K by a set of K filter
coefficients g(n, m − m/I I), n = 0, 1, . . . , K − 1. There are I such sets
of coefficients, one set for each block of I output points of y(m). For each
block of I output points, there is a corresponding block of D input points
of x(n) that enter in the computation.
The block processing algorithm for computing (10.69) can be visualized as illustrated in Figure 10.39. A block of D input samples is buffered
and shifted into a second buffer of length K, one sample at a time. The
shifting from the input buffer to the second buffer occurs at a rate of
one sample each time the quantity mD/I increases by one. For each
output sample y(l), the samples from the second buffer are multiplied by
x(n)
Coefficient Storage
Input
buffer of
length D
g(n, 0); 0 ≤ n ≤ K −1
g(n, 1); 0 ≤ n ≤ K −1
Buffer
of
length
K
1
2
3
K
K−1
g(n, I − 1); 0 ≤ n ≤ K −1
Σ
n=0
Output
buffer of
length I
FIGURE 10.39
y(m)
Rate:
I
F
D x
Efficient implementation of sampling rate conversion by block
processing
536
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x(n)
Rate: Fx
z −1
z −1
x
mD
I
x
mD
−1
I
x
mD
−2
I
DI
DI
g(0, 艎); 艎 = 0,1,..., I − 1
y (m)
g(1, 艎)
Rate:
I
F
D x
g(2, 艎)
DI
z −1
x
g(K − 1, 艎)
mD
−K+1
I
DI
FIGURE 10.40
Efficient realization of sampling rate conversion by a factor I/D
the corresponding set of filter coefficients g(n, l) for n = 0, 1, . . . , K − 1,
and the K products are accumulated to give y(l), for l = 0, 1, . . . , I − 1.
Thus this computation produces I outputs. It is then repeated for a new
set of D input samples, and so on.
An alternative method for computing the output of the sampling rate
converter, specified by (10.69), is by means of an FIR filter structure with
periodically varying filter coefficients. Such a structure is illustrated in
Figure 10.40. The input samples x(n) are passed into a shift register that
operates at the sampling rate Fx and is of length K = M/I, where M
is the length of the time-invariant FIR filter specified by the frequency
response given by (10.36). Each stage of the register is connected to a
hold-and-sample device that serves to couple the input sampling rate Fx
to the output sampling rate Fy = (I/D)Fx . The sample at the input to
each hold-and-sample device is held until the next input sample arrives
and then is discarded. The output samples on the hold-and-sample device
are taken at times mD/I, m = 0, 1, 2, . . . . When both the input and
output sampling times coincide (i.e., when mD/I is an integer), the input
to the hold-and-sample is changed first; then the output samples the new
input. The K outputs from the K hold-and-sample devices are multiplied
by the periodically time-varying coefficients g(n, m − m/I I), for n = 0,
1, . . . , K − 1, and the resulting products are summed to yield y(m). The
computations at the output of the hold-and-sample devices are repeated
at the output sampling rate of Fy = (I/D)Fx .
Finally, rate conversion by a rational factor I/D can also be performed
by use of a polyphase filter having I subfilters. If we assume that the mth
sample y(m) is computed by taking the output of the im th subfilter with
input data x(n), x(n − 1), . . . , x(n − K + 1), in the delay line, the next
sample y(m + 1) is taken from the (im+1 )st subfilter after shifting lm+1
FIR Filter Structures for Sampling Rate Conversion
537
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
new samples in the delay lines where im+1 = (im + D)mod I and lm+1 is
the integer part of (im + D)/I. The integer im+1 should be saved to be
used in determining the subfilter from which the next sample is taken.
EXAMPLE 10.19
For the sampling rate converter designed in Example 10.15, specify the set
of time-varying coefficients {g(n, m)} used in the realization of the converter
based on the structure given in Figure 10.19. Also, specify the corresponding
implementation based in polyphase filters.
Solution
The coefficients of the filter are given by (10.43)
g(n, m) = h(nI + (mD)I ) = h nI + mD −
1pt
I I
mD
By substituting I = 5 and D = 2, we obtain
g(n, m) = h 5n + 2m − 5
2m
5
By evaluating g(n, m) for n = 0, 1, . . . , 5 and m = 0, 1, . . . , 5 and m = 0, 1, . . . ., 4
we obtain the following coefficients for the time-variant filter:
g(0, m)
g(1, m)
g(2, m)
g(3, m)
g(4, m)
g(5, m)
= {h(0)
= {h(5)
= {h(10)
= {h(15)
= {h(20)
= {h(25)
h(2)
h(7)
h(12)
h(17)
h(22)
h(27)
h(4)
h(9)
h(14)
h(19)
h(24)
h(29)
h(1)
h(6)
h(11)
h(16)
h(21)
h(26)
h(3)}
h(8)}
h(13)}
h(18)}
h(23)}
h(28)}
A polyphase filter implementation would employ five subfilters, each of length
six. To decimate the output of the polyphase filters by a factor of D = 2 simply
means that we take every other output from the polyphase filters. Thus, the first
output y(0) is taken from p0 (n), the second output y(1) is taken from p2 (n),
the third output is taken from p4 (n), the fourth output is taken from p1 (n), the
fifth output is taken from p3 (n), and so on.
PROBLEMS
P10.1 Consider the upsampler with input x(n) and output v(m) given in (10.26). Show that the
upsampler is a linear but time-varying system.
P10.2 Let x(n) = 0.9n u(n). The signal is applied to a downsampler that reduces the rate by a
factor of 2 to obtain the signal y(m).
1. Determine and plot the spectrum X(ω).
2. Determine and plot the spectrum Y (ω).
3. Show that the spectrum in part (22) is simply the DTFT of x(2n).
538
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P10.3 Consider a signal with spectrum
X(ω) =
non-zero,
0,
|ω| ≤ ω0 ;
ω0 < |ω| ≤ π.
1. Show that the signal x(n) can be recovered from its samples x(mD) if the sampling
frequency ωs = 2π/D ≥ 2ω0 .
2. Sketch the spectra of x(n) and x(mD) for D = 4.
3. Show that x(n) can reconstructed from the bandlimited interpolation
x(n) = fc
∞
x(kD) sin c[2fc (n − kD)];
ω0 < 2πfc < ωs − ω0
k=−∞
P10.4 Using the function downsample, study the operation of factor-of-4 downsampling on the
following sequences. Use the stem function to plot the original and the downsampled
sequences. Experiment using the default offset value of zero and the offset value equal to 2.
Comment on any differences.
1.
2.
3.
4.
5.
x1 (n) = cos(0.15πn), 0 ≤ n ≤ 100
x2 (n) = sin(0.1πn) + sin(0.4πn), 0 ≤ n ≤ 100
x3 (n) = 1 − cos(0.25πn), 0 ≤ n ≤ 100
x4 (n) = 0.1 n, 0 ≤ n ≤ 100
x5 (n) = {0, 1, 2, 3, 4, 5, 4, 3, 2, 1}PERIODIC , 0 ≤ n ≤ 100
P10.5 Repeat Problem P10.4 using the factor-of-5 downsampler.
P10.6 Using the fir2 function, generate a 101-length sequence x(n) whose frequency-domain
sampled values are 0.5 at ω = 0, 1 at ω = 0.1π, 1 at ω = 0.2, 0 at ω = 0.22π, and 0 at
ω = π.
1.
2.
3.
4.
5.
Compute and plot the DTFT
Downsample x(n) by a factor
Downsample x(n) by a factor
Downsample x(n) by a factor
Comment on your results.
of
of
of
of
x(n).
2 and plot the DTFT of the resulting sequence.
4 and plot the DTFT of the resulting sequence.
5 and plot the DTFT of the resulting sequence.
P10.7 Using the function decimate, study the operation of factor-of-4 decimation on the
following sequences. Use the stem function to plot the original and the decimated
sequences. Experiment, using both the default IIR and FIR decimation filters. Comment
on any differences.
1.
2.
3.
4.
5.
x1 (n) = sin(0.15πn), 0 ≤ n ≤ 100
x2 (n) = cos(0.1πn) + cos(0.4πn), 0 ≤ n ≤ 100
x3 (n) = 1 − cos(0.25πn), 0 ≤ n ≤ 100
x4 (n) = 0.1 n, 0 ≤ n ≤ 100
x5 (n) = {0, 1, 2, 3, 4, 5, 4, 3, 2, 1}PERIODIC , 0 ≤ n ≤ 100
P10.8 Repeat Problem P10.7 using the 4th-order IIR filter and the 15th-order FIR decimation
filters. Comment on any performance differences.
P10.9 Repeat Problem P10.7 using the factor-of-5 decimation. Comment on any differences.
P10.10 Repeat Problem P10.9 using the the 4th-order IIR filter and the 15th-order FIR
decimation filters. Comment on any differences.
Problems
539
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P10.11 Using the fir2 function, generate a 101-length sequence x(n) whose frequency-domain
sampled values are 0.5 at ω = 0, 1 at ω = 0.1π, 1 at ω = 0.2, 0 at ω = 0.22π, and 0 at
ω = π.
1.
2.
3.
4.
5.
Compute and plot the DTFT of x(n).
Decimate x(n) by a factor of 2 and plot the DTFT of the resulting sequence.
Decimate x(n) by a factor of 4 and plot the DTFT of the resulting sequence.
Decimate x(n) by a factor of 5 and plot the DTFT of the resulting sequence.
Comment on your results.
P10.12 Using the function upsample, study the operation of factor-of-4 upsampling on the
following sequences. Use the stem function to plot the original and the upsampled
sequences. Experiment using the default offset value of zero and the offset value
equal to 2.
1.
2.
3.
4.
5.
x1 (n) = sin(0.6πn), 0 ≤ n ≤ 100
x2 (n) = sin(0.8πn) + cos(0.5πn), 0 ≤ n ≤ 100
x3 (n) = 1 + cos(πn), 0 ≤ n ≤ 100
x4 (n) = 0.2 n, 0 ≤ n ≤ 100
x5 (n) = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0}PERIODIC , 0 ≤ n ≤ 100
P10.13 Using the fir2 function generate a 91-length sequence x(n) whose frequency-domain
sampled values are 0 at ω = 0, 0.5 at ω = 0.1π, 1 at ω = 0.2, 1 at ω = 0.7π, 0.5 at
ω = 0.75π, 0 at ω = 0.8π, and 0 at ω = π.
1.
2.
3.
4.
5.
Compute and plot the DTFT of x(n).
Upsample x(n) by a factor of 2 and plot the DTFT of the resulting sequence.
Upsample x(n) by a factor of 3 and plot the DTFT of the resulting sequence.
Upsample x(n) by a factor of 4 and plot the DTFT of the resulting sequence.
Comment on your results.
P10.14 Using the function interp, study the operation of factor-of-4 interpolation on the
sequences of Problem P10.12. Use the stem function to plot the original and the
interpolated sequences. Experiment, using the filter length parameter values equal to 3
and 5. Comment on any differences in performance of the interpolation.
P10.15 Provide the frequency response plots of the lowpass filters used in the interpolators of
Problem P10.14.
P10.16 Repeat Problem P10.14, using the factor-of-3 interpolation.
P10.17 Provide the frequency response plots of the lowpass filters used in the interpolators of
Problem P10.16.
P10.18 Repeat Problem P10.14, using the factor-of-5 interpolation.
P10.19 Provide the frequency response plots of the lowpass filters used in the interpolators of
Problem P10.18.
P10.20 Using the fir2 function generate a 91-length sequence x(n) whose frequency-domain
sampled values are 0 at ω = 0, 0.5 at ω = 0.1π, 1 at ω = 0.2, 1 at ω = 0.7π, 0.5 at
ω = 0.75π, 0 at ω = 0.8π, and 0 at ω = π.
1. Compute and plot the DTFT of x(n).
2. Upsample x(n) by a factor of 2 and plot the DTFT of the resulting sequence.
3. Upsample x(n) by a factor of 3 and plot the DTFT of the resulting sequence.
540
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4. Upsample x(n) by a factor of 4 and plot the DTFT of the resulting sequence.
5. Comment on your results.
P10.21 Consider two sequences x1 (n) and x2 (n), which appear to be related.
x1 (n) = max (10 − |n|, 0)
and
x2 (n) = min (|n|, 10)
Use the resample function with default parameters.
1. Resample the sequence x1 (n) at 3/2 times the original rate to obtain y1 (m) and
provide the stem plots of both sequences.
2. Resample the sequence x2 (n) at 3/2 times the original rate to obtain y2 (m) and
provide the stem plots of both sequences.
3. Explain why the resampled plot of y2 (n) has inaccuracies near the boundaries that
y1 (n) does not have.
4. Plot the frequency response of the filter used in the resampling operation.
P10.22 Let x(n) = cos(0.1πn) + 0.5 sin(0.2πn) + 0.25 cos(0.4πn). Use the resample function with
default parameters.
1. Resample the sequence x(n) at 4/5 times the original rate to obtain y1 (m) and provide
the stem plots of both sequences.
2. Resample the sequence x(n) at 5/4 times the original rate to obtain y2 (m) and provide
the stem plots of both sequences.
3. Resample the sequence x(n) at 2/3 times the original rate to obtain y3 (m) and provide
the stem plots of both sequences.
4. Explain which of the three output sequences retain the “shape” of the original sequence
x(n).
P10.23 Let x(n) = {0, 0, 0, 1, 1, 1, 1, 0, 0, 0}PERIODIC be a periodic sequence with period 10. Use
the resample function for the following parts to resample the sequence x(n) at 3/5 times
the original rate. Consider the length of the input sequence to be 80.
1. Use the filter length parameter L equal to zero to obtain y1 (m) and provide the stem
plots of x(n) and y1 (m) sequences.
2. Use the default value of the filter length parameter L to obtain y2 (m) and provide the
stem plots of x(n) and y2 (m) sequences.
3. Use the filter length parameter L equal to 15 to obtain y3 (m) and provide the stem
plots of x(n) and y3 (m) sequences.
P10.24 Using the fir2 function, generate a 101-length sequence x(n) whose frequency-domain
sampled values are 0 at ω = 0, 0.5 at ω = 0.1π, 1 at ω = 0.2π, 1 at ω = 0.5π, 0.5 at
ω = 0.55π, 0 at ω = 0.6π, and 0 at ω = π.
1.
2.
3.
4.
5.
Compute and plot the DTFT of x(n).
Resample x(n) by a factor of 4/3 and plot the DTFT of the resulting sequence.
Resample x(n) by a factor of 3/4 and plot the DTFT of the resulting sequence.
Resample x(n) by a factor of 4/5 and plot the DTFT of the resulting sequence.
Comment on your results.
P10.25 We want to design a linear-phase FIR filter to increase the input sampling rate by a factor
of 3 using the intfilt function.
1. Assuming full bandwidth of the signal to be interpolated, determine the impulse
response of the required FIR filter. Plot its amplitude response and the log-magnitude
Problems
541
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
response in dB. Experiment with the length parameter L to obtain a reasonable
stopband attenuation.
2. Assuming that bandwidth of the signal to be interpolated is π/2, determine the
impulse response of the required FIR filter. Plot its amplitude response and the
log-magnitude response in dB. Again experiment with the length parameter L to obtain
a reasonable stopband attenuation.
P10.26 We want to design a linear-phase FIR filter to increase the input sampling rate by a factor
of 5 using the intfilt function.
1. Assuming full bandwidth of the signal to be interpolated, determine the impulse
response of the required FIR filter. Plot its amplitude response and the log-magnitude
response in dB. Experiment with the length parameter L to obtain a reasonable
stopband attenuation.
2. Assuming that bandwidth of the signal to be interpolated is 4π/5, determine the
impulse response of the required FIR filter. Plot its amplitude response and the
log-magnitude response in dB. Again experiment with the length parameter L to obtain
a reasonable stopband attenuation.
P10.27 Using the Parks-McClellan algorithm, design an interpolator that increases the input
sampling rate by a factor of I = 2.
1. Determine the coefficients of the FIR filter that has 0.5 dB ripple in the passband and
50 dB attenuation in the stopband. Choose reasonable values for the band-edge
frequencies.
2. Provide plots of the impulse and the log-magnitude responses.
3. Determine the corresponding polyphase structure for implementing the filter.
4. Let x(n) = cos(0.4πn). Generate 100 samples of x(n) and process it using the
above-designed filter to interpolate by I = 2 to obtain y(m). Provide the stem plots of
the both sequences.
P10.28 Using the Parks-McClellan algorithm, design an interpolator that increases the input
sampling rate by a factor of I = 3.
1. Determine the coefficients of the FIR filter that has 0.1 dB ripple in the passband and
40 dB attenuation in the stopband. Choose reasonable values for the band-edge
frequencies.
2. Provide plots of the impulse and the log-magnitude responses.
3. Determine the corresponding polyphase structure for implementing the filter.
4. Let x(n) = cos(0.3πn). Generate 100 samples of x(n) and process it using the
above-designed filter to interpolate by I = 3 to obtain y(m). Provide the stem plots of
both sequences.
P10.29 A signal x(n) is to be interpolated by a factor of 3. It has a bandwidth of 0.4π, but we
want to preserve frequency band up to 0.3π in the interpolated signal. Using the
Parks-McClellan algorithm, we want to design such an interpolator.
1. Determine the coefficients of the FIR filter that has 0.1 dB ripple in the passband and
40 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Let x(n) = cos(0.3πn) + 0.5 sin(0.4πn). Generate 100 samples of x(n) and process it
using the above-designed filter to interpolate by I = 3 to obtain y(m). Provide the stem
plots of both sequences.
542
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
P10.30 A signal x(n) is to be interpolated by a factor of 4. It has a bandwidth of 0.7π, but we
want to preserve frequency band up to 0.6π in the interpolated signal. Using the
Parks-McClellan algorithm, we want to design such an interpolator.
1. Determine the coefficients of the FIR filter that has 0.5 dB ripple in the passband and
50 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Let x(n) = sin(0.5πn) + cos(0.7πn). Generate 100 samples of x(n) and process it using
the above-designed filter to interpolate by I = 4 to obtain y(m). Provide the stem plots
of both sequences.
P10.31 Using the Parks-McClellan algorithm, design a decimator that downsamples an input
signal x(n) by a factor of D = 5.
1. Determine the coefficients of the FIR filter that has 0.1 dB ripple in the passband and
30 dB attenuation in the stopband. Choose reasonable values for the band-edge
frequencies.
2. Provide plots of the impulse and the log-magnitude responses.
3. Determine the corresponding polyphase structure for implementing the filter.
4. Using the fir2 function, generate a 131-length sequence x(n) whose frequency-domain
sampled values are 1 at ω = 0, 0.9 at ω = 0.1π, 1 at ω = 0.2π, 1 at ω = 0.5π, 0.5 at
ω = 0.55π, 0 at ω = 0.6π, and 0 at ω = π. Process x(n) using the above-designed filter
to decimate it by a factor of 5 to obtain y(m). Provide the spectral plots of both
sequences.
P10.32 Using the Parks-McClellan algorithm, design a decimator that downsamples an input
signal x(n) by a factor of D = 3.
1. Determine the coefficients of the FIR filter that has 0.5 dB ripple in the passband and
30 dB attenuation in the stopband. Choose reasonable values for the band-edge
frequencies.
2. Provide plots of the impulse and the log-magnitude responses.
3. Let x1 (n) = sin(0.2πn) + 0.2 cos(0.5πn). Generate 500 samples of x1 (n) and process it
using the above-designed filter to decimate by D = 3 to obtain y1 (m). Provide the stem
plots of both sequences.
4. Using the fir2 function, generate a 131-length sequence x2 (n) whose frequency-domain
sampled values are 1 at ω = 0, 0.8 at ω = 0.15π, 1 at ω = 0.3π, 1 at ω = 0.4π, 0.5 at
ω = 0.45π, 0 at ω = 0.5π, and 0 at ω = π. Process x2 (n), using the above-designed
filter to decimate it by a factor of 3 to obtain y2 (m). Provide the spectral plots of both
sequences.
P10.33 A signal x(n) is to be decimated by a factor of D = 2. It has a bandwidth of 0.4π, and we
will tolerate aliasing above frequency 0.45π in the decimated signal. Using the
Parks-McClellan algorithm, we want to design such a decimator.
1. Determine the coefficients of the FIR filter that has 0.1 dB ripple in the passband and
45 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Let x1 (n) = cos(0.4πn) + 2 sin(0.45πn). Generate 200 samples of x1 (n) and process it
using the above-designed filter to decimate by D = 2 to obtain y1 (m). Provide the stem
plots of both sequences.
Problems
543
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
4. Using the fir2 function, generate a 151-length sequence x2 (n) whose frequency-domain
sampled values are 1 at ω = 0, 0.9 at ω = 0.2π, 1 at ω = 0.4π, 0.5 at ω = 0.45π, 0 at
ω = 0.5π, and 0 at ω = π. Process x2 (n), using the above-designed filter to decimate it
by a factor of 2 to obtain y2 (m). Provide the spectral plots of both sequences.
P10.34 A signal x(n) is to be decimated by a factor of D = 3. It has a bandwidth of 0.25π, and we
will tolerate aliasing above frequency 0.3π in the decimated signal. Using the
Parks-McClellan algorithm, we want to design such a decimator.
1. Determine the coefficients of the FIR filter that has 0.1 dB ripple in the passband and
40 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Let x1 (n) = cos(0.2πn) + 2 sin(0.3πn). Generate 300 samples of x1 (n), and process it
using the above-designed filter to decimate by D = 3 to obtain y1 (m). Provide the stem
plots of both sequences.
4. Using the fir2 function, generate a 151-length sequence x2 (n) whose frequency-domain
sampled values are 1 at ω = 0, 1 at ω = 0.1π, 1 at ω = 0.25π, 0.5 at ω = 0.3π, 0 at
ω = 0.35π, and 0 at ω = π. Process x2 (n), using the above-designed filter to decimate it
by a factor of 3 to obtain y2 (m). Provide the spectral plots of both sequences.
P10.35 Design a sampling rate converter that reduces the sampling rate by a factor of 2/5.
1. Using the Parks-McClellan algorithm, determine the coefficients of the FIR filter that
has 0.1 dB ripple in the passband and 30 dB attenuation in the stopband. Choose
reasonable values for the band-edge frequencies.
2. Provide plots of the impulse and the log-magnitude responses.
3. Specify the sets of the time-varying coefficients g(m, n) and the corresponding
coefficients in the polyphase filter realization.
4. Let x(n) = sin(0.35πn) + 2 cos(0.45πn). Generate 500 samples of x(n) and process it
using the above-designed filter to resample by 2/5 to obtain y(m). Provide the stem
plots of both sequences.
P10.36 Design a sampling rate converter that increases the sampling rate by a factor of 7/4.
1. Using the Parks-McClellan algorithm, determine the coefficients of the FIR filter that
has 0.1 dB ripple in the passband and 40 dB attenuation in the stopband. Choose
reasonable values for the band-edge frequencies.
2. Provide plots of the impulse and the log-magnitude responses.
3. Specify the sets of the time-varying coefficients g(m, n) and the corresponding
coefficients in the polyphase filter realization.
4. Let x(n) = 2 sin(0.35πn) + cos(0.95πn). Generate 500 samples of x(n) and process it,
using the above-designed filter to resample by 2/5 to obtain y(m). Provide the stem
plots of both sequences.
P10.37 A signal x(n) is to be resampled by a factor of 3/2. It has a total bandwidth of 0.8π, but
we want to preserve frequencies only up to 0.75π and require that the band up to 0.6π be
free of aliasing in the resampled signal.
1. Using the Parks-McClellan algorithm, determine the coefficients of the FIR filter that
has 0.5 dB ripple in the passband and 50 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Using the fir2 function, generate a 101-length sequence x(n) whose frequency-domain
sampled values are 0.7 at ω = 0, 1 at ω = 0.3π, 1 at ω = 0.7π, 0.5 at ω = 0.75π, 0 at
544
Chapter 10
SAMPLING RATE CONVERSION
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
ω = 0.8π, and 0 at ω = π. Process x(n) using the above-designed filter to decimate it
by a factor of 3 to obtain y(m). Provide the spectral plots of both sequences.
P10.38 A signal x(n) is to be resampled by a factor of 4/5. It has a total bandwidth of 0.8π, but
we want to preserve frequencies only up to 0.75π and require that the band up to 0.5π be
free of aliasing in the resampled signal.
1. Using the Parks-McClellan algorithm, determine the coefficients of the FIR filter that
has 0.1 dB ripple in the passband and 40 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Using the fir2 function, generate a 101-length sequence x(n) whose frequency-domain
sampled values are 0.7 at ω = 0, 1 at ω = 0.3π, 1 at ω = 0.7π, 0.5 at ω = 0.75π, 0 at
ω = 0.8π, and 0 at ω = π. Process x(n), using the above-designed filter to decimate it
by a factor of 3 to obtain y(m). Provide the spectral plots of both sequences.
P10.39 A signal x(n) is to be resampled by a factor of 5/2. It has a total bandwidth of 0.8π, but
we want to preserve frequencies only up to 0.75π and require that the band up to 0.7π be
free of aliasing in the resampled signal.
1. Using the Parks-McClellan algorithm, determine the coefficients of the FIR filter that
has 0.5 dB ripple in the passband and 50 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Using the fir2 function, generate a 101-length sequence x(n) whose frequency-domain
sampled values are 0.7 at ω = 0, 1 at ω = 0.3π, 1 at ω = 0.7π, 0.5 at ω = 0.75π, 0 at
ω = 0.8π, and 0 at ω = π. Process x(n) using the above-designed filter to decimate it
by a factor of 3 to obtain y(m). Provide the spectral plots of both sequences.
P10.40 A signal x(n) is to be resampled by a factor of 3/8. It has a total bandwidth of 0.5π, but
we want to preserve frequencies only up to 0.35π and require that the band up to 0.3π be
free of aliasing in the resampled signal.
1. Using the Parks-McClellan algorithm, determine the coefficients of the FIR filter that
has 0.1 dB ripple in the passband and 40 dB attenuation in the stopband.
2. Provide plots of the impulse and the log-magnitude responses.
3. Using the fir2 function, generate a 101-length sequence x(n) whose frequency-domain
sampled values are 1 at ω = 0, 1 at ω = 0.25π, 1 at ω = 0.5π, 0.5 at ω = 0.55π, 0 at
ω = 0.6π, and 0 at ω = π. Process x(n) using the above-designed filter to decimate it
by a factor of 3 to obtain y(m). Provide the spectral plots of both sequences.
Problems
545
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
11
Applications
in Adaptive
Filtering
In Chapters 7 and 8 we described methods for designing FIR and IIR digital filters to satisfy some desired specifications. Our goal was to determine
the coefficients of the digital filter that met the desired specifications.
In contrast to the filter design techniques considered in those two
chapters, there are many digital signal processing applications in which
the filter coefficients cannot be specified a priori. For example, let us consider a high-speed modem that is designed to transmit data over telephone
channels. Such a modem employs a filter called a channel equalizer to compensate for the channel distortion. The modem must effectively transmit
data through communication channels that have different frequency response characteristics and hence result in different distortion effects. The
only way in which this is possible is if the channel equalizer has adjustable
coefficients that can be optimized to minimize some measure of the distortion, on the basis of measurements performed on the characteristics of
the channel. Such a filter with adjustable parameters is called an adaptive
filter, in this case an adaptive equalizer.
Numerous applications of adaptive filters have been described in the
literature. Some of the more noteworthy applications include (1) adaptive
antenna systems, in which adaptive filters are used for beam steering and
for providing nulls in the beam pattern to remove undesired interference
[28]; (2) digital communication receivers, in which adaptive filters are
used to provide equalization of intersymbol interference and for channel
546
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
identification [21]; (3) adaptive noise canceling techniques, in which an
adaptive filter is used to estimate and eliminate a noise component in
some desired signal [27, 9, 15] and (4) system modeling, in which an
adaptive filter is used as a model to estimate the characteristics of an unknown system. These are just a few of the best known examples on the use
of adaptive filters.
Although both IIR and FIR filters have been considered for adaptive filtering, the FIR filter is by far the most practical and widely used.
The reason for this preference is quite simple. The FIR filter has only
adjustable zeros, and hence it is free of stability problems associated with
adaptive IIR filters that have adjustable poles as well as zeros. We should
not conclude, however, that adaptive FIR filters are always stable. On the
contrary, the stability of the filter depends critically on the algorithm for
adjusting its coefficients.
Of the various FIR filter structures that we may use, the direct form
and the lattice form are the ones often used in adaptive filtering applications. The direct form FIR filter structure with adjustable coefficients
h(0), h(1), . . . , h(N − 1) is illustrated in Figure 11.1. On the other hand,
the adjustable parameters in an FIR lattice structure are the reflection
coefficients Kn shown in Figure 6.18.
An important consideration in the use of an adaptive filter is the
criterion for optimizing the adjustable filter parameters. The criterion
must not only provide a meaningful measure of filter performance, but it
must also result in a practically realizable algorithm.
One criterion that provides a good measure of performance in adaptive filtering applications is the least-squares criterion, and its counterpart
in a statistical formulation of the problem, namely, the mean-square-error
(MSE) criterion. The least squares (and MSE) criterion results in a quadratic performance index as a function of the filter coefficients, and hence
it possesses a single minimum. The resulting algorithms for adjusting the
coefficients of the filter are relatively easy to implement.
FIGURE 11.1
Applications in Adaptive Filtering
Direct-form adaptive FIR filter
547
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
In this chapter we describe a basic algorithm, called the least-meansquare (LMS) algorithm, to adaptively adjust the coefficients of an FIR
filter. The adaptive filter structure that will be implemented is the direct form FIR filter structure with adjustable coefficients h(0), h(1), . . . ,
h(N − 1), as illustrated in Figure 11.1. After we describe the LMS algorithm, we apply it to several practical systems in which adaptive filters
are employed.
LMS ALGORITHM FOR COEFFICIENT ADJUSTMENT
Suppose we have an FIR filter with adjustable coefficients {h(k), 0 ≤ k ≤
N − 1}. Let {x(n)} denote the input sequence to the filter, and let the
corresponding output be {y(n)}, where
N
−1
y(n) =
h(k)x (n − k) ,
n = 0, . . . , M
(11.1)
k=0
Suppose that we also have a desired sequence {d(n)} with which we can
compare the FIR filter output. Then we can form the error sequence
{e(n)} by taking the difference between d(n) and y(n). That is,
e(n) = d(n) − y(n),
n = 0, . . . , M
(11.2)
The coefficients of the FIR filter will be selected to minimize the sum of
squared errors. Thus we have
E =
M
e2 (n) =
n=0
=
M
M
d(n) −
N
−1
n=0
d2 (n) − 2
h(k)x (n − k)
(11.3)
k=0
N
−1
n=0
2
h(k)rdx (k) +
k=0
N
−1 N
−1
h(k)h () rxx (k − )
k=0 =0
where, by definition,
rdx (k) =
M
d(n)x (n − k) ,
0≤k ≤N −1
(11.4)
x(n)x (n + k) ,
0≤k ≤N −1
(11.5)
n=0
rxx (k) =
M
n=0
548
Chapter 11
APPLICATIONS IN ADAPTIVE FILTERING
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
We call {rdx (k)} the crosscorrelation between the desired output sequence
{d(n)} and the input sequence {x(n)}, and {rxx (k)} is the autocorrelation
sequence of {x(n)}.
The sum of squared errors E is a quadratic function of the FIR filter
coefficients. Consequently, the minimization of E with respect to the filter
coefficients {h(k)} results in a set of linear equations. By differentiating
E with respect to each of the filter coefficients, we obtain
∂E
= 0,
∂h(m)
0≤m≤N −1
(11.6)
and, hence
N
−1
h(k)rxx (k − m) = rdx (m),
0≤m≤N −1
(11.7)
k=0
This is the set of linear equations that yield the optimum filter coefficients.
To solve the set of linear equations directly, we must first compute
the autocorrelation sequence {rxx (k)} of the input signal and the crosscorrelation sequence {rdx (k)} between the desired sequence {d(n)} and
the input sequence {x(n)}.
The LMS algorithm provides an alternative computational method for
determining the optimum filter coefficients {h(k)} without explicitly computing the correlation sequences {rxx (k)} and {rdx (k)}. The algorithm is
basically a recursive gradient (steepest-descent) method that finds the
minimum of E and thus yields the set of optimum filter coefficients.
We begin with any arbitrary choice for the initial values of {h(k)},
say {h0 (k)}. For example, we may begin with h0 (k) = 0, 0 ≤ k ≤ N −1.
Then after each new input sample {x(n)} enters the adaptive FIR filter,
we compute the corresponding output, say {y(n)}, form the error signal
e(n) = d(n) − y(n), and update the filter coefficients according to the
equation
hn (k) = hn−1 (k) + · e(n) · x (n − k) ,
0 ≤ k ≤ N − 1,
n = 0, 1, . . .
(11.8)
where is called the step size parameter, x(n − k) is the sample of the
input signal located at the kth tap of the filter at time n, and e(n)x (n − k)
is an approximation (estimate) of the negative of the gradient for the kth
filter coefficient. This is the LMS recursive algorithm for adjusting the
filter coefficients adaptively so as to minimize the sum of squared errors E.
The step size parameter controls the rate of convergence of the
algorithm to the optimum solution. A large value of leads to large step
size adjustments and thus to rapid convergence, while a small value of
results in slower convergence. However, if is made too large the
algorithm becomes unstable. To ensure stability, must be chosen [21]
LMS Algorithm for Coefficient Adjustment
549
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
to be in the range
1
(11.9)
10N Px
where N is the length of the adaptive FIR filter and Px is the power in
the input signal, which can be approximated by
0<<
M
1 2
rxx (0)
Px ≈
x (n) =
1 + M n=0
M +1
(11.10)
The mathematical justification of equations (11.9) and (11.10) and the
proof that the LMS algorithm leads to the solution for the optimum filter
coefficients is given in more advanced treatments of adaptive filters. The
interested reader may refer to the books by Haykin [8] and Proakis [21].
MATLAB
IMPLEMENTATION
The LMS algorithm (11.8) can easily be implemented in MATLAB.
Given the input sequence {x(n)}, the desired sequence {d(n)}, step
size , and the desired length of the adaptive FIR filter N , we can
use (11.1), (11.2), and (11.8) to determine the adaptive filter coefficients
{h(n), 0 ≤ n ≤ N − 1} recursively. This is shown in the following function
called lms.
function [h,y] = lms(x,d,delta,N)
% LMS Algorithm for Coefficient Adjustment
% ---------------------------------------% [h,y] = lms(x,d,delta,N)
%
h = estimated FIR filter
%
y = output array y(n)
%
x = input array x(n)
%
d = desired array d(n), length must be same as x
% delta = step size
%
N = length of the FIR filter
%
M = length(x); y = zeros(1,M);
h = zeros(1,N);
for n = N:M
x1 = x(n:-1:n-N+1);
y = h * x1’;
e = d(n) - y;
h = h + delta*e*x1;
end
In addition, the lms function provides the output {y(n)} of the adaptive
filter.
Below, we apply the LMS algorithm to several practical applications
involving adaptive filtering.
550
Chapter 11
APPLICATIONS IN ADAPTIVE FILTERING
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
SYSTEM IDENTIFICATION OR SYSTEM MODELING
To formulate the problem, let us refer to Figure 11.2. We have an unknown
linear system that we wish to identify. The unknown system may be an
all-zero (FIR) system or a pole-zero (IIR) system. The unknown system
will be approximated (modeled) by an FIR filter of length N . Both the
unknown system and the FIR model are connected in parallel and are
excited by the same input sequence {x(n)}. If {y(n)} denotes the output
of the model and {d(n)} denotes the output of the unknown system, the
error sequence is {e(n) = d(n) − y(n)}. If we minimize the sum of squared
errors, we obtain the same set of linear equations as in (11.7). Therefore,
the LMS algorithm given by (11.8) may be used to adapt the coefficients of
the FIR model so that its output approximates the output of the unknown
system.
PROJECT 11.1:
SYSTEM
IDENTIFICATION
There are three basic modules that are needed to perform this project.
1. A noise signal generator that generates a sequence of random numbers
with zero mean value. For example, we may generate a sequence of
uniformly distributed random numbers over the interval [−a, a]. Such
a sequence of uniformly distributed numbers has an average value of
zero and a variance of a2 /3. This signal sequence, call it {x(n)}, will be
used as the input to the unknown system and the adaptive FIR model.
In this case the input signal {x(n)} has power Px = a2 /3. In MATLAB
this can be implemented using the rand function.
2. An unknown system module that may be selected is an IIR filter and
implemented by its difference equation. For example, we may select an
IIR filter specified by the second-order difference equation
d(n) = a1 d (n − 1) + a2 d (n − 2) + x(n) + b1 x (n − 1) + b2 x (n − 2)
(11.11)
FIGURE 11.2
Block diagram of system identification or system modeling
problem
System Identification or System Modeling
551
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where the parameters {a1 , a2 } determine the positions of the poles and
{b1 , b2 } determine the positions of the zeros of the filter. These parameters are input variables to the program. This can be implemented by
the filter function.
3. An adaptive FIR filter module where the FIR filter has N tap coefficients that are adjusted by means of the LMS algorithm. The length
N of the filter is an input variable to the program. This can be implemented using the lms function given in the previous section.
The three modules are configured as shown in Figure 11.2. From this
project we can determine how closely the impulse response of the FIR
model approximates the impulse response of the unknown system after
the LMS algorithm has converged.
To monitor the convergence rate of the LMS algorithm, we may compute a short-term average of the squared error e2 (n) and plot it. That is,
we may compute
n+K
1 2
ASE(m) =
e (k)
(11.12)
K
k=n+1
where m = n/K = 1, 2, . . . . The averaging interval K may be selected
to be (approximately) K = 10N . The effect of the choice of the step
size parameter on the convergence rate of the LMS algorithm may be
observed by monitoring the ASE(m).
Besides the main part of the program, you should also include, as an
aside, the computation of the impulse response of the unknown system,
which can be obtained by exciting the system with a unit sample sequence
δ(n). This actual impulse response can be compared with that of the FIR
model after convergence of the LMS algorithm. The two impulse responses
can be plotted for the purpose of comparison.
SUPPRESSION OF NARROWBAND INTERFERENCE
IN A WIDEBAND SIGNAL
Let us assume that we have a signal sequence {x(n)} that consists of a
desired wideband signal sequence, say {w(n)}, corrupted by an additive
narrowband interference sequence {s(n)}. The two sequences are uncorrelated. This problem arises in digital communications and in signal detection, where the desired signal sequence {w(n)} is a spread-spectrum
signal, while the narrowband interference represents a signal from another
user of the frequency band or some intentional interference from a jammer
who is trying to disrupt the communication or detection system.
552
Chapter 11
APPLICATIONS IN ADAPTIVE FILTERING
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 11.3
Adaptive filter for estimating and suppressing a narrowband in-
terference
From a filtering point of view, our objective is to design a filter that
suppresses the narrowband interference. In effect, such a filter should place
a notch in the frequency band occupied by the interference. In practice,
however, the frequency band of the interference might be unknown. Moreover, the frequency band of the interference may vary slowly in time.
The narrowband characteristics of the interference allow us to estimate s(n) from past samples of the sequence x(n) = s(n) + w(n) and to
subtract the estimate from x(n). Since the bandwidth of {s(n)} is narrow compared to the bandwidth of {w(n)}, the samples of {s(n)} are
highly correlated. On the other hand, the wideband sequence {w(n)} has
a relatively narrow correlation.
The general configuration of the interference suppression system is
shown in Figure 11.3. The signal x(n) is delayed by D samples, where
the delay D is chosen sufficiently large so that the wideband signal components w(n) and w(n − D), which are contained in x(n) and x(n − D),
respectively, are uncorrelated. The output of the adaptive FIR filter is the
estimate
ŝ(n) =
N
−1
h(k)x(n − k − D)
(11.13)
k=0
The error signal that is used in optimizing the FIR filter coefficients is
e(n) = x(n) − ŝ(n). The minimization of the sum of squared errors again
leads to a set of linear equations for determining the optimum coefficients.
Due to the delay D, the LMS algorithm for adjusting the coefficients
recursively becomes
hn (k) = hn−1 (k) + e(n)x(n − k − D),
Suppression of Narrowband Interference in a Wideband Signal
k = 0, 1, . . . , N − 1
(11.14)
n = 1, 2, . . .
553
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 11.4
Configuration of modules for experiment on interference suppres-
sion
PROJECT 11.2:
SUPPRESSION
OF
SINUSOIDAL
INTERFERENCE
There are three basic modules required to perform this project.
1. A noise signal generator module that generates a wideband sequence
{w(n)} of random numbers with zero mean value. In particular, we may
generate a sequence of uniformly distributed random numbers using
the rand function as previously described in the project on system
identification. The signal power is denoted as Pw .
2. A sinusoidal signal generator module that generates a sine wave sequence s(n) = A sin ω0 n, where 0 < ω0 < π and A is the signal amplitude. The power of the sinusoidal sequence is denoted as Ps .
3. An adaptive FIR filter module using the lms function, where the FIR
filter has N tap coefficients that are adjusted by the LMS algorithm.
The length N of the filter is an input variable to the program.
The three modules are configured as shown in Figure 11.4. In this
project the delay D = 1 is sufficient, since the sequence {w(n)} is a white
noise (spectrally flat or uncorrelated) sequence. The objective is to adapt
the FIR filter coefficients and then to investigate the characteristics of the
adaptive filter.
It is interesting to select the interference signal to be much stronger
than the desired signal w(n), for example, Ps = 10Pw . Note that the
power Px required in selecting the step size parameter in the LMS algorithm is Px = Ps + Pw . The frequency response characteristic H(ejω ) of
the adaptive FIR filter with coefficients {h(k)} should exhibit a resonant
peak at the frequency of the interference. The frequency response of the
interference suppression filter is Hs (ejω ) = 1 − H(ejω ), which should then
exhibit a notch at the frequency of the interference.
It is interesting to plot the sequences {w(n)}, {s(n)}, and {x(n)}. It
is also interesting to plot the frequency responses H(ejω ) and Hs (ejω )
after the LMS algorithm has converged. The short-time average squared
error ASE(m), defined by (11.12), may be used to monitor the convergence characteristics of the LMS algorithm. The effect of the length of
the adaptive filter on the quality of the estimate should be investigated.
554
Chapter 11
APPLICATIONS IN ADAPTIVE FILTERING
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The project may be generalized by adding a second sinusoid of a
different frequency. Then H(ejω ) should exhibit two resonant peaks, provided the frequencies are sufficiently separated. Investigate the effect of
the filter length N on the resolution of two closely spaced sinusoids.
ADAPTIVE LINE ENHANCEMENT
In the preceding section we described a method for suppressing a strong
narrowband interference from a wideband signal. An adaptive line enhancer (ALE) has the same configuration as the interference suppression
filter in Figure 11.3, except that the objective is different.
In the adaptive line enhancer, {s(n)} is the desired signal and {w(n)}
represents a wideband noise component that masks {s(n)}. The desired
signal {s(n)} may be a spectral line (a pure sinusoid) or a relatively
narrowband signal. Usually, the power in the wideband signal is greater
than that in the narrowband signal—that is, Pw > Ps . It is apparent that
the ALE is a self-tuning filter that has a peak in its frequency response
at the frequency of the input sinusoid or in the frequency band occupied
by the narrowband signal. By having a narrow bandwidth FIR filter, the
noise outside the frequency band of the signal is suppressed, and thus
the spectral line is enhanced in amplitude relative to the noise power in
{w(n)}.
PROJECT 11.3:
ADAPTIVE
LINE
ENHANCEMENT
This project requires the same software modules as those used in the
project on interference suppression. Hence the description given in
the preceding section applies directly. One change is that in the ALE, the
condition is that Pw > Ps . Secondly, the output signal from the ALE is
{s(n)}. Repeat the project described in the previous section under these
conditions.
ADAPTIVE CHANNEL EQUALIZATION
The speed of data transmission over telephone channels is usually limited
by channel distortion that causes intersymbol interference (ISI). At data
rates below 2400 bits the ISI is relatively small and is usually not a problem in the operation of a modem. However, at data rates above 2400 bits,
an adaptive equalizer is employed in the modem to compensate for the
channel distortion and thus to allow for highly reliable high-speed data
transmission. In telephone channels, filters are used throughout the system to separate signals in different frequency bands. These filters cause
Adaptive Channel Equalization
555
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 11.5
Application of adaptive filtering to adaptive channel equalization
amplitude and phase distortion. The adaptive equalizer is basically an
adaptive FIR filter with coefficients that are adjusted by means of the
LMS algorithm to correct for the channel distortion.
A block diagram showing the basic elements of a modem transmitting data over a channel is given in Figure 11.5. Initially, the equalizer
coefficients are adjusted by transmitting a short training sequence, usually less than one second in duration. After the short training period,
the transmitter begins to transmit the data sequence {a(n)}. To track
the possible slow time variations in the channel, the equalizer coefficients
must continue to be adjusted in an adaptive manner while receiving data.
This is usually accomplished, as illustrated in Figure 11.5, by treating
the decisions at the output of the decision device as correct, and using
the decisions in place of the reference {d(n)} to generate the error signal.
This approach works quite well when decision errors occur infrequently,
such as less than one error in 100 data symbols. The occasional decision
errors cause only a small misadjustment in the equalizer coefficients.
PROJECT 11.4:
ADAPTIVE
CHANNEL
EQUALIZATION
The objective of this project is to investigate the performance of an adaptive equalizer for data transmission over a channel that causes intersymbol interference. The basic configuration of the system to be simulated
is shown in Figure 11.6. As we observe, five basic modules are required.
Note that we have avoided carrier modulation and demodulation, which
is required in a telephone channel modem. This is done to simplify the
simulation program. However, all processing involves complex arithmetic
operations.
The five modules are as follows:
1. The data generator module is used to generate a sequence of complexvalued information symbols {a(n)}. In particular, employ four equally
probable symbols s + js, s − js, −s + js, and −s − js, where s is a
scale factor that may be set to s = 1, or it can be an input parameter.
556
Chapter 11
APPLICATIONS IN ADAPTIVE FILTERING
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 11.6
Experiment for investigating the performance of an adaptive
equalizer
2. The channel filter module is an FIR filter with coefficients {c(n),
0 ≤ n ≤ K − 1} that simulates the channel distortion. For distortionless transmission, set c(0) = 1 and c(n) = 0 for 1 ≤ n ≤ K − 1. The
length K of the filter is an input parameter.
3. The noise generator module is used to generate additive noise that is
usually present in any digital communication system. If we are modeling noise that is generated by electronic devices, the noise distribution
should be Gaussian with zero mean. Use the randu function.
4. The adaptive equalizer module is an FIR filter with tap coefficients
{h(k), 0 < k < N − 1}, which are adjusted by the LMS algorithm.
However, due to the use of complex arithmetic, the recursive equation
in the LMS algorithm is slightly modified to
hn (k) = hn−1 (k) + e(n)x∗ (n − k)
(11.15)
where the asterisk denotes the complex conjugate.
5. The decision device module takes the estimate â(n) and quantizes it
to one of the four possible signal points on the basis of the following
decision rule:
Adaptive Channel Equalization
Re [â(n)] > 0
and
Im [â(n)] > 0
−→
1+j
Re [â(n)] > 0
and
Im [â(n)] < 0
−→
1−j
Re [â(n)] < 0
and
Im [â(n)] > 0
−→
−1 + j
Re [â(n)] < 0
and
Im [â(n)] < 0
−→
−1 − j
557
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
The effectiveness of the equalizer in suppressing the ISI introduced by
the channel filter may be seen by plotting the following relevant sequences
in a two-dimensional (real–imaginary) display. The data generator output {a(n)} should consist of four points with values ±1 ± j. The effect
of channel distortion and additive noise may be viewed by displaying
the sequence {x(n)} at the input to the equalizer. The effectiveness of
the adaptive equalizer may be assessed by plotting its output {â(n)} after convergence of its coefficients. The short-time average squared error
ASE(n) may also be used to monitor the convergence characteristics of
the LMS algorithm. Note that a delay must be introduced into the output
of the data generator to compensate for the delays that the signal encounters due to the channel filter and the adaptive equalizer. For example, this
delay may be set to the largest integer closest to (N + K)/2. Finally, an
error counter may be used to count the number of symbol errors in the
received data sequence, and the ratio for the number of errors to the total
number of symbols (error rate) may be displayed. The error rate may be
varied by changing the level of the ISI and the level of the additive noise.
It is suggested that simulations be performed for the following three
channel conditions:
a. No ISI:
c(0) = 1, c(n) = 0, 1 ≤ n ≤ K − 1
b. Mild ISI: c(0) = 1, c(1) = 0.2, c(2) = −0.2, c(n) = 0, 3 ≤ n ≤ K − 1
c. Strong ISI: c(0) = 1, c(1) = 0.5, c(2) = 0.5, c(n) = 0, 3 ≤ n ≤ K − 1
The measured error rate may be plotted as a function of the signalto-noise ratio (SNR) at the input to the equalizer, where SNR is defined
as Ps /Pn , where Ps is the signal power, given as Ps = s2 , and Pn is the
noise power of the sequence at the output of the noise generator.
558
Chapter 11
APPLICATIONS IN ADAPTIVE FILTERING
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
CHAPTER
12
Applications in
Communications
Today MATLAB finds widespread use in the simulation of a variety of
communication systems. In this chapter we shall focus on several applications dealing with waveform representation and coding, especially speech
coding, and with digital communications. In particular, we shall describe
several methods for digitizing analog waveforms, with specific application
to speech coding and transmission. These methods are pulse-code modulation (PCM), differential PCM and adaptive differential PCM (ADPCM),
delta modulation (DM) and adaptive delta modulation (ADM), and linear predictive coding (LPC). A project is formulated involving each of
these waveform encoding methods for simulation using MATLAB.
The last three topics treated in this chapter deal with signal-detection
applications that are usually encountered in the implementation of a receiver in a digital communication system. For each of these topics we
describe a project that involves the implementations via simulation of the
detection scheme in MATLAB.
PULSE-CODE MODULATION
Pulse-code modulation is a method for quantizing an analog signal for
the purpose of transmitting or storing the signal in digital form. PCM is
widely used for speech transmission in telephone communications and for
telemetry systems that employ radio transmission. We shall concentrate
our attention on the application of PCM to speech signal processing.
559
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Speech signals transmitted over telephone channels are usually limited
in bandwidth to the frequency range below 4 kHz. Hence the Nyquist rate
for sampling such a signal is less than 8 kHz. In PCM the analog speech
signal is sampled at the nominal rate of 8 kHz (samples per second), and
each sample is quantized to one of 2b levels, and represented digitally by
a sequence of b bits. Thus the bit rate required to transmit the digitized
speech signal is 8000 b bits per second.
The quantization process may be modeled mathematically as
s̃(n) = s(n) + q(n)
(12.1)
where s̃(n) represents the quantized value of s(n), and q(n) represents the
quantization error, which we treat as an additive noise. Assuming that a
uniform quantizer is used and the number of levels is sufficiently large,
the quantization noise is well characterized statistically by the uniform
probability density function,
p(q) =
1
,
∆
−
∆
∆
≤q≤
2
2
(12.2)
where the step size of the quantizer is ∆ = 2−b . The mean square value
of the quantization error is
E(q 2 ) =
2−2b
∆2
=
12
12
(12.3)
Measured in decibels, the mean square value of the noise is
10 log
∆2
12
= 10 log
2−2b
12
= −6b − 10.8 dB
(12.4)
We observe that the quantization noise decreases by 6 dB/bit used
in the quantizer. High-quality speech requires a minimum of 12 bits per
sample and hence a bit rate of 96,000 bits per second (bps).
Speech signals have the characteristic that small signal amplitudes
occur more frequently than large signal amplitudes. However, a uniform
quantizer provides the same spacing between successive levels throughout the entire dynamic range of the signal. A better approach is to use
a nonuniform quantizer, which provides more closely spaced levels at the
low signal amplitudes and more widely spaced levels at the large signal
amplitudes. For a nonuniform quantizer with b bits, the resulting quantization error has a mean square value that is smaller than that given
by (12.4). A nonuniform quantizer characteristic is usually obtained by
passing the signal through a nonlinear device that compresses the signal
amplitude, followed by a uniform quantizer. For example, a logarithmic
compressor employed in U. S. and Canadian telecommunications systems,
560
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
called a µ-law compressor, has an input-output magnitude characteristic
of the form
ln (1 + µ|s|)
y=
sgn(s); |s| ≤ 1, |y| ≤ 1
(12.5)
ln(1 + µ)
where s is the normalized input, y is the normalized output, sgn (·) is the
sign function, and µ is a parameter that is selected to give the desired
compression characteristic.
In the encoding of speech waveforms the value of µ = 255 has been
adopted as a standard in the U. S. and Canada. This value results in about
a 24-dB reduction in the quantization noise power relative to uniform
quantization. Consequently, an 8-bit quantizer used in conjunction with
a µ = 255 logarithmic compressor produces the same quality speech as a
12-bit uniform quantizer with no compression. Thus the compressed PCM
speech signal has a bit rate of 64,000 bps.
The logarithmic compressor standard used in European telecommunication systems is called A-law and is defined as

1 + ln(A|s|)


sgn(s), A1 ≤ |s| ≤ 1

1 + ln A
(12.6)
y=


1
 A|s| sgn(s),
0 ≤ |s| ≤ A
1 + ln A
where A is chosen as 87.56. Although (12.5) and (12.6) are different
nonlinear functions, the two compression characteristics are very similar.
Figure 12.1 illustrates these two compression functions. Note their strong
similarity.
In the reconstruction of the signal from the quantized values, the
decoder employs an inverse logarithmic relation to expand the signal
FIGURE 12.1
Pulse-Code Modulation
Comparison of µ-law and A-law nonlinearities
561
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
amplitude. For example, in µ-law the inverse relation is given by
|s| =
(1 + µ)|y| − 1
;
µ
|y| ≤ 1, |s| ≤ 1
(12.7)
The combined compressor-expander pair is termed a compander.
PROJECT 12.1:
PCM
The purpose of this project is to gain an understanding of PCM compression (linear-to-logarithmic) and PCM expansion (logarithmic-to-linear).
Write the following three MATLAB functions for this project:
1. a µ-law compressor function to implement (12.5) that accepts a zeromean normalized (|s| ≤ 1) signal and produces a compressed zero-mean
signal with µ as a free parameter that can be specified,
2. a quantizer function that accepts a zero-mean input and produces an
integer output after b-bit quantization that can be specified, and
3. a µ-law expander to implement (12.7) that accepts an integer input
and produces a zero-mean output for a specified µ parameter.
For simulation purposes generate a large number of samples (10,000
or more) of the following sequences: (a) a sawtooth sequence, (b) an exponential pulse train sequence, (c) a sinusoidal sequence, and (d) a random
sequence with small variance. Care must be taken to generate nonperiodic
sequences by choosing their normalized frequencies as irrational numbers
(i.e., sample values should not repeat). For example, a sinusoidal sequence
can be generated using
s(n) = 0.5 sin(n/33),
0 ≤ n ≤ 10,000
From our discussions in Chapter 2 this sequence is nonperiodic, yet it has
a periodic envelope. Other sequences can also be generated in a similar
fashion. Process these signals through the above µ-law compressor, quantizer, and expander functions as shown in Figure 12.2, and compute the
FIGURE 12.2
562
PCM project
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
signal-to-quantization noise ratio (SQNR) in dB as
N
N
SQNR = 10 log10
n=1
n=1
s2 (n)
2
(s(n) − sq (n))
.
For different b-bit quantizers, systematically determine the value of µ
that maximizes the SQNR. Also plot the input and output waveforms
and comment on the results.
DIFFERENTIAL PCM (DPCM)
In PCM each sample of the waveform is encoded independently of all the
other samples. However, most signals, including speech, sampled at the
Nyquist rate or faster exhibit significant correlation between successive
samples. In other words, the average change in amplitude between successive samples is relatively small. Consequently, an encoding scheme that
exploits the redundancy in the samples will result in a lower bit rate for
the speech signal.
A relatively simple solution is to encode the differences between successive samples rather than the samples themselves. Since differences between samples are expected to be smaller than the actual sampled amplitudes, fewer bits are required to represent the differences. A refinement
of this general approach is to predict the current sample based on the
previous p samples. To be specific, let s(n) denote the current sample of
speech and let ŝ(n) denote the predicted value of s(n), defined as
p
a (i) s (n − i)
ŝ(n) =
(12.8)
i=1
Thus ŝ(n) is a weighted linear combination of the past p samples, and
the a (i) are the predictor (filter) coefficients. The a (i) are selected to
minimize some function of the error between s(n) and ŝ(n).
A mathematically and practically convenient error function is the sum
of squared errors. With this as the performance index for the predictor,
we select the a (i) to minimize
N
Ep =
s(n) −
e (n) =
n=1
n=1
a (i) s (n − i)
i=1
p
= rss (0) − 2
p
(12.9)
p
a (i) a (j) rss (i − j)
a (i) rss (i) +
i=1
Differential PCM (DPCM)
2
p
N
2
i=1 j=1
563
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
where rss (m) is the autocorrelation function of the sampled signal sequence s(n), defined as
N
rss (m) =
s (i) s (i + m)
(12.10)
i=1
Minimization of Ep with respect to the predictor coefficients {ai (n)} results in the set of linear equations, called the normal equations,
p
a (i) rss (i − j) = rss (j) ,
j = 1, 2, . . . , p
(12.11)
i=1
or in the matrix form,
Ra = r =⇒ a = R−1 r
(12.12)
where R is the autocorrelation matrix, a is the coefficient vector, and r
is the autocorrelation vector. Thus the values of the predictor coefficients
are established.
Having described the method for determining the predictor coefficients, let us now consider the block diagram of a practical DPCM system,
shown in Figure 12.3. In this configuration the predictor is implemented
with the feedback loop around the quantizer. The input to the predictor
is denoted as s̃(n), which represents the signal sample s(n) modified by
the quantization process, and the output of the predictor is
p
a (i) s̃ (n − i)
s̃ =
(12.13)
i=1
The difference
e(n) = s(n) − s̃(n)
(12.14)
is the input to the quantizer, and ẽ(n) denotes the output. Each value of
the quantized prediction error ẽ(n) is encoded into a sequence of binary
FIGURE 12.3
564
Block diagram of a DPCM transcoder: (a) Encoder, (b) Decoder
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
digits and transmitted over the channel to the receiver. The quantized
error ẽ(n) is also added to the predicted value s̃(n) to yield s̃(n).
At the receiver the same predictor that was used at the transmitting
end is synthesized, and its output s̃(n) is added to ẽ(n) to yield s̃(n). The
signal s̃(n) is the desired excitation for the predictor and also the desired
output sequence from which the reconstructed signal s̃ (t) is obtained by
filtering, as shown in Figure 12.3b.
The use of feedback around the quantizer, as described above, ensures
that the error in s̃(n) is simply the quantization error q(n) = ẽ(n) − e(n)
and that there is no accumulation of previous quantization errors in the
implementation of the decoder. That is,
q(n) = ẽ(n) − e(n) = ẽ(n) − s(n) + s̃(n) = s̃(n) − s(n)
(12.15)
Hence s̃(n) = s(n) + q(n). This means that the quantized sample s̃(n)
differs from the input s(n) by the quantization error q(n) independent of the predictor used. Therefore the quantization errors do not
accumulate.
In the DPCM system illustrated in Figure 12.3, the estimate or predicted value s̃(n) of the signal sample s(n) is obtained by taking a linear
combination of past values s̃ (n − k) , k = 1, 2, . . . , p, as indicated by
(12.13). An improvement in the quality of the estimate is obtained by
including linearly filtered past values of the quantized error. Specifically,
the estimate of s(n) may be expressed as
p
m
a (i) s̃ (n − i) +
s̃(n) =
i=1
b (i) ẽ (n − i)
(12.16)
i=1
where b (i) are the coefficients of the filter for the quantized error sequence
ẽ(n). The block diagram of the encoder at the transmitter and the decoder
at the receiver are shown in Figure 12.4. The two sets of coefficients
a (i) and b (i) are selected to minimize some function of the error e(n) =
s̃(n) − s(n), such as the sum of squared errors.
By using a logarithmic compressor and a 4-bit quantizer for the error
sequence e(n), DPCM results in high-quality speech at a rate of 32,000
bps, which is a factor of two lower than logarithmic PCM.
PROJECT 12.2:
DPCM
The objective of this project is to gain understanding of the DPCM encoding and decoding operations. For simulation purposes, generate correlated
random sequences using a pole-zero signal model of the form
s(n) = a (1) s (n − 1) + b0 x(n) + b1 x (n − 1)
(12.17)
where x(n) is a zero-mean unit variance Gaussian sequence. This can be
done using the filter function. The sequences developed in Project 12.1
Differential PCM (DPCM)
565
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 12.4
DPCM modified by the linearly filtered error sequence
can also be used for simulation. Develop the following three MATLAB
modules for this project:
1. a model predictor function to implement (12.12), given the input signal
s(n);
2. a DPCM encoder function to implement the block diagram of Figure 12.3a, which accepts a zero-mean input sequence and produces a
quantized b-bit integer error sequence, where b is a free parameter; and
3. a DPCM decoder function of Figure 12.3b, which reconstructs the signal from the quantized error sequence.
Experiment with several p-order prediction models for a given signal
and determine the optimum order. Compare this DPCM implementation
with the PCM system of Project 12.1 and comment on the results. Extend this implementation to include an mth-order moving average filter
as indicated in (12.16).
ADAPTIVE PCM AND DPCM (ADPCM)
In general, the power in a speech signal varies slowly with time. PCM
and DPCM encoders, however, are designed on the basis that the speech
signal power is constant, and hence the quantizer is fixed. The efficiency
566
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
and performance of these encoders can be improved by having them adapt
to the slowly time-variant power level of the speech signal.
In both PCM and DPCM the quantization error q(n) resulting from a
uniform quantizer operating on a slowly varying power level input signal
will have a time-variant variance (quantization noise power). One improvement that reduces the dynamic range of the quantization noise is
the use of an adaptive quantizer.
Adaptive quantizers can be classified as feedforward or feedback. A
feedforward adaptive quantizer adjusts its step size for each signal sample,
based on a measurement of the input speech signal variance (power). For
example, the estimated variance, based as a sliding window estimator, is
2
σ̂n+1
=
1
M
n+1
s2 (k)
(12.18)
k=n+1−M
Then the step size for the quantizer is
∆ (n + 1) = ∆(n)σ̂n+1
(12.19)
In this case it is necessary to transmit ∆ (n + 1) to the decoder in order
for it to reconstruct the signal.
A feedback adaptive quantizer employs the output of the quantizer
in the adjustment of the step size. In particular, we may set the step size
as
∆ (n + 1) = α(n)∆(n)
(12.20)
where the scale factor α(n) depends on the previous quantizer output.
For example, if the previous quantizer output is small, we may select
α(n) < 1 in order to provide for finer quantization. On the other hand,
if the quantizer output is large, then the step size should be increased
to reduce the possibility of signal clipping. Such an algorithm has been
successfully used in the encoding of speech signals. Figure 12.5 illustrates
such a (3-bit) quantizer in which the step size is adjusted recursively
according to the relation
∆ (n + 1) = ∆(n) · M (n)
where M (n) is a multiplication factor whose value depends on the quantizer level for the sample s(n), and ∆(n) is the step size of the quantizer for
processing s(n). Values of the multiplication factors optimized for speech
encoding have been given by [14]. These values are displayed in Table 12.1
for 2-, 3-, and 4-bit quantization for PCM and DPCM.
In DPCM the predictor can also be made adaptive. Thus in ADPCM
the coefficients of the predictor are changed periodically to reflect the
changing signal statistics of the speech. The linear equations given by
(12.11) still apply, but the short-term autocorrelation function of s(n),
rss (m) changes with time.
Adaptive PCM and DPCM (ADPCM)
567
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Example of a quantizer with an adaptive step size ([10])
FIGURE 12.5
ADPCM
STANDARD
Figure 12.6 illustrates, in block diagram form, a 32, 000 bps ADPCM
encoder and decoder that has been adopted as an international (CCITT)
standard for speech transmission over telephone channels. The ADPCM
encoder is designed to accept 8-bit PCM compressed signal samples at
64,000 bps, and by means of adaptive prediction and adaptive 4-bit
quantization to reduce the bit rate over the channel to 32,000 bps. The
ADPCM decoder accepts the 32,000 bps data stream and reconstructs
the signal in the form of an 8-bit compressed PCM at 64,000 bps. Thus we
have a configuration shown in Figure 12.7, where the ADPCM encoder/
decoder is embedded into a PCM system. Although the ADPCM encoder/
decoder could be used directly on the speech signal, the interface to the
TABLE 12.1
Multiplication factors for adaptive step size adjustment ([9])
2
M (1)
M (2)
M (3)
M (4)
M (5)
M (6)
M (7)
M (8)
568
0.60
2.20
PCM
3
0.85
1.00
1.00
1.50
4
2
0.80
0.80
0.80
0.80
0.80
0.80
0.80
0.80
0.80
1.60
Chapter 12
DPCM
3
0.90
0.90
1.25
1.70
4
0.90
0.90
0.90
0.90
1.20
1.60
2.00
2.40
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 12.6
ADPCM block diagram
PCM system is necessary in practice in order to maintain compatibility
with existing PCM systems that are widely used in the telephone network.
The ADPCM encoder accepts the 8-bit PCM compressed signal and
expands it to a 14-bit-per-sample linear representation for processing. The
predicted value is subtracted from this 14-bit linear value to produce a
difference signal sample that is fed to the quantizer. Adaptive quantization is performed on the difference signal to produce a 4-bit output for
transmission over the channel.
Both the encoder and decoder update their internal variables, based
only on the ADPCM values that are generated. Consequently, an ADPCM
decoder including an inverse adaptive quantizer is embedded in the
FIGURE 12.7
Adaptive PCM and DPCM (ADPCM)
ADPCM interface to PCM system
569
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
encoder so that all internal variables are updated, based on the same
data. This ensures that the encoder and decoder operate in synchronism
without the need to transmit any information on the values of internal
variables.
The adaptive predictor computes a weighted average of the last six
dequantized difference values and the last two predicted values. Hence
this predictor is basically a two-pole (p = 2) and six-zero (m = 6) filter
governed by the difference equation given by (12.16). The filter coefficients
are updated adaptively for every new input sample.
At the receiving decoder and at the decoder that is embedded in
the encoder, the 4-bit transmitted ADPCM value is used to update the
inverse adaptive quantizer, whose output is a dequantized version of the
difference signal. This dequantized value is added to the value generated
by the adaptive predictor to produce the reconstructed speech sample.
This signal is the output of the decoder, which is converted to compressed
PCM format at the receiver.
PROJECT 12.3:
ADPCM
The objective of this project is to gain familiarity with, and understanding
of, ADPCM and its interface with a PCM encoder/decoder (transcoder).
As described above, the ADPCM transcoder is inserted between the PCM
compressor and the PCM expander as shown in Figure 12.7. Use the
already developed MATLAB PCM and DPCM modules for this project.
The input to the PCM-ADPCM transcoder system can be supplied
from internally generated waveform data files, just as in the case of the
PCM project. The output of the transcoder can be plotted. Comparisons should be made between the output signal from the PCM-ADPCM
transcoder with the signal from the PCM transcoder (PCM project 12.1),
and with the original input signal.
DELTA MODULATION (DM)
Delta modulation may be viewed as a simplified form of DPCM in which
a two-level (1-bit) quantizer is used in conjunction with a fixed firstorder predictor. The block diagram of a DM encoder-decoder is shown in
Figure 12.8. We note that
s̃(n) = s̃ (n − 1) = s̃ (n − 1) + ẽ (n − 1)
Since
(12.21)
q(n) = ẽ(n) − e(n) = ẽ(n) − s(n) − s̃(n)
it follows that
s̃(n) = s (n − 1) + q (n − 1)
570
Chapter 12
(12.22)
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 12.8
Block diagram of a delta modulation system
Thus the estimated (predicted) value of s(n) is really the previous sample s (n − 1) modified by the quantization noise q (n − 1). We also note
that the difference equation in (12.21) represents an integrator with an
input ẽ(n). Hence an equivalent realization of the one-step predictor is
an accumulator with an input equal to the quantized error signal ẽ(n). In
general, the quantized error signal is scaled by some value, say ∆1 , which is
called the step size. This equivalent realization is illustrated in Figure 12.9.
In effect, the encoder shown in Figure 12.9 approximates a waveform s (t)
by a linear staircase function. In order for the approximation to be relatively good, the waveform s (t) must change slowly relative to the sampling
rate. This requirement implies that the sampling rate must be several (a
factor of at least 5) times the Nyquist rate. A lowpass filter is usually
FIGURE 12.9
Delta Modulation (DM)
An equivalent realization of a delta modulation system
571
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 12.10
Two types of distortion in the DM encoder
incorporated into the decoder to smooth out discontinuities in the reconstructed signal.
ADAPTIVE
DELTA
MODULATION
(ADM)
At any given sampling rate, the performance of the DM encoder is limited
by two types of distortion as shown in Figure 12.10. One is called slopeoverload distortion. It is due to the use of a step size ∆1 that is too small to
follow portions of the waveform that have a steep slope. The second type
of distortion, called granular noise, results from using a step size that is too
large in parts of the waveform having a small slope. The need to minimize
both of these two types of distortion results in conflicting requirements in
the selection of the step size ∆1 .
An alternative solution is to employ a variable size that adapts itself
to the short-term characteristics of the source signal. That is, the step size
is increased when the waveform has a steep slope and decreased when the
waveform has a relatively small slope.
A variety of methods can be used to set adaptively the step size in
every iteration. The quantized error sequence ẽ(n) provides a good indication of the slope characteristics of the waveform being encoded. When the
quantized error ẽ(n) is changing signs between successive iterations, this
is an indication that the slope of the waveform in the locality is relatively
small. On the other hand, when the waveform has a steep slope, successive
values of the error ẽ(n) are expected to have identical signs. From these observations it is possible to devise algorithms that decrease or increase the
step size, depending on successive values of ẽ(n). A relatively simple rule
devised by [13] is to vary adaptively the step size according to the relation
∆(n) = ∆ (n − 1) K ẽ(n)ẽ(n−1) ,
n = 1, 2, . . .
(12.23)
where K ≥ 1 is a constant that is selected to minimize the total distortion.
A block diagram of a DM encoder-decoder that incorporates this adaptive
algorithm is illustrated in Figure 12.11.
Several other variations of adaptive DM encoding have been investigated and described in the technical literature. A particularly effective
and popular technique first proposed by [6] is called continuously variable
572
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
FIGURE 12.11
An example of a delta modulation system with adaptive step size
slope delta modulation (CVSD). In CVSD the adaptive step size parameter may be expressed as
∆(n) = α∆ (n − 1) + k1
(12.24)
if ẽ(n), ẽ (n − 1), and ẽ(n − 2) have the same sign; otherwise
∆(n) = α∆ (n − 1) + k2
(12.25)
The parameters α, k1 , and k2 are selected such that 0 < α < 1 and
k1 > k2 > 0. For more discussion on this and other variations of adaptive
DM, the interested reader is referred to the papers by [14] and [4] and to
the extensive references contained in these papers.
PROJECT 12.4:
DM AND ADM
Delta Modulation (DM)
The purpose of this project is to gain an understanding of delta modulation and adaptive delta modulation for coding of waveforms. This project
involves writing MATLAB functions for the DM encoder and decoder as
573
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
shown in Figure 12.9, and for the ADM encoder and decoder shown in
Figure 12.11. The lowpass filter at the decoder can be implemented as a
linear-phase FIR filter. For example, a Hanning filter that has the impulse
response
2πn
1
1 − cos
, 0≤n≤N −1
(12.26)
h(n) =
2
N −1
may be used, where the length N may be selected in the range 5 ≤ N ≤ 15.
The input to the DM and ADM systems can be supplied from the
waveforms generated in Project 12.1 except that the sampling rate should
be higher by a factor of 5 to 10. The output of the decoder can be plotted.
Comparisons should be made between the output signal from the DM and
ADM decoders and the original input signal.
LINEAR PREDICTIVE CODING (LPC) OF SPEECH
The linear predictive coding (LPC) method for speech analysis and synthesis is based on modeling the vocal tract as a linear all-pole (IIR) filter
having the system function
G
H (z) =
(12.27)
p
1+
ap (k) z
−k
k=1
where p is the number of poles, G is the filter gain, and {ap (k)} are the
parameters that determine the poles. There are two mutually exclusive
excitation functions to model voiced and unvoiced speech sounds. On a
short-time basis, voiced speech is periodic with a fundamental frequency
F0 , or a pitch period 1/F0 , which depends on the speaker. Thus voiced
speech is generated by exciting the all-pole filter model by a periodic
impulse train with a period equal to the desired pitch period. Unvoiced
speech sounds are generated by exciting the all-pole filter model by the
output of a random-noise generator. This model is shown in Figure 12.12.
Given a short-time segment of a speech signal, usually about 20 ms
or 160 samples at an 8 kHz sampling rate, the speech encoder at the
transmitter must determine the proper excitation function, the pitch period for voiced speech, the gain parameter G, and the coefficients ap (k).
A block diagram that illustrates the speech encoding system is given in
Figure 12.13. The parameters of the model are determined adaptively
from the data and encoded into a binary sequence and transmitted to the
receiver. At the receiver the speech signal is synthesized from the model
and the excitation signal.
574
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Block diagram model for the generation of a speech signal
FIGURE 12.12
The parameters of the all-pole filter model are easily determined from
the speech samples by means of linear prediction. To be specific, the
output of the FIR linear prediction filter is
p
ap (k) s (n − k)
ŝ(n) = −
(12.28)
k=1
and the corresponding error between the observed sample s(n) and the
predicted value ŝ(n) is
p
ap (k) s (n − k)
e(n) = s(n) +
(12.29)
k=1
By minimizing the sum of squared errors, that is,
N
E=
FIGURE 12.13
Linear Predictive Coding (LPC) of Speech
ap (k) s (n − k)
s(n) +
e (n) =
n=0
n=0
2
p
N
2
(12.30)
k=1
Encoder and decoder for LPC
575
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
we can determine the pole parameters {ap (k)} of the model. The result
of differentiating E with respect to each of the parameters and equating
the result to zero, is a set of p linear equations
p
ap (k) rss (m − k) = −rss (m) ,
m = 1, 2, . . . , p
(12.31)
k=1
where rss (m) is the autocorrelation of the sequence s(n) defined as
N
rss (m) =
s(n)s (n + m)
(12.32)
n=0
The linear equations (12.31) can be expressed in matrix form as
Rss a = −rss
(12.33)
where Rss is a p × p autocorrelation matrix, rss is a p × 1 autocorrelation
vector, and a is a p × 1 vector of model parameters. Hence
a = −R−1
ss rss
(12.34)
These equations can also be solved recursively and most efficiently, without resorting to matrix inversion, by using the Levinson-Durbin algorithm
[19]. However, in MATLAB it is convenient to use the matrix inversion.
The all-pole filter parameters {ap (k)} can be converted to the all-pole
lattice parameters {Ki } (called the reflection coefficients) using the
MATLAB function dir2latc developed in Chapter 6.
The gain parameter of the filter can be obtained by noting that its
input-output equation is
p
s(n) = −
ap (k) s (n − k) + Gx(n)
(12.35)
k=1
where x(n) is the input sequence. Clearly,
p
ap (k) s (n − k) = e(n)
Gx(n) = s(n) +
k=1
Then
N −1
G2
N −1
x2 (n) =
n=0
e2 (n)
(12.36)
n=0
If the input excitation is normalized to unit energy by design, then
N −1
G2 =
p
e2 (n) = rss (0) +
n=0
576
ap (k) rss (k)
(12.37)
k=1
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Thus G2 is set equal to the residual energy resulting from the least-squares
optimization.
Once the LPC coefficients are computed, we can determine whether
the input speech frame is voiced, and if so, what the pitch is. This is
accomplished by computing the sequence
p
re (n) =
ra (k) rss (n − k)
(12.38)
ap (i) ap (i + k)
(12.39)
k=1
where ra (k) is defined as
p
ra (k) =
i=1
which is the autocorrelation sequence of the prediction coefficients.
The pitch is detected by finding the peak of the normalized sequence
re (n)/re (0) in the time interval that corresponds to 3 to 15 ms in the
20-ms sampling frame. If the value of this peak is at least 0.25, the frame
of speech is considered voiced with a pitch period equal to the value of
n = Np , where re (Np ) /re (0) is a maximum. If the peak value is less than
0.25, the frame of speech is considered unvoiced and the pitch is zero.
The values of the LPC coefficients, the pitch period, and the type of
excitation are transmitted to the receiver, where the decoder synthesizes
the speech signal by passing the proper excitation through the all-pole
filter model of the vocal tract. Typically, the pitch period requires 6 bits,
and the gain parameter may be represented by 5 bits after its dynamic
range is compressed logarithmically. If the prediction coefficients were to
be coded, they would require between 8 to 10 bits per coefficient for accurate representation. The reason for such high accuracy is that relatively
small changes in the prediction coefficients result in a large change in
the pole positions of the filter model. The accuracy requirements are lessened by transmitting the reflection coefficients {Ki }, which have a smaller
dynamic range—that is, |Ki | < 1. These are adequately represented by
6 bits per coefficient. Thus for a 10th-order predictor the total number
of bits assigned to the model parameters per frame is 72. If the model
parameters are changed every 20 milliseconds, the resulting bit rate is
3, 600 bps. Since the reflection coefficients are usually transmitted to the
receiver, the synthesis filter at the receiver is implemented as an all-pole
lattice filter, described in Chapter 6.
PROJECT 12.5:
LPC
The objective of this project is to analyze a speech signal through an
LPC coder and then to synthesize it through the corresponding PLC
decoder. Use several .wav sound files (sampled at 8000 sam/sec rate),
which are available in MATLAB for this purpose. Divide speech signals
Linear Predictive Coding (LPC) of Speech
577
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
into short-time segments (with lengths between 120 and 150 samples) and
process each segment to determine the proper excitation function (voiced
or unvoiced), the pitch period for voiced speech, the coefficients {ap (k)}
(p ≤ 10), and the gain G. The decoder that performs the synthesis is an
all-pole lattice filter whose parameters are the reflection coefficients that
can be determined from {ap (k)}. The output of this project is a synthetic speech signal that can be compared with the original speech signal.
The distortion effects due to LPC analysis/synthesis may be assessed
qualitatively.
DUAL-TONE MULTIFREQUENCY (DTMF) SIGNALS
DTMF is the generic name for push-button telephone signaling that is
equivalent to the Touch Tone system in use within the Bell System. DTMF
also finds widespread use in electronic mail systems and telephone banking
systems in which the user can select options from a menu by sending
DTMF signals from a telephone.
In a DTMF signaling system a combination of a high-frequency tone
and a low-frequency tone represent a specific digit or the characters *
and #. The eight frequencies are arranged as shown in Figure 12.14, to
accommodate a total of 16 characters, 12 of which are assigned as shown,
while the other four are reserved for future use.
FIGURE 12.14
578
DTMF digits
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
DTMF signals are easily generated in software and detected by means
of digital filters, also implemented in software, that are tuned to the eight
frequency tones. Usually, DTMF signals are interfaced to the analog world
via a codec (coder/decoder) chip or by linear A/D and D/A converters.
Codec chips contain all the necessary A/D and D/A, sampling, and filtering circuitry for a bi-directional analog/digital interface.
The DTMF tones may be generated either mathematically or from a
look-up table. In a hardware implementation (e.g., in a digital signal processor), digital samples of two sine waves are generated mathematically,
scaled, and added together. The sum is logarithmically compressed and
sent to the codec for conversion to an analog signal. At an 8 kHz sampling rate the hardware must output a sample every 125 ms. In this case
a sine look-up table is not used because the values of the sine wave can be
computed quickly without using the large amount of data memory that
a table look-up would require. For simulation and investigation purposes
the look-up table might be a good approach in MATLAB.
At the receiving end the logarithmically compressed, 8-bit digital data
words from the codec are received, logarithmically expanded to their 16bit linear format, and then the tones are detected to decide on the transmitted digit. The detection algorithm can be a DFT implementation using the FFT algorithm or a filter bank implementation. For the relatively
small number of tones to be detected, the filter bank implementation is
more efficient. Below, we describe the use of the Goertzel algorithm to
implement the eight tuned filters.
Recall from the discussion in Chapter 5 that the DFT of an N -point
data sequence {x(n)} is
N −1
x(n)WNnk ,
X (k) =
k = 0, 1, . . . , N − 1
(12.40)
n=0
If the FFT algorithm is used to perform the computation of the DFT,
the number of computations (complex multiplications and additions) is
N log2 N . In this case we obtain all N values of the DFT at once. However,
if we desire to compute only M points of the DFT, where M < log2 N ,
then a direct computation of the DFT is more efficient. The Goertzel
algorithm, which is described below, is basically a linear filtering approach
to the computation of the DFT, and provides an alternative to direct
computation.
THE
GOERTZEL
ALGORITHM
The Goertzel algorithm exploits the periodicity of the phase factors {WNk }
and allows us to express the computation of the DFT as a linear filtering
operation. Since WN−kN = 1, we can multiply the DFT by this factor.
Dual-tone Multifrequency (DTMF) Signals
579
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Thus
X (k) = WN−kN X (k) =
N −1
−k(N −m)
x (m) WN
(12.41)
m=0
We note that (12.41) is in the form of a convolution. Indeed, if we define
the sequence yk (n) as
N −1
yk (n) =
−k(n−m)
x (m) WN
(12.42)
m=0
then it is clear that yk (n) is the convolution of the finite-duration input
sequence x(n) of length N with a filter that has an impulse response
hk (n) = WN−kn u(n)
(12.43)
The output of this filter at n = N yields the value of the DFT at the
frequency ωk = 2πk/N . That is,
(12.44)
X (k) = yk (n)|n=N
as can be verified by comparing (12.41) with (12.42).
The filter with impulse response hk (n) has the system function
Hk (z) =
1
1 − WN−k z −1
(12.45)
This filter has a pole on the unit circle at the frequency ωk = 2πk/N .
Thus the entire DFT can be computed by passing the block of input data
into a parallel bank of N single-pole filters (resonators), where each filter
has a pole at the corresponding frequency of the DFT.
Instead of performing the computation of the DFT as in (12.42), via
convolution, we can use the difference equation corresponding to the filter
given by (12.45) to compute yk (n) recursively. Thus we have
yk (n) = WN−k yk (n − 1) + x(n),
yk (−1) = 0
(12.46)
The desired output is X (k) = yk (N ). To perform this computation, we
can compute once and store the phase factor WN−k .
The complex multiplications and additions inherent in (12.46) can
be avoided by combining the pairs of resonators possessing complex conjugate poles. This leads to two-pole filters with system functions of the
form
1 − WNk z −1
(12.47)
Hk (z) =
1 − 2 cos (2πk/N ) z −1 + z −2
580
Chapter 12
APPLICATIONS IN COMMUNICATIONS
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Realization of two-pole resonator for computing the DFT
FIGURE 12.15
The realization of the system illustrated in Figure 12.15 is described by
the difference equations
vk (n) = 2 cos
2πk
vk (n − 1) − vk (n − 2) + x(n)
N
yk (n) = vk (n) − WNk vk (n − 1)
(12.48)
(12.49)
with initial conditions vk (−1) = vk (−2) = 0. This is the Goertzel algorithm.
The recursive relation in (12.48) is iterated for n = 0, 1, . . . , N , but the
equation in (12.49) is computed only once, at time n = N . Each iteration
requires one real multiplication and two additions. Consequently, for a real
input sequence x(n), this algorithm requires N + 1 real multiplications to
yield not only X (k) but also, due to symmetry, the value of X (N − k).
We can now implement the DTMF decoder by use of the Goertzel
algorithm. Since there are eight possible tones to be detected, we require
eight filters of the type given by (12.47), with each filter tuned to one of the
eight frequencies. In the DTMF detector, there is no need to compute the
complex value X (k); only the magnitude |X(k)| or the magnitude-squared
2
value |X(k)| will suffice. Consequently, the final step in the computation
of the DFT value involving the numerator term (feedforward part of the
filter computation) can be simplified. In particular, we have
2
|X(k)|2 = |yk (N )|2 = vk (N ) − WNk vk (N − 1)
=
vk2 (N )
+
vk2
2πk
(N − 1) − 2 cos
N
(12.50)
vk (N )vk (N − 1)
Thus complex-valued arithmetic operations are completely eliminated in
the DTMF detector.
Dual-tone Multifrequency (DTMF) Signals
581
Copyright 2010 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
PROJECT 12.6:
DTMF
SIGNALING
The objective of this project is to gain an understanding of the DTMF
tone generation software and the DTMF decoding algorithm (the Goertzel
algorithm). Design the following MATLAB modules:
1. a tone generation function that accepts an array containing dialing
digits and produces a signal containing appropriate tones (from Figure
12.14) of one-half-second duration for each digit at 8 kHz sampling
frequency,
2. a dial-tone generator generating samples of (350 + 440) Hz frequency
at 8 kHz sampling interval for a specified amount of duration, and
3. a decoding function to implement (12.50) that accepts a DTMF signal
and produces an array containing dialing digits.
Generate several dialing list arrays containing a mix of digits and
dial tones. Experiment with the tone generation and detection modules
and comment on your observations. Use MATLAB’s sound generation
capabilities to listen to the tones and to observe the frequency components
of the generated tones.
BINARY DIGITAL COMMUNICATIONS
Digitized speech signals that have been encoded via PCM, ADPCM, DM,
and LPC are usually transmitted to the decoder by means of digital modulation. A binary digital communications system employs two signal waveforms, say s1 (t) = s(t) and s2 (t) = −s(t), to transmit the binary sequence
representing the speech signal. The signal waveform s(t), which is nonzero
over the interval 0 ≤ t ≤ T , is transmitted to the receiver if the data bit is
a 1, and the signal waveform −s(t), 0 ≤ t ≤ T is transmitted if the data b
Download