Compute data spectra. More...
#include <Spectrum.h>
Public Member Functions | |
TGraph * | GetASD (void) |
Returns the current ASD as a TGraph. | |
double | GetPower (const double aFrequency) |
Returns the power value at a given frequency. | |
TGraph * | GetPSD (void) |
Returns the current PSD as a TGraph. | |
bool | GetStatus (void) |
Returns class status. | |
bool | LoadData (const int aDataSize, double *aData) |
Loads a data vector and computes the PSD. | |
Constructors and destructors | |
Spectrum (const int aSamplingFrequency, const int aNpoints, const int aPaddingDuration, const int aVerbosity=0) | |
Constructor of the Spectrum class. | |
virtual | ~Spectrum (void) |
Destructor of the Spectrum class. |
Compute data spectra.
This class was designed to compute the power spectrum of a given stretch of data. It uses the median-mean method described in gr-qc/0509116. This method can be represented by the cartoon below:
|----------------------------------------| input data vector (time domain) |//| |//| padding |---|---|---|---|---|---|---|---| N even subsegments |---|---|---|---|---|---|---| N-1 odd subsegments
After removing pads at both ends of the input data vector, the remaining data is divided in 2N-1 overlapping subsegments (N is determined by the requested frequency resolution of the PSD). Each subsegment is hann-windowed and FFTed to get 2N-1 power spectra. The median PSDs are computed for odd and even subsegments independently. The 2 PSDs are finally averaged into one.
For this method to work properly, N should be at least 2.
Spectrum::Spectrum | ( | const int | aSamplingFrequency, | |
const int | aNpoints, | |||
const int | aPaddingDuration, | |||
const int | aVerbosity = 0 | |||
) |
Constructor of the Spectrum class.
It defines the vector sizes and initiates the FFT plan. Half of the padding duration is removed at both ends; therefore, this number must be an even number.
aSamplingFrequency | input data sampling frequency [Hz] | |
aNpoints | number of points in the spectrum | |
aPaddingDuration | padding duration [s] | |
averbose | verbosity level |
virtual Spectrum::~Spectrum | ( | void | ) | [virtual] |
Destructor of the Spectrum class.
TGraph* Spectrum::GetASD | ( | void | ) |
Returns the current ASD as a TGraph.
The returned TGraph must be deleted by the user.
double Spectrum::GetPower | ( | const double | aFrequency | ) |
Returns the power value at a given frequency.
The LoadData() function must be called before using this function. The power value, is computed by linearly interpolating the PSD if the requested frequency in inside the PSD frequency range. If it is outside this range, the PSD is linearly extrapolated using the last 2 points in the range. If the extrapolation leads to a negative value, the power is forced to 0.0.
-1.0 is returned if this function fails.
If this function is called many times in a row, it is more optimal if the requested frequencies are called in a sorted order (increasing or decreasing).
aFrequency | frequency value [Hz] |
TGraph* Spectrum::GetPSD | ( | void | ) |
Returns the current PSD as a TGraph.
The returned TGraph must be deleted by the user.
bool Spectrum::GetStatus | ( | void | ) | [inline] |
Returns class status.
bool Spectrum::LoadData | ( | const int | aDataSize, | |
double * | aData | |||
) |
Loads a data vector and computes the PSD.
The data vector 'aData' (time domain) is used to compute the PSD. The user must specify the size of this vector and make sure it is correct since no check will be performed.
The input data vector must be long enough to perform the median-mean method. It means, that after removing the padding, the remaining data must be long enough to contain at least 2 PSD stretches:
data size - padding size >= 2*aNpoints
aDataSize | input vector size | |
aData | input data vector (time domain) |