Real FFT Functions

void riscv_rfft_f32(const riscv_rfft_instance_f32 *S, float32_t *pSrc, float32_t *pDst)
void riscv_rfft_fast_f32(riscv_rfft_fast_instance_f32 *S, float32_t *p, float32_t *pOut, uint8_t ifftFlag)
riscv_status riscv_rfft_32_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_64_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_128_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_256_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_512_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_1024_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_2048_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_4096_fast_init_f32(riscv_rfft_fast_instance_f32 *S)
riscv_status riscv_rfft_fast_init_f32(riscv_rfft_fast_instance_f32 *S, uint16_t fftLen)
riscv_status riscv_rfft_init_f32(riscv_rfft_instance_f32 *S, riscv_cfft_radix4_instance_f32 *S_CFFT, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)
riscv_status riscv_rfft_init_q15(riscv_rfft_instance_q15 *S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)
riscv_status riscv_rfft_init_q31(riscv_rfft_instance_q31 *S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)
void riscv_rfft_q15(const riscv_rfft_instance_q15 *S, q15_t *pSrc, q15_t *pDst)
void riscv_rfft_q31(const riscv_rfft_instance_q31 *S, q31_t *pSrc, q31_t *pDst)
group RealFFT

The NMSIS DSP library includes specialized algorithms for computing the FFT of real data sequences. The FFT is defined over complex data but in many applications the input is real. Real FFT algorithms take advantage of the symmetry properties of the FFT and have a speed advantage over complex algorithms of the same length.

The Fast RFFT algorith relays on the mixed radix CFFT that save processor usage.

The real length N forward FFT of a sequence is computed using the steps shown below.

../../../_images/RFFT.png

The real sequence is initially treated as if it were complex to perform a CFFT. Later, a processing stage reshapes the data to obtain half of the frequency spectrum in complex format. Except the first complex number that contains the two real numbers X[0] and X[N/2] all the data is complex. In other words, the first complex sample contains two real values packed.

The input for the inverse RFFT should keep the same format as the output of the forward RFFT. A first processing stage pre-process the data to later perform an inverse CFFT.

../../../_images/RIFFT.png

The algorithms for floating-point, Q15, and Q31 data are slightly different and we describe each algorithm in turn.

Floating-point

The main functions are riscv_rfft_fast_f32() and riscv_rfft_fast_init_f32(). The older functions riscv_rfft_f32() and riscv_rfft_init_f32() have been deprecated but are still documented.

The FFT of a real N-point sequence has even symmetry in the frequency domain. The second half of the data equals the conjugate of the first half flipped in frequency. Looking at the data, we see that we can uniquely represent the FFT using only N/2 complex numbers. These are packed into the output array in alternating real and imaginary components:

X = { real[0], imag[0], real[1], imag[1], real[2], imag[2] … real[(N/2)-1], imag[(N/2)-1 }

It happens that the first complex number (real[0], imag[0]) is actually all real. real[0] represents the DC offset, and imag[0] should be 0. (real[1], imag[1]) is the fundamental frequency, (real[2], imag[2]) is the first harmonic and so on.

The real FFT functions pack the frequency domain data in this fashion. The forward transform outputs the data in this form and the inverse transform expects input data in this form. The function always performs the needed bitreversal so that the input and output data is always in normal order. The functions support lengths of [32, 64, 128, …, 4096] samples.

Q15 and Q31

The real algorithms are defined in a similar manner and utilize N/2 complex transforms behind the scenes.

The complex transforms used internally include scaling to prevent fixed-point overflows. The overall scaling equals 1/(fftLen/2).

A separate instance structure must be defined for each transform used but twiddle factor and bit reversal tables can be reused.

There is also an associated initialization function for each data type. The initialization function performs the following operations:

  • Sets the values of the internal structure fields.

  • Initializes twiddle factor table and bit reversal table pointers.

  • Initializes the internal complex FFT data structure.

Use of the initialization function is optional. However, if the initialization function is used, then the instance structure cannot be placed into a const data section. To place an instance structure into a const data section, the instance structure should be manually initialized as follows: where fftLenReal is the length of the real transform; fftLenBy2 length of the internal complex transform. ifftFlagR Selects forward (=0) or inverse (=1) transform. bitReverseFlagR Selects bit reversed output (=0) or normal order output (=1). twidCoefRModifier stride modifier for the twiddle factor table. The value is based on the FFT length; pTwiddleARealpoints to the A array of twiddle coefficients; pTwiddleBRealpoints to the B array of twiddle coefficients; pCfft points to the CFFT Instance structure. The CFFT structure must also be initialized. Refer to riscv_cfft_radix4_f32() for details regarding static initialization of the complex FFT instance structure.

Functions

void riscv_rfft_f32(const riscv_rfft_instance_f32 *S, float32_t *pSrc, float32_t *pDst)

Processing function for the floating-point RFFT/RIFFT.

Return

none

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

  • [in] pSrc: points to the input buffer

  • [out] pDst: points to the output buffer

void riscv_rfft_fast_f32(riscv_rfft_fast_instance_f32 *S, float32_t *p, float32_t *pOut, uint8_t ifftFlag)

Processing function for the floating-point real FFT.

Return

none

Parameters
  • [in] S: points to an riscv_rfft_fast_instance_f32 structure

  • [in] p: points to input buffer

  • [in] pOut: points to output buffer

  • [in] ifftFlag:

    • value = 0: RFFT

    • value = 1: RIFFT

riscv_status riscv_rfft_32_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 32pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_64_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 64pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_128_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 128pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_256_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 256pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_512_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 512pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_1024_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 1024pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_2048_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 2048pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_4096_fast_init_f32(riscv_rfft_fast_instance_f32 *S)

Initialization function for the 4096pt floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : an error is detected

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

riscv_status riscv_rfft_fast_init_f32(riscv_rfft_fast_instance_f32 *S, uint16_t fftLen)

Initialization function for the floating-point real FFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLen is not a supported length

Description

The parameter fftLen specifies the length of RFFT/CIFFT process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096.

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

Parameters
  • [inout] S: points to an riscv_rfft_fast_instance_f32 structure

  • [in] fftLen: length of the Real Sequence

riscv_status riscv_rfft_init_f32(riscv_rfft_instance_f32 *S, riscv_cfft_radix4_instance_f32 *S_CFFT, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)

Initialization function for the floating-point RFFT/RIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLenReal is not a supported length

Description

The parameter fftLenRealspecifies length of RFFT/RIFFT Process. Supported FFT Lengths are 128, 512, 2048.

The parameter ifftFlagR controls whether a forward or inverse transform is computed. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT 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.

This function also initializes Twiddle factor table.

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

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

  • [in] fftLenReal: length of the FFT.

  • [in] ifftFlagR: 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_rfft_init_q15(riscv_rfft_instance_q15 *S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)

Initialization function for the Q15 RFFT/RIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLenReal is not a supported length

Details

The parameter fftLenReal specifies length of RFFT/RIFFT Process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.

The parameter ifftFlagR controls whether a forward or inverse transform is computed. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT 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.

This function also initializes Twiddle factor table.

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

  • [in] fftLenReal: length of the FFT

  • [in] ifftFlagR: 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_rfft_init_q31(riscv_rfft_instance_q31 *S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)

Initialization function for the Q31 RFFT/RIFFT.

Return

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_ARGUMENT_ERROR : fftLenReal is not a supported length

Details

The parameter fftLenReal specifies length of RFFT/RIFFT Process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.

The parameter ifftFlagR controls whether a forward or inverse transform is computed. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT 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.

This function also initializes Twiddle factor table.

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

  • [in] fftLenReal: length of the FFT

  • [in] ifftFlagR: 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_rfft_q15(const riscv_rfft_instance_q15 *S, q15_t *pSrc, q15_t *pDst)

Processing function for the Q15 RFFT/RIFFT.

Return

none

Input an 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 RFFT sizes. The input and output formats for different RFFT sizes and number of bits to upscale are mentioned in the tables below for RFFT and RIFFT:

../../../_images/RFFTQ15.png

../../../_images/RIFFTQ15.png

Parameters
  • [in] S: points to an instance of the Q15 RFFT/RIFFT structure

  • [in] pSrc: points to input buffer

  • [out] pDst: points to output buffer

void riscv_rfft_q31(const riscv_rfft_instance_q31 *S, q31_t *pSrc, q31_t *pDst)

Processing function for the Q31 RFFT/RIFFT.

Return

none

Input an 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 RFFT sizes. The input and output formats for different RFFT sizes and number of bits to upscale are mentioned in the tables below for RFFT and RIFFT:

../../../_images/RFFTQ31.png

../../../_images/RIFFTQ31.png

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

  • [in] pSrc: points to input buffer

  • [out] pDst: points to output buffer