%% Encode Number Sequence
% Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).

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

% Copyright 2012 The MathWorks, Inc.