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

Enumerations

enum  mel_base { base_e, base_10 }
 

Functions

template<typename T >
constexpr T bark2hertz (T z) noexcept
 Converts a critical band rate in Bark scale to Hertz. More...
 
template<typename InputIt , typename OutputIt >
constexpr void complex2real (InputIt first, InputIt last, OutputIt d_first1, OutputIt d_first2)
 Converts a range of complex numbers in two ranges storing the real and imaginary parts. More...
 
template<typename T >
constexpr T db2mag (T db) noexcept
 Convert decibels to magnitude. More...
 
template<typename T >
constexpr T db2pow (T db) noexcept
 Convert decibels to power. More...
 
template<typename T >
constexpr T deg2rad (T degree) noexcept
 Convert angle from degrees to radians. More...
 
template<typename T >
constexpr T bark2band (T z) noexcept
 Converts a frequency in Hertz into its equivalent Bark scale value. More...
 
template<mel_base scale, typename T >
constexpr T hertz2mel (T f) noexcept
 Converts a frequency in Hertz into mels. More...
 
template<typename T >
constexpr T mag2db (T magnitude) noexcept
 Convert magnitude to decibels (dB) More...
 
template<mel_base scale, typename T >
constexpr T mel2hertz (T mel) noexcept
 Converts a frequency in mels to Hertz. More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > peak2peak (ForwardIt first, ForwardIt last)
 Maximum-to-minimum difference in the range [first, last) More...
 
template<typename ForwardIt >
constexpr meta::value_type_t< ForwardIt > peak2rms (ForwardIt first, ForwardIt last)
 Maximum Peak-magnitude-to-RMS ratio in the range [first, last) More...
 
template<typename T >
constexpr T pow2db (T power) noexcept
 Convert power to decibels. More...
 
template<typename T >
constexpr T rad2deg (T radians) noexcept
 Convert angle from radians to degrees. More...
 
template<typename T >
constexpr std::complex< T > real2complex (T real, T imag=static_cast< T >(0)) noexcept
 Converts a real scalar to an equivalent complex number. More...
 
template<typename InputIt , typename OutputIt >
constexpr void real2complex (InputIt first, InputIt last, OutputIt d_first)
 Converts a range of scalar numbers in to an equivalent complex number and stores the result in another range. More...
 
template<typename InputIt , typename OutputIt >
constexpr void real2complex (InputIt first1, InputIt last1, InputIt first2, OutputIt d_first)
 Converts a range of scalar numbers in to an equivalent complex number and stores the result in another range. More...
 

Enumeration Type Documentation

◆ mel_base

Enumerator
base_e 

e base

base_10 

10 base

Function Documentation

◆ bark2band()

template<typename T >
constexpr T edsp::converter::bark2band ( z)
noexcept

Converts a frequency in Hertz into its equivalent Bark scale value.

The conversion of a frequency f (Hz) into Bark is implemented as follows:

\[ { \alpha =[(26.81f)/(1960+f)]-0.53\, f] An then: - If \f$ \alpha < 2 \f$ then \f$ f_b = 0.15 * (2 - \alpha) \f$. - If \f$ \alpha > 20.1 \f$ then \f$ f_b = 0.22 * (\alpha - 20.1) \f$. @param f Frequency in Hz @returns Frequency in Bark scale. @see bark2band, hertz2band */ template <typename T> constexpr T hertz2bark(T f) noexcept { const auto b = (26.81 * f) / (1960 + f) - 0.53; if (b < 2) { b += 0.15 * (2 - b); } if (b > 20.1) { b += 0.22 * (b - 20.1); } return b; } /** @brief Converts a critical band rate in Bark into a critical bandwidth in Hz. The conversion of a critical band rate z into a critical bandwidth in Hz is implemented as follows: \f[ f = 52548/ (z^{2}-52.56z+690.39)\, with z in bark. \]

or

\[ {\displaystyle f=600\sinh(z/6)} {\displaystyle f=600\sinh(z/6)} \]

Parameters
zThe critical band rate, in Bark
Returns
The critical bandwidth in Hz.

◆ bark2hertz()

template<typename T >
constexpr T edsp::converter::bark2hertz ( z)
noexcept

Converts a critical band rate in Bark scale to Hertz.

The conversion of a critical band rate z into Hertz is as follows:

\[ f = 52548/ (z^{2}-52.56z+690.39)\, with z in bark. \]

or

\[ {\displaystyle f=600\sinh(z/6)} {\displaystyle f=600\sinh(z/6)} \]

Parameters
zThe critical band rate, in Bark
Returns
Frequency in Hz.
See also
hertz2bark

◆ complex2real()

template<typename InputIt , typename OutputIt >
constexpr void edsp::converter::complex2real ( InputIt  first,
InputIt  last,
OutputIt  d_first1,
OutputIt  d_first2 
)

Converts a range of complex numbers in two ranges storing the real and imaginary parts.

Parameters
firstInput iterator defining the beginning of the range.
lastInput iterator defining the ending of the range.
d_first1Output iterator defining the beginning of the real part.
d_first2Output iterator defining the beginning of the imaginary part.

◆ db2mag()

template<typename T >
constexpr T edsp::converter::db2mag ( db)
noexcept

Convert decibels to magnitude.

The output is computed as follows:

\[ y = 10^{\frac{x}{20}} \]

Parameters
dbScalar number in decibels.
Returns
Magnitude measurement, returned as a scalar.

◆ db2pow()

template<typename T >
constexpr T edsp::converter::db2pow ( db)
noexcept

Convert decibels to power.

The output is computed as follows:

\[ y = 10^{\frac{x}{10}} \]

Parameters
dbScalar number in decibels.
Returns
Power measurements.

◆ deg2rad()

template<typename T >
constexpr T edsp::converter::deg2rad ( degree)
noexcept

Convert angle from degrees to radians.

The output is computed as follows:

\[ y = \frac{x\pi}{180} \]

Parameters
degreeAngle in degrees
Returns
Angle in radians

◆ hertz2mel()

template<mel_base scale, typename T >
constexpr T edsp::converter::hertz2mel ( f)
noexcept

Converts a frequency in Hertz into mels.

The popular formula from O'Shaugnessy's book can be expressed with different logarithmic bases:

\[ {\displaystyle m=2595\log _{10}\left(1+{\frac {f}{700}}\right)=1127\ln \left(1+{\frac {f}{700}}\right)} \]

Parameters
fFrequency in Hertz.
Returns
Frequency in mels.
See also
mel2hertz, mel_base

◆ mag2db()

template<typename T >
constexpr T edsp::converter::mag2db ( magnitude)
noexcept

Convert magnitude to decibels (dB)

The output is computed as follows:

\[ y = 20 \log10{ \left( x \right) } \]

Parameters
magnitudeScalar number in magnitude scale.
Returns
Scalar number in decibels.

◆ mel2hertz()

template<mel_base scale, typename T >
constexpr T edsp::converter::mel2hertz ( mel)
noexcept

Converts a frequency in mels to Hertz.

Depending of the base, the corresponding inverse expressions are:

\[ {\displaystyle f=700\left(10^{\frac {m}{2595}}-1\right)=700\left(e^{\frac {m}{1127}}-1\right)} \]

Parameters
melFrequency in mels.
Returns
Frequency in Hz.
See also
hertz2mel

◆ peak2peak()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::converter::peak2peak ( ForwardIt  first,
ForwardIt  last 
)

Maximum-to-minimum difference in 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
Maximum-to-minimum difference.

◆ peak2rms()

template<typename ForwardIt >
constexpr meta::value_type_t<ForwardIt> edsp::converter::peak2rms ( ForwardIt  first,
ForwardIt  last 
)

Maximum Peak-magnitude-to-RMS ratio in the range [first, last)

Returns the ratio of the largest absolute value in the range [first, last) to the root-mean-square (RMS) value of the range. The Peak-magnitude-to-RMS Level is:

\[ y =\frac{\left| x \right|_{\infty}}{\sqrt{\frac{1}{N}\sum_{n=0}^{N-1}\left|x\left(i\right)\right|^2}} \]

Parameters
firstForward iterator defining the begin of the range to examine.
lastForward iterator defining the end of the range to examine.
Returns
Peak-magnitude-to-RMS ratio.

◆ pow2db()

template<typename T >
constexpr T edsp::converter::pow2db ( power)
noexcept

Convert power to decibels.

The output is computed as follows:

\[ y = 10 \log10{\left( x \right)} \]

Parameters
powerScalar number representing the power of a sample.
Returns
Power measurement in decibel (dB).

◆ rad2deg()

template<typename T >
constexpr T edsp::converter::rad2deg ( radians)
noexcept

Convert angle from radians to degrees.

The output is computed as follows:

\[ y = x \frac{180}{\pi} \]

Parameters
radiansAngle in radians.
Returns
Angle in degrees.

◆ real2complex() [1/3]

template<typename T >
constexpr std::complex<T> edsp::converter::real2complex ( real,
imag = static_cast<T>(0) 
)
noexcept

Converts a real scalar to an equivalent complex number.

Parameters
realScalar number representing the real part of the complex number.
imagScalar number representing the imaginary part of the complex number.
Returns
Returns the complex-valued.

◆ real2complex() [2/3]

template<typename InputIt , typename OutputIt >
constexpr void edsp::converter::real2complex ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)

Converts a range of scalar numbers in to an equivalent complex number and stores the result in another range.

Note
Use this function when the output range does not have an imaginary part.
Parameters
firstInput iterator defining the beginning of the range representing the real part.
lastInput iterator defining the ending of the range representing the real part.
d_firstOutput iterator defining the beginning of the destination range.

◆ real2complex() [3/3]

template<typename InputIt , typename OutputIt >
constexpr void edsp::converter::real2complex ( InputIt  first1,
InputIt  last1,
InputIt  first2,
OutputIt  d_first 
)

Converts a range of scalar numbers in to an equivalent complex number and stores the result in another range.

Parameters
first1Input iterator defining the beginning of the range representing the real part.
last1Input iterator defining the ending of the range representing the real part.
first2Input iterator defining the beginning of the range representing the imaginary part.
d_firstOutput iterator defining the beginning of the destination range.