none
Complex all 0s DFT function

    Question

  • I am running this cold

                int N2 = 16 - 1;
                for (int F3 = 0; F3 <= 4; F3++)
                {
                    for (int K = 0; K <= N2; K++)
                    {
                        F[F3] = F[F3] + (Complex)DSP2.ElementAt(K) * Complex.Exp((-Complex.ImaginaryOne * Math.PI * 2D * F3) / 16D);
                    }
                   }

    and I am getting this :

    this is DSP2:

    0
    7.07106781186547
    10
    7.07106781186548
    1.22460635382238E-15
    -7.07106781186547
    -10
    -7.07106781186548
    -2.44921270764475E-15
    7.07106781186547
    10
    7.07106781186548
    3.67381906146713E-15
    -7.07106781186548
    -10
    -7.07106781186548
    -4.89842541528951E-15

    This is F[]

    F[0] = (-8.88178419700125E-15, 0) 
    F[1] = (-7.105427357601E-15, 2.66453525910038E-15)
    F[2] = (-3.5527136788005E-15, 5.32907051820075E-15)// this should not be 0 
    F[3] = (-8.88178419700125E-16, 7.105427357601E-15)
    F[4] = (-7.39557098644699E-31, 8.88178419700125E-15)

    Did I do some thing wrong ?

    now I am getting all 0 or number very close to 0

    why?

    Saturday, August 24, 2013 3:43 PM

Answers

All replies

  • ok this is the have now

     double temp; 
                 int samplingFrequency = 120;
                 //int numberValues = 240;
                Complex [] temp1 = new Complex[16];
                int[] temp2 = new int[16];
                 DSP2 = new List<double>();
                 double f4 = 10 / (2 * Math.PI);
                 double t1;
                for (int i = 0; i <= 16; i++)
                {
                    t1 = (double)i / (double)samplingFrequency;
                    temp =10* Math.Sin( 10  * Math.PI* t1 );
                    DSP2.Add(temp);
                    test.Text = test.Text + Convert.ToString(temp) + "\n";
                }

                void DFT1()
            {
                int N2 = 16 - 1;
                for (int F3 = 0; F3 < 11; F3++)
                {
                    for (int K = 0; K <= N2; K++)
                    {
                        F[F3] = F[F3] + (Complex)DSP2.ElementAt(K) * Complex.Exp((-Complex.ImaginaryOne * Math.PI * 2D * F3*K) / 16D);
                    }
                   }

                for (int t = 0; t < 11; t++)
                {
                    test.Text = test.Text + "F[" + t + "] = " + F[t]+ "\n";

                }
            }

    and when i run it I get  this 

               0
    2.58819045102521
    5
    7.07106781186547
    8.66025403784439
    9.65925826289068
    10
    9.65925826289068
    8.66025403784439
    7.07106781186548
    5
    2.58819045102521
    1.22460635382238E-15
    -2.58819045102521
    -5
    -7.07106781186547
    -8.66025403784438
    F[0] = (61.2982828643608, 0)
    F[1] = (-41.8366730450269, -39.4105572999064)
    F[2] = (-3.1698729810778, -11.8301270189222)
    F[3] = (1.0019347295909, -6.85909626534755)
    F[4] = (2.32050807568879, -4.48287736084026)
    F[5] = (2.89076063031674, -2.96640090543989)
    F[6] = (3.16987298107781, -1.83012701892219)
    F[7] = (3.30296153374168, -0.876845788621259)
    F[8] = (3.34273328701673, 1.43009813832102E-14)
    F[9] = (3.30296153374167, 0.876845788621271)
    F[10] = (3.16987298107778, 1.8301270189222)

    F[10] is the only one that  have a value that i not 0 

    not F[0]

    Saturday, August 24, 2013 5:53 PM
  • What is the meaning of DPS2 in your code? Are you using Complex Structure?

    Tuesday, August 27, 2013 1:19 AM
  • I am not fully sure about your issue because some code that might be important is missing.

     Here are some links:

    http://www.codeproject.com/Articles/590638/Quick-Fourier-Transformation

    http://stackoverflow.com/questions/7582744/discrete-fourier-transform

    Hope this info will help you.

    Wednesday, August 28, 2013 1:44 AM
  • I explained why your first code gives zero in the other post.

    Do you have a question about your second post?

    "F[10] is the only one that have a value that I not 0"

    What does this mean?  All elements of F are non-zero.

    "not F[0]"

    ???

    Do you have a question?


    Paul Linton

    Wednesday, August 28, 2013 3:46 AM