quick logarithms

I have a problem that generates measurements of distance. The measured values fit the general form

I = A * exp(-B * x)

where x is distance.

I can calibrate and get values for A and B. Thing is, given I how best to calculate x? Since an exponential can be expressed as a power of 2 rather than e, it seems that there should be a relatively quick way of finding log(I). It is, after all, the number of bits required to store I in one sense.

However, I can't seem to find an example of doing quick (and probably dirty logs). It does need to be quick. I need six of these per millisecond and still have time to draw breath.

Failing that I will have to look at soime kind of look up table.

Any suggestions?

Pete Harrison

Reply to
Peter Harrison
Loading thread data ...

Which CPU are you using ?

Reply to
Arlet Ottens

exp(x) =3D 1 + x + x2/2 + x3/6 + x4/24 + x5/120 + =85 + xn/n! + =85

Reply to
linnix

Would doing a binary search over a small table be fast enough ?

--
:wq
^X^Cy^K^X^C^C^C^C
Reply to
Ico

That might do the trick

I am using a dsPIC30 with the clock at 64MHz. The measured values are integers. Pretty much as soon as I hit the send key, I thought again about the table.

This happens too often. I should pay more attention to the golden rule:

"think twice, speak once"

Anyway... Since the range of measured values is 0-1023, I can afford a lookup table. I just hadn't considered it until I wrote it down. I shall be sure not to give up the day job too soon.

Thanks for your help

Pete

Reply to
Peter Harrison
0E142F9864C572DC60A75ECA Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit

Peter Harris> I have a problem that generates measurements of distance. The measured

The following is a fixed point log routine from our transcendental library. This might not be the latest version.

FIX_MATH needs to be defined as an accum data type (integer.fract) in a compiler that supports fract and accums. Without accum support it will probably work with integers by scaling the constants to and math represent a fixed point value.

If you have any questions contact me off line.

FIX_MATH fix_log(FIX_MATH x)

/* (C) Copyright 2006 Byte Craft Limited Waterloo, ON, Canada, N2L 6H7 Walter Banks Email: snipped-for-privacy@bytecraft.com URL :

formatting link
*/

{ int n=1; FIX_MATH a,log1,log2; log1 = 0.0; if (x = 2.0) { x/=2.0; log1 += __fix_log2; } while(x < 1.0) { x*=2.0; log1 -= __fix_log2; } x =(x-1.0)/(x+1.0); a=2*x; x*=x; do {log2=log1; log1 += a/n; a*=x; n+=2; }while(log1!=log2); return (log1); }

Regards,

Reply to
Walter Banks

How quick is "quick", i.e. how many operations of what type can you afford?

How dirty is "dirty", i.e. what error threshold can you tolerate?

On what platform? What's the format of the input and output?

I find it hard to believe you couldn't find any algorithms to compute logarithms. There's one right there on the wikipedia page for the binary logarithm!

Reply to
Hans-Bernhard Bröker

Me too. Some days I seem to do bad searches, some days good ones.

I didn't get as far as the computers section. In any case, I don't really understand what they mean. I can find the integer part easily enough anyway.

Still, I posted in haste withut due consideration. Something I generally try to avoid.

Thanks (all) for your time

Pete Harrison

Reply to
Peter Harrison

And now I have found the page I guess you were referring to. It hadn't occured to me to call it a binary logarithm. Ah well...

Reply to
Peter Harrison

I collected some stuff.

formatting link

Rene

--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com
& commercial newsgroups - http://www.talkto.net
Reply to
Rene Tschaggelar

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.