On Sat, 6 Dec 2003 07:14:29 +1300, Bevan Weiss wrote:
>
> "Phil Frisbie, Jr." <phil@hawksoft.com> wrote in message
> news:Gd3Ab.911$XF6.22096@typhoon.sonic.net...
>> 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
Reply by Phil Frisbie, Jr.●December 5, 20032003-12-05
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
> 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;
In my world, 3*PI/8 comes out to 67.5 degrees. Take it from there.
Jerry
--
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������
Reply by Bevan Weiss●December 5, 20032003-12-05
"Phil Frisbie, Jr." <phil@hawksoft.com> wrote in message
news:Gd3Ab.911$XF6.22096@typhoon.sonic.net...
> 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.
Reply by Clay S. Turner●December 5, 20032003-12-05
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" <prussell@sonic.net> wrote in message
news:4q3Ab.916$XF6.21919@typhoon.sonic.net...
> 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
>
Reply by Jerry Avins●December 5, 20032003-12-05
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
>
> -vijay
From the gist, I guess that you don't use floating point.
0.5/cos(3*PI/8) is just a constant; about 1.3065623. If you sat what
precision you need and how much time you can spend, I or someone else
might be able to suggest something. How about an intermediate 32-bit
product and a division?
Jerry
--
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������
Reply by Paul Russell●December 5, 20032003-12-05
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
Reply by Phil Frisbie, Jr.●December 5, 20032003-12-05
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;
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