-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfourier-test.cpp
167 lines (147 loc) · 3.9 KB
/
fourier-test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**************************************************************************
*
* $Id: fourier-test.cpp,v 1.13 2011/03/26 07:10:50 patrick Exp $
*
* Copyright (c) 2001-2011 Patrick Guio <[email protected]>
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2. of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**************************************************************************/
#include <iostream>
using std::cout;
using std::endl;
#if defined(FOURIER_FFTW)
#if defined(HAVE_FFTW_FFT)
#undef HAVE_FFTW3_FFT
#undef HAVE_DXML_FFT
#undef HAVE_MLIB_FFT
#define HAVE_FOURIER 1
#else
#define HAVE_FOURIER 0
#endif
const char fft_name[] = "fftw";
#elif defined(FOURIER_FFTW3)
#if defined(HAVE_FFTW3_FFT)
#undef HAVE_FFTW_FFT
#undef HAVE_DXML_FFT
#undef HAVE_MLIB_FFT
#define HAVE_FOURIER 1
#else
#define HAVE_FOURIER 0
#endif
const char fft_name[] = "fftw3";
#elif defined(FOURIER_DXML)
#if defined(HAVE_DXML_FFT)
#undef HAVE_FFTW_FFT
#undef HAVE_FFTW3_FFT
#undef HAVE_MLIB_FFT
#define HAVE_FOURIER 1
#else
#define HAVE_FOURIER 0
#endif
const char fft_name[] = "dxml";
#elif defined(FOURIER_MLIB)
#if defined(HAVE_MLIB_FFT)
#undef HAVE_FFTW_FFT
#undef HAVE_FFTW3_FFT
#undef HAVE_DXML_FFT
#define HAVE_FOURIER 1
#else
#define HAVE_FOURIER 0
#endif
const char fft_name[] = "mlib";
#else
#define HAVE_FOURIER 0
const char fft_name[] = "";
#endif
#if HAVE_FOURIER==1 && HAVE_BLITZ==1
#include <fourier.h>
using namespace blitz;
template <class Array>
void initArray(int sign, Array &A)
{
switch (sign) {
case -1:
A = 1.0;
break;
case 1:
A = 0.0;
A(0) = A.size();
break;
}
}
template <class T1, class T2>
void itest(int n1, int sign)
{
fourier::IDFT1D<T1,T2> dft1d(n1, sign);
cout << " DFT1D = " << dft1d << endl;
typename fourier::IDFT1D<T1,T2>::Array1di A(n1);
initArray(sign, A);
cout << "A = " << A << endl;
dft1d.direct(A);
cout << "A = DFT(A) " << A << endl;
dft1d.inverse(A);
cout << "A = IDFT(A) " << A << endl << endl;
}
template <class T1, class T2>
void otest(int n1, int n2, int sign)
{
fourier::ODFT1D<T1,T2> dft1d(n1, sign);
cout << " DFT1D = " << dft1d << endl;
typename fourier::ODFT1D<T1,T2>::Array1di A(n1);
typename fourier::ODFT1D<T1,T2>::Array1do B(n2);
initArray(sign, A);
cout << "A = " << A << endl;
dft1d.direct(A, B);
cout << "B = DFT(A) " << B << endl;
dft1d.inverse(B, A);
cout << "A = IDFT(B) " << A << endl << endl;
}
int main(int nargs, char *args[])
{
try {
int n = ( nargs == 2 ? atoi(args[1]) : 6);
itest<fourier::complex, fourier::complex>(n,-1);
itest<fourier::complex, fourier::complex>(n, 1);
otest<fourier::complex, fourier::complex>(n,n,-1);
otest<fourier::complex, fourier::complex>(n,n, 1);
itest<double, double>(n,-1);
itest<double, double>(n, 1);
otest<double, double>(n,n,-1);
otest<double, double>(n,n, 1);
#if defined(HAVE_FFTW3_FFT)
itest<double, fourier::complex>(n,-1);
itest<double, fourier::complex>(n, 1);
otest<double, fourier::complex>(n,n/2+1,-1);
otest<double, fourier::complex>(n,n/2+1, 1);
#endif
return 0;
}
catch(int status) {
return status;
}
catch(ClassException& c) {
cerr << c.what() << endl;
return !0;
}
}
#else
int main()
{
cout << "Cannot test " << __FILE__ << " with " << fft_name
<< " implementation.\n" << "Not supported on this platform" << endl;
return 0;
}
#endif