MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::dsp::spectral::FFT< SampleType > Class Template Referencefinal

Class for performing real or complex 1D FFTs. More...

#include <marvin_FFT.h>

Public Types

using ValueType = typename getValueType<SampleType>::ValueType
 

Public Member Functions

 FFT (size_t order)
 
 ~FFT () noexcept
 
EngineType getEngineType () const noexcept
 
size_t getFFTSize () const noexcept
 
void forward (std::span< SampleType > source, std::span< std::complex< ValueType > > dest)
 
std::span< std::complex< ValueType > > forward (std::span< SampleType > source)
 
void inverse (std::span< std::complex< ValueType > > source, std::span< SampleType > dest)
 
std::span< SampleType > inverse (std::span< std::complex< ValueType > > source)
 

Detailed Description

template<RealOrComplexFloatType SampleType>
class marvin::dsp::spectral::FFT< SampleType >

Class for performing real or complex 1D FFTs.

The template type SampleType dictates whether the transform is real-only, or complex. Accepted types are float, double, std::complex<float>, and std::complex<double>. Performs no scaling on the forward data, and scales the inverse data by 1 / N.

The implementation is chosen at compile-time based on a few factors:

  • On macOS, will use the vDSP implementation from Accelerate.
  • On Windows, if Intel's IPP was found, will use the IPP implementation.
  • Also on Windows, if Intel's IPP was not found, will use the (slow and rough and ready) fallback.

The fallback implementation is still a WIP, and is actively being updated. Particularly, at the time of writing it only performs radix 2 transforms.

Member Typedef Documentation

◆ ValueType

template<RealOrComplexFloatType SampleType>
using marvin::dsp::spectral::FFT< SampleType >::ValueType = typename getValueType<SampleType>::ValueType

Constructor & Destructor Documentation

◆ FFT()

template<RealOrComplexFloatType SampleType>
marvin::dsp::spectral::FFT< SampleType >::FFT ( size_t order)
explicit

Constructs an instance of FFT, with the specified order. The size of the FFT will be 2^order, and the exponent is essentially there to ensure you give it a power-of-two size.

◆ ~FFT()

template<RealOrComplexFloatType SampleType>
marvin::dsp::spectral::FFT< SampleType >::~FFT ( )
noexcept

Because the PImpl is wrapped in a unique_ptr, we need a non-default destructor.

Member Function Documentation

◆ forward() [1/2]

template<RealOrComplexFloatType SampleType>
std::span< std::complex< ValueType > > marvin::dsp::spectral::FFT< SampleType >::forward ( std::span< SampleType > source)

Performs a forward transform on the data passed to source, and writes the results to an internal vector preallocated to the correct size.

Parameters
sourceThe input array-like to perform the transform on. Must be N points long.
Returns
A non owning view into the internal result vector. Note that consecutive calls to forward will overwrite this data, so if it's needed, make sure to copy it between calls. The same sizing rules from the other overload of forward apply.

◆ forward() [2/2]

template<RealOrComplexFloatType SampleType>
void marvin::dsp::spectral::FFT< SampleType >::forward ( std::span< SampleType > source,
std::span< std::complex< ValueType > > dest )

Performs a forward transform on the data passed to source, and writes the results to the array-like passed to dest.

Parameters
sourceThe input array-like to perform the transform on. must be N points long.
destAn array like to store the results in. If SampleType is a real (float or double), dest.size() should be (N / 2) + 1. In this case, DC is stored in bin 0's real component, and nyquist is stored in the final bin's real component.
If SampleType is a std::complex<>, dest.size() should be N.

◆ getEngineType()

template<RealOrComplexFloatType SampleType>
EngineType marvin::dsp::spectral::FFT< SampleType >::getEngineType ( ) const
nodiscardnoexcept

Checks the FFT implementation being used. Useful for verifying the FFT is set up as expected.

Returns
The engine type currently being used.

◆ getFFTSize()

template<RealOrComplexFloatType SampleType>
size_t marvin::dsp::spectral::FFT< SampleType >::getFFTSize ( ) const
nodiscardnoexcept

Retrieves the FFT Size (2^order passed into the constructor).

Returns
The fft size.

◆ inverse() [1/2]

template<RealOrComplexFloatType SampleType>
std::span< SampleType > marvin::dsp::spectral::FFT< SampleType >::inverse ( std::span< std::complex< ValueType > > source)

Performs an inverse transform on the data passed to source, and writes the results to an internal vector preallocated to the right size.

Parameters
sourceThe input array-like to perform the inverse transform on. Sizing rules from the other overload of inverse apply.
Returns
A non owning view into the internal result vector. Note that consecutive calls to inverse will overwrite this data, so if it's needed, make sure to copy it between calls.

◆ inverse() [2/2]

template<RealOrComplexFloatType SampleType>
void marvin::dsp::spectral::FFT< SampleType >::inverse ( std::span< std::complex< ValueType > > source,
std::span< SampleType > dest )

Performs an inverse transform on the data passed to source, and writes the results to the array-like passed to dest.
Scales the data internally by 1/N, so if you've done any scaling yourself, be sure to revert it before calling this function.

Parameters
sourceThe input array-like to perform the inverse transform on. If SampleType is a real (float or double), source.size() should be (N / 2) + 1, with DC is stored in bin 0's real component, and nyquist stored in the final bin's real component.
If SampleType is a std::complex<>, source.size() should be N.
destThe destination array-like to write the results to. Must be N points long.

The documentation for this class was generated from the following file: