FFTDataContainer.h
Go to the documentation of this file.
1 #ifndef _utl_FFTDataContainer_h_
2 #define _utl_FFTDataContainer_h_
3 
4 #include <complex>
5 #include <utl/Trace.h>
6 #include <utl/ShadowPtr.h>
7 #include <utl/AugerException.h>
8 
9 #include <utl/fft++.h>
10 
11 
12 namespace utl {
13 
30  template<template<typename X> class C, typename T, typename F>
32 
33  public:
35 
37  FFTDataContainer() = default;
38 
40  unsigned int GetNyquistZone() const { return fNyquistZone; }
41 
43  void
44  SetNyquistZone(const unsigned int zone)
45  {
46  if (zone < 1)
47  throw OutOfBoundException("Requested illegal Nyquist zone of zero.");
48  fNyquistZone = zone;
49  }
50 
52  double
53  GetFrequencyOfBin(const typename C<F>::SizeType bin)
54  const
55  {
56  if (fUpToDateDomain == eTime)
57  UpdateFrequencySpectrum(); // do the fft
58  const double binning = fFrequencySpectrum.GetBinning();
59  const typename C<F>::SizeType highestbin = fFrequencySpectrum.GetSize() - 1;
60  if (bin > highestbin)
61  throw OutOfBoundException("Requested frequency for a bin that is not in the FrequencySpectrum.");
62  const double bandwidth = double(highestbin) * binning;
63  const unsigned int evenedzone = (fNyquistZone / 2) * 2;
64  const double startingfrequency = evenedzone * bandwidth;
65  // we are in an even Nyquist zone, i.e., the frequencies count downwards
66  const int sign = (fNyquistZone == evenedzone) ? -1 : 1;
67  return startingfrequency + sign * double(bin) * binning;
68  }
69 
71  int
72  GetBinOfFrequency(const double frequency)
73  const
74  {
75  if (fUpToDateDomain == eTime)
76  UpdateFrequencySpectrum(); // do the fft
77  const double binning = fFrequencySpectrum.GetBinning();
78  const typename C<F>::SizeType highestbin = fFrequencySpectrum.GetSize() - 1;
79  const double bandwidth = double(highestbin) * binning;
80  if ((fNyquistZone - 1)*bandwidth > frequency || fNyquistZone*bandwidth < frequency)
81  throw OutOfBoundException("Requested bin for a frequency that is not in the FrequencySpectrum.");
82  const unsigned int evenedzone = (fNyquistZone / 2) * 2;
83  const double startingfrequency = evenedzone * bandwidth;
84  // we are in an even Nyquist zone, i.e., the frequencies count downwards
85  const int sign = (fNyquistZone == evenedzone) ? -1 : 1;
86  const double timeBinning = fTimeSeries.GetBinning();
87  const int timeTraceLength = fTimeSeries.GetSize();
88  const double bin = (frequency - startingfrequency) * sign * timeBinning * timeTraceLength;
89  return std::round(bin);
90  }
91 
93  const C<T>&
94  GetConstTimeSeries()
95  const
96  {
98  UpdateTimeSeries(); // do the fft^-1
99  return fTimeSeries;
100  }
101 
103  C<T>&
105  {
107  UpdateTimeSeries(); // do the fft^-1
108  fUpToDateDomain = eTime; // write access is possible, so have to assume data will change
109  return fTimeSeries;
110  }
111 
113  const C<F>&
114  GetConstFrequencySpectrum()
115  const
116  {
117  if (fUpToDateDomain == eTime)
118  UpdateFrequencySpectrum(); // do the fft
120  }
121 
123  C<F>&
125  {
126  if (fUpToDateDomain == eTime)
127  UpdateFrequencySpectrum(); // do the fft
128  fUpToDateDomain = eFrequency; // write access is possible, so have to assume data will change
129  return fFrequencySpectrum;
130  }
131 
133  void
135  {
136  fTimeSeries.Clear();
137  fFrequencySpectrum.Clear();
138  fUpToDateDomain = eBoth; // no data there
139  }
140 
141  private:
143 
144  unsigned int fNyquistZone = 1; // data corresponds to which Nyquist zone
145 
146  mutable C<T> fTimeSeries;
147  mutable C<F> fFrequencySpectrum;
148 
150  void UpdateTimeSeries() const;
152  void UpdateFrequencySpectrum() const;
153 
154  };
155 
156 }
157 
158 
159 #endif
return startingfrequency sign * double(bin)*binning
void UpdateTimeSeries() const
if the frequency domain data has been changed last, update the time domain data with an fft^-1 ...
unsigned int GetNyquistZone() const
get the Nyquist zone
const double startingfrequency
C< F > & GetFrequencySpectrum()
read out the frequency spectrum (write access)
C< T > & GetTimeSeries()
read out the time series (write access)
throw OutOfBoundException("Requested frequency for a bin that is not in the FrequencySpectrum.")
FFTDataContainer()=default
constructor setting up default values
Template class for a data container that offers and takes both time series and corresponding frequenc...
const unsigned int evenedzone
const C< F >::SizeType highestbin
void SetNyquistZone(const unsigned int zone)
set the Nyquist zone
void UpdateFrequencySpectrum() const
if the time domain data has been changed last, update the frequency domain data with an fft ...
void Clear()
delete contents of the contained traces

, generated on Tue Sep 26 2023.