www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/QuantizeTheVaryingFractionalInputsExample.m

    %% Quantize the Varying Fractional Inputs
%%
% *Note*: This example runs only in R2016b or later. If you are using an
% earlier release, replace each call to the function with the equivalent
% |step| syntax. For example, myObject(x) becomes step(myObject,x).

%%
% Quantize the varying fractional inputs between zero and five to the
% closest integers, and then plot the results.
hsqe = dsp.ScalarQuantizerEncoder;
hsqe.BoundaryPoints = [-.001 .499 1.499 ...
    2.499 3.499 4.499 5.001];
hsqe.CodewordOutputPort = true;
hsqe.Codebook = [0 1 2 3 4 5];
input = (0:0.02:5)';
[index, quantizedValue] = hsqe(input);
plot(1:length(input), [input quantizedValue]);