MathUtilities.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  QM DSP Library
5 
6  Centre for Digital Music, Queen Mary, University of London.
7  This file 2005-2006 Christian Landone.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef MATHUTILITIES_H
17 #define MATHUTILITIES_H
18 
19 #include <vector>
20 
21 #include "nan-inf.h"
22 
27 {
28 public:
32  static double round( double x );
33 
38  static void getFrameMinMax( const double* data, int len,
39  double* min, double* max );
40 
44  static double mean( const double* src, int len );
45 
50  static double mean( const std::vector<double> &data,
51  int start, int count );
52 
57  static double sum( const double* src, int len );
58 
64  static double median( const double* src, int len );
65 
70  static double princarg( double ang );
71 
75  static double mod( double x, double y);
76 
83  static void getAlphaNorm(const double *data, int len, int alpha, double* ANorm);
84 
91  static double getAlphaNorm(const std::vector <double> &data, int alpha );
92 
97  };
98 
99  static void normalise(double *data, int length,
101 
102  static void normalise(std::vector<double> &data,
104 
109  static double getLpNorm(const std::vector<double> &data,
110  int p);
111 
118  static std::vector<double> normaliseLp(const std::vector<double> &data,
119  int p,
120  double threshold = 1e-6);
121 
126  static void adaptiveThreshold(std::vector<double> &data);
127 
128  static void circShift( double* data, int length, int shift);
129 
130  static int getMax( double* data, int length, double* max = 0 );
131  static int getMax( const std::vector<double> &data, double* max = 0 );
132  static int compareInt(const void * a, const void * b);
133 
137  static bool isPowerOfTwo(int x);
138 
143  static int nextPowerOfTwo(int x);
144 
149  static int previousPowerOfTwo(int x);
150 
155  static int nearestPowerOfTwo(int x);
156 
160  static double factorial(int x); // returns double in case it is large
161 
165  static int gcd(int a, int b);
166 };
167 
168 #endif
Static helper functions for simple mathematical calculations.
Definition: MathUtilities.h:26
static void adaptiveThreshold(std::vector< double > &data)
Threshold the input/output vector data against a moving-mean average filter.
static void circShift(double *data, int length, int shift)
static double mod(double x, double y)
Floating-point division modulus: return x % y.
static double sum(const double *src, int len)
Return the sum of the values in the given array of the given length.
static double princarg(double ang)
The principle argument function.
static int getMax(double *data, int length, double *max=0)
static void getFrameMinMax(const double *data, int len, double *min, double *max)
Return through min and max pointers the highest and lowest values in the given array of the given len...
static double factorial(int x)
Return x!
static int nextPowerOfTwo(int x)
Return the next higher integer power of two from x, e.g.
static int compareInt(const void *a, const void *b)
static double getLpNorm(const std::vector< double > &data, int p)
Calculate the L^p norm of a vector.
static bool isPowerOfTwo(int x)
Return true if x is 2^n for some integer n >= 0.
static int previousPowerOfTwo(int x)
Return the next lower integer power of two from x, e.g.
static int gcd(int a, int b)
Return the greatest common divisor of natural numbers a and b.
static void getAlphaNorm(const double *data, int len, int alpha, double *ANorm)
The alpha norm is the alpha&#39;th root of the mean alpha&#39;th power magnitude.
static int nearestPowerOfTwo(int x)
Return the nearest integer power of two to x, e.g.
static double median(const double *src, int len)
Return the median of the values in the given array of the given length.
static double round(double x)
Round x to the nearest integer.
static double mean(const double *src, int len)
Return the mean of the given array of the given length.
static void normalise(double *data, int length, NormaliseType n=NormaliseUnitMax)
static std::vector< double > normaliseLp(const std::vector< double > &data, int p, double threshold=1e-6)
Normalise a vector by dividing through by its L^p norm.