LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

R Series FPGA, calculate log base 10 of number >=1

Solved!
Go to solution

Hi all,

 

I'm stuck on a problem with calculating a base 10 log of a number greater than 1.  It seems the natural log function in the High Throughput Math library is limited to the range of 1/e to 1.  There must be others who need to work outside this range - how is it done?

 

thanks,

George

0 Kudos
Message 1 of 9
(5,216 Views)

Are you saying you are having problems with both the log10 function and the natural log function?  Where is this "high throughput" palette?

 

I doubt there is any problem with these functions, so it must be something with your implementation.  Show us your VI where you are having a problem.

0 Kudos
Message 2 of 9
(5,213 Views)

This is for a FPGA target (pcie-7841R), the high throughput library is used by the FPGA addon.  I'd like y = log(x) with  1<=x<=1000.  There is no log(x) available, as far as I know, but there is ln(x), so if ln(x)/ln(10) = log(x), then I thought I could use the available ln(x) function.  But it's input range is 1/e<x<1.

 

Here's what I was hoping to do with the ln(x) function.  X will range from 0.1 to 99.999.  The ln(x) functions do not allow more than 0 bits for the integer, hence the broken wires.

 

 

fpga_log10.png

0 Kudos
Message 3 of 9
(5,208 Views)
Solution
Accepted by topic author gharris

Hey gharris,

 

The only way I know of to do this is via look-up tables.

 

You will likely want to use BlockRAM, and use an initialization VI, as described here. You may also want a table of logarithms, that covers the range you expect to encounter. For values outside your table, you will need to interpolate.

 

To get this right for your application may take quite a bit of fine-tuning, especially if you have tight timing requirements or a need for high precision.

Cheers!

TJ G
Message 4 of 9
(5,207 Views)

That works for me - thanks.  I don't need more than a 3 significant figures, so I'll bet interpolation with a small table will work fine.  I'll give it a try.

0 Kudos
Message 5 of 9
(5,201 Views)

I think you may still encounter some difficulties in addressing the look-up table with the high dynamic range of x. You may still need some kind of scaling scheme to restrict your inputs to be (for example) between .1 and 1. This could be done with a few comparisons and dividing by 100 or 10 based on the results. Note that it will be cheaper to implement those divides with multiplications by .01 and .1. Then you would correct the result by adding log(100) or log(10) to the output.

 

Another question is how you got into base 10 arithmetic in the first place?  Often you can do things more efficiently in binary, so one option would be to go upstream of wherever the conversion to decimal ranges took place and work with log2 and binary data. All of the operations will be cheaper and more accurate in that domain, and you can consolidate your conversions to desired units at the end. I can make a dynamic normalization VI available to scale the data into the [.5, 1) range if you want to try that.

Message 6 of 9
(5,176 Views)

I think I'm stuck with log10.  I'm calculating optical density.  I made a LUT based program that I think can be re-coded to work on the FPGA.  I made the attached zip to run on a PC target so that I could play with it.  With a 1024 element LUT, it looks like the error of the log value is less than 5e-6.  Since I'm trying to resolve down to 1e-3, this should be fine.  If you have any feedback, I'd love to hear it.

 

 

0 Kudos
Message 7 of 9
(5,161 Views)

It looks like you're on the right track, though there's plenty of work left to port to FPGA. The first step would be to modify your error evaluation to use FPGA-supported types, in order to take into account quantization of the LUT values and scaling/interpolation arithmetic. You also need to consider quantization of the x values and include that in your error evaluation unless you can treat the quantized values as exact. 2012 allows SGL types on the FPGA, so that would be a good starting point if it will fit on your target.

 

Your interpolation scheme is a little complicated; you should be able to do it with a single multiply. There is a Linear Interpolation function on the FPGA Math and Analysis >> Utilities palette. If you right-click on it and select "Convert to SubVI", you can look at the diagram to see how it works. If you go with fixed-point types, you can use Look-Up Table 1D, which will take care of the interpolation for you. It only supports integers, unfortunately, but you can use Fixed-Point to Integer Cast to make use of it in a FXP diagram.

0 Kudos
Message 8 of 9
(5,146 Views)

I am also facing the same problem for values less then 1/e it gives wrong answer and for values greater then 1 it doesn't support how you solved it. I also need it.

Thanks!!!!!

0 Kudos
Message 9 of 9
(4,099 Views)