C++ fast-fourier-transform (package for wsjcpp)
via wsjcpp:
$ wsjcpp install https://github.com/wsjcpp/fast-fourier-transform:master
or include this files:
- src.wsjcpp/wsjcpp_core.h
- src.wsjcpp/wsjcpp_core.cpp
- src/fast_fourier_transform_wiki.h
- src/fast_fourier_transform_wiki.cpp
int nCount = 64;
double *pSignal = new double[nCount];
double *pFFT = new double[nCount];
// Fill here pSignal and reset values
for (int i = 0; i < nCount; i++) {
pFFT[i] = 0;
}
FastFourierTransformWiki fft;
long t0 = WsjcppCore::getCurrentTimeInMilliseconds();
fft.analitics(pSignal, pFFT, nCount, nCount);
long t1 = WsjcppCore::getCurrentTimeInMilliseconds();
WsjcppLog::info(TAG, "Calculation time: " + std::to_string(t1-t0) + " ms");
// Now values of fft will be in array: pFFT
// for example get 2 diff arrays
std::vector<float> vOffsetSin; // first attr of harmonic
std::vector<float> vAmplitudeSin; // second attr of harmonic
for (int i = 0; i < nCount/2; i++) {
vOffsetSin.push_back(pFFT[i*2]);
vAmplitudeSin.push_back(pFFT[i*2 + 1]);
}