Ardour  9.0-pre0-582-g084a23a80d
MathUtilities Class Reference

#include <MathUtilities.h>

Public Types

enum  NormaliseType { NormaliseNone , NormaliseUnitSum , NormaliseUnitMax }
 

Static Public Member Functions

static double round (double x)
 
static void getFrameMinMax (const double *data, int len, double *min, double *max)
 
static double mean (const double *src, int len)
 
static double mean (const std::vector< double > &data, int start, int count)
 
static double sum (const double *src, int len)
 
static double median (const double *src, int len)
 
static double princarg (double ang)
 
static double mod (double x, double y)
 
static void getAlphaNorm (const double *data, int len, int alpha, double *ANorm)
 
static double getAlphaNorm (const std::vector< double > &data, int alpha)
 
static void normalise (double *data, int length, NormaliseType n=NormaliseUnitMax)
 
static void normalise (std::vector< double > &data, NormaliseType n=NormaliseUnitMax)
 
static double getLpNorm (const std::vector< double > &data, int p)
 
static std::vector< double > normaliseLp (const std::vector< double > &data, int p, double threshold=1e-6)
 
static void adaptiveThreshold (std::vector< double > &data)
 
static void circShift (double *data, int length, int shift)
 
static int getMax (double *data, int length, double *max=0)
 
static int getMax (const std::vector< double > &data, double *max=0)
 
static int compareInt (const void *a, const void *b)
 
static bool isPowerOfTwo (int x)
 
static int nextPowerOfTwo (int x)
 
static int previousPowerOfTwo (int x)
 
static int nearestPowerOfTwo (int x)
 
static double factorial (int x)
 
static int gcd (int a, int b)
 

Detailed Description

Static helper functions for simple mathematical calculations.

Definition at line 26 of file MathUtilities.h.

Member Enumeration Documentation

◆ NormaliseType

Enumerator
NormaliseNone 
NormaliseUnitSum 
NormaliseUnitMax 

Definition at line 92 of file MathUtilities.h.

Member Function Documentation

◆ adaptiveThreshold()

static void MathUtilities::adaptiveThreshold ( std::vector< double > &  data)
static

Threshold the input/output vector data against a moving-mean average filter.

◆ circShift()

static void MathUtilities::circShift ( double *  data,
int  length,
int  shift 
)
static

◆ compareInt()

static int MathUtilities::compareInt ( const void *  a,
const void *  b 
)
static

◆ factorial()

static double MathUtilities::factorial ( int  x)
static

Return x!

◆ gcd()

static int MathUtilities::gcd ( int  a,
int  b 
)
static

Return the greatest common divisor of natural numbers a and b.

◆ getAlphaNorm() [1/2]

static void MathUtilities::getAlphaNorm ( const double *  data,
int  len,
int  alpha,
double *  ANorm 
)
static

The alpha norm is the alpha'th root of the mean alpha'th power magnitude. For example if alpha = 2 this corresponds to the RMS of the input data, and when alpha = 1 this is the mean magnitude.

◆ getAlphaNorm() [2/2]

static double MathUtilities::getAlphaNorm ( const std::vector< double > &  data,
int  alpha 
)
static

The alpha norm is the alpha'th root of the mean alpha'th power magnitude. For example if alpha = 2 this corresponds to the RMS of the input data, and when alpha = 1 this is the mean magnitude.

◆ getFrameMinMax()

static void MathUtilities::getFrameMinMax ( const double *  data,
int  len,
double *  min,
double *  max 
)
static

Return through min and max pointers the highest and lowest values in the given array of the given length.

◆ getLpNorm()

static double MathUtilities::getLpNorm ( const std::vector< double > &  data,
int  p 
)
static

Calculate the L^p norm of a vector. Equivalent to MATLAB's norm(data, p).

◆ getMax() [1/2]

static int MathUtilities::getMax ( const std::vector< double > &  data,
double *  max = 0 
)
static

◆ getMax() [2/2]

static int MathUtilities::getMax ( double *  data,
int  length,
double *  max = 0 
)
static

◆ isPowerOfTwo()

static bool MathUtilities::isPowerOfTwo ( int  x)
static

Return true if x is 2^n for some integer n >= 0.

◆ mean() [1/2]

static double MathUtilities::mean ( const double *  src,
int  len 
)
static

Return the mean of the given array of the given length.

◆ mean() [2/2]

static double MathUtilities::mean ( const std::vector< double > &  data,
int  start,
int  count 
)
static

Return the mean of the subset of the given vector identified by start and count.

◆ median()

static double MathUtilities::median ( const double *  src,
int  len 
)
static

Return the median of the values in the given array of the given length. If the array is even in length, the returned value will be half-way between the two values adjacent to median.

◆ mod()

static double MathUtilities::mod ( double  x,
double  y 
)
static

Floating-point division modulus: return x % y.

◆ nearestPowerOfTwo()

static int MathUtilities::nearestPowerOfTwo ( int  x)
static

Return the nearest integer power of two to x, e.g. 1300 -> 1024, 12 -> 16 (not 8; if two are equidistant, the higher is returned).

◆ nextPowerOfTwo()

static int MathUtilities::nextPowerOfTwo ( int  x)
static

Return the next higher integer power of two from x, e.g. 1300 -> 2048, 2048 -> 2048.

◆ normalise() [1/2]

static void MathUtilities::normalise ( double *  data,
int  length,
NormaliseType  n = NormaliseUnitMax 
)
static

◆ normalise() [2/2]

static void MathUtilities::normalise ( std::vector< double > &  data,
NormaliseType  n = NormaliseUnitMax 
)
static

◆ normaliseLp()

static std::vector<double> MathUtilities::normaliseLp ( const std::vector< double > &  data,
int  p,
double  threshold = 1e-6 
)
static

Normalise a vector by dividing through by its L^p norm. If the norm is below the given threshold, the unit vector for that norm is returned. p may be 0, in which case no normalisation happens and the data is returned unchanged.

◆ previousPowerOfTwo()

static int MathUtilities::previousPowerOfTwo ( int  x)
static

Return the next lower integer power of two from x, e.g. 1300 -> 1024, 2048 -> 2048.

◆ princarg()

static double MathUtilities::princarg ( double  ang)
static

The principle argument function. Map the phase angle ang into the range [-pi,pi).

◆ round()

static double MathUtilities::round ( double  x)
static

Round x to the nearest integer.

◆ sum()

static double MathUtilities::sum ( const double *  src,
int  len 
)
static

Return the sum of the values in the given array of the given length.


The documentation for this class was generated from the following file: