📄 lsp34.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 (602) 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.
%
% ******************************************************************
% LSP34
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 6-13-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Independent nonuniform scalar quantization of line spectral pairs
%
% DESIGN NOTES
%
% Independent (nondifferential) scalar LSP quantization. Determine
% LSP quantization by refined sequential quantization. Because the
% quantization tables overlap, sequential quantization can produce a
% nonmonotonic LSP vector. For nonmonotinic LSPs, the quantization
% is refined by adjusting the quantization for minimum error by
% selecting 1 of the following 2 cases:
%
% 1. Quantize current LSP to next higher level
% 2. Quantize previous LSP to the next lower level
%
% VARIABLES
%
% INPUTS
% freq - Input LSPs, unquantized
% bits - Bit allocation
% no - Order (predictor order)
%
% OUTPUTS
% freq - Quantized LSPs
% findex - Quantized LSP table indicies
%
% INTERNALS
% i - Counter
% low - Minimum quantization error
% levels - Quantization levels allocated to current LSP
% dist - Quantization error
% errorup - Quantization error w.r.t. next higher quantile
% errordn - Quantization error w.r.t. next lower quantile
% Q - LSP quantization table, reorganized into a column vector
% for : based index computation
%
% GLOBALS
% lspQ - LSP quantization table
%
% CONSTANTS
% FSCALE - Frequency scale factor (system sample rate)
% MAXNO - Predictor order
%
% ******************************************************************
function [ freq, findex ] = lsp34( freq, no, bits )
% DECLARE GLOBAL CONSTANTS
global MAXNO
% DECLARE GLOBAL VARIABLES (STATIC)
global lspQ
% DEFINE CONSTANTS
FSCALE = 8000.00;
% INIT RETURN VECTOR
findex = zeros( MAXNO, 1 );
% INIT LOCAL VARIABLES
freq = FSCALE * freq;
levels = ( 2 .^ bits ) - 1;
% QUANTIZE ALL LSP FREQUENCIES AND FORCE MONOTONICITY
for i = 1:no
% QUANTIZE TO NEAREST OUTPUT LEVEL
dist = abs( freq(i) - lspQ(i,1:levels(i)+1) );
[ low, findex(i) ] = min( dist );
% ADJUST QUANTIZATION IF NONMONOTONICALLY QUANTIZED AND
% FIND ADJUSTMENT FOR MINIMUM QUANTIZATION ERROR
if i > 1
if lspQ( i,findex(i) ) <= lspQ( i-1,findex(i-1) )
errorup = abs( freq(i) - lspQ(i,min(findex(i)+1,levels(i) )) ) + ...
abs( freq(i-1) - lspQ(i-1, findex(i-1)) );
errordn = abs( freq(i) - lspQ(i,findex(i)) ) + ...
abs( freq(i-1) - lspQ(i-1,max(findex(i-1)-1,0)) );
% ADJUST INDEX FOR MINIMUM ERROR (AND PRESERVE MONOTONICITY)
if errorup < errordn
findex(i) = min( findex(i)+1, levels(i) );
while ( lspQ(i,findex(i)) < lspQ(i-1,findex(i-1)) )
findex(i) = min( findex(i)+1, levels(i) );
end
elseif i == 1
findex(i-1) = max( findex(i-1)-1, 0 );
elseif lspQ( i-1, max(findex(i-1)-1, 0) ) > lspQ( i-2, findex(i-2) )
findex(i-1) = max( findex(i-1)-1, 0 );
else
findex(i) = min( findex(i)+1, levels(i) );
while lspQ( i, findex(i) ) < lspQ( i-1, findex(i-1) )
findex(i) = min( findex(i)+1, levels(i) );
end
end
end
end
end
% CORRECT FINDEX VALUES TO MAINTAIN COMPATIBILITY WITH C IMPLEMENTATION
findex = findex - 1;
% QUANTIZE LSP FREQUENCIES USING INDICIES FOUND ABOVE
% RESHAPE TO EXPLOIT : BASED INDEXING FOR COLUMN VECTOR INSTEAD OF
% LOOP INDEXING IN A TWO-DIMENSIONAL ARRAY
Q = reshape( lspQ',160,1);
freq( 1:no ) = Q( ((0:no-1)'*16)+findex(1:no)+1 ) / FSCALE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -