Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6975 Discussions

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

shiva_rama_krishna_b
182 Views

 

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.real() =(float) 1;
real = 1;
imag = 1;
x.imag() = (float)1;
}
printf("before printng\n");

for(int i =0 ; i < N1*N2; i++)
{
printf(" %f %f----------%f %f\n",x.real(),x.imag(),real,imag);
}
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.real(),x.imag(),real,imag);
}

}

 

 

Thanks

 

0 Kudos
2 Replies
Evarist_F_Intel
Employee
182 Views

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

[cpp] status = DftiComputeForward(hand,real, imag); [/cpp]

should be replaced with

[cpp] status = DftiComputeForward(hand1,real, imag); [/cpp]

Then the output is the same.

 

0 Kudos
shiva_rama_krishna_b
182 Views

Thank you Evarist Fomenko.

 

0 Kudos
Reply