Pergunta

I'm writing an application that will analyze data from an accelerometer. One of the most important algorithms for this is obviously the FFT, and after much looking I found that Exocortexs library is one of the best for this.

Anyway, when I try to implement it I get this exception:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in Exocortex.DSP.v1.dll

Additional information: must be a power of 2

Here's the code:

class FFT
    {
        public Exocortex.DSP.ComplexF[] FourierTransform(List<double> vector)
        {
            //Dictionary<string, List<double>>

            int vectorLength = vector.Count;
            Exocortex.DSP.ComplexF[] complexData = new Exocortex.DSP.ComplexF[vectorLength];

            for (int i = 0; i < vectorLength; ++i)
            {
                complexData[i].Re = Convert.ToSingle(vector[i]); // Add your real part here
            //    complexData[i].Im = 2; // Add your imaginary part here
            }

            Exocortex.DSP.Fourier.FFT(complexData, Exocortex.DSP.FourierDirection.Forward);

            return complexData;

(This is really just a version of this example: Fast Fourier Transform in C#).

The problem might be as simple as the imaginary part of the acceleration since I assume this kind of data is only real but the answer, the FFT that is, is imaginary.

Thanks in advance!

Foi útil?

Solução

I'm gonna go out on a limb here and suggest that your vectorLength variable is not a a power of 2.

Try cropping your data such that its new length L = N^2, where integer N > 1. Does that get ride of the exception?

Are you expecting your signal to be periodic in nature? Is it attached to some mechanism rotating/shaking at fairly steady frequency? If not, what would you hope to get out of using an FFT?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top