Mercurial > hg > qm-dsp
comparison maths/MathUtilities.h @ 377:59b151f13b3e
Some docs
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 21 Oct 2013 11:50:09 +0100 |
parents | a694700f71d8 |
children | 7e8d1f26b098 |
comparison
equal
deleted
inserted
replaced
376:8e32cd2af755 | 377:59b151f13b3e |
---|---|
18 | 18 |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "nan-inf.h" | 21 #include "nan-inf.h" |
22 | 22 |
23 /** | |
24 * Static helper functions for simple mathematical calculations. | |
25 */ | |
23 class MathUtilities | 26 class MathUtilities |
24 { | 27 { |
25 public: | 28 public: |
29 /** | |
30 * Round x to the nearest integer. | |
31 */ | |
26 static double round( double x ); | 32 static double round( double x ); |
27 | 33 |
34 /** | |
35 * Return through min and max pointers the highest and lowest | |
36 * values in the given array of the given length. | |
37 */ | |
28 static void getFrameMinMax( const double* data, unsigned int len, double* min, double* max ); | 38 static void getFrameMinMax( const double* data, unsigned int len, double* min, double* max ); |
29 | 39 |
40 /** | |
41 * Return the mean of the given array of the given length. | |
42 */ | |
30 static double mean( const double* src, unsigned int len ); | 43 static double mean( const double* src, unsigned int len ); |
44 | |
45 /** | |
46 * Return the mean of the subset of the given vector identified by | |
47 * start and count. | |
48 */ | |
31 static double mean( const std::vector<double> &data, | 49 static double mean( const std::vector<double> &data, |
32 unsigned int start, unsigned int count ); | 50 unsigned int start, unsigned int count ); |
51 | |
52 /** | |
53 * Return the sum of the values in the given array of the given | |
54 * length. | |
55 */ | |
33 static double sum( const double* src, unsigned int len ); | 56 static double sum( const double* src, unsigned int len ); |
57 | |
58 /** | |
59 * Return the median of the values in the given array of the given | |
60 * length. If the array is even in length, the returned value will | |
61 * be half-way between the two values adjacent to median. | |
62 */ | |
34 static double median( const double* src, unsigned int len ); | 63 static double median( const double* src, unsigned int len ); |
35 | 64 |
65 /** | |
66 * The principle argument function. Map the phase angle ang into | |
67 * the range [-pi,pi). | |
68 */ | |
36 static double princarg( double ang ); | 69 static double princarg( double ang ); |
70 | |
71 /** | |
72 * Floating-point division modulus: return x % y. | |
73 */ | |
37 static double mod( double x, double y); | 74 static double mod( double x, double y); |
38 | 75 |
39 static void getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double* ANorm); | 76 static void getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double* ANorm); |
40 static double getAlphaNorm(const std::vector <double> &data, unsigned int alpha ); | 77 static double getAlphaNorm(const std::vector <double> &data, unsigned int alpha ); |
41 | 78 |
55 NormaliseType n = NormaliseUnitMax); | 92 NormaliseType n = NormaliseUnitMax); |
56 | 93 |
57 static void normalise(std::vector<double> &data, | 94 static void normalise(std::vector<double> &data, |
58 NormaliseType n = NormaliseUnitMax); | 95 NormaliseType n = NormaliseUnitMax); |
59 | 96 |
60 // moving mean threshholding: | 97 /** |
98 * Threshold the input/output vector data against a moving-mean | |
99 * average filter. | |
100 */ | |
61 static void adaptiveThreshold(std::vector<double> &data); | 101 static void adaptiveThreshold(std::vector<double> &data); |
62 | 102 |
103 /** | |
104 * Return true if x is 2^n for some integer n >= 0. | |
105 */ | |
63 static bool isPowerOfTwo(int x); | 106 static bool isPowerOfTwo(int x); |
64 static int nextPowerOfTwo(int x); // e.g. 1300 -> 2048, 2048 -> 2048 | |
65 static int previousPowerOfTwo(int x); // e.g. 1300 -> 1024, 2048 -> 2048 | |
66 static int nearestPowerOfTwo(int x); // e.g. 1300 -> 1024, 12 -> 16 (not 8) | |
67 | 107 |
108 /** | |
109 * Return the next higher integer power of two from x, e.g. 1300 | |
110 * -> 2048, 2048 -> 2048. | |
111 */ | |
112 static int nextPowerOfTwo(int x); | |
113 | |
114 /** | |
115 * Return the next lower integer power of two from x, e.g. 1300 -> | |
116 * 1024, 2048 -> 2048. | |
117 */ | |
118 static int previousPowerOfTwo(int x); | |
119 | |
120 /** | |
121 * Return the nearest integer power of two to x, e.g. 1300 -> 1024, | |
122 * 12 -> 16 (not 8; if two are equidistant, the higher is returned). | |
123 */ | |
124 static int nearestPowerOfTwo(int x); | |
125 | |
126 /** | |
127 * Return x! | |
128 */ | |
68 static double factorial(int x); // returns double in case it is large | 129 static double factorial(int x); // returns double in case it is large |
69 | 130 |
131 /** | |
132 * Return the greatest common divisor of natural numbers a and b. | |
133 */ | |
70 static int gcd(int a, int b); | 134 static int gcd(int a, int b); |
71 }; | 135 }; |
72 | 136 |
73 #endif | 137 #endif |