Introduction Introduction The Texas Instruments TMS320C28x Floating Point Unit (FPU) Library is collection of highly opti- mized application functions written for the C28x+FPU. These functions enable C/C++ programmers to take full advantage of the performance potential of the C28x+FPU. This document provides a description of each function included within the library.
Library Structure Folder Description base Base install directory. default this C:/TI/controlSUITE/libs/dsp/FPU/VERSION For the rest of this document base will be omitted from the directory names base /cmd Linker command files used in the examples base /doc Documentation for the current revision of the library including re- vision history base /examples Examples that illustrate the library functions.
Library Structure 2.3 A Note about C functions and IQMath Most of the functions contained in the C28x FPU library are c-callable assembly. A few functions may be written in C. These C functions are written using the IQMath pre-processor notation. This allows these functions to be easily ported from fixed point to floating-point math.
Function Descriptions Function Descriptions DSP Routines Complex Fast Fourier Transform ................12 Complex Fast Fourier Transform (Unaligned) .
Page 10
Function Descriptions The following functions are included in this release of the FPU Library. The source code for these functions can be found in the source/C28x_FPU_LIB folder. CFFT_f32 void CFFT_f32(CFFT_F32_STRUCT *); CFFT_f32u void CFFT_f32u(CFFT_F32_STRUCT *); CFFT_f32_mag void CFFT_f32_mag(CFFT_F32_STRUCT *); CFFT_f32s_mag void CFFT_f32s_mag(CFFT_F32_STRUCT *);...
Function Descriptions 3.1 Complex Fast Fourier Transform Description: This module computes a 32-bit floating-point complex FFT including input bit reversing. This version of the function requires input buffer memory alignment. If you do not wish to align the input buffer, then use the CFFT_f32u function. Header File: FPU.h Declaration:...
Page 13
Function Descriptions Item Description Format Comment InPtr Input data Pointer to 32-bit float array Input buffer alignment is required. Refer to the alignment section. OutPtr Output buffer Pointer to 32-bit float array CoefPtr Twiddle factors Pointer to 32-bit float array Calculate using CFFT_f32_cossintable ( ).
Page 14
Function Descriptions Notes: 1. This function is not re-entrant as it uses global variables to store arguments; these will be overwritten if the function is invoked while it is currently processing. 2. If the input buffer is not properly aligned, then the output will be unpredictable. 3.
Function Descriptions 3.2 Complex Fast Fourier Transform (Unaligned) Description: This module computes a 32-bit floating-point complex FFT including input bit reversing. This version of the function does not have any buffer alignment requirements. If you can align the input buffer, then use the CFFT_f32 function for improved performance Header File: FPU.h Declaration:...
Page 16
Function Descriptions Example: The following sample code obtains the complex FFT of the input. #include "FPU.h" #define CFFT_STAGES #define CFFT_SIZE (1 << CFFT_STAGES) float CFFTin1Buff[CFFT_SIZE * 2]; float CFFTin2Buff[CFFT_SIZE * 2]; float CFFToutBuff[CFFT_SIZE * 2]; float CFFTF32Coef[CFFT_SIZE]; CFFT_F32_STRUCT cfft; main() cfft.InPtr = CFFTin1Buff;...
Function Descriptions 3.3 Complex Fast Fourier Transform Magnitude Description: This module computes the complex FFT magnitude. The output from CFFT_f32_mag matches the magnitude output from the FFT found in common mathematics software and Code Com- poser Studio FFT graphs. If instead a normalized magnitude like that performed by the fixed-point TMS320C28x IQmath FFT library is required, then the CFFT_f32s_mag function can be used.
Page 18
Function Descriptions Example: The following sample code obtains the complex FFT magnitude. #include "FPU.h" #define CFFT_STAGES #define CFFT_SIZE (1 << CFFT_STAGES) / * CFFTin1Buff section to 4 * FFT_SIZE in the linker file * / #pragma DATA_SECTION(CFFTin1Buff,"CFFTdata1"); float CFFTin1Buff[CFFT_SIZE * 2]; #pragma DATA_SECTION(CFFTin2Buff,"CFFTdata2");...
Function Descriptions 3.4 Complex Fast Fourier Transform Magnitude (Scaled) Description: This module computes the scaled complex FFT magnitude. The scaling is F F T ST AGES and is done to match the normalization performed by the fixed-point TMS320C28x IQmath FFT library for overflow avoidance. Floating-point calculations do not need this scaling to avoid overflow and therefore the CFFT_f32_mag function can be used instead.
Page 20
Function Descriptions Example: The following sample code obtains the scaled FFT magnitude. #include "FPU.h" #define CFFT_STAGES #define CFFT_SIZE (1 << CFFT_STAGES) / * CFFTin1Buff section to 4 * FFT_SIZE in the linker file * / #pragma DATA_SECTION(CFFTin1Buff,"CFFTdata1"); float CFFTin1Buff[CFFT_SIZE * 2]; #pragma DATA_SECTION(CFFTin2Buff,"CFFTdata2");...
Function Descriptions 3.5 Complex Fast Fourier Transform Phase Description: This module computes FFT Phase. Header File: FPU.h Declaration: void CFFT_f32_phase (CFFT_F32_STRUCT * ) Usage: A pointer to the following structure is passed to the CFFT_f32_phase function.It is the same structure described in the CFFT_f32 section: typedef struct { float32 * InPtr;...
Page 22
Function Descriptions Example: The following sample code obtains the Complex FFT phase. #include "FPU.h" #define CFFT_STAGES #define CFFT_SIZE (1 << CFFT_STAGES) / * CFFTin1Buff section to 4 * FFT_SIZE in the linker file * / #pragma DATA_SECTION(CFFTin1Buff,"CFFTdata1"); float CFFTin1Buff[CFFT_SIZE * 2]; #pragma DATA_SECTION(CFFTin2Buff,"CFFTdata2");...
Function Descriptions 3.6 Complex Fast Fourier Transform Twiddle Factors Description: This module generates the twiddle factors used by the complex FFT. Header File: FPU.h Declaration: void CFFT_f32_sincostable (CFFT_F32_STRUCT * ) Usage: A pointer to the following structure is passed to the CFFT_f32_sincostable function.It is the same structure described in the CFFT_f32 section: typedef struct { float32...
Page 24
Function Descriptions Example: The following sample code obtains the scaled FFT magnitude. #include "FPU.h" #define CFFT_STAGES #define CFFT_SIZE (1 << CFFT_STAGES) / * CFFTin1Buff section to 4 * FFT_SIZE in the linker file #pragma DATA_SECTION(CFFTin1Buff,"CFFTdata1"); float CFFTin1Buff[CFFT_SIZE * 2]; #pragma DATA_SECTION(CFFToutBuff,"CFFTdata3"); float CFFToutBuff[CFFT_SIZE * 2];...
Function Descriptions 3.7 Inverse Complex Fast Fourier Transform Description: This module computes a 32-bit floating-point Inverse complex FFT . This version of the function requires input buffer memory alignment. Header File: FPU.h Declaration: void ICFFT_f32 (CFFT_F32_STRUCT * ) Usage: A pointer to the following structure is passed to the CFFT_f32 function: typedef struct { float32 * InPtr;...
Page 26
Function Descriptions to switch the pointer cfft.CurrentInPtr with cfft.CurrentOutPtr so that the output from the stage becomes the input to the stage while the previous ( ) stage’s input buffer will be used as the output for the stage. In this manner the CurrentInPtr and CurrentOutPtr are switched successively for each IFFT stage.Therefore, If the number of stages is odd then at the end of all the coputation we get: currentInPtr=InPtr, currentOutPtr=OutPtr.
Page 27
Function Descriptions Example: The following sample code obtains the complex FFT of the input. #include "FPU.h" #define CFFT_STAGES #define CFFT_SIZE (1 << CFFT_STAGES) / * CFFTin1Buff section to 4 * FFT_SIZE in the linker file #pragma DATA_SECTION(CFFTin1Buff,"CFFTdata1"); float CFFTin1Buff[CFFT_SIZE * 2]; #pragma DATA_SECTION(CFFToutBuff,"CFFTdata2");...
Function Descriptions 3.8 Real Fast Fourier Transform Description: This module computes a 32-bit floating-point real FFT including input bit reversing. This version of the function requires input buffer memory alignment. If you do not wish to align the input buffer, then use the RFFT_f32u function. Header File: FPU.h Declaration:...
Page 29
Function Descriptions Item Description Format Comment InBuf Input data Pointer to 32-bit float array Input buffer alignment is required. Re- fer to the alignment section. OutBuf Output buffer Pointer to 32-bit float array Result of RFFT_f32. This buffer can then be used as the input to the magni- tude and phase calculations.
Page 30
Function Descriptions Example: The following sample code obtains the FFT of the real input. #include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE]; #pragma DATA_SECTION(RFFToutBuff,"RFFTdata2"); float32 RFFToutBuff[RFFT_SIZE];...
Function Descriptions 3.9 Real Fast Fourier Transform (Unaligned) Description: This module computes a 32-bit floating-point real FFT including input bit reversing. This version of the function does not have any buffer alignment requirements. If you can align the input buffer, then use the RFFT_f32 function for improved performance. Header File: FPU.h Declaration:...
Page 32
Function Descriptions Example: The following sample code obtains the FFT of the real input. #include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE]; #pragma DATA_SECTION(RFFToutBuff,"RFFTdata2"); float32 RFFToutBuff[RFFT_SIZE];...
Function Descriptions 3.10 Real Fast Fourier Transform with ADC Input Description: This module computes a 32-bit floating-point real FFT with 12-bit ADC input including input bit reversing. This version of the function requires input buffer memory alignment. If you do not wish to align the input buffer, then use the RFFT_adc_f32u function.
Page 34
Function Descriptions Item Description Format Comment InBuf Input data Pointer to 32-bit float array Not Used. OutBuf Output buffer Pointer to 32-bit float array Result of RFFT_adc_f32. This buffer is then used as the input to the magni- tude and phase calculations. The out- put order for FFTSize = N is: OutBuf[0] = real[0] OutBuf[1] = real[1]...
Page 35
Function Descriptions Example: The following sample code obtains the FFT of the real input. #include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) RFFT_ADC_F32_STRUCT rfft_adc; RFFT_F32_STRUCT rfft; / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE];...
Function Descriptions 3.11 Real Fast Fourier Transform with ADC Input (Unaligned) Description: This module computes a 32-bit floating-point real FFT with 12-bit ADC input including input bit reversing. This version of the function does not have any buffer alignment requirements. If you can align the input buffer, then use the RFFT_adc_f32 function for improved performance.
Page 37
Function Descriptions Example: The following sample code obtains the FFT of the real input. #include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) RFFT_ADC_F32_STRUCT rfft_adc; RFFT_F32_STRUCT rfft; / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE];...
Function Descriptions 3.12 Real Fast Fourier Transform Magnitude Description: This module computes the real FFT magnitude. The output from RFFT_f32_mag matches the magnitude output from the FFT found in common mathematics software and Code Composer Studio FFT graphs. If instead a normalized magnitude like that performed by the fixed-point TMS320C28x IQmath FFT library is required, then the RFFT_f32s_mag function can be used.
Page 39
Function Descriptions Example: The following sample code obtains the FFT magnitude. include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE]; #pragma DATA_SECTION(RFFToutBuff,"RFFTdata2"); float32 RFFToutBuff[RFFT_SIZE]; #pragma DATA_SECTION(RFFTmagBuff,"RFFTdata3");...
Function Descriptions 3.13 Real Fast Fourier Transform Magnitude (Scaled) Description: This module computes the scaled real FFT magnitude. The scaling is , and F F T ST AGES is done to match the normalization performed by the fixed-point TMS320C28x IQmath FFT library for overflow avoidance.
Page 41
Function Descriptions Example: The following sample code obtains the FFT magnitude. include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE]; #pragma DATA_SECTION(RFFToutBuff,"RFFTdata2"); float32 RFFToutBuff[RFFT_SIZE]; #pragma DATA_SECTION(RFFTmagBuff,"RFFTdata3");...
Function Descriptions 3.14 Real Fast Fourier Transform Phase Description: This module computes FFT Phase. Header File: FPU.h Declaration: void RFFT_f32_phase (RFFT_F32_STRUCT * ) Usage: A pointer to the following structure is passed to the RFFT_f32_phase function. It is the same structure described in the RFFT_f32 section: typedef struct { float32...
Page 43
Function Descriptions Example: The following sample code obtains the FFT phase. include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE]; #pragma DATA_SECTION(RFFToutBuff,"RFFTdata2"); float32 RFFToutBuff[RFFT_SIZE]; #pragma DATA_SECTION(RFFTmagBuff,"RFFTdata3");...
Function Descriptions 3.15 Real Fast Fourier Transform Twiddle Factors Description: This module generates the twiddle factors used by the real FFT. Header File: FPU.h Declaration: void RFFT_f32_sincostable (RFFT_F32_STRUCT * ) Usage: A pointer to the following structure is passed to the RFFT_f32_sincostable function. It is the same structure described in the RFFT_f32 section: typedef struct { float32...
Page 45
Function Descriptions Example: The following sample code obtains the FFT phase. #include "FPU.h" #define RFFT_STAGES #define RFFT_SIZE (1 << RFFT_STAGES) / * RFFTin1Buff section to 2 * FFT_SIZE in the linker file #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); float32 RFFTin1Buff[RFFT_SIZE]; #pragma DATA_SECTION(RFFToutBuff,"RFFTdata2"); float32 RFFToutBuff[RFFT_SIZE]; #pragma DATA_SECTION(RFFTmagBuff,"RFFTdata3");...
Function Descriptions 3.16 Finite Impulse Response Filter Description: This routine implements the non-recursive difference equation of an all-zero filter (FIR), of order N. All the coefficients of all-zero filter are assumed to be less than 1 in magnitude. Header File: FPU.h Declaration: void FIR_FP_calc(FIR_FP_handle)
Page 47
Function Descriptions Alignment Requirements: The delay and coefficients buffer must be aligned to a minimum of 2 x (order + 1) words. For example, if the filter order is 31, it will have 32 taps or coefficients each a 32-bit floating point value.
Page 48
Function Descriptions Example: The following sample code obtains the FIR response to a sample input. #include FPU.h #define FIR_ORDER #define SIGNAL_LENGTH (FIR_ORDER + 1) * 2 * 2 #pragma DATA_SECTION(firFP, "firfilt") FIR_FP firFP = FIR_FP_DEFAULTS; #pragma DATA_SECTION(dbuffer, "firldb") float dbuffer[FIR_ORDER+1]; #pragma DATA_SECTION(sigIn, "sigIn");...
Page 49
Function Descriptions Benchmark Information: The number of cycles is given by the following equation: + 52 The following table provides benchmark numbers for the function. Note that these include the cycles used in the call/return from the function. FIR order C-Callable ASM (Cycle Count) Table 3.22: Benchmark Information Sep 10, 2012...
Function Descriptions 3.17 Absolute Value of a Complex Vector Description: This module computes the absolute value of a complex vector. If N is even, use abs_SP_CV_2() for better performance. [ ] = Header File: FPU.h Declaration: void abs_SP_CV(float32 * y, const complex_float * x, const Uint16 N) Usage: abs_SP_CV(x, y, N);...
Function Descriptions 3.18 Absolute Value of an Even Length Complex Vector Description: This module computes the absolute value of an even length complex vector. [ ] = Header File: FPU.h Declaration: void abs_SP_CV_2(float32 * y, const complex_float * x, const Uint16 N) Usage: abs_SP_CV_2(x, y, N);...
Function Descriptions 3.21 Inverse Absolute Value of a Complex Vector Description: This module computes the inverse absolute value of a complex vector. [ ] = Header File: FPU.h Declaration: void iabs_SP_CV(float32 * y, const complex_float * x, const Uint16 N) Usage: iabs_SP_CV(y, x, N);...
Function Descriptions 3.22 Inverse Absolute Value of an Even Length Complex Vector Description: This module calculates the inverse absolute value of an even length complex vector. [ ] = Header File: FPU.h Declaration: void iabs_SP_CV_2(float32 * y, const complex_float * x, const Uint16 N) Usage: iabs_SP_CV_2(y, x, N);...
Function Descriptions 3.23 Index of Maximum Value of an Even Length Real Array Description: This module finds the index of the maximum value of an even length real array. Header File: FPU.h Declaration: Uint16 maxidx_SP_RV_2(float32 * x, Uint16 N) Usage: index = maxidx_SP_RV_2(x, N);...
Function Descriptions 3.24 Mean of Real and Imaginary Parts of a Complex Vector Description: This module calculates the mean of real and imaginary parts of a complex vector. Σ Σ Header File: FPU.h Declaration: complex_float mean_SP_CV_2(const complex_float * x, const Uint16 N) Usage: y = mean_SP_CV_2(x, N);...
Function Descriptions 3.25 Median of a Real Valued Array of Floats (Preserved Inputs) Description: This module computes the median of a real valued array of floats. The input array is preserved. If input array preservation is not required, use median_SP_RV() for better performance. This function calls median_SP_RV() and memcpy_fast().
Page 59
Function Descriptions Example: #include "FPU.h" #define float32 x[N]; float32 main() y = median_noreorder_SP_RV(x, N); Benchmark Information: The cycles for this function are data dependent and therefore the benchmark cannot be pro- vided. Sep 10, 2012...
Function Descriptions 3.26 Median of a real array of floats Description: This module computes the median of a real array of floats. The Input array is NOT preserved. If input array preservation is required, use median_noreorder_SP_RV(). Header File: FPU.h Declaration: float32 median_SP_RV(float32 * , Uint16) Usage: z = median_SP_RV(x, N);...
Function Descriptions 3.27 Complex Multiply of Two Floating Point Numbers Description: This module multiplies two floating point complex values. Header File: FPU.h Declaration: complex_float mpy_SP_CSxCS(complex_float w, complex_float x) Usage: y = mpy_SP_CSxCS(w,x); complex_float w input 1 complex_float x input 2 complex_float y result The type “complex_float”...
Function Descriptions 3.29 Multiplication of a Complex Vector and the Complex Conjugate of another Vector Description: This module multiplies a complex vector (w) and the complex conjugate of another complex vector (x). [ ] = [ ] = [ ] = [ ] = [ ] + Header File:...
Function Descriptions 3.30 Multiplication of a Real scalar and a Real Vector Description: This module multiplies a real scalar and a real vector. [ ] = Header File: FPU.h Declaration: void mpy_SP_RSxRV_2(float32 * y, const float32 * x, const float32 c, const Uint16 N) Usage: mpy_SP_RSxRV_2(y, x, c, N);...
Function Descriptions 3.31 Multiplication of a Real Scalar, a Real Vector, and another Real Vector Description: This module multiplies a real scalar with a real vector. and another real vector. [ ] = Header File: FPU.h Declaration: void mpy_SP_RSxRVxRV_2(float32 * y, const float32 * w, const float32 * x, const float32 c, const Uint16 N) Usage: mpy_SP_RSxRVxRV_2(y, w, x, c, N);...
Function Descriptions 3.32 Multiplication of a Real Vector and a Complex Vector Description: This module multiplies a real vector and a complex vector. [ ] = [ ] = Header File: FPU.h Declaration: void mpy_SP_RVxCV(complex_float * y, const complex_float * w, const float32 * x, const Uint16 N) Usage: mpy_SP_RVxCV(y, x, c, N);...
Function Descriptions 3.33 Multiplication of a Real Vector and a Real Vector Description: This module multiplies two real vectors. [ ] = Header File: FPU.h Declaration: void mpy_SP_RVxRV_2(float32 * y, const float32 * w, const float32 * x, const Uint16 N) Usage: mpy_SP_RVxRV_2(y, w, x, N);...
Function Descriptions 3.34 Sort an Array of Floats Description: This module sorts an array of floats. This function is a partially optmized version of qsort.c from the C28x cgtools lib qsort() v6.0.1. Header File: FPU.h Declaration: void qsort_SP_RV(void * x, Uint16 N) Usage: qsort_SP_RV(x, N);...
Function Descriptions 3.35 Rounding (Unbiased) of a Floating Point Scalar Description: This module performs the unbiased rounding of a floating point scalar. Header File: FPU.h Declaration: float32 rnd_SP_RS(float32 x) Usage: y = rnd_SP_RS(x); float32 x input value float32 y result Alignment Requirements: None Notes:...
Function Descriptions 3.38 Fast Square Root Description: This function is an inline optmized fast square root function using two iterations of the newton raphson method to achieve an accurate result. Header File: FPU.h Declaration: inline static float32 __ffsqrtf(float32 x) Usage: __ffsqrtf(x);...
Function Descriptions 3.40 Optimized Memory Set Description: This module performs optimized memory sets. Header File: FPU.h Declaration: void memset_fast(void * dst, int16 value, Uint16 N) Usage: memset_fast(dst, value, N); void* dst pointer to destination int16 value initialization value Uint16 N number of 16-bit words to initialize Alignment Requirements: None...
Page 75
Revision History Revision History V1.31: Minor Update Revised documentation Updated median_SP_RV() routine V1.30: Moderate Update Added vector and matrix functions and examples Added Inverse complex FFT and example Revised benchmark numbers Revised alignment requirements for FFT’s V1.20: Moderate Update Added equiripple FIR filter function V1.10: Moderate Update Includes the complex FFT and real FFT with 12-bit ADC fixed-point input supporting functions.
Page 76
IMPORTANT NOTICE Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete.
Need help?
Do you have a question about the C28 Series and is the answer not in the manual?
Questions and answers