This project has moved. For the latest updates, please go here.

Where should I look for a FFT class?

Apr 13, 2011 at 6:02 AM

I am really graceful to find such useful library.


I am trying to do a FFT on some time series discrete data. I am not familiar to FFT.

From what I have learned recently, DFT is for transforming discrete data into a frequency domain function.

Then the processed signal are being able to divide into signals with different frequency. Could be use to filter out the noise signal.

And FFT is Fast DFT, which factorize the function f(t) into complex number (or sin/cos??) achieving N log N complexity.


There is a FFT support according to the release notes.

I am reading the documentation website right now, don't know which category which FFT falls into.

Complex Numbers, is it?


By the way, I see some book reading suggestion on the documentation website.

If I want to learn more about time series and discrete data modeling, what book would you suggest?


Thank you very much.


Apr 13, 2011 at 6:56 AM

The FFT class is FourierTansformer in the Meta.Numerics.SignalProcessing namespace. Here is the documentation. It contains an example, which I'll go ahead and reproduce here:

// Create a Fourier transformer for length-6 series
FourierTransformer ft = new FourierTransformer(6);
// Create a length-6 series and transform it
Complex[] x = new Complex[] { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 };
Complex[] xt = ft.Transform(x);
// Re-use the same transformer to transform a different  series
Complex[] y = new Complex[] { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
Complex[] yt = ft.Transform(y);
// Transform them back
Complex[] xtt = ft.InverseTransform(xt);
Complex[] ytt = ft.InverseTransform(yt);

Basically, you new up a FourierTransform class for the series length you want to transform, then hand your input data as a Complex[] to the Transform method. If your data is actually real, as it is in most applications, that's fine: the Complex numbers in your input array will just happen to have zero imaginary parts, as they do in the example code above.

The classic reference on time series analysis is Box and Jenkin's Time Series Analysis. It's pretty advanced, though. If you just want a quick practical introduction to discrete Fourier transform, take a look at Chapters 12 and 13 of Numerical Recipies.

Apr 13, 2011 at 8:31 AM
Edited Apr 13, 2011 at 8:42 AM

Thank you. great sample.

And thank you for those recommended books too.


I understand the sample, just input my discrete data and call Transform().

How do I get the value of a specific time n(t) from one of the many frequency components?

Apr 14, 2011 at 12:09 AM

You can't get a signal value at a particular time from the frequency-series, other than by transforming back to the time-series using InverseTransform. In the frequency domain, time doesn't exist, and in the time domain, frequency doesn't exist. What I think you are asking actually: how do the indexes of the frequency-array map to frequencies (not times)? Is that right?

Remember there are two waves for each frequency f, a positive frequency wave exp(+2 pi f t j) and a negative frequency wave exp(-2 pi f t j). If your sampling interval is T, then xt[k] is the amplitude of the component with positive frequency (k / N T) and xt[N-k] is the amplitude of the component with negative frequency (-k / N T). That means that the amplitude of the zero-frequency (constant) component is in xt[0], and that the highest-frequency component you can measure is in x[N/2] has frequency (1/2T), which is called the Nyquist frequency.

Often people want to know what is the total power in both the positive and negative waves (alternatively, in both the sine and cosine waves) of a given frequency. That's called a power spectrum. For the frequency f = k / N T, the power is proportional to the sum of the squares of the amplitudes of the positive and negative frequency components, i.e. MoreMath.Pow(ComplexMath.Abs(xt[k]), 2) + MoreMath.Pow(ComplexMath.Abs(xt[N-k]), 2).