<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172798</link>
    <title>MATLAB Central Newsreader - Fixed-Point Toolbox : ProductWordLength</title>
    <description>Feed for thread: Fixed-Point Toolbox : ProductWordLength</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 17 Jul 2008 23:36:02 -0400</pubDate>
      <title>Fixed-Point Toolbox : ProductWordLength</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172798#443782</link>
      <author>Michael Hui</author>
      <description>I am starting to use Fixed-Point Toolbox, within an Embedded&lt;br&gt;
MATLAB Function. I noticed that, since M code does not&lt;br&gt;
support type definitions for variables, the&lt;br&gt;
ProductWordLength attribute in the terms of an equation (its&lt;br&gt;
RHS) determine the ProductWordLength of the product (its LHS).&lt;br&gt;
&lt;br&gt;
This is quite a departure from conventional programming&lt;br&gt;
language where you can separately specify the&lt;br&gt;
ProductWordLength of each LHS of an equation.&lt;br&gt;
&lt;br&gt;
So how do I model the case where a variable is stored in one&lt;br&gt;
format only, but is used in multiple equations, each needing&lt;br&gt;
a different ProductWordLength in its LHS?</description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 11:37:20 -0400</pubDate>
      <title>Re: Fixed-Point Toolbox : ProductWordLength</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172798#443880</link>
      <author>Tom Bryan</author>
      <description>Michael Hui wrote:&lt;br&gt;
&amp;gt; I am starting to use Fixed-Point Toolbox, within an Embedded&lt;br&gt;
&amp;gt; MATLAB Function. I noticed that, since M code does not&lt;br&gt;
&amp;gt; support type definitions for variables, the&lt;br&gt;
&amp;gt; ProductWordLength attribute in the terms of an equation (its&lt;br&gt;
&amp;gt; RHS) determine the ProductWordLength of the product (its LHS).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is quite a departure from conventional programming&lt;br&gt;
&amp;gt; language where you can separately specify the&lt;br&gt;
&amp;gt; ProductWordLength of each LHS of an equation.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So how do I model the case where a variable is stored in one&lt;br&gt;
&amp;gt; format only, but is used in multiple equations, each needing&lt;br&gt;
&amp;gt; a different ProductWordLength in its LHS?&lt;br&gt;
&lt;br&gt;
Hi Michael,&lt;br&gt;
&lt;br&gt;
One way to do it is to leave the product-mode in full-precision, then &lt;br&gt;
assign into a left-hand-side argument to cast to a specific type.&lt;br&gt;
&lt;br&gt;
For example, leave the ProductMode in the FullPrecision default, define &lt;br&gt;
the types of the left-hand-side variables, and assign into them:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;A = fi(2, true,  8, 0);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;B = fi(3, true,  8, 0);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;C = fi(5, true, 16, 0);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;D = fi(0, true,  8, 0);  % To hold the first product&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;E = fi(0, true, 16, 0);  % To hold the second product&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;% The full-precision product is s16,0, then assign into s8,0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;D(:) = A*B  % Assign into D&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;% D =  6   s8,0&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;% The full-precision product is s24,0, then assign into s16,0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;E(:) = A*C  % Assign into E&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;% E =  10  s16,0&lt;br&gt;
&lt;br&gt;
If this doesn't answer the question, I would be happy to follow up with &lt;br&gt;
you if you could send a specific example.&lt;br&gt;
&lt;br&gt;
Best wishes,&lt;br&gt;
Tom Bryan&lt;br&gt;
tbryan@mathworks.com&lt;br&gt;
&lt;br&gt;
p.s.&lt;br&gt;
&lt;br&gt;
Here is a section from the demos, and there is more in the &lt;br&gt;
documentation.  From the MATLAB command line, type demos.  Then select &lt;br&gt;
Fixed-Point Toolbox, Fixed-Point Basics, and the section&lt;br&gt;
&lt;br&gt;
A(:) = B vs. A = B&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
There is a difference between&lt;br&gt;
&amp;nbsp;&amp;nbsp;A = B&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
and&lt;br&gt;
&amp;nbsp;&amp;nbsp;A(:) = B&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
In the first case, A = B replaces A with B, and A assumes B's numeric type.&lt;br&gt;
&lt;br&gt;
In the second case, A(:) = B assigns the value of B into A, while &lt;br&gt;
keeping A's numeric type. This is very handy for casting one numeric &lt;br&gt;
type into another.</description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 18:14:03 -0400</pubDate>
      <title>Re: Fixed-Point Toolbox : ProductWordLength</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172798#443982</link>
      <author>Michael Hui</author>
      <description>OK thanks for the help Tom.&lt;br&gt;
&lt;br&gt;
I will standardize on that coding style then, since we &lt;br&gt;
traditionally (and want to continue to) define LHS word &lt;br&gt;
lengths independently from RHS word lengths.&lt;br&gt;
&lt;br&gt;
We of course will take advantage of Fixed-Point Toolbox's &lt;br&gt;
ability to warn of overflows, and this coding style does &lt;br&gt;
allow that.</description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 19:04:02 -0400</pubDate>
      <title>Re: Fixed-Point Toolbox : ProductWordLength</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172798#443995</link>
      <author>Michael Hui</author>
      <description>But wait ...&lt;br&gt;
&lt;br&gt;
I just tried your demo, and FPT didn't give any overflow&lt;br&gt;
indication at all. So that's no good.&lt;br&gt;
&lt;br&gt;
I suppose another solution is to make local copies of all&lt;br&gt;
variables that will be used in more than one equation's RHS,&lt;br&gt;
and set their ProductWordLength to different values.&lt;br&gt;
&lt;br&gt;
Or should I use Fixed-Point Block Sets?&lt;br&gt;
&lt;br&gt;
The doc gives a good reason for using Embedded MATLAB&lt;br&gt;
Functions, and that reason is exactly why I am using it:&lt;br&gt;
&lt;br&gt;
&quot;This capability is useful for coding algorithms that are&lt;br&gt;
better stated in the textual language of the MATLAB software&lt;br&gt;
than in the graphical language of the Simulink product.&quot;&lt;br&gt;
&lt;br&gt;
Another reason is that a lot of our algorithms are already&lt;br&gt;
in floating point M code, so we benefit from not having to&lt;br&gt;
rewrite that code extensively to convert them to fixed-point.</description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 19:19:02 -0400</pubDate>
      <title>Re: Fixed-Point Toolbox : ProductWordLength</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172798#443998</link>
      <author>Michael Hui</author>
      <description>Ooops ... the overflow detection does work.&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; D = fi(0, true, 3, 0);&lt;br&gt;
&amp;gt;&amp;gt; D(:)=A*B&lt;br&gt;
Warning: 1 overflow occurred in the fi assignment operation.&lt;br&gt;
&lt;br&gt;
I forgot to set&lt;br&gt;
&lt;br&gt;
P.LoggingMode = 'on';</description>
    </item>
  </channel>
</rss>

