eDSP  0.0.1
A cross-platform DSP library written in C++.
amdf.hpp
Go to the documentation of this file.
1 
27 #ifndef EDSP_AMDF_HPP
28 #define EDSP_AMDF_HPP
29 
30 #include <iterator>
31 
32 namespace edsp { namespace feature { inline namespace temporal {
33 
50  template <typename InputIt, typename OutputIt>
51  constexpr void amdf(InputIt first, InputIt last, OutputIt d_first) {
52  using value_type = typename std::iterator_traits<OutputIt>::value_type;
53  const auto N = std::distance(first, last);
54  auto * array = &(*first);
55  for (auto i = 0; i < N; ++i, ++d_first) {
56  for (auto j = 0; j < (N - i); ++j) {
57  *d_first += std::abs(array[j] - array[j + i]);
58  }
59  *d_first /= static_cast<value_type>(N);
60  }
61  }
62 }}}
63 #endif //EDSP_AMDF_HPP
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
constexpr void amdf(InputIt first, InputIt last, OutputIt d_first)
Computes the AMDF (Average Magnitude Difference Function) of the contiguous elements in the range [fi...
Definition: amdf.hpp:51
Definition: amplifier.hpp:29