27 #ifndef EDSP_SPECTRAL_SPREAD_HPP 28 #define EDSP_SPECTRAL_SPREAD_HPP 33 namespace edsp {
namespace feature {
inline namespace spectral {
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) {
63 weighted_sum += (diff * diff) * (*first1);
64 unweighted_sum += *first1;
66 return static_cast<value_type
>(std::sqrt(weighted_sum / unweighted_sum));
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