stfinvfourier.cc 8.16 KB
Newer Older
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
/*! \file stfinvfourier.cc
 * \brief a base class for all engines which operate in the Fourier domain (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id$
 * \author Thomas Forbriger
 * \date 08/05/2011
 * 
 * a base class for all engines which operate in the Fourier domain (implementation)
 * 
 * Copyright (c) 2011 by Thomas Forbriger (BFO Schiltach) 
 *
 * ----
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
 *
 * 
 * REVISIONS and CHANGES 
 *  - 08/05/2011   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define STFINV_STFINVFOURIER_CC_VERSION \
  "STFINV_STFINVFOURIER_CC   V1.0   "
#define STFINV_STFINVFOURIER_CC_CVSID \
  "$Id$"

41
#include <sstream>
42
43
44
45
#include <stfinv/stfinvfourier.h>

namespace stfinv {

thomas.forbriger's avatar
thomas.forbriger committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  /*! 
   * - Refernces to signal storage are available
   * - Parameters are parsed and available through the base class
   * What has to be done here:
   * -# The FFT engine must be initialized appropriately
   *    -# Time domain padding has to be read from the parameters
   *    -# Number of sample modulo has to be read from parameters
   *    -# number of samples must be calculated from these values
   *    -# based on these values workspace arrays must be constructed
   *    -# The FFT engine must be constructed from the workspace arrays.
   *       This requires a copy constructor for the FFT engine, which
   *       currently is not present.
   *       Alternatively, we could only use a pointer to the engine.
   */
  STFFourierDomainEngine::STFFourierDomainEngine(const stfinv::Tvectoroftriples& triples,
                                                 const stfinv::Waveform& stf,
                                                 const std::string& parameters)
thomas.forbriger's avatar
thomas.forbriger committed
63
    :Tbase(triples, stf, parameters)
thomas.forbriger's avatar
thomas.forbriger committed
64
  { 
thomas.forbriger's avatar
thomas.forbriger committed
65
    this->initialize();
thomas.forbriger's avatar
thomas.forbriger committed
66
67
  } // STFFourierDomainEngine::STFFourierDomainEngine

68
69
70
71
72
73
74
75
  /*----------------------------------------------------------------------*/

  void STFFourierDomainEngine::help(std::ostream& os) const
  {
    STFFourierDomainEngine::classhelp(os);
  } // void STFFourierDomainEngine::help(std::ostream& os) const


76
77
78
79
80
81
  /*----------------------------------------------------------------------*/

  const char* STFFourierDomainEngine::name() const
  {
    return("STFFourierDomainEngine");
  } //  const char const* STFFourierDomainEngine::name() const
82
83
84
85
86
87
88
89
90
91
92
93
  /*----------------------------------------------------------------------*/

  /*! \brief online help text giving information on options
   *
   * This must be kept synchronous with the options used by
   * STFFourierDomainEngine::initialize()
   */
  void STFFourierDomainEngine::classhelp(std::ostream& os)
  {
    os << "This class is not yet implemented." << std::endl;
    os << "Online help is not yet provided." << std::endl;
  } // void STFFourierDomainEngine::classhelp(std::ostream& os)
94

thomas.forbriger's avatar
thomas.forbriger committed
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
  /*! \brief Create FFT engines
   *
   * \par Number of samples
   * For the FFT we usually use a number of samples larger than that of the
   * underlying time series. 
   * This way we at least partially avoid the undesired effect of the cyclic
   * discrete Fourier transform, which can lead to wrap-around.
   * Currently there are three ways to modify the number of samples actually
   * used:
   * -# Option \c fpad specifies an padding factor. 
   *    The number of samples simply is larger than the number of samples of
   *    the underlying time series by this factor.
   * -# Option \c fpow2:
   *    If set, the next power of two larger than the fpad*nsamples is used.
   * -# Option \c fdiv specifies a divisor.
   *    If set and if \c fpow2 is not set the number of samples will be the
   *    next integer multiple of the divisor larger than fpad*nsamples.
   *
   * \par Workspace
   * Two FFT engines will be created:
   * -# One engine (\c Mfftengineinput) being shared by recorded data and
   *  synthetic data, because both have to be transformed to Fourier domain at
   *  once.
   * -# One engine (\c Mfftengineoutpu) being shared by the stf and the
   *  convolved synthetics, because both have to be transformed to the time
   *  domain at once.
   */
thomas.forbriger's avatar
thomas.forbriger committed
124
125
  void STFFourierDomainEngine::initialize()
  {
126
    // extract parameter values
127
128
    // ------------------------
    // padding factor
129
130
131
132
133
134
135
    double padfactor;
    {
      std::istringstream is(this->parameter("fpad","1.5"));
      is >> padfactor;
    }
    STFINV_assert(padfactor >= 1.,
                  "ERROR: parameter for option \"fpad\" not larger or equal 1");
136
    // flag: use power of two
137
    bool poweroftwo=(this->parameter("fpow2","false")=="true");
138
    // flag: use integer multiples of divisor
139
    bool divisorset=this->parameterisset("fdiv");
140
    // number of samples shall be integer power of divisor
141
142
143
144
    unsigned int divisor;
    if (divisorset)
    {
      std::istringstream is (this->parameter("fdiv","100")); 
145
146
      STFINV_assert(divisor > 0,
                  "ERROR: parameter for option \"fdiv\" not larger than 0");
147
148
149
    }

    // define number of samples to be used by Fourier engine
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    // -----------------------------------------------------
    // use at least the number of samples sepcified by the padfactor
    unsigned int nsamples=padfactor*this->nsamples();
    if (nsamples<this->nsamples()) { nsamples=this->nsamples(); }
    // power of two has precendence
    if (poweroftwo)
    {
      unsigned int n=2;
      while (n<nsamples) { n *= 2; }
      nsamples=n;
    }
    else if (divisorset)
    {
      unsigned int rest=nsamples % divisor;
      nsamples -= rest;
      nsamples += divisor;
    } // if (poweroftwo) or (divisorset)

    // allocate workspace by creating engines
    // --------------------------------------
    Mfftengineinput=fourier::fft::DRFFTWAFFArrayEngine(2*this->nreceivers(),
                                                       nsamples);
    Mfftengineoutput=fourier::fft::DRFFTWAFFArrayEngine(1+this->nreceivers(),
                                                        nsamples);
thomas.forbriger's avatar
thomas.forbriger committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  } // void STFFourierDomainEngine::initialize() 

  /*----------------------------------------------------------------------*/

  void STFFourierDomainEngine::fftinput()
  {
    STFINV_abort("STFFourierDomainEngine::fftinput not yet implemented");
  } // void STFFourierDomainEngine::fftinput() 

  /*----------------------------------------------------------------------*/

  void STFFourierDomainEngine::fftoutput()
  {
    STFINV_abort("STFFourierDomainEngine::fftoutput not yet implemented");
  } // void STFFourierDomainEngine::fftoutput() 

  /*----------------------------------------------------------------------*/

  STFFourierDomainEngine::TAspectrum STFFourierDomainEngine::data() const
  {
    STFINV_abort("STFFourierDomainEngine::data not yet implemented");
  } // STFFourierDomainEngine::TAspectrum STFFourierDomainEngine::data() const

  /*----------------------------------------------------------------------*/

  STFFourierDomainEngine::TAspectrum STFFourierDomainEngine::synthetics() const
  {
    STFINV_abort("STFFourierDomainEngine::synthetics not yet implemented");
  } // STFFourierDomainEngine::TAspectrum STFFourierDomainEngine::synthetics() const

  /*----------------------------------------------------------------------*/

  STFFourierDomainEngine::Tspectrum STFFourierDomainEngine::stf() const
  {
    STFINV_abort("STFFourierDomainEngine::stf not yet implemented");
  } // STFFourierDomainEngine::Tspectrum STFFourierDomainEngine::stf() const

211
212
213
} // namespace stfinv

/* ----- END OF stfinvfourier.cc ----- */