FFTInterface Manual

About

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
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();
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// transform signal
genericFFT.Transform1D(signal.ToArray(), complexDFT.ToArray()) iferr_return;
// convert to amplitude 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 = i * resolution;
const maxon::Float amplitude = spectrum[i];
const maxon::Float normalizedAmplitude = (amplitude / maxon::Float(sampleCount));
DiagnosticOutput("@ Hz: @", frequency, normalizedAmplitude);
}

Further Reading