Using FFTW for Fourier transform and programming examples under Windows

Source: Internet
Author: User

Fourier transform should be a sophomore when the "Signal and system" class, after the study in the "Digital signal processing" class and learned again. What is the use of the Fourier transform in the beginning? When can I use it? Time flies, did not expect to graduate four years later, a small project to use the Fourier transform, Xi da Pu ran ah, the original obscure concept, dizzying formula, finally did not learn white. Yes,actuallyany knowledge is not a white learning, even if the work has not been used in the Fourier transform, at least the thinking has been exercised, are beneficial . In the process of applying Fourier transform, it can be programmed by the formula, or the existing open source Fourier transform function library can be used. After reviewing the data, I chose the FFTW function library for Fourier transform, becauseFFTWThe official web site mentions that the function library performs very well and can even compete with the same type of commercial software. FFTW website address is:http://www.fftw.org/. First, FFTW downloadsince I was developing on the Windows platform, I went to the following link: http://www.fftw.org/install/windows.html download the compiled version. As shown, the graph has a large amount of information, both 32/642 versions of the download link, as well as the Generate LIB file command. That is, the 32-bit system command is: Lib/def:libfftw3-3.def, while the 64-bit system is: lib/machine:x64/def:libfftw3-3.def.
Download Decompression, you will find only DLL and header files, when there is no Lib file, using the FFTW library will be more cumbersome. So before the application of FFTW programming or Mr. Hands into LIB file. Method is simple, first open the VS command prompt tool. The development tools I use are VS2005, as shown in:
Open the CD to the downloaded FFTW file directory, and then execute the previously mentioned LIB build command as shown in:
after the command is finished, you can see the newly generated LIB file in the current directory, I have generated a double, float, long double three versions, in actual use, according to the needs of the project, select the appropriate version of the accuracy. The generated Lib library file looks like this:



        Two, simple programming examples         have a header file, Lib/dll file, then everything has. Create a new project and use it right away. The following is a very simple programming example, the main completion of the real Fourier transform, the input sine curve, the output of the Fourier transform amplitude spectrum.
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <math.h> #include "include/ Fftw3.h "#pragma comment (lib," Libfftw3-3.lib ")//double version//#pragma comment (lib," Libfftw3f-3.lib ")//Float Version//# pragma comment (lib, "Libfftw3l-3.lib")//long double version # define PI 3.1415926int main () {int len = 8;double *in = null;//If you want to make With the float version, you need to refer to the float version of the Lib library, and then add the F suffix after fftw. Fftw_complex *out = null;//Fftwf_complex--float version Fftw_plan p;in = (  Double *) fftw_malloc (sizeof (double) * len), out = (Fftw_complex *) fftw_malloc (sizeof (FFTW_COMPLEX) * len);d ouble dx = 1.0/ len;//input Pure real number for (int i = 0; i < len; i++) {in[i] = sin (2*PI * dx*i) + sin (4*pi * dx*i);p rintf ("%.2f", In[i]);} printf ("\ n");//Fourier transform P = fftw_plan_dft_r2c_1d (len, in, out, fftw_estimate); Fftw_execute (P);//output amplitude spectrum for (int i = 0; I &lt ; Len i++) {Float len = sqrt (out[i][0]*out[i][0] + out[i][1]*out[i][1]);p rintf ("%.2f", Len);} printf ("\ n");//Release Resource Fftw_destroy_plan (p); Fftw_free (in); Fftw_free (out); System ("Pause"); return 0;} 
As shown in the results, from the results, the frequency is 1 and 22 positions have amplitude output, which is the input frequency of 1 and 2 of the two superposition sine wave, the result is correct.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.