eDSP  0.0.1
A cross-platform DSP library written in C++.
Classes | Functions
edsp::statistics Namespace Reference

Classes

struct  histogram
 Histogram density estimator. More...
 

Functions

template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > centroid (ForwardIt first, ForwardIt last)
 Computes the centroid value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > centroid (ForwardIt first1, ForwardIt last1, ForwardIt first2)
 Computes the centroid value of the range [first1, last1) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > crest (ForwardIt first, ForwardIt last)
 Computes the crest value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > entropy (ForwardIt first, ForwardIt last)
 Computes the normalized entropy of the probability mass function given in the range [first, last). More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > flatness (ForwardIt first, ForwardIt last)
 Computes the flatness value of the range [first, last) More...
 
template<distances d, typename InputIt >
constexpr meta::value_type_t< InputIt > flux (InputIt first1, InputIt last1, InputIt first2)
 Computes the flux between the elements in the range [first1, last1) and the elements starting at first2. More...
 
template<typename ForwardIt , typename Integer >
constexpr meta::value_type_t< ForwardIt > generalized_mean (ForwardIt first, ForwardIt last, Integer beta)
 Computes the generalized mean of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > geometric_mean (ForwardIt first, ForwardIt last)
 Computes the geometric mean of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > harmonic_mean (ForwardIt first, ForwardIt last)
 Computes the harmonic mean of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > kurtosis (ForwardIt first, ForwardIt last)
 Computes the Kurtosis of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > max (ForwardIt first, ForwardIt last)
 Computes the maximum value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > maxabs (ForwardIt first, ForwardIt last)
 Computes the maximum absolute value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > mean (ForwardIt first, ForwardIt last)
 Computes the average or mean value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > median (ForwardIt first, ForwardIt last)
 Computes the median of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > min (ForwardIt first, ForwardIt last)
 Computes the minimum value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > minabs (ForwardIt first, ForwardIt last)
 Computes the minimum absolute value of the range [first, last) More...
 
template<std::size_t N, typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > moment (ForwardIt first, ForwardIt last)
 Computes the n-th moment of the range [first, last) More...
 
template<std::size_t N, typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > moment (ForwardIt first, ForwardIt last, const meta::value_type_t< ForwardIt > mean)
 Computes the nth moment of the range [first, last) considering the precomputed average. More...
 
template<typename InputIt >
constexpr meta::value_type_t< InputIt > norm (InputIt first, InputIt last)
 Compute the L2-norm of the signals in the range [first1, last1). More...
 
template<typename ForwardIt >
constexpr auto peak (ForwardIt first, ForwardIt last) -> std::pair< typename meta::diff_type_t< ForwardIt >, typename meta::value_type_t< ForwardIt >>
 Computes the peak value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr auto peakabs (ForwardIt first, ForwardIt last) -> std::pair< typename meta::diff_type_t< ForwardIt >, typename meta::value_type_t< ForwardIt >>
 Computes the absolute peak value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > rms (ForwardIt first, ForwardIt last)
 Computes the root-mean-square (RMS) value of the range [first, last) More...
 
template<typename ForwardIt , typename Floating >
constexpr auto rolloff (ForwardIt first, ForwardIt last, Floating percentage)
 Computes the roll-off index of the elements in the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > rssq (ForwardIt first, ForwardIt last)
 Computes the root-sum-of-squares (RSSS) value of the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > skewness (ForwardIt first, ForwardIt last)
 Computes the skewness of the range [first, last) More...
 
template<typename InputIt , typename Allocator = std::allocator<meta::value_type_t<InputIt>>>
constexpr meta::value_type_t< InputIt > snr (InputIt first1, InputIt last1, InputIt first2)
 Compute the SNR of the signals in the range [first1, last1) and the signal starting in first2. More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > variance (ForwardIt first, ForwardIt last)
 Computes the variance of the range [first, last) More...
 
template<typename ForwardIt >
meta::value_type_t< ForwardIt > standard_deviation (ForwardIt first, ForwardIt last)
 Computes the standard deviation of the range [first, last) More...
 

Function Documentation

◆ centroid() [1/2]

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::centroid ( ForwardIt  first,
ForwardIt  last 
)

Computes the centroid value of the range [first, last)

It is calculated as the division of the weighted mean of the the signal and the average of the magnitudes.

\[ y = \frac{\sum_{n=0}^{N-1}nx(n)}{\sum_{n=0}^{N-1}x(n)} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The centroid value of the input range.
See also
mean

◆ centroid() [2/2]

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::centroid ( ForwardIt  first1,
ForwardIt  last1,
ForwardIt  first2 
)

Computes the centroid value of the range [first1, last1)

It is calculated as the division of the weighted mean of the the signal and the average of the magnitudes.

\[ y = \frac{\sum_{n=0}^{N-1}f(n)x(n)}{\sum_{n=0}^{N-1}x(n)} \]

Parameters
first1Forward iterator defining the begin of the range to examine.
last1Forward iterator defining the end of the range to examine.
first2Forward iterator defining the beginning of the range representing the weights, \(f(i)\).
Returns
The centroid value of the input range.
See also
mean

◆ crest()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::crest ( ForwardIt  first,
ForwardIt  last 
)

Computes the crest value of the range [first, last)

It is calculated as the division of mean of the the signal and the maximum value of the magnitudes.

\[ y = \frac{ \frac{1}{N} \sum_{n=0}^{N-1}x(n)}{max \left( x \right)} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The crest value of the input range.
See also
mean

◆ entropy()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::entropy ( ForwardIt  first,
ForwardIt  last 
)

Computes the normalized entropy of the probability mass function given in the range [first, last).

Given a normalized probability mass function \( p(n) \), the entropy can explicitly be written as:

\[ H = - \sum_{n=0}^{N-1} p(n) \log_2 \left( p(n) \right) \]

Normalizing:

\[ H_n = - \frac{H}{log2(N)} \]

Parameters
firstForward iterator defining the begin of the probability mass function.
lastForward iterator defining the end of the probability mass function.
Returns
The entropy of the probability mass function.

◆ flatness()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::flatness ( ForwardIt  first,
ForwardIt  last 
)

Computes the flatness value of the range [first, last)

It is calculated as the division of geometric mean and the average of the magnitudes.

\[ y = \frac{\mu_g}{\mu} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The flatness value of the input range.
See also
mean, geometric_mean

◆ flux()

template<distances d, typename InputIt >
constexpr meta::value_type_t<InputIt> edsp::statistics::flux ( InputIt  first1,
InputIt  last1,
InputIt  first2 
)

Computes the flux between the elements in the range [first1, last1) and the elements starting at first2.

The flux is a measure of the difference between two signals, it is frequently used to estimates the differences in the power spectral between consecutive frames.

Template Parameters
dType of distance to be compute between each point.
Parameters
first1Input iterator defining the beginning of the first input range.
last1Input iterator defining the ending of the first input range.
first2Input iterator defining the beginning of the second input range.
Returns
The estimated flux.
See also
distances, distance

◆ generalized_mean()

template<typename ForwardIt , typename Integer >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::generalized_mean ( ForwardIt  first,
ForwardIt  last,
Integer  beta 
)

Computes the generalized mean of the range [first, last)

The generalized mean or power mean with exponent \( \beta \) is defined as:

\[ \mu_{\beta} = \left( \frac{1}{N}\sum_{n=0}^{N-1}x(n)^{\beta} \right) ^{\frac{1}{\beta}} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
betaExponent ( \( \beta \)).
Returns
The generalized mean of the input range.

◆ geometric_mean()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::geometric_mean ( ForwardIt  first,
ForwardIt  last 
)

Computes the geometric mean of the range [first, last)

The geometric mean is defined as:

\[ {\displaystyle \left(\prod _{i=1}^{n}x_{i}\right)^{\frac {1}{n}}={\sqrt[{n}]{x_{1}x_{2}\cdots x_{n}}}} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The geometric mean of the input range.

◆ harmonic_mean()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::harmonic_mean ( ForwardIt  first,
ForwardIt  last 
)

Computes the harmonic mean of the range [first, last)

The harmonic mean is defined as:

\[ {\displaystyle H={\frac {n}{{\frac {1}{x_{1}}}+{\frac {1}{x_{2}}}+\cdots +{\frac {1}{x_{n}}}}} ={\frac {n}{\sum \limits _{i=1}^{n}{\frac {1}{x_{i}}}}}=\left({\frac {\sum \limits _{i=1}^{n}x_{i}^{-1}}{n}}\right)^{-1}.} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The geometric mean of the input range.

◆ kurtosis()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::kurtosis ( ForwardIt  first,
ForwardIt  last 
)

Computes the Kurtosis of the range [first, last)

The kurtosis is the fourth standardized moment, defined as:

\[ {\displaystyle K [X] =E \left[\left({\frac {X-\mu }{\sigma }}\right)^{4}\right]={\frac {\mu _{4}}{\sigma ^{4}}} ={\frac {E [(X-\mu )^{4}]}{(E[(X-\mu )^{2}])^{2}}},} \]

where \( \mu_4 \) is the fourth central moment and \( \sigma \) is the standard deviation.

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The Kurtosis of the input range.
See also
moment, standard_deviation

◆ max()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::max ( ForwardIt  first,
ForwardIt  last 
)

Computes the maximum value of the range [first, last)

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The maximum value of the input range.

◆ maxabs()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::maxabs ( ForwardIt  first,
ForwardIt  last 
)

Computes the maximum absolute value of the range [first, last)

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The maximum value of the input range.

◆ mean()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::mean ( ForwardIt  first,
ForwardIt  last 
)

Computes the average or mean value of the range [first, last)

The average is defined as:

\[ \mu = \frac{1}{N}\sum_{n=0}^{N-1}x(n) \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The average of the input range.

◆ median()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::median ( ForwardIt  first,
ForwardIt  last 
)

Computes the median of the range [first, last)

The median of a finite list of numbers can be found by arranging all the numbers from smallest to greatest. If there is an odd number of numbers, the middle one is picked. If there is an even number of observations, then there is no single middle value; the median is then usually defined to be the mean of the two middle values

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The median of the input range.

◆ min()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::min ( ForwardIt  first,
ForwardIt  last 
)

Computes the minimum value of the range [first, last)

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The minimum value of the input range.

◆ minabs()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::minabs ( ForwardIt  first,
ForwardIt  last 
)

Computes the minimum absolute value of the range [first, last)

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The minimum value of the input range.

◆ moment() [1/2]

template<std::size_t N, typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::moment ( ForwardIt  first,
ForwardIt  last 
)

Computes the n-th moment of the range [first, last)

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Template Parameters
NOrder of the moment.
Returns
The n-th moment of the input range.

◆ moment() [2/2]

template<std::size_t N, typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::moment ( ForwardIt  first,
ForwardIt  last,
const meta::value_type_t< ForwardIt >  mean 
)

Computes the nth moment of the range [first, last) considering the precomputed average.

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
meanAverage of the range [first, last)
Template Parameters
NOrder of the moment.
Returns
The n-th moment of the input range.
See also
mean

◆ norm()

template<typename InputIt >
constexpr meta::value_type_t<InputIt> edsp::statistics::norm ( InputIt  first,
InputIt  last 
)

Compute the L2-norm of the signals in the range [first1, last1).

The \( l^2 \)-norm is defined as:

\[ |x|=\sqrt(\sum_{n=0}^{N - 1}|x(n)|^2), \]

where \( |x_k| \) denotes the complex modules.

Parameters
firstInput iterator defining the beginning of the first input range.
lastInput iterator defining the ending of the first input range.
Returns
L2-norm of the input signal.

◆ peak()

template<typename ForwardIt >
constexpr auto edsp::statistics::peak ( ForwardIt  first,
ForwardIt  last 
) -> std::pair<typename meta::diff_type_t<ForwardIt>, typename meta::value_type_t<ForwardIt>>

Computes the peak value of the range [first, last)

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
Pair representing the index position and the value of the peak.

◆ peakabs()

template<typename ForwardIt >
constexpr auto edsp::statistics::peakabs ( ForwardIt  first,
ForwardIt  last 
) -> std::pair<typename meta::diff_type_t<ForwardIt>, typename meta::value_type_t<ForwardIt>>

Computes the absolute peak value of the range [first, last)

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
Pair representing the index position and the value of the peak.

◆ rms()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::rms ( ForwardIt  first,
ForwardIt  last 
)

Computes the root-mean-square (RMS) value of the range [first, last)

The RMS value is defined as:

\[ x_{\mathrm {rms} }={\sqrt {{\frac {1}{n}}\left(x_{1}^{2}+x_{2}^{2}+\cdots +x_{n}^{2}\right)}} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The root mean square value of the input range.

◆ rolloff()

template<typename ForwardIt , typename Floating >
constexpr auto edsp::statistics::rolloff ( ForwardIt  first,
ForwardIt  last,
Floating  percentage 
)

Computes the roll-off index of the elements in the range [first, last)

The roll-off index is defined as the index under which some percentage (cutoff) of the total energy of the signal is contained.

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
percentageNumber between [0, 1] representing the percentage of the total energy of the roll-off index..
Returns
The estimated roll-off index.

◆ rssq()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::rssq ( ForwardIt  first,
ForwardIt  last 
)

Computes the root-sum-of-squares (RSSS) value of the range [first, last)

\[ x_{\mathrm {rms} }={\sqrt {\left(x_{1}^{2}+x_{2}^{2}+\cdots +x_{n}^{2}\right)}} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The root-sum-of-squares value of the input range.

◆ skewness()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::skewness ( ForwardIt  first,
ForwardIt  last 
)

Computes the skewness of the range [first, last)

The skewness is the third standardized moment, defined as:

\[ {\displaystyle K [X] =E \left[\left({\frac {X-\mu }{\sigma }}\right)^{3}\right]={\frac {\mu _{3}}{\sigma ^{3}}} ={\frac {E [(X-\mu )^{3}]}{(E[(X-\mu )^{2}])^{2}}},} \]

where \( \mu_3 \) is the fourth central moment and \( \sigma \) is the standard deviation.

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The skewness of the input range.
See also
moment, standard_deviation

◆ snr()

template<typename InputIt , typename Allocator = std::allocator<meta::value_type_t<InputIt>>>
constexpr meta::value_type_t<InputIt> edsp::statistics::snr ( InputIt  first1,
InputIt  last1,
InputIt  first2 
)

Compute the SNR of the signals in the range [first1, last1) and the signal starting in first2.

Signal-to-noise ratio (abbreviated SNR or S/N) is a measure used in science and engineering that compares the level of a desired signal to the level of background noise. SNR is defined as the ratio of signal power to the noise power, often expressed in decibels. A ratio higher than 1:1 (greater than 0 dB) indicates more signal than noise.

If the variance of the signal and noise are known, and the signal and noise are both zero-mean, SNR can be:

\[ \mathrm{SNR} = \frac{\sigma^2_\mathrm{signal}}{\sigma^2_\mathrm{noise}}. \]

Parameters
first1Input iterator defining the beginning of the first input range.
last1Input iterator defining the ending of the first input range.
first2Input iterator defining the beginning of the second input range.
Returns
SNR of the signals.

◆ standard_deviation()

template<typename ForwardIt >
meta::value_type_t<ForwardIt> edsp::statistics::standard_deviation ( ForwardIt  first,
ForwardIt  last 
)
inline

Computes the standard deviation of the range [first, last)

The standard deviation is defined as the square root of the variance:

\[ \sigma = \sqrt(v) \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The variance of the input range.
See also
variance

◆ variance()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::statistics::variance ( ForwardIt  first,
ForwardIt  last 
)

Computes the variance of the range [first, last)

The variance is defined as:

\[ v =\sum _{i=1}^{n}p_{i}\cdot (x_{i}-\mu )^{2} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
The variance of the input range.
See also
standard_deviation