0 ratings0% found this document useful (0 votes) 221 views125 pagesC Algorithms For Real-Time DSP
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Libeary of Congress Cataloging Publication Data
bree, asl M,
‘ ngorthne fr rel ie DSP/ Pal M. Eb
Includes iboprapticlefeence
ASBNO.13-597353-3
1 € (Computer program language) 2. Computer sletims. 3. Rest
neds pressing Tile
QATETSCISESS 195
621.382 2085524020 95.4077
ce
Acquistions eto: Karen Gets
(Cone desiner: ith Leeds Design
“Manofactrng buyer: Ales R Hoye
ComposiorPrataction sevice: Pie Tie Composition, ne.
© 1995 by Prentice Hall PTR
Preatie Hal Ie
BSS 1 Siren Sctter Company
‘Upper Sale River, New lacy 07458
Allright reserved. Nop ofthis bok my be eprodacd,
inary form ory any means, wa permsioe a Weng
from the pubis,
The publisher ofr scout on his book wie ordered in bulk quantities
For more information contact
(Cnporat Sales Deparment
Prem Hall PTR
(One Lake Suse
Upper Sule River, New ere 7458
Phos: 300-382-3419
Fae 201-236-7
mil: Corpses @ renal om
Pte in the Unie Sates of America
Wooe7eseaar
ISBN: 0-13-337353-3
Presi Hal! neato (UK) Limit, Landon
Premce Hall of Assia ry. Litt. Sry
rntice Hal Cn, ne, Toronto.
Prentice Hal Hipunoameicam SA. Mexico
Prentice Hal of Ida Private Limited, New Del
Prentice Hal of apa, ine, Tokyo
Simon & Schuster Asa PL, Singapore
Editors Pence Hal do Bail Ld, Rio de ano
CONTENTS
PREFACE vii
CHAPTER 1 DIGITAL SIGNAL PROCESSING FUNDAMENTALS 1
1.1 SEQUENCES 2
1.4.1 The Sampling Function 3
1.1.2 Samples Signal Spectra 4
1.1.3 Spectra of Continuous Time and Discrete Time Signals 5
1.2 LINEAR TIME-INVARIANT OPERATORS 8
1.2.1 Causality 10
1.22 Difference Equations 10
1.2.3 The z-Transform Description of Linear Operators 11
1.24 Frequency Domain Transfer Function of an Operator 14
1.25 Frequency Response from the z-Transform Description 15,
13 DIGITAL FILTERS 17
1.3.1 Finite Impulse Response (FIR) Filters 18
1.32 Infinite Impulse Response (IR) Filters 21
1.3.3 Examples of Filter Responses 22
134 Filter Specifications 23
14 DISCRETE FOURIER TRANSFORMS 25
14.1 Form 25
142 Properties 26
1.43 Power Spectrum 27wv Contents
1.44 Averaged Periodograms 28
4.5 The Fast Fourier Transform (FFT) 28
1.46 An Example of the FFT 30
1S NONLINEAR OPERATORS 32
LS. peLaw and A-Law Compression 33,
1.6 PROBABILITY AND RANDOM PROCESSES 35
1.6.1 Basic Probability 35
1.62 Random Variables 36
1.6.3 Mean, Variance, and Gaussian Random Variables 37
1.64 Quantization of Sequences 40
1.65 Random Processes, Autocorrelation, nd Spectral Density 42
1.6.6 Modeling Real-World Signals with AR Processes 43
1.7 ADAPTIVE FILTERS AND SYSTEMS 46
1.7.1 Wiener Filter Theory 48
1.7.2 LMS Algorithms 50
1.8 REFERENCES. 51
CHAPTER 2 _C PROGRAMMING FUNDAMENTALS 53
2.1 THE ELEMENTS OF REAL-TIME DSP PROGRAMMING 53
22 VARIABLES ANDDATA TYPES. 56
22.1 Types of Numbers 56
222 Amays 58
23 OPERATORS 59
2.3.1 Assigament Operators 59
2.3.2 Arithmetic and Bitwise Operators 60
2.3.3 Combined Operators 61
2.34 Logical Operators 61
2.38 Operator Precedence and Type Conversion 62
24 PROGRAM CONTROL 63
2.4.1 Conditional Execution; ££.
242 The switeh Statement 64
2.4.3 Single-Line Conditional Expressions 65
2.44 Loops:while, do-while, and for 66
2.4.5 Program Jumps: break, continue, and goto 67
28 FUNCTIONS 69
2.5.1 Defining and Declaring Functions 69
25.2 Storage Class, Privacy, und Scope 71
2.5.3 Function Prototypes 73
26 MACROS AND THE C PREPROCESSOR 74
26.1 Conditional Preprocessor Directives 74
2.62 Aliases and Macros 75
ee 63
Contents
2.7 POINTERS AND ARRAYS 77
24.41 Special Pointer Operators 77
2.7.2 Pointers and Dynamic Memory Allocation 78
2.73 Amays of Pointers 80
28 STRUCTURES 82
28.1 Declaring and Referencing Structures $2
2.82 Pointers to Structures 84
28.3 Complex Numbers 85
29 COMMON C PROGRAMMING PITFALLS 87
2.9.1 Amray Indexing 87
2.9.2 Failure to Pass-by-Address 87
2.9.3 Misusing Pointers 88
2.10 NUMERICAL C EXTENSIONS 90
2.10.1 Complex Data Types 90
2.102 eration Operators 91
2.11 COMMENTS ON PROGRAMMING STYLE. 92
2ALL Software Quality 93
2.112 Structured Programming 95
2.12 REFERENCES 97
CHAPTER 3 DSP MICROPROCESSORS
IN EMBEDDED SYSTEMS
3,1 TYPICAL FLOATING-POINT DIGITAL SIGNAL PROCESSORS 99
3.1 AT&T DSP32C and DSP3210._ 100
3.1.2 Analog Devices ADSP-210XX 104
3.1.3 Texas Instruments TMS320C3X and TMS320C40 108.
32 TYPICAL PROGRAMMING TOOLS FOR DSP. 111
3.2.1 Basic C Compiler Tools 111
3.2.2 Memory Map and Memory Bandwidth Considerations 113
3.2.3 Assembly Language Simulators and Emulators 114
33 ADVANCED C SOFTWARE TOOLS FOR DSP. 117
3.31 Source Level Debuggers 117
3.32 Assembly-C Language Interfaces 120
3.33 Numeric C Compilers 121
34 REAL-TIME SYSTEM DESIGN CONSIDERATIONS 124
3.4.1 Physical InpuOutput (Memory Mapped, Serial, Polled) 124
3.42 Interrupts and Interupt-Driven UO 125
3.4.3 Efficiency of Real-Time Compiled Code 128
3.44 Mulprocessor Architectures 130a Contents
CHAPTER 4 REAL-TIME FILTERING 132
4 REAL-TIME FIR ANDIIR FILTERS 132
“4.1.1 FIR Filter Funetion 134
4.1.2 FIR Filter Coefficient Caleulat
4.13 TIR Filter Function 145
4.14 Real-Time Filtering Example 151
42 FILTERING TO REMOVE NOISE _ 158
4.2.1 Gaussian Noise Generation 158
4.22 Signal-to-Noise Ratio Improvement 160
43 SAMPLE RATE CONVERSION 160
“4.3.1 FIR Interpolation 163
4.3.2 Real-Time Interpolation Followed by Decimation 163,
4.3.3 Real-Time Sample Rate Conversion 167
44 FAST FILTERING ALGORITHMS | 168
4.4.1 Fast Convolution Using FFT Methods 170
4.4.2 Interpolation Using the FFT 176
4.5 OSCILLATORS AND WAVEFORM SYNTHESIS. 178
4.5.1 IIR Filters as Oscillators 178
4.5.2 Table-Generated Waveforms 179
46 REFERENCES 184
136
CHAPTERS REAL-TIME DSP APPLICATIONS 186
5.1 FFT POWER SPECTRUM ESTIMATION 186
‘Sud Speech Spectrum Analysis 187
5.1.2 Doppler Radar Processing 190
52 PARAMETRIC SPECTRAL ESTIMATION 193
5.2.1 ARMA Modeling of Signals 193,
5.2.2 AR Frequency Estimation 198
53 SPEECH PROCESSING 200
‘5.3.1 Speech Compression 201
5.3.2 ADPCM (G72) 202
54 MUSIC PROCESSING 218
5.4.1 Equalization and Noise Removal 218
5.42 Pitch-Shifting 220
5.43 Music Synthesis 225
58 ADAPTIVE FILTER APPLICATIONS 228
55.5.1 LMS Signal Enhancement 228
5.5.2 Frequency Tracking with Noise 233
54 REFERENCES 237
APPENDIX—DSP FUNCTION LIBRARY AND PROGRAMS 238
INDEX 241
ose
PREFACE
Digital signal processing techniques have become the method of choice in signal process-
ing as digital computers have increased in speed, convenienee, and availablity. As
microprocessors have become less expensive and more powerful, the number of DSP ap-
plications which have become commonly available has exploded. Thus, some DSP
microprocessors can now be considered commodity products. Perhaps the most visible
high volume DSP applications are the so called “multimedia” applications in digital
audio, speech processing, digital video, and digital communications. In many cases, these
‘applications contain embedded digital signal processors where a host CPU works in @
loosely coupled way with one or more DSPs to control the signa flow or DSP algorithm
‘behavior at real-time rate. Unfortunately the development of signl processing algo
rithms for these specialized embedded DSPs is still difficult and often requires special-
ized traning in a parcular assembly language for the target DSP.
‘The tools for developing new DSP algorithms are slowly improving asthe need to
design new DSP applications more quickly becomes important, The C language is prov-
ing itself to bea valuable programming ool for real-ime computationally intensive soft
ware tasks. C has high-level language capabilites (such as structures, arrays, and fune-
tions) as well as low-level assembly language capabilities (such as bit manipulation,
direct hardware inpuvoutput, and mactos) which makes C_an ideal language {
bedded DSP. Most of the manufacturers of digital signal processing devices (such as
‘Texas Instruments, AT&T, Motorola, and Analog Devices) provide C compiles, simula-
tors, and emulators for their parts, These C compilers offer standard C language with ex-
tensions for DSP to allow for very efficient code to he generated. For example, an inline
assembly language capability is usually provided inorder to optimize the performance of
{ime citcal pars ofan application. Because the majority of the code is C, an application
can be transferred to another processor much more easily than an all assembly language
rogram.
‘This book is constructed in such a way that it will be most useful to the engineer
‘who is familiar with DSP and the C language, but who is not necessarily an expert in
both. All ofthe example programs in this book have been tested using standard C compil-Preface
cers im the UNIX and MS-DOS programming environments, In addition, the examples
have been compiled utilizing the real-time programing tools of specific real-time embed-
‘ded DSP microprocessors (Analog Devices’ ADSP-21020 and ADSP-21062; Texas
Instrument’s TMS320C30 and TMS320C40; and AT&T's DSP32C) and then tested with
real-time hardware using real world signals. All ofthe example programs presented in the
text are provided in souree code form on the IBM PC floppy disk included with the book.
‘The tent is divided into several sections. Chapters | and 2 cover the basic principles
of digital signal processing and C programming. Readers familiar with these topics may
‘wish to skip one or both chapters. Chapter 3 introduces the basic real-time DSP program-
‘ming techniques and typical programming environments which ae used with DSP micro-
processors. Chapter 4 covers the basic real-time filtering techniques which are the comer-
stone of one-dimensional real-time digital signal processing. Finally, several real-time
DSP applications are presented in Chapter 5, including speech compression, musi signal
processing, radar signal processing, and adaptive signal processing techniques.
‘The floppy disk included with this text contains C language source code forall of
the DSP programs discussed inthis book. The floppy disk has a high density format and
was written by MS-DOS. The appendix and the READ.ME files on the floppy disk pro-
Vide more information about how to compile and run the C programs. These programs
hhave been tested using Borland's TURBO C (version 3 and greater) as wel as Microsoft C
(versions 6 and greater) for the IBM PC. Real-time DSP platforms using the Analog
Devices ADSP-71020 and the ADSP-21062, the Texas Instruments TMS320C30, and the
AT&T DSP32C have been used extensively to test the real-time performance of the
algorithms.
ACKNOWLEDGMENTS:
| thank the following people for their generous help: Laura Meres for help in preparing
the electronic manuscript and the software for the DSP32C; the engineers at Analog
Devices (in particular Steve Cox, Mare Hoffman, and Hans Rempel) for thei review of
the manuscript as well as hardware and software support; Texas Instruments for hardware
and software support; Jim Bridges at Communication Automation & Control, Ine. and
Talal Itani at Domain Technologies, Tne.
Paul M. Embree
‘TRADEMARKS.
TBM and IBM PC are trademarks ofthe International Business Machines Corporation
‘MS-DOS and MircosoftC are trademarks ofthe Microsoft Corporation.
‘TURBOC is a trademark of Borland Intemational,
‘UNIX is a trademark of American Telephone and Telegraph Corporation.
DSP32C and DSP3210 are trademarks of American Telephone and Telegraph Corporation.
"TMS320C30, TMS320C31, and TMS320C40 are trademarks of Texas Instramedts Incorporated.
ADSP-21020, ADSP-21060, and ADSP-21062 are wademarks of Analog Devices Incorporated.
CHAPTER 1
annem
DIGITAL SIGNAL PROCESSING
FUNDAMENTALS
Digital signal processing begins with a digital signal which appears to the computer as a
sequence of digital values. Figure 1.1 shows an example ofa digital signal processing op-
ration or simple DSP system. There is an input sequence x(n), the operator Gand an
‘output sequence. y(n). A complete digital signal processing system may consist of many
operations on the same sequence as well as operations on the result of operations
Because digital sequences are processed, ll operators in DSP are discrete time operators
(8 opposed to continuous time operators employed by analog systems). Discrete time op-
erators may be classified as time-varying ot time-invariant and linear or nonlinear. Most
Of the operators described in this text will be time-invariant with the exception of adap-
tive filters which are discussed in Section 1.7. Linearity will be discussed in Section 1.2
‘nd several nonlinear operators will be introduced in Section 1.5.
Operators are applied 10 sequences in order to effect the following results;
(1) Extract parameters or features from the sequence,
(@) Produce a similar sequence with particular features enhanced or eliminated.
(@) Restore the sequence to some earlier state
(@) Encode or compress the sequence.
‘This chapter is divided into several sections. Section 1.1 deals with sequences of
‘numbers: where and how they originate, their spectra, and their relation to continuous
signals. Section 1.2 describes the common characteristics of linear time-invariant opera.
tors which are the most often used in DSP. Section 1.3 discusses the class of operators
called digital filters. Section 1.4 introduces the diserete Fourier transform (DFTS and
12 Digital Signal Processing Fundamentals Chap. 1
DPS Operation
an) x0)
22), 49),40) ep OL} 9, 110.10)
FIGURE 1.1. OSP operation
FFTs). Section 1.5 describes the properties of commonly used nonlinear operators
Section 1.6 covers basic probability theory and random processes and discusses theit ap-
plication o signal processing. Finally, Section 1.7 discusses the subject of adaptive digi-
tal filters.
1.1 SEQUENCES:
In order for the digital computer to manipulate a signal, the signal must have been sam-
pled at some interval. Figure 1.2 shows an example of a continuous function of time
‘which has been sampled at intervals of T seconds. The resulting set of numbers is called a
sequence. Ifthe continuous time funetion was x(t), then the samples would be a(n) for n,
‘an integer extending over some finite range of values. I is common practice to normalize
‘the sample interval to | and drop it from the equations. The sequence then becomes x(n).
‘Care must be taken, however, when calculating power or energy from the sequences. The
‘sample interval, including units of time, must be reinserted atthe appropriate points in the
power or energy calculations.
‘A sequence as a representation ofa continuous time signal has the following impor-
tant charactristies:
xo
oT 27 af af 67 er 77 ef oT
FIGURE 12 Sempling
nase
Sec. 1.1 Sequences 3
(1) The signals sampled. thas nite value at ony discrete points
(@) The signal is wuncated outside some finite length representing finite time interval,
(@) The signa is quantized. Ii limited to discrete steps in amplitude, where the step
size and, therefore, the accuracy (or signal fidelity) depends on how many steps are
available in the A/D converter and on the arithmetic precision (numberof bits) of
the digital signal processor or computer.
In order to understand the nature of the results that DSP operators produce, these
characteristics must be taken into account. The effect of sampling will be considered in
Section 1.1.1. Truncation will be considered in the section on the discrete Fourier trans-
{orm (Section 1.4) and quantization willbe discussed in Section 1.7.4
1.1.1 The Sampling Function
‘The sampling function is the key to traveling between the continuous time and discrete
time worlds. It is called by various names: the Dirac delta function, te sifting function,
the singularity function, and the sampling function among, them. It has the following
properties:
Property 1. [fo 8—dt= fo. aay
Property 2. [3r—e)ar=1. 2
In the equations above, tan be any real number.
‘To see how this function can be thought of as the ideal sampling function, first con-
sider the realizable sampling function, A(), illustrated in Figure 1.3 Its pulse width is one
lunit of time and its amplitude is one unit of amplitude. It clearly exhibits Property 2 of
the sampling function, When AQ) is multiplied by the function to be sampled, however,
the A() sampling function chooses not a single instant in time but range from —4 t0
+4 As a result, Property I of the sampling function is not met Instead the following in-
tegral would result:
[Lnoau-nar= fro a3)
This can be thought of asa kind of smearing ofthe sampling process across a band which
is related to the pulse width of A(). A beter approximation to the sampling function
would be a function (0) with @ narrower pulse width, As the pulse width is narrowed,
however, the amplitude must be increased. In the limit, the ideal sampling function must
have infinitely narrow pulse width so that it samples at a single instant in time, and infi-
nitely large amplitude so that the sampled signal stil contains the same finite energy.
Figure 12 illustrates the sampling process at sample intervals of 7. The resulting
time waveform can be written