Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Last active October 11, 2019 04:59
Show Gist options
  • Save jniemann66/00b05e12603abd4ed64a6a51769a359c to your computer and use it in GitHub Desktop.
Save jniemann66/00b05e12603abd4ed64a6a51769a359c to your computer and use it in GitHub Desktop.
fft size selector
// pick a good fft size for fftw (of the form 2^a * 3^b * 5^c * 7^d * [1|11|13] )
int selectFFTSize(int n)
{
int s = 1;
for(int ef : {1, 11, 13}) {
for(int d = 1 ; d <= n; d *= 7) {
for(int c = 1; c <= n; c *= 5) {
for(int b = 1; b <= n; b *= 3) {
for(int a = 1; a <= n; a *= 2) {
int t = a * b * c * d * ef;
if(t > n) {
break;
}
s = std::max(s, t);
}
}
}
}
}
return s;
}
int fftsize = selectFFTSize(2 * (desiredSpectrumSize - 1));
int actualSpectrumSize = static_cast<int>(floor(fftsize / 2)) + 1;
@jniemann66
Copy link
Author

fftsize_vs_spectrumsize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment