eDSP  0.0.1
A cross-platform DSP library written in C++.
spectral_variation.hpp
Go to the documentation of this file.
1 
27 #ifndef EDSP_SPECTRAL_VARIATION_HPP
28 #define EDSP_SPECTRAL_VARIATION_HPP
29 
30 #include <iterator>
31 #include <cmath>
32 
33 namespace edsp { namespace feature { inline namespace spectral {
34 
56  template <typename ForwardIt>
57  constexpr auto spectral_variation(ForwardIt first1, ForwardIt last1, ForwardIt first2) {
58  using value_type = typename std::iterator_traits<ForwardIt>::value_type ;
59  auto sum_x1 = static_cast<value_type >(0);
60  auto sum_x2 = static_cast<value_type >(0);
61  auto sum_x12 = static_cast<value_type >(0);
62  for (; first1 != last1; ++first1, ++first2) {
63  sum_x1 += *first1;
64  sum_x2 += *first2;
65  sum_x12 += *first1 * *first2;
66  }
67  return 1 - sum_x2 / (std::sqrt(sum_x1) * std::sqrt(sum_x2));
68  }
69 
70 }}}
71 
72 #endif //EDSP_SPECTRAL_VARIATION_HPP
constexpr auto spectral_variation(ForwardIt first1, ForwardIt last1, ForwardIt first2)
Computes the spectral variation of the of the magnitude spectrum represented by the elements in the r...
Definition: spectral_variation.hpp:57
Definition: amplifier.hpp:29