STIR
6.2.0
|
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... | |
void stir::fourier | ( | T & | c, |
const int | sign = 1 |
||
) |
Compute multi-dimensional discrete fourier transform.
[in,out] | c | The 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] | sign | This can be used to implement a different convention for the DFT. |
get_min_index()==0
at each dimension. Referenced by stir::SeparableMetzArrayFilter< num_dimensions, elemT >::SeparableMetzArrayFilter().
|
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.
Referenced by stir::inverse_fourier_1d_for_real_data_corrupting_input(), and stir::SeparableMetzArrayFilter< num_dimensions, elemT >::SeparableMetzArrayFilter().
void stir::fourier_1d | ( | T & | c, |
const int | sign | ||
) |
Compute one-dimensional discrete fourier transform of an array.
[in,out] | c | The 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] | sign | This can be used to implement a different convention for the DFT |
The convention used is as follows. For a vector of length n, the result is
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.
|
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.
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).
[in] | c | The type of c should normally be Array<1,float> (or double ). |
[in] | sign | This can be used to implement a different convention for the DFT. |
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
).
get_min_index()==0
. 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).
c
has to be made. This obviously affects performance. References stir::inverse_fourier_1d_for_real_data_corrupting_input().
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.
References _PI, stir::error(), and stir::inverse_fourier().
Referenced by stir::inverse_fourier_1d_for_real_data().
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).
[in] | c | The type of c should normally be Array<d,float> (or double ). |
[in] | sign | This can be used to implement a different convention for the DFT. |
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)
.
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.
c
has to be a regular array with all indices starting from 0. Referenced by stir::ArrayFilterUsingRealDFTWithPadding< 2, float >::do_it(), stir::ArrayFilterUsingRealDFTWithPadding< 2, float >::set_kernel(), and stir::ColsherFilter::set_up().
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).
c
has to be made. This 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.
Referenced by stir::ArrayFilterUsingRealDFTWithPadding< 2, float >::do_it(), and stir::ColsherFilter::set_up().
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.