Commit 4fb82fc9 authored by thomas.forbriger's avatar thomas.forbriger
Browse files

croposp [WP][FEATURE]: compute PSD

parent b71e0bdc
......@@ -236,11 +236,16 @@ noisymize: \
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@ \
$(LIBTSIOXX)
croposp cross fregra foutra deconv: \
cross fregra foutra deconv: \
%: %.o
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@ \
-lfourierxx $(LIBTSIOXX) -lfftw3
croposp: \
%: %.o
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@ \
-lpsdxx -lfourierxx $(LIBTSIOXX) -lfftw3
soutifu: \
%: %.o
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@ \
......
......@@ -43,6 +43,7 @@
#include <tfxx/stringfunc.h>
#include <tsioxx/cmdlinefiles.h>
#include <tsxx/tscollection.h>
#include <psdxx/psd.h>
using std::cout;
using std::cerr;
......@@ -69,6 +70,15 @@ typedef ts::TimeSeriesCollection<double> TCollection;
// a vector to gold meta data for each time series
typedef std::vector<Meta> TMetaVector;
// a struct to hold computation results for exactly one series
struct NamedSeries {
std::string label;
psd::TDseries series;
}; // struct NamedSeries
// a vector type to hold results
typedef std::vector<NamedSeries> TNamedSeriesVector;
/* ====================================================================== */
// define usage information
......@@ -379,6 +389,64 @@ int main(int iargc, char* argv[])
TFXX_assert(!opt.compute_transfer, "-transfer is not yet implemented");
TFXX_assert(!opt.compute_coherency, "-coherency is not yet implemented");
// provide container for frequency values (will be filled upon computation
// of PSD values)
psd::TDseries frequencies;
/* ---------------------------------------------------------------------- */
/* compute power spectral density
* ------------------------------
*/
// provide container for PSD values
TNamedSeriesVector PSD_vector;
if (opt.compute_psd || opt.compute_npsd || opt.compute_transfer ||
opt.compute_coherency)
{
psd::DPSDComputer psd_computer;
TCollection::const_iterator i_series=collection_of_series.begin();
TMetaVector::const_iterator i_meta=vector_of_metadata.begin();
while (i_series != collection_of_series.end() &&
i_meta != vector_of_metadata.end())
{
psd::TDISeries interval_series;
interval_series.data=*i_series;
interval_series.interval=i_series->header.dt;
psd::TDISeries psd=psd_computer.psd(interval_series);
if (i_series==collection_of_series.begin())
{
if (opt.logscale)
{
frequencies=psd::log_frequency(psd.interval, psd.data.size(),
opt.n_per_decade);
}
else
{
frequencies=psd::lin_frequency(psd.interval, psd.data.size());
} // if (opt.logscale) ... else
} // if (i_series==collection_of_series.begin())
NamedSeries named_psd;
if (opt.logscale)
{
named_psd.series=psd::log_sampling(psd, frequencies);
} // if (opt.logscale)
else
{
named_psd.series=psd.data;
} // if (opt.logscale) ... else
named_psd.label=i_meta->label;
PSD_vector.push_back(named_psd);
++i_series;
++i_meta;
} // while (i_series != collection_of_series.end() &&
// i_meta != vector_of_metadata.end())
} // if (opt.compute_psd)
} // main()
/* ----- END OF croposp.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment