FE_delta.cpp
上传用户:italyroyal
上传日期:2013-05-06
资源大小:473k
文件大小:2k
- ///////////////////////////////////////////////////////////////////////////////
- // This is a part of the Feature program.
- // Version: 1.0
- // Date: February 22, 2003
- // Programmer: Oh-Wook Kwon
- // Copyright(c) 2003 Oh-Wook Kwon. All rights reserved. owkwon@ucsd.edu
- ///////////////////////////////////////////////////////////////////////////////
- /****************************************************************************
* Computing delta coefficients, cepstral liftering, preemphasis
****************************************************************************/
#include "StdAfx.h"
#include "FE_feature.h"
-
/************************************************************************
* Compute Delta coefficients
************************************************************************/
-
int Fe::delta_compute(FeMatrix<float>& input, int filterLen, FeMatrix<float>& output)
{
- int num_frames=input.size();
- if(num_frames==0) return 0;
- int dim=input[0].size();
- output.Resize(num_frames,dim);
- vector<float> filterCoeff(filterLen);
- delta_init_filter(&filterCoeff[0], filterLen);
- delta_basic(input, output, &filterCoeff[0], filterLen);
- return(1);
}
- int Fe::delta_basic(FeMatrix<float>& input, FeMatrix<float>& output, float *filterCoeff, int filterLen)
- {
- int num_frames=input.size();
- if(num_frames==0) return 0;
- int dim=input[0].size();
- int i,j,n;
- int delta = (filterLen-1)/2;
- for(n=0;n<num_frames;n++){
- for(i=0;i<dim;i++){
- float sum = 0;
- for(j=0; j<filterLen; j++){
- float x = (n-delta+j >= 0) ? ((n-delta+j < num_frames) ? input[n-delta+j][i]: input[num_frames-1][i]) : input[0][i];
- sum += x * filterCoeff[j];
- }
- output[n][i] = sum;
- }
- }
- return(1);
- }
-
int Fe::delta_init_filter(float *filterCoeff, int filterLen)
{
- if(filterLen == 1){
- filterCoeff[0] = 1;
- return 1;
- }
int j;
- int center = (filterLen-1)/2;
float sqsum = 0;
for (j=0; j<filterLen; j++) {
filterCoeff[j] = (float)(j-center);
- sqsum += (filterCoeff[j])*(filterCoeff[j]);
}
- /* Assuming that cepstrum parameters are uncorrelated, */
- /* variances of cepstrum and delta cepstrum are set */
- /* approximately equal through the SQRT operation */
for (j=0; j<filterLen; j++) {
filterCoeff[j] /= (float)sqrt(sqsum);
}
return(1);
}