Formatting bits to better implement signal processing algorithms - - PowerPoint PPT Presentation

formatting bits to better implement signal processing
SMART_READER_LITE
LIVE PREVIEW

Formatting bits to better implement signal processing algorithms - - PowerPoint PPT Presentation

Context and Objectives Bits Formatting Conclusion Formatting bits to better implement signal processing algorithms Benoit Lopez - Thibault Hilaire - Laurent-St ephane Didier PECCS 2014 January 9 th 2014 1/20 Context and Objectives Bits


slide-1
SLIDE 1

Context and Objectives Bits Formatting Conclusion

Formatting bits to better implement signal processing algorithms

Benoit Lopez - Thibault Hilaire - Laurent-St´ ephane Didier PECCS 2014 January 9th 2014

1/20

slide-2
SLIDE 2

Context and Objectives Bits Formatting Conclusion

Outline

1

Context and Objectives

2

Bits Formatting

3

Conclusion

2/20

slide-3
SLIDE 3

Context and Objectives Bits Formatting Conclusion

In PECCS’14 Smartphone applications, measurement applications, embedded devices, ...

3/20

slide-4
SLIDE 4

Context and Objectives Bits Formatting Conclusion

In PECCS’14 Smartphone applications, measurement applications, embedded devices, ... Implementation problem We need methodology and tools for the implementation of embedded filter algorithms with only integer arithmetic.

3/20

slide-5
SLIDE 5

Context and Objectives Bits Formatting Conclusion

On the first hand... A filter

+

z−1 z−1 z−1 z−1 z−1 z−1 b1 b1 b2 b3 a3 a2 a1

x[n] y[n]

+

z−1 z−1 z−1

x[n] y[n]

b0 b1 b2 b3

+ + + + +

−a3 −a2 −a1 z−1 z−1 z−1

h(z) = Pn

i=0 biz−i

1 + Pn

i=1 aiz−i

Signal Processing LTI filters: FIR or IIR Its transfer function Algorithmic relationship used to compute output(s) from input(s), for example: y(k) =

n

  • i=0

biu(k − i) −

n

  • i=1

aiy(k − i)

4/20

slide-6
SLIDE 6

Context and Objectives Bits Formatting Conclusion

On the other hand... A target

± . . . . . . 2

−γ

2 2

α−2

s β α γ

Hardware target (FPGA, ASIC) or software target (DSP,µC) Due to resources constraints (cost, size, power consumption, ...) we have no FPU, so we can only use fixed-point arithmetic

5/20

slide-7
SLIDE 7

Context and Objectives Bits Formatting Conclusion Fixed-Point Arithmetic

Fixed-Point number

Fixed-point numbers are integers used to approximate real numbers.

Xm X0 X−1 Xℓ w −2m 20 2−1 2m−1 2ℓ

Representation : X.2ℓ with X = XmXm−1...X0...Xℓ. Format : determined by wordlength and fixed-point position, and noted for example (m, ℓ).

6/20

slide-8
SLIDE 8

Context and Objectives Bits Formatting Conclusion Fixed-Point Arithmetic

Fixed-Point number

Fixed-point numbers are integers used to approximate real numbers.

Xm X0 X−1 Xℓ w −2m 20 2−1 2m−1 2ℓ

Representation : X.2ℓ with X = XmXm−1...X0...Xℓ. Format : determined by wordlength and fixed-point position, and noted for example (m, ℓ). Computation in finite precision and choice of formats imply errors. Numerical degradations quantization of the coefficients round-off errors in computations

6/20

slide-9
SLIDE 9

Context and Objectives Bits Formatting Conclusion Filter

IIR Filter

Let H be the transfer function of a n − th order IIR filter : H(z) = b0 + b1z−1 + · · · + bnz−n 1 + a1z−1 + · · · + anz−n , ∀z ∈ C. (1)

7/20

slide-10
SLIDE 10

Context and Objectives Bits Formatting Conclusion Filter

IIR Filter

Let H be the transfer function of a n − th order IIR filter : H(z) = b0 + b1z−1 + · · · + bnz−n 1 + a1z−1 + · · · + anz−n , ∀z ∈ C. (1) This filter is usually realized with the following algorithm y(k) =

n

  • i=0

biu(k − i) −

n

  • i=1

aiy(k − i) (2) where u(k) is the input at step k and y(k) the output at step k.

7/20

slide-11
SLIDE 11

Context and Objectives Bits Formatting Conclusion Filter

IIR Filter

Let H be the transfer function of a n − th order IIR filter : H(z) = b0 + b1z−1 + · · · + bnz−n 1 + a1z−1 + · · · + anz−n , ∀z ∈ C. (1) This filter is usually realized with the following algorithm y(k) =

n

  • i=0

biu(k − i) −

n

  • i=1

aiy(k − i) (2) where u(k) is the input at step k and y(k) the output at step k. We can see round-off errors as the add of an error e(k) on the

  • utput and only y†(k) can be computed.

y†(k) =

n

  • i=0

biu(k − i) −

n

  • i=1

aiy†(k − i) + e(k). (3)

7/20

slide-12
SLIDE 12

Context and Objectives Bits Formatting Conclusion Filter

+ H He u(k) e(k) ∆y(k) y†(k) y(k)

∆y(k) y†(k) − y(k) can be seen as the result of the error through the filter He : He(z) = 1 1 + a1z−1 + · · · + anz−n , ∀z ∈ C.

8/20

slide-13
SLIDE 13

Context and Objectives Bits Formatting Conclusion Filter

+ H He u(k) e(k) ∆y(k) y†(k) y(k)

∆y(k) y†(k) − y(k) can be seen as the result of the error through the filter He : He(z) = 1 1 + a1z−1 + · · · + anz−n , ∀z ∈ C. If the error e(k) is in [e; e], then we are able to compute ∆y and ∆y such that ∆y(k) is in [∆y; ∆y] : ∆y = e + e 2 |He|DC − e − e 2 Heℓ∞ ∆y = e + e 2 |He|DC + e − e 2 Heℓ∞

8/20

slide-14
SLIDE 14

Context and Objectives Bits Formatting Conclusion Objective

Fixed-Point implementation and especially the choice of formats, imply errors. In the context of digital signal processing, we are able to control these errors.

9/20

slide-15
SLIDE 15

Context and Objectives Bits Formatting Conclusion Objective

Fixed-Point implementation and especially the choice of formats, imply errors. In the context of digital signal processing, we are able to control these errors. Objective: Given an algorithm and a bound on the final error, find an implementation which reduces the number of bits of the computation while controlling the error on the output result.

9/20

slide-16
SLIDE 16

Context and Objectives Bits Formatting Conclusion

Outline

1

Context and Objectives

2

Bits Formatting

3

Conclusion

10/20

slide-17
SLIDE 17

Context and Objectives Bits Formatting Conclusion

Sum-of-Products

The only operations needed in filter algorithm computation are sum-of-products: s =

n

  • i=1

ci · xi =

n

  • i=1

pi where ci are known constants and xi variables (inputs, state or intermediate variables). In the context of filter design, we know the fixed-point format

  • f the final result.

11/20

slide-18
SLIDE 18

Context and Objectives Bits Formatting Conclusion

Formatting

s s s s s s s s s sf

Context A sum of N terms (pi)1≤i≤N with different formats, and the known FPF of final result (sf ), less than total wordlength (s).

12/20

slide-19
SLIDE 19

Context and Objectives Bits Formatting Conclusion

Formatting

s s s s s s s s s sf

Context A sum of N terms (pi)1≤i≤N with different formats, and the known FPF of final result (sf ), less than total wordlength (s). Questions: Can we remove bits that don’t impact the final result ? If we want a faithful round-off of the final result, can we remove some bits ?

12/20

slide-20
SLIDE 20

Context and Objectives Bits Formatting Conclusion

Formatting

s s s s s s s s s sf

Two-step formatting

1 most significant bits 2 least significant bits 12/20

slide-21
SLIDE 21

Context and Objectives Bits Formatting Conclusion MSB formatting

Jacskon’s Rule (1979)

This Rule states that in consecutive additions and/or subtractions in two’s complement arithmetic, some intermediate results and

  • perands may overflow. As long as the final result representation

can handle the final result without overflow, then the result is valid.

13/20

slide-22
SLIDE 22

Context and Objectives Bits Formatting Conclusion MSB formatting

Jacskon’s Rule (1979)

This Rule states that in consecutive additions and/or subtractions in two’s complement arithmetic, some intermediate results and

  • perands may overflow. As long as the final result representation

can handle the final result without overflow, then the result is valid. Example : We want to compute 104 + 82 − 94 with 8 bits :

13/20

slide-23
SLIDE 23

Context and Objectives Bits Formatting Conclusion MSB formatting

Jacskon’s Rule (1979)

This Rule states that in consecutive additions and/or subtractions in two’s complement arithmetic, some intermediate results and

  • perands may overflow. As long as the final result representation

can handle the final result without overflow, then the result is valid. Example : We want to compute 104 + 82 − 94 with 8 bits : 104 + 82 = −70 overflow !

13/20

slide-24
SLIDE 24

Context and Objectives Bits Formatting Conclusion MSB formatting

Jacskon’s Rule (1979)

This Rule states that in consecutive additions and/or subtractions in two’s complement arithmetic, some intermediate results and

  • perands may overflow. As long as the final result representation

can handle the final result without overflow, then the result is valid. Example : We want to compute 104 + 82 − 94 with 8 bits : 104 + 82 = −70 overflow ! but −70 − 94 = 92 overflow ! This second overflow cancels the first one and we obtain the expected result.

13/20

slide-25
SLIDE 25

Context and Objectives Bits Formatting Conclusion MSB formatting

Fixed-Point Jacskon’s Rule

Let s be a sum of n fixed-point number pis, in format (M, L). If s is known to have a final MSB equals to mf with mf < M, then: s =

mf +1

  • 1≤i≤n

 

mf

  • j=L

2jpi,j  

s s s s s s s s s sf M L mf

14/20

slide-26
SLIDE 26

Context and Objectives Bits Formatting Conclusion MSB formatting

Fixed-Point Jacskon’s Rule

Let s be a sum of n fixed-point number pis, in format (M, L). If s is known to have a final MSB equals to mf with mf < M, then: s =

mf +1

  • 1≤i≤n

 

mf

  • j=L

2jpi,j  

s s s s s s s s s s s sf M L mf

14/20

slide-27
SLIDE 27

Context and Objectives Bits Formatting Conclusion LSB formatting

LSB Formatting main idea

s s s s s s s s s sf

15/20

slide-28
SLIDE 28

Context and Objectives Bits Formatting Conclusion LSB formatting

LSB Formatting main idea

s s s s s s s s s sf

If we remove some bits, we will not compute sf anymore but a faithful round-off of sf can be acceptable.

15/20

slide-29
SLIDE 29

Context and Objectives Bits Formatting Conclusion LSB formatting

LSB Formatting main idea

s s s s s s δ s sδ s s′

f

Can we determine a minimal δ such that s′

f is always a faithful

round-off of sf ?

15/20

slide-30
SLIDE 30

Context and Objectives Bits Formatting Conclusion LSB formatting

LSB Formatting main idea

s s s s s s δ s sδ s s′

f

δ evaluation For both rounding mode (round-to-nearest or truncation), the smallest integer δ that provides s′

f = ⋆lf (sf ) is given by:

δ = ⌈log2(n)⌉

15/20

slide-31
SLIDE 31

Context and Objectives Bits Formatting Conclusion Formatting

Formatting method

s s s s s s s s s sf

1 we compute δ 16/20

slide-32
SLIDE 32

Context and Objectives Bits Formatting Conclusion Formatting

Formatting method

s s s s s s δ s sδ s s′

f 1 we compute δ 2 we format all pis into FPF (mf , lf − δ) 16/20

slide-33
SLIDE 33

Context and Objectives Bits Formatting Conclusion Formatting

Formatting method

s s s s δ s sδ s s′

f 1 we compute δ 2 we format all pis into FPF (mf , lf − δ) 3 we compute sδ 16/20

slide-34
SLIDE 34

Context and Objectives Bits Formatting Conclusion Formatting

Formatting method

s s s s δ s sδ s s′

f 1 we compute δ 2 we format all pis into FPF (mf , lf − δ) 3 we compute sδ 4 we obtain s′

f from sδ

16/20

slide-35
SLIDE 35

Context and Objectives Bits Formatting Conclusion Formatting

Example

The following algorithm is the fixed-point algorithm of a 4th−order butterworth filter: y(k) = 0.0013279914856 u(k) + 0.00531196594238 u(k − 1) +0.00796794891357 u(k − 2) + 0.00531196594238 u(k − 3) +0.0013279914856 u(k − 4) + 2.87109375 y(k − 1) −3.20825195312 y(k − 2) + 1.63458251953 y(k − 3) −0.318710327148 y(k − 4) Inputs datas : wordlength of constants, u(k) and y(k) : 16 bits u(k) ∈ [−13, 13]

17/20

slide-36
SLIDE 36

Context and Objectives Bits Formatting Conclusion Formatting

Example

The following algorithm is the fixed-point algorithm of a 4th−order butterworth filter: y(k) = 0.0013279914856 u(k) + 0.00531196594238 u(k − 1) +0.00796794891357 u(k − 2) + 0.00531196594238 u(k − 3) +0.0013279914856 u(k − 4) + 2.87109375 y(k − 1) −3.20825195312 y(k − 2) + 1.63458251953 y(k − 3) −0.318710327148 y(k − 4) Inputs datas : wordlength of constants, u(k) and y(k) : 16 bits u(k) ∈ [−13, 13] and y(k) ∈ [−17.123541; 17.123541]

17/20

slide-37
SLIDE 37

Context and Objectives Bits Formatting Conclusion Formatting

Example

s s s s s s s s s s s

18/20

slide-38
SLIDE 38

Context and Objectives Bits Formatting Conclusion Formatting

Example

s s s s s s s s s s s δ = ⌈log2(n)⌉

18/20

slide-39
SLIDE 39

Context and Objectives Bits Formatting Conclusion

Conclusion

We try to answer the following question : For a given sum-of-products, how to reduce the number of bits of the operands while controlling the error ? For this, some works have been realized: FiPoGen : a tool generating fixed-point code for a given sum-of-products Bits formatting : a first step towards word-length optimization

19/20

slide-40
SLIDE 40

Context and Objectives Bits Formatting Conclusion

THANK YOU

Any questions?

20/20