Fourier transform functions

Overview

All forward transforms use the standard convention \(X(k) = \sum_n x(n) e^{-2 \pi i k n / N}\), and inverse transforms use \(e^{+2 \pi i k n / N}\) and the \(1/N\) scale factor.

// global functions

void mrpt::math::fft_real(CVectorFloat& in_realData, CVectorFloat& out_FFT_Re, CVectorFloat& out_FFT_Im, CVectorFloat& out_FFT_Mag);
void mrpt::math::dft2_real(const CMatrixFloat& in_data, CMatrixFloat& out_real, CMatrixFloat& out_imag);
void mrpt::math::idft2_real(const CMatrixFloat& in_real, const CMatrixFloat& in_imag, CMatrixFloat& out_data);
void mrpt::math::dft2_complex(const CMatrixFloat& in_real, const CMatrixFloat& in_imag, CMatrixFloat& out_real, CMatrixFloat& out_imag);
void mrpt::math::idft2_complex(const CMatrixFloat& in_real, const CMatrixFloat& in_imag, CMatrixFloat& out_real, CMatrixFloat& out_imag);
void mrpt::math::cross_correlation_FFT(const CMatrixFloat& A, const CMatrixFloat& B, CMatrixFloat& out_corr);

Global Functions

void mrpt::math::fft_real(
    CVectorFloat& in_realData,
    CVectorFloat& out_FFT_Re,
    CVectorFloat& out_FFT_Im,
    CVectorFloat& out_FFT_Mag
    )

Computes the FFT of a 2^N-size vector of real numbers, and returns the Re+Im+Magnitude parts of the first N/2+1 frequency bins (DC to Nyquist).

Computes real FFT of input data.

Parameters:

std::exception

If the length is not a power of two >= 2.

inRealData

Input real-valued signal (must be power of 2 length)

outFftRe

Real part of FFT output

outFftIm

Imaginary part of FFT output

outFftMag

Magnitude of FFT output

See also:

dft2_real

void mrpt::math::dft2_real(const CMatrixFloat& in_data, CMatrixFloat& out_real, CMatrixFloat& out_imag)

Compute the 2D Discrete Fourier Transform (DFT) of a real matrix, returning the real and imaginary parts separately.

2D real DFT

Parameters:

in_data

The N_1xN_2 matrix.

out_real

The N_1xN_2 output matrix which will store the real values (user has not to initialize the size of this matrix).

out_imag

The N_1xN_2 output matrix which will store the imaginary values (user has not to initialize the size of this matrix). If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.

inData

Input 2D real data (must be power of 2 dimensions)

outReal

Real part of output

outImag

Imaginary part of output

See also:

fft_real, idft2_real, dft2_complex

void mrpt::math::idft2_real(const CMatrixFloat& in_real, const CMatrixFloat& in_imag, CMatrixFloat& out_data)

Compute the 2D inverse Discrete Fourier Transform (DFT)

2D inverse real DFT

Parameters:

in_real

The N_1xN_2 input matrix with real values.

in_imag

The N_1xN_2 input matrix with imaginary values.

out_data

The N_1xN_2 output matrix (user has not to initialize the size of this matrix). Note that the real and imaginary parts of the FFT will NOT be checked to assure that they represent the transformation of purely real data: for power-of-two sizes, only half of the spectrum is used, assuming Hermitian symmetry; otherwise, the real part of the general inverse DFT is returned. If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.

See also:

fft_real, dft2_real

void mrpt::math::dft2_complex(
    const CMatrixFloat& in_real,
    const CMatrixFloat& in_imag,
    CMatrixFloat& out_real,
    CMatrixFloat& out_imag
    )

Compute the 2D Discrete Fourier Transform (DFT) of a complex matrix, returning the real and imaginary parts separately.

2D complex DFT

Parameters:

in_real

The N_1xN_2 matrix with the real part.

in_imag

The N_1xN_2 matrix with the imaginary part.

out_real

The N_1xN_2 output matrix which will store the real values (user has not to initialize the size of this matrix).

out_imag

The N_1xN_2 output matrix which will store the imaginary values (user has not to initialize the size of this matrix). If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.

See also:

fft_real, idft2_complex, dft2_real

void mrpt::math::idft2_complex(
    const CMatrixFloat& in_real,
    const CMatrixFloat& in_imag,
    CMatrixFloat& out_real,
    CMatrixFloat& out_imag
    )

Compute the 2D inverse Discrete Fourier Transform (DFT) of a complex matrix, the inverse of dft2_complex().

2D inverse complex DFT

Parameters:

in_real

The N_1xN_2 input matrix with real values.

in_imag

The N_1xN_2 input matrix with imaginary values.

out_real

The N_1xN_2 output matrix for real part (user has not to initialize the size of this matrix).

out_imag

The N_1xN_2 output matrix for imaginary part (user has not to initialize the size of this matrix). If the dimensions of the matrix are powers of two, the fast fourier transform (FFT) is used instead of the general algorithm.

See also:

fft_real, dft2_real, dft2_complex

void mrpt::math::cross_correlation_FFT(const CMatrixFloat& A, const CMatrixFloat& B, CMatrixFloat& out_corr)

Phase-correlation-like matching of two matrices using 2D FFTs: returns the magnitude of IDFT( DFT(B) / DFT(A) ), which for B being a circular shift of A has a sharp peak at the shift.

Cross-correlation using FFT.

Frequencies with a zero magnitude in DFT(A) are ignored.

Parameters:

std::exception

If sizes differ or are not powers of two.