www.pudn.com > code.rar > code.m


%a golomb coder write by linghan liu 2008 
%first to encode the code to numbers count by nomuber of 0's 
clear 
a = input('code'); 
y=length(a); 
count0=0; 
count1=0; 
 
z(1)=0; 
c=2; 
for i=1:y 
    if (a(i)==0) 
        count0=count0+1; 
        count1=0; 
    else 
        count1=count1+1; 
 
    end 
    if (count1 ==1)&&(count0>0) 
        z(c)=count0; 
        c=c+1; 
        count0=0; 
    end 
end 
finalcode=[]; 
%the second part to encode the rise code 
for d= 1:length(z); 
    x=z(d); 
    m=3; 
    b=ceil(log2(m)); 
    q=floor((x-1)/m); 
    r=rem(x,m);   %find out the q and the remander 
 
    if q>=1 
        for i=1:q 
 
            v(i)=1;      %write q onesand  
        end 
        v(i+1)=0;       %write one zero 
 
    else 
        v=0; 
    end 
    if r < 2b - m 
        bits=b-1; 
    else 
        bits=b; 
    end 
    c=bits; 
    for i=1:bits 
        if r>=1 
            k=rem(r,2); 
            r=floor(r/2); 
        else k=0; 
        end 
        re(c)=k; 
        c=c-1; 
    end 
    encode =[v re]; 
     
    finalcode=[finalcode,encode]; 
end 
finalcode1=num2str(finalcode); 
finalcodes=strrep(finalcode1,' ','')