peccs 2014
TRANSCRIPT
![Page 1: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/1.jpg)
Context and Objectives Bits Formatting Conclusion
Formatting bits to better implement signalprocessing algorithms
Benoit Lopez - Thibault Hilaire - Laurent-Stephane DidierPECCS 2014
January 9th 2014
1/20
![Page 2: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/2.jpg)
Context and Objectives Bits Formatting Conclusion
Outline
1 Context and Objectives
2 Bits Formatting
3 Conclusion
2/20
![Page 3: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/3.jpg)
Context and Objectives Bits Formatting Conclusion
In PECCS’14
Smartphone applications, measurement applications, embeddeddevices, ...
Implementation problem
We need methodology and tools for the implementation ofembedded filter algorithms with only integer arithmetic.
3/20
![Page 4: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/4.jpg)
Context and Objectives Bits Formatting Conclusion
In PECCS’14
Smartphone applications, measurement applications, embeddeddevices, ...
Implementation problem
We need methodology and tools for the implementation ofembedded filter algorithms with only integer arithmetic.
3/20
![Page 5: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/5.jpg)
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) =
Pni=0 biz
�i
1 +Pn
i=1 aiz�i
Signal ProcessingLTI filters: FIR or IIRIts transfer functionAlgorithmic relationship used to compute output(s) frominput(s), for example:
y(k) =n∑
i=0
biu(k − i)−n∑
i=1
aiy(k − i)
4/20
![Page 6: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/6.jpg)
Context and Objectives Bits Formatting Conclusion
On the other hand... A target
±
. . .
. . .
2��
20
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
![Page 7: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/7.jpg)
Context and Objectives Bits Formatting Conclusion
Fixed-Point Arithmetic
Fixed-Point number
Fixed-point numbers are integers used to approximate realnumbers.
Xm X0 X−1 X`
w
−2m 20 2−12m−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
![Page 8: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/8.jpg)
Context and Objectives Bits Formatting Conclusion
Fixed-Point Arithmetic
Fixed-Point number
Fixed-point numbers are integers used to approximate realnumbers.
Xm X0 X−1 X`
w
−2m 20 2−12m−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
![Page 9: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/9.jpg)
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 theoutput 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
![Page 10: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/10.jpg)
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 theoutput 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
![Page 11: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/11.jpg)
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 theoutput 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
![Page 12: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/12.jpg)
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 errorthrough 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
![Page 13: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/13.jpg)
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 errorthrough 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
![Page 14: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/14.jpg)
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 controlthese errors.
Objective:
Given an algorithm and a bound on the final error, find animplementation which reduces the number of bits of thecomputation while controlling the error on the output result.
9/20
![Page 15: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/15.jpg)
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 controlthese errors.
Objective:
Given an algorithm and a bound on the final error, find animplementation which reduces the number of bits of thecomputation while controlling the error on the output result.
9/20
![Page 16: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/16.jpg)
Context and Objectives Bits Formatting Conclusion
Outline
1 Context and Objectives
2 Bits Formatting
3 Conclusion
10/20
![Page 17: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/17.jpg)
Context and Objectives Bits Formatting Conclusion
Sum-of-Products
The only operations needed in filter algorithm computation aresum-of-products:
s =n∑
i=1
ci · xi =n∑
i=1
pi
where ci are known constants and xi variables (inputs, state orintermediate variables).
In the context of filter design, we know the fixed-point formatof the final result.
11/20
![Page 18: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/18.jpg)
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 knownFPF of final result (sf ), less than total wordlength (s).
Questions:
Can we remove bits that don’t impact the final result ? If we wanta faithful round-off of the final result, can we remove some bits ?
12/20
![Page 19: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/19.jpg)
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 knownFPF of final result (sf ), less than total wordlength (s).
Questions:
Can we remove bits that don’t impact the final result ? If we wanta faithful round-off of the final result, can we remove some bits ?
12/20
![Page 20: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/20.jpg)
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
![Page 21: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/21.jpg)
Context and Objectives Bits Formatting Conclusion
MSB formatting
Jacskon’s Rule (1979)
This Rule states that in consecutive additions and/or subtractionsin two’s complement arithmetic, some intermediate results andoperands may overflow. As long as the final result representationcan 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 theexpected result.
13/20
![Page 22: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/22.jpg)
Context and Objectives Bits Formatting Conclusion
MSB formatting
Jacskon’s Rule (1979)
This Rule states that in consecutive additions and/or subtractionsin two’s complement arithmetic, some intermediate results andoperands may overflow. As long as the final result representationcan 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 theexpected result.
13/20
![Page 23: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/23.jpg)
Context and Objectives Bits Formatting Conclusion
MSB formatting
Jacskon’s Rule (1979)
This Rule states that in consecutive additions and/or subtractionsin two’s complement arithmetic, some intermediate results andoperands may overflow. As long as the final result representationcan 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 theexpected result.
13/20
![Page 24: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/24.jpg)
Context and Objectives Bits Formatting Conclusion
MSB formatting
Jacskon’s Rule (1979)
This Rule states that in consecutive additions and/or subtractionsin two’s complement arithmetic, some intermediate results andoperands may overflow. As long as the final result representationcan 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 theexpected result.
13/20
![Page 25: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/25.jpg)
Context and Objectives Bits Formatting Conclusion
MSB formatting
Fixed-Point Jacskon’s Rule
Let s be a sum of n fixed-point number pi s, in format (M, L). If sis 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 sfM Lmf
14/20
![Page 26: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/26.jpg)
Context and Objectives Bits Formatting Conclusion
MSB formatting
Fixed-Point Jacskon’s Rule
Let s be a sum of n fixed-point number pi s, in format (M, L). If sis 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 sfM Lmf
14/20
![Page 27: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/27.jpg)
Context and Objectives Bits Formatting Conclusion
LSB formatting
LSB Formatting main idea
s
s
s
s
s
s
s s
s sf
15/20
![Page 28: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/28.jpg)
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 afaithful round-off of sf can be acceptable.
15/20
![Page 29: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/29.jpg)
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 faithfulround-off of sf ?
15/20
![Page 30: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/30.jpg)
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), thesmallest integer δ that provides s ′f = ?lf (sf ) is given by:
δ = dlog2(n)e15/20
![Page 31: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/31.jpg)
Context and Objectives Bits Formatting Conclusion
Formatting
Formatting method
s
s
s
s
s
s
s s
s sf
1 we compute δ
2 we format all pi s into FPF (mf , lf − δ)
3 we compute sδ4 we obtain s ′f from sδ
16/20
![Page 32: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/32.jpg)
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 pi s into FPF (mf , lf − δ)
3 we compute sδ4 we obtain s ′f from sδ
16/20
![Page 33: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/33.jpg)
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 pi s into FPF (mf , lf − δ)
3 we compute sδ
4 we obtain s ′f from sδ
16/20
![Page 34: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/34.jpg)
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 pi s into FPF (mf , lf − δ)
3 we compute sδ4 we obtain s ′f from sδ
16/20
![Page 35: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/35.jpg)
Context and Objectives Bits Formatting Conclusion
Formatting
Example
The following algorithm is the fixed-point algorithm of a 4th−orderbutterworth 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
![Page 36: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/36.jpg)
Context and Objectives Bits Formatting Conclusion
Formatting
Example
The following algorithm is the fixed-point algorithm of a 4th−orderbutterworth 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
![Page 37: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/37.jpg)
Context and Objectives Bits Formatting Conclusion
Formatting
Example
s
s
s
s
s
s
s
s
s
s
s
18/20
![Page 38: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/38.jpg)
Context and Objectives Bits Formatting Conclusion
Formatting
Example
s
s
s
s
s
s
s
s
s
s
s
δ = dlog2(n)e
18/20
![Page 39: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/39.jpg)
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 ofthe operands while controlling the error ?
For this, some works have been realized:
FiPoGen : a tool generating fixed-point code for a givensum-of-products
Bits formatting : a first step towards word-length optimization
19/20
![Page 40: PECCS 2014](https://reader036.vdocuments.mx/reader036/viewer/2022062514/55beb1eebb61eba36c8b4767/html5/thumbnails/40.jpg)
Context and Objectives Bits Formatting Conclusion
THANK YOUAny questions?
20/20