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

FastFourierTransform not working right

Jul 28, 2014 at 5:20 PM
ok I am going this:
dataGridView1.Rows.Clear();
            dataGridView2.Rows.Clear();
            double Frequency3 = Convert.ToDouble(textBox1.Text);
            double Frequency2 = Convert.ToDouble(textBox2.Text);
            double Peak3 = 2; //Convert.ToDouble(PeakTXT3.Text);
            Complex [] list = new Complex[16384 * 2];
            double[] F1 = new double[16384 * 2];
            for (int n = 0; n < (16384 * 2); n++)
            {
                list[n].X  = (float)(Peak3 * (Math.Sin((Math.PI * n * Frequency3 / 44100D))) + Peak3 * (Math.Sin((Math.PI * n * Frequency2 / 44100D))));
               
            }
            FastFourierTransform temp = new FastFourierTransform();
            FastFourierTransform.FFT(true,list.Length,list );
            for (int i = 0; i < list.Length; i++)
            {
                if (((i / list.Length) * 44100) >= (44100 / 2))
                {
                    break;

                }
                if (list[i].X > 0)
                {
                    F1[i] = ((double)i / (16384D * 2D)) * 44100D;
                    dataGridView1.Rows.Add(F1[i],list[i].X);
                }
            }
        }
so i tested it with
frequency3 = 500HZ
frequency2 = 180Hz
and when i print it out
it has peaks at
69.98291015625Hz
285.31494140625Hz
777.886962890625HZ
994.564819335938 HZ
...

and not
500HZ or 180Hz
so am I doing something wrong ?
or what ?

oh I am using NAudio Version 1.6.0.0
is that ok?
Coordinator
Aug 20, 2014 at 2:04 PM
the output of FFT is a complex number. You need to take its magnitude rather than just looking at the real portion. It would be a good idea to do some research on FFTs. They are quite complicated for people new to signal processing. You may also need to apply a window function before applying the FFT.