?? cbsearch.m
字號:
% MATLAB SIMULATION OF NSA FS-1016 CELP v3.2
% COPYRIGHT (C) 1995-99 ANDREAS SPANIAS AND TED PAINTER
%
% This Copyright applies only to this particular MATLAB implementation
% of the FS-1016 CELP coder. The MATLAB software is intended only for educational
% purposes. No other use is intended or authorized. This is not a public
% domain program and distribution to individuals or networks is strictly
% prohibited. Be aware that use of the standard in any form is goverened
% by rules of the US DoD. Therefore patents and royalties may apply to
% authors, companies, or committees associated with this standard, FS-1016. For
% questions regarding the MATLAB implementation please contact Andreas
% Spanias at (480) 965-1837. For questions on rules,
% royalties, or patents associated with the standard, please contact the DoD.
%
% ALL DERIVATIVE WORKS MUST INCLUDE THIS COPYRIGHT NOTICE.
%
% ******************************************************************
% CBSEARCH
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 7-11-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Find optimal MSPE excitation code word
%
% DESIGN NOTES
%
% Code book search is performed by closed-loop analysis using conventional
% minimum squared prediction error (MSPE) criteria of the perceptually
% weighted error signal. The code book is overlaped to allow recursive
% computational savings in routine cgain:
%
% index code book
% +-------------------------+
% 1 | 2(M-1) 2(M-1)+L-1 |
% 2 | 2(M-2) 2(M-2)+L-1 |
% : | : : |
% N-1 | . . |
% N | . . |
% : | 2 61 |
% : | 0 59 |
% +-------------------------+
%
% where: M = maximum code book size
% N = actual code book search size (any value between 1 & M)
% L = code word length
%
% each code word is: 2(M-index) -> 2(M-index)+L-1
%
% REFERENCES
%
% 1. Tremain, Thomas E., Joseph P. Campbell, Jr and Vanoy C. Welch,
% "A 4.8 kbps Code Excited Linear Predictive Coder," Proceedings
% of the Mobile Satellite Conference, 3-5 May 1988, pp. 491-496.
%
% 2. Campbell, Joseph P. Jr., Vanoy C. Welch and Thomas E. Tremain,
% "An Expandable Error-Protected 4800 bps CELP Coder (U.S. Federal
% Standard 4800 bps Voice Coder)," Proceedings of ICASSP, 1989.
% (and Proceedings of Speech Tech, 1989.)
%
% VARIABLES
%
% INPUTS/OUTPUTS
% l - Length of vectors
% v - Optimum excitation segment found
%
% INTERNALS
% gain - Gains for each codeword (vector)
% err - Error terms for each codeword (vector)
% codeword - Current codeword
% emax - Maximum error found during codebook search
% i - General purpose loop counter
%
% GLOBALS
% StochCB - Stochastic codebook
% cbindex - Stochastic codebook index
% ncsize - Stochastic codebook size
% mxsw - Excitation flag
% gindex - Stochastic codebook gain index
% cbgbits - Codebook gain quantization bit allocation
% cbgtype - Codebook gain quantization type
%
% CONSTANTS
% LEN - Length of truncated impulse response
% MAXNCSIZE - Maximum codebook size (max number of codewords)
% TRUE - General purpose boolean flag
% FALSE - General purpose boolean flag
%
% ******************************************************************
function v = cbsearch( l, v )
% DECLARE GLOBAL VARIABLES
global cbindex StochCB ncsize mxsw gindex cbgbits cbgtype
% DECLARE GLOBAL CONSTANTS
global TRUE FALSE MAXNCSIZE
% INITIALIZE LOCAL CONSTANTS
LEN = 30;
% INITIALIZE LOCAL VARIABLES
gain = zeros( MAXNCSIZE, 1 );
err = zeros( MAXNCSIZE, 1 );
% FIND GAIN AND -ERROR TERM FOR EACH CODE WORD AND SEARCH FOR BEST
% CODE WORD (MAX -ERROR TERM). CODEWORDS ARE OVERLAPPED BY SHIFTS
% OF -2 ALONG THE CODE VECTOR X. GAIN(I) AND ERR(I) CAN BE REPLACED
% BY SCALARS.
codeword = ( 2 * MAXNCSIZE ) - 2;
cbindex = 1;
[ gain(1), err(1) ] = cgain( StochCB(codeword+1:codeword+l), l, TRUE, LEN );
emax = err(1);
codeword = codeword - 2;
for i = 1:ncsize-1
[ gain(i+1), err(i+1) ] = cgain( StochCB(codeword+1:codeword+l), l, FALSE, LEN );
codeword = codeword - 2;
if err(i+1) >= emax
emax = err(i+1);
cbindex = i + 1;
end
end
% ESTABLISH POINTER TO THE BEST CODEWORD
codeword = 2 * (MAXNCSIZE - cbindex);
% GIVEN BEST CODEWORD, RECOMPUTE ITS GAIN TO CORRECT ANY ACCUMULATED
% ERRORS IN THE RECURSIONS
[ gain(cbindex), err(cbindex) ] = cgain( StochCB(codeword+1:codeword+l), l, TRUE, LEN );
% CONSTRAIN EXCITATION GAIN TO LIMITS IMPOSED BY MEXCITE3
if mxsw == 1
gain(cbindex) = mexcite3( gain(cbindex) );
end
% DO GAIN QUANTIZATION (UNNESCESSARY FOR CLOSED-LOOP QUANTIZATION)
if strcmp( cbgtype, 'none' ) == 0
if cbgbits == 5
[ gindex, gain(cbindex) ] = gaincode( gain(cbindex) );
else
fprintf( 'cbsearch: not quantizing cbgain\n' );
end
end
% SCALE SELECTED CODE WORD VECTOR -> EXCITATION VECTOR
v = ( gain(cbindex) * StochCB(codeword+1:codeword+l) )';
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -