Fixed Point Effects in Digital Filters

Fixed Point Effects in Digital Filters Cimarron Mittelsteadt David Hwang Finite-precision Problems  Quantizers are nonlinear devices     Char...
5 downloads 1 Views 388KB Size
Fixed Point Effects in Digital Filters Cimarron Mittelsteadt David Hwang

Finite-precision Problems 

Quantizers are nonlinear devices 

  

Characteristics may be significantly different from the ideal linear filter

Overflow Coefficient quantization Limit-Cycle Oscillations

1

Quantizers 



Nonlinear effects make it extremely difficult to precisely analyze the filter’s performance. How do we model a fixed-point filter then? 



Adopt a statistical model of the quantization effects Results in a linear model for the filter

Statistical Characterization v(n) = Q[av(n-1)]+x(n)

x(n)

v(n)

Q[av(n-1)] = av(n-1)+e(n) v(n) = av(n-1)+x(n)+e(n) 

We can now view the response of the filter as coming from two inputs.

a

e(n)

2

Basic Assumptions 

The noise source is stationary white noise. 





The sequence e(n) is uncorrelated with the sequence e(m) for n≠m. Sequence is mean ergodic and correlation ergodic.

The error sequence e(n) is uncorrelated with the input sequence x(n).

Mean 

The mean of the output generated by the filter with impulse response h(n) when excited by e(n) is mq = me



h ( n)

n =−∞

equivalently put mq = me H (0)

3

Autocorrelation The autocorrelation is computed to be γ qq (n) =





h(k )h(l )γ ee ( k − l + n)

k = −∞ l = −∞

This reduces to σ q2 = σ e2



h 2 (k )

k = −∞

σ2

2 By Parseval’s theorem σ q = 2πe

π −π

2

H (ω ) dω

Types of Quantization b fractional bits Rounding

me = 0

σ e2 =

2 −2b 12



Truncation

2 −b me = − 2

σ e2 =

2 −2b 12



Magnitude Truncation

me = 0

2 −2b σ = 3



2 e

4

Section Ordering is Important 

Example H ( z ) = H1 ( z ) H 2 ( z )

Where H1 ( z ) =

1 1− z 1 2

−1

H 2 ( z) =

1 1 − 14 z −1

and their corresponding impulse responses are given by h(n), h1(n) and h2(n)

Realization 1 x(n)

v(n)

½ e1(n)

¼ e2(n)

With rounding ∞ é∞ ù σ q21 = σ e2 ê h 2 (n) + h22 (n) ≈ 2.90σ e2 ë n =0 n =0

5

Realization 2 x(n)

v(n)

¼ e1(n)

½ e2(n)

With rounding ∞ é∞ ù σ q22 = σ e2 ê h 2 (n) + h12 (n) ≈ 3.16σ e2 ë n =0 n =0

Section Ordering Comparison 

The overall noises were found to be σ q21 ≈ 2.90σ e2 σ q22 ≈ 3.16σ e2



σ q22 ≈ 1.09 σ q21

Thus, the second realization leads to 9% more noise power than the first.

6

Overflow 

Wrap Around



Ex. 7 (0111) + 1 (0001) = -8 (1000)

Saturation Ex. 5 (0101) + 4 (0100) = 7 (0111)





Scaling to Prevent Overflow 

Pessimistic Scaling

Ax
.2031250 (00011010 two’s complement)



Lesson: Over-design the filter and/or use an optimization algorithm to meet the spec

Frequency Response Floating Point -Passband Ripple: .003 dB -Stopband Attenuation: 48 dB

Fixed Point -Passband Ripple: .14 dB -Stopband Attenuation: 36 dB Fixed Point Passband

Floating Point Passband 0.2 Magnitude Response (dB)

Magnitude Response (dB)

0.2

0.1

0

−0.1

−0.2

0

−0.1

−0.2

0

0.05

0.1 0.15 Normalized frequency (Nyquist == 1)

0.2

0.25

Floating Point Stopband Magnitude Response (dB)

−50 −60 −70 −80 −90 0.55

0.6

0.65 0.7 0.75 0.8 0.85 Normalized frequency (Nyquist == 1)

0.05

0.1 0.15 Normalized frequency (Nyquist == 1)

0.2

0.25

−30

−40

−100 0.5

0

Fixed Point Stopband

−30 Magnitude Response (dB)

0.1

0.9

0.95

1

−40 −50 −60 −70 −80 −90 −100 0.5

0.55

0.6

0.65 0.7 0.75 0.8 0.85 Normalized frequency (Nyquist == 1)

0.9

0.95

1

Coefficient Quantization => Frequency Response Degradation

9

Internal Wordlength Quantization 

Quantization of internal wordlength leads to finite-wordlength effects

x(n)

Z-1

Z-1

1) Dynamic Range

Z-1

2) Signal-to-Noise Ratio Q

Q

Q

3) Limit Cycles

Q y(n)

internal wordlength b

Dynamic Range Constraints 

Dynamic Range is defined as: | range of representable numbers | 20 log10

| smallest non-zero representable number |

 The larger the dynamic range specification, the larger internal wordlength b required  Ex. b-bit number (x0. x1 x2 x3 x4….xb-1)  DR: 20 log |2 – 2-(b-1)| / | 2-(b-1) | = 20 log (2-b – 1) ~ 6 dB / bit

10

Dynamic Range (cont’d)   

b = 8 => DR ~ 48 dB b = 12 => DR ~ 72 dB b = 16 => DR ~ 96 dB

Nowadays, most hi-fi audio systems have a DR in the range of 80-100 dB

Signal-to-Noise Ratio 

The signal-to-noise ratio is defined as: = 10 log10 signal power / noise power SNR = 10 log10 σx2=/= σe2=



For our system (wordlength b): = 10 log10 σx2=/=(2-(b-1)/12) SNR = 10 log10 σx2=+ 6.02b + 4.77



Ex.

x(n) = .75 sin (ωn) => SNR = 6.02b - .739 b = 8 => SNR = 47 dB

11

Signal-to-Noise Ratio (cont’d)  



Thus, SNR increases by ~ 6 dB / bit To maximize SNR, you want to scale the signal x(n) as large as possible (to increase σx2 ) However, there is a tradeoff—you need to keep all internal signals small enough to prevent overflow / saturation (use normalization and scaling techniques)

Limit Cycles 





Limit cycles occur when the output of a digital filter does not decay to zero when the input goes to zero Limit cycles occur only in IIR filters and never occur in FIR filters They are caused by quantizing the data after a feedback multiplier in a recursive loop

12

Limit-Cycle Example x(n)



let M = -.96, y(-1) = 14, x(n) = 0 and rounding to the nearest integer

y(n)

b Z-1 Q

M

2b

b

n

-.96 * y(n-1)

y(n)

0

-13.44

-13

1

12.48

12

2

-11.52

-12

3

11.52

12

=> Limit cycle puts energy at Fs/2 which is detrimental

Limit Cycles in Matlab Limit cycle of .125 …

Output of the system 1

Input to the system 1

0.5 0.5

0 0

−0.5

−0.5

−1

100

200

300

400

500

600

700

800

900

1000

−1

100

200

300

400

Input FFT

500

600

700

800

900

1000

Output FFT

60

100

50

80 40 30

60

20

40

10

20 0

0

200

400

600

800

1000

1200

0

INPUT

0

200

400

600

800

1000

1200

OUTPUT …causes a spike at DC

13

Eliminating Limit Cycles 



 

Use magnitude truncation (which always decreases the energy of the signal) Use a filter for which a Lyapunov function exists Use controlled rounding Use novel filter structures designed to eliminate limit cycles

References 





J. Proakis and D. Manolakis. Digital Signal Processing: Principles, Algorithms, and Applications. 3rd Edition. Prentice Hall, Upper Saddle River, New Jersey, 1996. M. Werter. EE 212A Lecture Notes. Los Angeles, California, 1998. R. Schafer. MEAD DSP IC Design Course, Lecture #3, Quantization Effects in Digital Filters. Atlanta, Georgia.

14