version
0.0.1
Defines the C++ API for MsPASS
|
Multittaper power spectral estimator. More...
#include <MTPowerSpectrumEngine.h>
Public Member Functions | |
MTPowerSpectrumEngine () | |
MTPowerSpectrumEngine (const int winsize, const double tbp, const int ntapers, const int nfftin=-1, const double dtin=1.0) | |
construct with full definition. | |
MTPowerSpectrumEngine (const MTPowerSpectrumEngine &parent) | |
~MTPowerSpectrumEngine () | |
MTPowerSpectrumEngine & | operator= (const MTPowerSpectrumEngine &parent) |
mspass::seismic::PowerSpectrum | apply (const mspass::seismic::TimeSeries &d) |
std::vector< double > | apply (const std::vector< double > &d) |
Low level processing of vector of data. | |
double | df () const |
std::vector< double > | frequencies () |
int | taper_length () const |
double | time_bandwidth_product () const |
int | number_tapers () const |
int | fftsize () const |
double | dt () const |
double | set_df (double dt) |
Putter equivalent of df. | |
int | nf () |
Multittaper power spectral estimator.
The multitaper method uses averages of spectra windowed by Slepian functions. This class can be used to compute power spectra. For efficiency the design has constructors that build the Slepian functions and cache them in a private area. We use this model because computing spectra on a large data set in parallel will usually be done with a fixed time window. The expected use is that normally the engine is created once and passed as an argument to functions using it in a map operator.
This class uses the apply model for processing. It accepts raw vector or TimeSeries data. The former assumes the sample interval is 1 while the second scales the spectrum to have units of 1/Hz.
mspass::algorithms::deconvolution::MTPowerSpectrumEngine::MTPowerSpectrumEngine | ( | ) |
Default constructor. Do not use as it produces a null object that is no functional.
mspass::algorithms::deconvolution::MTPowerSpectrumEngine::MTPowerSpectrumEngine | ( | const int | winsize, |
const double | tbp, | ||
const int | ntapers, | ||
const int | nfftin = -1 , |
||
const double | dtin = 1.0 |
||
) |
construct with full definition.
This should be the normal constructor used to create this object. It creates and caches the Slepian tapers that are used on calls the apply method.
winsize | is the length of time windows in samples the operator will be designed to compute. |
tbp | is the time bandwidth product to use for the operator. |
ntapers | is the number of tapers to actually use for the operator. Note the maximum ntapers is always int(tbp*2). If ntapers is more than 2*tbp a mesage will be posted to cerr and ntapers set to tbp*2. |
nfftin | is the size of the fft workspace to use for computation. When less than the winsize (the default forces this) set to 2*winsize+1. |
dtin | sets the operator sample interval stored in the object and used to compute frequency bin size from fft length. |
References set_df().
mspass::algorithms::deconvolution::MTPowerSpectrumEngine::MTPowerSpectrumEngine | ( | const MTPowerSpectrumEngine & | parent | ) |
Standard copy constructor
mspass::algorithms::deconvolution::MTPowerSpectrumEngine::~MTPowerSpectrumEngine | ( | ) |
Destructor. Not trivial as it has to delete the fft workspace and cached tapers.
PowerSpectrum mspass::algorithms::deconvolution::MTPowerSpectrumEngine::apply | ( | const mspass::seismic::TimeSeries & | d | ) |
\process a TimeSeries.
This is one of two methods for applying the multiaper algorithm to data. This one uses dt and data length to set the Rayleigh bin size (df). If the input data vector length is not the same as the operator length an elog complaint is posted to parent. Short data are processed but should be considered suspect unless the sizes differ by only a tiny fraction (e.g. and off by one error from rounding). Long data will be truncated on the right (i.e. sample 0 will be the start of the window used). The data return will be scaled to psd in units if 1/Hz.
parent | is the data to process |
References apply(), mspass::seismic::BasicTimeSeries::dt(), mspass::seismic::PowerSpectrum::elog, mspass::seismic::BasicSpectrum::kill(), mspass::utility::ErrorLogger::log_error(), mspass::seismic::BasicTimeSeries::npts(), and mspass::seismic::CoreTimeSeries::s.
std::vector< double > mspass::algorithms::deconvolution::MTPowerSpectrumEngine::apply | ( | const std::vector< double > & | d | ) |
Low level processing of vector of data.
This is lower level function that processes a raw vector of data. Since it does not know the sample interval it cannot compute the rayleigh bin size so if callers need that feature they must do that (simple) calculation themselves. Unlike the TimeSeries method this one will throw an exception if the input data size does not match the operator size. It returns power spectral density assuming a sample rate of 1. i.e. it scales to correct for the gsl fft scaling by of the forward transform by N.
d | is the vector of data to process. d.size() must this->taperlen() value. |
throw | a MsPASSError if the size of d does not match operator length |
|
inline |
Return the frquency bin size defined for this operator.
|
inline |
Retrieve the internally cached required data sample interval.
|
inline |
Return size of fft used by this operator - usually not the same as taper length.
vector< double > mspass::algorithms::deconvolution::MTPowerSpectrumEngine::frequencies | ( | ) |
Return and std::vector of all frequencies for spectral estimates this operator computes.
References nf().
|
inline |
Return tne number of frequency bins in estimates the operator will compute.
|
inline |
Return number of tapers used by this engine.
MTPowerSpectrumEngine & mspass::algorithms::deconvolution::MTPowerSpectrumEngine::operator= | ( | const MTPowerSpectrumEngine & | parent | ) |
Standard assignment operator.
|
inline |
Putter equivalent of df.
The computation of the Rayleigh bin size is complicated a bit by the folding properties of fft algorithms that have to handle odd and even length inputs differently. This algorithm uses the internally set nfft value to set the frequency bin size for even or odd nfft and the input sample interval. NOTE POSSIBLE CONFUSION that input is time sample interval NOT the actual frquency bin size. The reason is that the odd/even issue makes df dependent on if the fft size is even or odd. We include this method as a convenience as that is an implementation detail for the fft algorithm.
Note also this method sets not just df but the internally stored sample interval (symbol operator_dt in the source code.)
dt | is the data sample interval (time domain) |
|
inline |
Retrieve the taper length.
|
inline |
Retrieve time-bandwidth product.