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

    %% Encode a Sequence Of Numbers
%%
% *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).

%%
hue = dsp.UniformEncoder;
hue.PeakValue = 2;
hue.NumBits = 4;
hue.OutputDataType = 'Signed integer';
x = [-1:0.01:1]'; % Create an input sequence
x_encoded = hue(x);
plot(x, x_encoded,'.');
xlabel('Input'); ylabel('Encoded Output'); grid