-
October 19th, 2015, 05:40 AM
#1
Discrete Fourier Transform Test Results
Hello. I have been testing my Discrete Fourier Transform program for 1 dimensional data (written in using C++).
For the following test input data(X), the corresponding DFT(X) output is expected. The first number in each separate column is the REAL and the second number is the IMAGINARY.
Code:
X DFT X
( 1.000, 0.000) ( 4.000, 0.000)
( 1.000, 0.000) ( 1.000,-2.414)
( 1.000, 0.000) ( 0.000, 0.000)
( 1.000, 0.000) ( 1.000,-0.414)
( 0.000, 0.000) ( 0.000, 0.000)
( 0.000, 0.000) ( 1.000, 0.414)
( 0.000, 0.000) ( 0.000, 0.000)
( 0.000, 0.000) ( 1.000, 2.414)
My program produces the output below for the same input test data.
Code:
(0.5, 0)
(0.125, -0.302)
(-2.3e-017, -2.78e-017)
(0.125, -0.0518)
(0, -3.06e-017)
(0.125, 0.0518)
(4.11e-017, -4.16e-017)
(0.125, 0.302)
The program code is below. I would appreciate to learn where the error lies and how to fix this, thank you!
Code:
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;
}
}
fstream DFTdata;
DFTdata.open("DFT_Bdata.txt");
for (int i = 0; i<n; i++) // width
{
DFTdata <<"Input: "<< testReal[i]
<<" Real: "<< setprecision(3)<<FReal[i] <<" Imag: "<<setprecision(3)<<FIma[i]<< endl;
}
DFTdata.close();
Last edited by DavyS; October 19th, 2015 at 05:45 AM.
-
October 19th, 2015, 06:23 AM
#2
Re: Discrete Fourier Transform Test Results
1) I don't see how you get the output you posted with the code you posted.
2) The main difference the two outputs seems to be that you divide by the number of points.
-
October 26th, 2015, 04:15 PM
#3
Re: Discrete Fourier Transform Test Results
Originally Posted by Philip Nicoletti
1) I don't see how you get the output you posted with the code you posted.
2) The main difference the two outputs seems to be that you divide by the number of points.
Thanks for your feedback. My program is working now.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|