Example 1.2 Quantizing a Digital Signal

Contents

Creating a 4 row random column vector

format long
y = rand(4,1)
y =

   0.814723686393179
   0.905791937075619
   0.126986816293506
   0.913375856139019

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
y1 =

   1.0e+02 *

   2.085692637166538
   2.318827358913585
   0.325086249711376
   2.338242191715890

Then I apply the floor command to produce the integer.

z = floor(y1)
z =

   208
   231
    32
   233

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

dec2bin(z)
ans =

11010000
11100111
00100000
11101001