FFT
Computes the forward/inverse FFT of a real-number sequence or complex sequence whose length is a power of 2.
Forward FFT: 
Inverse FFT: 

The FFT function calling process is as follows:
- Initialize the HmppsFFTPolicy structure by calling Init.
- Call the main functions such as CToC, RToC, and CToR.
- Call Release to release the memory contained in the HmppsFFTPolicy function.
The function interface declaration is as follows:
- Initialization:
HmppResult HMPPS_FFTCToCInit_32f(int32_t power, int32_t direction, int32_t flag, HmppsFFTPolicy_32f **policy);
HmppResult HMPPS_FFTCToCInit_64f(int32_t power, int32_t direction, int32_t flag, HmppsFFTPolicy_64f **policy);
HmppResult HMPPS_FFTCToCInit_32fc(int32_t power, int32_t direction, int32_t flag, HmppsFFTPolicy_32fc **policy);
HmppResult HMPPS_FFTCToCInit_64fc(int32_t power, int32_t direction, int32_t flag, HmppsFFTPolicy_64fc **policy);
HmppResult HMPPS_FFTRToCInit_32f(int32_t power, int32_t flag, HmppsFFTPolicy_32f **policy);
HmppResult HMPPS_FFTRToCInit_64f(int32_t power, int32_t flag, HmppsFFTPolicy_64f **policy);
HmppResult HMPPS_FFTCToRInit_32f(int32_t power, int32_t flag, HmppsFFTPolicy_32f **policy);
HmppResult HMPPS_FFTCToRInit_64f(int32_t power, int32_t flag, HmppsFFTPolicy_64f **policy);
- Main functions:
HmppResult HMPPS_FFTCToC_32f(float *srcRe, float *srcIm, float *dstRe, float *dstIm, HmppsFFTPolicy_32f *policy);
HmppResult HMPPS_FFTCToC_64f(double *srcRe, double *srcIm, double *dstRe, double *dstIm, HmppsFFTPolicy_64f *policy)
HmppResult HMPPS_FFTCToC_32fc(Hmpp32fc *src, Hmpp32fc *dst, HmppsFFTPolicy_32fc *policy);
HmppResult HMPPS_FFTCToC_64fc(Hmpp64fc *src, Hmpp64fc *dst, HmppsFFTPolicy_64fc *policy)
HmppResult HMPPS_FFTCToC_32fc_I(Hmpp32fc *srcDst, HmppsFFTPolicy_32fc *policy);
HmppResult HMPPS_FFTCToC_64fc_I(Hmpp64fc *srcDst, HmppsFFTPolicy_64fc *policy);
HmppResult HMPPS_FFTRToC_32f(float *src, Hmpp32fc *dst, HmppsFFTPolicy_32f *policy)
HmppResult HMPPS_FFTRToC_64f(double *src, Hmpp64fc *dst, HmppsFFTPolicy_64f *policy);
HmppResult HMPPS_FFTCToR_32f(Hmpp32fc *src, float *dst, HmppsFFTPolicy_32f *policy);
HmppResult HMPPS_FFTCToR_64f(Hmpp64fc *src, double *dst, HmppsFFTPolicy_64f *policy);
- Memory release:
HmppResult HMPPS_FFTCToCRelease_32f(HmppsFFTPolicy_32f *policy);
HmppResult HMPPS_FFTCToCRelease_64f(HmppsFFTPolicy_64f *policy);
HmppResult HMPPS_FFTCToCRelease_32fc(HmppsFFTPolicy_32fc *policy);
HmppResult HMPPS_FFTCToCRelease_64fc(HmppsFFTPolicy_64fc *policy);
HmppResult HMPPS_FFTRToCRelease_32f(HmppsFFTPolicy_32f *policy);
HmppResult HMPPS_FFTRToCRelease_64f(HmppsFFTPolicy_64f *policy);
HmppResult HMPPS_FFTCToRRelease_32f(HmppsFFTPolicy_32f *policy);
HmppResult HMPPS_FFTCToRRelease_64f(HmppsFFTPolicy_64f *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
power |
The length of the FFT sequence input signal is |
[0, 27] |
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 HmppsFFTPolicy structure. The structure contains the pointers to information and buffer block required for FFT calculation. |
The value cannot be NULL. |
Output |
policy (in the main and release functions) |
Pointer to the HmppsFFTPolicy 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 |
Value |
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 Code
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
Any of the specified pointers is NULL. |
HMPP_STS_FFT_POWER_ERR |
The value of power is less than 0 or greater than 27. |
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_FFTCToCInit interface must be called to initialize the HmppsFFTPolicy standard structure.
- The initialization of the HmppsFFTPolicy structure needs to be applied for in the Init function. You cannot apply for and define this structure by yourself.
Example
- FFTCToC calling example:
#define PI 3.14159265358979323846 void FFTCToC_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; HmppsFFTPolicy_32fc *policy = NULL; result = HMPPS_FFTCToCInit_32fc(3, 1, HMPP_FFT_NODIV_BY_ANY, &policy);// forward FFT if (result != HMPP_STS_NO_ERR) { printf("Create Policy Error!\n"); return; } result = HMPPS_FFTCToC_32fc(src, dst, policy); if (result != HMPP_STS_NO_ERR) { printf("FFT Error!\n"); return; } HMPPS_FFTCToCRelease_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
- FFTRToC/CToR calling example:
void FFT_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; HmppsFFTPolicy_32f *policy = NULL; result = HMPPS_FFTRToCInit_32f(3, HMPP_FFT_NODIV_BY_ANY, &policy); if (result != HMPP_STS_NO_ERR) { printf("RToC Create Policy Error!\n"); return; } result = HMPPS_FFTRToC_32f(src, rtoc_dst, policy); if (result != HMPP_STS_NO_ERR) { printf("FFTRToC Error!\n"); return; } HMPPS_FFTRToCRelease_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_FFTCToRInit_32f(3, HMPP_FFT_NODIV_BY_ANY, &policy); if (result != HMPP_STS_NO_ERR) { printf("CToR Create Policy Error!\n"); return; } result = HMPPS_FFTCToR_32f(rtoc_dst, ctor_dst, policy); if (result != HMPP_STS_NO_ERR) { printf("FFTCToR Error!\n"); return; } HMPPS_FFTCToRRelease_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
