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

MKL FFT functions - compute the N-point fft?

andreasjh
Beginner
1,201 Views

Hello,

Is there a way to compute the n-point fft of an 1D array in MKL (C-language, Linux) for an arbitrary number of n?
The problem is that i need to translate the matlab function fft(X,N) to use with the MKL-lib. The function inside matlab is described as : "fft(X,N) is the N-point fft, padded with zeros if X has less
than N points and truncated if it has more." (see ref.)

As an example, lets say i have a:
Input vector, I_vec, with size of 100 (can vary from 1 to 1500) elements and a output vector, O_vec, with size of 2048 (can vary between the fifth closest power of 2 of input vec).
I want to compute the values on these 100 elements to "fill up" the 2048 (1D) vector.
Let's say that i have computed the values  by the DftiComputeForward. I am then expecting the output to be:
inplace fft for I_vec: I_vec[0] = 0.1, i_vec[1] = 0.2, ....
out of place fft for I_vec to O_vec: O_vec[0] = 0.1 ... O_vec[~10] = 0.15 ... O_vec[~20] = 0.2. 

Is this possible? I have tried to read the reference document and looked at the examples - but cant find anything that does this kind of computation straight away. Maybe do a number of transformations and try to pad inside the vector?  If you have any tips to where to look or can give an example of how to do this, it would be highly appreciated.

Thanks in advance,
Andreas


More info of the n-point fft can be found on: https://www.dsprelated.com/showthread/comp.dsp/56353-1.php and the matlab api: https://se.mathworks.com/help/matlab/ref/fft.html#d123e392801

Specs:
Ubuntu 20.04 (linux)
Intel oneAPI integrated in Eclipse IDE (v. 2021.2.0)
Intel C++ compiler
Intel MKL - static lib
C-languge
Intel core i7-8750h

0 Kudos
1 Solution
MRajesh_intel
Moderator
1,137 Views

Hi,

 

The output 2048 array will be padded with zeros after the computation is completed. You may refer to this sample.

 

#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
#include "mkl.h"
#include "mkl_dfti.h"

float _Complex c2c_input[100];
float _Complex c2c_output[2048];
DFTI_DESCRIPTOR_HANDLE my_desc_handle = NULL;
MKL_LONG status;

int main(int argc, char* argv[])
{
int i;
for(i=0;i<100;i++)
c2c_input[i]=i;
status = DftiCreateDescriptor(&my_desc_handle, DFTI_SINGLE,DFTI_COMPLEX, 1, 100);
status = DftiSetValue(my_desc_handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
status = DftiCommitDescriptor(my_desc_handle);
status = DftiComputeForward(my_desc_handle, c2c_input,c2c_output);
status = DftiFreeDescriptor(&my_desc_handle);
for(i=0;i<110;i++)
printf("%f\t",creal(c2c_output[i]));
return 0;
}

 

 

If this is not the kind of computation you were looking for, can you please elaborate more?

 

Regards

Rajesh.

 

View solution in original post

0 Kudos
4 Replies
MRajesh_intel
Moderator
1,138 Views

Hi,

 

The output 2048 array will be padded with zeros after the computation is completed. You may refer to this sample.

 

#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
#include "mkl.h"
#include "mkl_dfti.h"

float _Complex c2c_input[100];
float _Complex c2c_output[2048];
DFTI_DESCRIPTOR_HANDLE my_desc_handle = NULL;
MKL_LONG status;

int main(int argc, char* argv[])
{
int i;
for(i=0;i<100;i++)
c2c_input[i]=i;
status = DftiCreateDescriptor(&my_desc_handle, DFTI_SINGLE,DFTI_COMPLEX, 1, 100);
status = DftiSetValue(my_desc_handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
status = DftiCommitDescriptor(my_desc_handle);
status = DftiComputeForward(my_desc_handle, c2c_input,c2c_output);
status = DftiFreeDescriptor(&my_desc_handle);
for(i=0;i<110;i++)
printf("%f\t",creal(c2c_output[i]));
return 0;
}

 

 

If this is not the kind of computation you were looking for, can you please elaborate more?

 

Regards

Rajesh.

 

0 Kudos
MRajesh_intel
Moderator
1,112 Views

Hi,


Can you please give us any updates regarding the query?


Regards

Rajesh.



0 Kudos
andreasjh
Beginner
1,102 Views

Hi Rajesh, 

I managed to get my wanted result working by trial and error principle but your reply was really spot on.

The reply is more then satisfying.
Thanks you so much for the help, really appreciated!

MVH, 
Andreas

0 Kudos
MRajesh_intel
Moderator
1,097 Views

Hi,


Thanks for the confirmation!


As this issue has been resolved, we will no longer respond to this thread. If you require any additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.


Have a Good day.

Regards

Rajesh


0 Kudos
Reply