Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

AvgMFCC.java

00001 /*
00002  *  Copyright 2006-2007 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
00021  */
00022 
00023 package com.meapsoft.featextractors;
00024 
00025 import java.util.Arrays;
00026 
00027 import com.meapsoft.STFT;
00028 
00037 public class AvgMFCC extends AvgMelSpec 
00038 {
00039     private int nceps = 13;
00040 
00041     // Default constructor - Use AvgMelSpec defaults
00042     public AvgMFCC() 
00043     {
00044         super();
00045     }
00046 
00047 
00048     public double[] features(STFT stft, long startFrame, int length) 
00049     {
00050         double[] mfccs = new double[nceps];
00051         Arrays.fill(mfccs, 0);
00052 
00053         // precompute DCT matrix
00054         int nmel = outDim;  
00055         double m = Math.sqrt(2.0/nmel);
00056         double[][] DCTcoeffs = new double[nmel][nceps];
00057         for(int i = 0; i < nmel; i++)
00058             for(int j = 0; j < nceps; j++)
00059                 DCTcoeffs[i][j] = m*Math.cos(Math.PI*(j+1)*(i+.5)/(double)nmel);
00060 
00061         for(int frm = 0; frm < length; frm++)
00062         {
00063             double[] melSpec = super.features(stft, startFrame+frm, 1);
00064             
00065             // convert to cepstrum:
00066             for(int x = 0; x < melSpec.length; x++)
00067             {
00068                 // convert from dB to plain old log magnitude
00069                 melSpec[x] = melSpec[x]/10;  
00070 
00071                 // take DCT
00072                 for(int y = 0; y < mfccs.length; y++)
00073                     mfccs[y] = mfccs[y] + DCTcoeffs[x][y]*melSpec[x]/length;
00074             }
00075         }
00076 
00077         return mfccs;
00078     }
00079 
00080     public String description()
00081     {
00082         return "Computes the mean MFCCs of a chunk, a commonly used feature in speech recognition.";
00083     }
00084 }

Generated on Tue Feb 6 19:02:24 2007 for MEAPsoft by doxygen1.2.18