www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/FindIndicesOfNearestCodewordsExample.m
%% Find Indices of Nearest Codewords %% % *Note*: This example runs only in R2016b or later. If you are using an % earlier release, replace each call to the function with the equivalent % |step| syntax. For example, myObject(x) becomes step(myObject,x). %% % Find the indices of nearest codewords based on Euclidean distances. hvqenc = dsp.VectorQuantizerEncoder(... 'Codebook', [-1 -1 1 1;1 -1 -1 1], ... 'CodewordOutputPort', true, ... 'QuantizationErrorOutputPort', true, ... 'OutputIndexDataType', 'uint8'); %% % Generate an input signal with some additive noise x = sign(rand(2,40)-0.5) + 0.1*randn(2,40); [ind, cw, err] = hvqenc(x); plot(cw(1,:), cw(2,:), 'rO', x(1,:), x(2,:), 'g.'); legend('Quantized', 'Inputs', 'location', 'best');