%% Example 1.2 Quantizing a Digital Signal
%% Creating a 4 row random column vector

format long
y = rand(4,1)

% This vector has components between 0 and 1. The command format long makes MATLAB display more digits.
%
%
%% Converting it to an integer between 0 and 256
% I'll do eight bit quantization. Since 2^8=256 I want to turn each component of y into an integer between 0 and 256. To do this, I multiply y by 256, then replace each component by the greatest integer less than or equal to it.

y1 = 256*y

%
% Then I apply the floor command to produce the integer.

z = floor(y1)

%
% Finally, I want to convert to a binary vector. The command dec2bin does that.

dec2bin(z)