📄 dist.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.
%
% ******************************************************************
% DIST
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 6-17-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Computes distance measures and the likelihood ratio
%
% DESIGN NOTES
%
% See references.
%
% REFERENCES
%
% 1. "Distance Measures for Speech Processing", A.H. Gray
% and J.D. Markel, IEEE Trans. on ASSP, Vol. ASSP-24,
% no. 5, Oct. 1976
%
% 2. "Quantization and Bit Allocation in Speech Processing",
% A.H. Gray and J.D. Markel, IEEE Trans. on ASSP, Vol. ASSP-24
% no. 6, Dec. 1976
%
% 3. "A Note on Quantization and Bit Allocation in Speech Processing",
% A.H. Gray and J.D. Markel, IEEE Trans. on ASSP, Vol. ASSP-25
% no. 3, June 1977
%
% VARIABLES
%
% INPUTS
% m - Filter order
% l - Number of terms used in cepstral distance measure
% r - Autocorrelation sequence 1 (undistorted)
% rp - Autocorrelation sequence 2 (distorted)
%
% OUTPUTS
% dm - Distances array
% sumdm - Distances array summation (averaging over many frames)
% iframedm - Number of frames summation has run
%
% INTERNALS
% c, cp - Cepstral coefficients
% ra, rap - Filter autocorrelation lags
% alp, alpp - Filter ?
% a, ap - Filter direct form coefficients
% rc, rcp - Filter reflection coefficients
% del - Intermediate result for DM(1)
% delp - Intermediate result for DM(2)
% q - Intermediate result for DM(3) - DM(9)
% q1 - Intermediate result for DM(4), DM(8)
% q2 - Intermediate result for DM(5), DM(9)
% cepsum - Intermediate result for DM(7), DM(8), DM(9)
%
% CONSTANTS
% DBFAC - dB scale conversion scale factor
%
% ******************************************************************
function [ dm, sumdm, iframedm ] = dist( m, l, r, rp, sumdm, iframedm )
% DEFINE LOCAL CONSTANTS
DBFAC = 4.342944819;
% INITIALIZE LOCAL VARIABLES AND RETURN VECTORS
dm = zeros( 9, 1 );
% COMPUTE CEPSTRAL AND FILTER COEFFICIENTS
[ c, ra, alp, a, rc ] = cfind( m, l, r );
[ cp, rap, alpp, ap, rcp ] = cfind( m, l, rp );
% COMPUTE DM(0), DM(1)
del = ( r(1) * rap(1) ) + sum( 2 * r(2:m+1) .* rap(2:m+1) );
delp = ( rp(1) * ra(1) ) + sum( 2 * rp(2:m+1) .* ra(2:m+1) );
dm(1) = del / alp;
dm(2) = delp / alpp;
% COMPUTE DM(3)
q = ( ( dm(1) + dm(2) ) / 2.0 ) - 1;
if q >= 0.00
dm(3) = fin(q);
end
% COMPUTE DM(4)
q1 = ( alpp * r(1) ) / ( alp * rp(1) );
q = ( ( ( dm(1) / q1 ) + dm(2) * q1 ) * 0.5 ) - 1.0;
if q >= 0.00
dm(4) = fin(q);
end
% COMPUTE DM(5)
q2 = alpp / alp;
q = ( ( ( dm(1) / q2 ) + dm(2) * q2 ) * 0.5 ) - 1.0;
if q >= 0.00
dm(5) = fin(q);
end
% COMPUTE DM(6)
q = sqrt( dm(1) * dm(2) ) - 1.0;
qflag = ( q >= 0.00 );
if qflag
dm(6) = fin(q);
end
% COMPUTE DM(7), DM(8), DM(9)
cepsum = 2 * sum( ( c(1:l) - cp(1:l) ) .^ 2 );
if cepsum >= 0.0
dm(7) = DBFAC * sqrt( cepsum );
q = log(q1);
dm(8) = DBFAC * sqrt( cepsum + (q * q) );
q = log(q2);
dm(9) = DBFAC * sqrt( cepsum + (q * q) );;
else
qflag = FALSE;
end
% COMPUTE DM SUMMATIONS FOR AVERAGING DMs OVER MANY FRAMES
if qflag
sumdm(1:9) = sumdm(1:9) + dm(1:9);
sumdm(10) = sumdm(10) + sum( dm(3:9) / 7.0 );
iframedm = iframedm + 1;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -