DIGITAL SIGNAL AND IMAGE PROCESSING SERIES Digital Signal and Image Processing using MATLAB® nd Revised and Updated 2 Edition Digital Signal and Image Processing using MATLAB® Volume 1 Fundamentals Gerard Blanchet Maurice Charbit iSlE WILEY First edition published 2006 in Great Britain and the United States by ISTE Ltd and John Wiley & Sons, Inc. © ISTE Ltd 2006 This edition published 2014 in Great Britain and the United States by ISTE Ltd and John Wiley & Sons, Inc. Apart trom any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing ofthe publishers, or in the case of reprographic reproduction in accordance with the terms and licenses issued by the CLA. Enquiries concerning reproduction outside these terms should be sent to the publishers at the undermentioned address: ISTE Ltd John Wiley & Sons, Inc. 27-37 St George's Road III River Street London SW19 4EU Hoboken, NJ 07030 UK USA www.iste.co.uk www.wiley.com © ISTE Ltd 2014 The rights of Gerard Blanchet and Maurice Charbit to be identified as the authors of this work have been asserted by them in accordance with the Copyright, Designs and Patents Act 1988. Library of Congress Control Number: 2014942418 British Library Cataloguing-in-Publication Data A CIP record for this book is available trom the British Library ISBN 978-1-84821-640-2 MA TLAB®is a trademark of The Math Works, Inc. and is used with permission. The MathWorks does not warrant the accuracy of the text or exercises in this book. This book's use or discussion of MA TLAB® software does not constitute endorsement or sponsorship by The Math Works of a particular pedagogical approach or use of the MAT LAB®s oftware. J;;S MIX Paper from FSC responsible sources www.fsc.org FSC" C013604 Printed and bound in Great Britain by CPI Group (UK) Ltd., Croydon, Surrey CRO 4YY Contents Foreword 11 Notations and Abbreviations 15 Introduction to MATLAB 19 1 Variables and constants . 22 1.1 Vectors and matrices. 22 1.2 Predefined matrices . 25 1.3 Constants and initialization 26 1.4 Multidimensional arrays 26 1.5 Cells and structures 27 2 Operations and functions . 29 2.1 Matrix operations . 29 2.2 Pointwise operations 31 2.3 Mathematical functions 32 2.4 Matrix functions . . . . 34 2.5 Searching elements using min, max, find, etc. functions 34 2.6 Other useful functions . . . . . . . . . 36 3 Programming structures . . . . . . . . . . . . 37 3.1 Logical operators on boolean variables 37 3.2 Program loops ... . 38 3.3 Functions... .. . . 39 4 Graphically displaying results 39 4.1 2D display. . . . . . . 39 4.2 3D display ...... . 43 4.3 Notes on plotting a curve 44 4.4 Animations.. .. .... 45 5 Converting numbers to character strings 47 6 Input/o utput . .. . ... . .. . .. . . 47 7 Program writing . . ... . .. . .. . . 48 7.1 Developing and testing performances . 48 7.2 Various functions ... 49 7.3 Using other languages ........ . 51 6 Digital Signal and Image Processing using MATLAB® Part I Deterministic Signals 53 Chapter 1 Signal Fundamentals 55 1.1 The concept of signal. . . . . . . . . . . 55 1.1.1 A few signals . . . . . . . . . . . 56 1.1.2 Spectral representation of signals 57 1.2 The concept of system 60 1.3 Summary .. . .. .. .. .... .. . . 62 Chapter 2 Discrete Time Signals and Sampling 65 2.1 Fundamentals of sampling .. 66 2.1.1 The Poisson formula ... . 66 2.1.2 Perfect reconstruction .. . 68 2.1.3 Digital-to-analog conversion 79 2.2 Plotting a signal as a function of time 80 2.3 Spectral representation ........ . 82 2.3.1 Discrete-time Fourier transform (DTFT) . 82 2.3.2 Discrete Fourier transform (DFT) 86 2.3.3 Fast Fourier transform . . . . . . . 91 Chapter 3 Spectral Observation 95 3.1 Spectral accuracy and resolution . . . . . . . 95 3.1.1 Observation of a complex exponential 95 3.1.2 Plotting accuracy of the DTFT ... . 98 3.1.3 Frequency resolution ......... . 98 3.1.4 Effects of windowing on the resolution 101 3.2 Short term Fourier transform .. . 104 3.3 Summing up . .... ...... . 108 3.4 Application examples and exercises 110 3.4.1 Amplitude modulations 110 3.4.2 Frequency modulation 112 Chapter 4 Linear Filters 115 4.1 Definitions and properties 115 4.2 The z-transform ..... 120 4.2.1 Definition and properties 121 4.2.2 A few examples ..... . 122 4.3 Transforms and linear filtering . 123 4.4 Difference equations and rational TF filters 125 4.4.1 Stability considerations ...... . 128 4.4.2 FIR and IIR filters ......... . 129 4.4.3 Causal solution and initial conditions 130 4.4.4 Calculating the responses . 133 4.4.5 Stability and the Jury test .. .. .. . 134 Contents 7 4.5 Connection between gain and poles/zeros 135 4.6 Minimum phase filters .... 144 4.6.1 All-pass filters 145 4.6.2 Minimum phase filters 146 4.7 Filter design methods .... 149 4.7.1 Going from the continuous-time filter to the discrete-time filter . . . . . . . . . . . . . . . . . . . . . . 149 4.7.2 FIR filter design using the window method 153 4.7.3 IIR filter design ..... . 164 4.8 Oversampling and undersampling 167 4.8.1 Oversampling. 167 4.8.2 Undersampling ... .. . 171 Chapter 5 An Introduction to Image Processing 175 5.1 Introduction . . .. . ....... . 175 5.1.1 Image display, color palette . . .. . 175 5.1.2 Importing images. . . . . . . . . . . 179 5.1.3 Arithmetical and logical operations. 181 5.2 Color spaces. . . . . 183 5.2.1 RGB coding. . 187 5.2.2 HSV coding . . 188 5.2.3 CMYK coding 189 5.2.4 How to extract the RGB information from an image 191 5.2.5 Converting from color to grayscale 191 5.3 Geometric transformations of an image. 192 5.3.1 The typical transformations 192 5.3.2 Image registration ... 195 5.4 Frequential content of an image 198 5.5 Linear filtering . . . . . . . 204 5.6 Other operations on images 213 5.6.1 Undersampling .. 213 5.6.2 Oversampling ... 215 5.6.3 Contour detection 217 5.6.4 Median filtering .. 221 5.6.5 Image binarization 222 5.6.6 Modifying the contrast of an image. 227 5.6.7 Morphological filtering of binary images 231 5.7 JPEG lossy compression ......... . 233 5.7.1 Basic algorithm ........ . .. . 234 5.7.2 Writing the compression function .. 235 5.7.3 Writing the decompression function 238 8 Digital Signal and Image Processing using MATLAB® Part II Random Signals 241 Chapter 6 Random Variables 243 6.1 Random phenomena in signal processing 243 6.2 Basic concepts of random variables . . . 244 6.3 Common probability distributions 253 6.3.1 Uniform probability distribution on (a, b) 253 6.3.2 Real Gaussian random variable . . . . . . 254 6.3.3 Complex Gaussian random variable 255 6.3.4 Generating the common probability distributions 256 6.3.5 Estimating the probability density 259 6.3.6 Gaussian random vectors .. .. 260 6.4 Generating an r.v. with any type of p.d. 262 6.5 Uniform quantization. . . . . . . . . . . 268 Chapter 7 Random Processes 271 7.1 Introduction ........ . 271 7.2 Wide-sense stationary processes ........... . 272 7.2.1 Definitions and properties of WSS processes. 273 7.2.2 Spectral representation of a WSS process 276 7.2.3 Sampling a WSS process ....... . 285 7.3 Estimating the covariance .......... . 288 7.4 Filtering formulae for WSS random processes 296 7.5 MA, AR and ARMA time series ...... . 302 7.5.1 Q order MA (Moving Average) process. 302 7.5.2 P order AR (AutoRegressive) Process 304 7.5.3 ARMA (P, Q) process ........ . 311 Chapter 8 Spectra Estimation 313 8.1 Non-parametric estimation of the psd ...... . . 313 8.l.1 Estimation from the auto covariance function 313 8.l.2 Estimation based on the periodogram 317 8.2 AR estimation .. . ...... . .. . .... .. . 325 8.2.1 AR parameters . . ... . .. . .. . ... . 325 8.2.2 Estimating the spectrum of an AR process 329 8.3 Estimating the amplitudes and the frequencies . 330 8.3.1 The case of a single complex exponential. 330 8.3.2 Real harmonic mixtures . .. . 332 8.3.3 Complex harmonic mixtures . . 334 8.4 Periodograms and the resolution limit 336 Chapter 9 The Least Squares Method 349 9.1 The projection theorem . 349 9.2 The least squares method ... . . . . 353