Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21611 Discussions

fixed point precision

Altera_Forum
Honored Contributor II
1,585 Views

Peace! 

I want ask about the number of bits shoud I use in an fixed_point number to obtein the good precision, precision of distance eclidean. 

some detail: 

I want to determine an vector of foor element VECT[MOY1,MOY2,MOY3,MOY4], each element is the moyen of one quart of matrix of (64*64),  

the matrix' element value varies (0-255)'''it's pixel valor'''  

--> the result of division (MOY1=SUM/Nbits) has 8 bits in the integer part; 

Question: how many bits of fractional part shout I use to get the good result (result of euclidean distance between two vector VECT1[MOY11,MOY12,MOY13,MOY14] and VECT[MOY21,MOY22,MOY23,MOY24]).. thank you....peace:
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
599 Views

If you sum N digital values you generally need log2(N) (approximate to the next integer) more bits to store the result. Otherwise you possibly overflow the sum or lose information. 

The same applies to the average of N values: you need log2(N) more bits if you want to have the full precision; consider, for example, that any division by 2 introduces one more decimal bit.
0 Kudos
Altera_Forum
Honored Contributor II
599 Views

thank you Cris72! 

 

I divide 18 bits by "10000000000" //1024//, I want to keep a big part of information 

 

consider that the integer part of the division result id coded in 8 bit (varies from 0 to 255), 

how many of bits shoud Allocated to the fractional part so I keep big part of information.
0 Kudos
Altera_Forum
Honored Contributor II
599 Views

your division just needs discarding 10 lsb bits from 18 so you are left with 8 bits. If you want to keep fractional bits then just don't divide as the 10 lsbs is the fractional bits. so I don't really get it.

0 Kudos
Altera_Forum
Honored Contributor II
599 Views

so 10 bits in fractional part assure the big part of information 

..thank you Kaz !
0 Kudos
Reply