qm-dsp 1.8
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{
28public:
32 static double round( double x );
33
38 static void getFrameMinMax( const double* data, unsigned int len, double* min, double* max );
39
43 static double mean( const double* src, unsigned int len );
44
49 static double mean( const std::vector<double> &data,
50 unsigned int start, unsigned int count );
51
56 static double sum( const double* src, unsigned int len );
57
63 static double median( const double* src, unsigned int len );
64
69 static double princarg( double ang );
70
74 static double mod( double x, double y);
75
76 static void getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double* ANorm);
77 static double getAlphaNorm(const std::vector <double> &data, unsigned int alpha );
78
79 static void circShift( double* data, int length, int shift);
80
81 static int getMax( double* data, unsigned int length, double* max = 0 );
82 static int getMax( const std::vector<double> &data, double* max = 0 );
83 static int compareInt(const void * a, const void * b);
84
90
91 static void normalise(double *data, int length,
93
94 static void normalise(std::vector<double> &data,
96
101 static void adaptiveThreshold(std::vector<double> &data);
102
106 static bool isPowerOfTwo(int x);
107
112 static int nextPowerOfTwo(int x);
113
118 static int previousPowerOfTwo(int x);
119
124 static int nearestPowerOfTwo(int x);
125
129 static double factorial(int x); // returns double in case it is large
130
134 static int gcd(int a, int b);
135};
136
137#endif
Static helper functions for simple mathematical calculations.
static int nearestPowerOfTwo(int x)
Return the nearest integer power of two to x, e.g.
static void getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double *ANorm)
static int compareInt(const void *a, const void *b)
static double sum(const double *src, unsigned int len)
Return the sum of the values in the given array of the given length.
static void normalise(double *data, int length, NormaliseType n=NormaliseUnitMax)
static double mod(double x, double y)
Floating-point division modulus: return x % y.
static int nextPowerOfTwo(int x)
Return the next higher integer power of two from x, e.g.
static double median(const double *src, unsigned int len)
Return the median of the values in the given array of the given length.
static double mean(const double *src, unsigned int len)
Return the mean of the given array of the given length.
static bool isPowerOfTwo(int x)
Return true if x is 2^n for some integer n >= 0.
static int gcd(int a, int b)
Return the greatest common divisor of natural numbers a and b.
static void adaptiveThreshold(std::vector< double > &data)
Threshold the input/output vector data against a moving-mean average filter.
static double factorial(int x)
Return x!
static double round(double x)
Round x to the nearest integer.
static int getMax(double *data, unsigned int length, double *max=0)
static void getFrameMinMax(const double *data, unsigned 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 void circShift(double *data, int length, int shift)
static int previousPowerOfTwo(int x)
Return the next lower integer power of two from x, e.g.
static double princarg(double ang)
The principle argument function.