STIR  6.2.0
Files | Functions
Discrete Fourier transforms
Collaboration diagram for Discrete Fourier transforms:

Files

file  fourier.h
 Functions for computing FFTs.
 
file  fourier.cxx
 Functions for computing discrete fourier transforms.
 
file  test_Fourier.cxx
 Tests for function in the DFT group.
 

Functions

template<typename T >
void stir::fourier (T &c, const int sign=1)
 Compute multi-dimensional discrete fourier transform. More...
 
template<typename T >
void stir::inverse_fourier (T &c, const int sign=1)
 Compute the inverse of the multi-dimensional discrete fourier transform. More...
 
template<typename T >
void stir::fourier_1d (T &c, const int sign)
 Compute one-dimensional discrete fourier transform of an array. More...
 
template<typename T >
void stir::inverse_fourier_1d (T &c, const int sign=1)
 Compute the inverse of the one-dimensional discrete fourier transform. More...
 
template<typename T >
Array< 1, std::complex< T > > stir::fourier_1d_for_real_data (const Array< 1, T > &c, const int sign=1)
 Compute one-dimensional discrete fourier transform of a real array (of even size). More...
 
template<typename T >
Array< 1, T > stir::inverse_fourier_1d_for_real_data (const Array< 1, std::complex< T >> &c, const int sign=1)
 Compute the inverse of the one-dimensional discrete fourier transform of a real array (of even size). More...
 
template<typename T >
Array< 1, T > stir::inverse_fourier_1d_for_real_data_corrupting_input (Array< 1, std::complex< T >> &c, const int sign)
 As inverse_fourier_1d_for_real_data(), but avoiding the copy of the input array. More...
 
template<int num_dimensions, typename T >
Array< num_dimensions, std::complex< T > > stir::fourier_for_real_data (const Array< num_dimensions, T > &c, const int sign=1)
 Compute discrete fourier transform of a real array (with the last dimensions of even size). More...
 
template<int num_dimensions, typename T >
Array< num_dimensions, T > stir::inverse_fourier_for_real_data (const Array< num_dimensions, std::complex< T >> &c, const int sign=1)
 Compute the inverse of the discrete fourier transform of a real array (with the last dimension of even size). More...
 
template<int num_dimensions, typename T >
Array< num_dimensions, T > stir::inverse_fourier_for_real_data_corrupting_input (Array< num_dimensions, std::complex< T >> &c, const int sign=1)
 As inverse_fourier_for_real_data(), but avoiding the copy of the input array. More...
 
template<int num_dimensions, typename T >
Array< num_dimensions, std::complex< T > > stir::pos_frequencies_to_all (const Array< num_dimensions, std::complex< T >> &c)
 Adds negative frequencies to the last dimension of a complex array by complex conjugation. More...
 

Detailed Description

Function Documentation

◆ fourier()

template<typename T >
void stir::fourier ( T &  c,
const int  sign = 1 
)

Compute multi-dimensional discrete fourier transform.

Parameters
[in,out]cThe type of c should normally be Array<n,std::complex<T> >. The function will then compute the n- dimensional fourier transform of the data, and store the result in c.
[in]signThis can be used to implement a different convention for the DFT.
See also
fourier_1d for conventions and restrictions
Warning
Currently, the array has to have get_min_index()==0 at each dimension.

Referenced by stir::SeparableMetzArrayFilter< num_dimensions, elemT >::SeparableMetzArrayFilter().

◆ inverse_fourier()

template<typename T >
void stir::inverse_fourier ( T &  c,
const int  sign = 1 
)
inline

Compute the inverse of the multi-dimensional discrete fourier transform.

The scale factor is such that inverse_fourier(fourier(c,sign),sign)==c, aside from numerical error of course.

See also
fourier

Referenced by stir::inverse_fourier_1d_for_real_data_corrupting_input(), and stir::SeparableMetzArrayFilter< num_dimensions, elemT >::SeparableMetzArrayFilter().

◆ fourier_1d()

template<typename T >
void stir::fourier_1d ( T &  c,
const int  sign 
)

Compute one-dimensional discrete fourier transform of an array.

Parameters
[in,out]cThe type of c should normally be Array<n,std::complex<T> > (but see below). The function will then compute the one-dimensional fourier transform (i.e. on the 'outer' index) of the data, and store the result in c.
[in]signThis can be used to implement a different convention for the DFT
Warning
Currently, the array has to be indexed from 0.
Currently, the length of the array has to be a power of 2.

The convention used is as follows. For a vector of length n, the result is

\[ r_s = \sum_{s=0}^{n-1} c_r e^{\mathrm{sign} 2\pi i r s/n} \]

This means that the zero-frequency will be returned in c[0]

This function can be used with more general type of c (if instantiated in fourier.cxx). The type T has to be such that T::value_type, T::reference and T::reference T::operator[](const int) exist. Moreover, numerical operations operator*=(T::reference, std::complex<float>), operator+=(T::reference, T::value_type) and operator*=(T::reference, int), have to be defined as well.

◆ inverse_fourier_1d()

template<typename T >
void stir::inverse_fourier_1d ( T &  c,
const int  sign = 1 
)
inline

Compute the inverse of the one-dimensional discrete fourier transform.

The scale factor is such that inverse_fourier_1d(fourier_1d(c,sign),sign)==c, aside from numerical error of course.

See also
fourier_1d()

◆ fourier_1d_for_real_data()

template<typename T >
Array< 1, std::complex< T > > stir::fourier_1d_for_real_data ( const Array< 1, T > &  c,
const int  sign = 1 
)

Compute one-dimensional discrete fourier transform of a real array (of even size).

Parameters
[in]cThe type of c should normally be Array<1,float> (or double).
[in]signThis can be used to implement a different convention for the DFT.
Returns
The positive frequencies of the DFT as an array of complex numbers. That is, for c.size()==2*n, the returned array will have indices from 0 to n, with the 0 frequency at 0.

For a real array, the DFT is such that the values at negative frequencies are the complex conjugate of the value at the corresponding positive frequency. In addition, if the length of the real array is even, the DFT can be computed efficiently by creating a complex array of half the length (by putting the even-numbered elements as the real part, and the odd-numbered as the imaginary part).

This function implements the above and is hence (probably) a faster way to compute DFTs of real arrays. Note however, that in contrast to the Numerical Recipes routines, the result is not stored in the same memory location as the input. For a recent compiler that implements the Named-Return-Value-Optimisation, this should not be a problem in most cases.

Result is such that pos_frequencies_to_all(fourier_1d_for_real_data(v,sign))==fourier(v,sign) (this is meant symbolically. In code you'd have to make v into an array of complex numbers before passing to fourier).

See also
pos_frequencies_to_all()
fourier_1d() for conventions and restrictions
Warning
Currently, the array has to have get_min_index()==0.

◆ inverse_fourier_1d_for_real_data()

template<typename T >
Array< 1, T > stir::inverse_fourier_1d_for_real_data ( const Array< 1, std::complex< T >> &  c,
const int  sign = 1 
)

Compute the inverse of the one-dimensional discrete fourier transform of a real array (of even size).

Warning
Because of implementation issues, a temporary copy of the input data c has to be made. This obviously affects performance.
See also
fourier_1d_for_real_data()

References stir::inverse_fourier_1d_for_real_data_corrupting_input().

◆ inverse_fourier_1d_for_real_data_corrupting_input()

template<typename T >
Array< 1, T > stir::inverse_fourier_1d_for_real_data_corrupting_input ( Array< 1, std::complex< T >> &  c,
const int  sign 
)

As inverse_fourier_1d_for_real_data(), but avoiding the copy of the input array.

Warning
destroys values in (and resizes) first argument c
See also
inverse_fourier_1d_for_real_data()

References _PI, stir::error(), and stir::inverse_fourier().

Referenced by stir::inverse_fourier_1d_for_real_data().

◆ fourier_for_real_data()

template<int num_dimensions, typename T >
Array< num_dimensions, std::complex< T > > stir::fourier_for_real_data ( const Array< num_dimensions, T > &  c,
const int  sign = 1 
)

Compute discrete fourier transform of a real array (with the last dimensions of even size).

Parameters
[in]cThe type of c should normally be Array<d,float> (or double).
[in]signThis can be used to implement a different convention for the DFT.
Returns
The positive frequencies of the DFT as an array of complex numbers. That is, if c has sizes (n1,n2,...,nd), with nd even, the returned array will have sizes (n1,n2,...,(nd/2)+1), with the 0 frequency at index (0,0,...0).

For a real array, the DFT is such that the values at frequency (k1,k2,...,kd) are the complex conjugate of the value at the corresponding frequency (-k1,-k2,...,-kd).

See also
fourier_1d_for_real_data()

This can be used to compute only the 'positive' half of the frequencies. For this implementation, this means that only results for frequencies (k1,k2,...,kd) with 0<=kd<=(nd/2), i.e. the 'last' dimension has positive frequencies.

Warning
At present, c has to be a regular array with all indices starting from 0.
See also
pos_frequencies_to_all()

Referenced by stir::ArrayFilterUsingRealDFTWithPadding< 2, float >::do_it(), stir::ArrayFilterUsingRealDFTWithPadding< 2, float >::set_kernel(), and stir::ColsherFilter::set_up().

◆ inverse_fourier_for_real_data()

template<int num_dimensions, typename T >
Array< num_dimensions, T > stir::inverse_fourier_for_real_data ( const Array< num_dimensions, std::complex< T >> &  c,
const int  sign = 1 
)

Compute the inverse of the discrete fourier transform of a real array (with the last dimension of even size).

Warning
Because of implementation issues, a temporary copy of the input data c has to be made. This
See also
fourier_for_real_data()

◆ inverse_fourier_for_real_data_corrupting_input()

template<int num_dimensions, typename T >
Array< num_dimensions, T > stir::inverse_fourier_for_real_data_corrupting_input ( Array< num_dimensions, std::complex< T >> &  c,
const int  sign = 1 
)

As inverse_fourier_for_real_data(), but avoiding the copy of the input array.

Warning
destroys values in (and resizes) first argument c
See also
inverse_fourier_for_real_data()

Referenced by stir::ArrayFilterUsingRealDFTWithPadding< 2, float >::do_it(), and stir::ColsherFilter::set_up().

◆ pos_frequencies_to_all()

template<int num_dimensions, typename T >
Array< num_dimensions, std::complex< T > > stir::pos_frequencies_to_all ( const Array< num_dimensions, std::complex< T >> &  c)

Adds negative frequencies to the last dimension of a complex array by complex conjugation.

See also
fourier_for_real_data()