Quantization

quantization is the process of approximating ("mapping") a continuous range of values (or a very large set of possible discrete values) by a relatively small ("finite") set of ("values which can still take on continuous range") discrete symbols or integer values.



The quantization process is the necessary and natural follower of the sampling operation. It is necessary because in practice the digital computer with is general purpose CPU is used to implement DSP algorithms. And since computers can only process finite word length (finite resolution/precision) quantities, any infinite precision continuous valued signal should be quantized to fit a finite resolution, so that it can be represented (stored) in CPU registers and memory.

Narrow range quantization matlab code


function [levelNumbers,scaling] = quantization(vect,bits)

%...'levelNumbers' contains the index of the quantization value
%...'scaling' contains 2 values, the lowest quant. value and delta

[M,N] = size(vect);
if (M>1)
vect = vect';
end

range = max(vect)-min(vect);
delta = roundVal(range/2^(bits));

levels = 2^bits;
base = roundVal(min(vect));

%quantValues = [base : delta : roundVal(max(vect)-delta)]' + delta/2;
quantValues = [base : delta : roundVal(max(vect)-delta)]';


inputArray = repmat(vect , length(quantValues), 1 );
quantArray = repmat(quantValues, 1 , length(vect));

quantDiff = abs(inputArray-quantArray);
[Y,I] = min(quantDiff);

quantResults=quantArray(I);
for i=1:length(quantResults)
levelNumbers(i) = find(quantResults(i)==quantValues);
end
scaling = [base, delta];

if length(quantResults)==0
levelNumbers=ones(1,length(vect));
end

function newVal = roundVal(num)
num = num*1e4;
num = round(num);
newVal = num*1e-4;

No comments:

Post a Comment

 
;