Thread Subject: Quantizer vs. fi object (Fixed Point Toolbox)

Subject: Quantizer vs. fi object (Fixed Point Toolbox)

From: Walid Abdelfatah

Date: 19 Jun, 2009 13:56:01

Message: 1 of 5

Hello,

 I want to know why do we have both of these objects "quantizer() and fi()" in matlab;
in other words when to use evey one of them.

Thanks,
 Walid F. Abdelfatah

Subject: Quantizer vs. fi object (Fixed Point Toolbox)

From: Ashok Charry

Date: 19 Jun, 2009 14:25:07

Message: 2 of 5

Walid,

The quatizer object is an older object. It wok only on double precision
inputs and also returns a double precision value for its quantize
method. It also does not support fixed-point arithmetic (like +,-,* etc)
like the fi object does.

However the quantizer object also supports custom floating-point if that
is of interest to you.

Ashok Charry
Fixed-Point Engineer,
The MathWorks.


Walid Abdelfatah wrote:
> Hello,
>
> I want to know why do we have both of these objects "quantizer() and fi()" in matlab;
> in other words when to use evey one of them.
>
> Thanks,
> Walid F. Abdelfatah

Subject: Quantizer vs. fi object (Fixed Point Toolbox)

From: Walid Abdelfatah

Date: 19 Jun, 2009 20:05:18

Message: 3 of 5

Hello Ashok,

 Thanks for replying to my message.
 I implemented a code in both the fi() and quantizer() object and I know that
 1- For the quantizer object, the operations are done in floating point and then are returnde back in fooating point.
2- For the fi object(), all the arithmetic operations are done between fi objects of the same fi math object and it gives closer and better results if I want to get the results in pure Fixed-Point ... However it is slower which I know can be accelerated by emlmex.

The reason for asking the above question is because many people use the quantizer objects instaed of fi(), and it can be justified as you said by the quantizer() being the older object.

So, I'll ask some questions regarding this issue:
1- What do you mean by "However the quantizer object also supports custom floating-point if that is of interest to you" ?
Do you mean by custom floating point the "ScaledDoubles" ? and how can I set this option.

2- For the fi() object, what do I need to do to apply trignometric functions "e.g sin(), cosine()" on an fi object other than using (data field) "e.g. sin(fi_object.data)".

3- For the fi() object, when an arithmetic expression is complex, I use the data field in the fi object to solve the equation and then put the result back in the fi object. Is there any other better way to do that ? Or is what I'm doing absolutely wrong?
I just know it won't give me the exact results in Fixed point implementation.

4- When using emlmex to accelerate the fixed point simulation; Does the code have to be written using the embedded Matlab subset only?

Sorry for my long reply and many questions.

Thanks,
 Walid F. Abdelfatah

Subject: Quantizer vs. fi object (Fixed Point Toolbox)

From: Ashok Charry

Date: 22 Jun, 2009 14:43:36

Message: 4 of 5

Hi Walid,

 > 1- What do you mean by "However the quantizer object also supports
 > custom floating-point if that is of interest to you" ?
 > Do you mean by custom floating point the "ScaledDoubles" ? and how
can > I set this option.


By this I mean that the quantizer object may be configured to do custom-
(IEEE standard)-floating point including IEEE Single and IEEE Double
precision. The quantizer object does not support scaled-doubles. That is
a feature of only the fi object.

Example of quantizer custom floating-point:

q = quantizer('float',[24,12])
% this will simulate a 24 bit floating point with 12 exponent bits using
% the IEEE standard for floating point

 > 2- For the fi() object, what do I need to do to apply trignometric
 > functions "e.g sin(), cosine()" on an fi object other than using
(data > field) "e.g. sin(fi_object.data)".

The fi object currently does not support trigonometric functions. We are
working on extending the set of supported functionality in the
Fixed-Point Toolbox every release. For now a workaround for you would be
something like this, where you cast the fi object to a double, call the
function of your choice an then re-cast the output to a fi:

a = fi(val);
% find sine of a: sin(a)
b = fi(sin(double(a)),numerictype(b));

 > 3- For the fi() object, when an arithmetic expression is complex, I
 > use the data field in the fi object to solve the equation and then put
 > the result back in the fi object. Is there any other better way to do
 > that ? Or is what I'm doing absolutely wrong?

This will not give the same result as doing everything in fixed-point in
most cases, since the "data" property of the fi is a double. What is the
exact nature of the complexity of the expression that is preventing you
from using fi directly? Send me an example of your code and I may be
able to help you simplify it.

 > 4- When using emlmex to accelerate the fixed point simulation; Does
 > the code have to be written using the embedded Matlab subset only?

This is correct. The Embedded MATLAB (fixed-point) )subset is still
quite extensive but is a little restrictive in its semantics. For
example if 'a' is a fi object you cannot do a.<something>. You have to
do: something(a). You also cannot change the fimath or the type of a
during the course of your program.

There is more information about working with the Fixed-Point Embedded
MATLAB subset in our documentation:

http://www.mathworks.com/access/helpdesk/help/toolbox/fixedpoint/ug/bq4crme.html

Again, if you have trouble using emlmex on your code, if you like you
could send me a snippet of your code and I could help you convert it to
something that is EML friendly.


Thank you for using the Fixed-Point Toolbox!

Ashok Charry
The MathWorks Inc.


Walid Abdelfatah wrote:
> Hello Ashok,
>
> Thanks for replying to my message.
> I implemented a code in both the fi() and quantizer() object and I know that
> 1- For the quantizer object, the operations are done in floating point and then are returnde back in fooating point.
> 2- For the fi object(), all the arithmetic operations are done between fi objects of the same fi math object and it gives closer and better results if I want to get the results in pure Fixed-Point ... However it is slower which I know can be accelerated by emlmex.
>
> The reason for asking the above question is because many people use the quantizer objects instaed of fi(), and it can be justified as you said by the quantizer() being the older object.
>
> So, I'll ask some questions regarding this issue:
> 1- What do you mean by "However the quantizer object also supports custom floating-point if that is of interest to you" ?
> Do you mean by custom floating point the "ScaledDoubles" ? and how can I set this option.
>
> 2- For the fi() object, what do I need to do to apply trignometric functions "e.g sin(), cosine()" on an fi object other than using (data field) "e.g. sin(fi_object.data)".
>
> 3- For the fi() object, when an arithmetic expression is complex, I use the data field in the fi object to solve the equation and then put the result back in the fi object. Is there any other better way to do that ? Or is what I'm doing absolutely wrong?
> I just know it won't give me the exact results in Fixed point implementation.
>
> 4- When using emlmex to accelerate the fixed point simulation; Does the code have to be written using the embedded Matlab subset only?
>
> Sorry for my long reply and many questions.
>
> Thanks,
> Walid F. Abdelfatah

Subject: Quantizer vs. fi object (Fixed Point Toolbox)

From: Walid Abdelfatah

Date: 22 Jun, 2009 16:14:01

Message: 5 of 5

Hi Ashok,

(1) The workaround using trigonometric functions :

> a = fi(val);
> % find sine of a: sin(a)
> b = fi(sin(double(a)),numerictype(b));

------->
Isn't that similar to
b = fi(sin(a.data),T_b,fimath_obj) ;

where T_b : numerictype object of b.
          fimath_obj : fimath object of the operations to be done in the code.

(2) I'm trying to simulate a code in Fixed-point to know what are the number of bits needed to hold the variables in all the expressions that shall be converted to HDL in the next stage , so

a- I use 'ScaledDoubles' and the 'On' Logging mode of the fipref object to know the number of bits for every constant and variable.
b- fimath object uses 'Specify precision' with 50 bits of WordLength and 25 bits for the fractionLength for both the procut and sum operations.

a complex expression will be like the following where the computation is done first using the data field due to using the 'tan' and then it is casted to the numeric type I want in the 2nd line

az_k , w , v_k , la_k , N , az ------> all are fi objects

az_calc = az_k.data - ((w.data(sec_count)) - v_k.data*tan(la_k.data)/(N.data));
az(sec_count) = fi(az_calc,'numerictype',T_az,'fimath',fimath_obj);

-So how can you help me with this expression and using emlmex ? "This expression is a simple one (not that complex as I omitted some operations)"

- Since I'm doing this (not applying the operations on the fi objects) , I think the fimath_obj is not utilized at all ... am I right ?

- Everyone of these variables has a numerictype object of its own:
for example:
1- az_k : Signed = 1 , WordLength = 50 , FractionLength = 40
2- la_k : Signed = 0 , WordLength = 50, FractionLength = 10

where fimath object is 'SpecifyPrecision' , WordLength = 50 , FractionLength = 25 for both the product and sum operations

If I'm doing this


out = az_k * la_k; ------> Output should be of WordLength of 100 (if fullpresion is used) but I'm forcing it to be of WordLength of 50 and 25 due to the fimath properties .. right ?

what if I made it like this
out = fi(az_k * la_k , T_out)
where T_out : Signed = 1 , WordLength = 60 , FractionLength = 35

so the way it will work is that the output due to the operation is [50 25] due to the fimath object and then it will be casted to [60 35] ---- Is that the right way, and so if that is happening the other bits will just filled with zeros and then they will be useless .. right?

(3) Last issue:

When using Simulink fixed point, with the division block
1st input is fixdt(0,50,20)
2nd input is fixdt(0,50,20)

Why is the output defined to be fixdt(0,50,0) if the "Inherit via internal rule" option is used?

-If I'm using the product point instead and I forced the output to be fixdt(0,70,30)
then how will I get this precision?
I mean is the product operation done first so the output is calculate in fixdt(0,100,40) and then it is casted to fixdt(0,70,30) or how it will be done ?

-If the output of the product is casted to be fixdt (0,60,50) ,,,, how will be the mapping from fixdt(0,100,40) ....... I mean how will the integer parts and fraction parts be casted after forcing the outputs to a smaller length , so will I take the LS bits of the 60 (100-40) Integer bits and put them on the 10(60-50) bits for forcing ... and take the 40 fraction bits and put them in the the MS bits of the 50 fraction bits and add zeros to the last 10 bits ??

The answer to the last question will be very helpful as I want to know how it can be done in Hardware, as for that reason I'll have to make the product in a register of a longer length first and then cast it or I can have an output of whatever length I want from the product operation directly.

Thank you so much Ashok for your continuous help and simple answers.

KUDOS
 Walid F. Abdelfatah

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
fimath Walid Abdelfatah 26 Jun, 2009 09:17:44
quantizer Walid Abdelfatah 19 Jun, 2009 10:00:52
fi Walid Abdelfatah 19 Jun, 2009 10:00:52
embedded Walid Abdelfatah 19 Jun, 2009 10:00:52
embeddedfi Walid Abdelfatah 19 Jun, 2009 10:00:52
fixed point too... Walid Abdelfatah 19 Jun, 2009 10:00:51
rssFeed for this Thread

Contact us at files@mathworks.com