フィルターのクリア

How do i quantize data with N levels?

35 ビュー (過去 30 日間)
Deniz Bozdogan
Deniz Bozdogan 2021 年 11 月 3 日
コメント済み: Mathieu NOE 2021 年 11 月 19 日
I have the following code and have to quantize Y with N=8 levels in the uniform quantizer where Y=X1+X2 and x1∈[0,4] x2∈[-2,0]. Can you help me about it? Thank you in advance.
close all;
clear all;
rand('seed', sum(100*clock));
x1 = 0 + (4-0) .* rand(1000000,1);
x2 = -2 + (0-(-2)) .* rand(1000000,1);
y=x1+x2;

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 11 月 5 日
hello
here an example of code and results
N = 1000;
x = 1:N-1;
signal = sin(x*2*pi/N);
nbits = 3; % 3 bits = 8 qantization levels
qLevels = 2^nbits ;
% The next step will be to scale your signal to have the same magnitude as your number of bits.
signalMin = min(signal);
signalMax = max(signal);
scalingFactor = (signalMax-signalMin)/qLevels;
signal_scaled = signal / scalingFactor ;
% This gives you a signal ranging from -8 to 8.
% I will use round(), then scale the signal back to its original magnitude
signal_scaled = round(signal_scaled);
signal_scaled = signal_scaled * scalingFactor;
plot(x,signal,x,signal_scaled);
  1 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 11 月 19 日
hello
problem solved ?

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by