www.pudn.com > CELP.ZIP > CBsearch.m


function [synth_e0]=CBsearch(sube0) 
 
% This search routine is based on algebraic ternary codebook search. No real codebook exists! 
% Please refer to the following reference 
% Y-H. Kao, Low Complexity CELP Speech Coding at 4.8 kbps, Master thesis 1992, University of Maryland 
 
global h szsubf subvec nzero numsubv cindex cgain sub_cnt 
 
% For the first sub-frame, which is empty, just assume a stoch code 
if sub_cnt==1        
    cindex(sub_cnt)=512; 
    cgain(sub_cnt)=-1; 
else 
     
    % Each subframe (60) is divided into 3 sub-vectors(20). Only 4 points in each vector are 1 or -1; 
    offset=subvec/nzero; 
 
    for i=1:szsubf/(subvec/nzero)                    
        wex(i)=sube0((i-1)*offset+1:i*offset)*h(1:offset)';           % Weight the error signal 
    end 
 
    % Compute cross-correlation of error signal and code on sub-vector level 
    for i=1:numsubv 
        sub(i,1)=wex((i-1)*nzero+1)+wex((i-1)*nzero+2)+wex((i-1)*nzero+3)+wex((i-1)*nzero+4);     
        sub(i,2)=wex((i-1)*nzero+1)+wex((i-1)*nzero+2)-wex((i-1)*nzero+3)-wex((i-1)*nzero+4); 
        sub(i,3)=wex((i-1)*nzero+1)-wex((i-1)*nzero+2)+wex((i-1)*nzero+3)-wex((i-1)*nzero+4); 
        sub(i,4)=wex((i-1)*nzero+1)-wex((i-1)*nzero+2)-wex((i-1)*nzero+3)+wex((i-1)*nzero+4); 
        sub(i,5)=-wex((i-1)*nzero+1)+wex((i-1)*nzero+2)+wex((i-1)*nzero+3)-wex((i-1)*nzero+4); 
        sub(i,6)=-wex((i-1)*nzero+1)+wex((i-1)*nzero+2)-wex((i-1)*nzero+3)+wex((i-1)*nzero+4); 
        sub(i,7)=-wex((i-1)*nzero+1)-wex((i-1)*nzero+2)+wex((i-1)*nzero+3)+wex((i-1)*nzero+4); 
        sub(i,8)=-wex((i-1)*nzero+1)-wex((i-1)*nzero+2)-wex((i-1)*nzero+3)-wex((i-1)*nzero+4); 
    end 
     
    % Compute cross-correlation of error signal and code on subframe level 
    for i=1:8 
        for j=1:8 
            for k=1:8 
                cor((i-1)*8*8+(j-1)*8+k)=sub(1,i)+sub(2,j)+sub(3,k); 
            end 
        end 
    end 
 
    % Find the best estimate 
    eng=12*sum(h(1:5).^2); 
    gain=cor/eng; 
    [pk,cindex(sub_cnt)]=max(cor.*gain); 
 
    cgain(sub_cnt)=gain(cindex(sub_cnt)); 
     
end 
 
% Given the best estimate of stoch code and gain, synthesize the stochastic excitation 
synth_e0=exc_syn(cindex(sub_cnt),cgain(sub_cnt));