Rate This Document
Findability
Accuracy
Completeness
Readability

DFT

Computes the forward or inverse FFT of a real-number sequence of any length and a complex sequence.

Forward FFT:

Inverse FFT:

The DFT function calling process is as follows:

  1. Initialize the HmppsDFTPolicy structure by calling Init.
  2. Call the main functions such as CToC, RToC, and CToR.
  3. Call Release to release the memory contained in the HmppsDFTPolicy function.

The function interface declaration is as follows:

  • Initialization:

    HmppResult HMPPS_DFTCToCInit_32f(int32_t len, int32_t direction, int32_t flag, HmppsDFTPolicy_32f **policy);

    HmppResult HMPPS_DFTCToCInit_64f(int32_t len, int32_t direction, int32_t flag, HmppsDFTPolicy_64f **policy);

    HmppResult HMPPS_DFTCToCInit_32fc(int32_t len, int32_t direction, int32_t flag, HmppsDFTPolicy_32fc **policy);

    HmppResult HMPPS_DFTCToCInit_64fc(int32_t len, int32_t direction, int32_t flag, HmppsDFTPolicy_64fc **policy);

    HmppResult HMPPS_DFTRToCInit_32f(int32_t len, int32_t flag, HmppsDFTPolicy_32f **policy);

    HmppResult HMPPS_DFTRToCInit_64f(int32_t len, int32_t flag, HmppsDFTPolicy_64f **policy);

    HmppResult HMPPS_DFTCToRInit_32f(int32_t len, int32_t flag, HmppsDFTPolicy_32f **policy);

    HmppResult HMPPS_DFTCToRInit_64f(int32_t len, int32_t flag, HmppsDFTPolicy_64f **policy);

  • Main functions:

    HmppResult HMPPS_DFTCToC_32f(float *srcRe, float *srcIm, float *dstRe, float *dstIm, HmppsFFTPolicy_32f *policy);

    HmppResult HMPPS_DFTCToC_64f(double *srcRe, double *srcIm, double *dstRe, double *dstIm, HmppsFFTPolicy_64f *policy);

    HmppResult HMPPS_DFTCToC_32fc(Hmpp32fc *src, Hmpp32fc *dst, HmppsFFTPolicy_32fc *policy);

    HmppResult HMPPS_DFTCToC_64fc(Hmpp64fc *src, Hmpp64fc *dst, HmppsFFTPolicy_64fc *policy);

    HmppResult HMPPS_DFTRToC_32f(float *src, Hmpp32fc *dst, HmppsDFTPolicy_32f *policy);

    HmppResult HMPPS_DFTRToC_64f(double *src, Hmpp64fc *dst, HmppsDFTPolicy_64f *policy);

    HmppResult HMPPS_DFTCToR_32f(Hmpp32fc *src, float *dst, HmppsDFTPolicy_32f *policy);

    HmppResult HMPPS_DFTCToR_64f(Hmpp64fc *src, double *dst, HmppsDFTPolicy_64f *policy);

  • Memory release:

    HmppResult HMPPS_DFTCToCRelease_32f(HmppsDFTPolicy_32f *policy);

    HmppResult HMPPS_DFTCToCRelease_64f(HmppsDFTPolicy_64f *policy);

    HmppResult HMPPS_DFTCToCRelease_32fc(HmppsDFTPolicy_32fc *policy);

    HmppResult HMPPS_DFTCToCRelease_64fc(HmppsDFTPolicy_64fc *policy);

    HmppResult HMPPS_DFTRToCRelease_32f(HmppsDFTPolicy_32f *policy);

    HmppResult HMPPS_DFTRToCRelease_64f(HmppsDFTPolicy_64f *policy);

    HmppResult HMPPS_DFTCToRRelease_32f(HmppsDFTPolicy_32f *policy);

    HmppResult HMPPS_DFTCToRRelease_64f(HmppsDFTPolicy_64f *policy);

Parameters

Parameter

Description

Value Range

Input/Output

len

Length of the FFT sequence input signal

(0, 227]

Input

direction

Value 1 indicates forward FFT.

Value -1 indicates inverse FFT.

(used for the CToC mode)

±1

Input

flag

Result normalization mode

HMPP_FFT_DIV_FWD_BY_N, HMPP_FFT_DIV_BWD_BY_N, HMPP_FFT_DIV_BY_SQRTN, HMPP_FFT_NODIV_BY_ANY

Input

policy (in the Init function)

Dual pointer to the HmppsDFTPolicy structure. The structure contains the pointers to information and buffer block required for DFT calculation.

The value cannot be NULL.

Output

policy (in the main and release functions)

Pointer to the HmppsDFTPolicy structure

The value cannot be NULL.

Input

src

Pointer to the source sequence

The value cannot be NULL.

Input

dst

Pointer to the output sequence

The value cannot be NULL.

Output

srcDst

Pointer to the in-place operation sequence

The value cannot be NULL.

Input/Output

Table 1 Values of the flag parameter

Descriptor

Description

HMPP_FFT_DIV_FWD_BY_N

Forward FFT with 1/N normalization

HMPP_FFT_DIV_BWD_BY_N

Inverse FFT with 1/N normalization

HMPP_FFT_DIV_BY_SQRTN

Forward or inverse FFT with 1/N1/2 normalization

HMPP_FFT_NODIV_BY_ANY

Forward or inverse FFT without normalization

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

Any of the specified pointers is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than 0.

HMPP_STS_MALLOC_FAILED

Failed to allocate the required extra memory.

HMPP_STS_FFT_FLAG_ERR

The value of flag is not in the range of [1, 4].

Note

  • Before this interface is called for calculation, the HMPPS_DFTInit interface must be called to initialize the HmppsDFTPolicy standard structure.
  • The initialization of the HmppsDFTPolicy structure needs to be applied for in the Init function. You cannot apply for and define this structure by yourself.

Example

  • DFTCToC calling example:
    #define PI 3.14159265358979323846
    
    void DFTCToC_Example()
    {
        Hmpp32fc src[8], dst[8];
        for (int32_t i = 0; i < 8; i++) {
            src[i].re = cos(2 * PI * i * 16 / 64);
            src[i].im = 1;
        }
        HmppResult result;
        HmppsDFTPolicy_32fc *policy = NULL;
        
        result = HMPPS_DFTCToCInit_32fc(8, 1, HMPP_FFT_NODIV_BY_ANY, &policy);// forward FFT
        if (result != HMPP_STS_NO_ERR) {
            printf("Create Policy Error!\n");
            return;
        }
        result = HMPPS_DFTCToC_32fc(src, dst, policy);
        if (result != HMPP_STS_NO_ERR) {
            printf("DFT Error!\n");
            return;
        }
        HMPPS_DFTCToCRelease_32fc(policy);
        printf("dstRe =");
        for (int32_t i = 0; i < 8; i++) {
            printf("    %.2f", dst[i].re);
        }
        printf("\ndstIm =");
        for (int32_t i = 0; i < 8; i++) {
            printf("    %.2f", dst[i].im);
        }
        printf("\n");
    }
    Output:
    dstRe =    -0.00    -0.00    4.00    0.00    0.00    0.00    4.00    -0.00
    dstIm =    8.00    -0.00    -0.00    -0.00    0.00    0.00    0.00    0.00
  • DFTRToC/CToR calling example:
    void DFT_R_Example()
    {
        float src[8];
        Hmpp32fc rtoc_dst[5];
        float ctor_dst[8] = {0};
        for (int32_t i = 0; i < 8; i++) {
            src[i] = i + 1;
        }
        HmppResult result;
        HmppsDFTPolicy_32f *policy = NULL;
    
        result = HMPPS_DFTRToCInit_32f(8, HMPP_FFT_NODIV_BY_ANY, &policy);
        if (result != HMPP_STS_NO_ERR) {
            printf("DFTRToC Create Policy Error!\n");
            return;
        }
        result = HMPPS_DFTRToC_32f(src, rtoc_dst, policy);
        if (result != HMPP_STS_NO_ERR) {
            printf("DFTRToC Error!\n");
            return;
        }
        HMPPS_DFTRToCRelease_32f(policy);
        printf("rtoc_dstRe =");
        for (int32_t i = 0; i < 8; i++) {
            printf("    %.2f", rtoc_dst[i].re);
        }
        printf("\nrtoc_dstIm =");
        for (int32_t i = 0; i < 8; i++) {
            printf("    %.2f", rtoc_dst[i].im);
        }
        printf("\n");
    
        result = HMPPS_DFTCToRInit_32f(8, HMPP_FFT_NODIV_BY_ANY, &policy);
        if (result != HMPP_STS_NO_ERR) {
            printf("DFTCToR Create Policy Error!\n");
            return;
        }
        result = HMPPS_DFTCToR_32f(rtoc_dst, ctor_dst, policy);
        if (result != HMPP_STS_NO_ERR) {
            printf("DFTCToR Error!\n");
            return;
        }
        HMPPS_DFTCToRRelease_32f(policy);
        printf("ctor_dst =");
        for (int32_t i = 0; i < 8; i++) {
            printf("    %.2f", ctor_dst[i]);
        }
        printf("\n");
    }
    Output:
    rtoc_dstRe =    36.00    -4.00    -4.00    -4.00    -4.00    1.00    3.00    5.00
    rtoc_dstIm =    0.00    9.66    4.00    1.66    0.00    2.00    4.00    6.00
    ctor_dst =    8.00    16.00    24.00    32.00    40.00    48.00    56.00    64.00