Quick and Easy Binary to dB Conversion
George Weistroffer, Jeremy Cooper, and Jerry Tucker
Electrical and Computer Engineering
Virginia Commonwealth University
Richmond, VA.
2
New algorithm for converting binary integers to decibels (dB)
• Advantages over known alternative methods– Faster
• No real-time floating point operations• Only real-time arithmetic is one integer subtraction
– Requires fewer resources (i.e. less memory)– Simple to implement
• Limitations– Reduced precision
• High precision is not typically needed for dB’s• Precision can be increased at the cost of more memory.
3
Motivation
Analog
Mux
n-bit
ADC
Level detector
Level detector
Level detector
V1
V2
Vk
w, n-bit word
Binary output samples of analog input voltages.
V1,V2,…Vk
dB
4
The problemConsider an unsigned binary integer w expressed as
• Typically w is the output of an n-bit ADC and is changing in real-time.
Let G be the comparison in dB of w to the maximum value of w. Then G
1 2 0 2( ... ... )n n iw w w w w
10 10 1020log 20log ( ) 20log (2 1)2 1
nn
wG w
Changes in real time Fixed – depends only on
number of bits in w.
5
1020log (2 1)ncG
For any particular value of n, the Gc term is a constant and does not have to be computed in real time.
6
Computing 20log10(w)
• The difficulty is the evaluation of the 20log10(w) term.
• The input w changes for each sample.
• 20log10(w) must continually be recalculated.
• A fast method is needed for this calculation.
• Such a method can be developed by taking advantage of the fact that dB values typically do not need to be represented with high precision.
• Therefore, it is possible to use an approximation for w.
7
The approximation of w• Then assuming w ≠ 0, w can be expressed as
where bit m with m < n is the left-most (most significant) “1” of w.
• To approximate w, use only the first r-bits to the right of the most significant “1” of w.
• Let wmin = (1wm-1wm-2…wm-r0…0)2
and wmax = (1wm-1wm-2…wm-r 1…1)2
• Then wmin ≤ w ≤ wmax
Note that when m ≤ r then wmin = w = wmax.• w wmin = (1wm-1wm-2…wm-r0…0)2
1 2 0 2(1 ... )m mw w w w
r-bitsBit m
8
The approximation of GRecall that G = 20log10(w)-20log10(2n-1)
Therefore, Gmin = 20log10(wmin)-20log10(2n-1)
Using G Gmin
and letting R = (wm-1wm-2…wm-r)2
it is easy to show that G can be approximated using three terms.
where 10
10
10
( ) 20log (2) 6.02
( , ) 20log 1 2
( ) 20log (2 1)
m
rR
nC
G m m m
G R r R
G n
( ) ( , ) ( )m R CG G m G R r G n
Depends only on m
Depends only on R
A constant
9
The approximation error( )
10
1 2max 20log 1 when >
2
m r
rerror m r
max 0 when error m r
( 1 )
10
1 220log 1
2
n r
rworst case error
The worst case error occurs when m=n-1.
Using ( ) ( , ) ( )m R CG G m G R r G n
The error will never exceed this worst case error.
10
11
12
Refinements to the algorithm• Combine the Gc value with each term in the Gm table.
– This is slightly more efficient than subtracting the Gc value each time a dB value is computed.
• Scale table values to avoid fractional values.– Let k be the scale factor.
– If resolution is ½ dB let k = 2, if resolution is ¼ dB let k = 4, etc.
• Represent the negation of G as an unsigned integer.– G is always negative.
Therefore, evaluate –kG k(GC – Gm) - kGR
13
14
Example: Let w = (1 0101 01011000011)2
m = 15, R = (0101)2 = 5, 2(Gc – Gm(15)) = 12, 2GR(5) = 5
-2G 12 – 5 = 7, G -3.5 dB, Actual value G = -3.517 dB
15
16
Conclusion• A technique that is fast, easy to implement, and memory
efficient has been developed for converting a binary integer to dB’s.
• It takes advantage of the fact that in practice decibels do not need to be calculate to high precision.
• It uses two small lookup tables to find the dB values.• The method has been illustrated for the specific case where
w is a 16-bit unsigned integer, and where four bits following the most significant “1” of w are used to approximate w.– Requires two 16 byte tables.– The dB value obtained is always within ½ dB of the actual value.
• The algorithm has been implemented and verified using both 8051 assembly language and VHDL.