DSPRelated.com
Forums

fixed point to integer conversion

Started by raj June 28, 2008
Hai,

I have one fixed point number generated using FDAtool
=0.0593719482421875.

FDAtool report equivalent of the above in 16-bit signed integer using
const int16 data type as
=3891 (using generate header file option)

My first question is whether 0.0593719482421875 is equivalent to 3891?

To verify that:

I have written a MATLAB code

x1=[ 0.0593719482421875 ];

a= fi(x1);
outfile1 = fopen('samples_in.txt','w');
result=a.int;
fprintf( outfile1, '%d\n',result );
  fclose(outfile1);

it is giving as 31128 but i am expecting like answer like fdatool
i.e., 3891..


My second question is:
whether my code is not giving proper integer value or the tool?
Basically i am trying to convert fixed point to integer using MATLAB
code like FDAtool?

Can anyone help me in this issue.

regards,
raj.
raj schrieb:
> I have one fixed point number generated using FDAtool > =0.0593719482421875. > > FDAtool report equivalent of the above in 16-bit signed integer using > const int16 data type as > =3891 (using generate header file option) > > My first question is whether 0.0593719482421875 is equivalent to 3891?
16-bit fixed point means that your value (3891) is defined as multiples of 1/(2^16) = 1/65536. 3891 * 1/65536 = 0.0593719482421875 Hendrik vdH
NTG

Try to ask in proper place:

comp.soft-sys.matlab


-- 
Mikolaj
Hai,

FDAtool converts fixed point to integer as:

3891 * 1/65536 = 0.0593719482421875

I also want to do the same using MATLAB code.For that I have written a
MATLAB code:

x1=[ 0.0593719482421875 ];

a= fi(x1);
outfile1 = fopen('samples_in.txt','w');
result=a.int;
fprintf( outfile1, '%d\n',result );
  fclose(outfile1);

it is giving as 31128 but i am expecting like answer like fdatool
i.e., 3891..


how a.int will convert fixed point number to integer?will it not do
like fdatool?
what is the change i have to do in my code to achieve this task?

Can anyone help me in this issue.

regards,
raj.



On Jun 28, 6:03&#4294967295;pm, Hendrik van der Heijden <h...@gmx.de> wrote:
> raj schrieb: > > > I have one fixed point number generated using FDAtool > > =0.0593719482421875. > > > FDAtool report equivalent of the above in 16-bit signed integer using > > const int16 data type as > > =3891 (using generate header file option) > > > My first question is whether 0.0593719482421875 is equivalent to 3891? > > 16-bit fixed point means that your value (3891) is defined as > multiples of 1/(2^16) = 1/65536. > > 3891 * 1/65536 = 0.0593719482421875 > > Hendrik vdH
raj wrote:
> Hai, > > FDAtool converts fixed point to integer as: > > 3891 * 1/65536 = 0.0593719482421875 > > I also want to do the same using MATLAB code.For that I have written a > MATLAB code: > > x1=[ 0.0593719482421875 ]; > > a= fi(x1); > outfile1 = fopen('samples_in.txt','w'); > result=a.int; > fprintf( outfile1, '%d\n',result ); > fclose(outfile1); > > it is giving as 31128 but i am expecting like answer like fdatool > i.e., 3891.. > > > how a.int will convert fixed point number to integer?will it not do > like fdatool? > what is the change i have to do in my code to achieve this task? > > Can anyone help me in this issue. > > regards, > raj. > > > > On Jun 28, 6:03 pm, Hendrik van der Heijden <h...@gmx.de> wrote: >> raj schrieb: >> >>> I have one fixed point number generated using FDAtool >>> =0.0593719482421875. >>> FDAtool report equivalent of the above in 16-bit signed integer using >>> const int16 data type as >>> =3891 (using generate header file option) >>> My first question is whether 0.0593719482421875 is equivalent to 3891? >> 16-bit fixed point means that your value (3891) is defined as >> multiples of 1/(2^16) = 1/65536. >> >> 3891 * 1/65536 = 0.0593719482421875 >> >> Hendrik vdH
You got a good answer and ignored it. Do we have some reason to suppose that repeating that answer would be helpful? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
hai,
You got a good answer and ignored it
I got the answer for my first question that FDAtool generation fixed
point and integer numbers are equal by
3891 * 1/65536 = 0.0593719482421875


But still no one answered how to get the same using MATLAB code "fi"
command and a.int..

pls clarify...

regards,
raj


On Jun 28, 10:41&#4294967295;pm, Jerry Avins <j...@ieee.org> wrote:
> raj wrote: > > Hai, > > > FDAtool converts fixed point to integer as: > > > 3891 * 1/65536 = 0.0593719482421875 > > > I also want to do the same using MATLAB code.For that I have written a > > MATLAB code: > > > x1=[ 0.0593719482421875 ]; > > > a= fi(x1); > > outfile1 = fopen('samples_in.txt','w'); > > result=a.int; > > fprintf( outfile1, '%d\n',result ); > > &#4294967295; fclose(outfile1); > > > it is giving as 31128 but i am expecting like answer like fdatool > > i.e., 3891.. > > > how a.int will convert fixed point number to integer?will it not do > > like fdatool? > > what is the change i have to do in my code to achieve this task? > > > Can anyone help me in this issue. > > > regards, > > raj. > > > On Jun 28, 6:03 pm, Hendrik van der Heijden <h...@gmx.de> wrote: > >> raj schrieb: > > >>> I have one fixed point number generated using FDAtool > >>> =0.0593719482421875. > >>> FDAtool report equivalent of the above in 16-bit signed integer using > >>> const int16 data type as > >>> =3891 (using generate header file option) > >>> My first question is whether 0.0593719482421875 is equivalent to 3891? > >> 16-bit fixed point means that your value (3891) is defined as > >> multiples of 1/(2^16) = 1/65536. > > >> 3891 * 1/65536 = 0.0593719482421875 > > >> Hendrik vdH > > You got a good answer and ignored it. Do we have some reason to suppose > that repeating that answer would be helpful? > > Jerry > -- > Engineering is the art of making what you want from things you can get. > &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Jun 28, 1:41 pm, Jerry Avins <j...@ieee.org> wrote:
...
> >>> FDAtool report equivalent of the above in 16-bit signed integer using > >>> const int16 data type as > >>> =3891 (using generate header file option) > >>> My first question is whether 0.0593719482421875 is equivalent to 3891? > >> 16-bit fixed point means that your value (3891) is defined as > >> multiples of 1/(2^16) = 1/65536. > > >> 3891 * 1/65536 = 0.0593719482421875 >
...
> > You got a good answer and ignored it. Do we have some reason to suppose > that repeating that answer would be helpful?
one thing wrong about the answer (and question) is that for 16-bit *signed* fixed to integer conversion, it's not 1/(2^16) = 1/65536, but 1/(2^15) = 1/32768 . r b-j
"raj" <rajesh.obli@gmail.com> wrote in message
news:38f3cb3c-47e0-4f8c-a57f-18469842a40f@t12g2000prg.googlegroups.com...
still i am waiting for the correct procedure to convert from fixed
point to integer..

Wow, what a demanding pitch. Do it yourself, imbecile.

VLV




On Jun 29, 12:17 am, Vladimir Vassilevsky <antispam_bo...@hotmail.com>
wrote:
> robert bristow-johnson wrote: > > one thing wrong about the answer (and question) is that for 16-bit > > *signed* fixed to integer conversion, it's not 1/(2^16) = 1/65536, > > but 1/(2^15) = 1/32768 . > > With integers, there is a problem with -32768 but +32767. For that > matter, I prefer the scale factors of 2^N - 1. > > Vladimir Vassilevsky > DSP and Mixed Signal Design Consultanthttp://www.abvolt.com

robert bristow-johnson wrote:


> one thing wrong about the answer (and question) is that for 16-bit > *signed* fixed to integer conversion, it's not 1/(2^16) = 1/65536, > but 1/(2^15) = 1/32768 .
With integers, there is a problem with -32768 but +32767. For that matter, I prefer the scale factors of 2^N - 1. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
still i am waiting for the correct procedure to convert from fixed
point to integer..



On Jun 29, 12:17&#4294967295;am, Vladimir Vassilevsky <antispam_bo...@hotmail.com>
wrote:
> robert bristow-johnson wrote: > > one thing wrong about the answer (and question) is that for 16-bit > > *signed* fixed to integer conversion, it's not &#4294967295;1/(2^16) = 1/65536, > > but &#4294967295;1/(2^15) = 1/32768 . > > With integers, there is a problem with -32768 but +32767. For that > matter, I prefer the scale factors of 2^N - 1. > > Vladimir Vassilevsky > DSP and Mixed Signal Design Consultanthttp://www.abvolt.com