user2045143
user2045143

Reputation: 249

Converting data into fixed point binary in Matlab?

I am not a regular Matlab user, so I apologize if this question is naïve. I am working on a hardware project and would like to convert some data to fixed point binary using the fixed point toolbox.

All my data are float in nature and in the range of -1 to +1. I was trying to convert them into fixed point in Matlab, to no avail.

I have been getting different types of errors, from "Cell contents assignment to non cell array objects" to just wrong binary values. Below is my code.

for i=1:count
    temp=datax(i); % datax is a array of decimal values between -1 and 1

    fixeda{i}=bin(sfi(temp,16,15)); 
    % Since all values are in the same range I set the word length to be 16 and fractional part to be 15
end

Upvotes: 1

Views: 1661

Answers (1)

AShelly
AShelly

Reputation: 35540

I'm not a matlab user, but shouldn't the 1.15 representation of a float between -1 and 1 just be int(f*32768)

Note that you can only represent numbers less than 1.0 in this representation. 1.0 exactly causes an overflow.

Looking at the help pages it looks like fixeda = bin(sfi(datax,16,15)) should be all you need.

Upvotes: 0

Related Questions