Re: Best processors for trig?
- From: Stefan Reuther <stefan.news@xxxxxxxx>
- Date: Sat, 31 Mar 2007 20:42:00 +0200
Tauno Voipio wrote:
The MacLaurin series for a log (calculated for log(1 + x))
needs 5000 terms for 4 digits. Pick your favourite formula
collection and have a look.
5000 terms?
I recently needed an exp/log pair for a fixed-point DSP, and came up
with the equivalent of the following code (recited from memory), which
needs one loop iteration per mantissa bit.
// as many as you need, enlarge tables accordingly
#define BITS 10
// 2**-1 .. 2**-10
const double tab1[] = {
0.5,
0.25,
0.125,
0.0625,
0.03125,
0.015625,
0.0078125,
0.00390625,
0.001953125,
0.0009765625,
};
// base ** tab1[i]
const double tab2[] = {
1.4142135623731,
1.18920711500272,
1.09050773266526,
1.04427378242741,
1.02189714865412,
1.0108892860517,
1.0054299011128,
1.0027112750502,
1.00135471989211,
1.00067713069307,
};
// compute 2**a, for a \in [0,1).
double mypow(double a)
{
int i;
double result = 1.0;
for (i = 0; i < BITS; ++i) {
if (a >= tab1[i]) {
result *= tab2[i];
a -= tab1[i];
}
}
return result;
}
// compute ld(a) for a \in [0.5, 1]
double mylog(double a)
{
int i;
double result = 0.0;
for (i = 0; i < BITS; ++i) {
// a inverse-of-tab2 table could be handy here
if (a <= 1.0 / tab2[i]) {
a *= tab2[i];
result -= tab1[i];
}
}
return result;
}
The good thing is that this works for all bases and scales (e.g. also
for converting decibels into levels and back), and only uses operations
easily available in a fixed-point DSP.
Maybe it can be done faster, but at least I'm faster than using my
compiler's runtime library, and I'm nowhere near 5000 terms.
Stefan
.
- References:
- Best processors for trig?
- From: Mike Noone
- Re: Best processors for trig?
- From: Tim Wescott
- Re: Best processors for trig?
- From: larwe
- Re: Best processors for trig?
- From: Tauno Voipio
- Re: Best processors for trig?
- From: Paul Keinanen
- Re: Best processors for trig?
- From: Tauno Voipio
- Best processors for trig?
- Prev by Date: Re: where is the FAQ for this group please
- Next by Date: Re: Best processors for trig?
- Previous by thread: Re: Best processors for trig?
- Next by thread: Re: Best processors for trig?
- Index(es):
Relevant Pages
|