29 #ifndef autocorrelation_hpp
30 #define autocorrelation_hpp
32 #include "../math/fft/fft.hpp"
55 #pragma omp parallel for
56 for(
int i=0; i< Nac; ++i)
60 for(
int j=0; j<Nsig-i; ++j)
62 ac[i] += sig[j]*sig[j+i];
67 for(
int i=0; i<Nac; ++i) ac[i] /= norm;
83 if(ac.size()==0) ac.resize(sig.size());
98 std::vector<std::complex<T>> fftOut;
99 std::vector<std::complex<T>> fftIn;
101 math::fft::fftT<std::complex<T>, std::complex<T>, 1, 0> fft;
113 fft.plan( Npsd, MXFFT_FORWARD);
118 for(
size_t i=0; i< Npsd; ++i) fftIn[i] = psd[i];
120 fft( fftOut.data(),fftIn.data() );
122 T norm = fftOut[0].real();
123 for(
size_t i=0; i < Npsd && i < Nac; ++i) ac[i] = fftOut[i].real()/norm;
135 if(ac.size() == 0) ac.resize(psd.size());
136 operator()( ac.data(), ac.size(), psd.data(), psd.size() );
void autocorrelation(std::vector< T > &ac, std::vector< T > &sig)
Calculate the autocorrelation of a time-series.
Functor for calculating the autocorrelation given a PSD.
void operator()(T *ac, size_t Nac, T *psd, size_t Npsd)
Calculate the A.C. as the inverse FFT of the PSD.