n-bit Quantizer
Made in Matlab
Program:
function [YBit,BinCounts,LowerBucketValue,UpperBucketValue,UniqueQuantize] = quantize(Samples,Bits,LowerRange,UpperRange)
Range = UpperRange-LowerRange;
Bins = 2^Bits;
BinRange = Range/Bins;
BinCounts = zeros(1,Bins);
YBit = Samples;
UniqueQuantize=[];
for SampleIndex = 1:length(YBit)
for BinIndex = 1:Bins
LowerBucketValue = ((BinIndex-1)*BinRange)+LowerRange;
UpperBucketValue = ((BinIndex)*BinRange)+LowerRange;
if YBit(SampleIndex) < UpperBucketValue && YBit(SampleIndex) >= LowerBucketValue
BinCounts(BinIndex) = BinCounts(BinIndex)+1;
BucketMean = (LowerBucketValue+UpperBucketValue)/2;
YBit(SampleIndex) = BucketMean;
if(isempty(find(UniqueQuantize==BucketMean)))
UniqueQuantize(length(UniqueQuantize)+1)=BucketMean;
end
end
end
end
end
General Description:
The quantize function in MATLAB is designed to perform uniform quantization on a given array of input samples. It accepts four input parameters: the array of real-valued samples (samples), the number of quantization bits (bits), and the lower and upper bounds of the quantization range (lowerRange and upperRange). Based on the number of bits specified, the function computes the number of bins and determines the range of each bin accordingly.
Within the function, each sample is evaluated to determine which bin it falls into. The sample is then replaced by the mean value of that bin, effectively quantizing the data to discrete levels. As this process occurs, the function keeps track of how many samples fall into each bin using the binCounts array. Additionally, it maintains a list of the unique quantized values encountered in unique_Quantize.
The final output of the function includes the quantized data array (y3bit), the histogram of bin occupancy (binCounts), and the lower and upper boundaries of the most recently processed bin (lowerBucketValue and UpperBucketValue). This function provides a straightforward implementation of mid-rise uniform quantization, useful in signal processing and data compression contexts.


Original Aduio Samples

Quantized Aduio Samples