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
  • 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

Skip Navigation LinksHome»Documentation»Mathematics Library User's Guide»Fast Fourier Transforms»Two-Dimensional Fast Fourier Transforms

Two-Dimensional Fast Fourier Transforms

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

To compute multiple FFT's of the same length, it is more efficient to use an Fft2DT object from a FftOperationsT. FFT providers were discussed in the previous section.

Real FFT's

Use the static CreateReal(Int32, Int32) method of the Fft2DT class to create an Fft2DT object that can be used to compute two-dimensional real FFT's. The method takes two arguments: the number of rows and columns in the data.

C#
VB
C++
F#
Copy
int N = 1024;
var fft2d = Fft2D<double>.CreateReal(N, N);
Dim N As Integer = 1024
Dim fft = Fft2D(Of Double).CreateReal(N, N)

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

let N = 1024
let fft2d = Fft2D<double>.CreateReal(N, N)

Similar to the 1-dimensional case, the Fft2DT 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.

These properties can be changed up to the point where the Fft2DT 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 MatrixT that specifies the signal to transform. It returns a ComplexConjugateSignalMatrixT, a special type of complex matrix that enforces the symmetry properties of real FFT's and does not store any duplicate information. The corresponding BackwardTransform method takes a ComplexConjugateSignalMatrixT and returns a MatrixT.

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 MatrixT and a ComplexConjugateSignalMatrixT. For the backward transform, the parameters are a ComplexConjugateSignalMatrixT and a MatrixT.

The third pair of overloads is similar to the second, but allows any matrix types for the parameters. The forward transform takes any real and complex MatrixT. The backward transform takes the same argument 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 matrix. 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 matrix argument must equal N/2+1 for a one-sided transform.

C#
VB
C++
F#
Copy
var m = Matrix.Create(36, 56, (i, j) =>
    Math.Exp(-0.1 * i) * Math.Sin(0.01 * (i * i + j * j - i * j)));
var mFft = Matrix.Create<Complex<double>>(m.RowCount, m.ColumnCount);
using (Fft2D<double> fft2 = Fft2D<double>.CreateReal(m.ColumnCount, m.ColumnCount))
{
    fft2.ForwardTransform(m, mFft);
    Console.WriteLine("First few terms of fft(m):");
    Console.WriteLine(mFft.GetSubmatrix(0, 4, 0, 4).ToString("F4"));
    fft2.BackwardTransform(mFft, m);
}
Dim m = Matrix.Create(Of Double)(36, 56,
    Function(i, j) Math.Exp(-0.1 * i) * Math.Sin(0.01 * (i * i + j * j - i * j)))
Dim mFft = Matrix.Create(Of Complex(Of Double))(m.RowCount, m.ColumnCount)
Using fft2 As Fft2D(Of Double) = Fft2D(Of Double).CreateReal(m.ColumnCount, m.ColumnCount)
    fft2.ForwardTransform(m, mFft)
    Console.WriteLine("First few terms of fft(m):")
    Console.WriteLine(mFft.GetSubmatrix(0, 4, 0, 4).ToString("F4"))
    fft2.BackwardTransform(mFft, m)
End Using

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

let m = 
    let init i j =
        exp(-0.1 * (float i)) * sin(0.01 * float (i * i + j * j - i * j))
    Matrix.Create<float>(36, 56, init)
let mFft = Matrix.Create<Complex<double>>(m.RowCount, m.ColumnCount)
use fft2 = Fft2D<double>.CreateReal(m.ColumnCount, m.ColumnCount)
fft2.ForwardTransform(m, mFft)
Console.WriteLine("First few terms of fft(m):")
Console.WriteLine(mFft.GetSubmatrix(0, 4, 0, 4).ToString("F4"))
fft2.BackwardTransform(mFft, m)
Complex FFT's

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

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 MatrixT and returns a complex MatrixT that is the forward or backward Fourier transform of its argument.

The second pair of overloads take two complex MatrixT 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.

Copyright (c) 2004-2023 ExoAnalytics Inc.

Send comments on this topic to support@extremeoptimization.com

Copyright © 2004-2023, 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.