eDSP  0.0.1
A cross-platform DSP library written in C++.
complex2real.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  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22  * File: complex2real.hpp
23  * Date: 04/10/18
24  * Author: Mohammed Boujemaoui Boulaghmoudi
25  */
26 
27 #ifndef EDSP_COMPLEX2REAL_HPP
28 #define EDSP_COMPLEX2REAL_HPP
29 
30 #include <edsp/meta/iterator.hpp>
31 #include <algorithm>
32 #include <complex>
33 
34 namespace edsp { inline namespace converter {
35 
43  template <typename InputIt, typename OutputIt>
44  constexpr void complex2real(InputIt first, InputIt last, OutputIt d_first1, OutputIt d_first2) {
45  using input_t = meta::value_type_t<InputIt>;
46  using output_t = meta::value_type_t<OutputIt>;
47  for (; first != last; ++first, ++d_first1, ++d_first2) {
48  *d_first1 = std::real(*first);
49  *d_first2 = std::imag(*first);
50  }
51  }
52 
53 }} // namespace edsp::converter
54 
55 #endif //EDSP_COMPLEX2REAL_HPP
constexpr void complex2real(InputIt first, InputIt last, OutputIt d_first1, OutputIt d_first2)
Converts a range of complex numbers in two ranges storing the real and imaginary parts.
Definition: complex2real.hpp:44
constexpr T real(const std::complex< T > &z)
Computes the real component of the complex number z.
Definition: complex.hpp:60
constexpr T imag(const std::complex< T > &z)
Computes the imaginary component of the complex number z.
Definition: complex.hpp:70
Definition: amplifier.hpp:29