Anda di halaman 1dari 30

DSP-CIS

Chapter-6: Filter Implementation


Marc Moonen
Dept. E.E./ESAT, KU Leuven
marc.moonen@esat.kuleuven.be
www.esat.kuleuven.be/scd/

Filter Design/Realization
Step-1 : define filter specs
(pass-band, stop-band, optimization criterion,)

Step-2 : derive optimal transfer function


FIR or IIR design

Chapter-4

Step-3 : filter realization (block scheme/flow graph)


direct form realizations, lattice realizations, Chapter-5

Step-4 : filter implementation (software/hardware)


finite word-length issues,
question: implemented filter = designed filter ?
You cant always get what you want -Jagger/Richards (?)
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

Chapter-6
p. 2

Chapter-6 : Filter Implementation

Introduction
Filter implementation & finite wordlength problem

Coefficient Quantization
Arithmetic Operations
Scaling
Quantization noise
Limit Cycles

Orthogonal Filters
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 3

Introduction
Filter implementation & finite word-length problem :
So far have assumed that signals/coefficients/arithmetic
operations are represented/performed with infinite precision.
In practice, numbers can be represented only to a finite
precision, and hence signals/coefficients/arithmetic
operations are subject to quantization
(truncation/rounding/...) errors.
Investigate impact of
- quantization of filter coefficients
- quantization (& overflow) in arithmetic operations
PS: Chapter partly adopted from
`A course in digital signal processing, B.Porat, Wiley 1997
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 4

Introduction
Filter implementation & finite word-length problem :
We consider fixed-point filter implementations, with a
`short word-length.
In hardware design, with tight speed requirements, finite
word-length problem is a relevant problem.
In signal processors with a `sufficiently long word-length,
e.g. with 16 bits (=4 decimal digits) or 24 bits (=7 decimal
digits) precision, or with floating-point representations and
arithmetic, finite word-length issues are less relevant.
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 5

Introduction

Back to Chapter-5

Q:Why bother
about many different realizations
for one and the same filter?

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 6

Introduction: Example

% IIR Elliptic Lowpass filter designed using


% ELLIP function.
% All frequency values are in Hz.
Fs = 48000; % Sampling Frequency
L = 8;
% Order
Fpass = 9600; % Passband Frequency
Apass = 60;
% Passband Ripple (dB)
Astop = 160; % Stopband Attenuation (dB)

Transfer function

Poles & zeros


DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 7

Introduction: Example
Filter outputs
Direct form realization
@ infinite precision

Lattice-ladder realization
@ infinite precision

Difference

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 8

Introduction: Example
Filter outputs
Direct form realization
@ infinite precision

Direct form realization


@ 10-bit precision

Difference

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 9

Introduction: Example
Filter outputs
Direct form realization
@ infinite precision

Direct form realization


@ 8-bit precision

Difference

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 10

Introduction: Example
Filter outputs
Direct form realization
@ infinite precision

Lattice-ladder realization
@ 8-bit precision

Difference

Better select a good


DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 11

Coefficient Quantization
The coefficient quantization problem :
Filter design in Matlab (e.g.) provides filter coefficients to
15 decimal digits (such that filter meets specifications)
For implementation, have to quantize coefficients to the
word-length used for the implementation.
As a result, implemented filter may fail to meet
specifications ??

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 12

Coefficient Quantization
Coefficient quantization effect on pole locations :
example : 2nd-order system (e.g. for cascade/direct form realization)
1 i .z 1 i .z 2
H i ( z)
1 i .z 1 i .z 2

`triangle of stability : denominator polynomial is stable (i.e.


roots inside unit circle) iff coefficients lie inside triangle

1
-2

-1

Proof: Apply Schur-Cohn stability test (see Chapter-5).


DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 13

Coefficient Quantization
example (continued) :
with 5 bits per coefficient, all possible `quantized pole positions are...
for i 2 : 0.1250 : 2
for i 1 : 0.0625 : 1
plot(poles)
end
end

(if stable)

1.5
1
0.5
0
-0.5
-1
-1.5
-1.5

-1

-0.5

0.5

1.5

Low density of `quantized pole locations at z=1, z=-1,


hence problem for narrow-band LP and HP filters (see Chapter-4).
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 14

Coefficient Quantization
example (continued) :
possible remedy: `coupled realization
poles are j. where 1 , 1 are realized/quantized
hence quantized pole locations are (5 bits)

u[k]

+
+

1.5
1

0.5
0

y[k]

-0.5

coefficient precision = pole precision

-1
-1.5
-1.5

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

-1

-0.5

0.5

1.5

p. 15

Coefficient Quantization
Coefficient quantization effect on pole locations :
example : higher-order systems (first-order analysis)
polynomial : 1 a1.z1 a2 .z2 ... aL .z L
roots are : p1, p2 ,..., pL
1.z1 a
2 .z2 ... a
L .z L
`quantized' polynomial: 1 a
1, p
2 ,..., p
L
`quantized' roots are: p
L

plLi
l pl
i ai )
p
.( a
(
p

p
)
i1
l
j
jl

tightly spaced poles (e.g. for narrow band filters) imply


high sensitivity of pole locations to coefficient quantization
hence preference for low-order systems (e.g. in parallel/cascade)
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 16

Coefficient Quantization
PS: Coefficient quantization in lossless lattice realizations
o = original transfer function
+ = transfer function after 8-bit
truncation of lossless lattice
filter coefficients
- = transfer function after 8-bit
truncation of direct-form
coefficients (bis)

In lossless lattice, all coefficients are sines and cosines, hence all
values between 1 and +1, i.e. `dynamic range and coefficient
quantization error well under control.
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 17

Arithmetic Operations
Finite word-length effects in arithmetic operations :
In linear filters, have to consider additions & multiplications

Addition:
if, two B-bit numbers are added, the result has (B+1) bits.

Multiplication:
if a B1-bit number is multiplied by a B2-bit number, the
result has (B1+B2-1) bits.
For instance, two B-bit numbers yield a (2B-1)-bit product
Typically (especially so in an IIR (feedback) filter), the result of an
addition/multiplication has to be represented again as a B-bit number
(e.g. B=B). Hence have to remove most significant bits and/or least
significant bits
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 18

Arithmetic Operations
Option-1: Most significant bits (MSBs)
If the result is known to be (almost) always upper bounded such that 1 or
more MSBs are (almost) always redundant, these MSBs can be dropped
without loss of accuracy (mostly). Dropping MSBs then leads to better
usage of available word-length, hence better SNR.
This implies we have to monitor
potential overflow (=dropping MSBs that are non-redundant), and
possibly introduce additional scaling to avoid overflow.

Option-2 : Least significant bits (LSBs)


Rounding/truncation/ to B bits introduces quantization noise.
The effect of quantization noise is usually analyzed in a statistical
manner.
Quantization, however, is a deterministic non-linear effect, which may
give rise to limit cycle oscillations.
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 19

Quantization Noise
Quantization mechanisms:
Rounding

Truncation

Magnitude Truncation

output

input
probability

error

mean=0

mean=(-0.5)LSB (biased!)

mean=0

variance=(1/12)LSB^2

variance=(1/12)LSB^2

variance=(1/6)LSB^2

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 20

Quantization Noise
Statistical analysis is based on the following assumptions :
- each quantization error is random, with uniform probability distribution
function (see previous slide)
- quantization errors at the output of a given multiplier are
uncorrelated/independent (=white noise assumption)
- quantization errors at the outputs of different multipliers are
uncorrelated/independent (=independent sources assumption)

One noise source is inserted


for each multiplier(/adder)

u[k]

Since the filter is a linear filter the output


noise generated by each noise source can be
y[k]
computed and added to the output signal
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

+ e[k]
-.99

p. 21

Limit Cycles
Statistical analysis is simple/convenient, but quantization is
truly a non-linear effect, and should be analyzed as a
deterministic process.
Though very difficult, such analysis may reveal odd behavior:
Example: y[k] = -0.625.y[k-1]+u[k]
4-bit rounding arithmetic
input u[k]=0, y[0]=3/8
output y[k] = 3/8, -1/4, 1/8, -1/8, 1/8, -1/8, 1/8, -1/8, 1/8,..

Oscillations in the absence of input (u[k]=0) are called


`zero-input limit cycle oscillations

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 22

Limit Cycles
Example: y[k] = -0.625.y[k-1]+u[k]
4-bit truncation (instead of rounding)
input u[k]=0, y[0]=3/8
output y[k] = 3/8, -1/4, 1/8, 0, 0, 0,.. (no limit cycle!)
Example: y[k] = 0.625.y[k-1]+u[k]
4-bit rounding
input u[k]=0, y[0]=3/8
output y[k] = 3/8, 1/4, 1/8, 1/8, 1/8, 1/8,..
Example: y[k] = 0.625.y[k-1]+u[k]
4-bit truncation
input u[k]=0, y[0]=-3/8
output y[k] = -3/8, -1/4, -1/8, -1/8, -1/8, -1/8,..

Conclusion: weird, weird, weird, !


DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 23

Limit Cycles
Limit cycle oscillations are clearly unwanted (e.g. may be
audible in speech/audio applications)
Limit cycle oscillations can only appear if the filter has
feedback. Hence FIR filters cannot have limit cycle
oscillations.
Mathematical analysis is very difficult
Truncation often helps to avoid limit cycles (e.g. magnitude
truncation, where absolute value of quantizer output is
never larger than absolute value of quantizer input
(=`passive quantizer)).
Some filter realizations can be made limit cycle free, e.g.
coupled realization, orthogonal filters (see below).
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 24

Orthogonal
Filters
e

h
t
ip

d
i
l
s
s
i

k
Sorthogonal
realization matrix:

Orthogonal filter = state-space realization with


A
R
C

B
D

R T .R R.R T I
PS : lattice filters and lattice-part of lattice-ladder .
Strictly speaking, these are not state-space realizations (cfr. supra), but
orthogonal R is realized as a product of matrices, each of which is again
orthogonal, such that useful properties of orthogonal states-space
realizations indeed carry over (see p. 38)

Why should we be so fond of orthogonal filters ?


DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 25

Orthogonal
Filters
e

Sk

h
t
ip

d
i
l
s
s
i

Scaling :

- in a state-space realization, have to monitor overflow in internal states

x[k 1] A.x[k ] B.u[k ]


- transfer functions from input to internal states (`scaling functions) are
defined by impulse response sequence (see p. 22)

AB

A2 B

A3 B

...

- for an orthogonal filter (R.R=I), it is proven (next slide) that


.T I

AB

A2 B

...

which implies that all scaling functions (rows of Delta) have L2-norm=1
(=diagonal elements of .T

conclusion: orthogonal filters are `scaled in L2-sense


DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 26

Orthogonal
Filters
e

Sk

Proof :

h
t
ip

d
i
l
s
s
i

First :
R. R T I A. AT B. B T I
Then:
I .T I
B.B T A
B. B T AT AA
B. B T AT AT ...
I A. AT

I A. AT

I A. AT

( I I ) ( A. AT A. AT ) ( AA. AT AT AA. AT AT ) ......


0 0 0 ...

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 27

Orthogonal
Filters
e

d
i
l
s
s
i
Quantization
noise
:
h
t
p
i
- in ak
state-space
realization, quantization noise in internal states may be
S
represented by equivalent noise source (vector) Ex[k]
x[k 1] A. x[k ] B.u[k ] E x [k ]

- transfer functions from noise sources to output (`noise transfer


functions) are defined by impulse response sequence

(CA)T

(CA2 )T

...

- for an orthogonal filter (R.R=I), it is proven that

T . I

T C T

(CA)T

(CA 2 )T

(try it)

...

which implies that all noise gains are =1 (all noise transfer functions
T
have L2-norm = 1 = diagonal elements of . ).
- This is then proven to correspond to minimum possible output noise
variance for given transfer function, under L2 scaled conditions (i.e.
when states are scaled such that scaling functions have L2-norm=1) !! (details omitted)
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 28

Orthogonal Filters
Limit cycle oscillations :
if magnitude truncation is used (=`passive quantization),
orthogonal filters are guaranteed to be free of limit cycles
(details omitted)

intuition: quantization consumes energy/power, orthogonal


filter does not generate power to feed limit cycle.

DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 29

Orthogonal Filters

Orthogonal filters

= L2-scaled, minimum output noise,


limit cycle oscillation free filters !

It can be shown that these statements also hold for :


* lossless lattice realizations of a general IIR filter
* lattice-part of a general IIR filter in lattice-ladder realization
DSP-CIS / Chapter-6: Filter Implementation / Version 2012-2013

p. 30

Anda mungkin juga menyukai