Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

TimeCentroid.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.disgraced;
00024 
00025 import com.meapsoft.STFT;
00026 import com.meapsoft.featextractors.FeatureExtractor;
00027 
00038 public class TimeCentroid extends FeatureExtractor 
00039 {
00040         
00041     public double[] features(STFT stft, long startFrame, int length) 
00042     {
00043         double[] curFrame;
00044         double[] TimeCentroid = new double[1];
00045         double num0 = 0;
00046         double num1 = 0;
00047         double den = 0;
00048 
00049         for(int frame=0; frame<length; frame++) 
00050         {
00051             curFrame = stft.getFrame(startFrame+frame);
00052             double timeCenter = stft.fr2Seconds(frame);
00053 
00054             for(int band=0; band<stft.getRows(); band++) 
00055             {
00056                 //double freqCenter = band*(stft.samplingRate/2)/(stft.getRows()-1);
00057                 // convert back to linear power
00058                 double p = Math.pow(10,curFrame[band]/10);
00059 
00060                 num0 += timeCenter*p;
00061                 //num1 += freqCenter*p;
00062                 den += p;
00063             }
00064         }
00065         
00066         TimeCentroid[0] = num0/den;
00067         //TimeFreqCentroid[1] = num1/den;
00068 
00069         // scale it by length so it ends up between zero and one.
00070         TimeCentroid[0] /= stft.fr2Seconds(length);
00071 
00072         return TimeCentroid;
00073     }
00074 
00075         public String description()
00076         {
00077                 //return "Computes the center of mass in the time/frequency plane of each chunk's spectrogram.";
00078         return "Computes the center of mass of a chunk's power in time.  Gives a simple indication of a chunk's stationarity.";
00079         }
00080 }

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