Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Quantization

 
Thread Tools Search this Thread
Old 11-05-2009, 11:32 AM   #1
Default Quantization


Hi Dear
I am working on quantization, for this I need to divide two signed
numbers. The procedure I am using is working fine for most of the
input data but with some values results are not correct. Please
suggest me the remedy. The procedure I am using is as follows:

I. 33/22 = 1.5 =~ 2

II. 33*512\22*512

III. (33 * 23)/512 ( as 512/22 = 23.2 =~ 23)

IV. Binary representation of 33*22 (1011110111) is shifted by nine
bits right (SRA Shift right arithematic) to divide by 512 & if the
last shifted bit i.e. ninth bit is one then result is incremented by
one else leave it as such.

V. In this particular case as ninth bit is 0 thus I did not increment
the result & get the result as one which actually should be two.

It will be a great favor if anybody can help me out.


Thanks & regards
Ashwani


ashu
  Reply With Quote
Old 11-06-2009, 08:34 AM   #2
Pascal Peyremorte
 
Posts: n/a
Default Re: Quantization
ashu a écrit :
> Hi Dear
> I am working on quantization, for this I need to divide two signed
> numbers. The procedure I am using is working fine for most of the
> input data but with some values results are not correct. Please
> suggest me the remedy. The procedure I am using is as follows:
>
> I. 33/22 = 1.5 =~ 2
>
> II. 33*512\22*512
>
> III. (33 * 23)/512 ( as 512/22 = 23.2 =~ 23)
>
> IV. Binary representation of 33*22 (1011110111) is shifted by nine
> bits right (SRA Shift right arithematic) to divide by 512 & if the
> last shifted bit i.e. ninth bit is one then result is incremented by
> one else leave it as such.
>
> V. In this particular case as ninth bit is 0 thus I did not increment
> the result & get the result as one which actually should be two.
>
> It will be a great favor if anybody can help me out.



Hi,

This is due to the rounding done when you assimilate 512/22 = 23 instead of 23.2

If you look at the binary representation of 33*23, you will found :
1 011110111 (instead of 1 100000000 that is the real value of 1.5 * 512)

Checking only 1 bit make you to round 011110111 to zero instead to 100000000 and report that error in your result.


A better solution to make a right rounding is to add half the divisor to the dividend before doing the division.

You will get (33*23 + 256) / 512 that will give you 2 after the integer division.

Pascal





Pascal Peyremorte
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46