27 #ifndef EDSP_SPECTRAL_SLOPE_HPP 28 #define EDSP_SPECTRAL_SLOPE_HPP 32 namespace edsp {
namespace feature {
inline namespace spectral {
62 template <
typename ForwardIt>
63 constexpr
auto spectral_slope(ForwardIt first1, ForwardIt last1, ForwardIt first2) {
64 using value_type =
typename std::iterator_traits<ForwardIt>::value_type ;
65 auto m_sum =
static_cast<value_type
>(0);
66 auto f_sum =
static_cast<value_type
>(0);
67 auto ff_sum =
static_cast<value_type
>(0);
68 auto mf_sum =
static_cast<value_type
>(0);
69 for (; first1 != last1; ++first1, ++first2) {
72 mf_sum += (*first1) * (*first2);
73 ff_sum += (*first2) * (*first2);
75 const auto N =
static_cast<value_type
>(
std::distance(first1, last1));
76 return (1 / m_sum) * (N * mf_sum - f_sum * m_sum) / (N * ff_sum - (f_sum * f_sum));
81 #endif //EDSP_SPECTRAL_SLOPE_HPP constexpr auto spectral_slope(ForwardIt first1, ForwardIt last1, ForwardIt first2)
Computes the spectral slope of the of the magnitude spectrum represented by the elements in the range...
Definition: spectral_slope.hpp:63
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
Definition: amplifier.hpp:29