26 double a = floor( x / y );
28 double b = x - ( y * a );
36 ValOut =
mod( ang + M_PI, -2 * M_PI ) + M_PI;
47 for( i = 0; i < len; i++)
51 a += ::pow( fabs(temp),
double(alpha) );
54 a = ::pow( a, ( 1.0 / (
double) alpha ) );
62 unsigned int len = data.size();
66 for( i = 0; i < len; i++)
70 a += ::pow( fabs(temp),
double(alpha) );
73 a = ::pow( a, ( 1.0 / (
double) alpha ) );
81 return -floor(-x + 0.5);
83 return floor(x + 0.5);
89 if (len == 0)
return 0;
91 std::vector<double> scratch;
92 for (
int i = 0; i < len; ++i) scratch.push_back(src[i]);
93 std::sort(scratch.begin(), scratch.end());
97 return (scratch[middle] + scratch[middle - 1]) / 2;
99 return scratch[middle];
108 for( i = 0; i < len; i++)
120 if (len == 0)
return 0;
122 double s =
sum( src, len );
124 retVal = s / (double)len;
135 if (count == 0)
return 0;
137 for (
int i = 0; i < (int)count; ++i)
139 sum += src[start + i];
158 for( i = 0; i < len; i++)
176 unsigned int index = 0;
180 double max = pData[0];
182 for( i = 0; i < Length; i++)
194 if (pMax) *pMax = max;
202 unsigned int index = 0;
206 double max = data[0];
208 for( i = 0; i < data.size(); i++)
220 if (pMax) *pMax = max;
228 shift = shift % length;
232 for( i = 0; i < shift; i++)
234 temp=*(pData + length - 1);
236 for( n = length-2; n >= 0; n--)
238 *(pData+n+1)=*(pData+n);
247 return ( *(
int*)a - *(
int*)b );
259 for (
int i = 0; i < length; ++i) {
263 for (
int i = 0; i < length; ++i) {
273 for (
int i = 0; i < length; ++i) {
274 if (fabs(data[i]) > max) {
279 for (
int i = 0; i < length; ++i) {
298 for (
int i = 0; i < (int)data.size(); ++i) sum += data[i];
300 for (
int i = 0; i < (int)data.size(); ++i) data[i] /= sum;
308 for (
int i = 0; i < (int)data.size(); ++i) {
309 if (fabs(data[i]) > max) max = fabs(data[i]);
312 for (
int i = 0; i < (int)data.size(); ++i) data[i] /= max;
322 int sz = int(data.size());
325 std::vector<double> smoothed(sz);
330 for (
int i = 0; i < sz; ++i) {
332 int first = std::max(0, i - p_pre);
333 int last = std::min(sz - 1, i + p_post);
335 smoothed[i] =
mean(data, first, last - first + 1);
338 for (
int i = 0; i < sz; i++) {
339 data[i] -= smoothed[i];
340 if (data[i] < 0.0) data[i] = 0.0;
347 if (x < 1)
return false;
348 if (x & (x-1))
return false;
358 while (x) { x >>= 1; n <<= 1; }
369 while (x) { x >>= 1; n <<= 1; }
378 if (x - n0 < n1 - x)
return n0;
387 for (
int i = 1; i <= x; ++i) {
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 princarg(double ang)
The principle argument function.
static double mean(const double *src, unsigned int len)
Return the mean of the given array of the given length.
static double sum(const double *src, unsigned int len)
Return the sum of the values in the given array of the given length.
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 factorial(int x)
Return x!
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 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 void getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double *ANorm)
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 int nearestPowerOfTwo(int x)
Return the nearest integer power of two to x, e.g.
static double round(double x)
Round x to the nearest integer.
static int getMax(double *data, unsigned int length, double *max=0)
static void normalise(double *data, int length, NormaliseType n=NormaliseUnitMax)