7 #include "TVirtualFFT.h" 24 const string myname =
"DuneFFT::fftForward: ";
26 if ( ! dft.
isValid() )
return 1;
27 if ( nsam == 0 )
return 0;
29 for (
Index isam=0; isam<nsam; ++isam ) sams[isam] = psam[isam];
31 TVirtualFFT* pfft = TVirtualFFT::FFT(1, &nsamInt,
"R2C");
32 pfft->SetPoints(&sams[0]);
44 for (
Index ifrq=0; ifrq<namp; ++ifrq ) {
45 pfft->GetPointComplex(ifrq, xre, xim);
48 double xam = ifrq < npha ? sqrt(xre*xre + xim*xim) : xre;
49 double xph = atan2(xim, xre);
57 if ( logLevel >= 3 ) {
58 cout << myname <<
setw(4) << ifrq <<
": (" 59 <<
setw(10) << fixed << xre <<
", " 60 <<
setw(10) << fixed << xim <<
"): " 61 <<
setw(10) << fixed << xam;
62 if ( ifrq < npha ) cout <<
" @ " <<
setw(10) << fixed << xph;
73 return fftForward(sams.size(), &sams[0], dft, logLevel);
80 const string myname =
"DuneFFT::fftInverse: ";
81 if ( ! dft.
isValid() )
return 1;
84 if ( namp == 0 || npha == 0 )
return 1;
85 if ( namp < npha )
return 2;
86 if ( namp - npha > 1 )
return 3;
87 Index nsam = namp + npha - 1;
89 TVirtualFFT* pfft = TVirtualFFT::FFT(1, &nsamInt,
"C2R");
92 for (
Index ifrq=0; ifrq<nsam; ++ifrq ) {
94 double pha = dft.
phase(ifrq);
95 double xre = amp*cos(pha);
96 double xim = amp*sin(pha);
100 pfft->SetPointsComplex(&xdres[0], &xdims[0]);
101 if ( logLevel >= 3 ) {
102 cout << myname <<
"Inverting" <<
endl;
103 cout << myname <<
"Real/imag components:" <<
endl;
104 for (
Index ifrq=0; ifrq<nsam; ++ifrq ) {
105 float xre = xdres[ifrq];
106 float xim = xdims[ifrq];
107 cout << myname <<
setw(4) << ifrq <<
": (" <<
setw(10) << fixed << xre
108 <<
", " <<
setw(10) << fixed << xim <<
")" <<
endl;
113 float nfac = 1.0/nsam;
114 for (
Index isam=0; isam<nsam; ++isam ) sams[isam] = nfac*pfft->GetPointReal(isam);
std::vector< float > FloatVector
bool isConsistent() const
int setPhase(Index ifrq, F val)
void reset(Index nsam) override
virtual bool isValid() const
F phase(Index ifrq) const override
F convAmplitude(Index ifrq) const
static int fftForward(Index ntick, const float *psam, DFT &dft, Index logLevel=0)
int setAmplitude(Index ifrq, F val)
bool isAliased(Index ifrq) const
Q_EXPORT QTSManip setw(int w)
static int fftInverse(const DFT &dft, FloatVector &sams, Index logLevel=0)
const Norm & normalization() const override
QTextStream & endl(QTextStream &s)