DIGITAL SIGNAL PROCESSING USING MATLAB FOR STUDENTS AND RESEARCHERS ffirs01.indd iffirs01.indd i 4/13/2011 5:25:59 PM4/13/2011 5:25:59 PM www.it-ebooks.info DIGITAL SIGNAL PROCESSING USING MATLAB FOR STUDENTS AND RESEARCHERS JOHN W. LEIS University of Southern Queensland A JOHN WILEY & SONS, INC., PUBLICATION ffirs02.indd iiiffirs02.indd iii 4/13/2011 5:52:42 PM4/13/2011 5:52:42 PM www.it-ebooks.info Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved. Published by John Wiley & Sons, Inc., Hoboken, New Jersey. Published simultaneously in Canada. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created ore extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. For general information on our other products and services please contact our Customer Care Department with the U.S. at 877-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print, however, may not be available in electronic format. Library of Congress Cataloging-in-Publication Data: Leis, John W. (John William), 1966- Digital Signal Processsing Using MATLAB for Students and Researchers / John W. Leis. p. cm Includes bibliographical references and index. ISBN 978-0-470-88091-3 1. Signal processing–Digital techniques. 2. Signal processing–Mathematics–Data processing. 3. MATLAB. I. Title. TK5102.9.L4525 2011 621.382′2–dc22 2010048285 Printed in Singapore. 10 9 8 7 6 5 4 3 2 1 ffirs03.indd ivffirs03.indd iv 4/13/2011 5:26:00 PM4/13/2011 5:26:00 PM www.it-ebooks.info To Debbie, Amy, and Kate ffirs04.indd vffirs04.indd v 4/13/2011 5:26:01 PM4/13/2011 5:26:01 PM www.it-ebooks.info CONTENTS PREFACE XI CHAPTER 1 WHAT IS SIGNAL PROCESSING? 1 1.1 Chapter Objectives 1 1.2 Introduction 1 1.3 Book Objectives 2 1.4 DSP and ITS Applications 3 1.5 Application Case Studies Using DSP 4 1.6 Overview of Learning Objectives 12 1.7 Conventions Used in This Book 15 1.8 Chapter Summary 16 CHAPTER 2 MATLAB FOR SIGNAL PROCESSING 19 2.1 Chapter Objectives 19 2.2 Introduction 19 2.3 What Is MATLAB? 19 2.4 Getting Started 20 2.5 Everything Is a Matrix 20 2.6 Interactive Use 21 2.7 Testing and Looping 23 2.8 Functions and Variables 25 2.9 Plotting and Graphing 30 2.10 Loading and Saving Data 31 2.11 Multidimensional Arrays 35 2.12 Bitwise Operators 37 2.13 Vectorizing Code 38 2.14 Using MATLAB for Processing Signals 40 2.15 Chapter Summary 43 CHAPTER 3 SAMPLED SIGNALS AND DIGITAL PROCESSING 45 3.1 Chapter Objectives 45 3.2 Introduction 45 3.3 Processing Signals Using Computer Algorithms 45 3.4 Digital Representation of Numbers 47 3.5 Sampling 61 3.6 Quantization 64 3.7 Image Display 74 3.8 Aliasing 81 3.9 Reconstruction 84 3.10 Block Diagrams and Difference Equations 88 ftoc.indd viiftoc.indd vii 4/13/2011 5:26:03 PM4/13/2011 5:26:03 PM www.it-ebooks.info viii CONTENTS 3.11 Linearity, Superposition, and Time Invariance 92 3.12 Practical Issues and Computational Effi ciency 95 3.13 Chapter Summary 98 CHAPTER 4 RANDOM SIGNALS 103 4.1 Chapter Objectives 103 4.2 Introduction 103 4.3 Random and Deterministic Signals 103 4.4 Random Number Generation 105 4.5 Statistical Parameters 106 4.6 Probability Functions 108 4.7 Common Distributions 112 4.8 Continuous and Discrete Variables 114 4.9 Signal Characterization 116 4.10 Histogram Operators 117 4.11 Median Filters 122 4.12 Chapter Summary 125 CHAPTER 5 REPRESENTING SIGNALS AND SYSTEMS 127 5.1 Chapter Objectives 127 5.2 Introduction 127 5.3 Discrete-Time Waveform Generation 127 5.4 The z Transform 137 5.5 Polynomial Approach 144 5.6 Poles, Zeros, and Stability 146 5.7 Transfer Functions and Frequency Response 152 5.8 Vector Interpretation of Frequency Response 153 5.9 Convolution 156 5.10 Chapter Summary 160 CHAPTER 6 TEMPORAL AND SPATIAL SIGNAL PROCESSING 165 6.1 Chapter Objectives 165 6.2 Introduction 165 6.3 Correlation 165 6.4 Linear Prediction 177 6.5 Noise Estimation and Optimal Filtering 183 6.6 Tomography 188 6.7 Chapter Summary 201 CHAPTER 7 FREQUENCY ANALYSIS OF SIGNALS 203 7.1 Chapter Objectives 203 7.2 Introduction 203 7.3 Fourier Series 203 7.4 How Do the Fourier Series Coeffi cient Equations Come About? 209 7.5 Phase-Shifted Waveforms 211 7.6 The Fourier Transform 212 7.7 Aliasing in Discrete-Time Sampling 231 7.8 The FFT as a Sample Interpolator 233 ftoc.indd viiiftoc.indd viii 4/13/2011 5:26:03 PM4/13/2011 5:26:03 PM www.it-ebooks.info CONTENTS ix 7.9 Sampling a Signal over a Finite Time Window 236 7.10 Time-Frequency Distributions 240 7.11 Buffering and Windowing 241 7.12 The FFT 243 7.13 The DCT 252 7.14 Chapter Summary 266 CHAPTER 8 DISCRETE-TIME FILTERS 271 8.1 Chapter Objectives 271 8.2 Introduction 271 8.3 What Do We Mean by “Filtering”? 272 8.4 Filter Specifi cation, Design, and Implementation 274 8.5 Filter Responses 282 8.6 Nonrecursive Filter Design 285 8.7 Ideal Reconstruction Filter 293 8.8 Filters with Linear Phase 294 8.9 Fast Algorithms for Filtering, Convolution, and Correlation 298 8.10 Chapter Summary 311 CHAPTER 9 RECURSIVE FILTERS 315 9.1 Chapter Objectives 315 9.2 Introduction 315 9.3 Essential Analog System Theory 319 9.4 Continuous-Time Recursive Filters 326 9.5 Comparing Continuous-Time Filters 339 9.6 Converting Continuous-Time Filters to Discrete Filters 340 9.7 Scaling and Transformation of Continuous Filters 361 9.8 Summary of Digital Filter Design via Analog Approximation 371 9.9 Chapter Summary 372 BIBLIOGRAPHY 375 INDEX 379 ftoc.indd ixftoc.indd ix 4/13/2011 5:26:03 PM4/13/2011 5:26:03 PM www.it-ebooks.info PREFACE I was once asked what signal processing is. The questioner thought it had something to do with traffi c lights. It became clear to me at that moment that although the theory and practice of signal processing in an engineering context has made possible the massive advances of recent times in everything from consumer electronics to healthcare, the area is poorly understood by those not familiar with digital signal processing (DSP). Unfortunately, such lack of understanding sometimes extends to those embarking on higher education courses in engineering, computer science, and allied fi elds, and I believe it is our responsibility not simply to try to cover every possible theoretical aspect, but to endeavor to open the student ’ s eyes to the possible applications of signal processing, particularly in a multidisciplinary context. With that in mind, this book sets out to provide the necessary theoretical and practical underpinnings of signal processing, but in a way that can be readily under- stood by the newcomer to the fi eld. The assumed audience is the practicing engineer, the engineering undergraduate or graduate student, or the researcher in an allied fi eld who can make use of signal processing in a research context. The examples given to introduce the topics have been chosen to clearly introduce the motivation behind the topic and where it might be applied. Necessarily, a great deal of detail has to be sacrifi ced in order to meet the expectations of the audience. This is not to say that the theory or implementation has been trivialized. Far from it; the treatment given extends from the theoretical underpinnings of key algorithms and techniques to computational and numerical aspects. The text may be used in a one - term or longer course in signal processing, and the assumptions regarding background knowledge have been kept to a minimum. Shorter courses may not be able to cover all that is presented, and an instructor may have to sacrifi ce some breadth in order to ensure adequate depth of coverage of important topics. The sections on fast convolution and fi ltering, and medical image processing, may be omitted in that case. Likewise, recursive fi lter design via analog prototyping may be omitted or left to a second course if time does not permit coverage. A basic understanding of algebra, polynomials, calculus, matrices, and vectors would provide a solid background to studying the material, and a fi rst course in linear systems theory is an advantage but is not essential. In addition to the aforementioned mathematical background, a good understanding of computational principles and coding, and a working knowledge of a structured programming language is desirable, as is prior study of numerical mathematics. Above all, these xi fpref.indd xifpref.indd xi 4/13/2011 5:26:02 PM4/13/2011 5:26:02 PM www.it-ebooks.info xii PREFACE should not be considered as a list of essential prerequisites; the reader who is lacking in some of these areas should not be deterred. It is hoped that the problems at the end of each chapter, in conjunction with the various case studies, will give rise to a suffi ciently rich learning environment, and appropriately challenging term projects may be developed with those problems as starting points. John W. Leis fpref.indd xiifpref.indd xii 4/13/2011 5:26:02 PM4/13/2011 5:26:02 PM www.it-ebooks.info CHAPTER 1 WHAT IS SIGNAL PROCESSING? 1.1 CHAPTER OBJECTIVES On completion of this chapter, the reader should 1. be able to explain the broad concept of digital signal processing (DSP); 2. know some of the key terms associated with DSP; and 3. be familiar with the conventions used in the book, both mathematical and for code examples. 1.2 INTRODUCTION Signals are time - varying quantities which carry information. They may be, for example, audio signals (speech, music), images or video signals, sonar signals or ultrasound, biological signals such as the electrical pulses from the heart, commu- nications signals, or many other types. With the emergence of high - speed, low - cost computing hardware, we now have the opportunity to analyze and process signals via computer algorithms. The basic idea is straightforward: Rather than design complex circuits to process signals, the signal is fi rst converted into a sequence of numbers and pro- cessed via software. By its very nature, software is more easily extensible and more versatile as compared with hard - wired circuits, which are diffi cult to change. Furthermore, using software, we can build in more “ intelligence ” into the operation of our designs and thus develop more human - usable devices. A vitally important concept to master at the outset is that of an algorithm : the logical sequence of steps which must be followed in order to generate a useful result. Although this defi nition is applicable to general - purpose information processing, the key difference is in the nature of the data which are processed. In signal processing, the data sequence represents information which is not inherently digital and is usually imprecise. Digital Signal Processing Using MATLAB for Students and Researchers, First Edition. John W. Leis. © 2011 John Wiley & Sons, Inc. Published 2011 by John Wiley & Sons, Inc. 1 c01.indd 1c01.indd 1 4/13/2011 5:20:44 PM4/13/2011 5:20:44 PM www.it-ebooks.info [...]... http://www.mathworks.com/ Digital Signal Processing Using MATLAB for Students and Researchers, First Edition John W Leis © 2011 John Wiley & Sons, Inc Published 2011 by John Wiley & Sons, Inc 19 www.it-ebooks.info c02.indd 19 4/13/2011 5:20:50 PM 20 CHAPTER 2 MATLAB FOR SIGNAL PROCESSING It is worth noting that DSP systems are often developed in MATLAB, and implemented on the target hardware using the C language... 2 MATLAB FOR SIGNAL PROCESSING 2.1 CHAPTER OBJECTIVES On completion of this chapter, the reader should be able to: 1 use the MATLAB interactive window command line, and enter MATLAB scripts 2 use MATLAB function files 3 be able to display image data from a matrix 4 be able to play back audio data from a vector 5 understand the concepts of signal data file storage and data formats 2.2 INTRODUCTION MATLAB ... CHAPTER 1 WHAT IS SIGNAL PROCESSING? Chapter 3 looks at how signals in the real world are acquired for processing by computer Computer arithmetic is introduced since it is fundamental to any signal processing algorithms where the processing is performed digitally How signals in the real world are acquired is discussed, and from all these aspects, we can gauge the processing accuracy, speed, and memory space... required for any given application Chapter 4 looks at random signals The “noise” which affects signals is often random, and thus it is important to understand the basics of how random signals are characterized The examples in the chapter look at noise in both audio signals and images Chapter 5 introduces the representation of known signals via mathematical equations This is important, as many signals... as vehicles In cars and planes, for example, this is a desirable objective in order to improve passenger comfort and to enhance safety Digital music in the entertainment industry uses special effects and enhancements for example, adding three-dimensional sound “presence” and simulating reverberation from the surroundings Communications and data transmission relies heavily on signal processing Error control,... algorithms and their associated mathematics A basic grounding in linear algebra and calculus is necessary for some sections, as is an understanding of complex numbers Because we often have to explain the use of blocks of samples and how they are stored and processed, the concepts of vectors and matrices are essential To avoid confusion between scalar values and vectors, vectors and matrices, and constants and. .. feasible test signal, and thus the impulse response cannot be measured directly Rather, we use methods such as that described using white noise, to estimate the impulse response of the system Chapter 6 discusses correlation and system identification, and Chapter 7 further examines the concept of frequency response 1.5.3 Image Processing The processing of digital pictures, in particular, and digital images... distance between samples Other information about the speaker–microphone–room coupling can be gleaned by using a different test signal, which is not difficult to do using DSP techniques Figure 1.4 shows the result of using random noise for the output signal (the random noise is also termed “white noise” by analogy with white light, which comprises all wavelengths) This type of signal is a broad-spectrum one,... of values as with the for loop www.it-ebooks.info c02.indd 24 4/13/2011 5:20:50 PM 2.8 FUNCTIONS AND VARIABLES 25 x = 1; while( x < 10 ) x = x*1.1; end Care should be exercised when testing for exact equality, and where very large or very small numbers might be encountered MATLAB has the built-in variables realmin and realmax for the smallest and largest positive numbers, and eps for floating-point relative... 25 4/13/2011 5:20:50 PM 26 CHAPTER 2 MATLAB FOR SIGNAL PROCESSING % add extra paths − user library files addpath(‘c: \matlab\ lib’); % start in this directory cd c: \matlab\ work The comment character % makes the remainder of the line a comment (which is ignored by MATLAB) The addpath command adds a new directory path to the existing search path (where MATLAB searches for files) path may be used to show the . DIGITAL SIGNAL PROCESSING USING MATLAB FOR STUDENTS AND RESEARCHERS ffirs01.indd iffirs01.indd i 4/13/2011 5:25:59 PM4/13/2011 5:25:59 PM www.it-ebooks.info DIGITAL SIGNAL PROCESSING USING. Digital Signal Processsing Using MATLAB for Students and Researchers / John W. Leis. p. cm Includes bibliographical references and index. ISBN 978-0-470-88091-3 1. Signal processing Digital. Processing Signals 40 2.15 Chapter Summary 43 CHAPTER 3 SAMPLED SIGNALS AND DIGITAL PROCESSING 45 3.1 Chapter Objectives 45 3.2 Introduction 45 3.3 Processing Signals Using Computer Algorithms 45 3.4 Digital