eDSP  0.0.1
A cross-platform DSP library written in C++.
dft.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: dft.hpp
19  * Date: 09/06/18
20  * Author: Mohammed Boujemaoui
21  */
22 
23 #ifndef EDSP_DFT_HPP
24 #define EDSP_DFT_HPP
25 
26 #include <edsp/spectral/internal/fft_impl.hpp>
27 
28 namespace edsp { inline namespace spectral {
29 
34  template <typename Integer>
35  constexpr Integer make_fft_size(Integer real_size) noexcept {
36  return std::floor(real_size / 2) + 1;
37  }
38 
43  template <typename Integer>
44  constexpr Integer make_ifft_size(Integer complex_size) noexcept {
45  return 2 * (complex_size - 1);
46  }
47 
64  template <typename InputIt, typename OutputIt>
65  inline void cdft(InputIt first, InputIt last, OutputIt d_first) {
66  using complex_t = meta::value_type_t<InputIt>;
67  using underlying_t = typename complex_t::value_type;
68  const auto nfft = static_cast<typename fft_impl<underlying_t>::size_type>(std::distance(first, last));
69  fft_impl<underlying_t> plan(nfft);
70  plan.dft(&(*first), &(*d_first));
71  }
72 
88  template <typename InputIt, typename OutputIt>
89  inline void cidft(InputIt first, InputIt last, OutputIt d_first) {
90  using complex_t = meta::value_type_t<InputIt>;
91  using underlying_t = typename complex_t::value_type;
92  const auto nfft = static_cast<typename fft_impl<underlying_t>::size_type>(std::distance(first, last));
93  fft_impl<underlying_t> plan(nfft);
94  plan.idft(&(*first), &(*d_first));
95  plan.idft_scale(&(*d_first));
96  }
97 
111  template <typename InputIt, typename OutputIt>
112  void dft(InputIt first, InputIt last, OutputIt d_first) {
113  using value_type = typename std::iterator_traits<InputIt>::value_type;
114  fft_impl<value_type> plan(std::distance(first, last));
115  plan.dft(&(*first), &(*d_first));
116  }
117 
131  template <typename InputIt, typename OutputIt>
132  void idft(InputIt first, InputIt last, OutputIt d_first) {
133  using value_type = typename std::iterator_traits<OutputIt>::value_type;
134  const auto nfft =
135  static_cast<typename fft_impl<value_type>::size_type>(make_ifft_size(std::distance(first, last)));
136  fft_impl<value_type> plan(nfft);
137  plan.idft(&(*first), &(*d_first));
138  plan.idft_scale(&(*d_first));
139  }
140 
141 }} // namespace edsp::spectral
142 
143 #endif // EDSP_DFT_HPP
void cdft(InputIt first, InputIt last, OutputIt d_first)
Computes the complex-to-complex Discrete-Fourier-Transform of the range [first, last) and stores the ...
Definition: dft.hpp:65
constexpr void floor(InputIt first, InputIt last, OutputIt d_first)
For each element in the range [first, last) computes the largest integer value not greater than the e...
Definition: floor.hpp:40
void cidft(InputIt first, InputIt last, OutputIt d_first)
Computes the complex-to-complex Inverse-Discrete-Fourier-Transform of the range [first, last) and stores the result in another range, beginning at d_first.
Definition: dft.hpp:89
constexpr Integer make_fft_size(Integer real_size) noexcept
Computes the expected DFT size for a real-to-complex DFT transform.
Definition: dft.hpp:35
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
constexpr Integer make_ifft_size(Integer complex_size) noexcept
Computes the expected IDFT size for a complex-to-real IDFT transform.
Definition: dft.hpp:44
void idft(InputIt first, InputIt last, OutputIt d_first)
Computes the complex-to-real Inverse-Discrete-Fourier-Transform of the complex range [first...
Definition: dft.hpp:132
Definition: amplifier.hpp:29
void dft(InputIt first, InputIt last, OutputIt d_first)
Computes the real-to-complex Discrete-Fourier-Transform of the range [first, last) and stores the res...
Definition: dft.hpp:112