Matlab中的数据量化
假设我在Matlab中有一些绘图,如下所示:Matlab中的数据量化,matlab,Matlab,假设我在Matlab中有一些绘图,如下所示: x = linspace(0,10,10000); input= sin(x); 我想把数据量化到一定的位数。(我意识到MATLAB从技术上量化了它的所有图形。)我尝试了以下方法: bits = 7; output =floor(2^bits*input)/2^bits 但这仅在输入介于0和1之间时有效。我该怎么办 方法#1bsxfun基于“插值查找”方案- 此外,尽量不要使用与内置MATLAB函数名相同的变量名,在本例中,它是input 方法
x = linspace(0,10,10000);
input= sin(x);
我想把数据量化到一定的位数。(我意识到MATLAB从技术上量化了它的所有图形。)我尝试了以下方法:
bits = 7;
output =floor(2^bits*input)/2^bits
但这仅在输入介于0和1之间时有效。我该怎么办 方法#1bsxfun
基于“插值查找”方案-
此外,尽量不要使用与内置MATLAB函数名相同的变量名,在本例中,它是input
方法#2
interp1
基于-
x = linspace(min(input),max(input),2^bits) %// Setup the quantizied levels
%// ranging from min to max of the input data
output = interp1(x,x,input,'nearest') %// Get quantized values with 1-D interpolation
%// to the nearest quantized levels
范例-
input [Input data] =
0.8017 1.0533 -0.7489 -0.9363 -1.2691 0.4980 2.7891
bits [No. of bits used for quantization ] =
2
x [These are 2^bits quantized levels ranging from min to max of input] =
-1.2691 0.0836 1.4364 2.7891
output [Input data is brought to the nearest quantized levels taken from x] =
1.4364 1.4364 -1.2691 -1.2691 -1.2691 0.0836 2.7891
好奇-这里提供的任何解决方案对您有用吗?仍在研究解决方案,但目前我正在试验quantiz函数。
input [Input data] =
0.8017 1.0533 -0.7489 -0.9363 -1.2691 0.4980 2.7891
bits [No. of bits used for quantization ] =
2
x [These are 2^bits quantized levels ranging from min to max of input] =
-1.2691 0.0836 1.4364 2.7891
output [Input data is brought to the nearest quantized levels taken from x] =
1.4364 1.4364 -1.2691 -1.2691 -1.2691 0.0836 2.7891