James H. MCCLELLAN ¢ C. SIDNEY BURRUS
ALAN V. OPPENHEIM ® THOMAS W, PARKS
RONALD W. SCHAFER ® HANS W. SCHUESSLER
MATLAB®
CURRICULUM,
‘SERIESComputer-Based Exercises
for Signal Processing
Using MATLAB® 5
James H. McClellan
C. Sidney Burrus
Alan V. Oppenheim
Thomas W. Parks
Ronald W. Schafer
Hans W. Schuessler
M Mariap® Curriculum Series
PRENTICE HALL, Upper Saddle River, New Jersey 07458Library of Congress Cataloging-in-Publication Data
‘Computer-based exercises fo signal processing using MATLAB® 5 / James
HL MeCiellan etal
pom
Includes index
SBN 0-13-789009-5
1. Signal processing—Digitltechniques—Mathematies. 2, MATLAB,
|. MeCletlan, James H.,
‘TKSIO29.C367_ 1998
621.382 2078553042 —de2t 9741499
cr
Publisher: Tom Robbins
Editor-in-Chief: Marcia Horton
Production Coordinator: Wanda EspaiaWEE DESIGN GROUP,
Vice President Director of Production and Manufacturing: David W. Riccardi
‘Managing Edivor: Bayani Mendoza de Leon
Cover Designer: Design Source
‘Manufacturing Buyer: Donna Sullivan
Editorial Assistant: Nancy Garcia
Compositor: Techsetters, Inc.
(©1998 by Prentice-Hall, Ine.
Upper Saddle River, New Jersey 07458,
‘The author and publisher of this book have used their best efforts in preparing this
book. These efforts include the development, research, and testing of the theories,
‘and programs to determine their effectiveness. The author and publisher shall not
be liable in any event for incidental or consequential damages in connection with,
‘or arising out of, the furnishing, performance, or use of these programs.
Al rights reserved, No part of this book may be reproduced, in any form or by any
‘means, without permission in writing from the publisher.
Maran is a registered trademark of the MathWorks, Ine.
Printed in the United States of America
9876543
ISBN 0-13-789009-5
Prentice-Hall International (UK) Limited, London ‘The MathWorks, Inc.
Prentice-Hall of Australia Pty. Limited, Sydney 24 Prime Park Way
Prentice-Hall Canada Ine., Toronto, Natick, Massachusetts 01760-1500
Prentice-Hall Hispanoamericana, S.A., México Phone: (508) 647-7000
Prentice-Hall of India Private Limited, New Dethi Fax: (508) 647-7001
Prentice-Hall of Japan, Inc., Tokyo E-mail:
[email protected]
Pearson Education Asia Pte, Ltd, Asia ‘hup://www.mathworks.com
Editora Prentice-Hall do Brazil, Ltda., Rio de JaneiroOUTLINE
10
u
Presace
BASIC SIGNALS AND SYSTEMS
DiscRETE FOURIER TRANSFORM,
‘SPECTRUM ANALYSIS
(MuLTTRATE PROCESSING
SYSTEMS AND STRUCTURES.
STOCHASTIC SIGNALS
‘Woroiencrh Errects
DiscRETE-Time FieR DESIGN
DFT ANo FFT AicormTams
‘APPUCATIONS.
SIGNAL MODELING
‘Appenoix A
‘SOFTWARE AND PROGRAMMING NOTES
Inpex
xi
83
113
129
159
205
287
289
317
351
385
399beige Sei
CONTENTS
PREFACE xi
1 BASIC SIGNALS AND SysTEMs 1
Signals 2
Project 1 Basi Signals, 2
Project 2: Comples-Valaed Signals, 6
Difference Equations 8
Projet 1: Time-Domain Response of Difference Equations, 9
Projet 2: Steady-State Response. 10
Prnjct 3: Frequency Response for Diference Equations, 12
Fourier Transform: DTFT 13
Project 1: Computing the DTFT: Finite-Length Signals, 14
Project 2: DTFT Symmetries, 17
Project 3: DTET of lnfinite-Length Signals, 19
Project 4: Windowing forthe DTT, 21
Project S: Frequency Response ofa Notch Filter 23
Group Delay 24
Project I: Algorithm for Computing the Group Delay. 25
Project 2: Effect of Group Delay on Signals, 27
Project 3: Negative Group Delay, 28
Basic Sampling Theory 29
Project I: Aliasing Caused by Sampling, 29
Project 2: Frequency-Domain View of Sampling, 31
Project 3: Reconstruction of Signals From Samples, 33
Zero-Phase UR Filtering 35
Project 1: Amticausal Filtering, 36
Project 2: Forwant-Backward Filter2 Discrere Fourier TRANSFORM 43
DFT Properties 44
Project 1: Examples of the DFT of Common Signals, 45
Projet 2: Difficult DFTs, 47
Project 3: Symmetries in the DFT. 49.
Pmmject 4: Tricks for the lmerse DFT, 52
Projet S: Zero Padding and Decimation Properties, $4
Project 6: Real Data FFT, 55
Prnjet 7: Discrete Fourier Series, 8
DFT asa Matrix 59
Project 1: DFT as an Orthogonal Matrix, 60
Project 2: Eigenvalues ofthe DFT Marri, 61
Project 3: DFT Diagonalizes Civculant Matrices, 64
Project 4: FFT Algorithm as a Matrix Factorization, 64
Convolution: Circular and Block 66
Project I: Circular Indexing, 67
Project 2: Circular Convolution, 68
Projet 3: Relation 10 Linear Convolution, 70
Praject 4: Black Processing, 73
Projet 5: High-Speed Convolution, 75
Related Transforms 77
Projet I: Diserete Cosine Transform, 77,
Project 2: Diseree Hartley Transform, 8)
3 SPECTRUM ANALYSIS 83
Spectral Windows 84
Project 1: Window Types, 85
Project 2: Window Performance, 88
Project 3: Resolution, 91
Sliding Window DFT 92
Projet I: Spectrogram, 93
Project 2: Tone Generator, 97
Narrowband Signals 100
Projet I: Synthesis of a Bandpass Pulse, 1OF
Projet 2: Ftering the Bandpass Pulse, 105
Project 3: Resonant Peaks, 108
Project 4: Line Spectra, 109
Project 5: Frequency Sampling in the DTPT, 11
4 Mummpare Processine 3
Bandlimited Interpolation 114
Project 1: Inerpolation Fler Performance, 115
Project 2: Optimum Min-Mas Interpolation, 117Contents __vii
Zoom Transform 121
Prnjct 1: Zoom Transform, 121
Rate Changing 123,
Project 1: Rate Reduction: Decimation, 124
Project 2: Rate Changing, 127
5 SYSTEMS AND STRUCTURES 129
Systems and Structures 130
Project I: Description of Systems, 131
Project 2: Measuring the Frequency Response for @ = 0, 137
Project 3: Types of Systems, 139
Project 4: Structures, 148
6 STocHasmic SiGNALS 159
Stochastic Signals 161
Projet 1: Random Variables, 162
Projet 2: Nonstationary, Stationary, and Ergodie Random
Processes, 165
Project 3: Influence ofa Linear System on a Stochastic
Process, 168
Project 4: Infuence of a Nonlinear Mapping on a Random
Process, I73
Project 5: Combining Two Random Processes, 176
FET Spectrum Estimation 178
Project 12 Periodogram, 178
Project 2: Periodogram Averaging, 182
Project 3: Narrowband Signals, 185
Projet 4: Crmss Spectrum, 187
‘Modem Spectrum Estimation 188
Pret I: Maxinum Entropy Method, 189
Projet 2: Spectrum Estimates Based on Linear Prediction, 192
Pinject 3: Narrowband Signals, 195
Pinject 4: Eigenvector-Based Methods, 197
Project S: Testing with Symhetic Signals, 201
7 WorDuNGTH EFFEcts 205
Wordlength Effects 206
Projet 1: Quantzed Signals, 207
Projet 2: Modeling a Multiplier 213
Project 3: Sensitivity of Filter Structures, 216
Project 4: Limit Cyeles, 225,
Project 8: Quantization Noise in Digital Filters, 231Disceeve-Time FitreR DESIGN 207
Discrete Design of FIR Filters 249
Project I: FIR Filter Design by Frequency Sampling, 249
Project 2: Use ofa Transition Band in the Filter Specifications, 256
Project 3: FIR Filter Design by Discrete Least Squared -Error
Approximation, 258
Least-Squares Design of FIR Filters 261
Projet I: FIR Filter Design by Least Integral Squared Error
Approximation, 261
Project 2: Design of High-Puss, Bandpass, and Band-Reject
Least-Squared-Evror FIR Filters, 265,
Project 3: FIR Flier Design Using Window Functions, 267
Chebyshev Design of FIR Filters 270
Projet I: FIR Filter Design by the Parks-McClellan Method, 270,
Projet 2: Alteration Theorem and Reme: Exchange Algorithm, 272
Project 3: FIR Filter Design Using Linear Programming, 277,
Design of TR Filters 279)
Project 1: Characteristics of HR Filters, 280
Project 2: Using the Bilinear Transformation, 282
Project 3: Design of High-Pass, Bandpass, and Band-Reject
UR Filters, 284
Project 4: UR Filter Design inthe Tine Domain
by Prony's Method, 285
Project 5: Special Topics, 287
DFT AND FFT ALGORITHMS 289
Direct Calculation of the DFT 291
Projet 1: Calculation ofthe DFT from the Definition, 291
Project 2> Goertzel's Algorithm, 293
‘The CooleyTukey FFT 295
Pmmjet I: Recursive Derivation ofthe FFT, 295,
Projet 2: Two-Factor FFT with Twiddle Factors, 298
Projet 3: Split Radic FFT, 300
Prime Factor FFTs 302
Project 1: Two Factor Prime Factor Algovthon PFT, 302
Project 2: The General Linear Index Map, 304
Projet 3: Prime-Length DET Method and Some Base Ideas
from Number Theory, 308
General Length of FFTs 312
Project 1: Evaluation of the Marian FET, 312
Project 2: The Chirp =Transform, 313Contents ix
10 Appucanions 317
Radar Simulation 318
Project I: Properties of the LEM Chirp Signal, 319
Projet 2: Range Processing, 321
Projet 3: Velocity Processing, 323
Projet 4: Radar System Simulation, 325
Introduction to Speech Processing 329
Project I: Speech Segmentation, 329
Project 2: Preemphasis of Speech, 332
Project 3: Shori-Tine Fourier Analysis, 333
Project I: Glotal Pulse Models, 336
Pmject 2: Lossless Tube Vocal Tract Models, 38
Prnject 3: Vowel Synthesis, 324
Speech Quantization 343
Project 1: Speech Properties, 44
Projet 2: Uniform Quantization, 344
Project 3: jt-Law Companding, 357
Project 4: Signal-o-Noise-Ratios, 348
Project 5: Listening 10 Quantced Speech, 350
SIGNAL MODELING 351
Linear Prediction 352
Project I: Linear Prediction of Data, 354
Projet 2: Decorrelation by Linear Prediction, 357,
Linear Prediction of Speech 359
Project 1: Basic Linear Prediction, 360
Project 2: Line Spectrum Pair Representations, 361
Project 3: Quantization of Parameters, 362
Projet 4: Formant Tracking, 363
Exponential Modeling 365
Project I: Prony's Method, 366
Project 2: Pole-Zero Modeling, 368
Signal Estimation 371
Project I: Finding the Optimal Estimate ina Filter Class, 372
Project 2: Error Bounds: How Good isthe Esimate?, 374
Least-Squares Inversion 375
Projet I: Least Squares Inversion, 375.
Project 2: Testing with Noise-Free Signals, 377
Project 3: Inversion of Noisy Signals, 378
Project 4: Evaluation of Least-Squares Inversion, 379Contents
12 Appenoix A
‘SOFTWARE AND PROGRAMMING NOTES 385
Inoex 399ee
PREFACE
The area of digital signal processing has consistently derived its vitality from the interplay
between theory and applications. Correspondingly, university courses in digital signal
processing have been inereasingly incorporating computer exercises and laboratories to help
students better understand the principles of signal processing and experience the excitement
of applying abstract mathematical concepts to the processing of real signals,
This book is a collection of computer exercises about digital signal processing, Tt
is an outgrowth of our collective experience in incorporating computer-based projects into
‘our signal processing courses. Each of us has been involved in teaching signal processing
a our respective institutions for many years. Individually, we recognized the importance
‘of computer demonstrations and experiments as a supplement to the theory and had been
independently developing computer-based projects, Several years ago we began sharing
‘our experiences and projects with each other and eventually decided to make our combined
experiences and collection of projects more widely available,
‘The exercises in this book are designed to be used together with a digital signal
processing textbook and on the workstations and personal computers commonly used at
‘most universities. Students working alone or in small groups can approach the exercises in
a variety of ways consistent with their individual styles of learning and at a speed and for a
length of time consistent with their skills and abilities, The Format and exercises hopefully
encourage (even require) experimentation and learning by discovery, much as is done in
engineering practice. The use of high-speed integrated graphics allows visualization, which
is very valuable in learning abstract theories and methods.
‘In our early experiences with computer-based projects for signal processing, we used
4 variety of computers and software. Over a period of time, and again somewhat inde-
pendently, we each began gravitating toward the use of MATLAB in our courses because
‘we found that its interactive mathematical calculations, easy-to-use inte aphies,
simple programmability, consistent functional environment, and availability on a wide va
riety of hardware make it very efficient for students to focus quickly on the essential signal
processing issues without gged down with details of a particular m:
programming language. As a natural consequence, in combining our projects into this col
lection, we adopted MATLAB as the signal processing environment. The recent availability
of a student version of MATLAB makes it even more attractive For educational use, There
are, of course, many other excellent and well-supported computer-based signal processing
environments, and we tried to make the projects in this book adaptable to these as well.
In order to provide maximum flexibility in the use of these projects, each section in
‘a chapter contains one or more projects associated with a common theme. Te intent is for
each of the chapter sections to be independent of the others so that the order and selection
BoxPreface
can be as flexible as possible. When a section contains more than one project, we have
again tried to keep separate projects as independent as possible, although some of the more
advanced projects in a section might assume familiarity with earlier ones. Within each
project are exercises which, by necessity, are somewhat interdependent, although in many
eases, some of the exercises are optional
(Our individual experiences have varied in the use of these projects. In some cases,
these exercises have been used to supplement lecture and homework material, while in
others, the material in this book has been used in a signal processing laboratory, supple-
‘mented by real-time signal processing hardware and development systems for various DSP
chips. The level of the material is appropriate for senior and first-year graduate courses.
‘The time required to complete one exercise varies from as litle as five minutes to as much
as several hours. The diversity of exercises reflects the authors” different teaching styles.
‘Some projects include considerable text material reviewing the signal processing prineiples
involved in the associated exercises. Other projects focus on the signal processing problems
tobe solved and rely on the Suggested reading to provide the necessary theory. Oceasion-
ally samples of special MATLAB functions are included in the text, Sometimes special files
of data (e.g., speech) are referenced. The MathWorks, Inc., has arranged to supply th
‘material from their web site
From the outset, our goal has been to make this collection of projects available in a
timely way to.as wide an audience as possible. Without question, many of the projects could
have been polished and expanded further. There are also many other projects that were in
terms, and the other vector containing the
Feedback coefficients, a, forthe y terms. The coefficient ag is usually taken tobe 1, so that
‘when y[n] is writen in terms of past values it drops out:
Yau vin 1+ 5 beat — 01
In MATLAB the £1 tex function will divide out ap, soit must not be zero.
1
yin}
Hints
‘The function y = filter (b,a,x) implements a digital filter defined by the a
and b coefficient vectors as in (I-1) to filter the data stored in x. If x is the unit impulse
signal, then y will be the impulse response fi(n]. Note that the function £1ter returns
only as many samples into y as there are in x (i.e, the impulse response is truncated to the
length of the unit impulse vector, x).
ER
Simple
CCreate vectors band a that contain the coefficients of s[] and yl], respectively, inthe
following difference equation:
ifference Equation
yin] +0.9yIn ~
0.3xln) + 0.6x(n ~ 1] +0.34{n — 2}, (2)
'b, Caleulate yf] analytically for xf) = 5).
ce. Now ereate a unit impulse vector, imp, of length 128. Generate the frst 128 points ofthe
‘impulse response ofthe filter in (1-2). Use atem to plot these values as a diserete-time
signal versus time (see hep stem), It may help to plot just the first 10 or 20 point.
EXERCISE 1.2
Impulse Response with £4 ter
1. Use the £1 ter function to generate and plot the impulse response in] ofthe following
dlilfeence equation. Plot h(n] inthe range of 10 0, the output signal for large wis due entirely tothe input
Infact, the output becomes a constant in this cas.
1 Por the system in (1-3), find the response to step function input of amplitude 3 (ie
xn] = 3ubn)). Use a long enough seetion of the input signal so thatthe output from
i Leer is early constant This length can be estimated by considering the size of |p"
versus 7. Plot the step response and determine the constant level (Gy) of the output 3s
b. The constant level determined in part (a) isthe steady-state response, Its precise value can
be ealetated by observing that both yn] and x{a] become constants inthe limit => oc.
Thus, lim yf] = Gp and.x(n] = 3. Use these Facts in (1-3) to determine Gy
The variable part ofthe total response is called the transient response. Determine the
transient response yu] = y(n] ~ Gy and plot it for 0