- quick logarithms
- Posted by Peter Harrison on May 15th, 2008
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
- Posted by Arlet Ottens on May 15th, 2008
Peter Harrison wrote:
Which CPU are you using ?
- Posted by linnix on May 15th, 2008
On May 15, 11:59 am, Peter Harrison <peter.harri...@helicron.net>
wrote:
exp(x) = 1 + x + x2/2 + x3/6 + x4/24 + x5/120 + … + xn/n! + …
- Posted by Ico on May 15th, 2008
Peter Harrison <peter.harrison@helicron.net> wrote:
Would doing a binary search over a small table be fast enough ?
--
:wq
^X^Cy^K^X^C^C^C^C
- Posted by Peter Harrison on May 15th, 2008
linnix wrote:
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
- Posted by Walter Banks on May 15th, 2008
Peter Harrison wrote:
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: support@bytecraft.com
URL : http://www.bytecraft.com
*/
{
int n=1;
FIX_MATH a,log1,log2;
log1 = 0.0;
if (x <= 0.0) return(0.0); // illegal argument
while(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,
--
Walter Banks
Byte Craft Limited
Tel. (519) 888-6911
http://www.bytecraft.com
walter@bytecraft.com
- Posted by Hans-Bernhard Bröker on May 15th, 2008
Peter Harrison wrote:
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!
- Posted by Peter Harrison on May 15th, 2008
Hans-Bernhard Bröker wrote:
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
- Posted by Peter Harrison on May 15th, 2008
Peter Harrison wrote:
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...
- Posted by Rene Tschaggelar on May 16th, 2008
Peter Harrison wrote:
I collected some stuff.
http://www.ibrtses.com/embedded/logarithms.html
Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com
& commercial newsgroups - http://www.talkto.net