Public Types | Static Public Member Functions | List of all members
DuneFFT Class Reference

#include <DuneFFT.h>

Public Types

using Index = unsigned int
 
using DFT = CompactRealDftData< float >
 
using FloatVector = std::vector< float >
 

Static Public Member Functions

static int fftForward (Index ntick, const float *psam, DFT &dft, Index logLevel=0)
 
static int fftForward (const FloatVector &sams, DFT &dft, Index logLevel=0)
 
static int fftInverse (const DFT &dft, FloatVector &sams, Index logLevel=0)
 

Detailed Description

Definition at line 23 of file DuneFFT.h.

Member Typedef Documentation

Definition at line 28 of file DuneFFT.h.

Definition at line 29 of file DuneFFT.h.

using DuneFFT::Index = unsigned int

Definition at line 27 of file DuneFFT.h.

Member Function Documentation

int DuneFFT::fftForward ( Index  ntick,
const float *  psam,
DFT dft,
Index  logLevel = 0 
)
static

Definition at line 23 of file DuneFFT.cxx.

23  {
24  const string myname = "DuneFFT::fftForward: ";
25  dft.reset(nsam);
26  if ( ! dft.isValid() ) return 1;
27  if ( nsam == 0 ) return 0;
28  vector<double> sams(nsam);
29  for ( Index isam=0; isam<nsam; ++isam ) sams[isam] = psam[isam];
30  int nsamInt = nsam;
31  TVirtualFFT* pfft = TVirtualFFT::FFT(1, &nsamInt, "R2C");
32  pfft->SetPoints(&sams[0]);
33  pfft->Transform();
34  double xre = 0.0;
35  double xim = 0.0;
36  Index namp = dft.nAmplitude();
37  Index npha = dft.nPhase();
38  FloatVector amps(namp);
39  FloatVector phas(npha);
40  // Loop over the compact samples.
41  float nfac = 1.0;
42  if ( dft.normalization().isConsistent() ) nfac = 1.0/sqrt(nsam);
43  if ( dft.normalization().isBin() ) nfac = 1.0/nsam;
44  for ( Index ifrq=0; ifrq<namp; ++ifrq ) {
45  pfft->GetPointComplex(ifrq, xre, xim);
46  // For an even # samples (namp = npha + 1), the Nyquist term is real
47  // and we store the sign with the amplitude.
48  double xam = ifrq < npha ? sqrt(xre*xre + xim*xim) : xre;
49  double xph = atan2(xim, xre);
50  float fac = nfac;
51  if ( dft.normalization().isPower() && dft.isAliased(ifrq) ) fac *= sqrt(2.0);
52  xam *= fac;
53  dft.setAmplitude(ifrq, xam);
54  if ( ifrq < npha ) {
55  dft.setPhase(ifrq, xph);
56  }
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;
63  cout << endl;
64  }
65  }
66  return 0;
67 }
int setPhase(Index ifrq, F val)
unsigned int Index
void reset(Index nsam) override
virtual bool isValid() const
Definition: RealDftData.h:42
Index nAmplitude() const
int setAmplitude(Index ifrq, F val)
bool isAliased(Index ifrq) const
Definition: RealDftData.h:56
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
const Norm & normalization() const override
Dft::FloatVector FloatVector
QTextStream & endl(QTextStream &s)
int DuneFFT::fftForward ( const FloatVector sams,
DFT dft,
Index  logLevel = 0 
)
static

Definition at line 72 of file DuneFFT.cxx.

72  {
73  return fftForward(sams.size(), &sams[0], dft, logLevel);
74 }
static int fftForward(Index ntick, const float *psam, DFT &dft, Index logLevel=0)
Definition: DuneFFT.cxx:23
int DuneFFT::fftInverse ( const DFT dft,
FloatVector sams,
Index  logLevel = 0 
)
static

Definition at line 79 of file DuneFFT.cxx.

79  {
80  const string myname = "DuneFFT::fftInverse: ";
81  if ( ! dft.isValid() ) return 1;
82  Index namp = dft.nAmplitude();
83  Index npha = dft.nPhase();
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;
88  int nsamInt = nsam;
89  TVirtualFFT* pfft = TVirtualFFT::FFT(1, &nsamInt, "C2R");
90  vector<double> xdres(nsam, 0.0);
91  vector<double> xdims(nsam, 0.0);
92  for ( Index ifrq=0; ifrq<nsam; ++ifrq ) {
93  double amp = dft.convAmplitude(ifrq);
94  double pha = dft.phase(ifrq);
95  double xre = amp*cos(pha);
96  double xim = amp*sin(pha);
97  xdres[ifrq] = xre;
98  xdims[ifrq] = xim;
99  }
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;
109  }
110  }
111  pfft->Transform();
112  sams.resize(nsam);
113  float nfac = 1.0/nsam;
114  for ( Index isam=0; isam<nsam; ++isam ) sams[isam] = nfac*pfft->GetPointReal(isam);
115  return 0;
116 }
unsigned int Index
virtual bool isValid() const
Definition: RealDftData.h:42
F phase(Index ifrq) const override
Index nAmplitude() const
F convAmplitude(Index ifrq) const
Definition: RealDftData.h:70
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
QTextStream & endl(QTextStream &s)

The documentation for this class was generated from the following files: