Note: This page hasn't been updated for a long time, and is most likely outdated. If you need it to be updated, please submit a ticket to help@sharcnet.ca with the link to the page. |

Complete FFTW Examples in C, F90, OCTAVE and PETSc

**Nick Chepurniy, Ph.D.**

**e-mail: nickc@sharcnet.ca**

**HPC Consultant - SHARCNET**

**http://www.sharcnet.ca**

**Compute Canada**

**http://www.computecanada.org**

### Overview

If you untar file FFTW Examples in C, F90, OCTAVE and PETSc

the main directory should have the following four subdirectories:

C F90 OCTAVE PETSC

In each of the above subdirectories you will find complete examples of FORWARD and BACKWARD FFT's. All the programs use 3 vectors: "in", "out" and "new_in" of dimension N > 0.

The programs start by defining the vector "in" and then a FORWARD FFT is done on "in" and the results are stored in vector "out".

Then a BACKWARD FFT is done on vector "out" and the results are stored in vector "new_in". In F90, C and PETSC "new_in" must be normalized before it can be compared with the initial vector "in".

The error is measured using the NORM-1 procedure, and if all worked correctly the NORM-1 should be very small (say ~ 1.0e-12). Of course the value of NORM-1 will depend on N. The larger the size of the vectors the larger the error.

### OCTAVE

Above procedure can be done interactively in OCTAVE with following five commands:

N=10; in=[1:N]' out=fft(in) new_in=ifft(out) NORM_1=norm(in-new_in,1)

Here are the details:

[nickc@hnd50:/work/nickc/hound/P14/OCTAVE] octave GNU Octave, version 3.2.4

octave:1> N=10;

octave:2> in=[1:N]' in = 1 2 3 4 5 6 7 8 9 10

octave:3> out=fft(in) out = 55.0000 + 0.0000i -5.0000 + 15.3884i -5.0000 + 6.8819i -5.0000 + 3.6327i -5.0000 + 1.6246i -5.0000 + 0.0000i -5.0000 - 1.6246i -5.0000 - 3.6327i -5.0000 - 6.8819i -5.0000 - 15.3884i

octave:4> new_in=ifft(out) new_in = 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000

octave:5> NORM_1=norm(in-new_in,1) NORM_1 = 8.8818e-16

octave:6> quit

Last update: 12 Sept 2013