Real FFT Functions

void riscv_rfft_q15(const riscv_rfft_instance_q15 *S, q15_t *pSrc, q15_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 algorithm 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.
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.
The input for the inverse RFFT should keep the same format as the output of the forward RFFT. A first processing stage preprocess the data to later perform an inverse CFFT.
The algorithms for floatingpoint, Q15, and Q31 data are slightly different and we describe each algorithm in turn.
 Floatingpoint
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. For f16, the functions are riscv_rfft_fast_f16() and riscv_rfft_fast_init_f16(). For f64, the functions are riscv_rfft_fast_f64() and riscv_rfft_fast_init_f64().
The FFT of a real Npoint sequence has even symmetry in the frequency domain. The second half of the data equals the conjugate of the first half flipped in frequency. This conjugate part is not computed by the float RFFT. As consequence, the output of a N point real FFT should be a N//2 + 1 complex numbers so N + 2 floats.
It happens that the first complex of number of the RFFT output is actually all real. Its real part represents the DC offset. The value at Nyquist frequency is also real.
Those two complex numbers can be encoded with 2 floats rather than using two numbers with an imaginary part set to zero.
The implementation is using a trick so that the output buffer can be N float : the last real is packaged in the imaginary part of the first complex (since this imaginary part is not used and is zero).
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.
But warning, contrary to the float version, the fixed point implementation RFFT is also computing the conjugate part (except for MVE version) so the output buffer must be bigger. Also the fixed point RFFTs are not using any trick to pack the DC and Nyquist frequency in the same complex number. The RIFFT is not using the conjugate part but it is still using the Nyquist frequency value. The details are given in the documentation for the functions.
The complex transforms used internally include scaling to prevent fixedpoint overflows. The overall scaling equals 1/(fftLen/2). Due to the use of complex transform internally, the source buffer is modified by the rfft.
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 except for MVE versions where it is mandatory. If you don’t use the initialization functions, then the structures should be initialized with code similar to the one below: where
fftLenReal
is the length of the real transform;fftLenBy2
length of the internal complex transform (fftLenReal/2).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;pTwiddleAReal
points to the A array of twiddle coefficients;pTwiddleBReal
points to the B array of twiddle coefficients;pCfft
points to the CFFT Instance structure. The CFFT structure must also be initialized.Note that with MVE versions you can’t initialize instance structures directly and must use the initialization function.
Functions

void riscv_rfft_q15(const riscv_rfft_instance_q15 *S, q15_t *pSrc, q15_t *pDst)
Processing function for the Q15 RFFT/RIFFT.
RFFT Size
Input Format
Output Format
Number of bits to upscale
32
1.15
6.10
5
64
1.15
7.9
6
128
1.15
8.8
7
256
1.15
9.7
8
512
1.15
10.6
9
1024
1.15
11.5
10
2048
1.15
12.4
11
4096
1.15
13.3
12
8192
1.15
14.2
13
 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:
 Input and Output formats for RFFT Q15
RIFFT Size
Input Format
Output Format
Number of bits to upscale
32
1.15
6.10
0
64
1.15
7.9
0
128
1.15
8.8
0
256
1.15
9.7
0
512
1.15
10.6
0
1024
1.15
11.5
0
2048
1.15
12.4
0
4096
1.15
13.3
0
8192
1.15
14.2
0
 Input and Output formats for RIFFT Q15
If the input buffer is of length N (fftLenReal), the output buffer must have length 2N since it is containing the conjugate part. The input buffer is modified by this function.
For the RIFFT, the source buffer must have length N+2 since the Nyquist frequency value is needed but conjugate part is ignored. It is not using the packing trick of the float version.
 Parameters
S – [in] points to an instance of the Q15 RFFT/RIFFT structure
pSrc – [in] points to input buffer (Source buffer is modified by this function.)
pDst – [out] points to output buffer
 Returns
none