1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 out of 5)
Loading ... Loading ...
Print Print

Linear to log conversion

by Krishna Sankar on November 20, 2008

In signal processing blocks like power estimation used in digital communication, it may be required to represent the estimate in log scale. This post explains a simple linear to log conversion scheme proposed in the DSP Guru column on DSP Trick: Quick-and-Dirty Logarithms. The scheme makes implementation of a linear to log conversion simple and small in a digital hardware like FPGA.

Consider an integer . The floating point representation is,


is the exponent and

is the mantissa.

Assume that is normalized, i.e .

Taking logarithm to the base 2,


In digital hardware implementations, finding the exponent is simple. Its just noting the index of the first bit which is 1 starting from MSB side.

For example consider an input number .

Expressed in binary on 8 bit bus, .

The value of in this example is 3.

Now, the part which remains to be computed is the mantissa . In this example,


Given that lies in the range . this can be computed using a Look Up Table. The LUT can store values of input between 1 to 2. The precision requirement determines the number of elements in the LUT. Let us assume that we want to have a precision of , where . The look up table values will be as follows:

index. j Linear = 1+j/2^k LUT = log_2(Linear)
1 1.06250 0.0874628
2 1.12500 0.1699250
3 1.18750 0.2479275
4 1.25000 0.3219281
5 1.31250 0.3923174
6 1.37500 0.4594316
7 1.43750 0.5235620
8 1.50000 0.5849625
9 1.56250 0.6438562
10 1.62500 0.7004397
11 1.68750 0.7548875
12 1.75000 0.8073549
13 1.81250 0.8579810
14 1.87500 0.9068906
15 1.93750 0.9541963
16 2.00000 1.0000000

Table: Look up table values for logarithm computation

From the above look up table, we can see that mantissa of corresponds to index of . It is inituitive to note that the array index can be found out by the simple formula,

. To handle cases where this number can can be a fraction, the result is floored to the nearest integer, i.e.

So the value of in base is,

. :)

Once we have the number in base, conversion to any other base is simple.


So the number in base is,


Simulation Model

Simple Matlab/Octave script for computing the logarithm via the LUT based approach is provided. Click here to download Matlab/Octave script for performing linear to log conversion using LUT based approach

linear to log using LUT

Figure: Linear to log conversion using LUT


DSP Trick: Quick-and-Dirty Logarithms – Ray Andraka, June 2000

D id you like this article? Make sure that you do not miss a new article by subscribing to RSS feed OR subscribing to e-mail newsletter. Note: Subscribing via e-mail entitles you to download the free e-Book on BER of BPSK/QPSK/16QAM/16PSK in AWGN.

{ 10 comments… read them below or add one }

Sibo November 23, 2009 at 11:51 am

i need help i have to builld an audio power meter, right am stuk i need a linear to logarithm converter circuit


Avatar of Krishna Sankar Krishna Sankar December 6, 2009 at 4:32 pm

@Sibo: Well, did the idea in this post help you?


Avatar of Krishna Sankar Krishna Sankar December 3, 2008 at 6:02 am

@sandeep: Oh, yes :) I corrected the equation in the post to j = (N/2^E -1)2^k.
Thanks for the close review.


sandeep December 2, 2008 at 9:27 am

Guess I was not clear. In your write-up you have written
j = (M/2^E -1)2^k. Agee? Now in Matlab code it is
j = (N/2^E -1)2^k. Agree? if yes then both doesnot match.


Avatar of Krishna Sankar Krishna Sankar December 2, 2008 at 6:20 am

@sandeep: No, it is indeed M. The index j is used for finding only the mantissa part.

k need not be related to bitwidth of N. k just defines the depth of the LUT; higher the value of k, better the precision.

Makes sense?


sandeep December 1, 2008 at 2:25 pm

Nice article..Some minor correction
In equation for j, there should N instead of M.
Also i think choice of k should be related to bit width of N. Have you defined it?


Avatar of Krishna Sankar Krishna Sankar November 25, 2008 at 6:01 am

@vasundhara: Sorry, I do not have the source code. Typically I only try to help the reader to debug the model rather than writing the code myself. Kindly do email if you have explicit queries.


Avatar of Krishna Sankar Krishna Sankar November 25, 2008 at 6:00 am

@Sky Stradlin: Thanks :) Sure, do hope to run. btw, if you want to share your ideas/thoughts on the blog, you can email me.


Sky Stradlin November 24, 2008 at 2:10 am

man, your blog is really useful, please keep it running !


vasundhara November 23, 2008 at 11:30 pm

please can you privide me a matlab source code?

Finger Assignment Schemes for RAKE Receivers with
Multiple-Way Soft Handover
Seyeong Choi, Member, IEEE, Mohamed-Slim Alouini, Senior Member, IEEE,
Khalid A. Qaraqe, Senior Member, IEEE, and Hong-Chuan Yang, Senior Member, IEEE
Abstract—We propose and analyze new finger assignment
techniques that are applicable for RAKE receivers in the soft
handover (SHO) region. Specifically, extending the results for the
case of two-base station (BS), we consider the multi-BS situation,
attack the statistics of several correlated generalized selection
combining (GSC) stages, and provide closed-form expressions for
the statistics of the output signal-to-noise ratio (SNR). By investigating
the tradeoff among the error performance, the average
number of required path estimations/comparisons, and the SHO
overhead, we show through numerical examples that the new
schemes offer commensurate performance in comparison with
more complicated GSC-based diversity systems while requiring
a smaller estimation load and SHO overhead.
Index Terms—Fading channels, diversity methods, RAKE
receiver, generalized selection combining (GSC), performance


Leave a Comment

Previous post:

Next post: