Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
6557 Discussions

MKL FFT bin zero real and imaginary parts (part II)

pedro-erencia
Beginner
545 Views

Since my previous post didn't have much success I've made a reproducible program in case anyone wants to take a look.

I'm trying to do an FFT on .NET using MKL. I've downloaded the examples  and modified the code to show my case. 

 

public class Test_dfti
{
    private Test_dfti() { }
    public static void Main(string[] args)
    {
        int num_samples = 20480;        

        /* The data to be transformed */
        float[] x_normal = new float[num_samples + 2]; // CSS requires an array of N + 2
        /* Initialize the data array */
        int sampling_freq = 1024000;
        int tone = 16000;
        int amplitude = 1;
        for (int i = 0; i < num_samples; i++)
        {
            x_normal[i] = amplitude * (float)Math.Sin((2 * 3.14159265358979323846 / sampling_freq) * i * tone);
        }

        IntPtr desc = new();        
        /* Create new DFTI descriptor */
        if (
           (DFTI.DftiCreateDescriptor(ref desc, DFTI.SINGLE,  DFTI.REAL, 1, num_samples) == 0)
        && (DFTI.DftiSetValue(desc, DFTI.PLACEMENT, DFTI.INPLACE) == 0)
        && (DFTI.DftiSetValue(desc, DFTI.PACKED_FORMAT, DFTI.CCS_FORMAT) == 0)
        && (DFTI.DftiCommitDescriptor(desc) == 0)
        && (DFTI.DftiComputeForward(desc, x_normal) == 0))
        {
            Console.WriteLine(x_normal[19840] + " - " + x_normal[19841]);
        }
    }
}

 

As can be seen in the code, I'm doing a 1D, inplace, single precission fft of 20480 samples from a tone of 16K sampled at 1.024 Msps. The output is in CCS format.

The problem is that bin 9920 (array positions 19840, 19840 + 1) is 0+0i. I understand that this shouldn't happen with the input tone. This 0+0i bin happens at different places with different frequencies other than 16K. Sometimes there's no 0+0i bin, sometimes there are several, depending on the input tone.

I attached the visual studio project with the full code in case someone tries to reproduce it.

Note: 

This is the output of MKL_VERBOSE 

MKL_VERBOSE Intel(R) MKL 2021.0 Update 2 Product build 20210312 for Intel(R) 64 architecture Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2) enabled processors, Win 3.60GHz intel_thread
MKL_VERBOSE FFT(srfi20480,pack:ccs,tLim:1,unaligned_input,desc:000002154E347840) 127.94us CNR:OFF Dyn:1 FastMM:1 TID:0 NThr:1

Thanks!

 

0 Kudos
1 Solution
MRajesh_intel
Moderator
417 Views

Hi,

 

Your issue was reproducible, but unfortunately, we only support C/C++, DPC++, and Fortran for now. Please visit the below system requirements page.

 

https://software.intel.com/content/www/us/en/develop/articles/oneapi-math-kernel-library-system-requ...

 

Please try using the supported languages mentioned above and let us know if the issue remains.

 

Regards

Rajesh.

 

View solution in original post

5 Replies
MRajesh_intel
Moderator
493 Views

Hi,

 

I have tried using the provided intel example and your inputs and I got x[19840] and x[19841] as

 

5.45696821063757E-12 - -0.000107872744592896 respectively.

 

I have attached the source code below. Please let us know if you have any issues.

 

Regards

Rajesh.

 

pedro-erencia
Beginner
482 Views

Hi Rajesh,

In your example you are using DOUBLE instead of SINGLE. You should reproduce the problem by changing to SINGLE.

UPDATE: I've changed to SINGLE and it doesn't reproduces. I'll take a look.

Regards,

Pedro.

 

pedro-erencia
Beginner
477 Views

Hi Rajesh,

You were using doubles throughout all the code, not just in the fft descriptor. We must use floats for performance reasons. The problem only arises with floats.

I've modified your code, basically just changed the precision of the descriptor to SINGLE and replaced all doubles with floats. Also, I write to the console after the forward fft, not after the backward one.

I attach the modified code, you can reproduce the problem from it.

 

Regards,

Pedro

 

MRajesh_intel
Moderator
418 Views

Hi,

 

Your issue was reproducible, but unfortunately, we only support C/C++, DPC++, and Fortran for now. Please visit the below system requirements page.

 

https://software.intel.com/content/www/us/en/develop/articles/oneapi-math-kernel-library-system-requ...

 

Please try using the supported languages mentioned above and let us know if the issue remains.

 

Regards

Rajesh.

 

MRajesh_intel
Moderator
406 Views

 Hi,


Thanks for accepting as a solution!


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


Reply