# Fast Fourier Transforms

**Numerics.NET**
provides a set of classes for computing
the Discrete Fourier Transform of real and complex signals.

## One time FFT's

When only very few Fourier transforms of a given length need to be computed, the Vector<T> class provides methods that can perform this computation in one line of code.

To compute the Fourier transform of a real sequence, use FourierTransform. This method takes as its only argument a Vector<T> that specifies the signal that is to be transformed. It returns a Vector<T> of Complex<T> that contains the transform.

The inverse transform is computed using the
InverseFourierTransform<T> method.
This method takes a complex
Vector<T>
and returns a Vector<T>.
Only the first *n/2+1* elements are used in the computation.

The following example computes the Fourier transform of a short vector, and then computes the inverse transform. The result is a vector identical to the first one:

```
var v = Vector.CreateFromFunction(1024, i => Math.Sin(0.05 * i));
var w = Vector.FourierTransform(v);
```

For complex signals, the Vector<T> of Complex<T> class has a FourierTransform and a InverseFourierTransform<T> method. Each method takes one argument: a Vector<T> of Complex<T>, and also returns a Vector<T> of Complex<T>.

## Multiple FFT's of the same size

In many applications, many Fourier transforms of the same length need to be calculated. To make this process more efficient, you can use Fft<T> objects, that represent the implementation of an FFT of a given length. Fft<T> objects are created through an FftOperations<T>.

### FFT Providers

The FftOperations<T> is the base class for accessing a specific set of FFT algorithms. Two FFT providers are shipped with the library: a managed provider that uses 100% managed code, and a 'native' provider that uses hand-optimized unmanaged code and is an order of magnitude faster for longer transforms.

In order to use the native provider, the assembly containing the native FFT code for the current processor architecture must be present. This assembly is called Numerics.NET.Native.Mkl.dll. If this assembly cannot be found, the managed provider is used instead.

You can access the two providers through the ManagedImplementation and NativeImplementation properties.

The managed provider has two additional properties that indicate when to switch to the native provider (if it is present). The RealManagedThresholdLength property specifies the shortest length of a real FFT for which the native FFT provider will be used. The default is 64. The ComplexManagedThresholdLength property specifies the shortest length of a complex FFT for which the native FFT provider will be used. The default is 32.

Using FFT providers, you can obtain Fft<T> objects for one-dimensional transforms and Fft2D<T> objects for two-dimensional transforms. The Fft<T> and Fft2D<T> classes implement System.IDisposable, so you should always use a using statement or call Dispose once you are done using the object.