Hello. I have been testing my Discrete Fourier Transform program for 1 dimensional data (written in using C++).

For the following test input data,

REAL[0]= 0.000, IMAG[0]= 0.000
REAL[1]= +1.000, IMAG[1]= 0.000
REAL[2]= 0.000, IMAG[2]= 0.000
REAL[3]= 0.000, IMAG[3]= 0.000
REAL[4]= 0.000, IMAG[4]= 0.000
REAL[5]= 0.000, IMAG[5]= 0.000
REAL[6]= 0.000, IMAG[6]= 0.000
REAL[7]= 0.000, IMAG[7]= 0.000

The correct expected results are(should have constant magnitude in the transform domain; in this case, the squareroot of "real[x] squared imag[x] squared" equals 0.125 in every case):

REAL[0]= 0.125, IMAG[0]= +0.000
REAL[1]= +0.088, IMAG[1]= -0.088
REAL[2]= +0.000, IMAG[2]= -0.125
REAL[3]= -0.088, IMAG[3]= -0.088
REAL[4]= -0.125, IMAG[4]= +0.000
REAL[5]= -0.088, IMAG[5]= +0.088
REAL[6]= +0.000, IMAG[6]= +0.125
REAL[7]= +0.088, IMAG[7]= +0.088

However, my program returns the following results:

Real[0]: 0.125 Imag[0]: 0
Real[1]: 0.0883883 Imag[1]: -0.0883883
Real[2]: 7.65404e-018 Imag[2]: -0.125
Real[3]: -0.0883883 Imag[3]: -0.0883883
Real[4]: -0.125 Imag[4]: -1.53081e-017
Real[5]: -0.0883883 Imag[5]: 0.0883883
Real[6]: -2.29621e-017 Imag[6]: 0.125
Real[7]: 0.0883883 Imag[7]: 0.0883883

Below is my program. I would appreciate guidance in learning where the error lies and how to fix my this, thank you!

bool inverse = false;
int n = 8;
double gRe[8] = {0,1,0,0,0,0,0,0};
double gIm[8] = {0,0,0,0,0,0,0,0};
double GRe[8] = {0,0,0,0,0,0,0,0};
double GIm[8] = {0,0,0,0,0,0,0,0};
for(int w = 0; w < n; w++)
{
GRe[w] = GIm[w] = 0;
for(int x = 0; x < n; x++)
{
double a = -2 * pi * w * x / float(n);
if(inverse) a = -a;
double ca = cos(a);
double sa = sin(a);
GRe[w] += gRe[x] * ca - gIm[x] * sa;
GIm[w] += gRe[x] * sa + gIm[x] * ca;
}
if(!inverse)
{
GRe[w] /= n;
GIm[w] /= n;
}
}