Extreme Optimization™: Complexity made simple.

Math and Statistics
Libraries for .NET

  • Home
  • Features
    • Math Library
    • Vector and Matrix Library
    • Statistics Library
    • Performance
    • Usability
  • Documentation
    • Introduction
    • Math Library User's Guide
    • Vector and Matrix Library User's Guide
    • Data Analysis Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Resources
    • Downloads
    • QuickStart Samples
    • Sample Applications
    • Frequently Asked Questions
    • Technical Support
  • Blog
  • Order
  • Company
    • About us
    • Testimonials
    • Customers
    • Press Releases
    • Careers
    • Partners
    • Contact us
Introduction
Deployment Guide
Nuget packages
Configuration
Using Parallelism
Expand Mathematics Library User's GuideMathematics Library User's Guide
Expand Vector and Matrix Library User's GuideVector and Matrix Library User's Guide
Expand Data Analysis Library User's GuideData Analysis Library User's Guide
Expand Statistics Library User's GuideStatistics Library User's Guide
Expand Data Access Library User's GuideData Access Library User's Guide
Expand ReferenceReference
  • Extreme Optimization
    • Features
    • Solutions
    • Documentation
    • QuickStart Samples
    • Sample Applications
    • Downloads
    • Technical Support
    • Download trial
    • How to buy
    • Blog
    • Company
    • Resources
  • Documentation
    • Introduction
    • Deployment Guide
    • Nuget packages
    • Configuration
    • Using Parallelism
    • Mathematics Library User's Guide
    • Vector and Matrix Library User's Guide
    • Data Analysis Library User's Guide
    • Statistics Library User's Guide
    • Data Access Library User's Guide
    • Reference
  • Mathematics Library User's Guide
    • General Classes
    • Mathematical Functions
    • Complex Numbers
    • Arbitrary Precision Arithmetic
    • Automatic Differentiation
    • Curves and Interpolation
    • Curve Fitting
    • Solving Equations
    • Optimization
    • Calculus
    • Fast Fourier Transforms
    • Random Numbers
    • Generic Arithmetic
    • Appendices
  • Fast Fourier Transforms
    • One-Dimensional Fast Fourier Transforms
    • Window Functions
    • Two-Dimensional Fast Fourier Transforms
  • One-Dimensional Fast Fourier Transforms

One-Dimensional Fast Fourier Transforms

Extreme Optimization Numerical Libraries for .NET Professional
One-dimensional FFT's

The computation of an FFT involves some preprocessing steps. When multiple FFT's of the same length need to be computed, it is more efficient to use an FftT object, which caches the results of these calculations.

Real FFT's

Use the static CreateReal(Int32) method of the FftT class to create an FftT object that can be used to compute one-dimensional real FFT's. The method takes one argument: the length of the signal.

C#
VB
C++
F#
Copy
int N = 1024;
Fft<double> realFft = Fft<double>.CreateReal(N);
Dim N As Integer = 1024
Dim realFft As Fft(Of Double) = Fft(Of Double).CreateReal(N)

No code example is currently available or this language may not be supported.

let N = 1024
let realFft = Fft<double>.CreateReal(N)

The FftT object has several properties that can be used to fine-tune the transform. The ForwardScaleFactor property sets or gets the scale factor used in the forward transform. The default is 1/N where N is the number of points in the transform. The BackwardScaleFactor property sets or gets the scale factor used in the backward or inverse transform. The default is 1. There is also a InPlace property, which is not valid for real FFT's.

C#
VB
C++
F#
Copy
realFft.ForwardScaleFactor = 1.0 / Math.Sqrt(N);
realFft.BackwardScaleFactor = realFft.ForwardScaleFactor;
realFft.ForwardScaleFactor = 1.0 / Math.Sqrt(N)
realFft.BackwardScaleFactor = realFft.ForwardScaleFactor

No code example is currently available or this language may not be supported.

realFft.ForwardScaleFactor <- 1.0 / Math.Sqrt(float N)
realFft.BackwardScaleFactor <- realFft.ForwardScaleFactor

These properties can be changed up to the point where the FftT object is committed. This happens when one of the transform methods is called for the first time. The Committed property indicates whether this is the case.

The actual transform is computed by two methods: ForwardTransform and BackwardTransform. As the name implies, these methods perform the forward and backward (inverse) transform. They have seven overloads, four of which apply to real transforms.

The first overload for ForwardTransform takes one argument: a VectorT that specifies the signal to transform. It returns a ComplexConjugateSignalVectorT, a special type of complex vector that enforces the symmetry properties of real FFT's and does not store any duplicate information. The corresponding BackwardTransform method takes a ComplexConjugateSignalVectorT and returns a VectorT.

C#
VB
C++
F#
Copy
var r1 = Vector.Create(1000, i => 1.0 / (1 + i));
var c1 = realFft.ForwardTransform(r1);
var r2 = realFft.BackwardTransform(c1);
Dim r1 = Vector.Create(1000, Function(i) 1.0 / (1 + i))
Dim c1 = realFft.ForwardTransform(r1)
Dim r2 = realFft.BackwardTransform(c1)

No code example is currently available or this language may not be supported.

let r1 = Vector.Create(1000, fun i -> 1.0 / (1.0 + float i))
let c1 = realFft.ForwardTransform(r1)
let r2 = realFft.BackwardTransform(c1)

The second pair of overloads is similar to the first, but takes a second parameter that is used to store the result. For the forward transform, the parameters are a VectorT and a ComplexConjugateSignalVectorT. For the backward transform, the parameters are a ComplexConjugateSignalVectorT and a VectorT.

C#
VB
C++
F#
Copy
var c2 = new ComplexConjugateSignalVector<double>(r1.Length);
realFft.ForwardTransform(r1, c2);
var r3 = Vector.Create<double>(c2.Length);
realFft.BackwardTransform(c2, r3);
Dim c2 = New ComplexConjugateSignalVector(Of Double)(r1.Length)
realFft.ForwardTransform(r1, c2)
Dim r3 = Vector.Create(Of Double)(c2.Length)
realFft.BackwardTransform(c2, r3)

No code example is currently available or this language may not be supported.

let c2 = new ComplexConjugateSignalVector<double>(r1.Length)
realFft.ForwardTransform(r1, c2)
let r3 = Vector.Create<double>(c2.Length)
realFft.BackwardTransform(c2, r3)

The third pair of overloads is similar to the second, but allows any vector types for the arguments. The forward transform takes any real and complex VectorT. The backward transform takes the same parameter types in reverse order.

The final overload is similar to the third, but allows you to specify whether to return a one-sided or a two-sided transform. Because of symmetry, only the first N/2+1 terms of a real FFT are independent. The remaining terms are the complex conjugate of terms in the first half. A one-sided transform returns only the first N/2+1 terms of the transform, while a two-sided transform returns the full FFT vector. This fourth overload of ForwardTransform and BackwardTransform takes a third parameter: a RealFftFormat value with possible values OneSided and TwoSided. The length of the complex vector argument must equal N/2+1 for a one-sided transform.

C#
VB
C++
F#
Copy
var c3 = Vector.Create<Complex<double>>(r1.Length / 2 + 1);
realFft.ForwardTransform(r1, c3, RealFftFormat.OneSided);

var r4 = Vector.Create<double>(r1.Length);
realFft.BackwardTransform(c3, r4, RealFftFormat.OneSided);
Dim c3 = Vector.Create(Of Complex(Of Double))(r1.Length / 2 + 1)
realFft.ForwardTransform(r1, c3, RealFftFormat.OneSided)

Dim r4 = Vector.Create(Of Double)(r1.Length)
realFft.BackwardTransform(c3, r4, RealFftFormat.OneSided)

No code example is currently available or this language may not be supported.

let c3 = Vector.Create<Complex<double>>(r1.Length / 2 + 1)
realFft.ForwardTransform(r1, c3, RealFftFormat.OneSided)

let r4 = Vector.Create<double>(r1.Length)
realFft.BackwardTransform(c3, r4, RealFftFormat.OneSided)
Complex FFT's

Use the static CreateComplex(Int32) method of the FftT class to create an FftT object that can be used to compute one-dimensional real FFT's. The method takes one argument: the length of the signal.

C#
VB
C++
F#
Copy
int N = 1024;
Fft<double> complexFft = Fft<double>.CreateComplex(N);
Dim N As Integer = 1024
Dim complexFft As Fft(Of Double) = Fft(Of Double).CreateComplex(N)

No code example is currently available or this language may not be supported.

let N = 1024
let complexFft = Fft<double>.CreateComplex(N)

Complex FFT's are simpler in that the Fourier transform of a complex signal is always complex also. This means that the transform can be done in-place. To perform a transform in place, set the InPlace property to true.

The transformation methods, ForwardTransform and BackwardTransform, have three overloads that apply to complex transforms. The first overload takes a single complex VectorT and returns a complex VectorT that is the forward or backward Fourier transform of its argument.

C#
VB
C++
F#
Copy
var c1 = Vector.Create(N, i => new Complex<double>(1.0 / (1 + i), i));
var c2 = complexFft.ForwardTransform(c1);
var c3 = complexFft.BackwardTransform(c2);
Dim c1 = Vector.Create(N, Function(i) New Complex(Of Double)(1.0 / (1 + i), i))
Dim c2 = complexFft.ForwardTransform(c1)
Dim c3 = complexFft.BackwardTransform(c2)

No code example is currently available or this language may not be supported.

let c1 = Vector.Create(N, 
            fun i -> new Complex<double>(1.0 / (1.0 + float i), float i))
let c2 = complexFft.ForwardTransform(c1)
let c3 = complexFft.BackwardTransform(c2)

The second pair of overloads take two complex VectorT objects. They compute the forward or backward transform of the first argument and return it in the second. The third pair of overloads is more general than the second, taking two complex vectors of any type.

C#
VB
C++
F#
Copy
var c4 = Vector.Create<Complex<double>>(c1.Length);
complexFft.ForwardTransform(c1, c4);
var c5 = Vector.Create<Complex<double>>(c4.Length);
complexFft.BackwardTransform(c4, c5);
Dim c4 = Vector.Create(Of Complex(Of Double))(c1.Length)
complexFft.ForwardTransform(c1, c4)
Dim c5 = Vector.Create(Of Complex(Of Double))(c4.Length)
complexFft.BackwardTransform(c4, c5)

No code example is currently available or this language may not be supported.

let c4 = Vector.Create<Complex<double>>(c1.Length)
complexFft.ForwardTransform(c1, c4)
let c5 = Vector.Create<Complex<double>>(c4.Length)
complexFft.BackwardTransform(c4, c5)

Since the Fourier transform of a complex vector is again a complex vector of the same length, it is possible to perform a Fourier transform in-place. The ForwardTransformInPlace and BackwardTransformInPlace methods perform this operation.

C#
VB
C++
F#
Copy
complexFft.ForwardTransformInPlace(c1);
complexFft.BackwardTransformInPlace(c1);
complexFft.ForwardTransformInPlace(c1)
complexFft.BackwardTransformInPlace(c1)

No code example is currently available or this language may not be supported.

complexFft.ForwardTransformInPlace(c1)
complexFft.BackwardTransformInPlace(c1)

Copyright (c) 2004-2021 ExoAnalytics Inc.

Send comments on this topic to support@extremeoptimization.com

Copyright © 2004-2021, Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual Studio.NET, and the Optimized for Visual Studio logo
are registered trademarks of Microsoft Corporation.