Sunteți pe pagina 1din 8

REAL-TIME

DIGITAL SIGNAL
PROCESSING
from MATLAB to C with
the TMS320C6x DSK
Thad B. Welch
United States Naval Academy, Annapolis, Maryland
Cameron KG. Wright
University of Wyoming, Laramie, Wyoming
Michael G. Morrow
University of Wisconsin, Madison, Wisconsin
(CoC\ Taylor &. Francis
^ ^ J Taylor & Francis Group
Boca Raton London New York
A CRC title, part of the Taylor & Francis imprint, a member of the
Taylor & Francis Croup, the academic division of T&F Informa pic.
Contents
Preface xxxi
Acknowledgments xxxiii
Enduring Fundamentals 1
1 Introduction and Organization 3
1.1 Why Do You Need This Book? 3
1.1.1 Other DSP Books 3
1.1.2 Demos and DSP Hardware 4
1.1.3 Philosophy of This Book 4
1.2 Real-Time DSP 4
1.3 How to Use This Book 5
1.3.1 Transition to Real-Time 8
1.3.2 Chapter Coverage 8
1.3.3 Hardware and Software Installation 9
1.3.4 Reading Program Listings 9
1.4 Get Started 10
2 Sampling and Reconstruction 11
2.1 Theory 11
2.1.1 Choosing a Sampling Frequency 11
2.1.2 Input/Output Issues: Samples or Frames? 11
2.1.3 The Talk-Through Concept 12
2.2 winDSK6 Demonstration 12
2.2.1 Starting winDSK6 12
2.2.2 Talk-Thru Application 13
2.3 Talk-Through Using Windows 15
2.4 Talk-Through Using MATLAB and Windows 16
2.4.1 Talk-Through Using MATLAB Only 18
2.4.2 Talk-Through Using MATLAB 21
2.5 DSK Implementation in C 22
2.6 Follow-On Challenges 23
3 FIR Digital Filters 25
3.1 Theory 25
3.1.1 Traditional Notation 25
3.1.2 FIR Filters Compared to IIR Filters . . . 26
3.1.3 Calculating the Output of a Filter 26
xi
CONTENTS
3.2 winDSK6 Demonstration 28
3.2.1 Graphic Equalizer Application 29
3.2.2 Notch Filter Application 30
3.2.3 Audio Effects Application 32
3.3 MATLAB Implementation 33
3.3.1 Built-in Approach 33
3.3.2 Creating Your Own Filter Algorithm 37
3.4 DSK Implementation in C 39
3.4.1 Brute Force FIR Filtering in C: Part 1 39
3.4.2 Brute Force FIR Filtering in C: Part 2 41
3.4.3 Circular Buffered FIR Filtering 43
3.5 Follow-On Challenges 44
IIR Digital Filters 47
4.1 Theory 47
4.2 winDSK6 Demonstration: Notch Filter Application 50
4.3 MATLAB Implementation 53
4.3.1 Filter Design and Analysis 53
4.3.2 IIR Filter Notation 58
4.3.3 Block Diagrams 60
4.3.4 Built-in Approach 65
4.3.5 Creating Your Own Filter Algorithm ,. 65
4.4 DSK Implementation in C 68
4.4.1 Brute Force IIR Filtering 68
4.4.2 More Efficient IIR Filtering 70
4.5 Follow-On Challenges 70
Periodic Signal Generation 71
5.1 Theory 71
5.1.1 Periodic Signals in DSP 71
5.1.2 Signal Generation 72
5.2 winDSK6 Demonstration 79
5.2.1 Arbitrary Waveform . 80
5.2.2 DTMF 81
5.3 MATLAB Implementation 83
5.3.1 Direct Digital Synthesizer Technique 83
5.3.2 Table Lookup Technique 84
5.4 DSK Implementation in C : 84
5.4.1 Direct Digital Synthesizer Technique . 85
5.4.2 Table Lookup Technique 86
5.4.3 Table Lookup Technique with Table Creation 87
5.4.4 Digital Resonator Technique 89
5.5 Follow-On Challenges 90
Frame-Based DSP 91
6.1 Theory 91
6.1.1 Drawbacks of Sample-Based DSP 91
6.1.2 What Is a Frame? 92
6.2 winDSK6 Demonstration 93
6.3 MATLAB Implementation 95
6.4 DSK Implementation in C 95
CONTENTS xiii
6.4.1 Triple Buffering 95
6.4.2 A Frame-Based DSP Example 96
6.4.3 Using Direct Memory Access 101
6.5 Summary of Frame-Based Processing 109
6.6 Follow-On Challenges 110
7 Digital Filters Using Frames 111
7.1 Theory Il l
7.2 winDSK6 Demonstration Il l
7.3 MATLAB Implementation Il l
7.4 DSK Implementation in C Il l
7.4.1 Understanding the FIR Process for Frames 112
7.4.2 How to Avoid the "Edge" Problems 113
7.4.3 Explanation of the C Code 113
7.5 Follow-On Challenges 115
8 The Fast Fourier Transform 117
8.1 Theory 117
8.1.1 Defining the FFT 117
8.1.2 The Twiddle Factors 117
8.1.3 The FFT Process 118
8.1.4 Bit-Reversed Addressing 121
8.1.5 Using the FFT for Filtering 121
8.1.6 Avoiding Circular Convolution 122
8.1.7 Real-Time Fast Convolution 124
8.2 winDSK6 Demonstration 127
8.3 MATLAB Implementation 127
8.4 DSK Implementation in C 127
8.5 Follow-On Challenges 130
9 Spectral Analysis and Windowing 131
9.1 Theory 131
9.1.1 Power Spectrum of a Signal 131
9.1.2 The Need for Windowing 133
9.1.3 Window Characteristics 135
9.2 winDSK6 Demonstration 138
9.3 MATLAB Implementation 138
9.4 DSK Implementation in C 141
9.5 Conclusion 141
9.6 Follow-On Challenges '. 141
Projects 143
10 Project 1: Guitar Special Effects 145
10.1 Introduction to Projects 145
10.2 Theory 145
10.2.1 Background 145
10.2.2 How the Effects Work 146
10.3 winDSK6 Demonstration 158
10.4 MATLAB Implementation 158
10.4.1 FIR Comb Filter 158
xiv CONTENTS
10.4.2 IIR Comb Filter 159
10.4.3 Notch Filter 161
10.4.4 Flanger 162
10.4.5 Tremelo 163
10.5 DSK Implementation in C 164
10.5.1 Real-Time Comb Filters 164
10.5.2 Other Real-Time Special Effects 168
10.6 Follow-On Challenges 169
11 Project 2: Graphic Equalizer 171
11.1 Theory . . . .' 171
11.2 winDSK6 Demonstration 172
11.2.1 Graphic Equalizer Application 172
11.2.2 Effect of the Graphic Equalizer 172
11.3 MATLAB Implementation 174
11.4 DSK Implementation in C 176
11.4.1 Applying Gain to Filter Bands 176
11.4.2 GEL File Slider Control 179
11.5 Follow-On Challenges 181
12 Project 3: Peak Program Meter 183
12.1 Theory 183
12.2 winDSK6 Demonstration: commDSK 184
12.3 MATLAB Implementation 185
12.4 DSK Implementation in C 185
12.4.1 Example PPM Code 185
12.4.2 DSK LED Control 187
12.4.3 Another PPM Code Version 187
12.5 Follow-On Challenges 189
13 Project 4: AM Transmitter 191
13.1 Theory 191
13.2 winDSK6 Demonstration 194
13.3 MATLAB Implementation 194
13.4 DSK Implementation in C 196
13.5 Follow-On Challenges 198
14 Project 5: AM Receiver 199
14.1 Theory 199
14.1.1 Envelope Detector 200
14.1.2 The Hilbert-Based AM Receiver 206
14.2 winDSK6 Demonstration 209
14.3 MATLAB Implementation 209
14.4 DSK Implementation in C 211
14.5 Follow-On Challenges 213
15 Project 6: Phase-Locked Loop 215
15.1 Theory 215
15.2 winDSK6 Demonstration 216
15.3 MATLAB Implementation 216
15.3.1 PLL Simulation 216
CONTENTS xv
15.3.2 A Few Updates to the MATLAB Implementation 222
15.4 DSK Implementation in C 225
15.4.1 Components of the PLL 225
15.4.2 System Testing 228
15.5 Follow-On Challenges 228
16 Project 7: Digital Communications Transmitters 231
16.1 Theory 231
16.1.1 Random Data and Symbol Generation 231
16.1.2 BPSK Using Antipodal Rectangularly Shaped Bits 233
16.1.3 BPSK Using Impulse Modulated Raised-Cosine Shaped Bits . . . . 233
16.2 winDSK6 Demonstration 234
16.2.1 commDSK: Unfiltered BPSK 236
16.2.2 commDSK: Raised-Cosine Filtered BPSK 237
16.3 MATLAB Implementation 240
16.3.1 Rectangular Shaped BPSK Signal Generator 240
16.3.2 Impulse Modulated Raised-Cosine BPSK Signal Generator 242
16.4 DSK Implementation in C 245
16.4.1 A Rectangular Pulse Shaped BPSK Transmitter 246
16.4.2 A Raised-Cosine Pulse Shaped BPSK Transmitter 247
16.4.3 Summary of Real-Time Code 249
16.5 Follow-On Challenges 249
17 Project 8: Digital Communications Receivers 251
17.1 Theory : 251
17.1.1 The Output of the Matched Filter 253
17.1.2 The Eye-Pattern 254
17.1.3 Maximum Likelihood Timing Recovery 255
17.2 winDSK6 Demonstration 257
17.3 MATLAB Implementation 258
17.4 DSK Implementation in C 262
17.4.1 Components of the Digital Receiver 262
17.4.2 System Testing 266
17.5 Follow-On Challenges 268
Appendices 271
A Code Composer Studio: A Brief Tutorial 273
A.I Introduction 273
A.2 Starting Code Composer Studio 273
A.3 Needed Files 277
A.4 Creating a New Project 278
A.5 Opening Existing Projects 280
A.6 Adding Files to a Project 281
A.7 Project Options 284
A.8 Building the Project 285
A.9 Loading the Program on the DSK 287
A.10 Running the Program on, the DSK 290
A.ll Get to Know CCS 291
A.12 Typical Files for Our CCS Projects 291
xvi CONTENTS
B DSP/BIOS 295
B.I Introduction 295
B.I.I DSP/BIOS Major Features 295
B.1.2 DSP/BIOS Threads 295
B.2 Using the DSP/BIOS Scheduler 296
B.2.1 Adding a PRD Function 297
B.2.2 Adding a HWI Function 297
B.2.3 Adding a SWI Function 298
B.2.4 Adding a TSK Function 299
B.2.5 Real-Time Analysis Tools 299
B.3 A DSP/BIOS Talk-Through Application for the 6711 DSK 300
B.3.1 main.c 300
B.3.2 hwi.c 301
B.3.3 DSP/BIOS HWI Configuration 301
B.3.4 DSP/BIOS Serial Port Configuration 302
B.3.5 ' Source Code 302
B.4 Modification Needed for the Stereo Codecs 303
B.4.1 main.c 303
B.4.2 hwi.c 303
B.4.3 DSP/BIOS HWI Configuration 304
B.4.4 DSP/BIOS Serial Port Configuration 304
B.5 A DSP/BIOS Talk-Through Application for the 6713 DSK 305
B.5.1 main.c 305
B.5.2 hwi.c 306
B.5.3 DSP/BIOS HWI Configuration 306
B.5.4 DSP/BIOS Serial Port Configuration 307
B.5.5 Source Code 307
C Numeric Representations 311
C.I Endianness 311
C.2 Integer Representations 312
C.3 Integer Division and Rounding 313
C.4 Floating-Point Representations 314
C.5 Fixed-Point Representations 316
C.6 Summary of Numeric Representations 317
D TMS320C6x Architecture 319
D.I Computer Architecture Basics 319
D.I.I Instruction Set Architecture 320
D.1.2 Register Architectures 320
D.I.3 Memory Architectures 321
D.1.4 Fetch-Execute Model 322
D.I.5 Pipelining 322
D.I.6 Single- versus Multiple-Issue 325
D.I.7 Scheduling 325
D.2 TMS320C671x Architecture 326
D.2.1 Memory System 328
D.2.2 Pipeline and Scheduling 329
D.2.3 Peripherals 329
D.2.4 Host Port Interface : . 330
CONTENTS xvii
E Related Tools for DSKs 331
E.I Introduction 331
E.2 Windows Control Applications 331
E.2.1 The Basic Windows Control Application 332
E.2.2 Creating an Oscilloscope Application 333
E.2.3 Creating a Spectrum Analyzer Application 339
E.3 MATLAB Exports 339
E.3.1 Exporting Direct-Form II Implementations 340
E.3.2 Exporting Second Order Section Implementations 341
E.4 MATLAB Real-Time Interface 342
F Programming Perils and Pitfalls 343
F.I Debug versus Release Builds 343
F.2 The Volatile Keyword 343
F.3 Function Prototypes and Return Types 344
F.4 Arithmetic Issues 345
F.5 Controlling the Location of Variables in Memory 346
F.6 Real-Time Schedule Failures 347
G Abbreviations 349
References 355
Index 361

S-ar putea să vă placă și