📄 postfilt.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.
%
% ******************************************************************
% POSTFILT
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 8-9-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Reduce coder noise by applying an adaptive postfilter to output speech
%
% DESIGN NOTES
%
% Adaptive postfilter routine to reduce perceptual coder noise.
% This filter emphasizes spectral regions predicted by
% short-term LPC analysis, which tends to mask coder noise by
% concentrating it under the formant peaks. Unfortunately, acoustic
% background noise may also be enhanced because LPC analysis often
% models acoustic noise instead of speech formants. In addtion,
% postfiltering can be detrimental to tandem coding if not taken
% into consideration. To overcome these problems, FS1016 SHOULD
% eventually incorporate the postfilter's enhancement properties
% into the analysis process.
%
% Adaptive spectral tilt compensation is applied to flatten the
% overall tilt of the postfilter. Slight high frequency boost is
% applied for output shaping. A pitch postfilter is used to reduce
% pitch buzz. Finally, AGC compensates for the filter gains using
% a time constant set by parameter TC that should be dependent on
% frame length.
%
% REFERENCES
%
% 1. Chen & Gersho, Real-Time Vector APC Speech Coding at 4800 bps
% with Adaptive Postfiltering, ICASSP '87
%
% 2. Juin-Hwey (Raymond) Chen, "Low-Bit-Rate Predictive Coding of
% Speech Waveforms Based on Vector Quantization," PhD Dissertation,
% UCSB ECE Dept., March 1987.
%
% 3. Ramamoorthy, Jayant, Cox, & Sondhi, "Enhancement of ADPCM Speech
% Coding with Backward-Adaptive Algorithms for Postfiltering and
% Noise Feedback," IEEE JOSAIC, Feb. 1988, pp. 364-382.
%
% VARIABLES
%
% INPUTS
% s - Input speech (coder output,non-postfiltered)
% l - Subframe size
% alpha - Filter parameter
% beta - Filter parameter
% powerin - Input power estimate
% powerout - Output power estimate
% dp1 - Filter memory
% dp2 - Filter memory
% dp3 - Filter memory
% fci - LPC predictor poles
% no - Predictor order
%
% OUTPUTS
% s - Output speech (postfiltered)
% powerin - Input power estimate
% powerout - Output power estimate
% dp1 - Filter memory
% dp2 - Filter memory
% dp3 - Filter memory
%
% INTERNALS
% pcexp1 - Bandwidth expanded predictor poles = postfilter zeros
% pcexp2 - Bandwidth expanded predictor poles = postfilter poles
% rcexp2 - Reflection coefficients derived from postfilter poles
% newpowerin - Input power estimate vector
% newpowerout - Output power estimate vector
% agcScale - Automatic gain control scaling vector
% agcUnity - Unity gain locations in agc vector
% ast - Spectral tilt compensation filter memory
%
% GLOBALS
% ipZ - Input power estimation filter memory
% opZ - Output power estimation filter memory
%
% CONSTANTS
% TC - Input/Output power estimate time constant
%
% ******************************************************************
function [ s, powerin, powerout, dp1, dp2, dp3 ] = ...
postfilt( s, l, alpha, beta, powerin, powerout, dp1, dp2, ...
dp3, fci, no )
% DECLARE GLOBAL CONSTANTS
global TC
% DECLARE GLOBAL VARIABLES
global ipZ opZ
% ALLOCATE LOCAL FILTER MEMORY (SPECTRAL TILT COMPENSATOR)
ast = zeros( 2, 1 );
% ESTIMATE INPUT POWER
[ newpowerin, ipZ ] = filter( [TC 0], [1 -1+TC], ( s .* s ), ipZ );
powerin = newpowerin(l);
% DO BANDWIDTH EXPANSION ON PREDICTOR POLES TO FORM PERCEPTUAL POSTFILTER
pcexp1 = bwexp( beta, fci, no );
pcexp2 = bwexp( alpha, fci, no );
% APPLY POLE-ZERO POSTFILTER
[ dp1, s ] = zerofilt( pcexp1, no, dp1, s, l );
[ dp2, s ] = polefilt( pcexp2, no, dp2, s, l );
% ESTIMATE SPECTRAL TILT (1ST ORDER FIT) OF POSTFILTER
% DENOMINATOR DOMINATES (POLES)
rcexp2 = pctorc( pcexp2, no );
% ADD TILT COMPENSATION BY A SCALED ZERO (DON'T ALLOW HF ROLL-OFF)
ast(1) = 1.0;
if rcexp2(1) > 0.0
ast(2) = -0.5 * rcexp2(1);
else
ast(2) = 0.00;
end
[ dp3, s ] = zerofilt( ast, 1, dp3, s, l );
% ESTIMATE OUTPUT POWER
[ newpowerout, opZ ] = filter( [TC 0], [1 -1+TC], ( s .* s ), opZ );
powerout = newpowerout(l);
% INCORPORATE SAMPLE-BY-SAMPLE AUTOMATIC GAIN CONTROL
agcUnity = find( newpowerout <= 0 );
newpowerout( agcUnity ) = ones( length( agcUnity ), 1 );
agcScale = sqrt( newpowerin ./ newpowerout );
agcScale( agcUnity ) = ones( length( agcUnity ), 1 );
s = s .* agcScale;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -