aubio  0.4.0~beta1
 All Data Structures Files Functions Variables Typedefs Macros
Functions
mathutils.h File Reference

Various math functions. More...

#include "fvec.h"
#include "musicutils.h"

Go to the source code of this file.

Functions

smpl_t fvec_mean (fvec_t *s)
 compute the mean of a vector More...
 
smpl_t fvec_max (fvec_t *s)
 find the max of a vector More...
 
smpl_t fvec_min (fvec_t *s)
 find the min of a vector More...
 
uint_t fvec_min_elem (fvec_t *s)
 find the index of the min of a vector More...
 
uint_t fvec_max_elem (fvec_t *s)
 find the index of the max of a vector More...
 
void fvec_shift (fvec_t *v)
 swap the left and right halves of a vector More...
 
smpl_t fvec_sum (fvec_t *v)
 compute the sum of all elements of a vector More...
 
smpl_t fvec_local_hfc (fvec_t *v)
 compute the High Frequency Content of a vector More...
 
smpl_t fvec_alpha_norm (fvec_t *v, smpl_t p)
 computes the p-norm of a vector More...
 
void fvec_alpha_normalise (fvec_t *v, smpl_t p)
 alpha normalisation More...
 
void fvec_add (fvec_t *v, smpl_t c)
 add a constant to each elements of a vector More...
 
void fvec_min_removal (fvec_t *v)
 remove the minimum value of the vector to each elements More...
 
smpl_t fvec_moving_thres (fvec_t *v, fvec_t *tmp, uint_t post, uint_t pre, uint_t pos)
 compute moving median threshold of a vector More...
 
void fvec_adapt_thres (fvec_t *v, fvec_t *tmp, uint_t post, uint_t pre)
 apply adaptive threshold to a vector More...
 
smpl_t fvec_median (fvec_t *v)
 returns the median of a vector More...
 
smpl_t fvec_quadratic_peak_pos (fvec_t *x, uint_t p)
 finds exact peak index by quadratic interpolation More...
 
smpl_t aubio_quadfrac (smpl_t s0, smpl_t s1, smpl_t s2, smpl_t pf)
 Quadratic interpolation using Lagrange polynomial. More...
 
uint_t fvec_peakpick (fvec_t *v, uint_t p)
 return 1 if v[p] is a peak and positive, 0 otherwise More...
 
uint_t aubio_is_power_of_two (uint_t a)
 return 1 if a is a power of 2, 0 otherwise
 
uint_t aubio_next_power_of_two (uint_t a)
 return the next power of power of 2 greater than a
 
void aubio_autocorr (fvec_t *input, fvec_t *output)
 compute normalised autocorrelation function More...
 

Detailed Description

Various math functions.

Definition in file mathutils.h.

Function Documentation

void aubio_autocorr ( fvec_t input,
fvec_t output 
)

compute normalised autocorrelation function

Parameters
inputvector to compute autocorrelation from
outputvector to store autocorrelation function to
smpl_t aubio_quadfrac ( smpl_t  s0,
smpl_t  s1,
smpl_t  s2,
smpl_t  pf 
)

Quadratic interpolation using Lagrange polynomial.

Inspired from ``Comparison of interpolation algorithms in real-time sound processing'', Vladimir Arnost,

Parameters
s0,s1,s2are 3 consecutive samples of a curve
pfis the floating point index [0;2]
Returns
\( s0 + (pf/2.)*((pf-3.)*s0-2.*(pf-2.)*s1+(pf-1.)*s2); \)
void fvec_adapt_thres ( fvec_t v,
fvec_t tmp,
uint_t  post,
uint_t  pre 
)

apply adaptive threshold to a vector

For each points at position p of an input vector, this function remove the moving median threshold computed at p.

Parameters
vinput vector
tmptemporary vector of length post+1+pre
postlength of causal part to take before pos
prelength of anti-causal part to take after pos
void fvec_add ( fvec_t v,
smpl_t  c 
)

add a constant to each elements of a vector

Parameters
vvector to add constant to
cconstant to add to v
smpl_t fvec_alpha_norm ( fvec_t v,
smpl_t  p 
)

computes the p-norm of a vector

Computes the p-norm of a vector for \( p = \alpha \)

\( L^p = ||x||_p = (|x_1|^p + |x_2|^p + ... + |x_n|^p ) ^ \frac{1}{p} \)

If p = 1, the result is the Manhattan distance.

If p = 2, the result is the Euclidean distance.

As p tends towards large values, \( L^p \) tends towards the maximum of the input vector.

References:

Parameters
vvector to compute norm from
porder of the computed norm
Returns
the p-norm of v
void fvec_alpha_normalise ( fvec_t v,
smpl_t  p 
)

alpha normalisation

This function divides all elements of a vector by the p-norm as computed by fvec_alpha_norm().

Parameters
vvector to compute norm from
porder of the computed norm
smpl_t fvec_local_hfc ( fvec_t v)

compute the High Frequency Content of a vector

The High Frequency Content is defined as \( \sum_0^{N-1} (k+1) v[k] \).

Parameters
vvector to get the energy from
Returns
the HFC of v
smpl_t fvec_max ( fvec_t s)

find the max of a vector

Parameters
svector to get the max from
Returns
the value of the minimum of v
uint_t fvec_max_elem ( fvec_t s)

find the index of the max of a vector

Parameters
svector to get the index from
Returns
the index of the maximum element of v
smpl_t fvec_mean ( fvec_t s)

compute the mean of a vector

Parameters
svector to compute mean from
Returns
the mean of v
smpl_t fvec_median ( fvec_t v)

returns the median of a vector

The QuickSelect routine is based on the algorithm described in "Numerical recipes in C", Second Edition, Cambridge University Press, 1992, Section 8.5, ISBN 0-521-43108-5

This implementation of the QuickSelect routine is based on Nicolas Devillard's implementation, available at http://ndevilla.free.fr/median/median/ and in the Public Domain.

Parameters
vvector to get median from
Returns
the median of v
Examples:
examples/aubionotes.c.
smpl_t fvec_min ( fvec_t s)

find the min of a vector

Parameters
svector to get the min from
Returns
the value of the maximum of v
uint_t fvec_min_elem ( fvec_t s)

find the index of the min of a vector

Parameters
svector to get the index from
Returns
the index of the minimum element of v
void fvec_min_removal ( fvec_t v)

remove the minimum value of the vector to each elements

Parameters
vvector to remove minimum from
smpl_t fvec_moving_thres ( fvec_t v,
fvec_t tmp,
uint_t  post,
uint_t  pre,
uint_t  pos 
)

compute moving median threshold of a vector

This function computes the moving median threshold value of at the given position of a vector, taking the median among post elements before and up to pre elements after pos.

Parameters
vinput vector
tmptemporary vector of length post+1+pre
postlength of causal part to take before pos
prelength of anti-causal part to take after pos
posindex to compute threshold for
Returns
moving median threshold value
uint_t fvec_peakpick ( fvec_t v,
uint_t  p 
)

return 1 if v[p] is a peak and positive, 0 otherwise

This function returns 1 if a peak is found at index p in the vector v. The peak is defined as follows:

  • v[p] is positive
  • v[p-1] < v[p]
  • v[p] > v[p+1]
Parameters
vinput vector
pposition of supposed for peak
Returns
1 if a peak is found, 0 otherwise
smpl_t fvec_quadratic_peak_pos ( fvec_t x,
uint_t  p 
)

finds exact peak index by quadratic interpolation

See Quadratic Interpolation of Spectral Peaks, by Julius O. Smith III

\( p_{frac} = \frac{1}{2} \frac {x[p-1] - x[p+1]} {x[p-1] - 2 x[p] + x[p+1]} \in [ -.5, .5] \)

Parameters
xvector to get the interpolated peak position from
pindex of the peak in vector x
Returns
\( p + p_{frac} \) exact peak position of interpolated maximum or minimum
void fvec_shift ( fvec_t v)

swap the left and right halves of a vector

This function swaps the left part of the signal with the right part of the signal. Therefore

\( a[0], a[1], ..., a[\frac{N}{2}], a[\frac{N}{2}+1], ..., a[N-1], a[N] \)

becomes

\( a[\frac{N}{2}+1], ..., a[N-1], a[N], a[0], a[1], ..., a[\frac{N}{2}] \)

This operation, known as 'fftshift' in the Matlab Signal Processing Toolbox, can be used before computing the FFT to simplify the phase relationship of the resulting spectrum. See Amalia de Götzen's paper referred to above.

smpl_t fvec_sum ( fvec_t v)

compute the sum of all elements of a vector

Parameters
vvector to compute the sum of
Returns
the sum of v