quantisation using matlab
조회 수: 3 (최근 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!