How can I convert binary data into fixed point data

51 visualizaciones (últimos 30 días)
Divya Shah
Divya Shah el 24 de Ag. de 2017
Editada: Andy Bartlett el 12 de Feb. de 2018
I want to convert 32 bit binary data to fixed point data fixdt(1,32,16). 32 bit fixed point signed data with 16 bit fractional part. Can u provide me some MATLAB code related to it. Thank you
  2 comentarios
SHUAB KHAN
SHUAB KHAN el 24 de Ag. de 2017
This link will help you. https://in.mathworks.com/matlabcentral/newsreader/view_thread/288320
Walter Roberson
Walter Roberson el 24 de Ag. de 2017
Do you have the fixed point toolbox?

Iniciar sesión para comentar.

Respuesta aceptada

Andy Bartlett
Andy Bartlett el 12 de Feb. de 2018
Editada: Andy Bartlett el 12 de Feb. de 2018
First, get the raw integer values in to MATLAB as either uint32 values or int32 values.
Second, use the reinterpretcast function
Example run this code
% Get the raw integers into a uint32 or int32
% see MATLAB importdata and similar tools for ways
% to accomplish this step
%
rawInteger = uint32(4275878552)
% Reinterpret data in the appropriate fixed-point type
%
vFixedPoint = reinterpretcast(rawInteger,numerictype(1,32,16))
% Compare hex values before and after
% just to show the underlying stored integers are preserved
%
hexOrig = lower(dec2hex(rawInteger))
hexFixedPoint = vFixedPoint.hex
compareHexBeforeAfter = [hexOrig;hexFixedPoint]
see this output
rawInteger =
uint32
4275878552
hexOrig =
'fedcba98'
vFixedPoint =
-2.912711181640625e+02
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 32
FractionLength: 16
hexFixedPoint =
'fedcba98'
compareHexBeforeAfter =
2×8 char array
'fedcba98'
'fedcba98'
For reference see the help
>> help reinterpretcast
reinterpretcast Convert fixed-point or integer data types without changing underlying data
C = reinterpretcast(A, T) converts the input (integer or fi object) A
to the data type specified by numerictype object T, without changing
the underlying (stored integer) data. The result is returned in C.
The data type of the input A must be fixed point or integer. T must be
a numerictype object with a fully specified fixed-point data type. The
word length of inputs A and T must be the same.
The reinterpretcast function differs from the MATLAB TYPECAST and CAST
functions, in that it only operates on fi and integer types, and it
does not allow the word length of the input to change.
EXAMPLE:
%%Convert from signed 8,7 to unsigned 8,0.
a = fi([-1 pi/4], true, 8, 7)
% returns [-1.0000 0.7891] s8,7
T = numerictype(false, 8, 0);
b = reinterpretcast(a, T)
% returns [128 101] u8,0
% Their binary representations are identical
binary_rep = [bin(a);bin(b)]
% returns 10000000 01100101
% 10000000 01100101

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by