Logo
MSP DSP Library
Real FFT

Data Structures

struct  msp_fft_q15_params
 Parameter structure for Q15 real FFT functions. More...
 
struct  msp_fft_iq31_params
 Parameter structure for IQ31 real FFT functions. More...
 

Functions

msp_status msp_fft_auto_q15 (const msp_fft_q15_params *params, int16_t *src, uint16_t *shift)
 Real forward FFT function with auto-scaling. More...
 
msp_status msp_fft_fixed_q15 (const msp_fft_q15_params *params, int16_t *src)
 Real forward FFT function with fixed scaling by two at each stage. More...
 
msp_status msp_fft_iq31 (const msp_fft_iq31_params *params, int32_t *src)
 Real forward FFT function without scaling. More...
 
msp_status msp_ifft_auto_q15 (const msp_fft_q15_params *params, int16_t *src, uint16_t shift)
 Real result inverse FFT function with auto-scaling. More...
 
msp_status msp_ifft_fixed_q15 (const msp_fft_q15_params *params, int16_t *src)
 Real result inverse FFT function with fixed scaling by two at each stage. More...
 
msp_status msp_ifft_iq31 (const msp_fft_iq31_params *params, int32_t *src)
 Real result inverse FFT function without scaling. More...
 

Detailed Description

Functions for performing forward and inverse FFT of real 16-bit and 32-bit input data.

Function Documentation

msp_status msp_fft_auto_q15 ( const msp_fft_q15_params params,
int16_t *  src,
uint16_t *  shift 
)

Real forward FFT function with auto-scaling.

Details
Computes the forward discreet Fourier transform (DFT) of 16-bit real inputs. If the inputs are not already in bit reversed order the bit reversal parameter must be set. The output is monitored for overflow and scaled by a factor of two when an overflow risk is detected. The shift parameter contains the number of bit shifts that were applied to the output.
This functions requires half the data storage and consumes roughly half the cycles and energy as running a complex FFT of the same length. When transforming purely real inputs, such as samples from an ADC or analog sensor, it is recommended to use the real FFT functions.
Pseudo code
y = fft(real(x)) * 2^-shift
Scaling
Scaling is applied as needed to prevent saturation of the output. The scale factor that was applied to the output is returned in the shift parameter and can be used to calculate the result by applying the following function.
result = result * 2^shift
LEA Support
This function is supported by LEA and requires data to be placed into shared LEA memory with alignment equal to twice the data length (e.g. a 256-point real FFT requires 512-byte alignment). When allocating data the MSP_ALIGN_FFT_Q15 macro can be used to calculate correct alignment. The twiddle table pointer parameter is not used with LEA and can be null or uninitialized.
Parameters
paramsPointer to the real FFT parameter structure.
srcPointer to the real data array to perform the FFT on.
shiftAuto-scaling shift that was applied to the output.
Returns
Status of the operation.
msp_status msp_fft_fixed_q15 ( const msp_fft_q15_params params,
int16_t *  src 
)

Real forward FFT function with fixed scaling by two at each stage.

Details
Computes the forward discreet Fourier transform (DFT) of 16-bit real inputs. If the inputs are not already in bit reversed order the bit reversal parameter must be set. The output is scaled by a factor of two for each stage of the DFT.
This functions requires half the data storage and consumes roughly half the cycles and energy as running a complex FFT of the same length. When transforming purely real inputs, such as samples from an ADC or analog sensor, it is recommended to use the real FFT functions.
Pseudo code
y = fft(real(x)) ./ (N/2)
Scaling
Each stage of the real FFT, with the exception of the final split stage, scales the result by a factor of 0.5. The output format can either be interpreted as the same type with (N/2) scaling or a different fixed point data type. This can be helpful when using the IQmathLib to process the results of the FFT, such as computing the magnitude or phase angle of the complex result.
Length Input Type Result Type
16 _q15 _q12
32 _q15 _q11
64 _q15 _q10
128 _q15 _q9
256 _q15 _q8
512 _q15 _q7
1024 _q15 _q6
2048 _q15 _q5
4096 _q15 _q4
The following table lists the applied scaling factor and resulting data type when the input is a 16-bit integer.
Length Input Type Result Type
16 int16_t (int16_t)(result / 8)
32 int16_t (int16_t)(result / 16)
64 int16_t (int16_t)(result / 32)
128 int16_t (int16_t)(result / 64)
256 int16_t (int16_t)(result / 128)
512 int16_t (int16_t)(result / 256)
1024 int16_t (int16_t)(result / 512)
2048 int16_t (int16_t)(result / 1024)
4096 int16_t (int16_t)(result / 2048)
LEA Support
This function is supported by LEA and requires data to be placed into shared LEA memory with alignment equal to twice the data length (e.g. a 256-point real FFT requires 512-byte alignment). When allocating data the MSP_ALIGN_FFT_Q15 macro can be used to calculate correct alignment. The twiddle table pointer parameter is not used with LEA and can be null or uninitialized.
Parameters
paramsPointer to the real FFT parameter structure.
srcPointer to the real data array to perform the FFT on.
Returns
Status of the operation.
msp_status msp_fft_iq31 ( const msp_fft_iq31_params params,
int32_t *  src 
)

Real forward FFT function without scaling.

Details
Computes the forward discreet Fourier transform (DFT) of 32-bit real inputs. If the inputs are not already in bit reversed order the bit reversal parameter must be set. The output is not scaled.
This functions requires half the data storage and consumes roughly half the cycles and energy as running a complex FFT of the same length. When transforming purely real inputs, such as samples from an ADC or analog sensor, it is recommended to use the real FFT functions.
Pseudo code
y = fft(real(x))
LEA Support
This function is supported by LEA and requires data to be placed into shared LEA memory with alignment equal to four times the data length (e.g. a 256-point real FFT requires 1024-byte alignment). When allocating data the MSP_ALIGN_FFT_IQ31 macro can be used to calculate correct alignment. The twiddle table pointer parameter is not used with LEA and can be null or uninitialized.
Parameters
paramsPointer to the real FFT parameter structure.
srcPointer to the real data array to perform the FFT on.
Returns
Status of the operation.
Examples:
transform_ex3_fft_iq31.c.
msp_status msp_ifft_auto_q15 ( const msp_fft_q15_params params,
int16_t *  src,
uint16_t  shift 
)

Real result inverse FFT function with auto-scaling.

Details
Computes the inverse discreet Fourier transform (DFT) of 16-bit complex inputs with real result. If the inputs are not already in bit reversed order the bit reversal parameter must be set. Automatic scaling is performed such that this is the direct inverse of the forward FFT with auto scaling.
This functions uses half the data storage and consumes roughly half the cycles and energy as running a complex IFFT of the same length. When transforming purely real inputs, such as samples from an ADC or analog sensor, it is recommended to use the real FFT functions.
Pseudo code
y = (real(ifft(x)) * 2^shift) ./ (N/2)
LEA Support
This function is supported by LEA and requires data to be placed into shared LEA memory with alignment equal to twice the data length (e.g. a 256-point real FFT requires 512-byte alignment). When allocating data the MSP_ALIGN_FFT_Q15 macro can be used to calculate correct alignment. The twiddle table pointer parameter is not used with LEA and can be null or uninitialized.
Parameters
paramsPointer to the real FFT parameter structure.
srcPointer to the real data array to perform the FFT on.
shiftAuto-scaling shift that was applied to the forward FFT.
Returns
Status of the operation.
msp_status msp_ifft_fixed_q15 ( const msp_fft_q15_params params,
int16_t *  src 
)

Real result inverse FFT function with fixed scaling by two at each stage.

Details
Computes the inverse discreet Fourier transform (DFT) of 16-bit complex inputs with real result. If the inputs are not already in bit reversed order the bit reversal parameter must be set. Fixed scaling is performed such that this is the direct inverse of the forward FFT with fixed scaling.
This functions uses half the data storage and consumes roughly half the cycles and energy as running a complex IFFT of the same length. When transforming purely real inputs, such as samples from an ADC or analog sensor, it is recommended to use the real FFT functions.
Pseudo code
y = real(ifft(x))
Scaling
This function is the direct inverse of the forward real FFT with fixed scaling. The following fixed point input types will all result in Q15 results.
Length Input Type Result Type
16 _q12 _q15
32 _q11 _q15
64 _q10 _q15
128 _q9 _q15
256 _q8 _q15
512 _q7 _q15
1024 _q6 _q15
2048 _q5 _q15
4096 _q4 _q15
LEA Support
This function is supported by LEA and requires data to be placed into shared LEA memory with alignment equal to twice the data length (e.g. a 256-point real FFT requires 512-byte alignment). When allocating data the MSP_ALIGN_FFT_Q15 macro can be used to calculate correct alignment. The twiddle table pointer parameter is not used with LEA and can be null or uninitialized.
Parameters
paramsPointer to the real FFT parameter structure.
srcPointer to the real data array to perform the FFT on.
Returns
Status of the operation.
msp_status msp_ifft_iq31 ( const msp_fft_iq31_params params,
int32_t *  src 
)

Real result inverse FFT function without scaling.

Details
Computes the inverse discreet Fourier transform (DFT) of 32-bit complex inputs with real result. If the inputs are not already in bit reversed order the bit reversal parameter must be set. Fixed scaling is performed such that this is the direct inverse of the forward FFT without scaling.
This functions uses half the data storage and consumes roughly half the cycles and energy as running a complex IFFT of the same length. When transforming purely real inputs, such as samples from an ADC or analog sensor, it is recommended to use the real FFT functions.
Pseudo code
y = real(ifft(x)) ./ N
LEA Support
This function is supported by LEA and requires data to be placed into shared LEA memory with alignment equal to four times the data length (e.g. a 256-point real FFT requires 1024-byte alignment). When allocating data the MSP_ALIGN_FFT_IQ31 macro can be used to calculate correct alignment. The twiddle table pointer parameter is not used with LEA and can be null or uninitialized.
Parameters
paramsPointer to the real FFT parameter structure.
srcPointer to the real data array to perform the FFT on.
Returns
Status of the operation.