Mercurial > hg > qm-dsp
comparison maths/MathUtilities.h @ 194:26daede606a8
Add L^p norms, doc, tests
author | Chris Cannam |
---|---|
date | Wed, 07 Oct 2015 11:14:16 +0100 |
parents | e4a57215ddee |
children |
comparison
equal
deleted
inserted
replaced
193:ca658c7215a9 | 194:26daede606a8 |
---|---|
71 /** | 71 /** |
72 * Floating-point division modulus: return x % y. | 72 * Floating-point division modulus: return x % y. |
73 */ | 73 */ |
74 static double mod( double x, double y); | 74 static double mod( double x, double y); |
75 | 75 |
76 /** | |
77 * The alpha norm is the alpha'th root of the mean alpha'th power | |
78 * magnitude. For example if alpha = 2 this corresponds to the RMS | |
79 * of the input data, and when alpha = 1 this is the mean | |
80 * magnitude. | |
81 */ | |
76 static void getAlphaNorm(const double *data, int len, int alpha, double* ANorm); | 82 static void getAlphaNorm(const double *data, int len, int alpha, double* ANorm); |
83 | |
84 /** | |
85 * The alpha norm is the alpha'th root of the mean alpha'th power | |
86 * magnitude. For example if alpha = 2 this corresponds to the RMS | |
87 * of the input data, and when alpha = 1 this is the mean | |
88 * magnitude. | |
89 */ | |
77 static double getAlphaNorm(const std::vector <double> &data, int alpha ); | 90 static double getAlphaNorm(const std::vector <double> &data, int alpha ); |
78 | |
79 static void circShift( double* data, int length, int shift); | |
80 | |
81 static int getMax( double* data, 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 | 91 |
85 enum NormaliseType { | 92 enum NormaliseType { |
86 NormaliseNone, | 93 NormaliseNone, |
87 NormaliseUnitSum, | 94 NormaliseUnitSum, |
88 NormaliseUnitMax | 95 NormaliseUnitMax |
93 | 100 |
94 static void normalise(std::vector<double> &data, | 101 static void normalise(std::vector<double> &data, |
95 NormaliseType n = NormaliseUnitMax); | 102 NormaliseType n = NormaliseUnitMax); |
96 | 103 |
97 /** | 104 /** |
105 * Calculate the L^p norm of a vector. Equivalent to MATLAB's | |
106 * norm(data, p). | |
107 */ | |
108 static double getLpNorm(const std::vector<double> &data, | |
109 int p); | |
110 | |
111 /** | |
112 * Normalise a vector by dividing through by its L^p norm. If the | |
113 * norm is below the given threshold, the unit vector for that | |
114 * norm is returned. p may be 0, in which case no normalisation | |
115 * happens and the data is returned unchanged. | |
116 */ | |
117 static std::vector<double> normaliseLp(const std::vector<double> &data, | |
118 int p, | |
119 double threshold = 1e-6); | |
120 | |
121 /** | |
98 * Threshold the input/output vector data against a moving-mean | 122 * Threshold the input/output vector data against a moving-mean |
99 * average filter. | 123 * average filter. |
100 */ | 124 */ |
101 static void adaptiveThreshold(std::vector<double> &data); | 125 static void adaptiveThreshold(std::vector<double> &data); |
126 | |
127 static void circShift( double* data, int length, int shift); | |
128 | |
129 static int getMax( double* data, int length, double* max = 0 ); | |
130 static int getMax( const std::vector<double> &data, double* max = 0 ); | |
131 static int compareInt(const void * a, const void * b); | |
102 | 132 |
103 /** | 133 /** |
104 * Return true if x is 2^n for some integer n >= 0. | 134 * Return true if x is 2^n for some integer n >= 0. |
105 */ | 135 */ |
106 static bool isPowerOfTwo(int x); | 136 static bool isPowerOfTwo(int x); |