Various math functions. More...
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... | |
Various math functions.
Definition in file mathutils.h.
compute normalised autocorrelation function
input | vector to compute autocorrelation from |
output | vector to store autocorrelation function to |
Quadratic interpolation using Lagrange polynomial.
Inspired from ``Comparison of interpolation algorithms in real-time sound processing'', Vladimir Arnost,
s0,s1,s2 | are 3 consecutive samples of a curve |
pf | is the floating point index [0;2] |
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.
v | input vector |
tmp | temporary vector of length post+1+pre |
post | length of causal part to take before pos |
pre | length of anti-causal part to take after pos |
add a constant to each elements of a vector
v | vector to add constant to |
c | constant to add to v |
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:
v | vector to compute norm from |
p | order of the computed norm |
alpha normalisation
This function divides all elements of a vector by the p-norm as computed by fvec_alpha_norm().
v | vector to compute norm from |
p | order of the computed norm |
compute the High Frequency Content of a vector
The High Frequency Content is defined as \( \sum_0^{N-1} (k+1) v[k] \).
v | vector to get the energy from |
find the max of a vector
s | vector to get the max from |
find the index of the max of a vector
s | vector to get the index from |
compute the mean of a vector
s | vector to compute mean from |
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.
v | vector to get median from |
find the min of a vector
s | vector to get the min from |
find the index of the min of a vector
s | vector to get the index from |
void fvec_min_removal | ( | fvec_t * | v | ) |
remove the minimum value of the vector to each elements
v | vector to remove minimum from |
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.
v | input vector |
tmp | temporary vector of length post+1+pre |
post | length of causal part to take before pos |
pre | length of anti-causal part to take after pos |
pos | index to compute threshold for |
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 | input vector |
p | position of supposed for peak |
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] \)
x | vector to get the interpolated peak position from |
p | index of the peak in vector x |
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.