Example 2:
An example analog signal is given as between [s]
clc;
clear all;
Sample this analog signal each 0.05 s and quantize using 3 bits.
3-bits gives us number of quantization value (n).
n=2^3
n = 8
Then sample the signal:
t = [0:.05:1] % Times at which to sample the sine function
t = 1×21
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
sig = 0.99*sin(2*pi*t) % Original continuous signal, a sine wave
sig = 1×21
0 0.3059 0.5819 0.8009 0.9415 0.9900 0.9415 0.8009
plot(t,sig)
1
Partion values between -1 and +1 and space 2/(n-1)
partition = [-1:2/7:1] % Length 8
partition = 1×8
-1.0000 -0.7143 -0.4286 -0.1429 0.1429 0.4286 0.7143 1.0000
codebook = [-(1):2/8:(1)] % Length 9, one entry for each interval
codebook = 1×9
-1.0000 -0.7500 -0.5000 -0.2500 0 0.2500 0.5000 0.7500
[index,quants] = quantiz(sig,partition,codebook); % Quantize.
quants
quants = 1×21
0 0.2500 0.5000 0.7500 0.7500 0.7500 0.7500 0.7500
plot(t,sig,'x',t,quants,'.')
legend('Original signal','Quantized signal');
axis([-0.1 1.1 -1.2 1.1])
2
Binary Codes
bindat=dec2bin(index)
bindat = 21×3 char array
'100'
'101'
'110'
'111'
'111'
'111'
'111'
'111'
'110'
'101'
'100'
'011'
'010'
'001'
'001'
'001'
'001'
'001'
'010'
'011'
'100'