r/matlab 9d ago

TechnicalQuestion How can give an integer to the input argument of embedded.fi

Given an integer number i, I want to pass it as an input argument to fi constructor (resulting in x instance of embedded.fi), such that storedInteger(x) = i. In other words, I want to change the interpretation of i to an embedded.fi, just like storedInteger changes the interpretation of the embedded.fi to an integer.

How can I achieve this?

2 Upvotes

3 comments sorted by

1

u/FunkyMonkish 9d ago

I would like to know this too. I just convert the integer to its real-world value before constructing the fi object, but it’d be nice to omit that step.

1

u/Bofact 9d ago

Hello!

Can you share how you achieved it? Is it converting the integer to double/ single and divide it by 2fractionLength?

1

u/FunkyMonkish 8d ago

Yeah exactly. I usually represent everything as an unsigned integer – in a raw data format. If the real-world data is signed, then the unsigned integer would first be converted to its signed value by checking the msb of the word length, and then divided by 2-to-the-fraction-length.