quantisation using matlab
1 回表示 (過去 30 日間)
古いコメントを表示
How can i quantize decimal numbers with fractional parts(like 3.111112,1.22213) to specified number of bits using matlab?
1 件のコメント
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
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.)
0 件のコメント
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Fixed-Point Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!