• No results found

2.1 Reading and playing back a wav-file using MATLAB. . . 22 2.2 A simple MATLAB m-file for DSK talk-through. . . 26 2.3 Talk-through declarations. . . 27 2.4 Talk-through code to swap left and right channels. . . 28 3.1 Simple MATLAB FIR filter example. . . 39 3.2 MATLAB FIR filter adjusted for real-time processing. . . 43 3.3 Brute-force FIR filter declarations. . . 45 3.4 Brute-force FIR filtering for real-time. . . 45 3.5 An example coeff.h file. . . 49 3.6 FIR filter using a circular buffer. . . 50 4.1 Simple MATLAB IIR filter example. . . 79 4.2 Brute-force IIR filter declarations. . . 80 4.3 Brute-force IIR filtering for real-time. . . 80 5.1 MATLAB implementation of phase accumulator signal generation. . . 94 5.2 MATLAB implementation of the table lookup-based signal generation. . . 95 5.3 Variable declaration associated with sinusoidal signal generation. . . 97 5.4 Algorithm associated with sinusoidal signal generation. . . 97 5.5 Variable declaration associated with sinusoidal signal generation. . . 98 5.6 Algorithm associated with sinusoidal signal generation. . . 98 5.7 Variable declaration for table-based signal generation. . . 99 5.8 Algorithm for table-based sinusoidal signal generation. . . 99 5.9 Variable declaration associated with a digital resonator. . . 101 5.10 Algorithm associated with a digital resonator. . . 101 5.11 MATLAB implementation of circular and linear correlation for PN sequences.108 5.12 MATLAB program to generate PN sequences for a given set of feedback taps.112 5.13 Declarations for the PN Generator code. . . 114 5.14 Algorithm for the PN Generator code. . . 114 6.1 Main program for simple frame-based processing using ISRs. . . 127 6.2 Declarations from the “ISRs.c” file. . . 127 6.3 The input part of the interrupt service routine from the “ISRs.c” file. . . . 128 6.4 Abbreviated version of ProcessBuffer from the “ISRs.c” file. . . 129 6.5 The output part of the interrupt service routine from the “ISRs.c” file. . . 129 6.6 Main program for frame-based processing using EDMA. . . 131 6.7 Declarations from EDMA version of the “ISRs.c” file. . . 132 6.8 Function for implementing triple buffering using the EDMA hardware. . . 133 6.9 Function for initializing the DSK when using EDMA. . . 133

xxvii

xxviii PROGRAM LISTINGS 6.10 Function for initializing the EDMA hardware. . . 133 6.11 An abbreviated version of the ProcessBuffer function from the EDMA

version of the “ISRs.c” file. . . 136 7.1 ProcessBuffer() routine for implementing a frame-based FIR filter. . . . 144 8.1 A MATLAB listing that compares linear and circular convolution. . . 152 8.2 A MATLAB listing that demonstrates how to convert circular convolution

into the equivalent of linear convolution. . . 153 8.3 A structure for implementing complex numbers in C. . . 157 8.4 A function for calculating the complex twiddle factors. . . 158 8.5 The C code for performing the FFT butterfly operation. . . 158 8.6 A routine for “unscrambling” the order from bit-reversed addressing to

normal ordering. . . 159 8.7 MATLAB commands used to confirm the correctness of your FFT. . . 160 10.1 A MATLAB FIR comb filter example. . . 192 10.9 Excerpt of variable declarations for the ISRs_A.c comb filter. . . 198 10.10 Real-time comb filter from ISRs_A.c. . . 199 12.3 Another approach to creating the PPM, excerpted from PPM_ISRs3.c. . . 217 13.1 MATLAB example of AM (DSB-LC) generation. . . 223 13.2 C code for scaled implementation of DSB-LC AM. . . 225 13.3 C code to extract the sine function values from the lookup table. . . 226 13.4 C code for scaled implementation of DSB-LC with sine table lookup. . . . 226 14.1 Using MATLAB to design a Hilbert transforming filter. . . 235 14.2 MATLAB simulation of a Hilbert-based AM receiver. . . 238 14.3 Variable declaration associated with a Hilbert-based AM receiver. . . 239 14.4 Algorithm associated with Hilbert-based AM demodulation. . . 240 15.1 Simulation of a PLL. . . 244 15.2 Declaration portion of the PLL project code. . . 254 15.3 Algorithm portion of the PLL project code. . . 255 16.1 Simulation of a rectangular shaped BPSK signal generator. . . 268 16.2 Simulation of a impulse modulated raised-cosine BPSK signal generator. . 270

PROGRAM LISTINGS xxix 16.3 Declaration portion of the rectangular BPSK project code. . . 273 16.4 Algorithm portion of the rectangular BPSK project code. . . 274 16.5 Declaration portion of the impulse modulation raised-cosine pulse shaped

project code. . . 274 16.6 Algorithm portion of the impulse modulation raised-cosine pulse shaped

project code. . . 275 17.1 Declarations associated with the simulation of the BPSK receiver. . . 286 17.2 ISR simulation of the BPSK receiver. . . 287 17.3 Declaration portion of the BPSK receiver project code. . . 290 17.4 Algorithm portion of the BPSK receiver project code. . . 291 18.1 Simulation of an impulse modulated root-raised-cosine QPSK signal

gener-ator. . . 306 18.2 Declaration portion of the impulse modulation root-raised-cosine pulse shaped

QPSK project code. . . 310 18.3 Algorithm portion of the impulse modulation root-raised-cosine pulse shaped

project code. . . 311 18.4 Declaration portion of the more efficient impulse modulation

root-raised-cosine pulse shaped QPSK project code. . . 312 18.5 Algorithm portion of the improved efficiency impulse modulation

root-raised-cosine pulse shaped project code. . . 313 19.1 Modified sections of the QPSK signal generator. . . 320 19.2 Simulation of a QPSK receiver (through the AGC only). . . 320 19.3 Simulation of the complete QPSK receiver. . . 323 19.4 Declarations for the “through AGC” portion of the QPSK receiver code. . 330 19.5 Algorithm portion of the “through AGC” portion of the QPSK receiver code.331 19.6 Declaration portion of the complete QPSK receiver project code. . . 333 19.7 Algorithm portion of the complete QPSK receiver project code. . . 335 F.1 Checking for real-time schedule failure using the WriteDigitalOutputs()

function. . . 381 F.2 Checking for real-time schedule failure using the interrupt flags register. . 382 F.3 Example IIR filter code with incorrect variable initialization. . . 382 F.4 Correct variable initialization. . . 382 F.5 C6000 typedef directives. . . 383 F.6 C5000 typedef directives. . . 383

This page intentionally left blank This page intentionally left blank

Preface

T

HIS book is intended to be used by students, educators, and working engineers who need a straightforward, practical background in real-time digital signal processing (DSP). In the past, there has been a formidable “gap” between theory and practice with regard to real-time DSP. This book bridges that gap using methods proven by the authors.

The book is organized into three sections: Enduring Fundamentals (9 chapters), Projects (10 chapters), and Appendices (6 chapters). The CD-ROM that accompanies this book includes all necessary source code, along with additional information and tutorial material to help the reader master real-time DSP.

We anticipate that the reader will use this book in conjunction with a more traditional, theoretical signal processing text if this is their first exposure to DSP. The book you are now reading is not intended to teach basic DSP theory; we assume you already know or are in the process of learning the theory of DSP. Instead of teaching theory, this book uses a highly practical, step-by-step framework that provides hands-on experience in real-time DSP and, in so doing, reinforces such basic DSP theory (what the authors refer to as enduring fundamentals).1 This framework utilizes a series of demonstrations, exercises, and hands-on projects in each chapter that begins with a quick overview of the applicable theory, progresses to applying the concepts using MATLAB, and ultimately running applicable programs in real-time on some of the latest high-performance DSP hardware. For the projects, the reader is coached into creating for themselves various interesting real-time DSP programs. Be sure to check out the appendices of this book—some people think they are worth the price of the book all by themselves! Each of the enduring fundamentals chapters include at the end of the chapter a number of problems, for homework or self-study, that probe the reader’s understanding of key DSP concepts important to that particular chapter. These key concepts are typically only briefly covered in this text, as mentioned above; more depth is expected to come from the more traditional and theoretical text that the reader has already read or uses now in conjunction with this book. If the solutions to the end of chapter problems prove elusive to the reader, then a review of the theory is warranted.

Ideally, the reader should either be enrolled in, or have already taken, an introductory DSP (or discrete-time signals and systems) class. However, we have had success using various parts of this book with students who have not yet had a DSP class, using a “just in time” approach to supplemental theory. The topic coverage of this book is broad enough to accommodate both undergraduate and graduate level courses. A basic familiarity with MATLAB and the C programming language is expected—but you don’t have to be an expert in either. To take full advantage of this book, the reader should have access to a modest collection of hardware and software tools. In particular, recommended items include a standard PC running a fairly recent version of Windows (e.g., XP, Vista, Windows 7,

1It would be highly impractical for a book of reasonable size to teach both theory and hand-on practice in an effective manner.

xxxi

xxxii PREFACE etc.), a copy of MATLAB and its Signal Processing Toolbox, and one of the inexpensive Texas Instruments DSP Starter Kit boards (with software) described below. Some other miscellaneous items, such as a signal source (a portable digital music player such as an iPod works well, as does a CD player); speakers (the powered type typically attached to a PC works well), headphones, or earbuds; and 3.5 mm stereo patch cables (sometimes called 1/8th inch stereo phono plug cables) will all be useful. For processing the input and output signals with the greatest flexibility, several different codecs for the DSP boards are supported (see Chapter 1). Access to some common test equipment such as an oscilloscope, a spectrum analyzer, and a signal generator allows even more flexibility, but we show how a second inexpensive DSP board or even a PC’s soundcard can be used as a substitute for such test equipment if desired.

The real-time software explained in and provided with this book supports several of the relatively inexpensive DSP boards available from Texas Instruments. These boards in-clude the latest OMAP-L138 Experimenter Kit and the still available TMS320C6713 DSK.2 There is limited backward compatibility with the TMS320C6711 DSK as well, but there is no explicit coverage in the text of this now-discontinued board. These boards all come standard with (or have available for free download) powerful software development tools (Code Composer StudioTM) of which we make considerable use in the following chapters.

The first edition of this book was written in response to the many requests by both students and faculty at a variety of universities. When the authors presented some of the concepts and code that appear in this book at various conferences, we were besieged by an audience trying to “bridge the gap” from theory to practice (using real-time hardware) on their own. This book collects in a single source our unified step-by-step transition to get across that “gap,” and the first edition proved to be quite popular.

This second edition was written for several reasons. First, it updates the book to in-clude support for one of the latest and most powerful of the inexpensive DSP development boards now available from Texas Instruments, the OMAP-L138 Experimenter Kit. This complicated but extremely versatile board is a good example of why our book is used by so many engineers, educators, and students: we make it easy to begin using this board for real-time DSP and save the reader many hours of frustration. A more detailed description of the DSP boards supported by this book is included in Chapter 1. Second, this edition includes some additional topics (e.g., PN sequences) and some more advanced real-time DSP projects (e.g., higher-order digital communications projects such as QPSK and QAM for transmitters and receivers) that were requested by readers of the first edition. Third, we have incorporated all the valuable feedback and suggestions from many users of the first edition that has resulted in what we hope is an even better book.

Note that any errata, updates, additional software, and other pertinent material will be posted on the book’s web site maintained by the authors at http://rt-dsp.com. Since DSP hardware updates are made faster than we can publish a new addition of the book, this web site will provide a means for the authors to provide support even for selected new DSP boards that are introduced after this second edition is published. For your convenience, the QR code at the end of this preface will also take you to this web site. The publisher, CRC Press (part of the Taylor & Francis Group), also has a web page for this book. As of this writing, that URL is: http://www.crcpress.com/product/isbn/9780849373824.

However, the “Downloads” tab for that web page simply points to the appropriate page at http://rt-dsp.com.

2The acronym “DSK” stands for “DSP Starter Kit.” While the OMAP-L138 Experimenter Kit discussed in this book is not officially called a “DSK” by TI, we choose to simplify the discussion and often call both boards DSKs. Both of these boards can be purchased from authorized TI distributors or directly from TI (see dspvillage.ti.com). Note that significant academic discounts and donations from TI are available (go to www.ti.com/university).

PREFACE xxxiii The path from DSP theory to real-time implementation is filled with many potential potholes, roadblocks, and other impediments that have historically created that “gap” be-tween theory and practice. This book provides a proven method to smooth out the path, clear the obstacles, and avoid the usual frustrations to get you across the gap. We hope you enjoy the ride. . .

T.B.W., C.H.G.W., M.G.M.

Scan the QR code below to access http://rt-dsp.com.

MATLABis a trademark of The MathWorks, Inc. For product information, please contact:

The MathWorks, Inc.

3 Apple Hill Drive

Natick, MA 01760-2098 USA Tel: 508-647-7000

Fax: 508-647-7001

Email: [email protected] Web: www.mathworks.com

This page intentionally left blank This page intentionally left blank

Acknowledgments

T

HIS book would not have been possible without the support and assistance of Texas Instruments (TI), Inc. In particular, the authors would like to extend a sincere thank-you to Cathy Wicks, whose tireless efforts for TI’s University Program has helped make DSP affordable for countless students and professors. Cathy’s predecessors Christina Peterson, Maria Ho, and Torrence Robinson also contributed to our efforts that eventually resulted in this book. TI’s support of DSP education is unsurpassed in the industry, and the authors greatly appreciate such a forward-looking corporate vision.

We would also like to thank Nora Konopka, Jessica Vakili, and Jim McGovern of CRC Press (part of the Taylor & Francis Group), who helped guide this second edition project to completion. Their ready help, quick responses, and never-failing sense of humor should be the model to which other publishers aspire. Note that the manuscript was provided to the publisher fully formatted in “camera-ready” form, so any typos, if found, are the fault of the authors and not the publisher.

The authors would like to acknowledge Robert W. Conant for his valuable contributions to the chapter on QPSK digital receivers.

This book was certainly improved because of the input of both anonymous reviewers and the experiences of the many users of the first edition, who gave us valuable feedback and some excellent suggestions.

Our appreciation also extends to Debbie Rawlings as well as to Susan and Alan Czarnecki for the generous use of their waterfront vacation homes for some of our more productive

“geek-fests” during which key parts of this book were written.

We would be remiss if we omitted an acknowledgment related to the mechanics of writing the text: this book was typeset using LATEX, a wonderfully capable document preparation system developed by Leslie Lamport as a special version of Donald Knuth’s TEX program.

LATEX is ideally suited to technical writing, and is well supported by the worldwide members of the TEX Users Group (TUG); investigate http://www.tug.org/ for details. Both LATEX and TEX are freely available in the public domain (the name TEX is a trademark of the American Mathematical Society). We used the excellent WinEdt shareware editor (see http://www.winedt.com/) as a front-end to the free MikTeX distribution of LATEX (see http://www.miktex.org/). For maintaining our database of bibliographic references in the standard BibTEX syntax, we used the freely available and highly capable JabRef (see http://jabref.sourceforge.net/).

xxxv

This page intentionally left blank This page intentionally left blank

Section I: