Complex FFT Functions

void riscv_cfft_f32(const riscv_cfft_instance_f32 *S, float32_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag)
void riscv_cfft_q15(const riscv_cfft_instance_q15 *S, q15_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag)
void riscv_cfft_q31(const riscv_cfft_instance_q31 *S, q31_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag)
void riscv_cfft_radix2_f32(const riscv_cfft_radix2_instance_f32 *S, float32_t *pSrc)
riscv_status riscv_cfft_radix2_init_f32(riscv_cfft_radix2_instance_f32 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)
riscv_status riscv_cfft_radix2_init_q15(riscv_cfft_radix2_instance_q15 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)
riscv_status riscv_cfft_radix2_init_q31(riscv_cfft_radix2_instance_q31 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)
void riscv_cfft_radix2_q15(const riscv_cfft_radix2_instance_q15 *S, q15_t *pSrc)
void riscv_cfft_radix2_q31(const riscv_cfft_radix2_instance_q31 *S, q31_t *pSrc)
void riscv_cfft_radix4_f32(const riscv_cfft_radix4_instance_f32 *S, float32_t *pSrc)
riscv_status riscv_cfft_radix4_init_f32(riscv_cfft_radix4_instance_f32 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)
riscv_status riscv_cfft_radix4_init_q15(riscv_cfft_radix4_instance_q15 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)
riscv_status riscv_cfft_radix4_init_q31(riscv_cfft_radix4_instance_q31 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)
void riscv_cfft_radix4_q15(const riscv_cfft_radix4_instance_q15 *S, q15_t *pSrc)
void riscv_cfft_radix4_q31(const riscv_cfft_radix4_instance_q31 *S, q31_t *pSrc)
group ComplexFFT

The Fast Fourier Transform (FFT) is an efficient algorithm for computing the Discrete Fourier Transform (DFT). The FFT can be orders of magnitude faster than the DFT, especially for long lengths. The algorithms described in this section operate on complex data. A separate set of functions is devoted to handling of real sequences.

There are separate algorithms for handling floating-point, Q15, and Q31 data types. The algorithms available for each data type are described next.

The FFT functions operate in-place. That is, the array holding the input data will also be used to hold the corresponding result. The input data is complex and contains 2*fftLen interleaved values as shown below. The FFT result will be contained in the same array and the frequency domain values will have the same interleaving.

Floating-point

The floating-point complex FFT uses a mixed-radix algorithm. Multiple radix-8 stages are performed along with a single radix-2 or radix-4 stage, as needed. The algorithm supports lengths of [16, 32, 64, …, 4096] and each length uses a different twiddle factor table.

The function uses the standard FFT definition and output values may grow by a factor of fftLen when computing the forward transform. The inverse transform includes a scale of 1/fftLen as part of the calculation and this matches the textbook definition of the inverse FFT.

Pre-initialized data structures containing twiddle factors and bit reversal tables are provided and defined in riscv_const_structs.h. Include this header in your function and then pass one of the constant structures as an argument to riscv_cfft_f32. For example:

riscv_cfft_f32(riscv_cfft_sR_f32_len64, pSrc, 1, 1)

computes a 64-point inverse complex FFT including bit reversal. The data structures are treated as constant data and not modified during the calculation. The same data structure can be reused for multiple transforms including mixing forward and inverse transforms.

Earlier releases of the library provided separate radix-2 and radix-4 algorithms that operated on floating-point data. These functions are still provided but are deprecated. The older functions are slower and less general than the new functions.

An example of initialization of the constants for the riscv_cfft_f32 function follows:

const static riscv_cfft_instance_f32 *S;
...
  switch (length) {
    case 16:
      S = &riscv_cfft_sR_f32_len16;
      break;
    case 32:
      S = &riscv_cfft_sR_f32_len32;
      break;
    case 64:
      S = &riscv_cfft_sR_f32_len64;
      break;
    case 128:
      S = &riscv_cfft_sR_f32_len128;
      break;
    case 256:
      S = &riscv_cfft_sR_f32_len256;
      break;
    case 512:
      S = &riscv_cfft_sR_f32_len512;
      break;
    case 1024:
      S = &riscv_cfft_sR_f32_len1024;
      break;
    case 2048:
      S = &riscv_cfft_sR_f32_len2048;
      break;
    case 4096:
      S = &riscv_cfft_sR_f32_len4096;
      break;
  }

Q15 and Q31

The floating-point complex FFT uses a mixed-radix algorithm. Multiple radix-4 stages are performed along with a single radix-2 stage, as needed. The algorithm supports lengths of [16, 32, 64, …, 4096] and each length uses a different twiddle factor table.

The function uses the standard FFT definition and output values may grow by a factor of fftLen when computing the forward transform. The inverse transform includes a scale of 1/fftLen as part of the calculation and this matches the textbook definition of the inverse FFT.

Pre-initialized data structures containing twiddle factors and bit reversal tables are provided and defined in riscv_const_structs.h. Include this header in your function and then pass one of the constant structures as an argument to riscv_cfft_q31. For example:

riscv_cfft_q31(riscv_cfft_sR_q31_len64, pSrc, 1, 1)

computes a 64-point inverse complex FFT including bit reversal. The data structures are treated as constant data and not modified during the calculation. The same data structure can be reused for multiple transforms including mixing forward and inverse transforms.

Earlier releases of the library provided separate radix-2 and radix-4 algorithms that operated on floating-point data. These functions are still provided but are deprecated. The older functions are slower and less general than the new functions.

An example of initialization of the constants for the riscv_cfft_q31 function follows:

const static riscv_cfft_instance_q31 *S;
...
  switch (length) {
    case 16:
      S = &riscv_cfft_sR_q31_len16;
      break;
    case 32:
      S = &riscv_cfft_sR_q31_len32;
      break;
    case 64:
      S = &riscv_cfft_sR_q31_len64;
      break;
    case 128:
      S = &riscv_cfft_sR_q31_len128;
      break;
    case 256:
      S = &riscv_cfft_sR_q31_len256;
      break;
    case 512:
      S = &riscv_cfft_sR_q31_len512;
      break;
    case 1024:
      S = &riscv_cfft_sR_q31_len1024;
      break;
    case 2048:
      S = &riscv_cfft_sR_q31_len2048;
      break;
    case 4096:
      S = &riscv_cfft_sR_q31_len4096;
      break;
  }

Functions

void riscv_cfft_f32(const riscv_cfft_instance_f32 *S, float32_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag)

Processing function for the floating-point complex FFT.

Return

none

Parameters
  • [in] S: points to an instance of the floating-point CFFT structure

  • [inout] p1: points to the complex data buffer of size 2*fftLen. Processing occurs in-place

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

void riscv_cfft_q15(const riscv_cfft_instance_q15 *S, q15_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag)

Processing function for Q15 complex FFT.

Return

none

Parameters
  • [in] S: points to an instance of Q15 CFFT structure

  • [inout] p1: points to the complex data buffer of size 2*fftLen. Processing occurs in-place

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

void riscv_cfft_q31(const riscv_cfft_instance_q31 *S, q31_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag)

Processing function for the Q31 complex FFT.

Return

none

Parameters
  • [in] S: points to an instance of the fixed-point CFFT structure

  • [inout] p1: points to the complex data buffer of size 2*fftLen. Processing occurs in-place

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

void riscv_cfft_radix2_f32(const riscv_cfft_radix2_instance_f32 *S, float32_t *pSrc)

Radix-2 CFFT/CIFFT.

Return

none

Parameters
  • [in] S: points to an instance of the floating-point Radix-2 CFFT/CIFFT structure

  • [inout] pSrc: points to the complex data buffer of size 2*fftLen. Processing occurs in-place

riscv_status riscv_cfft_radix2_init_f32(riscv_cfft_radix2_instance_f32 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)

Initialization function for the floating-point CFFT/CIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLen is not a supported length

Details

The parameter ifftFlag controls whether a forward or inverse transform is computed. Set(=1) ifftFlag for calculation of CIFFT otherwise CFFT is calculated

The parameter bitReverseFlag controls whether output is in normal order or bit reversed order. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.

The parameter fftLen Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.

This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.

Parameters
  • [inout] S: points to an instance of the floating-point CFFT/CIFFT structure

  • [in] fftLen: length of the FFT

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

riscv_status riscv_cfft_radix2_init_q15(riscv_cfft_radix2_instance_q15 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)

Initialization function for the Q15 CFFT/CIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLen is not a supported length

Details

The parameter ifftFlag controls whether a forward or inverse transform is computed. Set(=1) ifftFlag for calculation of CIFFT otherwise CFFT is calculated

The parameter bitReverseFlag controls whether output is in normal order or bit reversed order. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.

The parameter fftLen Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.

This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.

Parameters
  • [inout] S: points to an instance of the Q15 CFFT/CIFFT structure.

  • [in] fftLen: length of the FFT.

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

riscv_status riscv_cfft_radix2_init_q31(riscv_cfft_radix2_instance_q31 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)

Initialization function for the Q31 CFFT/CIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLen is not a supported length

Details

The parameter ifftFlag controls whether a forward or inverse transform is computed. Set(=1) ifftFlag for calculation of CIFFT otherwise CFFT is calculated

The parameter bitReverseFlag controls whether output is in normal order or bit reversed order. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.

The parameter fftLen Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.

This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.

Parameters
  • [inout] S: points to an instance of the Q31 CFFT/CIFFT structure

  • [in] fftLen: length of the FFT

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

void riscv_cfft_radix2_q15(const riscv_cfft_radix2_instance_q15 *S, q15_t *pSrc)

Processing function for the fixed-point CFFT/CIFFT.

Return

none

Parameters
  • [in] S: points to an instance of the fixed-point CFFT/CIFFT structure

  • [inout] pSrc: points to the complex data buffer of size 2*fftLen. Processing occurs in-place

void riscv_cfft_radix2_q31(const riscv_cfft_radix2_instance_q31 *S, q31_t *pSrc)

Processing function for the fixed-point CFFT/CIFFT.

Return

none

Parameters
  • [in] S: points to an instance of the fixed-point CFFT/CIFFT structure

  • [inout] pSrc: points to the complex data buffer of size 2*fftLen. Processing occurs in-place

void riscv_cfft_radix4_f32(const riscv_cfft_radix4_instance_f32 *S, float32_t *pSrc)

Processing function for the floating-point Radix-4 CFFT/CIFFT.

Return

none

Parameters
  • [in] S: points to an instance of the floating-point Radix-4 CFFT/CIFFT structure

  • [inout] pSrc: points to the complex data buffer of size 2*fftLen. Processing occurs in-place

riscv_status riscv_cfft_radix4_init_f32(riscv_cfft_radix4_instance_f32 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)

Initialization function for the floating-point CFFT/CIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLen is not a supported length

Details

The parameter ifftFlag controls whether a forward or inverse transform is computed. Set(=1) ifftFlag for calculation of CIFFT otherwise CFFT is calculated

The parameter bitReverseFlag controls whether output is in normal order or bit reversed order. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.

The parameter fftLen Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.

This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.

Parameters
  • [inout] S: points to an instance of the floating-point CFFT/CIFFT structure

  • [in] fftLen: length of the FFT

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

riscv_status riscv_cfft_radix4_init_q15(riscv_cfft_radix4_instance_q15 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)

Initialization function for the Q15 CFFT/CIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLen is not a supported length

Details

The parameter ifftFlag controls whether a forward or inverse transform is computed. Set(=1) ifftFlag for calculation of CIFFT otherwise CFFT is calculated

The parameter bitReverseFlag controls whether output is in normal order or bit reversed order. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.

The parameter fftLen Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.

This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.

Parameters
  • [inout] S: points to an instance of the Q15 CFFT/CIFFT structure

  • [in] fftLen: length of the FFT

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

riscv_status riscv_cfft_radix4_init_q31(riscv_cfft_radix4_instance_q31 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)

Initialization function for the Q31 CFFT/CIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLen is not a supported length

Details

The parameter ifftFlag controls whether a forward or inverse transform is computed. Set(=1) ifftFlag for calculation of CIFFT otherwise CFFT is calculated

The parameter bitReverseFlag controls whether output is in normal order or bit reversed order. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.

The parameter fftLen Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.

This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.

Parameters
  • [inout] S: points to an instance of the Q31 CFFT/CIFFT structure.

  • [in] fftLen: length of the FFT.

  • [in] ifftFlag: flag that selects transform direction

    • value = 0: forward transform

    • value = 1: inverse transform

  • [in] bitReverseFlag: flag that enables / disables bit reversal of output

    • value = 0: disables bit reversal of output

    • value = 1: enables bit reversal of output

void riscv_cfft_radix4_q15(const riscv_cfft_radix4_instance_q15 *S, q15_t *pSrc)

Processing function for the Q15 CFFT/CIFFT.

Return

none

Input and output formats:

Internally input is downscaled by 2 for every stage to avoid saturations inside CFFT/CIFFT process. Hence the output format is different for different FFT sizes. The input and output formats for different FFT sizes and number of bits to upscale are mentioned in the tables below for CFFT and CIFFT:

../../../_images/CFFTQ15.png../../../_images/CIFFTQ15.png

Parameters
  • [in] S: points to an instance of the Q15 CFFT/CIFFT structure.

  • [inout] pSrc: points to the complex data buffer. Processing occurs in-place.

void riscv_cfft_radix4_q31(const riscv_cfft_radix4_instance_q31 *S, q31_t *pSrc)

Processing function for the Q31 CFFT/CIFFT.

Return

none

Input and output formats:

Internally input is downscaled by 2 for every stage to avoid saturations inside CFFT/CIFFT process. Hence the output format is different for different FFT sizes. The input and output formats for different FFT sizes and number of bits to upscale are mentioned in the tables below for CFFT and CIFFT:

../../../_images/CFFTQ31.png../../../_images/CIFFTQ31.png

Parameters
  • [in] S: points to an instance of the Q31 CFFT/CIFFT structure

  • [inout] pSrc: points to the complex data buffer of size 2*fftLen. Processing occurs in-place