quantisation using matlab

3 views (last 30 days)
fit institute
fit institute on 10 Mar 2011
How can i quantize decimal numbers with fractional parts(like 3.111112,1.22213) to specified number of bits using matlab?
  1 Comment
Knut
Knut on 10 Mar 2011
I believe that you could do something like the code below, given that you first decide on some scaling/range of your signal:
%clip
x(x<0) = 0;
x(x>1 = 1;
%round
N = 8;
y = round(x*(2^N-1));

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 10 Mar 2011
Are you using the fixed point toolbox? I did request in your previous question that you make that clear when asking about fixed point numbers. (Is that previous question answered to your satisfaction? If so then you should Accept the answer.)
If you are not using the fixed point toolbox, then let F be the number of bits to code in the fraction. Then, calculate
round(x * 2.^F)
and encode the resulting integral value in to the total number of bits.
Be sure to take in to account the encoding of the sign, whether it be through separate sign, 2's complement or other encoding (something you need to specify... a point which I believe I conveyed in response to your newsgroup posting.)

fit institute
fit institute on 11 Mar 2011
Thank you Roberson.......yes,I have fixed point toolbox....
I need to quantise the dctmtx(6) to 8 bit hexadecimal values
dctmtx is given below
>> dctmtx(6)
ans =
0.3536 0.3536 0.3536 0.3536 0.3536 0.3536
0.4904 0.4157 0.2778 0.0975 -0.0975 -0.2778
0.4619 0.1913 -0.1913 -0.4619 -0.4619 -0.1913
0.4157 -0.0975 -0.4904 -0.2778 0.2778 0.4904
0.3536 -0.3536 -0.3536 0.3536 0.3536 -0.3536
0.2778 -0.4904 0.0975 0.4157 -0.4157 -0.0975
0.1913 -0.4619 0.4619 -0.1913 -0.1913 0.4619
0.0975 -0.2778 0.4157 -0.4904 0.4904 -0.4157
how this can be done ? 1)by using fixed point tool box 2)without using fixed point toolbox
can you explain please?(with codes)

Walter Roberson
Walter Roberson on 11 Mar 2011
Without, 5 bits of fraction, 2's complement applied to the entire number.
>> M = [0.3536 0.3536 0.3536 0.3536 0.3536 0.3536
0.4904 0.4157 0.2778 0.0975 -0.0975 -0.2778
0.4619 0.1913 -0.1913 -0.4619 -0.4619 -0.1913
0.4157 -0.0975 -0.4904 -0.2778 0.2778 0.4904
0.3536 -0.3536 -0.3536 0.3536 0.3536 -0.3536
0.2778 -0.4904 0.0975 0.4157 -0.4157 -0.0975
0.1913 -0.4619 0.4619 -0.1913 -0.1913 0.4619
0.0975 -0.2778 0.4157 -0.4904 0.4904 -0.4157];
>> dec2hex(typecast(int8(M * 2^F),'uint8'))
ans =
0B
10
0F
0D
0B
09
06
03
0B
0D
06
FD
F5
F0
F1
F7
0B
09
FA
F0
F5
03
0F
0D
0B
03
F1
F7
0B
0D
FA
F0
0B
FD
F1
09
0B
F3
FA
10
0B
F7
FA
10
F5
FD
0F
F3

Community Treasure Hunt

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

Start Hunting!