Main Page   Class Hierarchy   Compound List   File List   Compound Members  

TimeFreqCentroid.java

00001 /*
00002  *  Copyright 2006 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 com.meapsoft.STFT;
00026 
00034 public class TimeFreqCentroid extends FeatureExtractor 
00035 {
00036         
00037     public double[] features(STFT stft, long startFrame, int length) 
00038     {
00039         double[] curFrame;
00040         double[] TimeFreqCentroid = new double[2];
00041         double num0 = 0;
00042         double num1 = 0;
00043         double den = 0;
00044 
00045         for(int frame=0; frame<length; frame++) 
00046         {
00047             curFrame = stft.getFrame(startFrame+frame);
00048             double timeCenter = stft.fr2Seconds(frame);
00049 
00050             for(int band=0; band<stft.getRows(); band++) 
00051             {
00052                 double freqCenter = band*(stft.samplingRate/2)/(stft.getRows()-1);
00053                 // convert back to linear power
00054                 double p = Math.pow(10,curFrame[band]/10);
00055 
00056                 num0 += timeCenter*p;
00057                 num1 += freqCenter*p;
00058                 den += p;
00059             }
00060         }
00061         
00062         TimeFreqCentroid[0] = num0/den;
00063         TimeFreqCentroid[1] = num1/den;
00064 
00065         return TimeFreqCentroid;
00066     }
00067 
00068         public String description()
00069         {
00070                 return "Computes the center of mass in the time/frequency plane of each chunk's spectrogram.";
00071         }
00072 }

Generated on Thu May 11 15:04:11 2006 for MEAPsoft by doxygen1.2.18