quantisation using matlab

3 次查看(过去 30 天)
fit institute
fit institute 2011-3-10
How can i quantize decimal numbers with fractional parts(like 3.111112,1.22213) to specified number of bits using matlab?
  1 个评论
Knut
Knut 2011-3-10
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));

请先登录,再进行评论。

回答(3 个)

Walter Roberson
Walter Roberson 2011-3-10
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 2011-3-11
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 2011-3-11
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

类别

Help CenterFile Exchange 中查找有关 Fixed-Point Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by