android平台的几个计算FFT(Fastest Fourier Transform)的库
1. fftw
源码下载:https://github.com/FFTW/fftw3
下面这个例子是做傅立叶变换与反变换,省略了填充数据部分。实际需要给in[]赋值。
fftwf_real *in;
fftwf_complex *out;
fftwf_plan p_r2c, p_c2r;
in = (fftwf_real*) fftwf_malloc(sizeof(fftwf_real) * N);
out = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * N);
p_r2c = fftwf_plan_dft_r2c_1d(N, in, out, FFTW_ESTIMATE);
p_c2r = fftwf_plan_dft_c2r_1d(N, out, in, FFTW_ESTIMATE);
//正向
fftwf_execute(p_r2c);
//反向
fftwf_execute(p_c2r);
fftwf_destroy_plan(p_r2c);
fftwf_destroy_plan(p_c2r);
fftwf_free(in);
fftwf_free(out);
2. ne10
这个是arm公司提供的,使用neon优化加速。支持armeabi-v7a,arm64两个架构。
文档:http://projectne10.github.io/Ne10/doc/
源码下载:https://github.com/projectNe10/Ne10/tree/v1.2.1
下面这个例子和fftw那个差不多。
ne10_float32_t src[SAMPLES] = {}; // A source array of input data
ne10_fft_cpx_float32_t dst[(SAMPLES / 2) + 1] = {}; // A destination array for the transformed data
ne10_fft_r2c_cfg_float32_t cfg; // An FFT "configuration structure"
ne10_fft_r2c_cfg_float32_t icfg;
// Initialise Ne10, using hardware auto-detection to set library function pointers
if (ne10_init() != NE10_OK)
{
fprintf(stderr, "Failed to initialise Ne10.\n");
return 1;
}
// Prepare the real-to-complex single precision floating point FFT configuration
// structure for inputs of length `SAMPLES`. (You need only generate this once for a
// particular input size.)
cfg = ne10_fft_alloc_r2c_float32(SAMPLES);
icfg = ne10_fft_alloc_r2c_float32(SAMPLES);
// Generate test input values
// Perform the FFT
ne10_fft_r2c_1d_float32(dst, src, cfg);
// Perform the IFFT
ne10_fft_c2r_1d_float32(src, dst, icfg);
// Free the allocated configuration structure
ne10_fft_destroy_r2c_float32(cfg);
ne10_fft_destroy_r2c_float32(icfg);