FFTW库安装与使用
一、FFTW库介绍与下载
FFTW ( the Faster Fourier Transform in the West) 是一个快速计算离散傅里叶变换的标准C语言程序集,其由MIT的M.Frigo 和S. Johnson 开发。可计算一维或多维实和复数据以及任意规模的DFT,且运行速度比Eigen和opencv自带的FFT库函数快10倍以上。
下载链接:http://www.fftw.org/install/windows.html
二、FFTW库安装
1、解压缩下载的FFTW库文件。
2、在window10的开始菜单栏中打开VS xx的X64 Native Tools Commond Prompt for VS xx。
3、运行lib.exe命令,出现如下提示信息:

4、跳转到解压缩后的库文件目录下,依次输入如下命令生成lib库
lib /machine:x64 /def:libfftw3-3.def
lib /machine:x64 /def:libfftw3l-3.def
lib /machine:x64 /def:libfftw3f-3.def

5、将fftw3.h文件加入VS项目的include文件夹中;将libfftw3-3.dll、libfftw3f-3.dll、libfftw3l-3.dll文件加入VS项目的bin文件夹中;将libfftw3-3.lib、libfftw3f-3.lib、libfftw3l-3.lib加入VS项目的lib文

三、FFTW库测试
#include "fftw3.h"
#include<stdio.h>
#include<iostream>
#include<vector>
using namespace std;
int main()
{
//****************************ifft********************************
double array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
double* out;
double* err;
int i, size = 10;
fftw_complex* out_cpx;
fftw_plan fft;
fftw_plan ifft;
out_cpx = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * size);
out = (double*)malloc(size * sizeof(double));
err = (double*)malloc(size * sizeof(double));
fft = fftw_plan_dft_r2c_1d(size, array, out_cpx, FFTW_ESTIMATE); //Setup fftw plan for fft
ifft = fftw_plan_dft_c2r_1d(size, out_cpx, out, FFTW_ESTIMATE); //Setup fftw plan for ifft
fftw_execute(fft);
fftw_execute(ifft);
for (i = 0; i < size; i++)
{
err[i] = (array[i] - out[i]);
printf("%f\t%f\n", (array[i]), out[i] / size);//需要做归一化处理
}
fftw_destroy_plan(fft);
fftw_destroy_plan(ifft);
fftw_free(out_cpx);
free(err);
free(out);
//***************************************ifft*********************
system("pause");//暂停
return 0;
}
