Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab中的扩展Huffman编码_Matlab_Huffman Code - Fatal编程技术网

Matlab中的扩展Huffman编码

Matlab中的扩展Huffman编码,matlab,huffman-code,Matlab,Huffman Code,嗨,我用扩展的哈夫曼编码编码1000个符号的消息时遇到问题。我已经有字典了。我只需要对信息进行编码。然而,我不知道如何做到这一点。有什么想法吗 我正在使用Matlab bdw。以下是我使用的代码: %Extended Huffman prob=0.1; m=4; %Generating the probabilities for i = 1:2^m q(i) = 1; for j=0: m-1 b=2^j; if bitand(i-1,b)

嗨,我用扩展的哈夫曼编码编码1000个符号的消息时遇到问题。我已经有字典了。我只需要对信息进行编码。然而,我不知道如何做到这一点。有什么想法吗


我正在使用Matlab bdw。

以下是我使用的代码:

%Extended Huffman 
prob=0.1;
m=4;

%Generating the probabilities

 for i = 1:2^m
   q(i) = 1;
    for j=0: m-1
      b=2^j;
      if bitand(i-1,b)
          q(i)= q(i)*prob;
      else 
          q(i)= q(i)*(1-prob);
     end
   end
end


disp ('Sum of probabilities');
disp (sum(q));

disp('Entropy per symbol');%should be equal to 1
E=sum(q.*log2(1./q));

disp(E/m); 


%huffman 

s=0:2^m-1; %There are 16 symbols from 0000 -> 1111
[dict,avglen] = huffmandict(s,q); %probabilities 
我已经在扩展的哈夫曼中尝试过这种方法,消息大小确实减少了,但没有减少很多,我不知道这是否是一种正确的方法。首先将消息分为4位,并将获得的十进制值与字典进行比较。然后获得新的编码信息:

for j=(0:4:1000-1)
    newcode=message(j+1:j+4); %Dividing the message into 4 bits and saving the     
                              %corresponding decimal values
   array(:,a)=bi2de(newcode);
   a=a+1;
end

 for(f=1:250)
   for(i=1:15)
     if(array(f)==cell2mat((dict(i,1)))) %cell2mat will obtain the value of the cell
     encodedmsg= horzcat(encodedmsg, dict(i,2)); %horzcat will concatenate the array                    with its corresponding codeword
  end
 end
end

你的字典和留言是哪种格式的?这些信息将有助于理解哈夫曼编码的实现。您可以在此处的代码中选中
norm2huff