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

Enumerations

enum  CorrelationScale { CorrelationScale::None, CorrelationScale::Biased, CorrelationScale::Unbiased }
 The ScaleOpt enum defines the normalization option of the correlation function. More...
 
enum  SpectralScale { SpectralScale::Linear, SpectralScale::Logarithmic }
 The SpectralScale enum represent the scale used to represent the power spectral density. More...
 

Functions

template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void cepstrum (InputIt first, InputIt last, OutputIt d_first)
 Computes the cepstrum of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void conv (InputIt first1, InputIt last1, InputIt first2, OutputIt d_first)
 Computes the convolution between the range [first1, last1) and the range [first2, last2), and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void xcorr (InputIt first, InputIt last, OutputIt d_first, CorrelationScale scale=CorrelationScale::None)
 Computes the autocorrelation of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void xcorr (InputIt first1, InputIt last1, InputIt first2, OutputIt d_first, CorrelationScale scale=CorrelationScale::None)
 Computes the correlation between the range [first1, last1) and the [first2, last2), and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt >
void dct (InputIt first, InputIt last, OutputIt d_first)
 Computes the Discrete-Cosine-Transform of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt >
void idct (InputIt first, InputIt last, OutputIt d_first)
 Computes the Inverse-Discrete-Cosine-Transform of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename Integer >
constexpr Integer make_fft_size (Integer real_size) noexcept
 Computes the expected DFT size for a real-to-complex DFT transform. More...
 
template<typename Integer >
constexpr Integer make_ifft_size (Integer complex_size) noexcept
 Computes the expected IDFT size for a complex-to-real IDFT transform. More...
 
template<typename InputIt , typename OutputIt >
void cdft (InputIt first, InputIt last, OutputIt d_first)
 Computes the complex-to-complex Discrete-Fourier-Transform of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt >
void cidft (InputIt first, InputIt last, OutputIt d_first)
 Computes the complex-to-complex Inverse-Discrete-Fourier-Transform of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt >
void dft (InputIt first, InputIt last, OutputIt d_first)
 Computes the real-to-complex Discrete-Fourier-Transform of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt >
void idft (InputIt first, InputIt last, OutputIt d_first)
 Computes the complex-to-real Inverse-Discrete-Fourier-Transform of the complex range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt >
void hartley (InputIt first, InputIt last, OutputIt d_first)
 Computes the Discrete-Hartley-Transform of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt , typename Allocator = std::allocator<std::complex<meta::value_type_t<InputIt>>>>
void hilbert (InputIt first, InputIt last, OutputIt d_first)
 Computes the Discrete-Time analytic signal using Hilbert transform of the range [first, last) and stores the result in another range, beginning at d_first. More...
 
template<typename InputIt , typename OutputIt , typename Allocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void periodogram (InputIt first, InputIt last, OutputIt d_first, SpectralScale scale)
 Computes the periodogram of the range [first, last) and stores the result in another range, beginning at d_first. More...
 

Enumeration Type Documentation

◆ CorrelationScale

The ScaleOpt enum defines the normalization option of the correlation function.

Enumerator
None 

Raw, unscaled cross-correlation.

Biased 

Biased estimate of the cross-correlation.

Unbiased 

Unbiased estimate of the cross-correlation.

◆ SpectralScale

The SpectralScale enum represent the scale used to represent the power spectral density.

Enumerator
Linear 

Linear scale

Logarithmic 

Logarithmic scale

Function Documentation

◆ cdft()

template<typename InputIt , typename OutputIt >
void edsp::spectral::cdft ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)
inline

Computes the complex-to-complex Discrete-Fourier-Transform of the range [first, last) and stores the result in another range, beginning at d_first.

The DFT transforms a sequence of \( N \) complex numbers \( x_n \) into another sequence of complex numbers \( X_k \):

\[ {\displaystyle {\begin{aligned}X_{k}&=\sum _{n=0}^{N-1}x_{n}\cdot e^{-{\frac {2\pi i}{N}}kn}\\&=\sum _{n=0}^{N-1}x_{n}\cdot [\cos(2\pi kn/N)-i\cdot \sin(2\pi kn/N)],\end{aligned}}} \]

Template Parameters
TUnderlying type to perform the arithmetic operations (float, double or long double).
Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
See also
complex_idft

◆ cepstrum()

template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void edsp::spectral::cepstrum ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)
inline

Computes the cepstrum of the range [first, last) and stores the result in another range, beginning at d_first.

The Cepstrum is the result of taking the inverse Fourier transform (IDFT) of the logarithm of the estimated spectrum of a signal:

\[ {\displaystyle C_K =\left|{\mathcal {F}}^{-1}\left\{\log \left(\left|{\mathcal {F}}\{f(t)\}\right|^{2}\right)\right\}\right|^{2}} \]

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.

◆ cidft()

template<typename InputIt , typename OutputIt >
void edsp::spectral::cidft ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)
inline

Computes the complex-to-complex Inverse-Discrete-Fourier-Transform of the range [first, last) and stores the result in another range, beginning at d_first.

The IDFT transforms a sequence of \( N \) complex numbers \( X_k \) into another sequence of complex numbers \( x_n \):

\[ {\displaystyle x_{n}={\frac {1}{N}}\sum _{k=0}^{N-1}X_{k}e^{{\frac {2\pi i}{N}}kn}\quad \quad n=0,\dots ,N-1.} \]

Template Parameters
TUnderlying type to perform the arithmetic operations (float, double or long double).
Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
See also
complex_dft

◆ conv()

template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void edsp::spectral::conv ( InputIt  first1,
InputIt  last1,
InputIt  first2,
OutputIt  d_first 
)
inline

Computes the convolution between the range [first1, last1) and the range [first2, last2), and stores the result in another range, beginning at d_first.

The result of conv can be interpreted as an estimate of how the shape of one range is modified by the other. It is defined as:

\[ {\displaystyle (f*g)[n]=\sum _{m=-M}^{M}f[n-m]g[m].} \]

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.
d_firstOutput iterator defining the beginning of the destination range.

◆ dct()

template<typename InputIt , typename OutputIt >
void edsp::spectral::dct ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)
inline

Computes the Discrete-Cosine-Transform of the range [first, last) and stores the result in another range, beginning at d_first.

The DCT-II is computed as follows:

\[ {\displaystyle X_{k}=\sum _{n=0}^{N-1}{x_{n}\cos \left[{\frac {\pi }{N}}\left(n+{\frac {1}{2}}\right)k\right]}} \]

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.

◆ dft()

template<typename InputIt , typename OutputIt >
void edsp::spectral::dft ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)

Computes the real-to-complex Discrete-Fourier-Transform of the range [first, last) and stores the result in another range, beginning at d_first.

When the input data are purely real number, the DFT output satisfies the “Hermitian” redundancy: \( F(i) \) is the conjugate of \( F(N - i) \), where \( N \) is the size of the DFT. To benefit from this property (speed and space advantages), the input and output arrays are of different sizes and types: the input is \( N \) real numbers, while the output is \( \frac{N}{2} + 1 \) complex numbers (the non-redundant outputs) where the division is rounded down.

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
See also
make_fft_size

◆ hartley()

template<typename InputIt , typename OutputIt >
void edsp::spectral::hartley ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)
inline

Computes the Discrete-Hartley-Transform of the range [first, last) and stores the result in another range, beginning at d_first.

The DHT transforms a sequence of \( N \) real numbers \( x_n \) into another sequence of real numbers \( H_k \):

\[ {\displaystyle H_{k}=\sum _{n=0}^{N-1}x_{n}\operatorname {cas} \left({\frac {2\pi }{N}}nk\right)=\sum _{n=0}^{N-1}x_{n} \left[\cos \left({\frac {2\pi }{N}}nk\right)+\sin \left({\frac {2\pi }{N}}nk\right)\right]\quad \quad k=0,\dots ,N-1} \]

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
See also
complex_idft

◆ hilbert()

template<typename InputIt , typename OutputIt , typename Allocator = std::allocator<std::complex<meta::value_type_t<InputIt>>>>
void edsp::spectral::hilbert ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)
inline

Computes the Discrete-Time analytic signal using Hilbert transform of the range [first, last) and stores the result in another range, beginning at d_first.

The Discrete-time analytic is the complex helical sequence obtained from a real data sequence. The analytic signal \( A_k = A_r + iA_i \) has a real part, \( A_r \), which is the original data, and an imaginary part, \( A_i \), which contains the Hilbert transform. The imaginary part is a version of the original real sequence with a 90° phase shift.

The Hilbert transform is computed as follows:

\[ {\displaystyle {\widehat {s}}(t)={\mathcal {H}}\{s\}(t)=(h*s)(t)={\frac {1}{\pi }}\int _{-\infty }^{\infty }{\frac {s(\tau )}{t-\tau }}\,d\tau .\,} \]

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
See also
complex_idft

◆ idct()

template<typename InputIt , typename OutputIt >
void edsp::spectral::idct ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)
inline

Computes the Inverse-Discrete-Cosine-Transform of the range [first, last) and stores the result in another range, beginning at d_first.

The IDCT-II is computed as follows:

\[ {\displaystyle X_{k}={\frac {1}{2}}x_{0}+\sum _{n=1}^{N-1}{x_{n}\cos \left[{\frac {\pi }{N}}n\left(k+{\frac {1}{2}}\right)\right]}} \]

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.

◆ idft()

template<typename InputIt , typename OutputIt >
void edsp::spectral::idft ( InputIt  first,
InputIt  last,
OutputIt  d_first 
)

Computes the complex-to-real Inverse-Discrete-Fourier-Transform of the complex range [first, last) and stores the result in another range, beginning at d_first.

When the input data are purely real number, the DFT output satisfies the “Hermitian” redundancy: \( F(i) \) is the conjugate of \( F(N - i) \), where \( N \) is the size of the DFT. To benefit from this property (speed and space advantages), the input and output arrays are of different sizes and types: the input is \( N \) real numbers, while the output is \( \frac{N}{2} + 1 \) complex numbers (the non-redundant outputs) where the division is rounded down.

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
See also
make_ifft_size

◆ make_fft_size()

template<typename Integer >
constexpr Integer edsp::spectral::make_fft_size ( Integer  real_size)
noexcept

Computes the expected DFT size for a real-to-complex DFT transform.

Returns
Size of the DFT

◆ make_ifft_size()

template<typename Integer >
constexpr Integer edsp::spectral::make_ifft_size ( Integer  complex_size)
noexcept

Computes the expected IDFT size for a complex-to-real IDFT transform.

Returns
Size of the IDFT

◆ periodogram()

template<typename InputIt , typename OutputIt , typename Allocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void edsp::spectral::periodogram ( InputIt  first,
InputIt  last,
OutputIt  d_first,
SpectralScale  scale 
)
inline

Computes the periodogram of the range [first, last) and stores the result in another range, beginning at d_first.

The periodogram is an estimate of the spectral density of a signal.

\[ {\displaystyle S\left({\tfrac {k}{NT}}\right)=\left|\sum _{n}x_{N}[n]\cdot e^{-i2\pi {\frac {kn}{N}}}\right|^{2}} \]

where T, is the inverse of the sample rate \( f_s \).

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
scaleScale to be used in the output

◆ xcorr() [1/2]

template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void edsp::spectral::xcorr ( InputIt  first,
InputIt  last,
OutputIt  d_first,
CorrelationScale  scale = CorrelationScale::None 
)
inline

Computes the autocorrelation of the range [first, last) and stores the result in another range, beginning at d_first.

The result of xcorr can be interpreted as an estimate of the correlation between two random sequences or as the deterministic correlation between two deterministic signals.

\[ R_{xx}(k) = \sum_{n=-\infty}^{\infty} x(n)x(n-k) \]

Parameters
firstInput iterator defining the beginning of the input range.
lastInput iterator defining the ending of the input range.
d_firstOutput iterator defining the beginning of the destination range.
scaleScale factor to use.

◆ xcorr() [2/2]

template<typename InputIt , typename OutputIt , typename RAllocator = std::allocator<meta::value_type_t<InputIt>>, typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
void edsp::spectral::xcorr ( InputIt  first1,
InputIt  last1,
InputIt  first2,
OutputIt  d_first,
CorrelationScale  scale = CorrelationScale::None 
)
inline

Computes the correlation between the range [first1, last1) and the [first2, last2), and stores the result in another range, beginning at d_first.

The result of xcorr can be interpreted as an estimate of the correlation between two random sequences or as the deterministic correlation between two deterministic signals.

\[ R_{x_1 x_2}(k) = \sum_{n=-\infty}^{\infty} x_1(n)x_2(n-k) \]

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.
d_firstOutput iterator defining the beginning of the destination range.
scaleScale factor to use.