DSPRelated.com
Forums

6.3121 in fixed point?

Started by Luis Fernando October 29, 2004
Bank-to-Turn <Bank-to-Turn@mchsi.com> wrote in message news:<at45o0ptg7292r65o4tlk09fotlu9ei5ks@4ax.com>...
> On 29 Oct 2004 07:47:13 -0700, wavebox@wavebox.com.br (Luis > Fernando) wrote: > > >>i'm working with a motorola that can represent 1.15 fixed-point numbers > >> > >>any ideas on how can I multiply a number by 6.3121? > > 6.3121 = 4 + 2 + 0.3121 > > Multiply by 4 = left shift twice > > Multiply by 2 = left shift once > > 0.3121 = 0x4FE6 in 1.15 fixed > > or > > Multiply by 0.7890125, then left-shift three times
GREETINGS, I've tried the above method in GUI56600 (Motorola's simulator) by using the following values: Fractional Value = 0.10 = 0x0CCD (Q1.15 format or Q.15 format) Scale Factor = 6.3121 Expected result = 0.63121000000000 (in Q1.15 format) EXPRIMENT: Multiplication with Integer Part a. left shift (0x0CCD) three times for interger part 6. b. add 0.3121 (0x27F3) the fractional part Result = 0x8E5B (in hex) = 36443 (in decimal) = 36443/(2^15) = 0.55607604980469 (in fractional form Q1.15 format) why the result is not exactly the same as expected? What goes wrong? Any comments? Thanks Argon
On 2 Nov 2004 00:21:54 -0800, argon_gold@hotmail.com wrote:

>>I've tried the above method in GUI56600 (Motorola's simulator) by >>using the following values: >>Fractional Value = 0.10 = 0x0CCD (Q1.15 format or Q.15 format) >>Scale Factor = 6.3121 >>Expected result = 0.63121000000000 (in Q1.15 format) >> >>EXPRIMENT: >>Multiplication with Integer Part >>a. left shift (0x0CCD) three times for interger part 6.
If you left shift three times, you multiply by 8, not 6.
>>b. add 0.3121 (0x27F3) the fractional part
Let me make certain that I understand what you did ... You multiplied 0.1 by 8, then added 0.3121? How is that in any way like multiplying 0.1 by 6.3121?
>>Result = 0x8E5B (in hex) = 36443 (in decimal) = 36443/(2^15) = >>0.55607604980469 (in fractional form Q1.15 format) >> >>why the result is not exactly the same as expected? >>What goes wrong? Any comments?
I assume that you are trying to implement the second method that I suggested ("Multiply by 0.7890125, then left-shift three times"): The number "0.7890125" is equal to 6.3121/8. So what you need to do is FIRST multiply 0x0CCD (0.10 decimal) by 0x64FE (0.7890125 decimal), yielding 0x050CC766 (0.078904962 decimal), THEN left shift three times to get 0x28663B30 (0.631239697 decimal). This is equivalent to FIRST multiplying by (6.3121/8), and THEN multiplying by 8. Maintain as many bits in the accumulator as possible, else you'll lose precision in the left shift. Greg Berchin
Bank-to-Turn <Bank-to-Turn@mchsi.com> wrote in message news:<f44fo0p77uoc0l3qimlgo7t0djlorseves@4ax.com>...
> On 2 Nov 2004 00:21:54 -0800, argon_gold@hotmail.com wrote: > > >>I've tried the above method in GUI56600 (Motorola's simulator) by > >>using the following values: > >>Fractional Value = 0.10 = 0x0CCD (Q1.15 format or Q.15 format) > >>Scale Factor = 6.3121 > >>Expected result = 0.63121000000000 (in Q1.15 format) > >> > >>EXPRIMENT: > >>Multiplication with Integer Part > >>a. left shift (0x0CCD) three times for interger part 6. > > If you left shift three times, you multiply by 8, not 6. > > >>b. add 0.3121 (0x27F3) the fractional part > > Let me make certain that I understand what you did ... > > You multiplied 0.1 by 8, then added 0.3121? How is that in any > way like multiplying 0.1 by 6.3121? > > >>Result = 0x8E5B (in hex) = 36443 (in decimal) = 36443/(2^15) = > >>0.55607604980469 (in fractional form Q1.15 format) > >> > >>why the result is not exactly the same as expected? > >>What goes wrong? Any comments? > > I assume that you are trying to implement the second method that I > suggested ("Multiply by 0.7890125, then left-shift three times"): > > The number "0.7890125" is equal to 6.3121/8. So what you need to > do is FIRST multiply 0x0CCD (0.10 decimal) by 0x64FE (0.7890125 > decimal), yielding 0x050CC766 (0.078904962 decimal), THEN left > shift three times to get 0x28663B30 (0.631239697 decimal). This > is equivalent to FIRST multiplying by (6.3121/8), and THEN > multiplying by 8. Maintain as many bits in the accumulator as > possible, else you'll lose precision in the left shift. > > Greg Berchin
Thanks for a clear explanation..... This time it works... Argon