version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
MTPowerSpectrumEngine.h
1#ifndef __MTPOWERSPECTRUM_ENGINE_H__
2#define __MTPOWERSPECTRUM_ENGINE_H__
3
4#include "mspass/seismic/PowerSpectrum.h"
5#include "mspass/seismic/TimeSeries.h"
6#include "mspass/utility/dmatrix.h"
7#include <boost/archive/text_iarchive.hpp>
8#include <boost/archive/text_oarchive.hpp>
9#include <gsl/gsl_errno.h>
10#include <gsl/gsl_fft_complex.h>
11#include <memory>
12#include <vector>
13
14namespace mspass::algorithms::deconvolution {
30public:
50 MTPowerSpectrumEngine(const int winsize, const double tbp, const int ntapers,
51 const int nfftin = -1, const double dtin = 1.0);
90 std::vector<double> apply(const std::vector<double> &d);
92 double df() const { return deltaf; };
95 std::vector<double> frequencies();
97 int taper_length() const { return taperlen; };
99 double time_bandwidth_product() const { return tbp; };
101 int number_tapers() const { return ntapers; };
104 int fftsize() const { return nfft; };
106 double dt() { return operator_dt; };
126 double set_df(double dt) {
127 this->operator_dt = dt;
128 int this_nf = this->nf();
129 double fny = 1.0 / (2.0 * dt);
130 this->deltaf = fny / static_cast<double>(this_nf - 1);
131 return deltaf;
132 };
135 int nf() {
136 /* this simple formula depends upon integer truncation when used with
137 nfft as an odd number. For reference, this is what prieto uses in
138 the python multitaper package:
139 if (nfft%2 == 0):
140 nf = int(nfft/2 + 1)
141 else:
142 nf = int((nfft+1)/2)
143 they will yield the same result but this is simpler and faster
144 */
145 return (this->nfft) / 2 + 1;
146 };
147
148private:
149 int taperlen;
150 int ntapers;
151 int nfft;
152 double tbp;
153 double operator_dt;
155 /* Frequency bin interval of last data processed.*/
156 double deltaf;
157 gsl_fft_complex_wavetable *wavetable;
158 gsl_fft_complex_workspace *workspace;
159 friend boost::serialization::access;
160 template <class Archive>
161 void save(Archive &ar, const unsigned int version) const {
162 ar & taperlen;
163 ar & ntapers;
164 ar & nfft;
165 ar & tbp;
166 ar & operator_dt;
167 ar & tapers;
168 ar & deltaf;
169 }
170 template <class Archive> void load(Archive &ar, const unsigned int version) {
171 ar & taperlen;
172 ar & ntapers;
173 ar & nfft;
174 ar & tbp;
175 ar & operator_dt;
176 ar & tapers;
177 ar & deltaf;
178 this->wavetable = gsl_fft_complex_wavetable_alloc(this->nfft);
179 this->workspace = gsl_fft_complex_workspace_alloc(this->nfft);
180 }
181 BOOST_SERIALIZATION_SPLIT_MEMBER()
182};
183} // namespace mspass::algorithms::deconvolution
184#endif
Multittaper power spectral estimator.
Definition MTPowerSpectrumEngine.h:29
int number_tapers() const
Definition MTPowerSpectrumEngine.h:101
int taper_length() const
Definition MTPowerSpectrumEngine.h:97
double set_df(double dt)
Putter equivalent of df.
Definition MTPowerSpectrumEngine.h:126
MTPowerSpectrumEngine()
Definition MTPowerSpectrumEngine.cc:17
MTPowerSpectrumEngine & operator=(const MTPowerSpectrumEngine &parent)
Definition MTPowerSpectrumEngine.cc:102
std::vector< double > frequencies()
Definition MTPowerSpectrumEngine.cc:256
~MTPowerSpectrumEngine()
Definition MTPowerSpectrumEngine.cc:95
int nf()
Definition MTPowerSpectrumEngine.h:135
mspass::seismic::PowerSpectrum apply(const mspass::seismic::TimeSeries &d)
Definition MTPowerSpectrumEngine.cc:116
std::vector< double > apply(const std::vector< double > &d)
Low level processing of vector of data.
double time_bandwidth_product() const
Definition MTPowerSpectrumEngine.h:99
double df() const
Definition MTPowerSpectrumEngine.h:92
double dt()
Definition MTPowerSpectrumEngine.h:106
int fftsize() const
Definition MTPowerSpectrumEngine.h:104
Definition PowerSpectrum.h:11
Implemntation of TimeSeries for MsPASS.
Definition TimeSeries.h:14
Lightweight, simple matrix object.
Definition dmatrix.h:104