2017/03/13

Matlab: How to use Quantiz with partition and codebook

The Quantiz function requires the Communications System Toolbox.
This quantization function requires at least an input signal and a partition vector.

Partition

The example below shows an input signal between 1 and 10. The partition vector equals [2 5 7]. When the signal is quantized, values become:

y = 0 if x <= 2
y = 1 if x <= 5
y = 2 if x <= 7
y = 3 if x > 7

>> x = 1:10

x =

     1     2     3     4     5     6     7     8     9    10

>> partition = [2 5 7]

partition =

     2     5     7

>> y = quantiz(x, partition)

y =

     0     0     1     1     1     2     2     3     3     3


Codebook

Using the same input signal x and partition above, add a codebook as:

>> codebook = [-4 0 2 4]

Insert the codebook as the third parameter in the Quantiz function. The index and quantized value quants are output:

>> [index,quants] = quantiz(x,partition,codebook)

index =

     0     0     1     1     1     2     2     3     3     3


quants =

    -4    -4     0     0     0     2     2     4     4     4



Reference

Quantization (MathWorks)

沒有留言:

張貼留言