version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
PowerSpectrum.h
1#ifndef _POWER_SPECTRUM_H_
2#define _POWER_SPECTRUM_H_
3#include "mspass/seismic/BasicSpectrum.h"
4#include "mspass/utility/ErrorLogger.h"
5#include "mspass/utility/Metadata.h"
6#include "mspass/utility/MsPASSError.h"
7#include <vector>
8namespace mspass::seismic {
12public:
18 std::string spectrum_type;
20 std::vector<double> spectrum;
45 template <class T>
46 PowerSpectrum(const mspass::utility::Metadata &md, const std::vector<T> &d,
47 const double dfin, const std::string nm, const double f0in,
48 const double dtin, const int npts_in);
49 PowerSpectrum(const PowerSpectrum &parent);
50 PowerSpectrum &operator=(const PowerSpectrum &parent);
65 std::vector<double> amplitude() const;
76 double power(const double f) const;
77
78 double frequency(const int sample_number) const {
79 const std::string base_error("PowerSpectrum::frequency: ");
80 if (sample_number < 0)
82 base_error + "Sample number parameter passed cannot be negative");
83 if (sample_number >= (this->nf()))
85 base_error +
86 "Sample number parameter passed xceeds range of spectrum array");
87 return this->f0() + sample_number * this->df();
88 };
89 std::vector<double> frequencies() const;
90 /* \brief Return number of frequencies in estimate (size of spectrum vector).
91
92 Users should be aware that when zero padding is used the size of the
93 spectrum vector will be larger than half the number of time series samples.*/
94 size_t nf() const { return spectrum.size(); };
96 double Nyquist() const { return 1.0 / (2.0 * this->parent_dt); };
97};
104template <class T>
106 const std::vector<T> &d, const double dfin,
107 const std::string nm, const double f0in,
108 const double dtin, const int npts_in)
109 : BasicSpectrum(dfin, f0in, dtin, npts_in), mspass::utility::Metadata(md),
110 elog() {
111 spectrum_type = nm;
112 spectrum.reserve(d.size());
113 for (size_t k = 0; k < d.size(); ++k)
114 spectrum.push_back(static_cast<double>(d[k]));
115 this->set_live();
116};
117} // namespace mspass::seismic
118#endif
Definition BasicSpectrum.h:19
int sample_number(const double f) const
Definition BasicSpectrum.h:124
void set_live()
Definition BasicSpectrum.h:91
double df() const
Definition BasicSpectrum.h:93
double f0() const
Definition BasicSpectrum.h:98
Definition PowerSpectrum.h:11
std::vector< double > frequencies() const
Definition PowerSpectrum.cc:90
double power(const double f) const
power at a given frequency.
Definition PowerSpectrum.cc:74
size_t nf() const
Definition PowerSpectrum.h:94
PowerSpectrum()
Definition PowerSpectrum.cc:10
PowerSpectrum & operator+=(const PowerSpectrum &other)
Standard accumulation operator.
Definition PowerSpectrum.cc:30
mspass::utility::ErrorLogger elog
Definition PowerSpectrum.h:26
std::vector< double > spectrum
Definition PowerSpectrum.h:20
std::vector< double > amplitude() const
Compute amplitude spectrum from power spectrum.
Definition PowerSpectrum.cc:67
double frequency(const int sample_number) const
Definition PowerSpectrum.h:78
double Nyquist() const
Definition PowerSpectrum.h:96
std::string spectrum_type
Definition PowerSpectrum.h:18
Container to hold error logs for a data object.
Definition ErrorLogger.h:60
Definition Metadata.h:71
Base class for error object thrown by MsPASS library routines.
Definition MsPASSError.h:38
Define metadata keys.
Definition BasicSpectrum.h:6