The fftw database in the machine has been down for a long time and has never been involved. Alas, there are a lot of things like this. If you get it, you will leave it there. I remember what Huang Sheng said in his book borrowing: "You cannot read a book without borrowing it ".
Okay, I'm sorry. Into the subject.
Install fftw library in Windows
1. Download the pre-compiled version of fftw's windows DLL from http://www.fftw.org/install/windows.html;
2. decompress the file and open the windows command line window, which is the CMD window. Then, convert the current directory to the directory of the decompressed file.
3. Execute the following three commands (in ix86 and/DEF: there is no space between the libfftw3-3.def will cause errors)
LIB/machine: ix86/DEF: libfftw3-3, def
LIB/machine: ix86/DEF: libfftw3f-3.def
LIB/machine: ix86/DEF: libfftw3l-3.def
This will create three corresponding DLL files and Lib files under this directory. Note that "3l-3" in the third. Def file is in the lower case of the letter L, not the number 1. I spent half an hour on this issue.
4. Copy the libfftw3l-3.dll, libfftw3f-3.dll, and libfftw3-3.dll files to the System32 folder. In this step, you do not need to include these three oil bottles in the folder where your executable files are located in the future, because the system will directly find them in system32.
5. Specify the directory of the libfftw3l-3.lib, libfftw3f-3.lib, libfftw3-3.li, and fftw3.h files in VC. That is, add these two directories to include files and library files in the directories options of tools> options in VC ++, so that later VC compilation will know which directory to find.
6. The last step is to remember # include "fftw3.h" when you create a new project ", then, write the Lib you want to use to the object/library modules in project> setting> link> General.
7. Next, you can use the fftw library programming with confidence. To get familiar with fftw's call method and data structure, you can also download a copy of manualfrom http://www.fftw.org/?documentationfor your research and development.
Possible errors:
1. lnk1181: cannot open input file "…" : The cause of this error is: (1) Your file name is wrong; (2) your current directory is incorrect. The current directory should be the file directory after extraction.
2. The LIB cannot be found when the source file is compiled. It is because step 2 or step 2 is not completed. We recommend that you redo Step 2 and step 2.
Use fftw to write test programs
After completing the above steps, write a small test code and try it out. I copied an online code:
# Include "fftw3.h"
Int main ()
{
Fftw_complex * In, * out;
Fftw_plan P;
Int n = 8;
In = (fftw_complex *) fftw_malloc (sizeof (fftw_complex) * n );
Out = (fftw_complex *) fftw_malloc (sizeof (fftw_complex) * n );
For (INT I = 0; I <n; I ++)
{
In [I] [0] = 1.0;
In [I] [1] = 0.0;
Printf ("% 6.2f", in [I] [0]);
}
Printf ("\ n"); // in is the input data
P = fftw_plan_dft_1d (n, in, out, fftw_forward, fftw_estimate );
Fftw_execute (p);/* repeat as needed */
For (Int J = 0; j <n; j ++)
{
Printf ("% 6.2f", out [J] [0]);
}
Printf ("\ n ");
Fftw_destroy_plan (P );
Fftw_free (in );
Fftw_free (out );
Return 0;
}
The program provides a DC time domain data, and a DFT data with only DC components should be generated.
Install fftw library in Linux
The fftw (the fastest Fourier transform in the west) Library is Matteo Frigo and Steven G from MIT (Massachusetts Institute of Technology. johnson developed for the Discrete Fourier transformation of one dimension and multiple-dimensional real numbers or complex numbers.
1. Download fftw-2_1_3_tar.gz (www.fftw.org, or
Www.rpmfind.net)
2. Tar zxvf fftw-2_1_3_tar.gz expand ZIP file
3. Install fftw in Linux:
A.
./Configure -- enable-type-Prefix -- prefix =/usr/local/fftw -- With-GCC -- disable-Fortran -- enable-i386-hacks
Where,
The -- enable-type-Prefix parameter is used to simultaneously use single precision (single precision) and double precision (Double Precision). If you do not use it, finally, only files starting with rfftw are installed (real fftw );
-- Prefix = the parameter is used to set the installation directory;
-- With-GCC uses the GCC compiler;
-- The disable-Fortran parameter is used to exclude the mechanism called by FORTRAN;
-- The enable-i386-hacks optimizes GCC Compilation speed for the CPU after Pentium and x86.
B.
Make Compilation
C.
Make install installation. After this installation, the installation directory contains files starting with dfftw and drfftw, but no files starting with sfftw.
D.
Make clean also needs to be installed once, first clear
E.
./Configure -- enable-float -- enable-type-Prefix -- prefix =/usr/local/fftw -- With-GCC -- disable-Fortran -- enable-i386-hacks
Here, -- enable-float is used to generate header files and library files for Single-precision computing, that is, files starting with sfftw.
F.
Make Re-compile
G.
Make install is installed again. After installation, files starting with sfftw and dfftw will exist in the directory (for the FFT transformation of the plural function/complex function) files starting with srfftw and drfftw (for FFT transformation of real functions)
For example, if you want to use double-precision real-number FFT transformation/FFTS, you need to add
-Ldrfftw-ldfftw Parameter
The following is an example of how to use
/*****************************
* Filename: test_fftw.cpp
* Author: Tiao Lu
* Company: School of mathematical sciences, Peking University
* Compilation command: G ++-O test_fftw.exe test_fftw.cpp-lfftw3
* Date: September 30th, 2007
* Description: This CoDe is an example to show the use of the free CoDe fftw, which implements the fast Fourier trasformation algorithm.
*/
# Include <complex>
# Include <fftw3.h>
# Include <math. h>
# Include <iostream>
# Define N 10
Using namespace STD;
Int main (INT argc, char * argv []) {
Fftw_complex in [N], out [N];
Fftw_plan P;
// One-Dimensional DFT, in input, out output, fftw_forward indicates that the exponent on exp is a negative number.
// Out = f in
// Where out and in are two vectors of the same length N, and F is a n-by-n matrix with the (j, k) Element
// F jk = exp (-I 2 Pi j k/n). I is a virtual number unit.
P = fftw_plan_dft_1d (n, in, out, fftw_forward, fftw_measure );
For (INT I = 0; I <n; I ++ ){
In [I] [0] = I;
In [I] [1] = 0.0;
}
Fftw_execute (P );
For (INT I = 0; I <n; I ++ ){
Cout <out [I] [0] <"" <out [I] [1] <Endl;
}
// Verify whether out [3] = \ sum _ {k = 0} ^ {N-1} exp (-I 2PI 3 K/n) in [k]
Complex & lt; double & gt; temp = 0.0;
For (int K = 0; k <n; k ++ ){
Double Pi = 4 * atan (1.0 );
Temp + = exp (complex <double> (0.0,-2.0 * pI * 3 * k/n) * Complex <double> (in [k] [0], in [k] [1]);
}
Cout <"out [3] is" <temp <Endl;
Fftw_complex out1 [N];
Fftw_plan P1;
// One-Dimensional DFT, in input, out output, fftw_backward indicates that the exponent on exp is positive.
// Out = if in
// Where out and in are two vectors of the same length N, and if is a n-by-n matrix with the (j, k) Element
// If JK = exp (+ I 2 pi JK/n). I is a virtual number unit.
P1 = fftw_plan_dft_1d (n, out1, In, fftw_backward, fftw_measure );
For (INT I = 0; I <n; I ++ ){
Out1 [I] [0] = out [I] [0];
Out1 [I] [1] = out [I] [1];
}
Fftw_execute (P1 );
// Note that the obtained in is not different from the original in value. After comparison, we find that the current in
// N times the original in. The reason is that the inverse Fourier transformation defined here is not divided by N.
// This is different from the inverse Fourier transformation defined in the textbook.
For (INT I = 0; I <n; I ++ ){
Cout <in [I] [0] <"" <in [I] [1] <Endl;
}
Fftw_destroy_plan (P );
Fftw_destroy_plan (P1 );
Return 1;
}