📄 delay.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.
%
% ******************************************************************
% DELAY
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 7-5-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Time delay a bandlimited signal using point-by-point recursion
%
% DESIGN NOTES
%
% Subroutine to time delay a bandlimited signal by resampling the
% reconstructed data (aka sinc interpolation). The well known
% reconstruction formula is:
%
% | M2 sin[pi(t-nT)/T] M2
% y(n) = X(t)| = SUM x(n) --------------- = SUM x(n) sinc[(t-nT)/T]
% | n=M1 pi(t-nT)/T n=M1
% |t=n+d
%
% The interpolating (sinc) function is Hamming windowed to bandlimit
% the signal to reduce aliasing.
%
% Multiple simultaneous time delays may be efficiently calculated
% by polyphase filtering. Polyphase filters decimate the unused
% filter coefficients. See Chapter 6 in C&R for details.
%
% REFERENCES
%
% 1. Crochiere & Rabiner, Multirate Digital Signal Processing,
% Prentice-Hall 1983, Chapters 2 and 6.
%
% 2. Kroon & Atal, "Pitch Predictors with High Temporal Resolution,"
% ICASSP '90, S12.6
%
% VARIABLES
%
% INPUTS
% x - Input signal
% start - Beginning of the output sequence
% n - Length of the input sequence
% d - Fractional pitch
% m - Integer pitch
%
% OUTPUTS
% y - Delayed input signal
% x - Input signal with zeroed upper elements
%
% INTERNALS
% kmin - Lower bound on k
% kmax - Upper bound on k
% i - General purpose loop variable
% index - Quantized fractional pitch delay (using dfrac quantiles)
%
% GLOBALS
% dfrac - Quantized fractional delays (5)
% twelfths - Fractional delays for hamming window
% wsinc - Windowed sinc interpolation kernel
% hwin - Hamming window for application to sinc interp. kernel
% FirstDelay - First call flag
% DelaySize - Length of interpolation interval, in samples (8)
% DelayM1 - Start of interpolation interval (-4)
% DelayM2 - End of interpolation interval (3)
%
% CONSTANTS
% TRUE - Boolean state
% FALSE - Boolean state
% MAXLP - Maximum pitch prediction frame size
% NFRAC - Number of fractional delays (5)
%
% ******************************************************************
function [ x, y ] = delay( x, start, n, d, m )
% DECLARE GLOBAL VARIABLES
global dfrac twelfths wsinc hwin FirstDelay DelaySize DelayM1 DelayM2
% DECLARE GLOBAL CONSTANTS
global TRUE FALSE NFRAC MAXLP
% INIT RETURN VECTOR AND LOCAL VARIABLES
y = zeros( MAXLP, 1 );
kmin = DelayM1;
kmax = kmin + DelaySize - 1;
% GENERATE HAMMING WINDOWED SINC INTERPOLATING FUNCTION FOR EACH
% ALLOWABLE FRACTION. THE INTERPOLATING FUNCTIONS ARE STORED IN
% TIME REVERSE ORDER (I.E., DELAY APPEARS AS ADVANCE) TO ALIGN
% WITH THE ADAPTIVE CODE BOOK V0 ARRAY. THE INTERP FILTERS ARE:
% WSINC(.,0) FRAC = 1/4 (3/12)
% WSINC(.,1) FRAC = 1/3 (4/12)
% . .
% WSINC(.,4) FRAC = 3/4 (9/12)
if FirstDelay == TRUE
hwin = ham( (12*DelaySize) + 1 );
for i = 1:NFRAC
wsinc( 1:DelaySize, i ) = sinc( dfrac(i) + (kmin:kmax) ) .* ...
hwin( 12*(0:DelaySize-1) + twelfths(i) + 1 );
end
FirstDelay = FALSE;
end
% QUANTIZE FRACTIONAL PITCH
index = qd(d);
% RESAMPLE
for i = 0:n-1
x( start + i ) = sum( x( start - m + i + (kmin:kmax) ) .* ...
wsinc((1:DelaySize),index) );
end
% THE V0 ARRAY IN PSEARCH AND PGAIN MUST BE ZERO ABOVE START BECAUSE
% OF OVERLAP AND ADD CONVOLUTION TEHNIQUES USED IN PGAIN
y( 1:n ) = x( start:start+n-1 );
x( start:start+n-1 ) = zeros( n, 1 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -