eDSP  0.0.1
A cross-platform DSP library written in C++.
peak2rms.hpp
Go to the documentation of this file.
1 /*
2  * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3  * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along width
16  * this program. If not, see <http://www.gnu.org/licenses/>
17  *
18  * File: peak2rms.hpp
19  * Author: Mohammed Boujemaoui
20  * Date: 2/8/2018
21  */
22 #ifndef EDSP_PEAK2RMS_HPP
23 #define EDSP_PEAK2RMS_HPP
24 
25 #include <edsp/statistics/rms.hpp>
26 #include <edsp/meta/iterator.hpp>
27 #include <algorithm>
28 #include <cmath>
29 
30 namespace edsp { inline namespace converter {
31 
44  template <typename ForwardIt>
45  constexpr meta::value_type_t<ForwardIt> peak2rms(ForwardIt first, ForwardIt last) {
46  const auto pair = std::minmax_element(first, last);
47  const auto max_abs = std::max(std::abs(pair.first), std::abs(pair.second));
48  return max_abs / statistics::rms(first, last);
49  }
50 }} // namespace edsp::converter
51 
52 #endif // EDSP_PEAK2RMS_HPP
constexpr meta::value_type_t< ForwardIt > max(ForwardIt first, ForwardIt last)
Computes the maximum value of the range [first, last)
Definition: max.hpp:38
constexpr meta::value_type_t< ForwardIt > rms(ForwardIt first, ForwardIt last)
Computes the root-mean-square (RMS) value of the range [first, last)
Definition: rms.hpp:44
constexpr meta::value_type_t< ForwardIt > peak2rms(ForwardIt first, ForwardIt last)
Maximum Peak-magnitude-to-RMS ratio in the range [first, last)
Definition: peak2rms.hpp:45
Definition: amplifier.hpp:29