GCpp general purpose C++ library
version 1.0
|
#include <GBaseSampleFFT.hh>
Public Member Functions | |
GBaseSampleFFT (u_int n=0, double dt=1.L) | |
GBaseSampleFFT (const GBaseSampleFFT &original) | |
GBaseSampleFFT & | operator= (const GBaseSampleFFT &original) |
virtual | ~GBaseSampleFFT () |
virtual void | ResetData () |
virtual void | ClearData () |
virtual u_int | InitData (u_int n, double dt=1.L, bool clear=true) |
virtual int | ResizeData (u_int n) |
virtual void | InitFunctionData (u_int n, const double data[])=0 |
virtual void | InitTransformData (u_int n, const double data[])=0 |
virtual void | InitTransformData (u_int n, const double data_re[], const double data_im[])=0 |
virtual void | SetFunctionValue (u_int i, double val)=0 |
virtual void | SetTransformValue (u_int i, double re, double im=0.L)=0 |
virtual void | SetFFTValue (u_int i, double re, double im=0.L)=0 |
virtual int | ComputeTransformData ()=0 |
virtual int | ComputeFunctionData ()=0 |
virtual void | Normalise (double s=1.L)=0 |
virtual void | Scale (double s) |
virtual double | GetSumSquared (bool f=false) |
bool | IsDefined () const |
bool | IsFunctionSet () const |
bool | IsTransformSet () const |
void | FunctionSet (bool b=true) |
void | TransformSet (bool b=true) |
int | GetDataType () const |
u_int | GetSamplesNumber () const |
u_int | GetDimension () const |
bool | HasSameSampling (const GBaseSampleFFT &sample, double prec=0.0001) const |
virtual int | SetTimeRange (double t_lo, double t_up, bool ctr=false) |
virtual double | GetTimeMin () const |
virtual double | GetTimeMax () const |
virtual double | GetTimeEnd () const |
virtual double | GetTimeStep () const |
virtual double | GetCriticalFrequency () const |
virtual double | GetFrequencyMax () const |
virtual double | GetFrequencyStep () const |
double * | GetFunctionData (bool check=true) |
double * | GetTransformData (bool check=true) |
double * | CopyFunctionData () const |
double * | CopyTransformData () const |
double * | CreatePowerSpectralDensity () |
double * | CreatePSD () |
virtual int | Write (const string &fname) |
virtual int | Write (FILE *fp) |
virtual int | Read (const string &fname) |
virtual int | Read (FILE *fp) |
Protected Member Functions | |
virtual int | WriteHeader (FILE *fp) |
virtual int | ReadHeader (FILE *fp) |
void | CopyData (const GBaseSampleFFT &original) |
Protected Attributes | |
int | data_type |
0=undefined; 1=real; 2=complex | |
u_int | samples_number |
Number of data samples. | |
u_int | samples_dim |
Effective arrays dimension (power of 2) | |
u_int | alloc_dim |
Effective allocated dim. | |
double * | data_array |
Array of function samples. | |
double * | fft_array |
Array of Fourier transform data. | |
bool | data_set |
Indicate if the data samples are set. | |
bool | fft_set |
Indicate if the FFT data are set. | |
double | time_min |
Time of the first sample. | |
double | time_max |
Time of the last sample (after padding with zeros) | |
double | time_end |
Time of the last (defined) sample (before padding) | |
double | time_step |
Time step. | |
double | freq_step |
Frequency step. | |
double | freq_crit |
Frequency maximum value (Nyquist critical frequency) | |
Static Protected Attributes | |
static double | epsilon = 1.e-30L |
Limit for 0 checking. | |
static string | data_type_name [3] = { "undefined", "real", "complex" } |
Names of the data types. | |
Private Member Functions | |
GObjectV (GBaseSampleFFT) | |
This class defines a base class to manage data samples and the corresponding Fourier transform.
The data are processed as real numbers with the FFT functions using the Danielson-Lanczos algorithm (see Danielson-Lanczos algorithm for FFT). Thus, the arrays (sample and Fourier transform) sizes depend whether the function is a real or a complex function.
The FFT algorithm works with dimensions N=2^k (power of two), so if the data dimension is not a power of 2, it is padded with zeros. It is anyway suggested to use samples with a dimension that is a power of 2.
In order to reduce computation time, the Fourier transform and/or the function samples are only computed when required. The status for the 2 data arrays (function samples and Fourier transform data) is defined by 2 boolean variables: data_set and fft_set.
GBaseSampleFFT::GBaseSampleFFT | ( | u_int | n = 0 , |
double | dt = 1.L |
||
) |
Base constructor. If the number of samples data is defined, the arrays are initialised. The time step is used to initialise the effective time range, starting at t = 0 for the first sample.
n | number of function samples |
dt | sampling time step |
References alloc_dim, data_array, data_set, data_type, fft_array, fft_set, freq_crit, freq_step, GDebugConst, GGetString(), InitData(), samples_dim, samples_number, time_end, time_max, time_min, and time_step.
GBaseSampleFFT::GBaseSampleFFT | ( | const GBaseSampleFFT & | original | ) |
Copy constructor.
original | object to be copied |
References alloc_dim, CopyData(), data_array, data_set, fft_array, fft_set, GDebugConst, samples_dim, and samples_number.
|
virtual |
Destructor: cleans-up the data.
References GDebugDest, and ResetData().
|
virtual |
Fonctions that fills the function and the FFT samples with zeros.
References data_array, data_set, fft_array, fft_set, GDebugClass, and samples_dim.
Referenced by InitData().
|
pure virtual |
Compute the inverse Fourier transform (function samples) from the Fourier transform data that are currently stored in the object. The function returns 0 if no error occured (dimensions and arrays are defined, ...).
Implemented in GRealSampleFFT.
Referenced by GetFunctionData(), GetSumSquared(), ResizeData(), and Write().
|
pure virtual |
Compute the Fourier transform from the function samples that are currently stored in the object. The function returns 0 if no error occured (dimensions and arrays are defined, ...).
Implemented in GRealSampleFFT.
Referenced by CreatePowerSpectralDensity(), GetSumSquared(), and GetTransformData().
|
protected |
This function copies the data from original to the current object. The current data should have been resetted before (this is not checked here). It is not a virtual function, and it copies only the part corresponding to this stage of the heritance tree.
original | object to be copied |
References alloc_dim, data_array, data_set, fft_array, fft_set, freq_crit, freq_step, GDebugClass, GetSamplesNumber(), GGetString(), samples_dim, samples_number, time_end, time_max, time_min, and time_step.
Referenced by GBaseSampleFFT(), GRealSampleFFT::GRealSampleFFT(), GRealSampleFFT::operator=(), and operator=().
double * GBaseSampleFFT::CopyFunctionData | ( | ) | const |
Allocate and create a copy of the function samples data. If the data are not defined, the function returns a NULL pointer. The returned array must be destroyed by the calling program.
References data_array, IsDefined(), and samples_dim.
double * GBaseSampleFFT::CopyTransformData | ( | ) | const |
Allocate and create a copy of the Forier transform data. If the data are not defined, the function returns a NULL pointer. The returned array must be destroyed by the calling program.
References fft_array, IsDefined(), and samples_dim.
double * GBaseSampleFFT::CreatePowerSpectralDensity | ( | ) |
Create an array of N/2+1 data with the power spectral density. The array must be deleted by the calling function.
References ComputeTransformData(), fft_array, fft_set, GDebugClass, and GetDimension().
Referenced by CreatePSD().
|
inline |
Create an array of N/2+1 data with the power spectral density. The array must be deleted by the calling function.
References CreatePowerSpectralDensity().
|
inline |
Force the function sample to be considered as defined (or undefined).
b | function sample set value |
References data_set.
Referenced by GRealSampleFFT::Derivate(), GRealSampleFFT::DoubleSymmetric(), GRealSampleFFT::HalfDivide(), GRealSampleFFT::Integrate(), GRealSampleFFT::operator*(), GRealSampleFFT::operator*=(), GRealSampleFFT::operator+(), GRealSampleFFT::operator+=(), GRealSampleFFT::operator-(), and GRealSampleFFT::operator-=().
|
inlinevirtual |
Return the Nyquist critical frequency of the Fourier discrete transform (maximum frequency).
References freq_crit.
Referenced by GetFrequencyMax().
|
inline |
Return the identifier of the type of data (real / complex) of the sample.
References data_type.
Referenced by HasSameSampling().
|
inline |
Function returning the effective dimension of data arrays in terms of double real data.
References samples_dim.
Referenced by CreatePowerSpectralDensity(), GetSumSquared(), HasSameSampling(), GRealSampleFFT::SetConvolution(), and GRealSampleFFT::SetProduct().
|
inlinevirtual |
Return the maximum frequency (critical) of the Fourier discrete transform.
References GetCriticalFrequency().
|
inlinevirtual |
Return the frequency step of the Fourier discrete transform.
References freq_step.
|
inline |
Returns pointer to the function samples. If check argument is true (default value), the functions checks if data must be recomputed before returning the result. The argument should be set to false to reduce computation time if the data does not need to contain valid data.
If the function is filled this way, the flag indicating that data is set must be updated (see FunctionSet).
check | indicate to check for recomputing of data |
References ComputeFunctionData(), data_array, and data_set.
Referenced by GExtremaFinder::Analyse(), GExtremaFinder::AnalyseMaxima(), GRealSampleFFT::Derivate(), GRealSampleFFT::Integrate(), GRealSampleFFT::operator*(), GRealSampleFFT::operator*=(), GRealSampleFFT::operator+(), GRealSampleFFT::operator+=(), GRealSampleFFT::operator-(), GRealSampleFFT::operator-=(), GRealSampleFFT::SetProduct(), and GRealSampleFFT::SetTimeResponse().
|
inline |
Returns the number of data samples (independant of the data type) of the function.
References samples_number.
Referenced by GExtremaFinder::Analyse(), GExtremaFinder::AnalyseMaxima(), CopyData(), GRealSampleFFT::Derivate(), GRealSampleFFT::GetMaximum(), GRealSampleFFT::GetMaximumIndex(), GRealSampleFFT::GetMinimum(), GRealSampleFFT::GetMinimumIndex(), GRealSampleFFT::GetRMS(), GRealSampleFFT::GetSum(), GetSumSquared(), GExtremaFinder::InitData(), GRealSampleFFT::Integrate(), GRealSampleFFT::InterpolateFrom(), GRealSampleFFT::operator+(), GRealSampleFFT::operator+=(), GRealSampleFFT::operator-(), GRealSampleFFT::operator-=(), GRealSampleFFT::SetConvolution(), and GRealSampleFFT::SetTimeResponse().
|
virtual |
Return the total power of the sample (sum squared amplitude).
f | indicates if calculation is done in frequency space (default is time), but the result is the same... |
References ComputeFunctionData(), ComputeTransformData(), data_array, data_type, fft_array, GetDimension(), GetSamplesNumber(), IsFunctionSet(), and IsTransformSet().
Referenced by GRealSampleFFT::GetPower().
|
inlinevirtual |
Return the upper time limit of the function samples.
References time_end.
Referenced by GRealSampleFFT::InterpolateFrom(), and GRealSampleFFT::SetTimeResponse().
|
inlinevirtual |
Return the max time limit of the function samples (after padding with zeros for a dimension as a power of 2).
References time_max.
|
inlinevirtual |
Return the lower time limit of the function samples.
References time_min.
Referenced by GRealSampleFFT::Derivate(), GRealSampleFFT::Integrate(), GRealSampleFFT::InterpolateFrom(), ResizeData(), GRealSampleFFT::SetConvolution(), and GRealSampleFFT::SetTimeResponse().
|
inlinevirtual |
Return the time step of the function sampling.
References time_step.
Referenced by GExtremaFinder::Analyse(), GExtremaFinder::AnalyseMaxima(), GRealSampleFFT::Derivate(), GExtremaFinder::DifferentialThreshold(), GRealSampleFFT::GetIntegral(), GRealSampleFFT::GetPower(), HasSameSampling(), GRealSampleFFT::Integrate(), GRealSampleFFT::InterpolateFrom(), ResizeData(), GRealSampleFFT::SetConvolution(), GRealSampleFFT::SetProduct(), and GRealSampleFFT::SetTimeResponse().
|
inline |
Returns pointer to the function samples. If check argument is true (default value), the functions checks if data must be recomputed before returning the result. The argument should be set to false to reduce computation time if the data does not need to contain valid data.
If the transform is filled this way, the flag indicating that fft is set must be updated (see TransformSet).
check | indicate to check for recomputing of data |
References ComputeTransformData(), fft_array, and fft_set.
Referenced by GRealSampleFFT::SetConvolution().
|
private |
Macro from GCpp library that defines the following functions:
bool GBaseSampleFFT::HasSameSampling | ( | const GBaseSampleFFT & | sample, |
double | prec = 0.0001 |
||
) | const |
Check if the sample has sampling sampling parameters than the argument: number of data and time step.
sample | sample to be compared |
prec | precision for time step comparison |
References GetDataType(), GetDimension(), and GetTimeStep().
Referenced by GRealSampleFFT::SetProduct().
This function (re)allocates the arrays for the sample and the FFT if the sample dimension has changed.
The given size n corresponds to the number of data samples. For real data it is the effective data array size, while for complex data, the effective allocated array size is
2*n.
If n is not a power of 2, the real allocated size (that is returned by the function) is the smallest power of 2 bigger than n.
The arrays are initialised with zeros if the clear argument is true. Both the function data and the Fourier transform are considered as defined, since they correspond to each other !
n | requested size of arrays |
dt | sampling time step |
clear | indicate if the data have to be cleared |
References alloc_dim, ClearData(), data_array, data_type, fft_array, GDebugClass, GFFTCheckDim(), GFFTGetPower2Dim(), GGetString(), GLogWarning(), ResetData(), samples_dim, samples_number, and SetTimeRange().
Referenced by GRealSampleFFT::Derivate(), GRealSampleFFT::DoubleSymmetric(), GBaseSampleFFT(), GRealSampleFFT::HalfDivide(), GRealSampleFFT::InitFunctionData(), GRealSampleFFT::InitTransformData(), GRealSampleFFT::Integrate(), GRealSampleFFT::InterpolateFrom(), GRealSampleFFT::operator*(), GRealSampleFFT::operator+(), GRealSampleFFT::operator-(), ReadHeader(), GRealSampleFFT::SetConvolution(), GRealSampleFFT::SetProduct(), and GRealSampleFFT::SetTimeResponse().
|
pure virtual |
Pure virtual function that must be defined in derived classes to fill the function samples data from an array.
n | number of data (expressed in real) |
data | data array |
Implemented in GRealSampleFFT.
|
pure virtual |
Pure virtual function that must be defined in derived classes to fill the Fourier transform data from an array of real numbers. The array must be sorted in the following order: Re[0], Im[0], Re[1], Im[1], ... Re[n/2-1], Imsee GFFTComplex, GFFTReal, ... "n/2-1".
n | number of data (expressed in real) |
data | data array |
Implemented in GRealSampleFFT.
|
pure virtual |
Pure virtual function that must be defined in derived classes to fill the Fourier transform data from 2 arrays of real numbers: 1 for the real terms of the Fourier transform, 1 for the imaginary terms.
n | number of complex numbers data |
data_re | array for real part of data |
data_im | array for imaginary part of data |
Implemented in GRealSampleFFT.
|
inline |
Returns true if the function samples and the FFT have been created.
References data_array, fft_array, and samples_dim.
Referenced by CopyFunctionData(), CopyTransformData(), GRealSampleFFT::InterpolateFrom(), GRealSampleFFT::operator*(), GRealSampleFFT::operator*=(), GRealSampleFFT::operator+(), GRealSampleFFT::operator+=(), ResizeData(), GRealSampleFFT::SetConvolution(), GRealSampleFFT::SetProduct(), and GRealSampleFFT::SetTimeResponse().
|
inline |
Returns true if the function samples are set.
References data_set.
Referenced by GRealSampleFFT::ComputeTransformData(), GRealSampleFFT::Derivate(), GRealSampleFFT::DoubleSymmetric(), GetSumSquared(), GRealSampleFFT::HalfDivide(), GRealSampleFFT::Integrate(), ResizeData(), GRealSampleFFT::SetConvolution(), GRealSampleFFT::SetProduct(), GRealSampleFFT::SetTimeResponse(), and Write().
|
inline |
Returns true if the FFT data are set.
References fft_set.
Referenced by GRealSampleFFT::ComputeFunctionData(), GRealSampleFFT::DoubleSymmetric(), GetSumSquared(), GRealSampleFFT::HalfDivide(), ResizeData(), GRealSampleFFT::SetConvolution(), GRealSampleFFT::SetProduct(), and GRealSampleFFT::SetTimeResponse().
|
pure virtual |
Normalisation of the samples sum. This function is virtual because the normalisation procedure is different for real or complex samples).
s | requested normalisation |
Implemented in GRealSampleFFT.
GBaseSampleFFT & GBaseSampleFFT::operator= | ( | const GBaseSampleFFT & | original | ) |
Affectation operator.
original | object to be copied |
References CopyData(), and GDebugClass.
|
virtual |
Write the sample from a binary file. The file is opened and close. The function returns 0 if no error occured.
fname | file name |
References GFFT_IOERR_FOPEN, and GLogWarning().
|
virtual |
Effective function to read the sample from a binary file. The file must have been opened previously in binary mode. It is not closed by the function. The function returns 0 if no error occured.
fp | file pointer |
References data_array, data_set, data_type, fft_set, GDebugClass, GFFT_IOERR_DATA, GFFT_IOERR_FOPEN, GGetStringHexa(), GLogWarning(), ReadHeader(), and samples_number.
|
protectedvirtual |
Read the file header (no check of file pointer).
fp | file pointer |
References data_set, data_type, data_type_name, fft_set, GDebugClass, GFFT_HEADER_ID, GFFT_IOERR_DATA_TYPE, GFFT_IOERR_HEADER, GFFT_IOERR_HEADER_DATA, GLogWarning(), InitData(), and SetTimeRange().
Referenced by Read().
|
virtual |
Fonctions that deletes the data arrays and resets the number of samples.
References alloc_dim, data_array, data_set, fft_array, fft_set, freq_crit, freq_step, GDebugClass, GGetString(), samples_dim, samples_number, time_end, time_max, time_min, and time_step.
Referenced by InitData(), ResizeData(), and ~GBaseSampleFFT().
|
virtual |
Function to resize the data sample.
The given size n corresponds to the number of data samples. For real data it is the effective data array size, while for complex data, the effective allocated array size is
2*n.
If n is not a power of 2, the effective sample dimension (that is returned by the function) is the smallest power of 2 bigger than n.
If the new number of samples is bigger than the old one, the sample is padded with zeros; If the new number of samples is smaller than the old one, the sample is is truncated. In this latter case, there is no memory reallocation (the previous allocation is enough), unlike the InitData function.
If the sample has been defined from its FFT, the function sample must be defined before its size is changed.
If the function samples are defined, they are copied in the new array and the Fourier transform is not valid anymore (it will be recomputed by functions that needs it).
In any case, the Fourier transform is not kept valid after resizing !
n | new number of samples |
References alloc_dim, ComputeFunctionData(), data_array, data_set, data_type, fft_array, fft_set, GDebugClass, GetTimeMin(), GetTimeStep(), GFFTGetPower2Dim(), GGetString(), GLogWarning(), IsDefined(), IsFunctionSet(), IsTransformSet(), ResetData(), samples_dim, samples_number, and SetTimeRange().
Referenced by GRealSampleFFT::SetConvolution().
|
virtual |
Scaling of the sample (both function and FFT are scaled).
s | requested normalisation |
References data_array, and samples_dim.
|
pure virtual |
Set a single (complex) value for the FFT (see derived class descriptions for SetFFTValue and SetTransformValue).
i | index of the FFT value |
re | real part of the data |
im | imaginary part of the data |
Implemented in GRealSampleFFT.
|
pure virtual |
Pure virtual function to set a single value in the sample. The index meaning is different for a real or a complex data sample.
The use of this function implies that the full sample is set using this function, and that the FFT data have to be recomputed.
i | data index |
val | data (real) value |
Implemented in GRealSampleFFT.
|
virtual |
Set the time range for the function (that defines the frequency range). This function does not scale the data if a time range was previously defined
If center mode is used, the time argument correspond to points times of the first and the last data (with a difference of n - 1 intervals). Otherwise, the limits are considered as bin limits, with the lower time of the first bin and upper time of the last bin (a difference of
intervals).
The function returns 0 if no error occured, and 1 if the time limits are invalid, 2 if the number of samples is not defined.
t_lo | lower time limit |
t_hi | upper time limit |
ctr | indicates how the time limits are defined (see time scale) |
References data_type, freq_crit, freq_step, samples_dim, samples_number, time_end, time_max, time_min, and time_step.
Referenced by GRealSampleFFT::Derivate(), GRealSampleFFT::GRealSampleFFT(), InitData(), GRealSampleFFT::InitFunctionData(), GRealSampleFFT::Integrate(), GRealSampleFFT::InterpolateFrom(), GRealSampleFFT::operator*(), GRealSampleFFT::operator+(), GRealSampleFFT::operator-(), ReadHeader(), ResizeData(), GRealSampleFFT::SetConvolution(), and GRealSampleFFT::SetTimeResponse().
|
pure virtual |
Set a single (complex) value for the FFT (see derived class descriptions for SetFFTValue and SetTransformValue).
i | index of the FFT value |
re | real part of the data |
im | imaginary part of the data |
Implemented in GRealSampleFFT.
|
inline |
Force the Fourier transform data to be considered as defined (or undefined).
b | Fourier transform set value |
References fft_set.
Referenced by GRealSampleFFT::Derivate(), GRealSampleFFT::DoubleSymmetric(), GRealSampleFFT::HalfDivide(), GRealSampleFFT::Integrate(), GRealSampleFFT::operator*(), GRealSampleFFT::operator*=(), GRealSampleFFT::operator+(), GRealSampleFFT::operator+=(), GRealSampleFFT::operator-(), and GRealSampleFFT::operator-=().
|
virtual |
Write the sample in a binary file. The file is opened and close. The function returns 0 if no error occured.
fname | file name |
References GFFT_IOERR_FOPEN, and GLogWarning().
|
virtual |
Effective function to write the sample in a binary file. The file must have been opened previously in binary mode. It is not closed by the function. The function returns 0 if no error occured.
fp | file pointer |
References ComputeFunctionData(), data_array, data_type, GFFT_IOERR_FOPEN, GLogWarning(), IsFunctionSet(), samples_number, and WriteHeader().
|
protectedvirtual |
Write the file header (no check of file pointer).
fp | file pointer |
References data_type, GFFT_HEADER_ID, GFFT_IOERR_HEADER, GLogWarning(), samples_dim, samples_number, time_min, and time_step.
Referenced by Write().