problem in computation of 2D FFT using two seperate real and imaginary arrays

problem in computation of 2D FFT using two seperate real and imaginary arrays

 

Hi,

i want to compute FFT of a complex 2D array. So first i have tried it in 2 ways.

1) Directly using complex 2D array(real and imaginary interleaved) .

2) 2 seperate arrays(where real and imaginary are deinterleaved into 2 seperate arrays).

i found the output is different in both cases. can some one tell me if i do some thing wrong in the code.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <complex>
#define MKL_Complex8 std::complex<float>
#include "mkl_dfti.h"

int main()
{
printf("hi\n");
int N1 = 4;
int N2 = 4;
MKL_LONG status = 0;
 MKL_Complex8 *x = 0;
float* real;
float* imag;
    DFTI_DESCRIPTOR_HANDLE hand = 0;
    DFTI_DESCRIPTOR_HANDLE hand1 =0;
MKL_LONG N[2]; N[0] = N1; N[1] = N2;
        status = DftiCreateDescriptor(&hand, DFTI_SINGLE, DFTI_COMPLEX, 2, N);
if (0 != status) printf("failed\n");
status = DftiSetValue( hand, DFTI_PLACEMENT, DFTI_INPLACE );
if (0 != status) printf("failed\n");
status = DftiCommitDescriptor(hand);
if (0 != status) printf("failed\n");
x = (MKL_Complex8*)malloc(N1*N2*sizeof(MKL_Complex8));
real = (float*)malloc(N1*N2*sizeof(float));
imag = (float*)malloc(N1*N2*sizeof(float));

status = DftiCreateDescriptor(&hand1, DFTI_SINGLE, DFTI_COMPLEX, 2,N);
if (0 != status) printf("failed\n");
status = DftiSetValue(hand1, DFTI_COMPLEX_STORAGE, DFTI_REAL_REAL);
if (0 != status) printf("failed\n");
status = DftiCommitDescriptor(hand1);
if (0 != status) printf("failed\n");
for(int i = 0; i < N1*N2; i++)
{
x[i].real() =(float) 1;
real[i] = 1;
imag[i] = 1;
x[i].imag() = (float)1;
}
printf("before printng\n");

for(int i =0 ; i < N1*N2; i++)
{
printf(" %f %f----------%f %f\n",x[i].real(),x[i].imag(),real[i],imag[i]);
}
status = DftiComputeForward(hand, x);
if (0 != status) printf("failed\n");
status = DftiComputeForward(hand,real, imag);
printf("after printng\n");

for(int i =0 ; i < N1*N2; i++)
{
printf(" %f %f--------%f %f\n",x[i].real(),x[i].imag(),real[i],imag[i]);
}

}

 

 

Thanks

 

3 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Hi, looks like you made a typo in line 52:

 status = DftiComputeForward(hand,real, imag); 

should be replaced with

 status = DftiComputeForward(hand1,real, imag); 

Then the output is the same.

 

Thank you Evarist Fomenko.

 

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen