cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor
9,629 Views
Registered: ‎10-31-2010

Floating point from Matlab to Blackbox

Jump to solution

Hello,

 

I want to take values from MATLAB thorgh Gateway-in to the blackbox in IEEE 754 Single prcision format(Single).

 

I have tried out this:

 

fpmat2fpga.PNG

 

  1. I am entering one vlaue in MATALB command line as shown below:
>> A=3.556

A =

    3.5560

>> whos
  Name      Size            Bytes  Class     Attributes

  A         1x1                 8  double              

>> A=single(3.556)

A =

    3.5560

>> whos
  Name      Size            Bytes  Class     Attributes

  A         1x1                 4  single    

 By default MATLAB takes double. I trie out single also.

 

2. In constant the cominations i have tried out for double as well as single vales of A are as follows:

 

In constant Properties : Signal Atributes > Output Data type > Inherit: Inherit from 'Constant value' or Single or fixft(1,32,23)

 

But i want to know how can we get ~exact fp values into FPGA.

 

Thanks & Regards,

 

 

 

 

Vihang Naik
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Explorer
Explorer
10,206 Views
Registered: ‎12-08-2010

Hello, Vihang.

 

There is a native support for floating-point operations in System Generator 13.3 (or higher).But if you are using older version, you can do a following trick: pass single precision floating-point value as 32-bit integer with same bits.

 

1. Gateway In block expects integer value, so set its properties to Fixed-point, Unsigned, Number of bits = 32, Binary point = 0.

2. Reinterpret the bits of your floating-point number as unsigned integer using MATLAB typecast function:

% single precision floating-point number
a_single = single(1.23);

% reinterpret it as 32-bit unsigned integer
a_uint32 = typecast(a_single, 'uint32');

Now you can pass a_uint32 value to Gateway In block.

 

To check the bits of your number you can use MATLAB function dec2bin. It returns following result for single(1.23):

>> dec2bin(a_uint32, 32)
ans =
00111111100111010111000010100100

 

Best Regards,
Vitaly.

View solution in original post

2 Replies
Highlighted
Explorer
Explorer
10,207 Views
Registered: ‎12-08-2010

Hello, Vihang.

 

There is a native support for floating-point operations in System Generator 13.3 (or higher).But if you are using older version, you can do a following trick: pass single precision floating-point value as 32-bit integer with same bits.

 

1. Gateway In block expects integer value, so set its properties to Fixed-point, Unsigned, Number of bits = 32, Binary point = 0.

2. Reinterpret the bits of your floating-point number as unsigned integer using MATLAB typecast function:

% single precision floating-point number
a_single = single(1.23);

% reinterpret it as 32-bit unsigned integer
a_uint32 = typecast(a_single, 'uint32');

Now you can pass a_uint32 value to Gateway In block.

 

To check the bits of your number you can use MATLAB function dec2bin. It returns following result for single(1.23):

>> dec2bin(a_uint32, 32)
ans =
00111111100111010111000010100100

 

Best Regards,
Vitaly.

View solution in original post

Highlighted
Contributor
Contributor
9,611 Views
Registered: ‎10-31-2010

Hello Vitaly,

 

Thanks once again for your help, this worked exactly i wanted it to.

Vihang Naik
Tags (1)
0 Kudos