PDA

View Full Version : fixed point implementation


n_vijay_anand
12-05-2003, 11:32 AM
Hi,

i want to implement the equation

p3 = p3*0.5/cos(3*PI/8);

into 16bit processor, where p3 is a 16 bit value;

any pointers as to how to go about it

-vijay

Phil Frisbie, Jr.
12-05-2003, 05:27 PM
n_vijay_anand wrote:

> Hi,
>
> i want to implement the equation
>
> p3 = p3*0.5/cos(3*PI/8);
>
> into 16bit processor, where p3 is a 16 bit value;
>
> any pointers as to how to go about it

It looks like '0.5/cos(3*PI/8)' is a constant, so simplify it.

cos(3*PI/8) = 0.99978861
0.5/0.99978861 = 0.50010571

Depending on the algorithm you might get away with simply dividing by 2:

p3 >>= 1;

> -vijay

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

Paul Russell
12-05-2003, 05:40 PM
Phil Frisbie, Jr. wrote:
>
> It looks like '0.5/cos(3*PI/8)' is a constant, so simplify it.
>
> cos(3*PI/8) = 0.99978861
> 0.5/0.99978861 = 0.50010571
>

Time to put new batteries in your calculator ? ;-)

Paul

Clay S. Turner
12-05-2003, 06:08 PM
No the batteries are okay, he just needs to switch over to radian mode.

The constant should be more like 1.3065629649 (10 places anyway)

Clay



"Paul Russell" <[email protected]> wrote in message
news:[email protected]...
> Phil Frisbie, Jr. wrote:
> >
> > It looks like '0.5/cos(3*PI/8)' is a constant, so simplify it.
> >
> > cos(3*PI/8) = 0.99978861
> > 0.5/0.99978861 = 0.50010571
> >
>
> Time to put new batteries in your calculator ? ;-)
>
> Paul
>

Bevan Weiss
12-05-2003, 06:14 PM
"Phil Frisbie, Jr." <[email protected]> wrote in message
news:[email protected]...
> n_vijay_anand wrote:
>
> > Hi,
> >
> > i want to implement the equation
> >
> > p3 = p3*0.5/cos(3*PI/8);
> >
> > into 16bit processor, where p3 is a 16 bit value;
> >
> > any pointers as to how to go about it
>
> It looks like '0.5/cos(3*PI/8)' is a constant, so simplify it.
>
> cos(3*PI/8) = 0.99978861
> 0.5/0.99978861 = 0.50010571
>
> Depending on the algorithm you might get away with simply dividing by 2:
>
> p3 >>= 1;

I think that you got ya radians/degrees mixed on the calc.
Try it in radian measure and you should get cos(3*PI/8) = 0.382683
thus 0.5/cos(3*PI/8) = 1.306563
So a basic multiplication by 1.306563 should do the trick...

If you're going to have to use cos/sin with a variable argument in other
parts of your code then it may be worth just using a lookup table for the
sinusoidal functions and doing the maths using some basic fixed point
library, it would make the code a little easier to read, though would make
coding it a little harder to start with.

Phil Frisbie, Jr.
12-05-2003, 10:24 PM
Clay S. Turner wrote:

> No the batteries are okay, he just needs to switch over to radian mode.

Yes, my son must have switched it and I did not notice! I always leave it in
radian mode because I use C, but my son's homework is almost always in degrees....

> The constant should be more like 1.3065629649 (10 places anyway)
>
> Clay

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

Andrew Reilly
12-08-2003, 06:05 AM
On Sat, 6 Dec 2003 07:14:29 +1300, Bevan Weiss wrote:
>
> "Phil Frisbie, Jr." <[email protected]> wrote in message
> news:[email protected]...
>> n_vijay_anand wrote:
>>
>> > Hi,
>> >
>> > i want to implement the equation
>> >
>> > p3 = p3*0.5/cos(3*PI/8);
>> >
>> > into 16bit processor, where p3 is a 16 bit value;
>> >
>> > any pointers as to how to go about it
>>
>> It looks like '0.5/cos(3*PI/8)' is a constant, so simplify it.
>>
>> cos(3*PI/8) = 0.99978861
>> 0.5/0.99978861 = 0.50010571
>>
>> Depending on the algorithm you might get away with simply dividing by 2:
>>
>> p3 >>= 1;
>
> I think that you got ya radians/degrees mixed on the calc.
> Try it in radian measure and you should get cos(3*PI/8) = 0.382683
> thus 0.5/cos(3*PI/8) = 1.306563
> So a basic multiplication by 1.306563 should do the trick...

To add a little for the OP:

Many 16-bit DSPs can't (easily) express 1.306563 as a
multiplicand, so you might have to multiply by (1.306563/2.0)
and then multiply the result by two, perhaps by arithmetic
left-shifting the accumulator, which will preserve an extra bit
of precision.

--
Andrew