Difference between revisions of "How to use FFTW"

From Qt Wiki
Jump to: navigation, search
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Learning::HowTo]]
+
[[Category:HowTo]]
 +
== Getting Started ==
  
= How to compute FFT using FFTW in Qt =
+
'''Note that this is done on an Ubuntu operating system, on Windows some steps are different.'''
  
== Getting Start ==
+
* '''Step 1''': Download FFTW from http://www.fftw.org/download.html
  
'''Note that I do this in Ubuntu operating system, in Windows some steps are different.'''
+
* '''Step 2''': Extract and Configure it (my path: /home/jafarabadi/Documents/fftw-3.3.4)
  
* Step1: Download FFTW ([[http://www.fftw.org/download.html]])
+
<pre>
 
+
cd /home/jafarabadi/Documents/fftw-3.3.4
* Step2: Extract and Configure it (my path: /home/jafarabadi/Documents/fftw-3.3.4)
 
<code>cd /home/jafarabadi/Documents/fftw-3.3.4
 
chmod ''x configure
 
 
./configure
 
./configure
 
make
 
make
make install</code>
+
make install
 +
</pre>
 +
 
 +
* Alternatively install fftw through your package manager (e.g. pacman -Sy fftw)
 +
 
 +
* '''Step 3''': Add library to project: first open [your_project_name].pro file in Qt Creator and add this line:
  
* Step 3: Add library to project: first open [your_project_name].pro file in Qt Creator and add this line:
+
<pre>
<code>LIBS''= -lfftw3<code>
+
LIBS += -lfftw3
 +
</pre>
  
* Step 4: Example
+
* '''Step 4''': Example
</code>#include <fftw3.h></code>
 
<code>int N;
 
  
fftw_complex *in, '''out;
+
<code>
in = (fftw_complex''') fftw_malloc(sizeof(fftw_complex)'''N);
+
#include <fftw3.h>
out = (fftw_complex''') fftw_malloc(sizeof(fftw_complex)*N);
+
int N;
 +
 
 +
// Set N to the number of complex elements in the input array
 +
 
 +
fftw_complex *in, *out;
 +
in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);
 +
out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);
 +
 
 +
// Initialize 'in' with N complex entries
  
 
fftw_plan my_plan;
 
fftw_plan my_plan;
 
my_plan = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
 
my_plan = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
 
fftw_execute(my_plan);
 
fftw_execute(my_plan);
 +
 +
// Use 'out' for something
  
 
fftw_destroy_plan(my_plan);
 
fftw_destroy_plan(my_plan);
Line 35: Line 47:
 
fftw_free(out);
 
fftw_free(out);
  
// A short tutorial: http://www2.math.uu.se/~figueras/fftw_tutorial/text/fftw_tutorial.pdf</code>
+
// A short tutorial:
 +
// http://www2.math.uu.se/~figueras/Other/text/fftw_tutorial.pdf
 +
</code>

Latest revision as of 07:58, 10 March 2017

Getting Started

Note that this is done on an Ubuntu operating system, on Windows some steps are different.

  • Step 2: Extract and Configure it (my path: /home/jafarabadi/Documents/fftw-3.3.4)
cd /home/jafarabadi/Documents/fftw-3.3.4
./configure
make
make install
  • Alternatively install fftw through your package manager (e.g. pacman -Sy fftw)
  • Step 3: Add library to project: first open [your_project_name].pro file in Qt Creator and add this line:
LIBS += -lfftw3
  • Step 4: Example

  1. include <fftw3.h>

int N;

// Set N to the number of complex elements in the input array

fftw_complex *in, *out; in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N); out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);

// Initialize 'in' with N complex entries

fftw_plan my_plan; my_plan = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE); fftw_execute(my_plan);

// Use 'out' for something

fftw_destroy_plan(my_plan); fftw_free(in); fftw_free(out);

// A short tutorial: // http://www2.math.uu.se/~figueras/Other/text/fftw_tutorial.pdf