function ENCODEDVECTOR = prefix_encode(CODE,DATAVECTOR); % prefix_encode: encode data using given code book. % % Usage: % CODE = [ ... % bitstring_to_index([1]),... % bitstring_to_index([0,1]),... % bitstring_to_index([0,0,1]),... % bitstring_to_index([0,0,0]) ]; % DATAVECTOR = [ 0 1 2 3 0 0 0 0 ]; % ENCODEDVECTOR = prefix_encode(CODE,DATAVECTOR)' % print_without_spaces(ENCODEDVECTOR); % returns % 1010010001111 % %DATAVECTOR has alphabet {0,1,...,k-1} for %some integer k %CODE is a vector of length k giving the %indices of the codewords for 0,1,...,k-1 %respectively (usually generated by compactcodeP ). %ENCODEDVECTOR is the encoder output when %DATAVECTOR is memorylessly encoded by CODE. % % See also HUFFMAN_COMPRESS, COMPACTCODEP, CONCAT, % PREFIX_DECODE. % documented in % ftp://oz.ee.umn.edu/users/kieffer/seminar/notes2.ps % Change log: % 1999-07-01:DAV: This was very slow for large images, so I sped it up. % Now it's much faster. % 1999-05-06more documentation by David Cary % 1999-05-06:DAV: David Cary added more documentation % ???:JCK: originally by John C. Kieffer % http://www.ee.umn.edu/users/kieffer/programs.html n=length(DATAVECTOR); i=1:n; u(i) = CODE(DATAVECTOR(i)+1); ENCODEDVECTOR=concat(u); if(0) % working original program. n=length(DATAVECTOR); for i=1:n; u(i)=CODE(DATAVECTOR(i)+1); end ENCODEDVECTOR=concat(u); end; % end prefix_encode.m