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

why the results of fortran mkl-fftw3 and matlab are not aligned?

fam__fen
Beginner
631 Views

I just want to convert my code from matlab to fortran. So I used the mkl-fftw3 library to complete the FFT computation. But during my test, the position of mkl-fftw3 results does not align with matlab results, it might seems like it's the reverse of matlab results.

Is there anyway to transform the fortran results to align with the matlab results?

Btw,I used vs2017 with ivf2019

In fortran I just wrote

      double complex t_in(5),t_out(5)
      integer*8 plan
      t_in = dcmplx([1:5])
      call dfftw_plan_dft_1d(plan,5,t_in,t_out,FFTW_FORWARD,FFTW_EST
 1  IMATE)
      call dfftw_execute_dft(plan, t_in, t_out)
      call dfftw_destroy_plan(plan)
      PRINT *,t_out

I also calculated the backward with t_out as the input

In matlab

      fft([1:5])

Results:

FORTRAN:

(15.0000000000000,0.000000000000000E+000) (-2.50000000000000,-3.44095480117793) (-2.50000000000000,-0.812299240582266) (-2.50000000000000,0.812299240582266) (-2.50000000000000,3.44095480117793)

(5,0) (25,0) (20,0) (15,0) (10,0)

MATLAB:

15.0000 + 0.0000i -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 - 3.4410i

 

0 Kudos
2 Replies
Gennady_F_Intel
Moderator
631 Views

you may take a look at the existing mkl's examples show how to call fftw3 API from intel MKL. As an example, check, dfftw_plan_dft_1d.f90 from mklroot/examples/fftw3xf/source directory

0 Kudos
Kirill_V_Intel
Employee
631 Views

Hello,

What do you mean by "reverse of the matlab results"? Your output from fortran looks strange. I see the same results.

Best,
Kirill

0 Kudos
Reply