PDA

View Full Version : fixed point exp10(x)


10-03-2005, 07:40 PM
Hello All,


Can anyone please help me in implementing exp10(x) in a fixed point C.
I need to convert a dB value ( 0 to 50 dB) to linear domain value. This
is for a 16-bit DSP application.


Thanks and Regards,

Patrick

Adrian Spilca
10-05-2005, 05:07 PM
[email protected] wrote:

> Hello All,
>
>
> Can anyone please help me in implementing exp10(x) in a fixed point C.
> I need to convert a dB value ( 0 to 50 dB) to linear domain value. This
> is for a 16-bit DSP application.
>
>
> Thanks and Regards,
>
> Patrick


If it's no time constraint then it's trivial, so I suspect it is student
homework.

If it is, then you might need somebody with function approximation
experience, would you consider paying for the job?

Adrian

Bob
10-05-2005, 05:34 PM
<[email protected]> wrote in message
news:[email protected] oups.com...
> Hello All,
>
> Can anyone please help me in implementing exp10(x) in a fixed point C.
> I need to convert a dB value ( 0 to 50 dB) to linear domain value. This
> is for a 16-bit DSP application.
>
> Thanks and Regards,
>
> Patrick

easy.

outputVal = exp10Table[ inputVal ];

very fast, too.

Of course, exp10Table will consume 128k bytes. Is that a problem? ;-)
If you can spare the time for a MAC or two (or three), the lookup tables can
be *tiny*. The first step in coding any integer approximation function is
usually writing the desired function using floating point. (You'll need to
test your integer code against it.)

e.g.
int16 LibFunc( int16 inVal )
{ return (int)( 65535* whateverFunction((float)(inVal) / 256.0)); }

Bob

10-05-2005, 05:45 PM
Adrian, thanks for reply.
I was hoping someone in this group had run into this problem before and
may be willing to discuss any issues/difficulty on the complexity and
precision.
It is for a real time application but doesnt have to be super fast (to
be written in C). I am looking for advice/pointers to tackle the
problem and I will do the simulation my self. Sorry if I sounds like a
cheap person trying to look for freebee on the net.
Currently I plan to use the 2nd order polynomial approximation but not
happy with the max. error.

Patrick

Adrian Spilca
10-05-2005, 06:44 PM
Bob wrote:

> <[email protected]> wrote in message
> news:[email protected] oups.com...
>> Hello All,
>>
>> Can anyone please help me in implementing exp10(x) in a fixed point C.
>> I need to convert a dB value ( 0 to 50 dB) to linear domain value. This
>> is for a 16-bit DSP application.
>>
>> Thanks and Regards,
>>
>> Patrick
>
> easy.
>
> outputVal = exp10Table[ inputVal ];
>
> very fast, too.
>
> Of course, exp10Table will consume 128k bytes. Is that a problem? ;-)
> If you can spare the time for a MAC or two (or three), the lookup tables
> can be *tiny*. The first step in coding any integer approximation function
> is usually writing the desired function using floating point. (You'll need
> to test your integer code against it.)
>
> e.g.
> int16 LibFunc( int16 inVal )
> { return (int)( 65535* whateverFunction((float)(inVal) / 256.0)); }
>
> Bob

Not quite integer... Patrick was talking about fixed point.
And in the second post he mentioned "precision", 128 values might not be
enough.

But the table method is not a bad idea, I was actually thinking about table
lookup and interpolation.

Adrian

10-05-2005, 06:59 PM
Hi
What polynomial are you using for approximation? You are better off
using the Chebyshev polynomial which has the minmax property (minimizes
the maximum error). But of course the problem is that the Chebyshev
polynomial is based on non-uniform sampling points and if your samples
are uniformly sampled then you would notice a slightly different error
pattern than the theoretical one.

You can take a look at some of the approximation results
(unfortunately only exp(x) can be found) that I have done for various
functions using chebyshev polynomial. the plots show the performance of
both fixed point (Q-15 or Q31) and floating-point(double precision). I
have used Horner's algoithm in this case to implement the polynomial.

http://utdallas.edu/~nithinr/EE6481_project_report.doc

I had done this a while back. I have seen that if you use the least
squares approximation the error is much 'noisier' (oscillatory pattern)
but the max. error is higher.

Hope this helps
Nithin

[email protected] wrote:
> Adrian, thanks for reply.
> I was hoping someone in this group had run into this problem before and
> may be willing to discuss any issues/difficulty on the complexity and
> precision.
> It is for a real time application but doesnt have to be super fast (to
> be written in C). I am looking for advice/pointers to tackle the
> problem and I will do the simulation my self. Sorry if I sounds like a
> cheap person trying to look for freebee on the net.
> Currently I plan to use the 2nd order polynomial approximation but not
> happy with the max. error.
>
> Patrick

Bob
10-05-2005, 07:24 PM
"Adrian Spilca" <adsp40@spamGuard_yahoo.co.uk> wrote in message
news:[email protected]...
> Bob wrote:
>
> > <[email protected]> wrote in message
> > news:[email protected] oups.com...
> >> Hello All,
> >>
> >> Can anyone please help me in implementing exp10(x) in a fixed point C.
> >> I need to convert a dB value ( 0 to 50 dB) to linear domain value. This
> >> is for a 16-bit DSP application.
> >>
> >> Thanks and Regards,
> >>
> >> Patrick
> >
> > easy.
> >
> > outputVal = exp10Table[ inputVal ];
> >
> > very fast, too.
> >
> > Of course, exp10Table will consume 128k bytes. Is that a problem? ;-)
> > If you can spare the time for a MAC or two (or three), the lookup tables
> > can be *tiny*. The first step in coding any integer approximation
function
> > is usually writing the desired function using floating point. (You'll
need
> > to test your integer code against it.)
> >
> > e.g.
> > int16 LibFunc( int16 inVal )
> > { return (int)( 65535* whateverFunction((float)(inVal) / 256.0)); }
> >
> > Bob
>
> Not quite integer... Patrick was talking about fixed point.
> And in the second post he mentioned "precision", 128 values might not be
> enough.
>
> But the table method is not a bad idea, I was actually thinking about
table
> lookup and interpolation.
>
> Adrian
Hi Adrian,
Yes, I made some pretty wild assumptions since Patrick hasn't really defined
the problem (how many bits wide and where is the radix of the input and
output? How much error is tolerable? How many MACs can he afford?). If you
assume 16bit in and 16bit out (doesn't matter what the bits represent -
fixed, float, Spanish, etc.) then a 64k*2byte table *will* do it in a single
lookup op. You'ld have to be awfully short on time and long on space to do
it that way, though ;-)

Bob
hint to Patrick: convert your dB to bB (binaryBell - not deciBell). The exp2
is easier than exp10 in a binary world.