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