eDSP  0.0.1
A cross-platform DSP library written in C++.
spectral_spread.hpp
Go to the documentation of this file.
1 
27 #ifndef EDSP_SPECTRAL_SPREAD_HPP
28 #define EDSP_SPECTRAL_SPREAD_HPP
29 
31 #include <cmath>
32 
33 namespace edsp { namespace feature { inline namespace spectral {
34 
55  template <typename ForwardIt>
56  constexpr auto spectral_spread(ForwardIt first1, ForwardIt last1, ForwardIt first2) {
57  using value_type = typename std::iterator_traits<ForwardIt>::value_type ;
58  const auto centroid = feature::spectral_centroid(first1, last1, first2);
59  auto weighted_sum = static_cast<value_type>(0);
60  auto unweighted_sum = static_cast<value_type>(0);
61  for (value_type i = 0; first1 != last1; ++first1, ++i) {
62  const auto diff = i - centroid;
63  weighted_sum += (diff * diff) * (*first1);
64  unweighted_sum += *first1;
65  }
66  return static_cast<value_type>(std::sqrt(weighted_sum / unweighted_sum));
67  }
68 
69 }}}
70 
71 
72 #endif //EDSP_SPECTRAL_SPREAD_HPP
constexpr auto spectral_spread(ForwardIt first1, ForwardIt last1, ForwardIt first2)
Computes the spectral spread of the of the magnitude spectrum represented by the elements in the rang...
Definition: spectral_spread.hpp:56
Definition: amplifier.hpp:29
constexpr meta::value_type_t< ForwardIt > centroid(ForwardIt first, ForwardIt last)
Computes the centroid value of the range [first, last)
Definition: centroid.hpp:43