# Complex all 0s

### 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) // this one should  be a real number!!!
F[1] = (-7.105427357601E-15, 2.66453525910038E-15)
F[2] = (-3.5527136788005E-15, 5.32907051820075E-15)
F[3] = (-8.88178419700125E-16, 7.105427357601E-15)
F[4] = (-7.39557098644699E-31, 8.88178419700125E-15)

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

why?

Saturday, August 24, 2013 3:33 PM

### Answers

• What do you mean by the comment "this one should be a real number"?  It is a real number.

What is in the F array at the start of this code?  I'm guessing it is (0,0).

You don't need the K loop as it can be simplified to

var sumDSP2 = add all the values of DSP2 together;

F[F3] += 16*sumDSP2*(a complex constant);

But sumDSP2 == 0 (try adding all the elements together).  So your F3 loop can be simplified to

for (int F3 = 0; F3 <= 4; F3++) F[F3] += 0;

which means you can delete the F3 loop.  Which leaves you with no code!  The F array is not altered by this code (except for some rounding errors introduced by all the exponential work).

Paul Linton

Tuesday, August 27, 2013 4:31 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:45 AM

### All replies

• Tuesday, August 27, 2013 1:20 AM
• What do you mean by the comment "this one should be a real number"?  It is a real number.

What is in the F array at the start of this code?  I'm guessing it is (0,0).

You don't need the K loop as it can be simplified to

var sumDSP2 = add all the values of DSP2 together;

F[F3] += 16*sumDSP2*(a complex constant);

But sumDSP2 == 0 (try adding all the elements together).  So your F3 loop can be simplified to

for (int F3 = 0; F3 <= 4; F3++) F[F3] += 0;

which means you can delete the F3 loop.  Which leaves you with no code!  The F array is not altered by this code (except for some rounding errors introduced by all the exponential work).

Paul Linton

Tuesday, August 27, 2013 4:31 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:45 AM