## One-Dimensional Fast Fourier Transforms | Extreme Optimization Numerical Libraries for .NET Professional |

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
Fft

Use the static
CreateReal(Int32)
method of the
Fft

The Fft

```
realFft.ForwardScaleFactor = 1.0 / Math.Sqrt(N);
realFft.BackwardScaleFactor = realFft.ForwardScaleFactor;
```

These properties can be changed up to the point where the
Fft

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 Vector

var r1 = Vector.Create(1000, i => 1.0 / (1 + i)); var c1 = realFft.ForwardTransform(r1); var 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
Vector

var c2 = new ComplexConjugateSignalVector<double>(r1.Length); realFft.ForwardTransform(r1, c2); var 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
Vector

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.

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);

Use the static
CreateComplex(Int32)
method of the
Fft

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 Vector

var c1 = Vector.Create(N, i => new Complex<double>(1.0 / (1 + i), i)); var c2 = complexFft.ForwardTransform(c1); var c3 = complexFft.BackwardTransform(c2);

The second pair of overloads take two complex
Vector

var c4 = Vector.Create<Complex<double>>(c1.Length); complexFft.ForwardTransform(c1, c4); var 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.

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.