matlab code about function of quantization
古いコメントを表示
I have been given a quantization function (matlab code) but I'm confused in some places, pls help....(PS: y is a signal(-1 to 1) and 12 bits is used to quantize)
===============================================================================
function [symbols_quant]=quantization(y)
b=12;
q=2/(2^b);
for i =1: length(y)
symbols_quant(i)= max(min((round(y(i) * 2^(b-1))/(2^(b-1)))-sign(y(i))*q/2 , 1) , -1);
==============================================================================
Question 1: why we should multiply the sample,y(i), with by 2^(b-1) , and then round it to get the quantized value? But not directly round it...What is the principle behind?
Thank you very much if you can give me a hand.
採用された回答
その他の回答 (3 件)
Azzi Abdelmalek
2013 年 3 月 13 日
function [symbols_quant]=quantization(y)
b=12
q=2/(2^b-1)
symbols_quant=round(y/q)*q
3 件のコメント
fdsa
2013 年 3 月 13 日
Azzi Abdelmalek
2013 年 3 月 13 日
Example
y=10
q=0.3
% after quantization y should be 9.9
% round(y/q)=round(10/0.3)=round(33.33)=33
% round(y/q)*q=33*0.3=9.9
fdsa
2013 年 3 月 13 日
Azzi Abdelmalek
2013 年 3 月 13 日
編集済み: Azzi Abdelmalek
2013 年 3 月 13 日
One way how a real ADC works
% for values from 0 to 10
n=12
q=10/(2^n-1)
max_val=10/2
u=6.5555 % Example
bit=zeros(1,n)
for k=1:n
if u>max_val
bit(k)=1
u=u-max_val
end
max_val=max_val/2
end
disp(bit) % The bits that codify your input.
quantized_value=sum(bit.*2.^(n-1:-1:0)*q)
カテゴリ
ヘルプ センター および File Exchange で Cast and Quantize Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!