Fourier transformations using boost::multi_array

Several functions offered by the fftw3 library are wrapped using boost::multi_array. More...

Classes

struct  mimas::fft_t< Real, Dim, TPtr >
 Discrete fourier transform using fftw. More...
struct  mimas::invfft_t< Real, Dim, TPtr >
 Inverse discrete fourier transform using fftw. More...
struct  mimas::rfft_t< Real, Dim, TPtr >
 Discrete fourier transform of real values using fftw. More...
struct  mimas::invrfft_t< Real, Dim, TPtr >
 Inverse discrete fourier transform of symmetric complex array using fftw. More...

Functions

template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< std::complex<
Real >, Dim > 
mimas::fft (const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &field)
 Discrete fourier transform of boost::multi_array.
template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< std::complex<
Real >, Dim > 
mimas::invfft (const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &field)
 Inverse discrete fourier transform of boost::multi_array.
template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< std::complex<
Real >, Dim > 
mimas::rfft (const boost::const_multi_array_ref< Real, Dim, TPtr > &field)
 Discrete fourier transform of real-valued boost::multi_array.
template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< Real,
Dim > 
mimas::invrfft (const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &field)
 Inverse discrete fourier resulting in real-valued boost::multi_array.

Detailed Description

Several functions offered by the fftw3 library are wrapped using boost::multi_array.

There are several types of fourier-transforms. The current implementation only allows fourier-transforms on double precision numbers.

The real-to-complex fourier transform will result in an array of about half the size, because the fourier transform of a real function always is symmetric: $\mathrm{mm\_rfft}:\mathbf{R}^{n_1\times n_2\times\ldots n_d}\rightarrow \mathbf{C}^{n_1\times n_2\times\ldots (n_d/2+1)}$

// Sample application of fourier library functions
// Bala Amavasai (bpa@amavasai.org)
// Thu Oct 18 12:38:26 BST 2001
// Jan Wedekind (jan at wedesoft.de)
// Mon Aug 23 14:37:05 UTC 2004

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <fstream>
#include "fourier.h"
#include "image.h"
#include "image_fileinput.h"
#include "image_funcs.h"
#include "image_mesaoutput.h"
#include "multi_array_op.h"

using namespace boost;
using namespace std;
using namespace mimas;

template<
  typename T,
  template< typename > class C
>
struct _creal: public unary_function< C< T >, T >
{
  T operator()( const C< T > &x ) const { return x.real(); }
};

template <
  typename T, size_t NumDims,
  template< class, size_t > class MultiArray,
  template< typename > class C
>
boost::multi_array< T, NumDims > creal
  ( const MultiArray< C< T >, NumDims > &a )
{
  return multi_func< T >( a, _creal< T, C >() );
};

int main(int argc, char **argv)
{
  int retVal = 0;
  try {
    x11_display display;
    image< int > img;
    image_mesaoutput< unsigned char >
      window1( &display ),
      window2( &display ),
      window3( &display ),
      window4( &display );

    ifstream file( "../images/stills/jellybeans-256x256.pgm", ios::binary );
    file >> img;

    const_multi_array_ref< int, 2 > data
      ( img.rawData(),
        extents[ img.getHeight() ][ img.getWidth() ] );

    {
      // Real fourier transform.
      multi_array< std::complex< double >,2 > imageFFT
  ( rfft( multi_cast< double >( data ) ) );
      multi_array< double, 2 > imageLogFFT
        ( logarithm( norm< double >( imageFFT ) + 1.0 ) );

      // Remove peak caused by constant component of input image.
      imageLogFFT[ 0 ][ 0 ] = 0.0;

      // Display.
      const_image_ref< double > result( imageLogFFT.data(),
                                        imageLogFFT.shape()[1],
                                        imageLogFFT.shape()[0] );
      window1 << normalise( result, 0.0, 255.0 );

      // Inverse fourier transform.
      boost::multi_array< double, 2 >
        result2( invrfft( imageFFT ) );
      window2 << const_image_ref< double >( result2.data(),
                                            result2.shape()[1],
                                            result2.shape()[0] );
    };
    {
      // Fourier transform.
      multi_array< std::complex< double >,2 > imageFFT
  ( fft( multi_cast< std::complex< double > >( data ) ) );
      multi_array< double, 2 > imageLogFFT
        ( logarithm( norm< double >( imageFFT ) + 1.0 ) );

      // Remove peak caused by constant component of input image.
      imageLogFFT[ 0 ][ 0 ] = 0.0;

      // Display.
      const_image_ref< double > result( imageLogFFT.data(),
                                        imageLogFFT.shape()[1],
                                        imageLogFFT.shape()[0] );
      window3 << normalise( result, 0.0, 255.0 );

      // Inverse fourier transform.
      boost::multi_array< double, 2 >
        result2 ( creal( invfft( imageFFT ) ) );
      window4 << const_image_ref< double >( result2.data(),
                                            result2.shape()[1],
                                            result2.shape()[0] )
              << mimas::pause();
    };
  } catch ( exception &e ) {
    cerr << e.what() << endl;
    retVal = 1;
  };
  return retVal;
}

Have a look at the fftw info-pages. Also see fftw docs and TiP-0.0.1.

Author:
Bala Amavasai (bpa@amavasai.org)

Jan Wedekind (jan at wedesoft.de)

Date:
Wed Aug 04 22:48:27 UTC 2004

Function Documentation

template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< std::complex< Real >, Dim > mimas::fft ( const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &  field  ) 

Discrete fourier transform of boost::multi_array.

See also:
fft_t

Definition at line 56 of file fourier.h.

template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< std::complex< Real >, Dim > mimas::invfft ( const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &  field  ) 

Inverse discrete fourier transform of boost::multi_array.

See also:
invfft_t

Definition at line 76 of file fourier.h.

template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< Real, Dim > mimas::invrfft ( const boost::const_multi_array_ref< std::complex< Real >, Dim, TPtr > &  field  ) 

Inverse discrete fourier resulting in real-valued boost::multi_array.

See also:
invrfft_t

Definition at line 138 of file fourier.h.

template<typename Real, std::size_t Dim, typename TPtr>
boost::multi_array< std::complex< Real >, Dim > mimas::rfft ( const boost::const_multi_array_ref< Real, Dim, TPtr > &  field  ) 

Discrete fourier transform of real-valued boost::multi_array.

See also:
rfft_t

Definition at line 107 of file fourier.h.


[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:20 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...