假设我在Matlab中有一些图,如下所示:
x = linspace(0,10,10000);
input= sin(x);我想把数据量化到一定数量的位。(我从技术上认识到,MATLAB量化了所有的图形。)我试过以下几种方法:
bits = 7;
output =floor(2^bits*input)/2^bits但是,只有当输入介于0和1之间时,这才有效。我应该做什么?
发布于 2014-09-07 20:58:31
基于方法#1 bsxfun的“内插式”方案
x = linspace(min(input),max(input),2^bits) %// Setup the quantizied levels
%// ranging from min to max of the input data
[~,ind1] = min(abs(bsxfun(@minus,input,x.'))) %//' Find the indices of the
%// levels nearest to the input data
output = x(ind1) %// Get the quantized values另外,不要使用与内置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.7891https://stackoverflow.com/questions/25714491
复制相似问题