Path: news.mathworks.com!not-for-mail
From: Tom Bryan <tom.bryan@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Fixed-Point Toolbox : ProductWordLength
Date: Fri, 18 Jul 2008 07:37:20 -0400
Organization: The MathWorks, Inc.
Lines: 67
Message-ID: <g5pv9g$1vn$1@fred.mathworks.com>
References: <g5ol12$nrp$1@fred.mathworks.com>
NNTP-Posting-Host: tbryan-macpro.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1216381040 2039 144.212.110.165 (18 Jul 2008 11:37:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 18 Jul 2008 11:37:20 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421)
In-Reply-To: <g5ol12$nrp$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:480234



Michael Hui wrote:
> I am starting to use Fixed-Point Toolbox, within an Embedded
> MATLAB Function. I noticed that, since M code does not
> support type definitions for variables, the
> ProductWordLength attribute in the terms of an equation (its
> RHS) determine the ProductWordLength of the product (its LHS).
> 
> This is quite a departure from conventional programming
> language where you can separately specify the
> ProductWordLength of each LHS of an equation.
> 
> So how do I model the case where a variable is stored in one
> format only, but is used in multiple equations, each needing
> a different ProductWordLength in its LHS?

Hi Michael,

One way to do it is to leave the product-mode in full-precision, then 
assign into a left-hand-side argument to cast to a specific type.

For example, leave the ProductMode in the FullPrecision default, define 
the types of the left-hand-side variables, and assign into them:

   A = fi(2, true,  8, 0);
   B = fi(3, true,  8, 0);
   C = fi(5, true, 16, 0);

   D = fi(0, true,  8, 0);  % To hold the first product
   E = fi(0, true, 16, 0);  % To hold the second product

   % The full-precision product is s16,0, then assign into s8,0
   D(:) = A*B  % Assign into D
   % D =  6   s8,0

   % The full-precision product is s24,0, then assign into s16,0
   E(:) = A*C  % Assign into E
   % E =  10  s16,0

If this doesn't answer the question, I would be happy to follow up with 
you if you could send a specific example.

Best wishes,
Tom Bryan
tbryan@mathworks.com

p.s.

Here is a section from the demos, and there is more in the 
documentation.  From the MATLAB command line, type demos.  Then select 
Fixed-Point Toolbox, Fixed-Point Basics, and the section

A(:) = B vs. A = B


There is a difference between
  A = B


and
  A(:) = B


In the first case, A = B replaces A with B, and A assumes B's numeric type.

In the second case, A(:) = B assigns the value of B into A, while 
keeping A's numeric type. This is very handy for casting one numeric 
type into another.