22 #ifndef EDSP_HILBERT_HPP 23 #define EDSP_HILBERT_HPP 25 #include <edsp/spectral/internal/fft_impl.hpp> 30 namespace edsp {
inline namespace spectral {
50 template <
typename InputIt,
typename OutputIt,
51 typename Allocator = std::allocator<std::complex<meta::value_type_t<InputIt>>>>
52 inline void hilbert(InputIt first, InputIt last, OutputIt d_first) {
53 using value_type = meta::value_type_t<InputIt>;
54 const auto nfft =
static_cast<typename fft_impl<value_type>::size_type
>(
std::distance(first, last));
56 std::vector<std::complex<value_type>, Allocator> input_data(nfft);
57 std::vector<std::complex<value_type>, Allocator> complex_data(nfft);
60 fft_impl<value_type> fft(nfft);
61 fft.dft(meta::data(input_data), meta::data(complex_data));
63 const auto limit_1 =
math::is_even(nfft) ? nfft / 2 : (nfft + 1) / 2;
64 const auto limit_2 =
math::is_even(nfft) ? limit_1 + 1 : limit_1;
65 for (
auto i = 1; i < limit_1; ++i) {
69 for (
auto i = limit_2; i < nfft; ++i) {
70 complex_data[i] = std::complex<value_type>(0, 0);
73 fft_impl<value_type> ifft(nfft);
74 ifft.idft(meta::data(complex_data), &(*d_first));
75 ifft.idft_scale(&(*d_first));
80 #endif // EDSP_HIRTLEY_HPP constexpr bool is_even(T x)
Determines if the number is even.
Definition: numeric.hpp:59
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
void hilbert(InputIt first, InputIt last, OutputIt d_first)
Computes the Discrete-Time analytic signal using Hilbert transform of the range [first, last) and stores the result in another range, beginning at d_first.
Definition: hilbert.hpp:52
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
Definition: amplifier.hpp:29