FFTInterface Manual

内容表

关于

The fast Fourier transform (FFT) is used to analyze a given signal in order to transform it into the frequency domain. The maxon::FFTInterface gives access to implementations of various algorithms.

Classes

Various implementations of the FFT are registered at maxon::FFTClasses :

  • maxon::FFTClasses::Generic: Generic Cinema 4D implementation.
  • maxon::FFTClasses::Kiss: Fast FFT algorithm using the KISS library.
  • maxon::FFTClasses::Cooley: Cooley Tukey algorithm.

FFTInterface

The maxon::FFTInterface provides the functions to perform the FFT:

// This example shows how to use FFT to get the spectrum of a signal.

// synthesize a signal of one second

// signal parameters const maxon::Int sampleCount = 500; const maxon::Float sampleTime = 1.0; // seconds const maxon::Float samplingFrequency = maxon::Float (sampleCount) / sampleTime;

const maxon::Float step = (2 * maxon::PI ) / maxon::Float (sampleCount);

// create signal maxon::BaseArray<maxon::Float> signal; signal. EnsureCapacity (sampleCount) iferr_return ;

for ( maxon::Int i = 0; i < sampleCount; ++i) { const maxon::Float pos = maxon::Float (i) * step; maxon::Float sample = 0.0;

// 1Hz component sample += maxon::Sin (pos); // 2Hz component sample += maxon::Sin (pos * 2); // 4Hz component sample += maxon::Sin (pos * 4) * 0.5; // 8Hz component sample += maxon::Sin (pos * 8) * 0.5; signal. Append (sample) iferr_return ; }

// perform FFT

// create FFTRef const maxon::FFTRef genericFFT = maxon::FFTClasses::Generic().Create() iferr_return ;

// check if this FFT implementation supports Transform1D() const maxon::FFT_SUPPORT options = genericFFT.GetSupportOptions(); if (!(options & maxon::FFT_SUPPORT::TRANSFORM_1D )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// transform signal maxon::BaseArray<maxon::Complex64> complexDFT; genericFFT.Transform1D(signal. ToArray (), complexDFT. ToArray ()) iferr_return ;

// convert to amplitude spectrum maxon::BaseArray<maxon::Float> spectrum; spectrum. EnsureCapacity (complexDFT. GetCount ()) iferr_return ; for ( const auto DFT : complexDFT) { const maxon::Float amplitude = DFT.GetLength(); spectrum. Append (amplitude) iferr_return ; }

// display spectrum

// spectrum resolution const maxon::Float resolution = samplingFrequency / sampleCount; const maxon::Float spectrumRange = maxon::Float (spectrum. GetCount ()); const maxon::Int maxFrequencyIndex = maxon::Int (spectrumRange * 0.5); for ( maxon::Int i = 0; i < maxFrequencyIndex; ++i) { const maxon::Float frequency = ( maxon::Float )i * resolution; const maxon::Float amplitude = spectrum[i]; const maxon::Float normalizedAmplitude = (amplitude / maxon::Float (sampleCount)); DiagnosticOutput ( "@ Hz: @" , frequency, normalizedAmplitude); }

延伸阅读

maxon::FFT_SUPPORT
FFT_SUPPORT
Flags for GetSupportOptions()
定义: fft.h:24
maxon::ArrayBase< BaseArray< T, BASEARRAY_DEFAULT_CHUNK_SIZE, BASEARRAYFLAGS::NONE, DefaultAllocator >, T, BaseArrayData< T, DefaultAllocator, STD_IS_REPLACEMENT(empty, DefaultAllocator)>, DefaultCompare >::ToArray
ArrayImpl< BaseArray< T, BASEARRAY_DEFAULT_CHUNK_SIZE, BASEARRAYFLAGS::NONE, DefaultAllocator > & > ToArray()
定义: array.h:1602
iferr_return
#define iferr_return
定义: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
maxon::Float
Float64 Float
定义: apibase.h:193
maxon::BaseArray
定义: basearray.h:366
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::PI
static constexpr Float64 PI
floating point constant: PI
定义: apibasemath.h:139
maxon::BaseArray::GetCount
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
定义: basearray.h:527
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
定义: basearray.h:569
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184
maxon::Sin
MAXON_ATTRIBUTE_FORCE_INLINE Float32 Sin(Float32 val)
Calculates the sine of a value.
定义: apibasemath.h:198
maxon::FFT_SUPPORT::TRANSFORM_1D
@ TRANSFORM_1D
Component supports 1D transformation.
maxon::BaseArray::EnsureCapacity
ResultMem EnsureCapacity(Int requestedCapacity, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
定义: basearray.h:1188

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1