TimeFrequency.h
Go to the documentation of this file.00001 #ifndef TIMEFREQUENCY_H_
00002 #define TIMEFREQUENCY_H_
00003 #include <complex>
00004 #include "TsSpectrum.h"
00005 #include "statutils.h"
00006 #include "VecMat.h"
00007 #include "FatalException.h"
00008
00009 namespace gplib
00010 {
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 template<typename InputIterator, typename WindowFunctype>
00023 gplib::cmat TimeFrequency(InputIterator tsbegin, InputIterator tsend,
00024 const size_t seglength, WindowFunctype WFunc)
00025 {
00026 const size_t insize = distance(tsbegin, tsend);
00027 if (insize < seglength)
00028 throw FatalException(
00029 "Time Series shorter than requested segment length");
00030 const unsigned int nsegments = insize / seglength;
00031 const unsigned int speclength = seglength / 2 + 1;
00032 TsSpectrum SpecEst(false);
00033 gplib::cmat output(nsegments, speclength);
00034 typedef std::vector<
00035 typename std::iterator_traits<InputIterator>::value_type> tinvector;
00036
00037 InputIterator currstart = tsbegin;
00038 InputIterator currend = tsbegin;
00039 advance(currend, seglength);
00040
00041 std::vector<std::complex<double> > segspec(speclength);
00042 for (unsigned int i = 0; i < nsegments; ++i)
00043 {
00044 tinvector currseg(currstart, currend);
00045 SubMean(currseg.begin(), currseg.end());
00046 for (typename tinvector::iterator it = currseg.begin(); it
00047 != currseg.end(); ++it)
00048 {
00049
00050 *it *= WFunc(
00051 static_cast<double> (distance(currseg.begin(), it))
00052 / seglength);
00053 }
00054 SpecEst.CalcSpectrum(currseg.begin(), currseg.end(),
00055 segspec.begin(), segspec.end());
00056 copy(segspec.begin(), segspec.end(), row(output, i).begin());
00057 advance(currstart, seglength);
00058 advance(currend, seglength);
00059 }
00060 return output;
00061 }
00062
00063 }
00064 #endif