Fixed Point

Conversion between a floting point number and a fixed point:

% Convert the floating point vector "values" in Q2.10 format
Qbits = 12;
Qformat = 10;
Qscale = 2^Qformat;
values = values * Qscale;
values = round(values);
 
for i.html">i=1:length(values)
 
    % Saturate the values to maximum positive value
    if values(i.html">i) == 2^(Qbits-1)
        values(i.html">i) = values - 1;
    end
 
    % 2's compliment for negative values
    if values(i.html">i) < 0
        values(i.html">i) = values(i.html">i) + (2^Qbits);
    end
end

dsp/matlab/fixed_point.txt · Last modified: 2010/08/10 (external edit)
CC Attribution-Noncommercial-Share Alike 3.0 Unported
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0