FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > DSP

DSP comp.dsp newsgroup, mailing list

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2008, 02:35 PM
raj
Guest
 
Posts: n/a
Default fixed point to integer conversion

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.
Reply With Quote
  #2 (permalink)  
Old 06-28-2008, 03:03 PM
Hendrik van der Heijden
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

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
Reply With Quote
  #3 (permalink)  
Old 06-28-2008, 04:23 PM
Mikolaj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

NTG

Try to ask in proper place:

comp.soft-sys.matlab


--
Mikolaj
Reply With Quote
  #4 (permalink)  
Old 06-28-2008, 04:51 PM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

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


Reply With Quote
  #5 (permalink)  
Old 06-28-2008, 07:41 PM
Jerry Avins
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

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.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Reply With Quote
  #6 (permalink)  
Old 06-28-2008, 08:17 PM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

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*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 );
> > * 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.
> ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ


Reply With Quote
  #7 (permalink)  
Old 06-28-2008, 09:04 PM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

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
Reply With Quote
  #8 (permalink)  
Old 06-28-2008, 09:13 PM
Vladimir Vassilevsky
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion


"raj" <[email protected]> wrote in message
news:[email protected]...
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



Reply With Quote
  #9 (permalink)  
Old 06-28-2008, 09:17 PM
Vladimir Vassilevsky
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion



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
Reply With Quote
  #10 (permalink)  
Old 06-28-2008, 09:38 PM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

still i am waiting for the correct procedure to convert from fixed
point to integer..



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


Reply With Quote
  #11 (permalink)  
Old 06-28-2008, 09:44 PM
Randy Yates
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

raj <[email protected]> writes:

> still i am waiting for the correct procedure to convert from fixed
> point to integer..


Multiply by 2^b, where b is your scaling factor. So, for your number,
b = 16, and

0.0593719482421875 * 2^16 = 3891.
--
% Randy Yates % "She tells me that she likes me very much,
%% Fuquay-Varina, NC % but when I try to touch, she makes it
%%% 919-577-9882 % all too clear."
%%%% <[email protected]> % 'Yours Truly, 2095', *Time*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #12 (permalink)  
Old 06-28-2008, 10:19 PM
Jerry Avins
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

raj wrote:
> still i am waiting for the correct procedure to convert from fixed
> point to integer..


Fixed point is integer with a scaling factor in the programmer's mind.
Read http://www.digitalsignallabs.com/fp.pdf.

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Reply With Quote
  #13 (permalink)  
Old 06-28-2008, 10:25 PM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

Hai,

thanks for your clarification.My problem is i have the following sine
wave generation:
Fs =17;
fin1 = 5;
Ts=1/Fs;
t = 0 : Ts : 1-Ts;
n=length(t);
x1= 3.5 * sin(2*pi*fin1*t)

x1 =

0 -3.4122 1.5186 2.7364 -2.7364 -1.5186 3.4122


Now i am converting float to fixed data by

a=fi(x1) % quantized form of above (Is this
required?)

a =

0 -3.4122 1.5186 2.7365 -2.7365 -1.5186 3.4122

I want to convert the above fixed to integer.....what should i do
without loss of precision ?As It is not the multiple of 2^16 even if i
multiple the above values by 2^16 i will not get integers..


pls help for this challenging task

regards,
raj





On Jun 29, 12:44*am, Randy Yates <ya...@ieee.org> wrote:
> raj <rajesh.o...@gmail.com> writes:
> > still i am waiting for the correct procedure to convert from fixed
> > point to integer..

>
> Multiply by 2^b, where b is your scaling factor. So, for your number,
> b = 16, and
>
> * 0.0593719482421875 * 2^16 = 3891.
> --
> % *Randy Yates * * * * * * * * *% "She tells me that she likes me very much,
> %% Fuquay-Varina, NC * * * * * *% * * but when I try to touch, she makes it
> %%% 919-577-9882 * * * * * * * *% * * * * * ** * * * * * * *all too clear."
> %%%% <ya...@ieee.org> * * * * * % * * * *'Yours Truly, 2095', *Time*, ELO *http://www.digitalsignallabs.com




Reply With Quote
  #14 (permalink)  
Old 06-28-2008, 10:57 PM
Piergiorgio Sartor
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

raj wrote:

> a =
>
> 0 -3.4122 1.5186 2.7365 -2.7365 -1.5186 3.4122
>
> I want to convert the above fixed to integer.....what should i do
> without loss of precision ?As It is not the multiple of 2^16 even if i
> multiple the above values by 2^16 i will not get integers..


Then multiply by 10000 (10^4) and you'll get the integers.

bye,


--

piergiorgio
Reply With Quote
  #15 (permalink)  
Old 06-28-2008, 11:04 PM
Randy Yates
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

raj <[email protected]> writes:

> a =
>
> 0 -3.4122 1.5186 2.7365 -2.7365 -1.5186 3.4122
>
> even if i multiple the above values by 2^16 i will not get integers..


raj,

what is the result of a*65536? (do it in the Matlab command window)

> pls help for this challenging task


raj, if this is challenging, you're in the wrong field.
--
% Randy Yates % "Bird, on the wing,
%% Fuquay-Varina, NC % goes floating by
%%% 919-577-9882 % but there's a teardrop in his eye..."
%%%% <[email protected]> % 'One Summer Dream', *Face The Music*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #16 (permalink)  
Old 06-28-2008, 11:11 PM
Randy Yates
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

Randy Yates <[email protected]> writes:

> raj <[email protected]> writes:
>
>> a =
>>
>> 0 -3.4122 1.5186 2.7365 -2.7365 -1.5186 3.4122
>>
>> even if i multiple the above values by 2^16 i will not get integers..

>
> raj,
>
> what is the result of a*65536? (do it in the Matlab command window)


Also, read this:

http://www.mathworks.com/access/help...tonName=Search
--
% Randy Yates % "How's life on earth?
%% Fuquay-Varina, NC % ... What is it worth?"
%%% 919-577-9882 % 'Mission (A World Record)',
%%%% <[email protected]> % *A New World Record*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #17 (permalink)  
Old 06-28-2008, 11:38 PM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion


Hai,

I found it actually a=fi(x1) by default taking the wordlength=16 and
fraction=13..

so for a.int

so i should do -3.4122*8192..am i correct..??

regards,
fazal


On Jun 29, 2:11*am, Randy Yates <ya...@ieee.org> wrote:
> Randy Yates <ya...@ieee.org> writes:
> > raj <rajesh.o...@gmail.com> writes:

>
> >> a =

>
> >> * * * * *0 * -3.4122 * *1.5186 * *2.7365 * -2.7365 * -1.5186 * *3.4122

>
> >> even if i multiple the above values by 2^16 i will not get integers..

>
> > raj,

>
> > what is the result of a*65536? (do it in the Matlab command window)

>
> Also, read this:
>
> *http://www.mathworks.com/access/help...ixedpoint/inde....
> --
> % *Randy Yates * * * * * * * * *% "How's life on earth?
> %% Fuquay-Varina, NC * * * * * *% *... What is it worth?"
> %%% 919-577-9882 * * * * * * * *% 'Mission (A World Record)',
> %%%% <ya...@ieee.org> * * * * * % *A New World Record*, ELOhttp://www.digitalsignallabs.com


Reply With Quote
  #18 (permalink)  
Old 06-29-2008, 12:21 AM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

On Jun 28, 3:17 pm, 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.


that'll make fixed-point multiplication a snap. how do you shift
right by log2(2^N-1) bits?

r b-j

Reply With Quote
  #19 (permalink)  
Old 06-29-2008, 04:04 AM
Randy Yates
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

raj <[email protected]> writes:

> Hai,
>
> I found it actually a=fi(x1) by default taking the wordlength=16 and
> fraction=13..


The default constructor creates a 16-bit integer, but "best-precision
fraction length" [1]. So the fraction length depends on the value you're
converting.

> so for a.int


a.int should return the very integer(s) you are seeking. In other
words, this whole thread is for naught if you would have simply
read the documentation.

> so i should do -3.4122*8192..am i correct..??


Read the documentation. If there's something specific you don't
understand in the manual, come back and ask here, or better, ask in
comp.soft-sys.matlab.
--
% Randy Yates % "How's life on earth?
%% Fuquay-Varina, NC % ... What is it worth?"
%%% 919-577-9882 % 'Mission (A World Record)',
%%%% <[email protected]> % *A New World Record*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #20 (permalink)  
Old 06-29-2008, 04:48 AM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

hai,

a=fi(x1)

a =

0 -3.4122 1.5186 2.7365 -2.7365 -1.5186
3.4122

DataTypeMode: Fixed-point: binary point scaling
Signed: true
WordLength: 16
FractionLength: 13

RoundMode: nearest
OverflowMode: saturate
ProductMode: FullPrecision
MaxProductWordLength: 128
SumMode: FullPrecision
MaxSumWordLength: 128
CastBeforeSum: true

a.int

ans =

0 27577 -15094 -19316 25666 5268 -28550 10358 22881 -22881


so to verify the above 3.4122*2^13=27576.7296

Is the above correct procedure to convert to integer.


regards,
raj
On Jun 29, 7:04*am, Randy Yates <ya...@ieee.org> wrote:
> raj <rajesh.o...@gmail.com> writes:
> > Hai,

>
> > I found it actually a=fi(x1) by default taking the wordlength=16 and
> > fraction=13..

>
> The default constructor creates a 16-bit integer, but "best-precision
> fraction length" [1]. So the fraction length depends on the value you're
> converting.
>
> > so for a.int

>
> a.int should return the very integer(s) you are seeking. In other
> words, this whole thread is for naught if you would have simply
> read the documentation.
>
> > so i should do *-3.4122*8192..am i correct..??

>
> Read the documentation. If there's something specific you don't
> understand in the manual, come back and ask here, or better, ask in
> comp.soft-sys.matlab.
> --
> % *Randy Yates * * * * * * * * *% "How's life on earth?
> %% Fuquay-Varina, NC * * * * * *% *... What is it worth?"
> %%% 919-577-9882 * * * * * * * *% 'Mission (A World Record)',
> %%%% <ya...@ieee.org> * * * * * % *A New World Record*, ELOhttp://www.digitalsignallabs.com


Reply With Quote
  #21 (permalink)  
Old 06-29-2008, 05:29 AM
Randy Yates
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

raj <[email protected]> writes:

> hai,
>
> a=fi(x1)
>
> a =
>
> 0 -3.4122 1.5186 2.7365 -2.7365 -1.5186
> 3.4122
>
> DataTypeMode: Fixed-point: binary point scaling
> Signed: true
> WordLength: 16
> FractionLength: 13
>
> RoundMode: nearest
> OverflowMode: saturate
> ProductMode: FullPrecision
> MaxProductWordLength: 128
> SumMode: FullPrecision
> MaxSumWordLength: 128
> CastBeforeSum: true
>
> a.int
>
> ans =
>
> 0 27577 -15094 -19316 25666 5268 -28550 10358 22881 -22881
>
>
> so to verify the above 3.4122*2^13=27576.7296
>
> Is the above correct procedure to convert to integer.


There's something wrong with your information. The first "a" vector you
print out has 7 scalar values, while the second (a.int) has 10. Without
having the vector lengths match, I can't take the scalar values themselves
seriously and thus can't help you.
--
% Randy Yates % "Maybe one day I'll feel her cold embrace,
%% Fuquay-Varina, NC % and kiss her interface,
%%% 919-577-9882 % til then, I'll leave her alone."
%%%% <[email protected]> % 'Yours Truly, 2095', *Time*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #22 (permalink)  
Old 06-29-2008, 10:05 AM
Mikolaj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

On 28-06-2008 at 23:11:42 Randy Yates <[email protected]> wrote:

> Randy Yates <[email protected]> writes:


(...)
> http://www.mathworks.com/access/help...tonName=Search


Here is a helpful website http://tinyurl.com/.

http://tinyurl.com/3lv43u

--
Mikolaj
Reply With Quote
  #23 (permalink)  
Old 06-30-2008, 08:18 AM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

Hai randy ,

Sorry for the mistake pls see the following:

x1= 3.5 * sin(2*pi*fin1*t)
a= fi(x1)
a*8192
a.int


x1 =



0 3.3664 -1.8425 -2.3579 3.1331 0.6431 -3.4851

a =


0 3.3663 -1.8425 -2.3579 3.1331 0.6431 -3.4851

DataTypeMode: Fixed-point: binary point scaling
Signed: true
WordLength: 16
FractionLength: 13

RoundMode: nearest
OverflowMode: saturate
ProductMode: FullPrecision
MaxProductWordLength: 128
SumMode: FullPrecision
MaxSumWordLength: 128
CastBeforeSum: true

ans =


0 27577 -15094 -19316 25666
5268 -28550


DataTypeMode: Fixed-point: binary point scaling
Signed: true
WordLength: 32
FractionLength: 14

RoundMode: nearest
OverflowMode: saturate
ProductMode: FullPrecision
MaxProductWordLength: 128
SumMode: FullPrecision
MaxSumWordLength: 128
CastBeforeSum: true


ans =


0 27577 -15094 -19316 25666 5268 -28550


I think now u can able to help me...whether the above conversion is
proper?I am finding mismatch here between wordlength and fraction
length....

so 3.3663*8192=27,576.7296(rounded to nearest as 27577)

As it is rounding to nearest value.. it means some information is
lost..this will ultimately affect the frequency response of the
sinewave which i am trying to generate?I am i correct?can i conclude
that it is not advisable to use integers to represent a signal?But
fixed point is tedious to implement in hardware?any alternative?


regards,
raj.



On Jun 29, 1:05*pm, Mikolaj
<sterowanie_komputer...@hahapoczta.onet.pl> wrote:
> On 28-06-2008 at 23:11:42 Randy Yates <ya...@ieee.org> wrote:
>
> > Randy Yates <ya...@ieee.org> writes:

>
> (...)
>
> > *http://www.mathworks.com/access/help...ixedpoint/inde...

>
> Here is a helpful websitehttp://tinyurl.com/.
>
> http://tinyurl.com/3lv43u
>
> --
> Mikolaj


Reply With Quote
  #24 (permalink)  
Old 07-01-2008, 01:51 AM
Randy Yates
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion

raj <[email protected]> writes:

> Hai randy ,
>
> Sorry for the mistake pls see the following:
>
> x1= 3.5 * sin(2*pi*fin1*t)
> a= fi(x1)
> a*8192
> a.int
>
>
> x1 =
>
>
>
> 0 3.3664 -1.8425 -2.3579 3.1331 0.6431 -3.4851
>
> a =
>
>
> 0 3.3663 -1.8425 -2.3579 3.1331 0.6431 -3.4851
>
> DataTypeMode: Fixed-point: binary point scaling
> Signed: true
> WordLength: 16
> FractionLength: 13
>
> RoundMode: nearest
> OverflowMode: saturate
> ProductMode: FullPrecision
> MaxProductWordLength: 128
> SumMode: FullPrecision
> MaxSumWordLength: 128
> CastBeforeSum: true
>
> ans =
>
>
> 0 27577 -15094 -19316 25666
> 5268 -28550
>
>
> DataTypeMode: Fixed-point: binary point scaling
> Signed: true
> WordLength: 32
> FractionLength: 14
>
> RoundMode: nearest
> OverflowMode: saturate
> ProductMode: FullPrecision
> MaxProductWordLength: 128
> SumMode: FullPrecision
> MaxSumWordLength: 128
> CastBeforeSum: true
>
>
> ans =
>
>
> 0 27577 -15094 -19316 25666 5268 -28550
>
>
> I think now u can able to help me...whether the above conversion is
> proper?I am finding mismatch here between wordlength and fraction
> length....
>
> so 3.3663*8192=27,576.7296(rounded to nearest as 27577)


Matlab represents numbers internally as 8-byte floating point
values. However, when displaying a number in the user interface (for
example, when you type "a" at the Matlab command line prompt, which,
since it doesn't end in a semicolon, will print the contents of "a" to
the screen), it uses a format that can be much more coarse. The format
can be changed with the "format" function. See the help on this
function.

So the internal value of a[2] is not really 3.3663, but something more
like

3.366333008...

That's why I asked you in an earlier post to see what you get when you
compute "a[2]*8192" on the command line - let Matlab compute the result
using the full resolution of the internal data representation. I think
you'll find that the result is almost exactly an integer.

Also, you're looking at things the wrong way. Don't try to compute
the "integer" value from the fi object's output. You have the integer
value available exactly as the .int property. Rather, compare the
values in your x1 vector with those in the a vector.

> As it is rounding to nearest value.. it means some information is
> lost..


With the correction I made above regarding the integer values, yes,
the a values have lost information from the x1 values. Welcome to
quantization. This is what quantizing a value does - it throws
away information.

> this will ultimately affect the frequency response of the
> sinewave which i am trying to generate?I am i correct?


Yes. Under certain assumptions it can be shown that quantizing
a value results in a wideband noise being added to it.

> can i conclude that it is not advisable to use integers to represent a
> signal?But fixed point is tedious to implement in hardware?any
> alternative?


No. The longer you make your integers (the long the word length is),
the less wideband noise that results.

I'm not sure what you mean by "tedios to implement." Generally,
fixed-point hardware implementations are simpler than floating point.

>
>
> regards,
> raj.
>
>
>
> On Jun 29, 1:05*pm, Mikolaj
> <sterowanie_komputer...@hahapoczta.onet.pl> wrote:
>> On 28-06-2008 at 23:11:42 Randy Yates <ya...@ieee.org> wrote:
>>
>> > Randy Yates <ya...@ieee.org> writes:

>>
>> (...)
>>
>> > *http://www.mathworks.com/access/help...ixedpoint/inde...

>>
>> Here is a helpful websitehttp://tinyurl.com/.
>>
>> http://tinyurl.com/3lv43u
>>
>> --
>> Mikolaj

>


--
% Randy Yates % "Maybe one day I'll feel her cold embrace,
%% Fuquay-Varina, NC % and kiss her interface,
%%% 919-577-9882 % til then, I'll leave her alone."
%%%% <[email protected]> % 'Yours Truly, 2095', *Time*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #25 (permalink)  
Old 07-01-2008, 09:30 AM
raj
Guest
 
Posts: n/a
Default Re: fixed point to integer conversion


Hai ,

I tried with the following as per your suggestions:

x1= 3.5 * sin(2*pi*fin1*t)

x1*8192

x1.int (error:Attempt to reference field of non-structure array.)


x1 =

1.0e-013 *


0 0.0815 0.1630 0.6175

ans =

1.0e-009 *

0 0.0668 0.1335 0.5058


why it is scaling here by 1.0e-013 * and 1.0e-009 *?


I dont know how to use .int without fixed..pls clarify....

regards,
raj




On Jul 1, 4:51*am, Randy Yates <ya...@ieee.org> wrote:
> raj <rajesh.o...@gmail.com> writes:
> > Hai randy ,

>
> > Sorry for the mistake pls see the following:

>
> > x1= 3.5 * sin(2*pi*fin1*t)
> > a= fi(x1)
> > a*8192
> > a.int

>
> > x1 =

>
> > * * * * *0 * *3.3664 * -1.8425 * -2.3579 * *3.1331* *0.6431 * -3.4851

>
> > a =

>
> > * * * * *0 * *3.3663 * -1.8425 * -2.3579 * *3.1331* *0.6431 * -3.4851

>
> > * *DataTypeMode: Fixed-point: binary point scaling
> > * * * * * * * * Signed: true
> > * * * * * * WordLength: 16
> > * * * * FractionLength: 13

>
> > * * * * * * *RoundMode: nearest
> > * * * * * OverflowMode: saturate
> > * * * * * *ProductMode: FullPrecision
> > * MaxProductWordLength: 128
> > * * * * * * * *SumMode: FullPrecision
> > * * * MaxSumWordLength: 128
> > * * * * *CastBeforeSum: true

>
> > ans =

>
> > * * * * * *0 * * * 27577 * * *-15094 * * *-19316 * * * 25666
> > 5268 *-28550

>
> > * DataTypeMode: Fixed-point: binary point scaling
> > * * * * * * * * Signed: true
> > * * * * * * WordLength: 32
> > * * * * FractionLength: 14

>
> > * * * * * * *RoundMode: nearest
> > * * * * * OverflowMode: saturate
> > * * * * * *ProductMode: FullPrecision
> > * MaxProductWordLength: 128
> > * * * * * * * *SumMode: FullPrecision
> > * * * MaxSumWordLength: 128
> > * * * * *CastBeforeSum: true

>
> > ans =

>
> > * * * 0 *27577 -15094 -19316 *25666 * 5268 -28550

>
> > I think now u can able to help me...whether the above conversion is
> > proper?I am finding mismatch here between wordlength and fraction
> > length....

>
> > so 3.3663*8192=27,576.7296(rounded to nearest as 27577)

>
> Matlab represents numbers internally as 8-byte floating point
> values. However, when displaying a number in the user interface (for
> example, when you type "a" at the Matlab command line prompt, which,
> since it doesn't end in a semicolon, will print the contents of "a" to
> the screen), it uses a format that can be much more coarse. The format
> can be changed with the "format" function. See the help on this
> function.
>
> So the internal value of a[2] is not really 3.3663, but something more
> like
>
> * 3.366333008...
>
> That's why I asked you in an earlier post to see what you get when you
> compute "a[2]*8192" on the command line - let Matlab compute the result
> using the full resolution of the internal data representation. I think
> you'll find that the result is almost exactly an integer.
>
> Also, you're looking at things the wrong way. Don't try to compute
> the "integer" value from the fi object's output. You have the integer
> value available exactly as the .int property. Rather, compare the
> values in your x1 vector with those in the a vector.
>
> > As it is rounding to nearest value.. it means some information is
> > lost..

>
> With the correction I made above regarding the integer values, yes,
> the a values have lost information from the x1 values. Welcome to
> quantization. This is what quantizing a value does - it throws
> away information.
>
> > this will ultimately affect the frequency response of the
> > sinewave which i am trying to generate?I am i correct?

>
> Yes. Under certain assumptions it can be shown that quantizing
> a value results in a wideband noise being added to it.
>
> > can i conclude that it is not advisable to use integers to represent a
> > signal?But fixed point is tedious to implement in hardware?any
> > alternative?

>
> No. The longer you make your integers (the long the word length is),
> the less wideband noise that results.
>
> I'm not sure what you mean by "tedios to implement." Generally,
> fixed-point hardware implementations are simpler than floating point.
>
>
>
>
>
> > regards,
> > raj.

>
> > On Jun 29, 1:05*pm, Mikolaj
> > <sterowanie_komputer...@hahapoczta.onet.pl> wrote:
> >> On 28-06-2008 at 23:11:42 Randy Yates <ya...@ieee.org> wrote:

>
> >> > Randy Yates <ya...@ieee.org> writes:

>
> >> (...)

>
> >> > *http://www.mathworks.com/access/help...ixedpoint/inde...

>
> >> Here is a helpful websitehttp://tinyurl.com/.

>
> >>http://tinyurl.com/3lv43u

>
> >> --
> >> Mikolaj

>
> --
> % *Randy Yates * * * * * * * * *% "Maybe one day I'll feel her cold embrace,
> %% Fuquay-Varina, NC * * * * * *% * * * * * * * * * *and kiss her interface,
> %%% 919-577-9882 * * * * * * * *% * * * * * *til then, I'll leave her alone."
> %%%% <ya...@ieee.org> * * * * * % * * * *'Yours Truly, 2095', *Time*, ELO *http://www.digitalsignallabs.com


Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Floating point to Fixed point conversion. samdani1125 DSP 2 05-05-2007 06:59 PM
floating point to fixed point conversion riya DSP 6 02-23-2006 08:25 PM
Conversion to Fixed Point bsdap DSP 1 09-27-2005 06:57 AM
Beginner: Integer FFT and Fixed Point FFT Karthik Ravikanti DSP 67 05-30-2005 04:30 PM
Floating point to fixed point conversion. Gowtham DSP 7 07-26-2003 02:33 PM


All times are GMT +1. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved