1.4.2 DSP Fixed-Point Math Libraries

Introduction

This topic describes the DSP Fixed-Point Math Libraries.

Description

The DSP Fixed-Point Library are available for the PIC32MZ family of microcontrollers. This library was created from optimized assembly routines written specifically for devices with microAptiv™ core features that utilize DSP ASE.

The LIBQ library is required to use the DSP library.

The DSP Fixed-Point Library contains building block functions for developing digital signal processing algorithms. The library supports the Q15 and Q31 fractional data formats. The functions are implemented in efficient assembly specifically targeted at the DSP extensions in this core family.

The library makes these functions available in a simple C-callable structure.

Functions included in the DSP Fixed-Point Library include complex math, vector math, matrix math, digital filters, and transforms.

In many cases, these functions require specific data structures to operate, which are detailed in the header file and examples.

Using the Library

This topic describes the basic architecture of the DSP Fixed-Point Library and provides information and examples on its use.

Interface Header File: dsp.h

The interface to the DSP Fixed-Point library is defined in the dsp.h header file. Any C language source (.c) file that uses the DSP.

Fixed-Point library must include dsp.h. This file is automatically included by definitions.h when the library is generated using MHC.

Some functions make special use of the optimized fixed-point math library libq.h. For use of those functions, the libq.h file must also be included in a project. The libq.h file is also installed with MPLAB Harmony. Specific notes within each function will describe if the function is dependent on the LibQ Fixed-Point Math Library.

Library Files:

The DSP Fixed-Point library archive (.a) files are installed with MPLAB Harmony. Although there are two PIC32 DSP files, the linker will only utilize one of these depending on your device usage.

This library is only available in prebuilt binary form, with prototypes for each function described in the dsp.h file. The available library versions are:

• dsp_mips32_mz_ef_nfO3.a

• dsp_mips32_mz_ef_nfOs.a

The naming convention for these libraries is as follows:

<name><arch><core><fpu><codes>.a

where, "name" is the name of the library (DSP); "arch" is the 32 MIPS architecture (MIPS32); "core" is the microAptive core with DSP ASE extensions (MZ); and "fpu" indicates that a Floating Point Unit(FPU) is available. The "codes" are as follows:

• <nf, fpu> - FPU disabled or enabled

• <O3,OS> - Fully optimized for speed or optimized for size.

Configuring the Library using MHC

Select the Audio/Math/Math Libraries component to load the libq_c, libq/dsp libraries.

The project configuration should now contain the Math Libraries block.

Either the Speed Optimized (as shown above) or the Space Optimized versions of the library can be selected (only 1) to be generated to the project.

Note: LIBQ is also required to be selected.

Library Overview

The library interface routines are divided into various sub-sections, which address one of the blocks or the overall operation of the DSP Fixed-Point Math Library.

Complex Math Functions

General mathematical operations using a complex structure with the form (a + bi)

Vector Math Functions

Mathematical operations on a array of numbers or vector

Matrix Math Functions

Mathematical operations on a matrix

Digital Filter Functions

FIR and IIR filtering functions with various architectures

Transform Functions

FFT, Windows and related transform elements

Support Functions

Quick support functions for numerical transform.

The DSP Fixed-Point Library uses fixed-point fractional functions to optimize execution speed. These functions limit the accuracy of the calculations to the bits specified for the function. Due to parallelism in some operations, the 16-bit version of the functions are more efficient than their 32-bit counterparts. In many cases both 16-bit and 32-bit functions are available to give the user the choice of balance between speed and functional resolution.

A majority of the DSP Fixed-Point Library uses functions with variables in Q15 or Q31 format. Representations of these numbers are given in Data Types and Constants in the Library Interface section, and generally are int16_t (for Q15 fractional representation) and int32_t (for Q31 fractional representation). This limits the equivalent numerical range to roughly -1.0 to 0.999999999. It is possible to represent other number ranges, but scaling before and after the function call are necessary.

All library functions will saturate the output if the value exceeds the maximum or is lower than the minimum allowable value for that resolution.

Some prescaling may be necessary to prevent unwanted saturation in functions that may otherwise create calculation errors.

Library Interface

Functions

NameDescription
DSP_ComplexAdd32Calculates the sum of two complex numbers.
DSP_ComplexConj16Calculates the complex conjugate of a complex number.
DSP_ComplexConj32Calculates the complex conjugate of a complex number.
DSP_ComplexDotProd32Calculates the dot product of two complex numbers.
DSP_ComplexMult32Multiplies two complex numbers.
DSP_ComplexScalarMult32Multiplies a complex number and a scalar number.
DSP_ComplexSub32Calculates the difference of two complex numbers.
DSP_FilterFIR32Performs a Finite Infinite Response (FIR) filter on a vector.
DSP_FilterFIRDecim32Performs a decimating FIR filter on the input array.
DSP_FilterFIRInterp32Performs an interpolating FIR filter on the input array.
DSP_FilterIIR16Performs a single-sample cascaded biquad Infinite Impulse Response (IIR) filter.
DSP_FilterIIRBQ16Performs a single-pass IIR Biquad Filter.
DSP_FilterIIRBQ16_cascade8Performs a single-sample IIR Biquad Filter as a cascade of 8 series filters.
DSP_FilterIIRBQ16_fastPerforms a single-pass IIR Biquad Filter.
DSP_FilterIIRBQ16_parallel8Performs a 8 parallel single-pass IIR Biquad Filters, and sums the result.
DSP_FilterIIRBQ16_parallel8_fastPerforms a 8 parallel single-pass IIR Biquad Filters, and sums the result.
DSP_FilterIIRBQ32Performs a high resolution single-pass IIR Biquad Filter.
DSP_FilterIIRSetup16Converts biquad structure to coeffs array to set up IIR filter.
DSP_FilterLMS16Performs a single sample Least Mean Squares FIR Filter.
DSP_MatrixAdd32Addition of two matrices C = (A + B).
DSP_MatrixEqual32Equality of two matrices C = (A).
DSP_MatrixInit32Initializes the first N elements of a Matrix to the value num.
DSP_MatrixMul32Multiplication of two matrices C = A x B.
DSP_MatrixScale32Scales each element of an input buffer (matrix) by a fixed number.
DSP_MatrixSub32Subtraction of two matrices C = (A - B).
DSP_MatrixTranspose32Transpose of a Matrix C = A (T).
DSP_TransformFFT16Creates an Fast Fourier Transform (FFT) from a time domain input.
DSP_TransformFFT16_setupCreates FFT coefficients for use in the FFT16 function.
DSP_TransformFFT32Creates an Fast Fourier Transform (FFT) from a time domain input.
DSP_TransformFFT32_setupCreates FFT coefficients for use in the FFT32 function.
DSP_TransformIFFT16Creates an Inverse Fast Fourier Transform (FFT) from a frequency domain input.
DSP_TransformWindow_Bart16Perform a Bartlett window on a vector.
DSP_TransformWindow_Bart32Perform a Bartlett window on a vector.
DSP_TransformWindow_Black16Perform a Blackman window on a vector.
DSP_TransformWindow_Black32Perform a Blackman window on a vector.
DSP_TransformWindow_Cosine16Perform a Cosine (Sine) window on a vector.
DSP_TransformWindow_Cosine32Perform a Cosine (Sine) window on a vector.
DSP_TransformWindow_Hamm16Perform a Hamming window on a vector.
DSP_TransformWindow_Hamm32Perform a Hamming window on a vector.
DSP_TransformWindow_Hann16Perform a Hanning window on a vector.
DSP_TransformWindow_Hann32Perform a Hanning window on a vector.
DSP_TransformWindow_Kaiser16Perform a Kaiser window on a vector.
DSP_TransformWindow_Kaiser32Perform a Kaiser window on a vector.
DSP_TransformWinInit_Bart16Create a Bartlett window.
DSP_TransformWinInit_Bart32Create a Bartlett window.
DSP_TransformWinInit_Black16Create a Blackman window.
DSP_TransformWinInit_Black32Create a Blackman window.
DSP_TransformWinInit_Cosine16Create a Cosine (Sine) window.
DSP_TransformWinInit_Cosine32Create a Cosine (Sine) window.
DSP_TransformWinInit_Hamm16Create a Hamming window.
DSP_TransformWinInit_Hamm32Create a Hamming window.
DSP_TransformWinInit_Hann16Create a Hanning window.
DSP_TransformWinInit_Hann32Create a Hanning window.
DSP_TransformWinInit_Kaiser16Create a Kaiser window.
DSP_TransformWinInit_Kaiser32Create a Kaiser window.
DSP_VectorAbs16Calculate the absolute value of a vector.
DSP_VectorAbs32Calculate the absolute value of a vector.
DSP_VectorAdd16Calculate the sum of two vectors.
DSP_VectorAdd32Calculate the sum of two vectors.
DSP_VectorAddc16Calculate the sum of a vector and a constant.
DSP_VectorAddc32Calculate the sum of a vector and a constant.
DSP_VectorAutocorr16Computes the Autocorrelation of a Vector.
DSP_VectorBexp16Computes the maximum binary exponent of a vector.
DSP_VectorBexp32Computes the maximum binary exponent of a vector.
DSP_VectorChkEqu32Compares two input vectors, returns an integer 1 if equal, and 0 if not equal.
DSP_VectorCopyCopies the elements of one vector to another.
DSP_VectorCopyReverse32Reverses the order of elements in one vector and copies them into another.
DSP_VectorDivCDivides the first N elements of inVector by a constant divisor, and stores the result in outVector.
DSP_VectorDotp16Computes the dot product of two vectors, and scales the output by a binary factor.
DSP_VectorDotp32Computes the dot product of two vectors, and scales the output by a binary factor.
DSP_VectorExpComputes the EXP (e^x) of the first N elements of inVector, and stores the result in outVector.
DSP_VectorFillFills an input vector with scalar data.
DSP_VectorLnComputes the Natural Log, Ln(x), of the first N elements of inVector, and stores the result in outVector.
DSP_VectorLog10Computes the Log10(x), of the first N elements of inVector, and stores the result in outVector.
DSP_VectorLog2Computes the Log2(x) of the first N elements of inVector, and stores the result in outVector.
DSP_VectorMax32Returns the maximum value of a vector.
DSP_VectorMaxIndex32Returns the index of the maximum value of a vector.
DSP_VectorMean32Calculates the mean average of an input vector.
DSP_VectorMin32Returns the minimum value of a vector.
DSP_VectorMinIndex32Returns the index of the minimum value of a vector.
DSP_VectorMul16Multiplication of a series of numbers in one vector to another vector.
DSP_VectorMul32Multiplication of a series of numbers in one vector to another vector.
DSP_VectorMulc16Multiplication of a series of numbers in one vector to a scalar value.
DSP_VectorMulc32Multiplication of a series of numbers in one vector to a scalar value.
DSP_VectorNegateInverses the sign (negates) the elements of a vector.
DSP_VectorRecipComputes the reciprocal (1/x) of the first N elements of inVector, and stores the result in outVector.
DSP_VectorRMS16Computes the root mean square (RMS) value of a vector.
DSP_VectorShiftShifts the data index of an input data vector.
DSP_VectorSqrtComputes the square root of the first N elements of inVector, and stores the result in outVector.
DSP_VectorStdDev16Computes the Standard Deviation of a Vector.
DSP_VectorSub16Calculate the difference of two vectors.
DSP_VectorSub32Calculate the difference of two vectors.
DSP_VectorSumSquares16Computes the sum of squares of a vector, and scales the output by a binary factor.
DSP_VectorSumSquares32Computes the sum of squares of a vector, and scales the output by a binary factor.
DSP_VectorVari16Computes the variance of N elements of a Vector.
DSP_VectorVarianceComputes the variance of N elements of inVector.
DSP_VectorZeroPadFills an input vector with zeros.
mul16Multiply and shift integer.
mul16rMultiply and shift Q15.
mul32Multiply and shift Q31.
SAT16Saturate both positive and negative Q15.
SAT16NSaturate negative Q15.
SAT16PSaturate positive Q15.