Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
fft_reference_probe.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9*/
10
16# include <locale>
17# include <iomanip>
18# include <iostream>
19
20# include <fft.H>
21# include <tpl_array.H>
22
23using namespace Aleph;
24
25namespace
26{
27 using FFTD = FFT<double>;
28 using Complex = FFTD::Complex;
29
30 void
32 {
33 std::cout << "[";
34 for (size_t i = 0; i < values.size(); ++i)
35 {
36 std::cout << "[" << std::setprecision(17) << values[i].real()
37 << ", " << values[i].imag() << "]";
38 if (i + 1 != values.size())
39 std::cout << ", ";
40 }
41 std::cout << "]";
42 }
43
44 void
45 print_real_array(const Array<double> & values)
46 {
47 std::cout << "[";
48 for (size_t i = 0; i < values.size(); ++i)
49 {
50 std::cout << std::setprecision(17) << values[i];
51 if (i + 1 != values.size())
52 std::cout << ", ";
53 }
54 std::cout << "]";
55 }
56}
57
58int
60{
61 std::locale::global(std::locale::classic());
62 std::cout.imbue(std::locale::classic());
63
65 Complex(1.25, -0.5),
66 Complex(-2.0, 1.75),
67 Complex(0.5, 2.25),
68 Complex(3.0, -1.25),
69 Complex(-0.75, 0.125),
70 Complex(1.5, -2.0),
71 Complex(0.0, 0.75),
72 Complex(-1.25, 0.5),
73 Complex(2.0, -0.25),
74 Complex(-0.5, 1.0)
75 };
76
77 Array<double> real_signal = {0.25, -1.5, 2.0, 0.0, -0.75, 1.25, 3.0};
78
81 for (size_t i = 0; i < 17; ++i)
82 prime_signal.append(Complex(0.5 * static_cast<double>(i) - 2.0,
83 (static_cast<double>(i % 5) - 2.0) * 0.75));
84
85 FFTD::Plan plan(17);
86
87 const auto complex_spectrum = FFTD::transformed(complex_signal, false);
88 const auto real_full_spectrum = FFTD::transform(real_signal);
89 const auto real_compact_spectrum = FFTD::rfft(real_signal);
90 const auto real_reconstructed = FFTD::irfft(real_compact_spectrum, real_signal.size());
91 const auto prime_spectrum = plan.transformed(prime_signal, false);
92
93 std::cout << "{\n";
94 std::cout << " \"complex_signal\": ";
96 std::cout << ",\n \"complex_spectrum\": ";
98 std::cout << ",\n \"real_signal\": ";
100 std::cout << ",\n \"real_full_spectrum\": ";
102 std::cout << ",\n \"real_compact_spectrum\": ";
104 std::cout << ",\n \"real_reconstructed\": ";
106 std::cout << ",\n \"prime_signal\": ";
108 std::cout << ",\n \"prime_spectrum\": ";
110 std::cout << "\n}\n";
111
112 return 0;
113}
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:139
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Definition tpl_array.H:351
void reserve(size_t cap)
Reserves cap cells into the array.
Definition tpl_array.H:315
Fast Fourier Transform (FFT) and DSP Toolkit.
Definition fft.H:154
Fast Fourier Transform (FFT) and Digital Signal Processing (DSP) toolkit.
int main()
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Dynamic array container with automatic resizing.