⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smt.m

📁 实现fs1016w的CELP的低速率语音编解码功能的基于vc开发环境的原代码。
💻 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.
%
% ******************************************************************
% SMT
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 8-7-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Smooth pitch delay (tau) when many errors are detected in the
% Hamming block.
%
% DESIGN NOTES
%
% Smoothes tau (pitch lag) when errors are detected:
%
% If the variance of past tau values is within the range VARLIMIT
% (indicating voiced speech) the validity of the current tau value
% is tested.  If the current value of TAU is within the range TAULIMIT,
% TAU is passed.  If TAU is not within that range TAULIMIT, TAU is reset
% to the average value of taus.
%
% The array OLDTAU contains past values of tau.  The array VECTOR
% is constructed from the array OLDTAU and TAU3 for subframes 1
% and 2 (TAU3 is a future absolute tau value).  For subframes 3
% and 4 there are no valid future values (since delta taus in the
% future are not valid), therefore the array VECTOR is constructed
% entirely from the array OLDTAU.  Decisions concering smoothing of
% a particular tau are made on the variance of the array VECTOR and
% the tau in question (TAU).
%
% If the value of tau is smoothed in subframe 3, smoothing is disabled
% for subframe 4 of the same frame since the tau value in subframe 4
% is a delta based on subframe 3.
%
% Note:  The smoothing parameters should be capable of adapting
% to various bit error rate estimates. For example, different
% values of SYNDAVG should select different levels of TAULIMIT and
% VARLIMIT.
%
% VARIABLES
%
% INPUTS
%   tau          -     Unsmoothed tau value (pitch lag value)
%   twoerror     -     Error flag indicating occurrence of 2 errors
%   syndavg      -     Error rate estimation parameter
%   tau3         -     Third tau value
%   subframe     -     Current subframe number
%
% OUTPUTS
%   tau          -     Smoothed pitch lag value
%
% INTERNALS
%   vector       -     Vector of smoothing parameters (lags)
%   var          -     Variance of smoothing parameters
%   avg          -     Mean of smoothing parameters
%
% GLOBALS
%   enableSMT    -     Smoothing enable/disable flag
%   oldtau       -     Vector of old pitch lags
%   FrameCnt     -     Current frame number
%
% CONSTANTS
%   TAUHISTORY   -     History buffer size, pitch delay smoothing
%   TAULIMIT     -     Pitch delay excursion limit, "         "
%   TRUE         -     Logical 1
%   FALSE        -     Logical 0
%   SYNDLIMIT    -     Error detection smoothing threshold
%   VARLIMIT     -     Variance limit for TAU history
%
% ******************************************************************

function tau = smt( tau, twoerror, syndavg, tau3, subframe )

% DECLARE GLOBAL VARIABLES
global enableSMT oldtau FrameCnt

% DECLARE GLOBAL CONSTANTS
global TAUHISTORY TAULIMIT TRUE FALSE

% DEFINE LOCAL CONSTANTS
SYNDLIMIT = 0.04;
VARLIMIT = 15;

% EXCLUDE SUBFRAME 4 FROM SMOOTHING
if subframe ~= 4
    enableSMT = TRUE;
end

% DO SMOOTHING IF TWOERROR FLAG OR SYNDLIMIT IS EXCEEDED
if ( ( twoerror == TRUE ) | ( syndavg > SYNDLIMIT ) ) & ...
   ( enableSMT == TRUE )
    if subframe == 1
        vector(1:3) = oldtau(1:3);
        vector(4)   = tau3;
    elseif subframe == 2
        vector(1:3) = oldtau(1:3);
        vector(4)   = tau3;
    elseif subframe == 3
        vector(1:4) = oldtau(1:4);
    elseif subframe == 4
        vector(1:4) = oldtau(1:4);
    else
        fprintf( 'smoothtau: Error in subframe number\n' );
    end

    % GENERATE STATISTICS OF PITCH LAG (TAU) HISTORY (MEAN AND VARIANCE)
    avg = mean(vector);
    var = std(vector) * std(vector);

    % CHECK FOR SMOOTHING CONDITION
    if ( var < VARLIMIT ) & ( ( tau >= avg + TAULIMIT ) | ...
                              ( tau <= avg - TAULIMIT ) )
        tau = round(avg);
        fprintf( 'smt: tau reset to avg @ frame %d\n', FrameCnt );

        % DISABLE SMOOTHING FOR SUBFRAME 4
        if subframe == 3
            enableSMT = FALSE;
            fprintf( 'smt: smoothing disabled for subframe 4\n' );
        end
    end
end

% UPDATE TAU HISTORY
oldtau(2:TAUHISTORY) = oldtau(1:TAUHISTORY-1);
oldtau(1)            = tau;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -