qm-dsp  1.8
MathUtilities.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     QM DSP Library
00005 
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file 2005-2006 Christian Landone.
00008 
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef MATHUTILITIES_H
00017 #define MATHUTILITIES_H
00018 
00019 #include <vector>
00020 
00021 #include "nan-inf.h"
00022 
00026 class MathUtilities  
00027 {
00028 public: 
00032     static double round( double x );
00033 
00038     static void   getFrameMinMax( const double* data, unsigned int len,  double* min, double* max );
00039 
00043     static double mean( const double* src, unsigned int len );
00044 
00049     static double mean( const std::vector<double> &data,
00050                         unsigned int start, unsigned int count );
00051     
00056     static double sum( const double* src, unsigned int len );
00057 
00063     static double median( const double* src, unsigned int len );
00064 
00069     static double princarg( double ang );
00070 
00074     static double mod( double x, double y);
00075 
00076     static void   getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double* ANorm);
00077     static double getAlphaNorm(const std::vector <double> &data, unsigned int alpha );
00078 
00079     static void   circShift( double* data, int length, int shift);
00080 
00081     static int    getMax( double* data, unsigned int length, double* max = 0 );
00082     static int    getMax( const std::vector<double> &data, double* max = 0 );
00083     static int    compareInt(const void * a, const void * b);
00084 
00085     enum NormaliseType {
00086         NormaliseNone,
00087         NormaliseUnitSum,
00088         NormaliseUnitMax
00089     };
00090 
00091     static void normalise(double *data, int length,
00092                           NormaliseType n = NormaliseUnitMax);
00093 
00094     static void normalise(std::vector<double> &data,
00095                           NormaliseType n = NormaliseUnitMax);
00096 
00101     static void adaptiveThreshold(std::vector<double> &data);
00102 
00106     static bool isPowerOfTwo(int x);
00107 
00112     static int nextPowerOfTwo(int x);
00113 
00118     static int previousPowerOfTwo(int x);
00119 
00124     static int nearestPowerOfTwo(int x);
00125 
00129     static double factorial(int x); // returns double in case it is large
00130 
00134     static int gcd(int a, int b);
00135 };
00136 
00137 #endif