PIC32 DSP Functions
PIC32 DSP Functions
Function Name
Description
mips_vec_abs16/32
mips_vec_add16/32
mips_vec_addc16/32
Vector Math
Functions mips_vec_dotp16/32
mips_vec_mul16/32
mips_vec_mulc16/32
mips_vec_sub16/32
Filters
Transforms
mips_fir16
mips_fir16_setup
mips_iir16
mips_iir16_setup
mips_lms16
mips_fft16
mips_fft16_setup
(deprecated)
mips_fft32
mips_fft32_setup
(deprecated)
mips_h264_iqt
mips_h264_iqt_setup
mips_h264_mc_luma
Video
Fxed-Point Types
Input and output data for most functions is represented in 16-bit fractional numbers, in Q15
format. This is the most commonly used data format for signal processing. Some function may
use other data formats internally for increased precision of the intermediate results. The Q15 data
type used by the DSP functions is specified as int16 in the C header files supplied with the
library. This data type is defined in the common dsplib_def.h header file.
Note that within C code care must be taken not to confuse fixed-point values with integers. To
the C compiler, objects declared with int16 type are integers, not fixed-point, and any arithmetic
performed on those objects in C will be done as integers. Fixed-point values have been declared
as int16 only because the standard C language does not include intrinsic support for fixed-point
data types.
Saturation, Scaling, and Overflow
In the majority of DSP applications, overflow or underflow during computation is not desirable.
It is best to design for appropriate scaling of the data path and avoid the possibility of overflow
and underflow. However, such scaling can significantly limit the usable data range. Hence, many
algorithm implementations relax the scaling and introduce saturation operations that clip the
values that would otherwise overflow to the maximum or minimum limit of the data range.
Some of the general purpose DSP library module functions accumulate a series of values before
producing the final result. Examples of these accumulations could include the vector dot product
calculation, the FIR filter, the sum of squared values and even the FFT transform. All of these
functions, with the exception of the FFT, include a parameter that controls the output scaling,
i.e., additional amount of right shift applied when the result is converted to a Q15 value. The
FFT results are automatically scaled down by 2 log2(N).
Array Alignment and Length Restrictions
For the sake of efficiency, most functions require that array pointer arguments are aligned on 4byte boundaries. Arrays of the int16 data type declared in C will be correctly aligned.
Furthermore, there are often restrictions on the number of elements that a function can operate
on. Typically the number of elements must be a multiple of a small integer (e.g., four or eight),
and must be larger than, or equal to, a specified minimum. Note that to improve performance, the
functions do not verify the validity of their input parameters. Supplying incorrect parameters
may lead to unpredictable results.
mips_vec_abs16
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_abs16
(
int16 *outdata,
int16 *indata,
int N
);
Argument:
Return
Value:
None.
mips_vec_abs32
Description: Computes the absolute value of each element of indata and
stores it to outdata. The number of samples to be processed
is given by the parameter N.
Mathematically,
outdata[n] = abs(indata[N])
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_abs32
(
int32 *outdata,
int32 *indata,
int N
);
Argument:
None.
Remarks:
mips_vec_add16
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_add16
(
int16 *outdata,
int16 *indata1,
int16 *indata2,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_add32
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_add32
(
int32 *outdata,
int32 *indata1,
int32 *indata2,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_addc16
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_addc16
(
int16 *outdata,
int16 *indata,
int16 c,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_addc32
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_addc32
(
int32 *outdata,
int32 *indata,
int32 c,
int N
);
Argument:
Return
None.
Value:
Remarks:
mips_vec_dotp16
Description: Computes the dot product of the Q15 vectors indata1 and
indata2. The number of samples to be processed is given by the
parameter N. The scale parameter specifies the amount of right
shift applied to the final result.
Mathematically,
Include:
dsplib_dsp.h
Prototype: int16
mips_vec_dotp16
(
int16 *indata1,
int16 *indata2,
int N,
int scale
);
Argument:
Return
Value:
Remarks:
mips_vec_dotp32
Description: Computes the dot product of the Q31 vectors indata1 and
indata2. The number of samples to be processed is given by
the parameter N. The scale parameter specifies the amount of
right shift applied to the final result.
Mathematically,
result
N 1
indata_1 indata_2
n
n
scale
2
1
n 0
Include:
dsplib_dsp.h
Prototype: int32
mips_vec_dotp32
(
int32 *indata1,
int32 *indata2,
int N,
int scale
);
Argument:
Return
Value:
Remarks:
mips_vec_dotp32
Description: Computes the dot product of the Q31 vectors indata1 and
indata2. The number of samples to be processed is given by
the parameter N. The scale parameter specifies the amount of
right shift applied to the final result.
Mathematically,
result
N 1
indata_1 indata_2
n
n
scale
2
1
n 0
Include:
dsplib_dsp.h
Prototype: int32
mips_vec_dotp32
(
int32 *indata1,
int32 *indata2,
int N,
int scale
);
Argument: indata1 : First input array with 32-bit fixed point elements in
Q31 format.
indata2 : Second input array.
N : Number of samples.
scale : Scaling factor: divide the result by 2scale.
Return
Value:
Remarks:
mips_vec_mul16
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_mul16
(
int16 *outdata,
int16 *indata1,
int16 *indata2,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_mul32
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_mul32
(
int32 *outdata,
int32 *indata1,
int32 *indata2,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_mulc16
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_mulc16
(
int16 *outdata,
int16 *indata,
int16 c,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_mulc32
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_mulc32
(
int32 *outdata,
int32 *indata,
int32 c,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_sub16
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_sub16
(
int16 *outdata,
int16 *indata1,
int16 *indata2,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_sub32
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_vec_sub32
(
int32 *outdata,
int32 *indata1,
int32 *indata2,
int N
);
Argument:
Return
Value:
None.
Remarks:
mips_vec_sum_squares16
Description: Computes the sum of squared values of all elements of
indata. The number of samples to be processed is given by
the parameter N. The scale parameter specifies the amount of
right shift applied to the final result.
Mathematically,
result
N 1
scale
2
indata_1
n 0
Include:
dsplib_dsp.h
Prototype:
int16
mips_vec_sum_squares16
(
int16 *indata,
int N,
int scale
);
Argument:
N Number of samples
scale Scaling factor: divide the result by 2scale.
Return
Value:
Remarks:
mips_vec_sum_squares32
Description: Computes the sum of squared values of all elements of
indata. The number of samples to be processed is given by
the parameter N. The scale parameter specifies the amount of
right shift applied to the final result.
Mathematically,
result
N 1
scale
indata_1
n 0
Include:
dsplib_dsp.h
Prototype:
int32
mips_vec_sum_squares32
(
int32 *indata,
int N,
int scale
);
Argument:
Return
Value:
Remarks:
FILTERING FUNCTIONS
mips_fir16
Description: Computes a finite impulse response (FIR) filter with
coefficients specified in coeffs2x over the input data samples
in indata. The function updates the delayline, which is used to
initialize the filter the next time mips_fir16() is called. The
number of samples to be processed is given by the parameter
N and the number of filter coefficients is given by K. The
scale parameter specifies the amount of right shift applied to
the final result.
Mathematically, output
n
scale
Include:
K 1
k 0
data_in ( n k ) coeffs k
dsplib_dsp.h
Prototype: void
mips_fir16
(
int16 *outdata,
int16 *indata,
int16 *coeffs2x,
int16 *delayline,
int N,
int K,
int scale
);
Argument:
Return
Value:
None.
Remarks:
Notes:
Example:
int i;
int K = 8;
int N = 32;
int16 coeffs[K];
int16 coeffs2x[2*K];
int16 delayline[K];
int16 indata[N];
int16 outdata[N];
for (i = 0; i < K; i++)
delayline[i] = 0;
// load coefficients into coeffs here
...
mips_fir16_setup(coeffs2x, coeffs, K);
while (true)
{
// load input data into indata
...
mips_fir16(outdata, indata, coeffs2x,
delayline, N, K, 3);
// do something with outdata
...
}
mips_fir16_setup
Description:
Include:
dsplib_dsp.h
Prototype:
void
mips_fir16_setup
(
int16 *coeffs2x,
int16 *coeffs,
int K
);
Argument:
Return
Value:
None.
Remarks:
None.
Note:
mips_iir16
Description: Computes a single-sample infinite impulse response (IIR) filter
with coefficients specified in coeffs. The number of biquad
sections composing the filter is given by the parameter B. The
scale parameter specifies the amount of right shift applied to
the input value of each biquad. Each biquad section is
specified by four coefficients A1, A2, B1, and B2 and has
two state variables stored inside delayline. The output of
each biquad section becomes input to the next one. The output
of the final section is returned as result of the mips_iir16()
function.
The operations performed for each biquad section are
illustrated below:
2-S
Input
Ounput
1/z
B1
-A1
S
1/z
-A2
B2
Include:
dsplib_dsp.h
Prototype: int16
mips_iir16
(
int16 in,
int16 *coeffs,
int16 *delayline,
int B,
int scale
);
Remarks:
Notes:
Example:
int i;
int B = 4;
biquad16 bq[B];
int16 coeffs[4*B];
int16 delayline[2*B];
int16 indata, outdata;
for (i = 0; i < 2*B; i++)
delayline[i] = 0;
// load coefficients into bq here
...
mips_iir16_setup
Description:
Rearranges the coefficients from the input array, bq, into the
output array coeffs, which is used by the mips_iir16()
function. The number of biquad sections to process is given
by the parameter B.
Include:
dsplib_dsp.h
Prototype:
void
mips_iir16_setup
(
int16 *coeffs,
biquad16 *bq,
int B
);
Argument:
Return
Value:
None.
Remarks:
None.
Notes:
mips_lms16
Description: Computes a Least Mean Squares (LMS) adaptive filter and
updates its coefficients. The new coefficients are computed
using the error between the last filter output and the reference
signal ref. The function takes one input sample in and
computes one output sample. The parameter mu controls the
adaptation rate of the filter.
Include:
dsplib_dsp.h
Prototype:
int16
mips_lms16
(
int16 in,
int16 ref,
int16 *coeffs,
int16 *delayline,
int16 *error,
int16 K,
int mu
);
Remarks:
Notes:
mips_fft16
Description: Computes the complex fast Fourier transform (FFT) of the
input sequence din. The number of samples to be processed is
specified by the parameter log2N: N = 2log2N. The fftc array
holds complex coefficients needed by the FFT algorithm. The
scratch hold intermediate data; its contents are destroyed on
each call to mips_fft16().
Mathematically,
( 2 k ) n
j
N 1
1
N
data_in e
output
n
n
log( 2 N)
2
k 0
Include:
dsplib_dsp.h
Prototype: void
mips_fft16
(
int16c *dout,
int16c *din,
int16c *fftc,
int16c *scratch,
int log2N
);
Argument:
dout : Output array with 16-bit complex fixedpoint elements in Q15 format.
din : Input array with 16-bit complex fixed-point
elements in Q15 format.
fftc : Input array with 16-bit complex fixed-point
twiddle factors in Q15 format.
scratch : Intermediate results array holding 16-bit
complex fixed-point data.
log2N : Logarithm base 2 of the number of
samples: N = 2log2N.
Return
None.
Value:
Remarks:
Notes:
Example:
Include:
dsplib_dsp.h
Prototype:
void
mips_fft16_setup
(
int16c *twiddles,
int log2N
);
Argument:
Return
Value:
None.
Remarks:
Notes:
mips_fft32
Description: Computes the complex Fast Fourier Transform (FFT) of the
input sequence din. The number of samples to be processed is
specified by the parameter log2N: N = 2log2N. The fftc array
holds complex coefficients needed by the FFT algorithm. The
scratch hold intermediate data; its contents are destroyed on
each call to mips_fft32().
Mathematically,
Include:
dsplib_dsp.h
Prototype: void
mips_fft32
(
int32c *dout,
int32c *din,
int32c *fftc,
int132 *scratch,
int log2N
);
Argument:
dout : Output array with 32-bit complex fixedpoint elements in Q31 format.
din : Input array with 32-bit complex fixed-point
elements in Q31 format.
fftc : Input array with 32-bit complex fixed-point
twiddle factors in Q31 format.
scratch : Intermediate results array holding 32-bit
complex fixed-point data.
log2N : Logarithm base 2 of the number of
samples: N = 2log2N.
Return
Value:
None.
Remarks:
Notes:
Include:
dsplib_dsp.h
Prototype:
void
mips_fft32_setup
(
int32c *twiddles,
int log2N
);
Argument:
Return
Value:
None.
Remarks:
Notes: