quantisation using matlab
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How can i quantize decimal numbers with fractional parts(like 3.111112,1.22213) to specified number of bits using matlab?
1 commentaire
Knut
le 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));
Réponses (3)
Walter Roberson
le 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.)
0 commentaires
Walter Roberson
le 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
0 commentaires
Voir également
Catégories
En savoir plus sur Fixed-Point Designer dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!