22 #ifndef EDSP_CEPSTRUM_HPP 23 #define EDSP_CEPSTRUM_HPP 28 namespace edsp {
inline namespace spectral {
43 template <
typename InputIt,
typename OutputIt,
typename RAllocator = std::allocator<meta::value_type_t<InputIt>>,
44 typename CAllocator = std::allocator<std::complex<meta::value_type_t<OutputIt>>>>
45 inline void cepstrum(InputIt first, InputIt last, OutputIt d_first) {
46 meta::expects(
std::distance(first, last) > 0,
"Not expecting empty input");
47 using value_type = meta::value_type_t<InputIt>;
49 const auto nfft = 2 * size;
50 fft_impl<value_type> fft_(nfft);
51 fft_impl<value_type> ifft_(nfft);
53 std::vector<value_type, RAllocator> temp_input(nfft, static_cast<value_type>(0)), temp_output(nfft);
54 std::copy(first, last, std::begin(temp_input));
56 std::vector<std::complex<value_type>, CAllocator> fft_data_(
make_fft_size(nfft));
57 fft_.dft(meta::data(temp_input), meta::data(fft_data_));
59 std::transform(std::cbegin(fft_data_), std::cend(fft_data_), std::begin(fft_data_),
60 [](
const std::complex<value_type>& val) -> std::complex<value_type> {
61 return std::complex<value_type>(std::log(std::abs(val)), 0);
64 ifft_.idft(meta::data(fft_data_), meta::data(temp_output));
65 ifft_.idft_scale(meta::data(temp_output));
66 std::copy(std::cbegin(temp_output), std::cbegin(temp_output) + size, d_first);
71 #endif // EDSP_CEPSTRUM_HPP void cepstrum(InputIt first, InputIt last, OutputIt d_first)
Computes the cepstrum of the range [first, last) and stores the result in another range...
Definition: cepstrum.hpp:45
constexpr Integer make_fft_size(Integer real_size) noexcept
Computes the expected DFT size for a real-to-complex DFT transform.
Definition: dft.hpp:35
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
Definition: amplifier.hpp:29