mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Calculate the average periodogram of a time-series.
Implements the overlapped average periodogram, cf. pp 843 to 845 of [18]. This produces the variance normalized 1-sided PSD estimate of the periodogram.
Optionally includes a window (by default no window is used, which is equivalent to the rectangle window).
Can also be used to calculate the unaveraged non-overlapped periodogram of the entire time series.
Example:
Definition at line 78 of file averagePeriodogram.hpp.
#include <sigproc/averagePeriodogram.hpp>
Public Member Functions | |
averagePeriodogram (size_t avgLen) | |
C'tor which sets up the optimum overlapped periodogram of the timeseries. More... | |
averagePeriodogram (size_t avgLen, realT dt) | |
C'tor which sets up the optimum overlapped periodogram of the timeseries and sets the sampling. More... | |
averagePeriodogram (size_t avgLen, size_t olap, realT dt) | |
C'tor setting up an arbitrary overlap. More... | |
~averagePeriodogram () | |
D'tor, frees all working memory. More... | |
void | dt (realT ndt) |
Set the sampling interval of the time-series. More... | |
realT | dt () |
Get the sampling interval of the time-series. More... | |
realT | df () |
Get the frequency interval of the periodogram. More... | |
int | resize (size_t avgLen) |
Resize the periodogram working memory, setting up the 1/2-overlapped optimum case. More... | |
int | resize (size_t avgLen, size_t olap) |
Resize the periodogram working memory. More... | |
std::vector< realT > & | win () |
Get a reference to the window vector. More... | |
void | win (void(*winFunc)(std::vector< realT > &)) |
Set the window vector using a function. More... | |
void | resizeWin (bool setRect=true) |
Resize the window and, unless not desired, initialize to the rectangular window by setting all 1s. More... | |
void | operator() (realT *pgram, const realT *ts, size_t sz) |
Calculate the periodogram for a time-series. More... | |
void | operator() (std::vector< realT > &pgram, const std::vector< realT > &ts) |
Calculate the periodogram for a time-series. More... | |
std::vector< realT > | operator() (std::vector< realT > &ts) |
Calculate the periodogram for a time-series. More... | |
size_t | size () |
Return the size of the periodogram. More... | |
realT | operator[] (size_t n) |
Get the frequency at a given point in the periodogram. More... | |
Protected Attributes | |
size_t | m_size {0} |
The size of the periodogram vector, calculated as m_avgLen/2 + 1;. More... | |
int | m_nOver {0} |
The number of overlapping segments. Calculated from m_avgLen and m_overlap;. More... | |
realT | m_df {1} |
The frequency sampling. This is used only for normalization and frequency scale output. More... | |
Configuration Parameters | |
size_t | m_avgLen {0} |
The number of samples in each periodgoram estimate. More... | |
size_t | m_overlap {0} |
The number of samples by which to overlap. This should almost always be 0.5*m_avgLen. Set 0 for the non-overlapped case. More... | |
realT | m_dt {1} |
The time sampling. Only used for normalization and calculation of the frequency scale. More... | |
std::vector< realT > | m_win |
The window function. By default this is empty, which is equivalent to setting it to the rectangular window. More... | |
|
explicit |
C'tor which sets up the optimum overlapped periodogram of the timeseries.
Sets m_overlap = 0.5*m_avgLen. If you desire the non-overlapped case use the alternate constructor:
[in] | avgLen | The length of averaging in samples. |
Definition at line 244 of file averagePeriodogram.hpp.
mx::sigproc::averagePeriodogram< realT >::averagePeriodogram | ( | size_t | avgLen, |
realT | dt | ||
) |
C'tor which sets up the optimum overlapped periodogram of the timeseries and sets the sampling.
Sets m_overlap = 0.5*m_avgLen. If you desire the non-overlapped case use the alternate constructor:
[in] | avgLen | The length of averaging in samples. |
[in] | dt | the sampling interval of the time-series |
Definition at line 251 of file averagePeriodogram.hpp.
mx::sigproc::averagePeriodogram< realT >::averagePeriodogram | ( | size_t | avgLen, |
size_t | olap, | ||
realT | dt | ||
) |
C'tor setting up an arbitrary overlap.
Set olap to 0 for the unoverlapped case.
[in] | avgLen | The number of samples in each periodgoram estimate. |
[in] | olap | The number of samples by which to overlap. This should almost always be 0.5*m_avgLen. Set 0 for the non-overlapped case. |
[in] | dt | the sampling interval of the time-series |
Definition at line 260 of file averagePeriodogram.hpp.
mx::sigproc::averagePeriodogram< realT >::~averagePeriodogram |
D'tor, frees all working memory.
Definition at line 270 of file averagePeriodogram.hpp.
References mx::math::fft::fftw_free().
realT mx::sigproc::averagePeriodogram< realT >::df |
Get the frequency interval of the periodogram.
Definition at line 290 of file averagePeriodogram.hpp.
realT mx::sigproc::averagePeriodogram< realT >::dt |
Get the sampling interval of the time-series.
Definition at line 284 of file averagePeriodogram.hpp.
void mx::sigproc::averagePeriodogram< realT >::dt | ( | realT | ndt | ) |
Set the sampling interval of the time-series.
This also sets the frequency scale of the output.
Definition at line 277 of file averagePeriodogram.hpp.
void mx::sigproc::averagePeriodogram< realT >::operator() | ( | realT * | pgram, |
const realT * | ts, | ||
size_t | sz | ||
) |
Calculate the periodogram for a time-series.
[out] | pgram | a pre-allocated to size() array which will be populated with the periodogram of the time-series |
[in] | ts | the time-series |
[in] | sz | the length of the time-series array |
Definition at line 356 of file averagePeriodogram.hpp.
References mx::sigproc::psdVar1sided(), and mx::math::vectorVariance().
void mx::sigproc::averagePeriodogram< realT >::operator() | ( | std::vector< realT > & | pgram, |
const std::vector< realT > & | ts | ||
) |
Calculate the periodogram for a time-series.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[out] | pgram | a vector which will be allocated and populated with the periodogram of the time-series |
[in] | ts | the time-series |
Definition at line 410 of file averagePeriodogram.hpp.
std::vector< realT > mx::sigproc::averagePeriodogram< realT >::operator() | ( | std::vector< realT > & | ts | ) |
Calculate the periodogram for a time-series.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | ts | the time-series |
Definition at line 420 of file averagePeriodogram.hpp.
realT mx::sigproc::averagePeriodogram< realT >::operator[] | ( | size_t | n | ) |
Get the frequency at a given point in the periodogram.
[in] | n | the point in the periodogram at which the frequency is desired |
Definition at line 434 of file averagePeriodogram.hpp.
int mx::sigproc::averagePeriodogram< realT >::resize | ( | size_t | avgLen | ) |
Resize the periodogram working memory, setting up the 1/2-overlapped optimum case.
This sets the overlap to 0.5*avgLen.
Also performs fft planning.
[in] | avgLen | The number of samples in each periodgoram estimate. |
Definition at line 297 of file averagePeriodogram.hpp.
int mx::sigproc::averagePeriodogram< realT >::resize | ( | size_t | avgLen, |
size_t | olap | ||
) |
Resize the periodogram working memory.
Also performs fft planning.
[in] | avgLen | The number of samples in each periodgoram estimate. |
[in] | olap | The number of samples by which to overlap. This should almost always be 0.5*m_avgLen. Set 0 for the non-overlapped case. |
Definition at line 303 of file averagePeriodogram.hpp.
References mx::math::fft::fftw_free().
void mx::sigproc::averagePeriodogram< realT >::resizeWin | ( | bool | setRect = true | ) |
Resize the window and, unless not desired, initialize to the rectangular window by setting all 1s.
If setRect=false
then the window is not initialized.
[in] | setRect | [optional] if false, then the window is not initialized to 1 |
Definition at line 343 of file averagePeriodogram.hpp.
size_t mx::sigproc::averagePeriodogram< realT >::size |
Return the size of the periodogram.
Definition at line 428 of file averagePeriodogram.hpp.
Referenced by mx::AO::analysis::speckleAmpPSD().
std::vector< realT > & mx::sigproc::averagePeriodogram< realT >::win |
Get a reference to the window vector.
This allows population of the window with any arbitrary function. You should call resizeWin() before using this to make sure that the vector has the correct length.
Definition at line 330 of file averagePeriodogram.hpp.
void mx::sigproc::averagePeriodogram< realT >::win | ( | void(*)(std::vector< realT > &) | winFunc | ) |
Set the window vector using a function.
This will resize m_win, and then call the function with m_win as the argument. For example to use the hann window defined signal_windows1D:
which will set the Hann window.
[in] | winFunc | pointer to a function which takes a pre-allocated vector and fills it in with a window function |
Definition at line 336 of file averagePeriodogram.hpp.
|
protected |
The number of samples in each periodgoram estimate.
Definition at line 88 of file averagePeriodogram.hpp.
|
protected |
The frequency sampling. This is used only for normalization and frequency scale output.
Definition at line 101 of file averagePeriodogram.hpp.
|
protected |
The time sampling. Only used for normalization and calculation of the frequency scale.
Definition at line 91 of file averagePeriodogram.hpp.
|
protected |
The number of overlapping segments. Calculated from m_avgLen and m_overlap;.
Definition at line 99 of file averagePeriodogram.hpp.
|
protected |
The number of samples by which to overlap. This should almost always be 0.5*m_avgLen. Set 0 for the non-overlapped case.
Definition at line 89 of file averagePeriodogram.hpp.
|
protected |
The size of the periodogram vector, calculated as m_avgLen/2 + 1;.
Definition at line 97 of file averagePeriodogram.hpp.
|
protected |
The window function. By default this is empty, which is equivalent to setting it to the rectangular window.
Definition at line 93 of file averagePeriodogram.hpp.