eDSP  0.0.1
A cross-platform DSP library written in C++.
real2complex.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: real2complex.hpp
19  * Author: Mohammed Boujemaoui
20  * Date: 1/9/2018
21  */
22 #ifndef EDSP_REAL2COMPLEX_HPP
23 #define EDSP_REAL2COMPLEX_HPP
24 
25 #include <edsp/meta/iterator.hpp>
26 #include <algorithm>
27 #include <complex>
28 
29 namespace edsp { inline namespace converter {
30 
37  template <typename T>
38  constexpr std::complex<T> real2complex(T real, T imag = static_cast<T>(0)) noexcept {
39  return std::complex<T>(real, imag);
40  }
41 
51  template <typename InputIt, typename OutputIt>
52  constexpr void real2complex(InputIt first, InputIt last, OutputIt d_first) {
53  using input_t = meta::value_type_t<InputIt>;
54  using output_t = meta::value_type_t<OutputIt>;
55  std::transform(first, last, d_first, [](const input_t value) -> output_t { return value; });
56  }
57 
67  template <typename InputIt, typename OutputIt>
68  constexpr void real2complex(InputIt first1, InputIt last1, InputIt first2, OutputIt d_first) {
69  using input_t = meta::value_type_t<InputIt>;
70  using output_t = meta::value_type_t<OutputIt>;
71  std::transform(first1, last1, first2, d_first, [](const input_t real, const input_t imag) -> output_t {
72  return {real, imag};
73  });
74  }
75 
76 }} // namespace edsp::converter
77 
78 #endif // EASDY_REAL2COMPLEX_HPP
constexpr T real(const std::complex< T > &z)
Computes the real component of the complex number z.
Definition: complex.hpp:60
constexpr std::complex< T > real2complex(T real, T imag=static_cast< T >(0)) noexcept
Converts a real scalar to an equivalent complex number.
Definition: real2complex.hpp:38
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