?? 1huffmancodding.m
字號:
function [huffcodes,symbo]=huffmancodding(symbi,p)
%%
%Assignment #1a Part2/2 ITC
%Subj: Huffman Decoder
%Instr : Lt Col Dr. Arif Wahla
%Code by PA-34715 Maj Syed Ghazanfar Ali Shah Bukhari (MSEE-14)
%Military College of Signals, National University of Sciences & Technology
%References: (1) ALIREZA LIAGHAT Digital & Analog Communications
% SHIRAZ UNIVERSITY OF TECHNOLOGY
% (2) Help Topics MATLAB ver 2008a
%Dated. April 06, 2009
%%
p=p/sum(p);
[pp,XI]=sort(p,'descend')
% p=fliplr(sort(p))
p=pp;
symbo=symbi(XI);
L=length(p);
%%
huffmatrix=[p' zeros(L,L-2)];
code=cell(L,L-1);
%%
for i=2:L-1
q=p(1:L+1-i);
p(1:L+1-i)=[p(1:L-i) sum([p(L+1-i) p(L+2-i)])];
p(L+2-i)=[];
p=sort(p);
p=fliplr(p);
a=(abs(p-q))<eps;
r=find(a==0);
c(i-1)=r(1);
huffmatrix((1:L+1-i),i)=p;
end
%%
j=2;
code{1,L-1}=0;
code{2,L-1}=1;
for i=L-1:-1:2
code{j,i-1}=[code{c(i-1),i} 0];
code{j+1,i-1}=[code{c(i-1),i} 1];
for k=1:j
if k~=c(i-1)
for m=1:j-1
F=code{m,i-1};
if isempty(F)
code{m,i-1}=code{k,i};
break;
end
end
continue;
end
end
j=j+1;
end
%%
huffcodes=cell(L+1,2);
huffcodes{1,1}='probability';
huffcodes{1,2}='code';
%%
for i=1:L
code{i,1}=num2str(code{i,1});
a=isspace(code{i,1});
r=find(a==1);
code{i,1}(r)=[];
huffcodes{i+1,1}=huffmatrix(i,1);
huffcodes{i+1,2}=code{i,1};
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -