Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 49 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
49
Dung lượng
558,82 KB
Nội dung
3 DSP Fundamentals and Implementation Considerations The derivation of discrete-time systems is based on the assumption that the signal and system parameters have infinite precision. However, most digital systems, filters, and algorithms are implemented on digital hardware with finite wordlength. Therefore DSP implementation with fixed-point hardware requires special attention because of the potential quantization and arithmetic errors, as well as the possibility of overflow. These effects must always be taken into consideration in DSP system design and implementation. This chapter presents some fundamental DSP concepts in time domain and practical considerations for the implementation of digital filters and algorithms on DSP hard- ware. Sections 3.1 and 3.2 briefly review basic time-domain DSP issues. Section 3.3 introduces probability and random processes, which are useful in analyzing the finite- precision effects in the latter half of the chapter and adaptive filtering in Chapter 8. The rigorous treatment of these subjects can be found in other DSP books listed in the reference. Readers who are familiar with these DSP fundamentals should be able to skip through some of these sections. However, most notations used throughout the book will be defined in this chapter. 3.1 Digital Signals and Systems In this section, we will define some widely used digital signals and simple DSP systems. The purpose of this section is to provide the necessary background for understanding the materials presented in subsequent sections and later chapters. 3.1.1 Elementary Digital Signals There are several ways to describe signals. For example, signals encountered in com- munications are classified as deterministic or random. Deterministic signals are used Real-Time DigitalSignal Processing. Sen M Kuo, Bob H Lee Copyright # 2001 John Wiley & Sons Ltd ISBNs: 0-470-84137-0 (Hardback); 0-470-84534-1 (Electronic) for testing purposes and for mathematically describing certain phenomena. Random signals are information-bearing signals such as speech. Some deterministic signals will be introduced in this section, while random signals will be discussed in Section 3.3. As discussed in Chapter 1, a digitalsignal is a sequence of numbers fxn, ÀI< n < Ig, where n is the time index. The unit-impulse sequence, with only one non-zero value at n 0, is defined as dn 1, n 0 0, n T 0, & 3:1:1 where dn is also called the Kronecker delta function. This unit-impulse sequence is very useful for testing and analyzing the characteristics of DSP systems, which will be discussed in Section 3.1.3. The unit-step sequence is defined as un 1, n ! 0 0, n < 0: & 3:1:2 This signal is very convenient for describing a causal (or right-sided) signal xn for n ! 0. Causal signals are the most commonly encountered signals in real-time DSP systems. Sinusoidal signals (sinusoids or sinewaves) are the most important sine (or cosine) signals that can be expressed in a simple mathematical formula. They are also good models for real-world signals. The analog sinewave can be expressed as xtA sinVt fA sin2pft f, 3:1:3 where A is the amplitude of the sinewave, V 2pf 3:1:4 is the frequency in radians per second (rad/s), f is the frequency in Hz, and f is the phase-shift (initial phase at origin t 0) in radians. When the analog sinewave defined in (3.1.3) is connected to the DSP system shown in Figure 1.1, the digitalsignal x(n) available for the DSP hardware is the causal sinusoidal signal xnA sinVnT f, n 0, 1, .,I A sinVnT fun A sin2pfnT fun, 3:1:5 where T is the sampling period in seconds. This causal sequence can also be expressed as xnA sin!n funA sin2pFn fun , 3:1:6 78 DSP FUNDAMENTALS AND IMPLEMENTATION CONSIDERATIONS where ! VT V f s 3:1:7 is the discrete-time frequency in radians per sample and F fT f f s 3:1:8 is the normalized frequency to its sampling frequency, f s , in cycles per sample. The fundamental difference between describing the frequency of analog and digital signals is summarized in Table 3.1. Analog signal sampling implies a mapping of an infinite range of real-world frequency variable f (or V) into a finite range of discrete- time frequency variable F (or !). The highest frequency in a digitalsignal is F 1=2 (or ! p) based on Shannon's sampling theorem defined in (1.2.3). Therefore the spectrum of discrete-time (digital) signals is restricted to a limited range as shown in Table 3.1. Note that some DSP books define the normalized frequency as F f f s =2 with frequency range À1 F 1. Example 3.1: Generate 64 samples of a sine signal with A 2, f 1000 Hz, and f s 8 kHzusing MATLAB. Since F f =f s 0:125, we have ! 2pF 0:25p. From Equation (3.1.6), we need to generate xn2 sin!n), for n 0, 1, ., 63. These sinewave samples can be generated and plotted by the following MATLAB script: n [0:63]; omega 0.25*pi; xn 2*sin(omega*n); plot(n, xn); 3.1.2 Block Diagram Representation of Digital Systems A DSP system (or algorithm) performs prescribed operations on digital signals. In some applications, we view a DSP system as an operation performed on an input signal, x(n), in order to produce an output signal, y(n), and express the general relationship between x(n) and y(n)as Table 3.1 Units, relationships, and range of four frequency variables Variables Unit Relationship Range V radians per second V 2pf ÀI < V < I f cycles per second (Hz) f F T ÀI < f < I ! radians per sample ! 2pF Àp ! p F cycles per sample F f f s À 1 2 F 1 2 DIGITAL SIGNALS AND SYSTEMS 79 ynTxn, 3:1:9 where T denotes the computational process for transforming the input signal, x(n), into the output signal, y(n). A block diagram of the DSP system defined in (3.1.9) is illustrated in Figure 3.1. The processing of digital signals can be described in terms of combinations of certain fundamental operations on signals. These operations include addition (or subtraction), multiplication, and time shift (or delay). A DSP system consists of the interconnection of three basic elements ± adders, multipliers, and delay units. Two signals, x 1 n and x 2 n, can be added as illustrated in Figure 3.2, where ynx 1 nx 2 n3:1:10 is the adder output. With more than two inputs, the adder could be drawn as a multi- input adder, but the additions are typically done two inputs at a time in digital hard- ware. The addition operation of Equation (3.1.10) can be implemented as the following C55x code using direct addressing mode: mov @x1n, AC0 ; AC0 x1(n) add @x2n, AC0 ; AC0 x1(n)x2(n) y(n) A given signal can be multiplied by a constant, a, as illustrated in Figure 3.3, where x(n) is the multiplier input, a represents the multiplier coefficient, and ynaxn3:1:11 x(n) DSP system T [ ] y(n) = T [x(n)] Figure 3.1 Block diagram of a DSP system x 1 (n) x 1 (n) x 2 (n) y(n) x 2 (n) y(n) + + Σ or Figure 3.2 Block diagram of an adder x(n) y(n) a or x(n) y(n) a Figure 3.3 Block diagram of a multiplier 80 DSP FUNDAMENTALS AND IMPLEMENTATION CONSIDERATIONS x(n) y(n) = x(n−1) z −1 Figure 3.4 Block diagram of a unit delay is the multiplier's output. The multiply operation of equation (3.1.11) can be imple- mented by the following C55x code using indirect addressing mode: amov #alpha, XAR1 ; AR1 points to alpha () amov #xn, XAR2 ; AR2 points to x(n) mpy *AR1, *AR2, AC0 ; AC0 *x(n) y(n) The sequence {xn} can be shifted (delayed) in time by one sampling period, T,as illustrated in Figure 3.4. The box labeled z À1 represents the unit delay, x(n) is the input signal, and ynxn À 13:1:12 is the output signal, which is the input signal delayed by one unit (a sampling period). In fact, the signal xn À 1 is actually the stored signal x(n) one sampling period (T seconds) before the current time. Therefore the delay unit is very easy to implement in a digital system, but is difficult to implement in an analog system. A delay by more than one unit can be implemented by cascading several delay units in a row. Therefore an L-unit delay requires L memory locations configured as a first-in first-out buffer, which can also be implemented as a circular buffer (will be discussed in Chapter 5) in memory. There are several ways to implement delay operations on the TMS320C55x. The following code uses a delay instruction to move the contents of the addressed data memory location into the next higher address location: amov #xn, XAR1 ; AR1 points to x(n) delay *AR1 ; Contents of x(n)is copied to x(nÀ1) These three basic building blocks can be connected to form a block diagram repre- sentation of a DSP system. The input±output (I/O) description of a DSP system consists of mathematical expressions with addition, multiplication, and delays, which explicitly define the relationship between the input and output signals. DSP algorithms are closely related to block diagram realizations of the I/O difference equations. For example, consider a simple DSP system described by the difference equation ynaxnaxn À 1: 3:1:13 The block diagram of the system using the three basic building blocks is sketched in Figure 3.5(a). Note that the difference equation (3.1.13) and the block diagram show exactly how the output signal y(n) is computed in the DSP system for a given input signal, x(n). The DSP algorithm shown in Figure 3.5(a) requires two multiplications and one addition to compute the output sample y(n). A simple algebraic simplification may DIGITAL SIGNALS AND SYSTEMS 81 y(n) Σ + + a a (a) y(n) Σ + + a x(n) x(n−1) x(n) x(n−1) z −1 z −1 (b) Figure 3.5 Block diagrams of DSP systems: (a) direct realization described in (3.1.13), and (b) simplified implementation given in (3.1.14) be used to reduce computational requirements. For example, (3.1.13) can be rewritten as ynaxnxn À 1: 3:1:14 The block diagram implementation of this difference equation is illustrated in Figure 3.5(b), where only one multiplication is required. This example shows that with careful design (or optimization), the complexity of the system (or algorithm) can be further reduced. The C55x implementation of (3.1.14) can be written as: amov #alpha, XAR1 ; AR1 points to amov #temp, XAR2 ; AR2 points to temp mov *(x1n), AC0 ; AC0 x1(n) add *(x2n), AC0 ; AC0 x1(n)x2(n) mov AC0, *AR2 ; Temp x1(n)x2(n), pointedby AR2 mpy *AR1, *AR2, AC1 ; AC1 à [x1(n)x2(n)] Equation (3.1.14) can also be implemented as: amov #x1n, XAR1 ; AR1 points to x1(n) amov #x2n, XAR2 ; AR2 points to x2(n) amov #alpha, XAR3 ; AR3 points to mpy *AR1, *AR3, AC1 ; AC1 à x1(n) mac *AR2, *AR3, AC1 ; AC1 à x1(n) à x2(n) When the multiplier coefficient a is a number with a base of 2 such as 0.25 (1/4), we can use shift operation instead of multiplication. The following example uses the absolute addressing mode: mov *(x1n)(#-2, AC0 ; AC0 0.25*x1(n) add *(x2n)(#-2, AC0 ; AC0 0.25*x1(n) 0.25*x2(n) where the right shift option, (#-2, shifts the content of x1n and x2n to the right by 2 bits (equivalent to dividing it by 4) before they are used. 82 DSP FUNDAMENTALS AND IMPLEMENTATION CONSIDERATIONS 3.1.3 Impulse Response of Digital Systems If the input signal to the DSP system is the unit-impulse sequence dn defined in (3.1.1), then the output signal, h(n), is called the impulse response of the system. The impulse response plays a very important role in the study of DSP systems. For example, consider a digital system with the I/O equation ynb 0 xnb 1 xn À 1b 2 xn À 2: 3:1:15 The impulse response of the system can be obtained by applying the unit-impulse sequence dn to the input of the system. The outputs are the impulse response coeffi- cients computed as follows: h0y0b 0 Á 1 b 1 Á 0 b 2 Á 0 b 0 h1y1b 0 Á 0 b 1 Á 1 b 2 Á 0 b 1 h2y2b 0 Á 0 b 1 Á 0 b 2 Á 1 b 2 h3y3b 0 Á 0 b 1 Á 0 b 2 Á 0 0 . Therefore the impulse response of the system defined in (3.1.15) is fb 0 , b 1 , b 2 ,0,0, .g. The I/O equation given in (3.1.15) can be generalized as the difference equation with L parameters, expressed as ynb 0 xnb 1 xn À 1ÁÁÁb LÀ1 xn À L 1 LÀ1 l0 b l xn À l : 3:1:16 Substituting xndn into (3.1.16), the output is the impulse response expressed as À 1 hn LÀ1 l0 b l dn À l b n n =0,1, ., L 0 otherwise. & 3:1:17 Therefore the length of the impulse response is L for the difference equation defined in (3.1.16). Such a system is called a finite impulse response (FIR) system (or filter). The impulse response coefficients, b l , l 0, 1, ., L À 1, are called filter coefficients (weights or taps). The FIR filter coefficients are identical to the impulse response coefficients. Table 3.2 shows the relationship of the FIR filter impulse response h(n) and its coefficients b l . 3.2 Introduction to Digital Filters As shown in (3.1.17), the system described in (3.1.16) has a finite number of non-zero impulse response coefficients b l , l 0, 1, ., L À 1. The signal-flow diagram of the INTRODUCTION TO DIGITAL FILTERS 83 Table 3.2 Relationship of impulse response and coefficients of an FIR filter b l b 0 b 1 b 2 . b LÀ1 nxn xn À 1 xn À 2 . xn À L 1 ynhn 01 0 0 . 0 h0b 0 10 1 0 . 0 h1b 1 20 0 1 . 0 h2b 2 . . . . . . . L À 10 0 0 . 1 hL À 1b LÀ1 L 00 0 . 00 y(n) Σ + + z −1 z −1 b 1 b 0 x(n) x(n−1) + x(n−L+1) b L−1 Figure 3.6 Detailed signal-flow diagram of FIR filter system described by the I/O Equation (3.1.16) is illustrated in Figure 3.6. The string of z À1 functions is called a tapped-delay-line, as each z À1 corresponds to a delay of one sampling period. The parameter, L, is the order (length) of the FIR filter. The design and implementation of FIR filters (transversal filters) will be discussed in Chapter 5. 3.2.1 FIRFilters and Power Estimators The moving (running) average filter is a simple example of an FIR filter. Averaging is used whenever data fluctuates and must be smoothed prior to interpretation. Consider an L-point moving-average filter defined as yn 1 L xnxn À 1ÁÁÁxn À L 1 1 L LÀ1 l0 xn À l, 3:2:1 where each output signal yn is the average of L consecutive input signal samples. The summation operation that adds all samples of xn between 1 and L can be implemented using the MATLAB statement: yn sum(xn(1:L)); 84 DSP FUNDAMENTALS AND IMPLEMENTATION CONSIDERATIONS Implementation of (3.2.1) requires L À 1 additions and L memory locations for storing signal sequence xn, xn À 1, ., xn À L 1 in a memory buffer. As illus- trated in Figure 3.7, the signal samples used to compute the output signal at time n are L samples included in the window at time n. These samples are almost the same as those samples used for the previous window at time n À 1 to compute yn À 1, except that the oldest sample xn À L of the window at time n À 1 is replaced by the newest sample xn of the window at time n. Thus (3.2.1) can be computed as ynyn À 1 1 L xnÀxn À L: 3:2:2 Therefore the averaged signal, yn, can be computed recursively as expressed in (3.2.2). This recursive equation can be realized by using only two additions. However, we need L 1 memory locations for keeping L 1 signal samples fxnxn À 1ÁÁÁxn À Lg. The following C5xx assembly code illustrates the implementation of a moving- average filter of L 8 based on Equation (3.2.2): L .set 8 ; Order of filter xin .usect "indata", 1 xbuffer .usect "indata", L ; Length of buffer y .usect "outdata", 2,1,1 ; Long-word format amov #xbufferLÀ1, XAR3 ; AR3 points to endof x buffer amov #xbufferLÀ2, XAR2 ; AR2 points to next sample mov dbl(*(y)), AC1 ; AC1 y(nÀ1)in long format mov *(xin), AC0 ; AC0 x(n) sub *AR3, AC0 ; AC0 x(n) À x(n±L) add AC0, #-3, AC1 ; AC1 y(n±1) 1/L[x(n)±x(n±L)] mov AC1, dbl(*(y)) ; y(n) AC1 rpt # (LÀ1) ; Update the tapped-delay-line mov *AR2À, *AR3À ; X(n±1) x(n) mov *(xin), AC0 ; Update the newest sample x(n) mov AC0, *AR3 ; X(n) input xin The strength of a digitalsignal may be expressed in terms of peak value, energy, and power. The peak value of deterministic signals is the maximum absolute value of the signal. That is, M x max n fjxnjg: 3:2:3 Window at time n n−L Time n−1 n−L+1 n Window at time n−1 Figure 3.7 Time windows at current time n and previous time n À 1 INTRODUCTION TO DIGITAL FILTERS 85 The maximum value of the array xn can be found using the MATLAB function Mx max(xn); The energy of the signal xn is defined as E x n jxnj 2 : 3:2:4 The energy of a real-valued xn can be calculated by the MATLAB statement: Ex sum(abs(xn).^ 2); Periodic signals and random processes have infinite energy. For such signals, an appropriate definition of strength is power. The power of signal xn is defined as P x lim L3I 1 L LÀ1 n0 jxnj 2 : 3:2:5 If xn is a periodic signal, we have xnxn kL, 3:2:6 where k is an integer and L is the period in samples. Any one period of L samples completely defines a periodic signal. From Figure 3.7, the power of xn can be computed by P x 1 L n lnÀL1 jxlj 2 1 L LÀ1 l0 jxn À lj 2 : 3:2:7 For example, a real-valued sinewave of amplitude A defined in (3.1.6) has the power P x 0:5A 2 . In most real-time applications, the power estimate of real-valued signals at time n can be expressed as ^ P x n 1 L LÀ1 l0 x 2 n À l: 3:2:8 Note that this power estimate uses L samples from the most recent sample at time n back to the oldest sample at time nÀ L 1, as shown in Figure 3.7. Following the derivation of (3.2.2), we have the recursive power estimator ^ P x n ^ P x n À 1 1 L x 2 nÀx 2 n À L: 3:2:9 86 DSP FUNDAMENTALS AND IMPLEMENTATION CONSIDERATIONS [...]... in Figure 1.2 converts a given analog signal x(t) into digital form x(n) The input signal is first sampled to obtain the discrete -time signal x(nT) Each x(nT) value is then encoded using B-bit wordlength to obtain the digital signal x(n), which consists of M magnitude bits and one sign-bit as shown in Figure 3.11 As discussed in Section 3.4, we assume that the signal x(n) is scaled such that À1 x n... Procedure for Real- Time Applications The digital filters and algorithms can be implemented on a DSP chip such as the TMS320C55x following a four-stage procedure to minimize the amount of time spent on finite wordlength analysis and real- time debugging Figure 3.17 shows a flowchart of this procedure In the first stage, algorithm design and study is performed on a general-purpose computer in a non -real- time environment... simulator Real- time testing in target system End Figure 3.17 Implementation procedure for real- time DSP applications x(n) Ideal system Practical system Figure 3.18 + ∑ e(n) − An efficient technique to study finite wordlength effects The final stage downloads the compiled (or assembled) and linked program into the target hardware (such as EVM) and brings it to a real- time operation Thus the realtime debugging... quantization levels The signal value above this line will be assigned to the higher quantization level, while the signal value below this line is assigned to the lower level For example, the 99 QUANTIZATION ERRORS Quantization level x(t) 011 ∆/2 ∆ 010 e(n) 001 000 T 0 Time, t 2T Figure 3.12 Quantization process related to ADC discrete -time signal x(T) is rounded to 010, since the real value is below the... linear process that introduces an additive noise e(n) to the discrete -time signal x(nT) as illustrated in Figure 3.13 Note that this model is not accurate for lowamplitude slowly varying signals For an arbitrary signal with fine quantization (B is large), the quantization error e(n) may be assumed to be uncorrelated with the digital signal x(n), and can be assumed to  à be random noise that is uniformly... Refer to the program listed in Table 3.6 Write a C function called exp3b.c to simulate 16, 12, 8, and 4 bits A/D converters (or copy the file exp3b.c from the software package) Use the digitized speech file timit1.asc (included in the software package) as the input signal for the experiment Create the project exp3b, add exp3b.c and exp3.cmd into the project 2 Use CCS probe points to connect disk files... three multiplications and only two memory locations for xn and pxn For stationary signals, a larger L (longer window) or smaller a can be used for obtaining a better average However, a smaller L (shorter window) should be used for non-stationary signals for better results In many real- time applications, the square of signal x2 n used in (3.2.10) and (3.2.11a) can be replaced with its absolute value... converters 3.8.2 Experiment 3B ± Quantization of Speech Signals There are many practical applications from cellular phones to MP3 players that process speech (audio) signals using DSP To understand the quantization effects of speech signals, we use a digitized speech file, timit1.asc, as the input for this experiment An experiment code for this experiment, exp3b.c, is listed in Table 3.6 1 Refer to the program... h kx n À k: 3:2:14 k0 Thus the output signal y n of a causal system at time n depends only on present and past input signals, and does not depend on future input signals Consider a causal system that has a finite impulse response of length L That is, @ h n 0, bn , 0 n . are classified as deterministic or random. Deterministic signals are used Real- Time Digital Signal Processing. Sen M Kuo, Bob H Lee Copyright # 2001 John. of the signal. That is, M x max n fjxnjg: 3:2:3 Window at time n n−L Time n−1 n−L+1 n Window at time n−1 Figure 3.7 Time windows at current time n