![](https://csdnimg.cn/release/download_crawler_static/12859715/bg6.jpg)
2 Introduction to Digital Signal Processing
6 Effective DSP Programming using MIPS® DSP Application Specific Extensions, Revision 01.22
output[k] = s;
}
In this code example, N is the total number of samples that are processed and T is the number of filter coefficients
(taps). The coefficients are stored in the array called filter in reverse order to simplify the array indexing. The inner-
most loop computes the dot product of the filter coefficients and the group of T input samples starting from sample k.
Note the MAC operation at the heart of the code - one input sample is multiplied by one coefficient and the product is
accumulated. Since MAC operations are very common in DSP algorithms, processors targeting DSP applications
often provide specialized MAC instructions. The MIPS32 instruction set provides MAC instructions, while its capa-
bilities are enhanced by the DSP ASE.
2.4 DSP Data Types
The example in the previous section does not make the data types explicit. It is easiest to perform all calculations
using floating-point numbers, but hardware floating-point support is not always available. Even if it is, the perfor-
mance of floating-point operations might be lower than that of integer operations and processors supporting floating-
point units are typically bigger and have a higher cost. To avoid magnitude growth of the multiplication product, DSP
algorithms often represent the data samples and the coefficients used in the computation as fractional numbers
between -1 and +1. This is accomplished by placing the binary point separating the integer and fractional parts of the
number immediately after the sign bit. Some of the commonly used fixed-point (or fractional) formats include Q15
(sign bit, zero integer bits, 15 fractional bits) and Q31 (sign bit, zero integer bits, 31 fractional bits). Sometimes data
formats with one or more integer bits are used, trading off increased dynamic range for lower precision.
Note that the same hardware that performs integer add, subtract, and multiply operations can also be used for fixed-
point operations. However, a fractional multiplication operation needs to be shifted left by one bit to re-align the data
to a correct fractional double-width product. This is because multiplying two numbers in fixed-point format produces
one redundant sign bit. The fractional multiply instructions in the MIPS32 DSP ASE automatically perform this cor-
rection.
2.5 Saturation And Rounding
Saturation and rounding are rare operations in non-DSP code, but used often in DSP algorithms. Saturation limits the
result of a computation to the range implied by the input data type, thus avoiding overflow and underflow conditions.
For example, an image processing application will typically use 8-bit unsigned integers for pixel representation, with
the value of zero corresponding to black and the value of 255 corresponding to white.
Now imagine that we have to make an image 25% brighter. If we have a somewhat white pixel with a value of 220
and we multiply it by 1.25 to make it 25% brighter, we would get:
220 x 1.25 = 275
But 275 is not representable as an 8-bit number! Instead, the multiplication result will wrap-around to
275 - 256 = 19,
and suddenly we have a somewhat dark pixel! Saturation prevents cases like this by clipping the result to the maxi-
mum allowed value-- in this example, 255:
saturate(275) = 255
The rounding operation is used when the precision of some calculated result needs to be reduced. For example, multi-
plying Q15 numbers produces a Q31 result, but if we want to store it to memory as a 16-bit value, then we simply