Thread Subject: FPT : how to inherit an fi object's attributes

Subject: FPT : how to inherit an fi object's attributes

From: Michael Hui

Date: 15 Aug, 2008 19:49:01

Message: 1 of 4

In my MATLAB workspace I do this:

cordic_p.addr_size = 4;

cordic_p.out_size = 23;

cordic_p.phase_size = pow2(cordic_p.addr_size);

cordic_p.phdiff_size = cordic_p.phint_size -
cordic_p.phase_size;

phase_size_int = cordic_p.phase_size - 2; % The RTL only
does phase_size - 2 iterations, so we match it here

% Generate atan() ROM values
atan_quantized = fi ( atan(pow2(0:-1:-phase_size_int+1))/pi, ...
    'Signed', 0, 'WordLength', cordic_p.out_size-2,
'FractionLength', cordic_p.out_size-2, 'OverflowMode',
'saturate', 'RoundMode', 'round');


And then I pass atan_quantized to a function as a read-only
argument.

I want to create an fi object inside the function that
inherits almost all attributes of that argument, except I
want to increase its word length.

What is the proper way to do this?

I can do it like this inside the function, which is very
tedious:

aq = fi(zeros(size(atan_quantized)),...
   atan_quantized.fimath,...
   atan_quantized.numerictype,...
   'WordLength',atan_quantized.numerictype.WordLength+2,...
  
'FractionLength',atan_quantized.numerictype.FractionLength+2);

Subject: FPT : how to inherit an fi object's attributes

From: Ashok Charry

Date: 15 Aug, 2008 20:39:51

Message: 2 of 4

Hi Michael,

What you are doing to inherit the fi's properties is correct. My suggestion
(below) is not a huge improvement but its fewer characters to type:

aq = fi(zeros(size(atan_quantized)),...
        atan_quantized.Signed,...
        atan_quantized.WordLength+2,...
        atan_quantized.FractionLength+2,...
        atan_quantized.fimath);

Hope that helps,

Ashok Charry
The MathWorks


On 8/15/08 3:49 PM, in article g84mjd$hpd$1@fred.mathworks.com, "Michael
Hui" <myhui@yahoo.com> wrote:

> In my MATLAB workspace I do this:
>
> cordic_p.addr_size = 4;
>
> cordic_p.out_size = 23;
>
> cordic_p.phase_size = pow2(cordic_p.addr_size);
>
> cordic_p.phdiff_size = cordic_p.phint_size -
> cordic_p.phase_size;
>
> phase_size_int = cordic_p.phase_size - 2; % The RTL only
> does phase_size - 2 iterations, so we match it here
>
> % Generate atan() ROM values
> atan_quantized = fi ( atan(pow2(0:-1:-phase_size_int+1))/pi, ...
> 'Signed', 0, 'WordLength', cordic_p.out_size-2,
> 'FractionLength', cordic_p.out_size-2, 'OverflowMode',
> 'saturate', 'RoundMode', 'round');
>
>
> And then I pass atan_quantized to a function as a read-only
> argument.
>
> I want to create an fi object inside the function that
> inherits almost all attributes of that argument, except I
> want to increase its word length.
>
> What is the proper way to do this?
>
> I can do it like this inside the function, which is very
> tedious:
>
> aq = fi(zeros(size(atan_quantized)),...
> atan_quantized.fimath,...
> atan_quantized.numerictype,...
> 'WordLength',atan_quantized.numerictype.WordLength+2,...
>
> 'FractionLength',atan_quantized.numerictype.FractionLength+2);
>

Subject: FPT : how to inherit an fi object's attributes

From: Donn Shull

Date: 17 Aug, 2008 05:35:03

Message: 3 of 4

The way you are doing this now is the "proper way" to do
it. If you are looking for alternatives then you could
create methods in the @embedded/@fi directory to give you
more flexibility. For instance you could create a file
setWordLength.m with this code:

function this = setWordLength(this, wordLength)

this.WordLength = wordLength;

in that directory. Then after restarting MATLAB you could
do the following

aq = atan_quantized.copy;
aq.setWordLength(23);

But this would be an "improper way" to do this.

Subject: FPT : how to inherit an fi object's attributes

From: Michael Hui

Date: 17 Aug, 2008 16:20:17

Message: 4 of 4

I thank you both for sharing your thoughts.

The difference between the following:

aq = fi(zeros(size(atan_quantized)),...
atan_quantized.fimath,...
atan_quantized.numerictype,...
'WordLength',atan_quantized.numerictype.WordLength+2,...
'FractionLength',atan_quantized.numerictype.FractionLength+2);

aq = fi(zeros(size(atan_quantized)),...
        atan_quantized.Signed,...
        atan_quantized.WordLength+2,...
        atan_quantized.FractionLength+2,...
        atan_quantized.fimath);

is that the first one takes in all properties of numerictype
without listing them out, and the second one lists them
explicitly.

I suppose the two will work differently if one adds more
properties to numerictype. The first method will continue to
inherit all properties and the second one might miss the new
properties.

So that's why both of you said the first method is the
proper method. Thanks for that!

Tags for this Thread

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com