CSI-DSP  Version 1.0.0
CSI DSP Software Library
Functions
Real FFT Functions

Functions

void csky_rfft_fast_f32 (csky_rfft_fast_instance_f32 *S, float32_t *p, float32_t *pOut, uint8_t ifftFlag)
 Processing function for the floating-point real FFT. More...
 
csky_status csky_rfft_fast_init_f32 (csky_rfft_fast_instance_f32 *S, uint16_t fftLen)
 Initialization function for the floating-point real FFT. More...
 
csky_status csky_cfft_radix4_init_f32 (csky_cfft_radix4_instance_f32 *S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag)
 Initialization function for the floating-point CFFT/CIFFT. More...
 
csky_status csky_rfft_init_f32 (csky_rfft_instance_f32 *S, csky_cfft_radix4_instance_f32 *S_CFFT, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)
 Initialization function for the floating-point RFFT/RIFFT. More...
 
csky_status csky_rfft_init_q15 (csky_rfft_instance_q15 *S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)
 Initialization function for the Q15 RFFT/RIFFT. More...
 
csky_status csky_rfft_init_q31 (csky_rfft_instance_q31 *S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag)
 Initialization function for the Q31 RFFT/RIFFT. More...
 
void csky_rfft_q15 (const csky_rfft_instance_q15 *S, q15_t *pSrc, q15_t *pDst)
 Processing function for the Q15 RFFT/RIFFT. More...
 
void csky_rfft_q31 (const csky_rfft_instance_q31 *S, q31_t *pSrc, q31_t *pDst)
 Processing function for the Q31 RFFT/RIFFT. More...
 

Description

The CSI 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.
RFFT.gif
Real Fast Fourier Transform
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.
RIFFT.gif
Real Inverse Fast Fourier Transform
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 csky_rfft_fast_f32() and csky_rfft_fast_init_f32(). The older functions csky_rfft_f32() and csky_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:
*X[0] - real data
*X[1] - complex data
*X[2] - complex data
*...
*X[fftLen/2-1] - complex data
*X[fftLen/2] - real data
*X[fftLen/2+1] - conjugate of X[fftLen/2-1]
*X[fftLen/2+2] - conjugate of X[fftLen/2-2]
*...
*X[fftLen-1] - conjugate of X[1]
  
Looking at the data, we see that we can uniquely represent the FFT using only
*N/2+1 samples:
*X[0] - real data
*X[1] - complex data
*X[2] - complex data
*...
*X[fftLen/2-1] - complex data
*X[fftLen/2] - real data
  
Looking more closely we see that the first and last samples are real valued. They can be packed together and we can thus represent the FFT of an N-point real sequence by N/2 complex values:
*X[0],X[N/2] - packed real data: X[0] + jX[N/2]
*X[1] - complex data
*X[2] - complex data
*...
*X[fftLen/2-1] - complex data
  
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.
The forward and inverse real FFT functions apply the standard FFT scaling; no scaling on the forward transform and 1/fftLen scaling on the inverse transform.
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:
*csky_rfft_instance_q31 S = {fftLenReal, fftLenBy2, ifftFlagR, bitReverseFlagR, twidCoefRModifier, pTwiddleAReal, pTwiddleBReal, pCfft};
*csky_rfft_instance_q15 S = {fftLenReal, fftLenBy2, ifftFlagR, bitReverseFlagR, twidCoefRModifier, pTwiddleAReal, pTwiddleBReal, pCfft};
  
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 csky_cfft_radix4_f32() for details regarding static initialization of the complex FFT instance structure.

Function Documentation

csky_status csky_cfft_radix4_init_f32 ( csky_cfft_radix4_instance_f32 S,
uint16_t  fftLen,
uint8_t  ifftFlag,
uint8_t  bitReverseFlag 
)
Deprecated:
Do not use this function. It has been superceded by csky_cfft_f32 and will be removed in the future.
Parameters
[in,out]*Spoints to an instance of the floating-point CFFT/CIFFT structure.
[in]fftLenlength of the FFT.
[in]ifftFlagflag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform.
[in]bitReverseFlagflag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output.
Returns
The function returns CSKY_MATH_SUCCESS if initialization is successful or CSKY_MATH_ARGUMENT_ERROR if fftLen is not a supported value.
Description:
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.
void csky_rfft_fast_f32 ( csky_rfft_fast_instance_f32 S,
float32_t p,
float32_t pOut,
uint8_t  ifftFlag 
)
Parameters
[in]*Spoints to an csky_rfft_fast_instance_f32 structure.
[in]*ppoints to the input buffer.
[in]*pOutpoints to the output buffer.
[in]ifftFlagRFFT if flag is 0, RIFFT if flag is 1
Returns
none.
csky_status csky_rfft_fast_init_f32 ( csky_rfft_fast_instance_f32 S,
uint16_t  fftLen 
)
Parameters
[in,out]*Spoints to an csky_rfft_fast_instance_f32 structure.
[in]fftLenlength of the Real Sequence.
Returns
The function returns CSKY_MATH_SUCCESS if initialization is successful or CSKY_MATH_ARGUMENT_ERROR if fftLen is not a supported value.
Description:
The parameter fftLen Specifies 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.
csky_status csky_rfft_init_f32 ( csky_rfft_instance_f32 S,
csky_cfft_radix4_instance_f32 S_CFFT,
uint32_t  fftLenReal,
uint32_t  ifftFlagR,
uint32_t  bitReverseFlag 
)
Deprecated:
Do not use this function. It has been superceded by csky_rfft_fast_init_f32 and will be removed in the future.
Parameters
[in,out]*Spoints to an instance of the floating-point RFFT/RIFFT structure.
[in,out]*S_CFFTpoints to an instance of the floating-point CFFT/CIFFT structure.
[in]fftLenReallength of the FFT.
[in]ifftFlagRflag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform.
[in]bitReverseFlagflag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output.
Returns
The function returns CSKY_MATH_SUCCESS if initialization is successful or CSKY_MATH_ARGUMENT_ERROR if fftLenReal is not a supported value.
Description:
The parameter fftLenReal Specifies 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.
csky_status csky_rfft_init_q15 ( csky_rfft_instance_q15 S,
uint32_t  fftLenReal,
uint32_t  ifftFlagR,
uint32_t  bitReverseFlag 
)
Parameters
[in,out]*Spoints to an instance of the Q15 RFFT/RIFFT structure.
[in]fftLenReallength of the FFT.
[in]ifftFlagRflag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform.
[in]bitReverseFlagflag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output.
Returns
The function returns CSKY_MATH_SUCCESS if initialization is successful or CSKY_MATH_ARGUMENT_ERROR if fftLenReal is not a supported value.
Description:
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.
csky_status csky_rfft_init_q31 ( csky_rfft_instance_q31 S,
uint32_t  fftLenReal,
uint32_t  ifftFlagR,
uint32_t  bitReverseFlag 
)
Parameters
[in,out]*Spoints to an instance of the Q31 RFFT/RIFFT structure.
[in]fftLenReallength of the FFT.
[in]ifftFlagRflag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform.
[in]bitReverseFlagflag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output.
Returns
The function returns CSKY_MATH_SUCCESS if initialization is successful or CSKY_MATH_ARGUMENT_ERROR if fftLenReal is not a supported value.
Description:
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.
void csky_rfft_q15 ( const csky_rfft_instance_q15 S,
q15_t pSrc,
q15_t pDst 
)
Parameters
[in]*Spoints to an instance of the Q15 RFFT/RIFFT structure.
[in]*pSrcpoints to the input buffer.
[out]*pDstpoints to the output buffer.
Returns
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:
RFFT Size Input Format Output Format Number of bits to upscale
32 1.15 5.11 4
64 1.15 6.10 5
128 1.15 7.9 6
256 1.15 8.8 7
512 1.15 9.7 8
1024 1.15 10.6 9
2048 1.15 11.5 10
4096 1.15 12.4 11
8192 1.15 13.3 12
RIFFT Size Input Format Output Format Number of bits to upscale
32 1.15 5.11 0
64 1.15 6.10 0
128 1.15 7.9 0
256 1.15 8.8 0
512 1.15 9.7 0
1024 1.15 10.6 0
2048 1.15 11.5 0
4096 1.15 12.4 0
8192 1.15 13.3 0
void csky_rfft_q31 ( const csky_rfft_instance_q31 S,
q31_t pSrc,
q31_t pDst 
)
Parameters
[in]*Spoints to an instance of the Q31 RFFT/RIFFT structure.
[in]*pSrcpoints to the input buffer.
[out]*pDstpoints to the output buffer.
Returns
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:
RFFT Size Input Format Output Format Number of bits to upscale
32 1.31 5.27 4
64 1.31 6.26 5
128 1.31 7.25 6
256 1.31 8.24 7
512 1.31 9.23 8
1024 1.31 10.22 9
2048 1.31 11.21 10
4096 1.31 12.20 11
8192 1.31 13.19 12
RIFFT Size Input Format Output Format Number of bits to upscale
32 1.31 5.27 0
64 1.31 6.26 0
128 1.31 7.25 0
256 1.31 8.24 0
512 1.31 9.23 0
1024 1.31 10.22 0
2048 1.31 11.21 0
4096 1.31 12.20 0
8192 1.31 13.19 0