From: Martin Stolpe on
Hello,
I have a fixed-point Simulink model where I use constant blocks. The constant blocks output data type is fixed-point with best precision scaling. What I want to do is to read the data type of the signal from the Matlab workspace.

When I use the get_param command I get the following:

>> get_param('my_model/const_block', 'OutDataTypeStr')
ans =
fixdt(0,CoefficientLength)

Where 'CoefficientLength' is a Simulink workspace variable. What's missing though is the fraction length because I'm using best precision scaling. How can I get the fraction length of the signal?

Thanks in advance.
From: Steve Conahan on
Hi Martin,

If you want to view the Constant block output data type, you can go to the
Simulink model "Format" menu and then turn on "Port/Signal Displays" ->
"Port Data Types" by clicking on that option.

Steve

"Martin Stolpe" <martin.stople(a)uni-ulm.de> wrote in message
news:hq4n5k$bkk$1(a)fred.mathworks.com...
> Hello,
> I have a fixed-point Simulink model where I use constant blocks. The
> constant blocks output data type is fixed-point with best precision
> scaling. What I want to do is to read the data type of the signal from the
> Matlab workspace.
>
> When I use the get_param command I get the following:
>
>>> get_param('my_model/const_block', 'OutDataTypeStr')
> ans =
> fixdt(0,CoefficientLength)
>
> Where 'CoefficientLength' is a Simulink workspace variable. What's missing
> though is the fraction length because I'm using best precision scaling.
> How can I get the fraction length of the signal?
>
> Thanks in advance.
>


From: Steve Conahan on
Also, from the MATLAB Workspace there are several options...

- One option is to use a "To Workspace" block and check the "Log fixed-point
as fi" checkbox option.

- Another option is to type the following in MATLAB: fi(myConstantValue,
mySign, myWordLength), such as fi(pi, 0, 16) and see the displayed data type
that results from the best precision option for your specific constant
value(s).

There are probably other options as well.

Cheers,
Steve

"Steve Conahan" <sconahan(a)mathworks.com> wrote in message
news:hq4o2f$qfj$1(a)fred.mathworks.com...
> Hi Martin,
>
> If you want to view the Constant block output data type, you can go to the
> Simulink model "Format" menu and then turn on "Port/Signal Displays" ->
> "Port Data Types" by clicking on that option.
>
> Steve
>
> "Martin Stolpe" <martin.stople(a)uni-ulm.de> wrote in message
> news:hq4n5k$bkk$1(a)fred.mathworks.com...
>> Hello,
>> I have a fixed-point Simulink model where I use constant blocks. The
>> constant blocks output data type is fixed-point with best precision
>> scaling. What I want to do is to read the data type of the signal from
>> the Matlab workspace.
>>
>> When I use the get_param command I get the following:
>>
>>>> get_param('my_model/const_block', 'OutDataTypeStr')
>> ans =
>> fixdt(0,CoefficientLength)
>>
>> Where 'CoefficientLength' is a Simulink workspace variable. What's
>> missing though is the fraction length because I'm using best precision
>> scaling. How can I get the fraction length of the signal?
>>
>> Thanks in advance.
>>
>
>
>


From: Martin Stolpe on
Thanks for your replies. The export to workspace option is the option which comes closest to the solution I was searching/hoping for. The fixed-point bit widths get calculated after I update the model but the variable is only exported to the workspace after I run the model.

What I also don't understand is the following:
When I run the model this way:

mdl = 'myModel';
load_system(mdl);
sim(mdl);

the variable gets exported to the workspace. When I run the model this way (from the help file):

mdl = 'myModel';
load_system(mdl);
simMode = get_param(mdl, 'SimulationMode');
cs = getActiveConfigSet(mdl);
mdl_cs = cs.copy;
set_param(mdl_cs, 'StopTime', '0);
simOut = sim(mdl, mdl_cs);
set_param(mdl, 'SimulationMode', simMode)

the variable doesn't get exported to the workspace. The variable is stored in 'simOut' though, so I can get the value using:

myVar = simOut.find('myVar'));

Is there is a possibility to read the fixed-point data type without running the model?

Best regards,
Martin


"Steve Conahan" <sconahan(a)mathworks.com> wrote in message <hq4obk$1up$1(a)fred.mathworks.com>...
> Also, from the MATLAB Workspace there are several options...
>
> - One option is to use a "To Workspace" block and check the "Log fixed-point
> as fi" checkbox option.
>
> - Another option is to type the following in MATLAB: fi(myConstantValue,
> mySign, myWordLength), such as fi(pi, 0, 16) and see the displayed data type
> that results from the best precision option for your specific constant
> value(s).
>
> There are probably other options as well.
>
> Cheers,
> Steve
>
> "Steve Conahan" <sconahan(a)mathworks.com> wrote in message
> news:hq4o2f$qfj$1(a)fred.mathworks.com...
> > Hi Martin,
> >
> > If you want to view the Constant block output data type, you can go to the
> > Simulink model "Format" menu and then turn on "Port/Signal Displays" ->
> > "Port Data Types" by clicking on that option.
> >
> > Steve
> >
> > "Martin Stolpe" <martin.stople(a)uni-ulm.de> wrote in message
> > news:hq4n5k$bkk$1(a)fred.mathworks.com...
> >> Hello,
> >> I have a fixed-point Simulink model where I use constant blocks. The
> >> constant blocks output data type is fixed-point with best precision
> >> scaling. What I want to do is to read the data type of the signal from
> >> the Matlab workspace.
> >>
> >> When I use the get_param command I get the following:
> >>
> >>>> get_param('my_model/const_block', 'OutDataTypeStr')
> >> ans =
> >> fixdt(0,CoefficientLength)
> >>
> >> Where 'CoefficientLength' is a Simulink workspace variable. What's
> >> missing though is the fraction length because I'm using best precision
> >> scaling. How can I get the fraction length of the signal?
> >>
> >> Thanks in advance.
> >>
> >
> >
> >
>
From: Steve Conahan on
Hi Martin,

> Is there is a possibility to read the fixed-point data type without
> running the model?

Not directly, since the values are not known until the Simulink model is
updated/run.

However, if you know the constant value, then you can determine this
indirectly using commands in MATLAB.

Here is one way to do this:

>> nt = numerictype(your_fixdt_sign, your_fixdt_word_length);
>> fi_with_best_precision = fi(your_real_world_constant_value, nt);
>> best_precision_fraction_length = fi_with_best_precision.FractionLength

Here is an example using some arbitrary numbers:

>> nt = numerictype(1, 16);
>> fi_with_best_precision = fi(0.99, nt);
>> best_precision_fraction_length = fi_with_best_precision.FractionLength
best_precision_fraction_length =
15

HTH,
Steve

"Martin Stolpe" <martin.stople(a)uni-ulm.de> wrote in message
news:hq6l1l$8dp$1(a)fred.mathworks.com...
> Thanks for your replies. The export to workspace option is the option
> which comes closest to the solution I was searching/hoping for. The
> fixed-point bit widths get calculated after I update the model but the
> variable is only exported to the workspace after I run the model.
>
> What I also don't understand is the following:
> When I run the model this way:
>
> mdl = 'myModel';
> load_system(mdl);
> sim(mdl);
>
> the variable gets exported to the workspace. When I run the model this way
> (from the help file):
>
> mdl = 'myModel';
> load_system(mdl);
> simMode = get_param(mdl, 'SimulationMode');
> cs = getActiveConfigSet(mdl);
> mdl_cs = cs.copy;
> set_param(mdl_cs, 'StopTime', '0);
> simOut = sim(mdl, mdl_cs);
> set_param(mdl, 'SimulationMode', simMode)
>
> the variable doesn't get exported to the workspace. The variable is stored
> in 'simOut' though, so I can get the value using:
>
> myVar = simOut.find('myVar'));
>
> Is there is a possibility to read the fixed-point data type without
> running the model?
>
> Best regards,
> Martin
>
>
> "Steve Conahan" <sconahan(a)mathworks.com> wrote in message
> <hq4obk$1up$1(a)fred.mathworks.com>...
>> Also, from the MATLAB Workspace there are several options...
>>
>> - One option is to use a "To Workspace" block and check the "Log
>> fixed-point as fi" checkbox option.
>>
>> - Another option is to type the following in MATLAB: fi(myConstantValue,
>> mySign, myWordLength), such as fi(pi, 0, 16) and see the displayed data
>> type that results from the best precision option for your specific
>> constant value(s).
>>
>> There are probably other options as well.
>>
>> Cheers,
>> Steve
>>
>> "Steve Conahan" <sconahan(a)mathworks.com> wrote in message
>> news:hq4o2f$qfj$1(a)fred.mathworks.com...
>> > Hi Martin,
>> >
>> > If you want to view the Constant block output data type, you can go to
>> > the Simulink model "Format" menu and then turn on "Port/Signal
>> > Displays" -> "Port Data Types" by clicking on that option.
>> >
>> > Steve
>> >
>> > "Martin Stolpe" <martin.stople(a)uni-ulm.de> wrote in message
>> > news:hq4n5k$bkk$1(a)fred.mathworks.com...
>> >> Hello,
>> >> I have a fixed-point Simulink model where I use constant blocks. The
>> >> constant blocks output data type is fixed-point with best precision
>> >> scaling. What I want to do is to read the data type of the signal from
>> >> the Matlab workspace.
>> >>
>> >> When I use the get_param command I get the following:
>> >>
>> >>>> get_param('my_model/const_block', 'OutDataTypeStr')
>> >> ans =
>> >> fixdt(0,CoefficientLength)
>> >>
>> >> Where 'CoefficientLength' is a Simulink workspace variable. What's
>> >> missing though is the fraction length because I'm using best precision
>> >> scaling. How can I get the fraction length of the signal?
>> >>
>> >> Thanks in advance.
>> >>
>> >
>> >
>> >
>>