eDSP  0.0.1
A cross-platform DSP library written in C++.
normalize.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: normalizer.hpp
19  * Date: 09/06/18
20  * Author: Mohammed Boujemaoui
21  */
22 
23 #ifndef EDSP_NORMALIZER_HPP
24 #define EDSP_NORMALIZER_HPP
25 
26 #include <algorithm>
27 #include <edsp/statistics/rms.hpp>
28 #include <edsp/statistics/max.hpp>
29 #include <edsp/meta/iterator.hpp>
30 
31 namespace edsp { inline namespace algorithm {
32 
45  template <typename InputIt, typename OutputIt>
46  constexpr void normalize(InputIt first, InputIt last, OutputIt d_first) {
47  const auto factor = statistics::maxabs(first, last);
48  std::transform(first, last, d_first,
49  [factor](const meta::value_type_t<InputIt> value) -> meta::value_type_t<OutputIt> {
50  return static_cast<meta::value_type_t<OutputIt>>(value) / factor;
51  });
52  }
53 
66  template <typename InputIt, typename OutputIt>
67  constexpr void normalize_rms(InputIt first, InputIt last, OutputIt d_first) {
68  const auto factor = statistics::rms(first, last);
69  std::transform(first, last, d_first,
70  [factor](const meta::value_type_t<InputIt> value) -> meta::value_type_t<OutputIt> {
71  return static_cast<meta::value_type_t<OutputIt>>(value) / factor;
72  });
73  }
74 
75 }} // namespace edsp::algorithm
76 
77 #endif // EDSP_NORMALIZER_HPP
constexpr void normalize_rms(InputIt first, InputIt last, OutputIt d_first)
Normalizes the elements in the range [first, last) and stores the result in another range...
Definition: normalize.hpp:67
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 > maxabs(ForwardIt first, ForwardIt last)
Computes the maximum absolute value of the range [first, last)
Definition: max.hpp:50
constexpr void normalize(InputIt first, InputIt last, OutputIt d_first)
Normalizes the elements in the range [first, last) and stores the result in another range...
Definition: normalize.hpp:46
Definition: amplifier.hpp:29