queso-0.51.1
ComplexFft.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008,2009,2010,2011,2012,2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/Fft.h>
26 #include <gsl/gsl_fft_complex.h>
27 
28 namespace QUESO {
29 
30 template <>
31 void
33  const std::vector<std::complex<double> >& data,
34  unsigned int fftSize,
35  std::vector<std::complex<double> >& forwardResult)
36 {
39  "Fft<complex>::forward()",
40  "not implemented yet");
41 
42  std::complex<double> z = data[0]; z += 0.; // just to avoid icpc warnings
43  unsigned int f = fftSize; f += 1; // just to avoid icpc warnings
44  forwardResult[0] = 0.; // just to avoid icpc warnings
45 #if 0
46  if (forwardResult.size() != fftSize) {
47  forwardResult.resize(fftSize,std::complex<double>(0.,0.));
48  std::vector<std::complex<double> >(forwardResult).swap(forwardResult);
49  }
50 
51  std::vector<double> internalData(fftSize,0.);
52  unsigned int minSize = std::min((unsigned int) data.size(),fftSize);
53  for (unsigned int j = 0; j < minSize; ++j) {
54  internalData[j] = data[j];
55  }
56 
57  gsl_fft_real_workspace* realWkSpace = gsl_fft_real_workspace_alloc(fftSize);
58  gsl_fft_real_wavetable* realWvTable = gsl_fft_real_wavetable_alloc(fftSize);
59 
60  gsl_fft_real_transform(&internalData[0],
61  1,
62  fftSize,
63  realWvTable,
64  realWkSpace);
65 
66  gsl_fft_real_wavetable_free(realWvTable);
67  gsl_fft_real_workspace_free(realWkSpace);
68 
69  unsigned int halfFFTSize = fftSize/2;
70  double realPartOfFFT = 0.;
71  double imagPartOfFFT = 0.;
72  for (unsigned int j = 0; j < internalData.size(); ++j) {
73  if (j == 0) {
74  realPartOfFFT = internalData[j];
75  imagPartOfFFT = 0.;
76  }
77  else if (j < halfFFTSize) {
78  realPartOfFFT = internalData[2*j-1];
79  imagPartOfFFT = internalData[2*j ];
80  }
81  else if (j == halfFFTSize) {
82  realPartOfFFT = internalData[2*j-1];
83  imagPartOfFFT = 0.;
84  }
85  else {
86  realPartOfFFT = internalData[2*(fftSize-j)-1];
87  imagPartOfFFT = -internalData[2*(fftSize-j) ];
88  }
89  forwardResult[j] = std::complex<double>(realPartOfFFT,imagPartOfFFT);
90  }
91 #endif
92  return;
93 }
94 
95 template <>
96 void
98  const std::vector<std::complex<double> >& data,
99  unsigned int fftSize,
100  std::vector<std::complex<double> >& inverseResult)
101 {
102  if (inverseResult.size() != fftSize) {
103  inverseResult.resize(fftSize,std::complex<double>(0.,0.));
104  std::vector<std::complex<double> >(inverseResult).swap(inverseResult);
105  }
106 
107  std::vector<double> internalData(2*fftSize,0.); // Yes, twice the fftSize
108  unsigned int minSize = 2 * std::min((unsigned int) data.size(),fftSize); // Yes, 2*
109  for (unsigned int j = 0; j < minSize; ++j) {
110  internalData[2*j ] = data[j].real();
111  internalData[2*j+1] = data[j].imag();
112  }
113 
114  gsl_fft_complex_workspace* complexWkSpace = gsl_fft_complex_workspace_alloc(fftSize);
115  gsl_fft_complex_wavetable* complexWvTable = gsl_fft_complex_wavetable_alloc(fftSize);
116 
117  gsl_fft_complex_inverse(&internalData[0],
118  1,
119  fftSize,
120  complexWvTable,
121  complexWkSpace);
122 
123  gsl_fft_complex_wavetable_free(complexWvTable);
124  gsl_fft_complex_workspace_free(complexWkSpace);
125 
126  for (unsigned int j = 0; j < fftSize; ++j) {
127  inverseResult[j] = std::complex<double>(internalData[2*j],internalData[2*j+1]);
128  }
129 
130  return;
131 }
132 
133 } // End namespace QUESO
Class for a Fast Fourier Transform (FFT) algorithm.
Definition: Fft.h:66
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223

Generated on Thu Apr 23 2015 19:26:15 for queso-0.51.1 by  doxygen 1.8.5