⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 huffmandeco.m

📁 MATLAB编写的huffman编解码程序
💻 M
字号:
function deco = huffmanDeco(enco, dict)
%    
%    Decodes the numeric Huffman code vector enco using the code dictionary
%    dict. The encoded signal is generated by the huffmanEeco function. 
%    The code dictionary can be generated using the huffmanDic function.
%--------------------------------------------------------------------------

isSigNonNumeric = max(cellfun('isclass', {dict{:,1}}, 'char') );
deco = {};

i = 1;
while(i <= length(enco))
    tempcode = enco(i); 
    found_code = is_a_valid_code(tempcode, dict);
    while(isempty(found_code) && i < length(enco))
        i = i+1;
        tempcode = [tempcode, enco(i)];
        found_code = is_a_valid_code(tempcode, dict);
    end
	deco{end+1} = found_code;
    i=i+1;
end

% Convert the decoded signal from cell array format to a double vector
if ( ~isSigNonNumeric )
    decoMat = zeros(size(deco));
    decoMat = feval(class(dict{1,1}), decoMat);  % to support single precision
    for i = 1 : length(decoMat)
        decoMat(i) = deco{i};
    end
    deco = decoMat;
end


%--------------------------------------------------------------------------
% Function: is_a_valid_code
% This functions does a reverse lookup for a signal. This function will
% compare the code with the entries in the codebook and return the signal
% if there is a match
function found_code = is_a_valid_code(code, dict)

found_code = [];
m = size(dict);
for i=1:m(1)
    if ( isequal(code, dict{i,2}) )  
        found_code = dict{i,1};
        return;
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -