Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
- FFT real to complex transform gives different result than Matlab

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

I wonder whether I did something wrong here.

Here is my example: a simple 2*3 matrix

float* pWeightMatrixfft = SYS_MALLOC(float, 6);

pWeightMatrixfft[0] = 1.0f;

pWeightMatrixfft[1] = 2.0f;

pWeightMatrixfft[2] = 3.0f;

pWeightMatrixfft[3] = 4.0f;

pWeightMatrixfft[4] = 5.0f;

pWeightMatrixfft[5] = 6.0f;

float* pWeightMatrixfftout = SYS_MALLOC(float, 12);

memset(pWeightMatrixfftout, 0, 12*sizeof(float));

DFTI_DESCRIPTOR_HANDLE my_desc1_handled =0;

l[0] = 2;

l[1] = 3;

status = DftiCreateDescriptor( &my_desc1_handled, DFTI_SINGLE, DFTI_REAL, 2, l);

status = DftiSetValue( my_desc1_handled, DFTI_PLACEMENT, DFTI_NOT_INPLACE);

status = DftiCommitDescriptor( my_desc1_handled);

status = DftiComputeForward( my_desc1_handled, pWeightMatrixfft, pWeightMatrixfftout );

status = DftiFreeDescriptor(&my_desc1_handled)

The output is : 21 0 -3 -9 0 0 9 0 0 0 0 0

But if I ran in Matlab:

x = [1 2 3

4 5 6]

x =

1 2 3

4 5 6

>> fft2(x)

ans =

21.0000 -3.0000 + 1.7321i -3.0000 - 1.7321i

-9.0000 0 0

Did I do anything wrong? If I run with DFTI_COMPLEX when the input is a complex array with all imag part to be 0, I can get the same result as in matlab.

Please help.

Zhu_W_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
10:30 AM

43 Views

FFT real to complex transform gives different result than Matlab

Here is my example: a simple 2*3 matrix

float* pWeightMatrixfft = SYS_MALLOC(float, 6);

pWeightMatrixfft[0] = 1.0f;

pWeightMatrixfft[1] = 2.0f;

pWeightMatrixfft[2] = 3.0f;

pWeightMatrixfft[3] = 4.0f;

pWeightMatrixfft[4] = 5.0f;

pWeightMatrixfft[5] = 6.0f;

float* pWeightMatrixfftout = SYS_MALLOC(float, 12);

memset(pWeightMatrixfftout, 0, 12*sizeof(float));

DFTI_DESCRIPTOR_HANDLE my_desc1_handled =0;

l[0] = 2;

l[1] = 3;

status = DftiCreateDescriptor( &my_desc1_handled, DFTI_SINGLE, DFTI_REAL, 2, l);

status = DftiSetValue( my_desc1_handled, DFTI_PLACEMENT, DFTI_NOT_INPLACE);

status = DftiCommitDescriptor( my_desc1_handled);

status = DftiComputeForward( my_desc1_handled, pWeightMatrixfft, pWeightMatrixfftout );

status = DftiFreeDescriptor(&my_desc1_handled)

The output is : 21 0 -3 -9 0 0 9 0 0 0 0 0

But if I ran in Matlab:

x = [1 2 3

4 5 6]

x =

1 2 3

4 5 6

>> fft2(x)

ans =

21.0000 -3.0000 + 1.7321i -3.0000 - 1.7321i

-9.0000 0 0

Did I do anything wrong? If I run with DFTI_COMPLEX when the input is a complex array with all imag part to be 0, I can get the same result as in matlab.

Please help.

7 Replies

Highlighted
##

Zhu:

How did you set your output strides?

DftiSetValue(my_desc1_handled,DFTI_OUTPUT_STRIDES,????);

-Ozzer

John_S_18

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
11:00 AM

43 Views

How did you set your output strides?

DftiSetValue(my_desc1_handled,DFTI_OUTPUT_STRIDES,????);

-Ozzer

Highlighted
##

*
*

I didn't set. How should I set?

Zhu_W_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
11:22 AM

43 Views

Quoting - ozzer

I didn't set. How should I set?

Highlighted
##

*
*

I didn't set. How should I set?

John_S_18

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
11:45 AM

43 Views

I am just a user like you, and so I will refer you to the specifics of FFT's in Chapter 11 of the MKL manual. There are many details about the layout of input and output data. Look for the "Strides" section. I recommend that you invest some time and read Chapter 11 very carefully, especially when transforming real-valued data out-of-place and when dealing with the packed output format.

You have a lead now, and you're welcome to follow it. Good luck, Zhu!

-Ozzer

Quoting - Zhu Wang (Intel)

You have a lead now, and you're welcome to follow it. Good luck, Zhu!

-Ozzer

Quoting - Zhu Wang (Intel)

I didn't set. How should I set?

Highlighted
##

*
*

Thanks for the useful suggestion. I read the manual, but still don't get it.

I can get the imag part now, but the order the pack format doesn't make sense to me.

I would appreciate some examples which can output similiar results as if I use DFTI_COMPLEX.

Zhu_W_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
12:20 PM

43 Views

Quoting - ozzer

Thanks for the useful suggestion. I read the manual, but still don't get it.

I can get the imag part now, but the order the pack format doesn't make sense to me.

I would appreciate some examples which can output similiar results as if I use DFTI_COMPLEX.

Highlighted
##

*
** *

I didn't set. How should I set?

zhu, specially for such cases, MKL package conatins a lot of DFTI examples (C-interfaces). Please look at thedirdftcsource dir.

Gennady_F_Intel

Moderator

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
12:40 PM

43 Views

Quoting - Zhu Wang (Intel)

Quoting - ozzer

I didn't set. How should I set?

zhu, specially for such cases, MKL package conatins a lot of DFTI examples (C-interfaces). Please look at the

Highlighted
##

zhu, specially for such cases, MKL package conatins a lot of DFTI examples (C-interfaces). Please look at thedirdftcsource dir.

I saw those examples. But I don't see anyone compare the Complex FFT vs. Real FFT.

For example, the matlab will return:

x =

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

>> fft2(x)

ans =

1.0e+02 *

1.3600 -0.0800 + 0.0800i -0.0800 -0.0800 - 0.0800i

-0.3200 + 0.3200i 0 0 0

-0.3200 0 0 0

-0.3200 - 0.3200i 0 0 0

But if I run Real FFT in MKL,

I got numbers like:

136 -8 8 -8

-0.539062 0.841543 0 0

-32 32 0 0

-0.841543 -0.539062 0 0

-32 0 0 0

0.539062 -0.841543 0 0

-32 -32 0 0

I don't know how the -0.539062 0.841543 come from.

Would appreciate any help.

Zhu_W_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
03:01 PM

43 Views

Quoting - Gennady Fedorov (Intel)

zhu, specially for such cases, MKL package conatins a lot of DFTI examples (C-interfaces). Please look at the

I saw those examples. But I don't see anyone compare the Complex FFT vs. Real FFT.

For example, the matlab will return:

x =

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

>> fft2(x)

ans =

1.0e+02 *

1.3600 -0.0800 + 0.0800i -0.0800 -0.0800 - 0.0800i

-0.3200 + 0.3200i 0 0 0

-0.3200 0 0 0

-0.3200 - 0.3200i 0 0 0

But if I run Real FFT in MKL,

I got numbers like:

136 -8 8 -8

-0.539062 0.841543 0 0

-32 32 0 0

-0.841543 -0.539062 0 0

-32 0 0 0

0.539062 -0.841543 0 0

-32 -32 0 0

I don't know how the -0.539062 0.841543 come from.

Would appreciate any help.

Highlighted
##

Hi Zhu,

By default real-to-complex FFTs store the transformed data in the CCS format (see the default value for DFTI_PACKED_FORMATp.2999 MKLReference Manual).

This format is described in detail for 2D FFTs onp. 3004.

Notice that, for a 2D FFT of MxN real numbers, the transformed data consist of (M+2)x(N+2) real numbers.

Furthermore, these transformed data are stored in a not so straightforward way :-)

We need to allocatemore memory (not 12 but 20 floats in the very first example in this thread.)

By default all FFTs are in-place and only input strides have a default value.

If we ask for a not-in-place FFT, we must set the output strides ourselves.

See example dftc/real_2d_ccs_single_ex2.c for an example that is closest to your use case.

For the first example in this thread, the output strides must be {0, 5, 1}.

Evgueni.

Evgueni_P_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-12-2010
08:02 PM

43 Views

By default real-to-complex FFTs store the transformed data in the CCS format (see the default value for DFTI_PACKED_FORMATp.2999 MKLReference Manual).

This format is described in detail for 2D FFTs onp. 3004.

Notice that, for a 2D FFT of MxN real numbers, the transformed data consist of (M+2)x(N+2) real numbers.

Furthermore, these transformed data are stored in a not so straightforward way :-)

We need to allocatemore memory (not 12 but 20 floats in the very first example in this thread.)

By default all FFTs are in-place and only input strides have a default value.

If we ask for a not-in-place FFT, we must set the output strides ourselves.

See example dftc/real_2d_ccs_single_ex2.c for an example that is closest to your use case.

For the first example in this thread, the output strides must be {0, 5, 1}.

Evgueni.

For more complete information about compiler optimizations, see our Optimization Notice.