What function to use to quantize a variable

9 ビュー (過去 30 日間)
Shawn
Shawn 2022 年 2 月 9 日
コメント済み: Shawn 2022 年 2 月 10 日
I think this is a fairly simple problem but not sure what Matlab function to use. I have several variables calculated in normal double precision. They are signed and symetrically bounded between a speficied negative and positive value. I need to "quantize" the variables so that they have a resolution of one part in 64 (6 bit) or one part in 128 (7 bit) resolution between the upper and lower bounds. The output should be a normal double percision variable but "quantized" as described. Not sure what Matlab function(s) or scripts to use.
I do not have any additional tooboxes so need to solve within basic Matlab.
Thanks
  1 件のコメント
HighPhi
HighPhi 2022 年 2 月 9 日
can you give us an example variable and desired output?

サインインしてコメントする。

回答 (1 件)

David Hill
David Hill 2022 年 2 月 9 日
Something like this.
x=100*rand(1000,1)-50;
h=linspace(-50,50,129);%for 128 resolution
[~,~,bin]=histcounts(x,h);
q=x(bin);
  1 件のコメント
Shawn
Shawn 2022 年 2 月 10 日
Dave,
Thanks. Not exactly what I was looking for but enough to set me on the correct path. The script below solves my problem. In the example, I'm taking a variable that spans a range from -5 t0 5 and quantizing into 64 levels. The behavior around zero is particularly what I wanted.... output is zero around zero.
x=linspace(-5,5,10000); % Create vector for example
q = 10/64; % Set quantization = input range/desired quantization
y = q * round(x/q); % This accomplishes the quantization
scatter(x,y) % Show results. Zoom in to see results
grid on

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFractals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by